From c682b12bea72dfbbab4819d01e029050a45eea28 Mon Sep 17 00:00:00 2001 From: Stephen Mardson McQuay Date: Tue, 7 Jun 2011 22:37:12 -0600 Subject: [PATCH] polish for inclusion into thesis --- bin/iqmgr.py | 6 ++--- bin/master.py | 12 ++++------ bin/minion.py | 1 - bin/resolution.2D.py | 4 ++-- bin/shepherd.py | 2 -- interp/baker/__init__.py | 52 +++++++++++++++++++--------------------- interp/grid/__init__.py | 19 +++++++-------- interp/grid/delaunay.py | 3 --- interp/grid/qhull.py | 14 ----------- interp/tools.py | 6 ----- 10 files changed, 43 insertions(+), 76 deletions(-) delete mode 100644 interp/grid/qhull.py diff --git a/bin/iqmgr.py b/bin/iqmgr.py index 87a49da..3083983 100755 --- a/bin/iqmgr.py +++ b/bin/iqmgr.py @@ -2,9 +2,9 @@ import sys import time -import interp.bootstrap -from interp.cluster import QueueManager, get_qs -from optparse import OptionParser + +from interp.cluster import QueueManager, get_qs +from optparse import OptionParser if __name__ == '__main__': parser = OptionParser(usage = "usage: %s [options] ") diff --git a/bin/master.py b/bin/master.py index 45a2666..c98aeb4 100644 --- a/bin/master.py +++ b/bin/master.py @@ -4,20 +4,18 @@ import sys import os import time - import shelve -from progressbar import * from collections import defaultdict from optparse import OptionParser -import numpy as np - -import interp.bootstrap - import logging log = logging.getLogger("interp") -from interp.cluster import QueueManager, get_qs +import numpy as np + +from interp.cluster import QueueManager, get_qs + +from progressbar import * if __name__ == '__main__': parser = OptionParser(usage = "usage: %s [options] ") diff --git a/bin/minion.py b/bin/minion.py index 78db766..f77ee54 100644 --- a/bin/minion.py +++ b/bin/minion.py @@ -11,7 +11,6 @@ import datetime import numpy as np -import interp.bootstrap from interp.grid.gmsh import ggrid from interp.tools import baker_exact_3D as exact diff --git a/bin/resolution.2D.py b/bin/resolution.2D.py index 61214f1..8597afe 100644 --- a/bin/resolution.2D.py +++ b/bin/resolution.2D.py @@ -6,8 +6,8 @@ import time from progressbar import * from interp.grid.DD import * -from interp.tools import * -from interp import bootstrap +from interp.tools import * +from interp import bootstrap EXTRA_POINTS = 64 diff --git a/bin/shepherd.py b/bin/shepherd.py index b5d36ce..3b18bb9 100644 --- a/bin/shepherd.py +++ b/bin/shepherd.py @@ -10,8 +10,6 @@ import pickle import numpy as np -import interp.bootstrap - from interp.cluster import QueueManager, get_qs if __name__ == '__main__': diff --git a/interp/baker/__init__.py b/interp/baker/__init__.py index 9de4992..0b9ab68 100644 --- a/interp/baker/__init__.py +++ b/interp/baker/__init__.py @@ -11,37 +11,35 @@ log = logging.getLogger('interp') def get_phis(X, R): """ - The get_phis function is used to get barycentric coordonites for a point on - a triangle or tetrahedron: - + The get_phis function is used to get barycentric coordonites for a + point on a triangle or tetrahedron. This is equation (*\ref{eq:qlinarea}*) in 2D: - X -- the destination point (2D) - X = [0,0] - r -- the three points that make up the containing triangular simplex (2D) - r = [[-1, -1], [0, 2], [1, -1]] + X - the destination point (2D) + X = [0,0] + R - the three points that make up the 2-D triangular simplex + R = [[-1, -1], [0, 2], [1, -1]] this will return [0.333, 0.333, 0.333] in 3D: - X -- the destination point (3D) - X = [0,0,0] - R -- the four points that make up the containing simplex, tetrahedron (3D) - R = [ - [0.0, 0.0, 1.0], - [0.94280904333606508, 0.0, -0.3333333283722672], - [-0.47140452166803232, 0.81649658244673617, -0.3333333283722672], - [-0.47140452166803298, -0.81649658244673584, -0.3333333283722672], - ] + X - the destination point (3D) + X = [0,0,0] + R - the four points that make up the 3-D simplex (tetrahedron) + R = [ + [ 0.0000, 0.0000, 1.0000], + [ 0.9428, 0.0000, -0.3333], + [-0.4714, 0.8165, -0.3333], + [-0.4714, -0.8165, -0.3333], + ] this will return [0.25, 0.25, 0.25, 0.25] """ - # baker: eq 7 - # TODO: perhaps also test len(R[0]) .. ? + # equations (*\ref{eq:lin3d}*) and (*\ref{eq:lin2d}*) if len(X) == 2: log.debug("running 2D") A = np.array([ @@ -85,7 +83,7 @@ def qlinear(X, R): """ this calculates the linear portion of q from R to X - also, this is baker eq 3 + This is equation (*\ref{eq:qlinbasis}*) X = destination point R = a inter.grid object; must have R.points and R.q @@ -100,9 +98,12 @@ def qlinear(X, R): return phis, qlin def get_error(phi, R, S, order = 2): - #TODO: change the equation names in the comments - B = [] # baker eq 9 - w = [] # baker eq 11 + """ + Calculate the error approximation terms, returning the unknowns + a,b, and c in equation (*\ref{eq:quadratic2d}*). + """ + B = [] # equation ((*\ref{eq:B2d}*) + w = [] # equation ((*\ref{eq:w}*) cur_pattern = pattern(len(phi), order) log.info("pattern: %s" % cur_pattern) @@ -150,8 +151,7 @@ def run_baker(X, R, S, order=2): 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] + X -- the destination point R = Simplex S = extra points @@ -190,9 +190,7 @@ def run_baker(X, R, S, order=2): def memoize(f): """ - for more information on what I'm doing here, - please read: - + for more information on what I'm doing here, please read: http://en.wikipedia.org/wiki/Memoize """ cache = {} diff --git a/interp/grid/__init__.py b/interp/grid/__init__.py index 3b76d9e..6a4d02e 100644 --- a/interp/grid/__init__.py +++ b/interp/grid/__init__.py @@ -20,8 +20,9 @@ class grid(object): """ verts = array of arrays (if passed in, will convert to numpy.array) [ - [x0,y0], - [x1,y1], ... + [x0,y0 <, z0>], + [x1,y1 <, z1>], + ... ] q = array (1D) of physical values @@ -97,10 +98,9 @@ class grid(object): """ this returns two grid objects: R and S. - R is a grid object that is supposedly a containing simplex around point X + R is a grid object that is a containing simplex around point X - S is S_j from baker's paper : some verts from all point that are not the - simplex + S : some verts from all points that are not the simplex """ simplex_size = self.dim + 1 log.debug("extra verts: %d" % extra_points) @@ -228,8 +228,9 @@ class cell(object): X = point of interest G = corrensponding grid object (G.verts) - because of the way i'm storing things, a cell simply stores indicies, and - so one must pass in a reference to the grid object containing real verts. + because of the way i'm storing things, a cell simply stores indicies, + and so one must pass in a reference to the grid object containing real + verts. this simply calls grid.simplex.contains """ @@ -255,10 +256,6 @@ def contains(X, R): tests if X (point) is in R R is a simplex, represented by a list of n-degree coordinates - - it now correctly checks for 2/3-D verts - - TODO: write unit test ... """ phis = get_phis(X, R) diff --git a/interp/grid/delaunay.py b/interp/grid/delaunay.py index 339a352..71fe17f 100644 --- a/interp/grid/delaunay.py +++ b/interp/grid/delaunay.py @@ -51,9 +51,6 @@ class dgrid(basegrid): def construct_connectivity(self): """ a call to this method prepares the internal connectivity structure. - - this is part of the __init__ for a interp.grid.delaunay.grid, but can be - called from any grid object """ log.info('start') qdelaunay_string = get_qdelaunay_dump_str(self) diff --git a/interp/grid/qhull.py b/interp/grid/qhull.py deleted file mode 100644 index 072d529..0000000 --- a/interp/grid/qhull.py +++ /dev/null @@ -1,14 +0,0 @@ -def parse_qhull_file(filename, verbose=False): - f = open(filename, 'r') - - if verbose: - print 'filename: ', filename - degree = int(f.readline().strip()) - print "degree:", degree - print "number of points", f.readline().strip() - - verts = [] - for p in f: - v = [float(i) for i in p.strip().split()] - verts.append(v) - return verts diff --git a/interp/tools.py b/interp/tools.py index fa91dc1..523687d 100644 --- a/interp/tools.py +++ b/interp/tools.py @@ -1,6 +1,5 @@ import os -import inspect import numpy as np import logging @@ -27,8 +26,6 @@ def baker_exact_2D(X): """ x ,y = X - # TODO: this is not baker's function!! this is: - # np.power(np.sin(x*np.pi/2.0) * np.sin(y*np.pi/2.0),2) answer = np.power((np.sin(x * np.pi) * np.cos(y * np.pi)), 2) log.debug(answer) return answer @@ -83,6 +80,3 @@ def improved(qlin, err, final, exact): return True else: return False - -def percent_improvement(answer, exact): - return np.abs(answer['error']) / exact