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:
parent
9064663600
commit
9ff48f4c12
@ -108,7 +108,7 @@ if __name__ == '__main__':
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
exact = exact_func(X[0], X[1])
|
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
|
success += 1
|
||||||
|
|
||||||
if options.verbose:
|
if options.verbose:
|
||||||
|
55
lib/grid.py
55
lib/grid.py
@ -31,6 +31,20 @@ class face(object):
|
|||||||
)
|
)
|
||||||
|
|
||||||
class grid(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):
|
def __init__(self, points, q):
|
||||||
"""
|
"""
|
||||||
this thing eats two pre-constructed arrays of stuff:
|
this thing eats two pre-constructed arrays of stuff:
|
||||||
@ -41,40 +55,38 @@ class grid(object):
|
|||||||
self.points = np.array(points)
|
self.points = np.array(points)
|
||||||
self.q = np.array(q)
|
self.q = np.array(q)
|
||||||
self.faces = {}
|
self.faces = {}
|
||||||
|
self.facets_for_point = {}
|
||||||
|
|
||||||
def construct_connectivity(self, s):
|
def construct_connectivity(self, qdelaunay_string):
|
||||||
facet_re = re.compile(r'''
|
facet_to_facets = []
|
||||||
-\s+(?P<facet>f\d+).*?
|
for matcher in grid.facet_re.finditer(qdelaunay_string):
|
||||||
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):
|
|
||||||
d = matcher.groupdict()
|
d = matcher.groupdict()
|
||||||
|
|
||||||
facet_name = d['facet']
|
facet_name = d['facet']
|
||||||
verticies = d['verts']
|
verticies = d['verts']
|
||||||
neighbors = d['neigh']
|
neighboring_facets = d['neigh']
|
||||||
|
|
||||||
cur_face = face(facet_name)
|
cur_face = face(facet_name)
|
||||||
self.faces[facet_name] = cur_face
|
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:]))
|
cur_face.add_vert(int(v[1:]))
|
||||||
|
|
||||||
nghbrs = [(facet_name, i) for i in neighbors.split()]
|
nghbrs = [(facet_name, i) for i in neighboring_facets.split()]
|
||||||
rajoutter.extend(nghbrs)
|
facet_to_facets.extend(nghbrs)
|
||||||
|
|
||||||
for rel in rajoutter:
|
for rel in facet_to_facets:
|
||||||
if rel[1] in self.faces:
|
if rel[1] in self.faces:
|
||||||
self.faces[rel[0]].add_neighbor(self.faces[rel[1]])
|
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):
|
def for_qhull_generator(self):
|
||||||
"""
|
"""
|
||||||
this returns a generator that should be fed into qdelaunay
|
this returns a generator that should be fed into qdelaunay
|
||||||
@ -100,7 +112,8 @@ class grid(object):
|
|||||||
r = ''
|
r = ''
|
||||||
assert( len(self.points) == len(self.q) )
|
assert( len(self.points) == len(self.q) )
|
||||||
for c, i in enumerate(zip(self.points, 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:
|
if self.faces:
|
||||||
for v in self.faces.itervalues():
|
for v in self.faces.itervalues():
|
||||||
r += "%s\n" % v
|
r += "%s\n" % v
|
||||||
|
Loading…
Reference in New Issue
Block a user