77 lines
1.9 KiB
Python
Executable File
77 lines
1.9 KiB
Python
Executable File
#!/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
|