source: inundation/ga/storm_surge/examples/run_tsh.py @ 718

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

adding regional modifiers

File size: 3.9 KB
RevLine 
[419]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,\
[718]20     Transmissive_boundary, Time_boundary, Set_region, Add_value_to_region
[419]21from mesh_factory import rectangular
22from pmesh2domain import pmesh_to_domain, pmesh_to_domain_instance
23
24from Numeric import array
25
26from config import data_dir
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
[449]51    domain.default_order = 1
[419]52    domain.visualise = visualise
53
54    if (domain.visualise):
55        domain.store = False  #True    #Store for visualisation purposes
56    else:
57        domain.store = True  #True    #Store for visualisation purposes
58        domain.format = 'sww'   #Native netcdf visualisation format
59   
60        file_path, filename = path.split(filename)
61        filename, ext = path.splitext(filename)
62        if domain.smooth is True:
63            s = 'smooth'
64        else:
65            s = 'nonsmooth'       
[421]66        domain.filename = filename + '_' + s + '_ys'+ str(yieldstep) + \
67                          '_ft' + str(finaltime)
[419]68        print "Output being written to " + data_dir + sep + \
69              domain.filename + "." + domain.format
70
71
72    #Set friction
[449]73    manning = 0.07
[514]74    inflow_stage = 20.0
[419]75    domain.set_quantity('friction', manning)
76
77    ######################
78    # Boundary conditions
79    #
80    print 'Boundaries'
[718]81    reflective = Reflective_boundary(domain)
[419]82    Bt = Transmissive_boundary(domain)
83
84    #Constant inflow
[718]85    Bd = Dirichlet_boundary(array([7, 0.0, 0.0]))
[419]86
87    #Time dependent inflow
88    from math import sin, pi
89    Bw = Time_boundary(domain=domain,
90                       f=lambda x: array([(1 + sin(x*pi/4))*\
91                        (inflow_stage*(sin(2.5*x*pi)+0.7)),0,0]))
92
93
94    print 'Available boundary tags are', domain.get_boundary_tags()
95
96    #Set boundary conditions
97   
98    tags = {}
99    tags['left'] = Bw
100    tags['1'] = Time_boundary(domain=domain,
101                       f=lambda x: array([(1 + sin(x*pi/4))*\
102                        (0.15*(sin(2.5*x*pi)+0.7)),0,0]))
103    tags['wave'] = Bd
104    tags['internal'] = None
105    tags['levee'] = None
[718]106    tags['0'] = reflective
107    tags['wall'] = reflective
108    tags['external'] = reflective
109    tags['open'] = Bd 
110    tags['opening'] = None 
[419]111
112    domain.set_boundary(tags)
113
[718]114    # region tags
115    #domain.set_region(Set_region('mound', 'elevation', 100, location='unique vertices'))
116    domain.set_region(Add_value_to_region('mound', 'elevation', 100, location='unique vertices', initial_quantity='elevation'))
117    domain.set_region(Add_value_to_region('reservoir', 'level', 100.0,initial_quantity='elevation'))
118   
[419]119    #print domain.quantities['elevation'].vertex_values
120    #print domain.quantities['level'].vertex_values
121         
122    domain.check_integrity()
123
124    ######################
125    #Evolution
126    for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime):
127        domain.write_time()
128   
129    print 'Done'
130
131   
Note: See TracBrowser for help on using the repository browser.