smbinterp/bin/test_baker.py

50 lines
1.0 KiB
Python
Executable File

#!/usr/bin/env python
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
import numpy as np
def exact_func(X):
x = X[0]
y = X[0]
return 1 - np.sin(np.power((x-0.5), 2) + np.power((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))
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))