working on getting baker to work in 3D. the code runs, but the numbers are odd. I suspect the rectangular grid, and am going to try a random cloud of points.

This commit is contained in:
Stephen Mardson McQuay
2010-03-18 23:18:59 -06:00
parent a2d7b3f063
commit b33159f8a9
8 changed files with 151 additions and 154 deletions
+4 -105
View File
@@ -7,49 +7,11 @@ from collections import defaultdict
import numpy as np
import scipy.spatial
from baker import run_baker, get_phis
from baker import run_baker
from baker.tools import exact_func, smberror
from simplex import face
from smcqdelaunay import *
class face(object):
def __init__(self, name):
self.name = name
self.verts = []
self.neighbors = []
def add_vert(self, v):
"""
v should be an index into grid.points
"""
self.verts.append(v)
def add_neighbor(self, n):
"""
reference to another face object
"""
self.neighbors.append(n)
def contains(self, X, grid):
R = [grid.points[i] for i in self.verts]
phis = get_phis(X, R)
r = True
if [i for i in phis if i < 0.0]:
r = False
return r
def __str__(self):
neighbors = [i.name for i in self.neighbors]
return '%s: verts: %s neighbors: [%s]' %\
(
self.name,
self.verts,
", ".join(neighbors)
)
class grid(object):
@@ -97,7 +59,7 @@ class grid(object):
R is a grid object that is the (a) containing simplex around point X
S is S_j from baker's paper : some points from all point that are not the simplex
"""
(dist, indicies) = self.tree.query(X, 3 + extra_points)
(dist, indicies) = self.tree.query(X, simplex_size + extra_points)
# get the containing simplex
@@ -152,7 +114,7 @@ class grid(object):
try:
(R, S) = self.get_simplex_and_nearest_points(X)
answer = run_baker(X, R, S)
except smberror as e:
except smberror, e:
print "caught error: %s, trying with connectivity-based mesh" % e
(R, S) = self.get_points_conn(X)
answer = run_baker(X, R, S)
@@ -199,27 +161,6 @@ class grid(object):
# self.facets_for_point[int(point[1:])] = [i for i in neighboring_facets.split() if i in self.faces]
def for_qhull_generator(self):
"""
this returns a generator that should be fed into qdelaunay
"""
yield '2';
yield '%d' % len(self.points)
for p in self.points:
yield "%f %f" % (p[0], p[1])
def for_qhull(self):
"""
this returns a single string that should be fed into qdelaunay
"""
r = '2\n'
r += '%d\n' % len(self.points)
for p in self.points:
r += "%f %f\n" % (p[0], p[1])
return r
def __str__(self):
r = ''
assert( len(self.points) == len(self.q) )
@@ -233,49 +174,7 @@ class grid(object):
r += "%s\n" % v
return r
class simple_rect_grid(grid):
def __init__(self, xres = 5, yres = 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)
points = []
q = []
for x in xrange(xres):
cur_x = xmin + (x * xdel)
for y in xrange(yres):
cur_y = ymin + (y * ydel)
points.append([cur_x, cur_y])
q.append(exact_func(cur_x, cur_y))
grid.__init__(self, points, q)
self.construct_connectivity()
class simple_random_grid(simple_rect_grid):
def __init__(self, num_points = 10):
points = []
q = []
r = np.random
for i in xrange(num_points):
cur_x = r.rand()
cur_y = r.rand()
points.append([cur_x, cur_y])
q.append(exact_func(cur_x, cur_y))
grid.__init__(self, points, q)
self.points = np.array(self.points)
self.q = np.array(self.q)
if __name__ == '__main__':