minor: added point to facet information to the grid object

I really think that I need to create my own point object, and hang the facet information directly off of that. right now there are simply parallel arrays for q, numpy.array(x,y), and {point_index: [adjacent faces]} ...

work to be done!
This commit is contained in:
Stephen Mardson McQuay 2010-02-10 00:20:06 -07:00
parent 9064663600
commit 9ff48f4c12
2 changed files with 40 additions and 27 deletions

View File

@ -108,7 +108,7 @@ if __name__ == '__main__':
continue
exact = exact_func(X[0], X[1])
if np.abs(exact - answer['final']) < np.abs(exact - answer['qlin']):
if np.abs(exact - answer['final']) <= np.abs(exact - answer['qlin']):
success += 1
if options.verbose:

View File

@ -31,6 +31,20 @@ class face(object):
)
class grid(object):
facet_re = re.compile(r'''
-\s+(?P<facet>f\d+).*?
vertices:\s(?P<verts>.*?)\n.*?
neighboring\s facets:\s+(?P<neigh>[\sf\d]*)
''', re.S|re.X)
point_re = re.compile(r'''
-\s+(?P<point>p\d+).*?
neighbors:\s+(?P<neigh>[\sf\d]*)
''', re.S|re.X)
vert_re = re.compile(r'''
(p\d+)
''', re.S|re.X)
def __init__(self, points, q):
"""
this thing eats two pre-constructed arrays of stuff:
@ -41,40 +55,38 @@ class grid(object):
self.points = np.array(points)
self.q = np.array(q)
self.faces = {}
self.facets_for_point = {}
def construct_connectivity(self, s):
facet_re = re.compile(r'''
-\s+(?P<facet>f\d+).*?
vertices:\s(?P<verts>.*?)\n.*?
neighboring\s facets:\s+(?P<neigh>[\sf\d]*)
''', re.S|re.X)
vert_re = re.compile(r'''
(p\d+)
''', re.S|re.X)
rajoutter = []
for matcher in facet_re.finditer(s):
def construct_connectivity(self, qdelaunay_string):
facet_to_facets = []
for matcher in grid.facet_re.finditer(qdelaunay_string):
d = matcher.groupdict()
facet_name = d['facet']
verticies = d['verts']
neighbors = d['neigh']
neighboring_facets = d['neigh']
cur_face = face(facet_name)
self.faces[facet_name] = cur_face
for v in vert_re.findall(verticies):
for v in grid.vert_re.findall(verticies):
cur_face.add_vert(int(v[1:]))
nghbrs = [(facet_name, i) for i in neighbors.split()]
rajoutter.extend(nghbrs)
nghbrs = [(facet_name, i) for i in neighboring_facets.split()]
facet_to_facets.extend(nghbrs)
for rel in rajoutter:
for rel in facet_to_facets:
if rel[1] in self.faces:
self.faces[rel[0]].add_neighbor(self.faces[rel[1]])
for matcher in grid.point_re.finditer(qdelaunay_string):
d = matcher.groupdict()
point = d['point']
neighboring_facets = d['neigh']
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
@ -100,7 +112,8 @@ class grid(object):
r = ''
assert( len(self.points) == len(self.q) )
for c, i in enumerate(zip(self.points, self.q)):
r += "%d %r: %0.4f\n" % (c,i[0], i[1])
r += "%d %r: %0.4f" % (c,i[0], i[1])
r += " faces: %s\n" % (self.facets_for_point[c])
if self.faces:
for v in self.faces.itervalues():
r += "%s\n" % v