smbinterp/bin/test.py

46 lines
1.1 KiB
Python
Raw Normal View History

#!/usr/bin/env python
import sys
from grid.DDD import random_grid
from baker import get_phis_3D, run_baker_3D
from baker.tools import smblog
from baker.tools import exact_func_3D, smberror, improved_answer
from grid.simplex import contains
try:
total_points = int(sys.argv[1])
except:
total_points = 20
smblog.info(total_points)
g = random_grid(total_points)
open('/tmp/for_qhull.txt', 'w').write(g.for_qhull())
X = [0.5, 0.3, 0.4]
R, S = g.get_simplex_and_nearest_points(X, extra_points = 6, simplex_size=4)
smblog.info("Containing Simplex: %s" % contains(X, R.points))
exact = exact_func_3D(X)
smblog.info("exact solution: %0.6f" % exact)
phis = get_phis_3D(X, R.points)
smblog.info("phi values (should all be positive): %s %s" % (phis, sum(phis)))
if [i for i in phis if i < 0.0]:
smblog.error("problems")
try:
r = run_baker_3D(X, R, S)
smblog.info("run_baker manual: %s" % improved_answer(r, exact))
except smberror as e:
smblog.error(e)
try:
answer = g.run_baker(X)
smblog.info("run_baker from grid: %s" % improved_answer(answer, exact))
except smberror as e:
smblog.error(e)