major refactoring
--HG-- rename : lib/baker/__init__.py => interp/baker/__init__.py rename : lib/grid/DD.py => interp/grid/DD.py rename : lib/grid/DDD.py => interp/grid/DDD.py rename : lib/grid/__init__.py => interp/grid/__init__.py rename : lib/grid/qhull.py => interp/grid/qhull.py rename : lib/grid/simplex.py => interp/grid/simplex.py rename : lib/grid/smcqdelaunay.py => interp/grid/smcqdelaunay.py rename : lib/baker/tools.py => interp/tools.py
This commit is contained in:
+23
-58
@@ -21,50 +21,15 @@ del os, atexit, readline, rlcompleter, save_history, historyPath
|
||||
import sys
|
||||
import pickle
|
||||
from itertools import combinations
|
||||
from collections import defaultdict
|
||||
from scipy.spatial import KDTree
|
||||
|
||||
from grid.simplex import face
|
||||
|
||||
import numpy as np
|
||||
|
||||
THREE_NODE_TRIANGLE = 2
|
||||
|
||||
class point(object):
|
||||
def __init__(self, xyz):
|
||||
self.index = index
|
||||
|
||||
self.xyz = xyz
|
||||
self.faces = []
|
||||
|
||||
def __getitem__(self, i):
|
||||
if isinstance(i, int):
|
||||
if i == 0:
|
||||
return self.xyz[0]
|
||||
elif i == 1:
|
||||
return self.xyz[1]
|
||||
elif i == 2:
|
||||
return self.xyz[2]
|
||||
else:
|
||||
raise IndexError("there are only (x,y,z)")
|
||||
else:
|
||||
raise TypeError("only point.x and point[0] access allowed")
|
||||
|
||||
def _getx(self):
|
||||
return self.xyz[0]
|
||||
x = property(_getx)
|
||||
def _gety(self):
|
||||
return self.xyz[1]
|
||||
y = property(_gety)
|
||||
def _getz(self):
|
||||
return self.xyz[2]
|
||||
z = property(_getz)
|
||||
|
||||
def __str__(self):
|
||||
return '%s' % self.xyz
|
||||
__repr__ = __str__
|
||||
|
||||
class face(object):
|
||||
def __init__(self):
|
||||
self.neighbors = []
|
||||
self.points = []
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) != 2:
|
||||
print >> sys.stderr, "usage: %s <gmsh file>" % sys.argv[0]
|
||||
@@ -81,8 +46,7 @@ if __name__ == '__main__':
|
||||
|
||||
node_count = int(gmsh_file.readline())
|
||||
|
||||
points = []
|
||||
nppoints = np.zeros((node_count, 3))
|
||||
verts = np.zeros((node_count, 3))
|
||||
for i in xrange(node_count):
|
||||
cur_line = gmsh_file.readline()
|
||||
(index, x,y,z) = cur_line.split()
|
||||
@@ -91,19 +55,20 @@ if __name__ == '__main__':
|
||||
y = float(y)
|
||||
z = float(z)
|
||||
|
||||
nppoints[i][0] = x
|
||||
nppoints[i][1] = y
|
||||
nppoints[i][2] = z
|
||||
points.append(point(nppoints[i]))
|
||||
verts[i][0] = x
|
||||
verts[i][1] = y
|
||||
verts[i][2] = z
|
||||
|
||||
tree = KDTree(verts)
|
||||
|
||||
gmsh_file.readline() # $EndNodes
|
||||
gmsh_file.readline() # $Elements
|
||||
gmsh_file.readline() # $E ndNodes
|
||||
gmsh_file.readline() # $E lements
|
||||
|
||||
element_count = int(gmsh_file.readline())
|
||||
|
||||
faceobjs = {}
|
||||
neighbors = {}
|
||||
faces = {}
|
||||
neighbors = {}
|
||||
faces_for_vert = defaultdict(list)
|
||||
|
||||
for i in xrange(element_count):
|
||||
cur_line = gmsh_file.readline()
|
||||
@@ -115,17 +80,17 @@ if __name__ == '__main__':
|
||||
if(node_type == THREE_NODE_TRIANGLE):
|
||||
points_for_cur_face = [i-1 for i in rest[rest[0]+1:]]
|
||||
|
||||
cur_face = face()
|
||||
cur_face = face(cur_face_index)
|
||||
|
||||
for cur_point in points_for_cur_face:
|
||||
points[cur_point].faces.append(cur_face_index)
|
||||
faces_for_vert[cur_point].append(cur_face_index)
|
||||
|
||||
cur_face.points = points_for_cur_face
|
||||
cur_face.verts = points_for_cur_face
|
||||
|
||||
faceobjs[cur_face_index] = cur_face
|
||||
faces[cur_face_index] = cur_face
|
||||
edges = [tuple(sorted(i)) for i in combinations(points_for_cur_face, 2)]
|
||||
|
||||
# edge is two points
|
||||
# edge is two verts
|
||||
for edge in edges:
|
||||
if edge in neighbors:
|
||||
neighbors[edge].append(cur_face_index)
|
||||
@@ -134,8 +99,8 @@ if __name__ == '__main__':
|
||||
|
||||
for k,v in neighbors.iteritems():
|
||||
if len(v) > 1:
|
||||
faceobjs[v[0]].neighbors.append(v[1])
|
||||
faceobjs[v[1]].neighbors.append(v[0])
|
||||
faces[v[0]].add_neighbor(faces[v[1]])
|
||||
faces[v[1]].add_neighbor(faces[v[0]])
|
||||
|
||||
pickle.dump([(p[0], p[1], p[2]) for p in points], open('/tmp/points.p', 'w'))
|
||||
pickle.dump([f.points for f in faceobjs.itervalues()], open('/tmp/faces.p', 'w'))
|
||||
pickle.dump([(p[0], p[1], p[2]) for p in verts], open('/tmp/points.p', 'w'))
|
||||
pickle.dump([f.verts for f in faces.itervalues()], open('/tmp/faces.p', 'w'))
|
||||
|
||||
@@ -67,4 +67,3 @@ if __name__ == '__main__':
|
||||
good.append(d[True])
|
||||
|
||||
draw_gb(bad = bad, good = good)
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python2.6
|
||||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
from grid.DD import grid
|
||||
@@ -24,6 +24,8 @@ g = grid(verts,q)
|
||||
|
||||
exact = exact_func(X)
|
||||
|
||||
d = {True:0, False:0}
|
||||
|
||||
try:
|
||||
answer = g.run_baker(X)
|
||||
d[improved_answer(answer, exact)] += 1
|
||||
|
||||
Reference in New Issue
Block a user