from interp.grid.delaunay import dgrid as basegrid from interp.tools import exact_func_3D, log import numpy as np class rect_grid(basegrid): 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) verts = [] 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) verts.append([cur_x, cur_y, cur_z]) q.append(exact_func_3D((cur_x, cur_y, cur_z))) basegrid.__init__(self, verts, q) class random_grid(rect_grid): def __init__(self, num_verts = 10): verts = [] q = [] r = np.random appx_side_res = int(np.power(num_verts, 1/3.0)) log.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_verts): cur_x = r.rand() cur_y = r.rand() cur_z = r.rand() verts.append([cur_x, cur_y, cur_z]) q.append(exact_func_3D((cur_x, cur_y, cur_z))) rect_grid.__init__(self, verts, q) self.verts = np.array(self.verts) self.q = np.array(self.q)