1
from fluidity_tools import stat_parser as stat
5
def get_convergence(statfileA, statfileB, field):
6
dt_A = abs(stat(statfileA)["dt"]['value'][-1])
7
dt_B = abs(stat(statfileB)["dt"]['value'][-1])
9
a_error_l1 = sum(stat(statfileA)["Fluid"][field]["integral"])*dt_A
10
b_error_l1 = sum(stat(statfileB)["Fluid"][field]["integral"])*dt_B
12
a_error_l2 = sum([x**2*dt_A for x in stat(statfileA)["Fluid"][field]["l2norm"]])**0.5
13
b_error_l2 = sum([x**2*dt_B for x in stat(statfileB)["Fluid"][field]["l2norm"]])**0.5
15
a_error_inf = max(stat(statfileA)["Fluid"][field]["max"])
16
b_error_inf = max(stat(statfileB)["Fluid"][field]["max"])
18
# Velocity error calculation
19
ab_ratio_l1 = a_error_l1 / b_error_l1
20
ab_ratio_l2 = a_error_l2 / b_error_l2
21
ab_ratio_inf = a_error_inf / b_error_inf
23
ab_error = [log(ab_ratio_l1, 2), log(ab_ratio_l2, 2), log(ab_ratio_inf, 2)]
27
def test_convergence(statfiles, fields, tol):
29
for i in range(len(statfiles)):
32
if min(get_convergence(statfiles[i-1], statfiles[i], field)) < tol:
36
def test_convergence_rates(tol, pattern, fields):
37
statfiles = sorted(glob.glob(pattern))
38
res = test_convergence(statfiles, fields, tol)
42
def print_convergence(statfiles, fields):
44
print "Field: ", field
45
for i in range(len(statfiles)):
48
print statfiles[i-1], " : ", statfiles[i], ' ', get_convergence(statfiles[i-1], statfiles[i], field)
50
def print_convergence_rates(pattern, fields):
52
print " =============== Time decreasing, mesh resolution increasing ================"
53
statfiles = sorted(glob.glob(pattern))
54
print_convergence(statfiles, fields)