more refactoring

This commit is contained in:
Stephen McQuay 2010-10-23 17:06:57 -06:00
parent 7d32f4391f
commit fe1564881a
3 changed files with 33 additions and 33 deletions

View File

@ -3,7 +3,7 @@ import sys
import numpy as np import numpy as np
import itertools import itertools
from interp.tools import log, smberror from interp.tools import log
def get_phis(X, R): def get_phis(X, R):
""" """
@ -32,7 +32,7 @@ def get_phis(X, R):
except np.linalg.LinAlgError as e: except np.linalg.LinAlgError as e:
msg = "calculation of phis yielded a linearly dependant system (%s)" % e msg = "calculation of phis yielded a linearly dependant system (%s)" % e
log.error(msg) log.error(msg)
raise smberror(msg) raise Exception(msg)
phi = np.dot(np.linalg.pinv(A), b) phi = np.dot(np.linalg.pinv(A), b)
return phi return phi
@ -256,10 +256,10 @@ def run_baker(X, R, S, order=2):
if order == 1: if order == 1:
answer['qlin'] = qlin answer['qlin'] = qlin
return answer return answer
elif order in (2,3): elif order in (2,3,4):
error_term, abc = get_error_sauron(phi, R, S, order) error_term, abc = get_error_sauron(phi, R, S, order)
else: else:
raise smberror('unsupported order for baker method') raise Exception('unsupported order for baker method')
q_final = qlin + error_term q_final = qlin + error_term

View File

@ -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 import numpy as np
class grid(basegrid): class grid(basegrid):
def __init__(self, points, q): def __init__(self, verts, q):
basegrid.__init__(self, points, q) basegrid.__init__(self, verts, q)
def for_qhull_generator(self): def for_qhull_generator(self):
""" """
@ -15,9 +15,9 @@ class grid(basegrid):
""" """
yield '2'; 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]) yield "%f %f" % (p[0], p[1])
def for_qhull(self): def for_qhull(self):
@ -25,8 +25,8 @@ class grid(basegrid):
this returns a single string that should be fed into qdelaunay this returns a single string that should be fed into qdelaunay
""" """
r = '2\n' r = '2\n'
r += '%d\n' % len(self.points) r += '%d\n' % len(self.verts)
for p in self.points: for p in self.verts:
r += "%f %f\n" % (p[0], p[1]) r += "%f %f\n" % (p[0], p[1])
return r return r
@ -43,50 +43,50 @@ class rect_grid(grid):
ydel = yspan / float(yres - 1) ydel = yspan / float(yres - 1)
points = [] verts = []
q = [] q = []
for x in xrange(xres): for x in xrange(xres):
cur_x = xmin + (x * xdel) cur_x = xmin + (x * xdel)
for y in xrange(yres): for y in xrange(yres):
cur_y = ymin + (y * ydel) 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))) q.append(exact_func((cur_x, cur_y)))
grid.__init__(self, points, q) grid.__init__(self, verts, q)
self.construct_connectivity() self.construct_connectivity()
class random_grid(rect_grid): class random_grid(rect_grid):
def __init__(self, num_points = 10): def __init__(self, num_verts = 10):
smblog.debug("number of points: %d" % num_points) log.debug("number of verts: %d" % num_verts)
points = [] verts = []
q = [] q = []
r = np.random r = np.random
appx_side_res = int(np.sqrt(num_points)) appx_side_res = int(np.sqrt(num_verts))
smblog.debug("appx_side_res: %d" % appx_side_res) log.debug("appx_side_res: %d" % appx_side_res)
delta = 1.0 / float(appx_side_res) delta = 1.0 / float(appx_side_res)
for x in xrange(appx_side_res + 1): for x in xrange(appx_side_res + 1):
cur_x = x * delta cur_x = x * delta
for cur_y in (0, 1): for cur_y in (0, 1):
new_point = [cur_x, cur_y] new_point = [cur_x, cur_y]
points.append(new_point) verts.append(new_point)
q.append(exact_func(new_point)) q.append(exact_func(new_point))
for y in xrange(appx_side_res + 1): for y in xrange(appx_side_res + 1):
cur_y = y * delta cur_y = y * delta
for cur_x in (0, 1): for cur_x in (0, 1):
new_point = [cur_x, cur_y] new_point = [cur_x, cur_y]
points.append(new_point) verts.append(new_point)
q.append(exact_func(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_x = r.rand()
cur_y = 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) ) ) 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) self.q = np.array(self.q)

View File

@ -8,11 +8,11 @@ def contains(X, R):
tests if X (point) is in R (a simplex, tests if X (point) is in R (a simplex,
represented by a list of n-degree coordinates) 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) phis = get_phis(X, R)
elif len(X) == 3: elif len(R) == 4:
phis = get_phis_3D(X, R) phis = get_phis_3D(X, R)
r = True r = True
@ -29,7 +29,7 @@ class face(object):
def add_vert(self, v): 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) self.verts.append(v)
@ -42,15 +42,15 @@ class face(object):
def contains(self, X, G): def contains(self, X, G):
""" """
X = point of interest X = point of interest
G = corrensponding grid object (G.points) G = corrensponding grid object (G.verts)
because of the way i'm storing things, because of the way i'm storing things,
a face simply stores indicies, and so one a face simply stores indicies, and so one
must pass in a reference to the grid object must pass in a reference to the grid object
containing real points. containing real verts.
this simply calls grid.simplex.contains 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): def __str__(self):
neighbors = [str(i.name) for i in self.neighbors] neighbors = [str(i.name) for i in self.neighbors]