2010-05-05 22:03:12 -07:00
|
|
|
#!/usr/bin/env python
|
2010-01-30 11:15:00 -08:00
|
|
|
|
|
|
|
import sys
|
|
|
|
from optparse import OptionParser
|
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
|
2011-03-24 14:51:53 -07:00
|
|
|
from interp.tools import rms, baker_exact_2D as exact_func
|
2010-10-23 16:06:11 -07:00
|
|
|
from interp.grid.DD import random_grid, rect_grid
|
2010-01-31 19:47:03 -08:00
|
|
|
|
|
|
|
|
|
|
|
def get_mesh(source, destination, use_structured_grid = False):
|
|
|
|
mesh_source = None
|
|
|
|
mesh_dest = None
|
|
|
|
if use_structured_grid:
|
2010-03-20 16:10:02 -07:00
|
|
|
mesh_source = rect_grid(source, source)
|
|
|
|
mesh_dest = rect_grid(destination, destination)
|
2010-01-31 19:47:03 -08:00
|
|
|
else:
|
2010-03-20 16:10:02 -07:00
|
|
|
mesh_source = random_grid(source)
|
|
|
|
mesh_dest = random_grid(destination)
|
2010-01-31 19:47:03 -08:00
|
|
|
|
|
|
|
if not (mesh_dest and mesh_source):
|
|
|
|
raise smberror('problem creating mesh objects')
|
|
|
|
else:
|
|
|
|
return mesh_source, mesh_dest
|
2010-01-30 11:15:00 -08:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
parser = OptionParser()
|
2011-03-24 15:08:01 -07:00
|
|
|
|
2010-01-31 19:47:03 -08:00
|
|
|
parser.add_option("-o",
|
2011-03-24 15:08:01 -07:00
|
|
|
"--order",
|
|
|
|
dest="order",
|
|
|
|
type='int',
|
|
|
|
default = 3,
|
|
|
|
help = "how many extra verts (%default)")
|
2010-01-31 19:47:03 -08:00
|
|
|
|
|
|
|
parser.add_option("-e",
|
2011-03-24 14:51:53 -07:00
|
|
|
"--extra-verts",
|
2010-01-31 19:47:03 -08:00
|
|
|
dest="extra",
|
|
|
|
type='int',
|
|
|
|
default = 3,
|
2011-03-24 14:51:53 -07:00
|
|
|
help = "how many extra verts (%default)")
|
2010-01-30 11:15:00 -08:00
|
|
|
|
2010-01-31 19:47:03 -08:00
|
|
|
parser.add_option("-s",
|
|
|
|
"--source-total",
|
|
|
|
dest="source_total",
|
|
|
|
type='int',
|
|
|
|
default = 100,
|
2011-03-24 14:51:53 -07:00
|
|
|
help = "total number of source verts for random, resolution for structured (%default)")
|
2010-01-30 11:15:00 -08:00
|
|
|
|
2010-01-31 19:47:03 -08:00
|
|
|
parser.add_option("-d",
|
|
|
|
"--destination-total",
|
|
|
|
dest="destination_total",
|
|
|
|
type='int',
|
|
|
|
default = 100,
|
2011-03-24 14:51:53 -07:00
|
|
|
help = "total number of destination verts, resolution for structured (%default)")
|
2010-01-31 19:47:03 -08:00
|
|
|
|
|
|
|
parser.add_option("-r",
|
|
|
|
"--structured",
|
|
|
|
action = 'store_true',
|
|
|
|
default = False,
|
2010-03-18 22:18:59 -07:00
|
|
|
help = "use a structured grid instead of random point cloud (%default)")
|
2010-01-31 19:47:03 -08:00
|
|
|
|
|
|
|
parser.add_option("-v",
|
|
|
|
"--verbose",
|
|
|
|
action = 'store_true',
|
|
|
|
default = False,
|
2010-03-18 22:18:59 -07:00
|
|
|
help = "verbosity (%default)")
|
2010-01-30 11:15:00 -08:00
|
|
|
|
|
|
|
(options, args) = parser.parse_args()
|
2010-01-31 19:47:03 -08:00
|
|
|
|
|
|
|
|
2010-02-20 12:18:24 -08:00
|
|
|
(mesh_source, mesh_dest) = get_mesh(options.source_total, options.destination_total, options.structured)
|
2010-01-30 11:15:00 -08:00
|
|
|
|
|
|
|
|
|
|
|
errors = []
|
|
|
|
success = 0
|
2010-01-31 19:47:03 -08:00
|
|
|
|
2010-10-23 16:06:11 -07:00
|
|
|
for X in mesh_dest.verts:
|
2010-01-31 19:47:03 -08:00
|
|
|
|
2011-03-24 15:08:01 -07:00
|
|
|
answer = mesh_source.run_baker(X, order = options.order, extra_points = options.extra)
|
2010-01-31 19:47:03 -08:00
|
|
|
|
2011-03-24 14:51:53 -07:00
|
|
|
if answer['abc'] == None:
|
2011-03-24 15:08:01 -07:00
|
|
|
print "None"
|
2010-01-31 20:15:47 -08:00
|
|
|
errors.append(0)
|
|
|
|
continue
|
|
|
|
|
2010-03-20 16:10:02 -07:00
|
|
|
exact = exact_func(X)
|
2010-02-09 23:20:06 -08:00
|
|
|
if np.abs(exact - answer['final']) <= np.abs(exact - answer['qlin']):
|
2010-01-30 11:15:00 -08:00
|
|
|
success += 1
|
|
|
|
|
|
|
|
if options.verbose:
|
2010-01-31 19:47:03 -08:00
|
|
|
print "current point : %s" % X
|
2010-01-30 11:15:00 -08:00
|
|
|
print "exact : %0.4f" % exact
|
2010-02-20 12:18:24 -08:00
|
|
|
print "qlin : %0.4f" % answer['qlin']
|
2010-01-31 19:47:03 -08:00
|
|
|
print "q_final : %0.4f" % answer['final']
|
2011-03-24 15:08:01 -07:00
|
|
|
print "error w/o : %1.4f" % (exact - answer['qlin'],)
|
|
|
|
print "error w/ : %0.4f" % (exact - answer['final'],)
|
|
|
|
print
|
2010-01-31 19:47:03 -08:00
|
|
|
cur_error = np.abs(answer['final'] - exact)
|
2010-01-30 11:15:00 -08:00
|
|
|
errors.append(cur_error)
|
|
|
|
|
|
|
|
print rms(errors)
|
2011-03-24 14:51:53 -07:00
|
|
|
print >>sys.stderr, "%s of %s won" % (success, len(mesh_dest.verts))
|