2011-02-02 09:56:20 -08:00
|
|
|
from interp.baker import get_phis
|
2010-10-23 12:49:15 -07:00
|
|
|
from interp.tools import log
|
2010-03-18 22:32:24 -07:00
|
|
|
|
2010-03-20 19:09:46 -07:00
|
|
|
TOL = 1e-8
|
2010-03-20 16:10:02 -07:00
|
|
|
|
|
|
|
def contains(X, R):
|
2010-03-20 19:09:46 -07:00
|
|
|
"""
|
|
|
|
tests if X (point) is in R (a simplex,
|
|
|
|
represented by a list of n-degree coordinates)
|
2010-04-29 22:29:35 -07:00
|
|
|
|
2010-10-23 16:06:57 -07:00
|
|
|
it now correctly checks for 2/3-D verts
|
2011-02-02 09:56:20 -08:00
|
|
|
|
|
|
|
TODO: write unit test ...
|
2010-03-20 19:09:46 -07:00
|
|
|
"""
|
2011-02-02 09:56:20 -08:00
|
|
|
phis = get_phis(X, R)
|
2010-04-29 22:29:35 -07:00
|
|
|
|
2010-03-20 19:09:46 -07:00
|
|
|
r = True
|
|
|
|
if [i for i in phis if i < 0.0 - TOL]:
|
|
|
|
r = False
|
|
|
|
return r
|
2010-03-20 16:10:02 -07:00
|
|
|
|
|
|
|
|
2010-11-08 14:07:48 -08:00
|
|
|
class cell(object):
|
2010-03-18 22:32:24 -07:00
|
|
|
def __init__(self, name):
|
|
|
|
self.name = name
|
|
|
|
self.verts = []
|
|
|
|
self.neighbors = []
|
|
|
|
|
|
|
|
def add_vert(self, v):
|
|
|
|
"""
|
2010-10-23 16:06:57 -07:00
|
|
|
v should be an index into grid.verts
|
2010-03-18 22:32:24 -07:00
|
|
|
"""
|
|
|
|
self.verts.append(v)
|
|
|
|
|
|
|
|
def add_neighbor(self, n):
|
|
|
|
"""
|
2010-11-08 14:07:48 -08:00
|
|
|
reference to another cell object
|
2010-03-18 22:32:24 -07:00
|
|
|
"""
|
|
|
|
self.neighbors.append(n)
|
|
|
|
|
2010-03-20 19:09:46 -07:00
|
|
|
def contains(self, X, G):
|
|
|
|
"""
|
|
|
|
X = point of interest
|
2010-10-23 16:06:57 -07:00
|
|
|
G = corrensponding grid object (G.verts)
|
2010-03-20 19:09:46 -07:00
|
|
|
because of the way i'm storing things,
|
2010-11-08 14:07:48 -08:00
|
|
|
a cell simply stores indicies, and so one
|
2010-03-20 19:09:46 -07:00
|
|
|
must pass in a reference to the grid object
|
2010-10-23 16:06:57 -07:00
|
|
|
containing real verts.
|
2010-03-20 19:09:46 -07:00
|
|
|
|
|
|
|
this simply calls grid.simplex.contains
|
|
|
|
"""
|
2010-10-23 16:06:57 -07:00
|
|
|
return contains(X, [G.verts[i] for i in self.verts])
|
2010-03-18 22:32:24 -07:00
|
|
|
|
|
|
|
def __str__(self):
|
2010-10-22 15:10:58 -07:00
|
|
|
neighbors = [str(i.name) for i in self.neighbors]
|
2010-11-08 14:07:48 -08:00
|
|
|
return '<cell %s: verts: %s neighbors: [%s]>' %\
|
2010-03-18 22:32:24 -07:00
|
|
|
(
|
|
|
|
self.name,
|
|
|
|
self.verts,
|
|
|
|
", ".join(neighbors)
|
|
|
|
)
|
2010-10-22 15:10:58 -07:00
|
|
|
|
|
|
|
__repr__ = __str__
|