smbinterp/bin/test_baker.py

51 lines
1.0 KiB
Python
Raw Normal View History

#!/usr/bin/env python
import math
from baker import run_baker
from baker.tools import improved_answer
from baker.tools import smblog
from grid.DD import grid
from grid.simplex import contains
def exact_func(X):
x = X[0]
y = X[0]
return 1 - math.sin((x-0.5)**2 + (y-0.5)**2)
if __name__ == '__main__':
points = [
[ 0.25, 0.40], # 0
[ 0.60, 0.80], # 1
[ 0.65, 0.28], # 2
[ 0.28, 0.65], # 3
[ 1.00, 0.75], # 4
[ 0.30, 0.95], # 5
[ 0.80, 0.50], # 6
[ 0.35, 0.15], # 7
]
q = [exact_func(p) for p in points]
X = [0.55, 0.45]
g = grid(points, q)
g.construct_connectivity()
R = g.create_mesh(range(3))
print contains(X, R.points)
try:
extra = int(sys.argv[1])
except:
extra = 3
S = g.create_mesh(range(3, 3 + extra))
for i in xrange(1,4):
answer = run_baker(X, R, S, i)
exact = exact_func(X)
smblog.debug(improved_answer(answer, exact))
smblog.debug(improved_answer(g.run_baker(X), exact))