MAJOR: updated the baker method. it's more generic, and should allow me to 3D-ifiy it more simply. a ton of other things

This commit is contained in:
Stephen Mardson McQuay
2010-01-31 20:47:03 -07:00
parent 98b13fb8c5
commit 80720c45fe
6 changed files with 223 additions and 175 deletions
+88 -19
View File
@@ -7,24 +7,77 @@ import numpy as np
import scipy.spatial
import baker
from tools import rms, get_mesh, exact_func
from tools import rms, exact_func
import grid
def get_mesh(source, destination, use_structured_grid = False):
mesh_source = None
mesh_dest = None
if use_structured_grid:
mesh_source = grid.simple_rect_grid(source, source)
mesh_dest = grid.simple_rect_grid(destination, destination)
else:
mesh_source = grid.simple_random_grid(source)
mesh_dest = grid.simple_random_grid(destination)
if not (mesh_dest and mesh_source):
raise smberror('problem creating mesh objects')
else:
return mesh_source, mesh_dest
if __name__ == '__main__':
parser = OptionParser()
parser.add_option("-o", "--output-file", dest="output", type='str', default = '/tmp/for_qhull.txt', help = "qhull output file")
parser.add_option("-e", "--extra-points", dest="extra", type='int', default = 3, help = "how many extra points")
parser.add_option("-o",
"--output-file",
dest="output",
type='str',
default = '/tmp/for_qhull.txt',
help = "qhull output file")
parser.add_option("-s", "--source-total", dest="source_total", type='int', default = 100, help = "total number of source points for random, resolution for structured")
parser.add_option("-d", "--destination-total", dest="destination_total", type='int', default = 100, help = "total number of destination points, resolution for structured")
parser.add_option("-e",
"--extra-points",
dest="extra",
type='int',
default = 3,
help = "how many extra points")
parser.add_option("-r", "--structured", action = 'store_true', default = False, help = "use a structured grid instead of random point cloud")
parser.add_option("-v", "--verbose", action = 'store_true', default = False, help = "verbosity")
parser.add_option("-s",
"--source-total",
dest="source_total",
type='int',
default = 100,
help = "total number of source points for random,\
resolution for structured")
parser.add_option("-d",
"--destination-total",
dest="destination_total",
type='int',
default = 100,
help = "total number of destination points,\
resolution for structured")
parser.add_option("-r",
"--structured",
action = 'store_true',
default = False,
help = "use a structured grid instead of random point cloud")
parser.add_option("-v",
"--verbose",
action = 'store_true',
default = False,
help = "verbosity")
(options, args) = parser.parse_args()
print >> sys.stderr, options
print >> sys.stderr, "options: %s, args: %s" % (options, args)
mesh_source, mesh_dest = get_mesh(options.source_total, options.destination_total, options.structured)
(mesh_source, mesh_dest) = get_mesh(options.source_total, options.destination_total, options.structured)
tree = scipy.spatial.KDTree(mesh_source.points)
open(options.output, 'w').write(mesh_source.for_qhull())
@@ -32,20 +85,36 @@ if __name__ == '__main__':
errors = []
success = 0
for x in mesh_dest.points:
lin, error, final = baker.run_baker(x, mesh_source, tree, options.extra, options.verbose)
exact = exact_func(x[0], x[1])
if np.abs(exact - final) < np.abs(exact - lin):
for X in mesh_dest.points:
(dist, indicies) = tree.query(X, 3 + options.extra)
# get the containing simplex
R = [mesh_source.points[i] for i in indicies[:3] ]
Rq = [mesh_source.q[i] for i in indicies[:3] ]
r_mesh = grid.grid(R, Rq)
# and some extra points
S = [mesh_source.points[i] for i in indicies[3:] ]
Sq = [mesh_source.q[i] for i in indicies[3:] ]
s_mesh = grid.grid(S, Sq)
answer = baker.run_baker(X, r_mesh, s_mesh, options.extra, options.verbose)
exact = exact_func(X[0], X[1])
if np.abs(exact - answer['final']) < np.abs(exact - answer['qlin']):
success += 1
if options.verbose:
print "current point : %s" % x
print "current point : %s" % X
print "exact : %0.4f" % exact
print "qlin : %0.4f" % lin
print "q_final : %0.4f" % final
print "qlinerr : %0.4f" % (exact - lin,)
print "q_final_err : %0.4f" % (exact - final,)
cur_error = np.abs(final - exact)
print "qlin : %0.4f" % answer['lin']
print "q_final : %0.4f" % answer['final']
print "qlinerr : %1.4f" % (exact - anser['lin'],)
print "q_final_err : %0.4f" % (exact - answer['final'],)
cur_error = np.abs(answer['final'] - exact)
errors.append(cur_error)
print rms(errors)