more refactoring
This commit is contained in:
parent
7d32f4391f
commit
fe1564881a
@ -3,7 +3,7 @@ import sys
|
||||
import numpy as np
|
||||
|
||||
import itertools
|
||||
from interp.tools import log, smberror
|
||||
from interp.tools import log
|
||||
|
||||
def get_phis(X, R):
|
||||
"""
|
||||
@ -32,7 +32,7 @@ def get_phis(X, R):
|
||||
except np.linalg.LinAlgError as e:
|
||||
msg = "calculation of phis yielded a linearly dependant system (%s)" % e
|
||||
log.error(msg)
|
||||
raise smberror(msg)
|
||||
raise Exception(msg)
|
||||
phi = np.dot(np.linalg.pinv(A), b)
|
||||
|
||||
return phi
|
||||
@ -256,10 +256,10 @@ def run_baker(X, R, S, order=2):
|
||||
if order == 1:
|
||||
answer['qlin'] = qlin
|
||||
return answer
|
||||
elif order in (2,3):
|
||||
elif order in (2,3,4):
|
||||
error_term, abc = get_error_sauron(phi, R, S, order)
|
||||
else:
|
||||
raise smberror('unsupported order for baker method')
|
||||
raise Exception('unsupported order for baker method')
|
||||
|
||||
q_final = qlin + error_term
|
||||
|
||||
|
@ -1,13 +1,13 @@
|
||||
from grid import grid as basegrid
|
||||
from interp.grid import grid as basegrid
|
||||
|
||||
from baker.tools import exact_func, smblog
|
||||
from interp.tools import exact_func, log
|
||||
|
||||
import numpy as np
|
||||
|
||||
|
||||
class grid(basegrid):
|
||||
def __init__(self, points, q):
|
||||
basegrid.__init__(self, points, q)
|
||||
def __init__(self, verts, q):
|
||||
basegrid.__init__(self, verts, q)
|
||||
|
||||
def for_qhull_generator(self):
|
||||
"""
|
||||
@ -15,9 +15,9 @@ class grid(basegrid):
|
||||
"""
|
||||
|
||||
yield '2';
|
||||
yield '%d' % len(self.points)
|
||||
yield '%d' % len(self.verts)
|
||||
|
||||
for p in self.points:
|
||||
for p in self.verts:
|
||||
yield "%f %f" % (p[0], p[1])
|
||||
|
||||
def for_qhull(self):
|
||||
@ -25,8 +25,8 @@ class grid(basegrid):
|
||||
this returns a single string that should be fed into qdelaunay
|
||||
"""
|
||||
r = '2\n'
|
||||
r += '%d\n' % len(self.points)
|
||||
for p in self.points:
|
||||
r += '%d\n' % len(self.verts)
|
||||
for p in self.verts:
|
||||
r += "%f %f\n" % (p[0], p[1])
|
||||
return r
|
||||
|
||||
@ -43,50 +43,50 @@ class rect_grid(grid):
|
||||
ydel = yspan / float(yres - 1)
|
||||
|
||||
|
||||
points = []
|
||||
verts = []
|
||||
q = []
|
||||
for x in xrange(xres):
|
||||
cur_x = xmin + (x * xdel)
|
||||
for y in xrange(yres):
|
||||
cur_y = ymin + (y * ydel)
|
||||
points.append([cur_x, cur_y])
|
||||
verts.append([cur_x, cur_y])
|
||||
q.append(exact_func((cur_x, cur_y)))
|
||||
grid.__init__(self, points, q)
|
||||
grid.__init__(self, verts, q)
|
||||
self.construct_connectivity()
|
||||
|
||||
|
||||
class random_grid(rect_grid):
|
||||
def __init__(self, num_points = 10):
|
||||
smblog.debug("number of points: %d" % num_points)
|
||||
points = []
|
||||
def __init__(self, num_verts = 10):
|
||||
log.debug("number of verts: %d" % num_verts)
|
||||
verts = []
|
||||
q = []
|
||||
|
||||
r = np.random
|
||||
appx_side_res = int(np.sqrt(num_points))
|
||||
smblog.debug("appx_side_res: %d" % appx_side_res)
|
||||
appx_side_res = int(np.sqrt(num_verts))
|
||||
log.debug("appx_side_res: %d" % appx_side_res)
|
||||
delta = 1.0 / float(appx_side_res)
|
||||
|
||||
for x in xrange(appx_side_res + 1):
|
||||
cur_x = x * delta
|
||||
for cur_y in (0, 1):
|
||||
new_point = [cur_x, cur_y]
|
||||
points.append(new_point)
|
||||
verts.append(new_point)
|
||||
q.append(exact_func(new_point))
|
||||
|
||||
for y in xrange(appx_side_res + 1):
|
||||
cur_y = y * delta
|
||||
for cur_x in (0, 1):
|
||||
new_point = [cur_x, cur_y]
|
||||
points.append(new_point)
|
||||
verts.append(new_point)
|
||||
q.append(exact_func(new_point))
|
||||
|
||||
for i in xrange(num_points):
|
||||
for i in xrange(num_verts):
|
||||
cur_x = r.rand()
|
||||
cur_y = r.rand()
|
||||
|
||||
points.append([cur_x, cur_y])
|
||||
verts.append([cur_x, cur_y])
|
||||
q.append( exact_func( (cur_x, cur_y) ) )
|
||||
grid.__init__(self, points, q)
|
||||
grid.__init__(self, verts, q)
|
||||
|
||||
self.points = np.array(self.points)
|
||||
self.verts = np.array(self.verts)
|
||||
self.q = np.array(self.q)
|
||||
|
@ -8,11 +8,11 @@ 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
|
||||
it now correctly checks for 2/3-D verts
|
||||
"""
|
||||
if len(X) == 2:
|
||||
if len(R) == 3:
|
||||
phis = get_phis(X, R)
|
||||
elif len(X) == 3:
|
||||
elif len(R) == 4:
|
||||
phis = get_phis_3D(X, R)
|
||||
|
||||
r = True
|
||||
@ -29,7 +29,7 @@ class face(object):
|
||||
|
||||
def add_vert(self, v):
|
||||
"""
|
||||
v should be an index into grid.points
|
||||
v should be an index into grid.verts
|
||||
"""
|
||||
self.verts.append(v)
|
||||
|
||||
@ -42,15 +42,15 @@ class face(object):
|
||||
def contains(self, X, G):
|
||||
"""
|
||||
X = point of interest
|
||||
G = corrensponding grid object (G.points)
|
||||
G = corrensponding grid object (G.verts)
|
||||
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.
|
||||
containing real verts.
|
||||
|
||||
this simply calls grid.simplex.contains
|
||||
"""
|
||||
return contains(X, [G.points[i] for i in self.verts])
|
||||
return contains(X, [G.verts[i] for i in self.verts])
|
||||
|
||||
def __str__(self):
|
||||
neighbors = [str(i.name) for i in self.neighbors]
|
||||
|
Loading…
Reference in New Issue
Block a user