~wence/fluidity/make-fixes

« back to all changes in this revision

Viewing changes to tests/python_shape_dshape_test_2d/python_shape_dshape_test_2d.py

  • Committer: Lawrence Mitchell
  • Date: 2011-05-26 15:04:09 UTC
  • mfrom: (3470.2.9 fluidity)
  • Revision ID: lawrence.mitchell@ed.ac.uk-20110526150409-umwrmt43ateiawr5
MergeĀ fromĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from fluidity_tools import stat_parser as stat
 
2
from math import log
 
3
import glob
 
4
 
 
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])
 
8
 
 
9
  a_error_l1 = sum(stat(statfileA)["Fluid"][field]["integral"])*dt_A
 
10
  b_error_l1 = sum(stat(statfileB)["Fluid"][field]["integral"])*dt_B
 
11
 
 
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
 
14
 
 
15
  a_error_inf = max(stat(statfileA)["Fluid"][field]["max"])
 
16
  b_error_inf = max(stat(statfileB)["Fluid"][field]["max"])
 
17
 
 
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
 
22
 
 
23
  ab_error = [log(ab_ratio_l1, 2), log(ab_ratio_l2, 2), log(ab_ratio_inf, 2)]
 
24
  return ab_error
 
25
 
 
26
 
 
27
def test_convergence(statfiles, fields, tol):
 
28
  for field in fields:
 
29
    for i in range(len(statfiles)):
 
30
      if i==0:
 
31
        continue
 
32
      if min(get_convergence(statfiles[i-1], statfiles[i], field)) < tol:
 
33
          return False
 
34
  return True      
 
35
 
 
36
def test_convergence_rates(tol, pattern, fields):
 
37
  statfiles = sorted(glob.glob(pattern))
 
38
  res = test_convergence(statfiles, fields, tol)
 
39
  return res
 
40
 
 
41
  
 
42
def print_convergence(statfiles, fields):
 
43
  for field in fields:
 
44
    print "Field: ", field
 
45
    for i in range(len(statfiles)):
 
46
      if i==0:
 
47
        continue
 
48
      print statfiles[i-1], " : ", statfiles[i], ' ', get_convergence(statfiles[i-1], statfiles[i], field)
 
49
 
 
50
def print_convergence_rates(pattern, fields):
 
51
  print ""
 
52
  print " =============== Time decreasing, mesh resolution increasing ================"
 
53
  statfiles = sorted(glob.glob(pattern))
 
54
  print_convergence(statfiles, fields)