smbinterp/bin/test.py

47 lines
1.1 KiB
Python
Raw Normal View History

#!/usr/bin/env python
import sys
2011-02-02 10:52:53 -08:00
from interp.grid.DDD import random_grid
from interp.baker import get_phis, run_baker
from interp.tools import log
from interp.tools import exact_func_3D, improved_answer
from interp.grid.simplex import contains
try:
total_points = int(sys.argv[1])
except:
total_points = 20
2011-02-02 10:52:53 -08:00
log.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)
2011-02-02 10:52:53 -08:00
sys.exit()
log.info("Containing Simplex: %s" % contains(X, R.points))
exact = exact_func_3D(X)
2011-02-02 10:52:53 -08:00
log.info("exact solution: %0.6f" % exact)
2011-02-02 10:52:53 -08:00
phis = get_phis(X, R.points)
log.info("phi values (should all be positive): %s %s" % (phis, sum(phis)))
if [i for i in phis if i < 0.0]:
2011-02-02 10:52:53 -08:00
log.error("problems")
try:
2011-02-02 10:52:53 -08:00
r = run_baker(X, R, S)
log.info("run_baker manual: %s" % improved_answer(r, exact))
except Exception as e:
log.error(e)
try:
answer = g.run_baker(X)
2011-02-02 10:52:53 -08:00
log.info("run_baker from grid: %s" % improved_answer(answer, exact))
except Exception as e:
log.error(e)