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

Last change on this file since 643 was 514, checked in by ole, 20 years ago

Windfield as explicit update

File size: 3.5 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, Constant_height, Weir
21
22from mesh_factory import rectangular
23from pmesh2domain import pmesh_to_domain, pmesh_to_domain_instance
24
25from Numeric import array
26
27from config import data_dir
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
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        if domain.smooth is True:
64            s = 'smooth'
65        else:
66            s = 'nonsmooth'       
67        domain.filename = filename + '_' + s + '_ys'+ str(yieldstep) + \
68                          '_ft' + str(finaltime)
69        print "Output being written to " + data_dir + sep + \
70              domain.filename + "." + domain.format
71
72
73    #Set friction
74    manning = 0.07
75    inflow_stage = 20.0
76    domain.set_quantity('friction', manning)
77
78    ######################
79    # Boundary conditions
80    #
81    print 'Boundaries'
82    Br = Reflective_boundary(domain)
83    Bt = Transmissive_boundary(domain)
84
85    #Constant inflow
86    Bd = Dirichlet_boundary(array([inflow_stage, 0.0, 0.0]))
87
88    #Time dependent inflow
89    from math import sin, pi
90    Bw = Time_boundary(domain=domain,
91                       f=lambda x: array([(1 + sin(x*pi/4))*\
92                        (inflow_stage*(sin(2.5*x*pi)+0.7)),0,0]))
93
94
95    print 'Available boundary tags are', domain.get_boundary_tags()
96
97    #Set boundary conditions
98   
99    tags = {}
100    tags['left'] = Bw
101    tags['1'] = Time_boundary(domain=domain,
102                       f=lambda x: array([(1 + sin(x*pi/4))*\
103                        (0.15*(sin(2.5*x*pi)+0.7)),0,0]))
104    tags['wave'] = Bd
105    tags['internal'] = None
106    tags['levee'] = None
107    tags['0'] = Br
108    tags['wall'] = Br
109    tags['external'] = Br
110    tags['open'] = Bd
111
112    domain.set_boundary(tags)
113
114
115    #print domain.quantities['elevation'].vertex_values
116    #print domain.quantities['level'].vertex_values
117         
118    domain.check_integrity()
119
120    ######################
121    #Evolution
122    for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime):
123        domain.write_time()
124   
125    print 'Done'
126
127   
Note: See TracBrowser for help on using the repository browser.