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
·68 lines (42 loc) · 1.36 KB
/
Copy pathsmooth_error.py
File metadata and controls
executable file
·68 lines (42 loc) · 1.36 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python
import numpy
import mesh.patch as patch
import getopt
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
"""
def abort(string):
print string
sys.exit(2)
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=numpy.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
aerr = abs(dens_numerical[myg.ilo:myg.ihi+1,myg.jlo:myg.jhi+1] -
dens_analytic[myg.ilo:myg.ihi+1,myg.jlo:myg.jhi+1])
rerr = aerr/dens_analytic[myg.ilo:myg.ihi+1,myg.jlo:myg.jhi+1]
# note that the numpy norm does not normalize by the number of elements,
# so we explicitly do so here
l2a = numpy.sqrt(numpy.sum(aerr**2)/(myg.nx*myg.ny))
l2r = numpy.sqrt(numpy.sum(rerr**2)/(myg.nx*myg.ny))
print "error norms (absolute, relative): ", l2a, l2r