2011-03-23 23:38:55 -07:00
|
|
|
#!/usr/bin/env python
|
2010-02-14 19:56:41 -08:00
|
|
|
|
|
|
|
import sys
|
|
|
|
import pickle
|
2010-03-20 19:09:46 -07:00
|
|
|
import pdb
|
2010-02-14 19:56:41 -08:00
|
|
|
|
2010-10-23 16:06:11 -07:00
|
|
|
from interp.grid.DD import rect_grid, random_grid
|
|
|
|
from interp.baker import run_baker
|
2011-03-28 17:46:59 -07:00
|
|
|
from interp.tools import baker_exact_2D as exact_func
|
2010-03-05 07:58:07 -08:00
|
|
|
|
2010-02-14 19:56:41 -08:00
|
|
|
qfile = '/tmp/grid_regular.txt'
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
try:
|
2010-02-26 13:44:29 -08:00
|
|
|
rx = int(sys.argv[1])
|
|
|
|
ry = int(sys.argv[2])
|
2010-03-05 07:58:07 -08:00
|
|
|
except (IndexError, ValueError) as e:
|
|
|
|
print "problem with argv: %s" % e
|
2010-02-26 13:44:29 -08:00
|
|
|
rx = 4
|
|
|
|
ry = 4 * rx
|
2010-02-21 19:52:51 -08:00
|
|
|
|
2010-03-20 16:10:02 -07:00
|
|
|
source_mesh = rect_grid(rx, ry)
|
2010-02-26 13:44:29 -08:00
|
|
|
|
2010-03-05 07:58:07 -08:00
|
|
|
# print source_mesh
|
2010-02-26 13:44:29 -08:00
|
|
|
|
2011-05-04 19:23:49 -07:00
|
|
|
X = [0.5, 0.5]
|
2010-02-26 13:44:29 -08:00
|
|
|
|
2010-03-05 07:58:07 -08:00
|
|
|
try:
|
2010-03-20 16:10:02 -07:00
|
|
|
print "trying to get simplex and nearest points using nearest points (kdtree)"
|
2010-03-05 07:58:07 -08:00
|
|
|
(R, S) = source_mesh.get_simplex_and_nearest_points(X, extra_points=4)
|
|
|
|
print "R for nearest-neighbor:\n", R
|
|
|
|
print "S for nearest-neighbor:\n", S
|
2010-03-20 16:10:02 -07:00
|
|
|
print "trying to run baker"
|
2010-03-05 07:58:07 -08:00
|
|
|
print run_baker(X, R, S)
|
2010-10-23 16:06:11 -07:00
|
|
|
except Exception as e:
|
2010-03-05 07:58:07 -08:00
|
|
|
print "caught error: %s" % e
|
2010-03-20 16:10:02 -07:00
|
|
|
|
|
|
|
print "trying to get simplex and nearest points using connectivity scheme"
|
2010-03-05 07:58:07 -08:00
|
|
|
(R, S) = source_mesh.get_points_conn(X)
|
|
|
|
print "R for connectivity:\n", R
|
|
|
|
print "S for connectivity:\n", S
|
|
|
|
print run_baker(X, R, S)
|
|
|
|
|
|
|
|
|
|
|
|
print "repeating the above just using the grid object:"
|
2010-03-20 16:10:02 -07:00
|
|
|
r = source_mesh.run_baker(X)
|
|
|
|
exact = exact_func(X)
|
|
|
|
print r
|
|
|
|
print 'exact', exact
|
|
|
|
print 'qlin' , r['qlin']
|
|
|
|
print 'error', r['error']
|
|
|
|
print 'final', r['final']
|
|
|
|
|
|
|
|
if abs(r['final'] - exact) <= abs(r['qlin'] - exact):
|
|
|
|
print "win"
|
|
|
|
else:
|
|
|
|
print "failure"
|
2010-02-21 19:52:51 -08:00
|
|
|
open(qfile, 'w').write(source_mesh.for_qhull())
|