source: inundation/ga/storm_surge/examples/run_gong.py @ 926

Last change on this file since 926 was 926, checked in by duncan, 20 years ago

no import bug fix

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 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
55    if (domain.visualise):
56        domain.store = False  #True    #Store for visualisation purposes
57    else:
58        domain.store = True  #True    #Store for visualisation purposes
59        domain.format = 'sww'   #Native netcdf visualisation format
60   
61        file_path, filename = path.split(filename)
62        filename, ext = path.splitext(filename)
63        domain.filename = filename + '_' + '_ys'+ str(yieldstep) + \
64                          '_ft' + str(finaltime)
65        print "Output being written to " + domain.get_datadir() + sep + \
66              domain.filename + "." + domain.format
67
68
69    #Set friction
70    manning = 0.07
71    inflow_stage = 10.0
72    domain.set_quantity('friction', manning)
73
74    ######################
75    # Boundary conditions
76    #
77    print 'Boundaries'
78    reflective = Reflective_boundary(domain)
79    Bt = Transmissive_boundary(domain)
80
81    #Constant inflow
82    Bd = Dirichlet_boundary(array([inflow_stage, 0.0, 0.0]))
83
84    #Time dependent inflow
85    from math import sin, pi
86    Bw = Time_boundary(domain=domain,
87                       f=lambda x: array([(1 + sin(x*pi/4))*\
88                        (inflow_stage*(sin(2.5*x*pi)+0.7)),0,0]))
89
90    boundary_file = 'kermadec2.sww'
91
92    Fb = File_boundary(boundary_file, domain, verbose=True)
93
94    print 'Available boundary tags are', domain.get_boundary_tags()
95    print 'The extent is ', domain.get_extent()
96
97    #Set the ocean...
98    domain.set_quantity('stage', 0.0)
99
100    #Set boundary conditions
101   
102    tags = {}
103   
104    tsunami = Bw
105    tags['w1'] = tsunami
106    tags['w2'] = tsunami
107    tags['w3'] = tsunami
108    tags['w4'] = tsunami
109    tags['w5'] = tsunami
110    tags['w6'] = tsunami
111    tags['w7'] = tsunami
112    tags['wave'] = tsunami
113    tags['external'] = reflective 
114    tags['exterior'] = reflective
115
116    domain.set_boundary(tags)
117
118    # region tags
119   
120    domain.check_integrity()
121
122    ######################
123    #Evolution
124    t0 = time.time()
125    for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime):
126        domain.write_time()
127   
128    print 'That took %.2f seconds' %(time.time()-t0)
129
130   
Note: See TracBrowser for help on using the repository browser.