smbinterp/interp/grid/DDD.py
Stephen Mardson McQuay 2db4169bfa major refactoring
--HG--
rename : lib/baker/__init__.py => interp/baker/__init__.py
rename : lib/grid/DD.py => interp/grid/DD.py
rename : lib/grid/DDD.py => interp/grid/DDD.py
rename : lib/grid/__init__.py => interp/grid/__init__.py
rename : lib/grid/qhull.py => interp/grid/qhull.py
rename : lib/grid/simplex.py => interp/grid/simplex.py
rename : lib/grid/smcqdelaunay.py => interp/grid/smcqdelaunay.py
rename : lib/baker/tools.py => interp/tools.py
2010-10-22 16:10:58 -06:00

109 lines
2.4 KiB
Python

from grid import grid as basegrid
from baker.tools import exact_func_3D, smblog
import numpy as np
class grid(basegrid):
def __init__(self, points, q):
basegrid.__init__(self, points, q)
def for_qhull_generator(self):
"""
this returns a generator that should be fed into qdelaunay
"""
yield '3';
yield '%d' % len(self.points)
for p in self.points:
yield "%f %f %f" % tuple(p)
def for_qhull(self):
"""
this returns a single string that should be fed into qdelaunay
"""
r = '3\n'
r += '%d\n' % len(self.points)
for p in self.points:
r += "%f %f %f\n" % tuple(p)
return r
class rect_grid(grid):
def __init__(self, xres = 5, yres = 5, zres = 5):
xmin = -1.0
xmax = 1.0
xspan = xmax - xmin
xdel = xspan / float(xres - 1)
ymin = -1.0
ymay = 1.0
yspan = ymay - ymin
ydel = yspan / float(yres - 1)
zmin = -1.0
zmaz = 1.0
zspan = zmaz - zmin
zdel = zspan / float(zres - 1)
points = []
q = []
for x in xrange(xres):
cur_x = xmin + (x * xdel)
for y in xrange(yres):
cur_y = ymin + (y * ydel)
for z in xrange(zres):
cur_z = zmin + (z * zdel)
points.append([cur_x, cur_y, cur_z])
q.append(exact_func_3D((cur_x, cur_y, cur_z)))
grid.__init__(self, points, q)
# self.construct_connectivity()
def for_qhull_generator(self):
"""
this returns a generator that should be fed into qdelaunay
"""
yield '3';
yield '%d' % len(self.points)
for p in self.points:
yield "%f %f %f" % tuple(p)
def for_qhull(self):
"""
this returns a single string that should be fed into qdelaunay
"""
r = '3\n'
r += '%d\n' % len(self.points)
for p in self.points:
r += "%f %f %f\n" % tuple(p)
return r
class random_grid(rect_grid):
def __init__(self, num_points = 10):
points = []
q = []
r = np.random
appx_side_res = int(np.power(num_points, 1/3.0))
smblog.debug("appx_side_res: %d" % appx_side_res)
delta = 1.0 / float(appx_side_res)
for x in xrange(appx_side_res + 1):
pass
for i in xrange(num_points):
cur_x = r.rand()
cur_y = r.rand()
cur_z = r.rand()
points.append([cur_x, cur_y, cur_z])
q.append(exact_func_3D((cur_x, cur_y, cur_z)))
grid.__init__(self, points, q)
self.points = np.array(self.points)
self.q = np.array(self.q)