50 lines
1.1 KiB
Python
50 lines
1.1 KiB
Python
|
#!/usr/bin/python
|
||
|
|
||
|
import math
|
||
|
from baker import run_baker
|
||
|
|
||
|
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)
|
||
|
|
||
|
extra = 3
|
||
|
S = g.create_mesh(range(3, 3 + extra))
|
||
|
|
||
|
answer = run_baker(X, R, S, 3)
|
||
|
answer['exact'] = exact_func(X)
|
||
|
t = ('qlin', 'error', 'exact')
|
||
|
|
||
|
for i in t:
|
||
|
print "%s %s" % (
|
||
|
i.ljust(10),
|
||
|
("%0.4f" % answer[i]),
|
||
|
)
|
||
|
lin_err = abs(answer['exact'] - answer['qlin'])
|
||
|
final_err = abs(answer['exact'] - answer['final'])
|
||
|
print lin_err >= final_err
|