moved teh grid code into the grid class

by next friday i need to have implemented a way to select between normal kdtree point lookups, and nearest-neighbor lookups. Hopefully i'll have that done tonight.
This commit is contained in:
smcquay@cfdviz2
2010-02-20 13:18:24 -07:00
parent 2cf9a0b574
commit 6c4c6d4cfe
3 changed files with 39 additions and 29 deletions
+4 -5
View File
@@ -1,4 +1,3 @@
from grid import exact_func
import numpy as np
import sys
@@ -93,16 +92,16 @@ def qlinear_3D(X, R, q):
qlin = sum([q_i * phi_i for q_i, phi_i in zip(q, phis)])
return qlin
def run_baker(X, R, S, verbose = False):
def run_baker(X, R, S):
"""
This is the main function to call to get an interpolation to X from the tree
This is the main function to call to get an interpolation to X from the input meshes
X -- the destination point (2D)
X = [0,0]
g -- the grid object
R = Simplex
tree -- the kdtree search object (built from the g mesh)
S = extra points
"""
+28
View File
@@ -7,6 +7,7 @@ from collections import defaultdict
import numpy as np
import scipy.spatial
from baker import run_baker
from tools import exact_func
from smcqdelaunay import *
@@ -58,9 +59,36 @@ class grid(object):
self.points = np.array(points)
self.q = np.array(q)
self.tree = scipy.spatial.KDTree(self.points)
self.faces = {}
self.facets_for_point = defaultdict(list)
def get_simplex_and_nearest_points(self, X, extra_points = 3, simplex_size = 3):
"""
this returns two grid objects: R and S.
R is a grid object that is the (a) containing simplex around point X
S is S_j from baker's paper : some points from all point that are not the simplex
"""
(dist, indicies) = self.tree.query(X, 3 + extra_points)
# get the containing simplex
R = [self.points[i] for i in indicies[:simplex_size] ]
Rq = [self.q[i] for i in indicies[:simplex_size] ]
r_mesh = grid(R, Rq)
# and some extra points
S = [self.points[i] for i in indicies[simplex_size:] ]
Sq = [self.q[i] for i in indicies[simplex_size:] ]
s_mesh = grid(S, Sq)
return (r_mesh, s_mesh)
def run_baker(self, X):
(R, S) = self.get_simplex_and_nearest_points(X)
return run_baker(X, R, S)
def construct_connectivity(self):
"""
a call to this method prepares the internal connectivity structure.