polish for inclusion into thesis
This commit is contained in:
parent
14fef76b2b
commit
c682b12bea
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import interp.bootstrap
|
|
||||||
from interp.cluster import QueueManager, get_qs
|
from interp.cluster import QueueManager, get_qs
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
|
@ -4,21 +4,19 @@ import sys
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import shelve
|
import shelve
|
||||||
from progressbar import *
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
import numpy as np
|
|
||||||
|
|
||||||
import interp.bootstrap
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
log = logging.getLogger("interp")
|
log = logging.getLogger("interp")
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
from interp.cluster import QueueManager, get_qs
|
from interp.cluster import QueueManager, get_qs
|
||||||
|
|
||||||
|
from progressbar import *
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
parser = OptionParser(usage = "usage: %s [options] <server> <interp count>")
|
parser = OptionParser(usage = "usage: %s [options] <server> <interp count>")
|
||||||
|
|
||||||
|
@ -11,7 +11,6 @@ import datetime
|
|||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
import interp.bootstrap
|
|
||||||
from interp.grid.gmsh import ggrid
|
from interp.grid.gmsh import ggrid
|
||||||
from interp.tools import baker_exact_3D as exact
|
from interp.tools import baker_exact_3D as exact
|
||||||
|
|
||||||
|
@ -10,8 +10,6 @@ import pickle
|
|||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
import interp.bootstrap
|
|
||||||
|
|
||||||
from interp.cluster import QueueManager, get_qs
|
from interp.cluster import QueueManager, get_qs
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -11,37 +11,35 @@ log = logging.getLogger('interp')
|
|||||||
|
|
||||||
def get_phis(X, R):
|
def get_phis(X, R):
|
||||||
"""
|
"""
|
||||||
The get_phis function is used to get barycentric coordonites for a point on
|
The get_phis function is used to get barycentric coordonites for a
|
||||||
a triangle or tetrahedron:
|
point on a triangle or tetrahedron. This is equation (*\ref{eq:qlinarea}*)
|
||||||
|
|
||||||
|
|
||||||
in 2D:
|
in 2D:
|
||||||
|
|
||||||
X -- the destination point (2D)
|
X - the destination point (2D)
|
||||||
X = [0,0]
|
X = [0,0]
|
||||||
r -- the three points that make up the containing triangular simplex (2D)
|
R - the three points that make up the 2-D triangular simplex
|
||||||
r = [[-1, -1], [0, 2], [1, -1]]
|
R = [[-1, -1], [0, 2], [1, -1]]
|
||||||
|
|
||||||
this will return [0.333, 0.333, 0.333]
|
this will return [0.333, 0.333, 0.333]
|
||||||
|
|
||||||
|
|
||||||
in 3D:
|
in 3D:
|
||||||
|
|
||||||
X -- the destination point (3D)
|
X - the destination point (3D)
|
||||||
X = [0,0,0]
|
X = [0,0,0]
|
||||||
R -- the four points that make up the containing simplex, tetrahedron (3D)
|
R - the four points that make up the 3-D simplex (tetrahedron)
|
||||||
R = [
|
R = [
|
||||||
[0.0, 0.0, 1.0],
|
[ 0.0000, 0.0000, 1.0000],
|
||||||
[0.94280904333606508, 0.0, -0.3333333283722672],
|
[ 0.9428, 0.0000, -0.3333],
|
||||||
[-0.47140452166803232, 0.81649658244673617, -0.3333333283722672],
|
[-0.4714, 0.8165, -0.3333],
|
||||||
[-0.47140452166803298, -0.81649658244673584, -0.3333333283722672],
|
[-0.4714, -0.8165, -0.3333],
|
||||||
]
|
]
|
||||||
|
|
||||||
this will return [0.25, 0.25, 0.25, 0.25]
|
this will return [0.25, 0.25, 0.25, 0.25]
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# baker: eq 7
|
# equations (*\ref{eq:lin3d}*) and (*\ref{eq:lin2d}*)
|
||||||
# TODO: perhaps also test len(R[0]) .. ?
|
|
||||||
if len(X) == 2:
|
if len(X) == 2:
|
||||||
log.debug("running 2D")
|
log.debug("running 2D")
|
||||||
A = np.array([
|
A = np.array([
|
||||||
@ -85,7 +83,7 @@ def qlinear(X, R):
|
|||||||
"""
|
"""
|
||||||
this calculates the linear portion of q from R to X
|
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
|
X = destination point
|
||||||
R = a inter.grid object; must have R.points and R.q
|
R = a inter.grid object; must have R.points and R.q
|
||||||
@ -100,9 +98,12 @@ def qlinear(X, R):
|
|||||||
return phis, qlin
|
return phis, qlin
|
||||||
|
|
||||||
def get_error(phi, R, S, order = 2):
|
def get_error(phi, R, S, order = 2):
|
||||||
#TODO: change the equation names in the comments
|
"""
|
||||||
B = [] # baker eq 9
|
Calculate the error approximation terms, returning the unknowns
|
||||||
w = [] # baker eq 11
|
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)
|
cur_pattern = pattern(len(phi), order)
|
||||||
log.info("pattern: %s" % cur_pattern)
|
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
|
This is the main function to call to get an interpolation to X from the
|
||||||
input meshes
|
input meshes
|
||||||
|
|
||||||
X -- the destination point (2D)
|
X -- the destination point
|
||||||
X = [0,0]
|
|
||||||
|
|
||||||
R = Simplex
|
R = Simplex
|
||||||
S = extra points
|
S = extra points
|
||||||
@ -190,9 +190,7 @@ def run_baker(X, R, S, order=2):
|
|||||||
|
|
||||||
def memoize(f):
|
def memoize(f):
|
||||||
"""
|
"""
|
||||||
for more information on what I'm doing here,
|
for more information on what I'm doing here, please read:
|
||||||
please read:
|
|
||||||
|
|
||||||
http://en.wikipedia.org/wiki/Memoize
|
http://en.wikipedia.org/wiki/Memoize
|
||||||
"""
|
"""
|
||||||
cache = {}
|
cache = {}
|
||||||
|
@ -20,8 +20,9 @@ class grid(object):
|
|||||||
"""
|
"""
|
||||||
verts = array of arrays (if passed in, will convert to numpy.array)
|
verts = array of arrays (if passed in, will convert to numpy.array)
|
||||||
[
|
[
|
||||||
[x0,y0],
|
[x0,y0 <, z0>],
|
||||||
[x1,y1], ...
|
[x1,y1 <, z1>],
|
||||||
|
...
|
||||||
]
|
]
|
||||||
|
|
||||||
q = array (1D) of physical values
|
q = array (1D) of physical values
|
||||||
@ -97,10 +98,9 @@ class grid(object):
|
|||||||
"""
|
"""
|
||||||
this returns two grid objects: R and S.
|
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
|
S : some verts from all points that are not the simplex
|
||||||
simplex
|
|
||||||
"""
|
"""
|
||||||
simplex_size = self.dim + 1
|
simplex_size = self.dim + 1
|
||||||
log.debug("extra verts: %d" % extra_points)
|
log.debug("extra verts: %d" % extra_points)
|
||||||
@ -228,8 +228,9 @@ class cell(object):
|
|||||||
X = point of interest
|
X = point of interest
|
||||||
G = corrensponding grid object (G.verts)
|
G = corrensponding grid object (G.verts)
|
||||||
|
|
||||||
because of the way i'm storing things, a cell simply stores indicies, and
|
because of the way i'm storing things, a cell simply stores indicies,
|
||||||
so one must pass in a reference to the grid object containing real verts.
|
and so one must pass in a reference to the grid object containing real
|
||||||
|
verts.
|
||||||
|
|
||||||
this simply calls grid.simplex.contains
|
this simply calls grid.simplex.contains
|
||||||
"""
|
"""
|
||||||
@ -255,10 +256,6 @@ def contains(X, R):
|
|||||||
tests if X (point) is in R
|
tests if X (point) is in R
|
||||||
|
|
||||||
R is a simplex, represented by a list of n-degree coordinates
|
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)
|
phis = get_phis(X, R)
|
||||||
|
|
||||||
|
@ -51,9 +51,6 @@ class dgrid(basegrid):
|
|||||||
def construct_connectivity(self):
|
def construct_connectivity(self):
|
||||||
"""
|
"""
|
||||||
a call to this method prepares the internal connectivity structure.
|
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')
|
log.info('start')
|
||||||
qdelaunay_string = get_qdelaunay_dump_str(self)
|
qdelaunay_string = get_qdelaunay_dump_str(self)
|
||||||
|
@ -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
|
|
@ -1,6 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
import inspect
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
@ -27,8 +26,6 @@ def baker_exact_2D(X):
|
|||||||
"""
|
"""
|
||||||
x ,y = 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)
|
answer = np.power((np.sin(x * np.pi) * np.cos(y * np.pi)), 2)
|
||||||
log.debug(answer)
|
log.debug(answer)
|
||||||
return answer
|
return answer
|
||||||
@ -83,6 +80,3 @@ def improved(qlin, err, final, exact):
|
|||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def percent_improvement(answer, exact):
|
|
||||||
return np.abs(answer['error']) / exact
|
|
||||||
|
Loading…
Reference in New Issue
Block a user