DDD random_grid now has edges. it needs faces

This commit is contained in:
Stephen McQuay 2011-05-21 08:53:37 -06:00
parent fb79daba36
commit ca49c7eec7

View File

@ -1,6 +1,8 @@
from interp.grid.delaunay import dgrid as basegrid from interp.grid.delaunay import dgrid as basegrid
from interp.tools import baker_exact_3D, log from interp.tools import baker_exact_3D, log
from itertools import product
import numpy as np import numpy as np
class rect_grid(basegrid): class rect_grid(basegrid):
@ -36,27 +38,40 @@ class rect_grid(basegrid):
class random_grid(rect_grid): class random_grid(rect_grid):
def __init__(self, num_verts = 10): def __init__(self, num_verts = 100):
verts = [] verts = []
q = []
r = np.random r = np.random
appx_side_res = int(np.power(num_verts, 1/3.0)) 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) delta = 1.0 / float(appx_side_res)
for x in xrange(appx_side_res + 1): # populate all corners
pass verts = [i for i in product((0,1), repeat = 3)]
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]) # populate the edges (bottom and top squares)
q.append(baker_exact_3D((cur_x, cur_y, cur_z))) for z in (0,1):
basegrid.__init__(self, verts, q) for x in xrange(1, appx_side_res):
cur_x = x * delta
for cur_y in (0, 1):
new_point = [cur_x, cur_y, z]
verts.append(new_point)
self.verts = np.array(self.verts) for y in xrange(1, appx_side_res):
self.q = np.array(self.q) cur_y = y * delta
for cur_x in (0, 1):
new_point = [cur_x, cur_y, z]
verts.append(new_point)
# populate side edges
for x in (0,1):
for y in (0,1):
for z in xrange(1, appx_side_res):
cur_z = z * delta
verts.append((x,y,cur_z))
verts.extend(np.random.random((num_verts - 12 * appx_side_res, 3)))
q = np.zeros(len(verts))
basegrid.__init__(self, np.array(verts), q)