moved and merged the gmsh test script

--HG--
rename : bin/parse_gmsh3D.py => bin/gmsh_bench.py
This commit is contained in:
Stephen McQuay 2011-03-24 00:28:04 -06:00
parent e581ab3215
commit c7b9731ee7
3 changed files with 76 additions and 119 deletions

76
bin/gmsh_bench.py Executable file
View File

@ -0,0 +1,76 @@
#!/usr/bin/env python
import sys
import numpy as np
from optparse import OptionParser
import interp.bootstrap
from interp.grid.gmsh import gmsh_grid3D, gmsh_grid
from interp.tools import *
def get_right_exact_func(options):
f = None
if options.dimension == 3:
if options.baker:
f = baker_exact_3D
else:
f =friendly_exact_3D
elif options.dimension == 2:
if options.baker:
f = baker_exact_2D
else:
f = friendly_exact_2D
return f
if __name__ == '__main__':
parser = OptionParser(usage = "%prog [options] <input file> <number of attempts>")
parser.add_option("-v", "--verbose",
action="store_true", dest="verbose", default=False,
help="verbose flag")
parser.add_option("-b", "--baker",
action="store_true", dest="baker", default=False,
help="use more impressive baker funcs")
parser.add_option("-d", "--dimension",
type="int", dest="dimension", default=3,
help="use 3D or 2D gmsh lib (default: %default)")
parser.add_option("-o", "--order",
type="int", dest="order", default=3,
help="order of interpolation (default: %default)")
parser.add_option("-e", "--extra-points",
type="int", dest="extra", default=3,
help="number of extra points (default: %default)")
(options, args) = parser.parse_args()
if len(args) != 2:
# print >> sys.stderr, "usage: %s <input file> <number of attempts>" % sys.argv[0]
parser.print_usage()
sys.exit(1)
input_file, count = args
if options.dimension == 3:
g = gmsh_grid3D(input_file)
else:
g = gmsh_grid(input_file)
g.q = np.array([get_right_exact_func(options)(x) for x in g.verts])
results = {True:0, False:0}
for i in xrange(int(count)):
X = np.random.random((1,options.dimension))[0]
a = g.run_baker(X, order = options.order, extra_points = options.extra)
e = get_right_exact_func(options)(X)
results[improved_answer(a, e)] += 1
print results

View File

@ -1,84 +0,0 @@
#!/usr/bin/env python
import sys
import numpy as np
from interp.grid.gmsh import gmsh_grid
from interp.tools import exact_func, improved_answer
from interp import bootstrap
if __name__ == '__main__':
if len(sys.argv) != 2:
print >> sys.stderr, "usage: %s <gmsh file>" % sys.argv[0]
sys.exit(1)
g = gmsh_grid(sys.argv[1])
g.q = np.array([exact_func(x) for x in g.verts])
# g.dump_to_blender_files()
X = np.array([0.2, 0.5]) #TODO:, 0.0])
R = g.get_containing_simplex(X)
print R
R, S = g.get_simplex_and_nearest_points(X, 10)
print "r", R
print "s", S
a = g.run_baker(X)
print a
e = exact_func(X)
print e
print improved_answer(a, e)
a = g.run_baker(X, extra_points = 5)
print a
e = exact_func(X)
print e
print improved_answer(a, e)
a = g.run_baker(X, extra_points = 7)
print a
e = exact_func(X)
print e
print improved_answer(a, e)
a = g.run_baker(X, order=3)
print a
e = exact_func(X)
print e
print improved_answer(a, e)
a = g.run_baker(X, order=3, extra_points = 5)
print a
e = exact_func(X)
print e
print improved_answer(a, e)
a = g.run_baker(X, order=3, extra_points = 7)
print a
e = exact_func(X)
print e
print improved_answer(a, e)
a = g.run_baker(X, order=3, extra_points = 10)
print a
e = exact_func(X)
print e
print improved_answer(a, e)
results = {True:0, False:0}
for i in xrange(1000):
X = np.random.random((1,2))[0]
try:
a = g.run_baker(X, order=2, extra_points = 3)
e = exact_func(X)
ia = improved_answer(a, e)
# if not ia:
# print a['final'] - e, a, e
results[ia] += 1
except Exception,e:
print >>sys.stderr, e
print >>sys.stderr, X
print results

View File

@ -1,35 +0,0 @@
#!/usr/bin/env python
import sys
import cProfile
import numpy as np
import interp.bootstrap
from interp.grid.gmsh import gmsh_grid3D
from interp.tools import improved_answer, exact
def test_success(input_file, count):
g = gmsh_grid3D(input_file)
g.q = np.array([exact(x) for x in g.verts])
results = {True:0, False:0}
# import pdb; pdb.set_trace()
for i in xrange(count):
X = np.random.random((1,3))[0]
a = g.run_baker(X, order = 3, extra_points = 32)
e = exact(X)
results[improved_answer(a, e)] += 1
return results
if __name__ == '__main__':
if len(sys.argv) != 3:
print >> sys.stderr, "usage: %s <input file> <number of attempts>" % sys.argv[0]
sys.exit(1)
input_file, count = sys.argv[1:]
print test_success(input_file, int(count))