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

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

fixed default_datadir issue

File size: 4.3 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
21from mesh_factory import rectangular
22from pmesh2domain import pmesh_to_domain, pmesh_to_domain_instance
23
24from Numeric import array
25
26
27from config import default_datadir
28
29######################
30# Domain
31
32import sys
33
34usage = "usage: %s ['visual'|'non-visual'] pmesh_file_name yieldstep finaltime" %         path.basename(sys.argv[0])
35
36if len(sys.argv) < 4:
37    print usage
38else:
39    if sys.argv[1][0] == "n" or sys.argv[1][0] == "N":
40        visualise = False
41    else:   
42        visualise = True
43    filename = sys.argv[2]
44    yieldstep = float(sys.argv[3])
45    finaltime = float(sys.argv[4])
46   
47    print 'Creating domain from', filename
48    domain = pmesh_to_domain_instance(filename, Domain)
49    print "Number of triangles = ", len(domain)
50
51    domain.checkpoint = False #True
52    domain.default_order = 1
53    domain.visualise = visualise
54    domain.smooth = True
55
56    if (domain.visualise):
57        domain.store = False  #True    #Store for visualisation purposes
58    else:
59        domain.store = True  #True    #Store for visualisation purposes
60        domain.format = 'sww'   #Native netcdf visualisation format
61   
62        file_path, filename = path.split(filename)
63        filename, ext = path.splitext(filename)
64        if domain.smooth is True:
65            s = 'smooth'
66        else:
67            s = 'nonsmooth'       
68        domain.filename = filename + '_' + s + '_ys'+ str(yieldstep) + \
69                          '_ft' + str(finaltime)
70        print "Output being written to " + default_datadir + sep + \
71              domain.filename + "." + domain.format
72
73
74    #Set friction
75    manning = 0.07
76    inflow_stage = 10.0
77    domain.set_quantity('friction', manning)
78
79    ######################
80    # Boundary conditions
81    #
82    print 'Boundaries'
83    reflective = Reflective_boundary(domain)
84    Bt = Transmissive_boundary(domain)
85
86    #Constant inflow
87    Bd = Dirichlet_boundary(array([10, 0.0, 0.0]))
88
89    #Time dependent inflow
90    from math import sin, pi
91    Bw = Time_boundary(domain=domain,
92                       f=lambda x: array([(1 + sin(x*pi/4))*\
93                        (inflow_stage*(sin(2.5*x*pi)+0.7)),0,0]))
94
95
96    print 'Available boundary tags are', domain.get_boundary_tags()
97
98    #Set boundary conditions
99   
100    tags = {}
101    tags['left'] = Bw
102    tags['1'] = Time_boundary(domain=domain,
103                       f=lambda x: array([(1 + sin(x*pi/4))*\
104                        (0.15*(sin(2.5*x*pi)+0.7)),0,0]))
105    tags['wave'] = Bd
106    tags['wave'] = Time_boundary(domain=domain,
107                       f=lambda x: array([(1 + sin(x*pi/4))*\
108                        (0.15*(sin(2.5*x*pi)+0.7)),0,0]))
109    tags['internal'] = None
110    tags['levee'] = None
111    tags['0'] = reflective
112    tags['wall'] = reflective
113    tags['external'] = reflective 
114    tags['exterior'] = reflective
115    tags['open'] = Bd 
116    tags['opening'] = None 
117
118    domain.set_boundary(tags)
119
120    # region tags
121    #domain.set_region(Set_region('mound', 'elevation', 100, location='unique vertices'))
122    domain.set_region(Add_value_to_region('floodplain', 'elevation', 100, location='unique vertices', initial_quantity='elevation'))
123    domain.set_region(Add_value_to_region('mound', 'elevation', 100, location='unique vertices', initial_quantity='elevation'))
124    domain.set_region(Add_value_to_region('reservoir', 'stage', 100.0,initial_quantity='elevation'))
125   
126    #print domain.quantities['elevation'].vertex_values
127    #print domain.quantities['stage'].vertex_values
128         
129    domain.check_integrity()
130
131    ######################
132    #Evolution
133    for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime):
134        domain.write_time()
135   
136    print 'Done'
137
138   
Note: See TracBrowser for help on using the repository browser.