source: anuga_core/source/anuga/examples/run_gong.py @ 3535

Last change on this file since 3535 was 3535, checked in by duncan, 18 years ago

change imports so reflect the new structure

File size: 3.6 KB
Line 
1"""Example of shallow water wave equation.
2
3Specific methods pertaining to the 2D shallow water equation
4are imported from shallow_water
5for use with the generic finite volume framework
6
7A example of running this program is;
8python run_tsh.py visualise hill.tsh 0.05 1
9"""
10
11######################
12# Module imports
13#
14
15import sys
16from os import sep, path
17sys.path.append('..'+sep+'pyvolution')
18
19from shallow_water import Domain, Reflective_boundary, Dirichlet_boundary,\
20     Transmissive_boundary, Time_boundary, Add_value_to_region, File_boundary
21from mesh_factory import rectangular
22from anuga.pyvolution.pmesh2domain import pmesh_to_domain, pmesh_to_domain_instance
23
24from Numeric import array
25
26import time
27
28######################
29# Domain
30
31import sys
32
33usage = "usage: %s ['visual'|'non-visual'] pmesh_file_name yieldstep finaltime" %         path.basename(sys.argv[0])
34
35if len(sys.argv) < 4:
36    print usage
37else:
38    if sys.argv[1][0] == "n" or sys.argv[1][0] == "N":
39        visualise = False
40    else:   
41        visualise = True
42    filename = sys.argv[2]
43    yieldstep = float(sys.argv[3])
44    finaltime = float(sys.argv[4])
45   
46    print 'Creating domain from', filename
47    domain = pmesh_to_domain_instance(filename, Domain)
48    print "Number of triangles = ", len(domain)
49
50    domain.checkpoint = False #True
51    domain.default_order = 1
52    domain.visualise = visualise
53    domain.smooth = True
54    domain.set_datadir('.')
55    domain.starttime = 20000 
56
57    if (domain.visualise):
58        domain.store = False  #True    #Store for visualisation purposes
59    else:
60        domain.store = True  #True    #Store for visualisation purposes
61        domain.format = 'sww'   #Native netcdf visualisation format
62   
63        file_path, filename = path.split(filename)
64        filename, ext = path.splitext(filename)
65        domain.filename = filename + '_' + '_ys'+ str(yieldstep) + \
66                          '_ft' + str(finaltime)
67        print "Output being written to " + domain.get_datadir() + sep + \
68              domain.filename + "." + domain.format
69
70
71    #Set friction
72    manning = 0.07
73    inflow_stage = 10.0
74    domain.set_quantity('friction', manning)
75
76    ######################
77    # Boundary conditions
78    #
79    print 'Boundaries'
80    reflective = Reflective_boundary(domain)
81    Bt = Transmissive_boundary(domain)
82
83    #Constant inflow
84    Bd = Dirichlet_boundary(array([inflow_stage, 0.0, 0.0]))
85
86    #Time dependent inflow
87    from math import sin, pi
88    Bw = Time_boundary(domain=domain,
89                       f=lambda x: array([(1 + sin(x*pi/4))*\
90                        (inflow_stage*(sin(2.5*x*pi)+0.7)),0,0]))
91
92    boundary_file = 'kermadec2.sww'
93
94    Fb = File_boundary(boundary_file, domain, verbose=True)
95
96    print 'Available boundary tags are', domain.get_boundary_tags()
97    print 'The extent is ', domain.get_extent()
98
99    #Set the ocean...
100    domain.set_quantity('stage', 0.0)
101
102    #Set boundary conditions
103   
104    tags = {}
105   
106    tsunami = Fb
107    tags['w1'] = tsunami
108    tags['w2'] = tsunami
109    tags['w3'] = tsunami
110    tags['w4'] = tsunami
111    tags['w5'] = tsunami
112    tags['w6'] = tsunami
113    tags['w7'] = tsunami
114    tags['wave'] = tsunami
115    tags['external'] = tsunami
116    tags['exterior'] = tsunami
117
118    domain.set_boundary(tags)
119
120    # region tags
121   
122    domain.check_integrity()
123
124    ######################
125    #Evolution
126    t0 = time.time()
127    for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime):
128        domain.write_time()
129   
130    print 'That took %.2f seconds' %(time.time()-t0)
131
132   
Note: See TracBrowser for help on using the repository browser.