forked from python-hydro/pyro2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmooth_error.py
More file actions
executable file
·47 lines (32 loc) · 983 Bytes
/
Copy pathsmooth_error.py
File metadata and controls
executable file
·47 lines (32 loc) · 983 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python
import numpy as np
import mesh.patch as patch
import sys
import advection.problems.smooth as smooth
usage = """
compare the output in file from the smooth advection problem to
the analytic solution.
usage: ./smooth_error.py file
"""
if not len(sys.argv) == 2:
print usage
sys.exit(2)
try: file1 = sys.argv[1]
except:
print usage
sys.exit(2)
myg, myd = patch.read(file1)
# create a new data object on the same grid
analytic = patch.CellCenterData2d(myg, dtype=np.float64)
bco = myd.BCs[myd.vars[0]]
analytic.register_var("density", bco)
analytic.create()
# use the original initialization routine to set the analytic solution
smooth.init_data(analytic, None)
# compare the error
dens_numerical = myd.get_var("density")
dens_analytic = analytic.get_var("density")
print "mesh details"
print myg
e = dens_numerical - dens_analytic
print "error norms (absolute, relative): ", e.norm(), e.norm()/dens_analytic.norm()