smbinterp/bin/resolution.py
2011-05-06 11:02:24 -06:00

46 lines
970 B
Python

import sys
import numpy as np
from interp.grid.delaunay import dgrid
from interp.tools import baker_exact_3D
from interp.tools import rms
from progressbar import *
attempts = 1000
widgets = ['submit jobs: ', Percentage(), ' ', Bar(), ' ', ETA()]
results = {}
for r in xrange(2,8):
resolution = float("1e%d" % r)
v = np.random.random((resolution,3))
q = [baker_exact_3D(x) for x in v]
g = dgrid(v,q)
pbar = ProgressBar(widgets = widgets, maxval = attempts)
pbar.start()
start = time.time()
errors = []
i = 0
outside = 0
while i < attempts:
try:
X = np.random.random((1,3))[0]
e = g.run_baker(X)['final'] - baker_exact_3D(X)
errors.append(e)
pbar.update(i+1)
i += 1
except Exception as e:
# print X, i, resolution
outside += 1
pbar.finish()
print "\n"
end = time.time()
rmserror = rms(errors)
results[resolution] = rmserror
print resolution, rmserror, outside, end - start