wrapping up a night. there isn't enough consistent improvement to merit using this method. i must have a bug somewhere.
This commit is contained in:
+12
-3
@@ -1,6 +1,6 @@
|
||||
from grid import grid as basegrid
|
||||
|
||||
from baker.tools import exact_func
|
||||
from baker.tools import exact_func, smblog
|
||||
|
||||
import numpy as np
|
||||
|
||||
@@ -57,16 +57,25 @@ class rect_grid(grid):
|
||||
|
||||
class random_grid(rect_grid):
|
||||
def __init__(self, num_points = 10):
|
||||
smblog.debug("number of points: %d" % num_points)
|
||||
points = []
|
||||
q = []
|
||||
|
||||
r = np.random
|
||||
appx_side_res = int(np.sqrt(num_points))
|
||||
smblog.debug("appx_side_res: %d" % appx_side_res)
|
||||
delta = 1.0 / float(appx_side_res)
|
||||
|
||||
for x in xrange(appx_side_res):
|
||||
cur_x = x * delta
|
||||
for y in xrange(appx_side_res):
|
||||
cur_y = y * delta
|
||||
for cur_y in (0, 1):
|
||||
new_point = [cur_x, cur_y]
|
||||
points.append(new_point)
|
||||
q.append(exact_func(new_point))
|
||||
|
||||
for y in xrange(appx_side_res):
|
||||
cur_y = y * delta
|
||||
for cur_x in (0, 1):
|
||||
new_point = [cur_x, cur_y]
|
||||
points.append(new_point)
|
||||
q.append(exact_func(new_point))
|
||||
|
||||
+15
-19
@@ -6,7 +6,7 @@ import numpy as np
|
||||
import scipy.spatial
|
||||
|
||||
from baker import run_baker
|
||||
from baker.tools import exact_func, smberror, logging
|
||||
from baker.tools import exact_func, smberror, smblog
|
||||
from simplex import face, contains
|
||||
from smcqdelaunay import *
|
||||
|
||||
@@ -42,7 +42,6 @@ class grid(object):
|
||||
self.tree = scipy.spatial.KDTree(self.points)
|
||||
self.faces = {}
|
||||
self.facets_for_point = defaultdict(list)
|
||||
self.counter = 0
|
||||
|
||||
def create_mesh(self, indicies):
|
||||
p = [self.points[i] for i in indicies]
|
||||
@@ -51,19 +50,17 @@ class grid(object):
|
||||
|
||||
def get_containing_simplex(self, X):
|
||||
if not self.faces:
|
||||
logging.debug('get_containing_simplex: setting up connectivity')
|
||||
smblog.debug('setting up connectivity')
|
||||
self.construct_connectivity()
|
||||
|
||||
# get closest point
|
||||
(dist, indicies) = self.tree.query(X, 2)
|
||||
closest_point = indicies[0]
|
||||
|
||||
logging.debug('counter: %d' % self.counter)
|
||||
self.counter += 1
|
||||
logging.debug('X: %s' % X)
|
||||
logging.debug('point index: %d' % closest_point)
|
||||
logging.debug('actual point %s' % self.points[closest_point])
|
||||
logging.debug('distance = %0.4f' % dist[0])
|
||||
smblog.debug('X: %s' % X)
|
||||
smblog.debug('point index: %d' % closest_point)
|
||||
smblog.debug('actual point %s' % self.points[closest_point])
|
||||
smblog.debug('distance = %0.4f' % dist[0])
|
||||
|
||||
simplex = None
|
||||
checked_facets = []
|
||||
@@ -71,10 +68,9 @@ class grid(object):
|
||||
|
||||
attempts = 0
|
||||
while not simplex:
|
||||
logging.debug('attempt: %d' % attempts)
|
||||
attempts += 1
|
||||
if attempts > 10:
|
||||
raise smberror("probably recursing to many times")
|
||||
# if attempts > 20:
|
||||
# raise smberror("probably recursing to many times")
|
||||
cur_facet = facets_to_check.pop()
|
||||
checked_facets.append(cur_facet)
|
||||
facets_to_check.extend([i for i in cur_facet.neighbors if i not in checked_facets])
|
||||
@@ -87,7 +83,7 @@ class grid(object):
|
||||
|
||||
R = self.create_mesh(simplex.verts)
|
||||
|
||||
logging.debug('this must be R: %s' % R)
|
||||
smblog.debug('total attempts before finding simplex: %d' % attempts)
|
||||
return R
|
||||
|
||||
|
||||
@@ -140,7 +136,7 @@ class grid(object):
|
||||
if not simplex:
|
||||
raise AssertionError('no containing simplex found')
|
||||
|
||||
R = get_containing_simplex(X)# self.create_mesh(simplex.verts)
|
||||
R = self.get_containing_simplex(X)# self.create_mesh(simplex.verts)
|
||||
|
||||
|
||||
s = []
|
||||
@@ -150,18 +146,18 @@ class grid(object):
|
||||
|
||||
return R, S
|
||||
|
||||
def run_baker(self, X):
|
||||
def run_baker(self, X, extra_points = 3, order = 2):
|
||||
answer = None
|
||||
|
||||
try:
|
||||
(R, S) = self.get_simplex_and_nearest_points(X)
|
||||
if not contains(X, R.points):
|
||||
raise smberror("run_baker with get_simplex_and_nearest_points returned non-containing simplex")
|
||||
answer = run_baker(X, R, S)
|
||||
answer = run_baker(X, R, S, order)
|
||||
except smberror, e:
|
||||
print >> sys.stderr, "caught error: %s, trying with connectivity-based mesh" % e
|
||||
smblog.error("caught error: %s, trying with connectivity-based mesh" % e)
|
||||
(R, S) = self.get_points_conn(X)
|
||||
answer = run_baker(X, R, S)
|
||||
answer = run_baker(X, R, S, order)
|
||||
|
||||
return answer
|
||||
|
||||
@@ -173,7 +169,7 @@ class grid(object):
|
||||
|
||||
this is part of the __init__ for a rect_grid, but can be called from any grid object
|
||||
"""
|
||||
logging.debug('calling construct_connectivity')
|
||||
smblog.debug()
|
||||
qdelaunay_string = get_qdelaunay_dump_str(self)
|
||||
facet_to_facets = []
|
||||
for matcher in grid.facet_re.finditer(qdelaunay_string):
|
||||
|
||||
+9
-2
@@ -1,4 +1,5 @@
|
||||
from baker import get_phis
|
||||
from baker import get_phis, get_phis_3D
|
||||
from baker.tools import smblog
|
||||
|
||||
TOL = 1e-8
|
||||
|
||||
@@ -6,8 +7,14 @@ 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
|
||||
"""
|
||||
phis = get_phis(X, R)
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user