smbinterp/interp/grid/simplex.py
Stephen Mardson McQuay 2db4169bfa 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
2010-10-22 16:10:58 -06:00

65 lines
1.4 KiB
Python

from baker import get_phis, get_phis_3D
from baker.tools import smblog
TOL = 1e-8
def contains(X, R):
"""
tests if X (point) is in R (a simplex,
represented by a list of n-degree coordinates)
it now correctly checks for 2/3-D points
"""
if len(X) == 2:
phis = get_phis(X, R)
elif len(X) == 3:
phis = get_phis_3D(X, R)
r = True
if [i for i in phis if i < 0.0 - TOL]:
r = False
return r
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, G):
"""
X = point of interest
G = corrensponding grid object (G.points)
because of the way i'm storing things,
a face simply stores indicies, and so one
must pass in a reference to the grid object
containing real points.
this simply calls grid.simplex.contains
"""
return contains(X, [G.points[i] for i in self.verts])
def __str__(self):
neighbors = [str(i.name) for i in self.neighbors]
return '<face %s: verts: %s neighbors: [%s]>' %\
(
self.name,
self.verts,
", ".join(neighbors)
)
__repr__ = __str__