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

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

this is a test from GA

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, 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        #f=lambda x: array([(1 + sin(x*pi/4))*\
74        #                (inflow_stage*(sin(2.5*x*pi)+0.7)),0,0])
75
76    #Set friction
77    manning = 0.07
78    inflow_stage = 10.0
79    domain.set_quantity('friction', manning)
80
81    ######################
82    # Boundary conditions
83    #
84    print 'Boundaries'
85    Br = Reflective_boundary(domain)
86    Bt = Transmissive_boundary(domain)
87
88    #Constant inflow
89    Bd = Dirichlet_boundary(array([inflow_stage, 0.0, 0.0]))
90
91    #Time dependent inflow
92    from math import sin, pi
93    Bw = Time_boundary(domain=domain,
94                       f=lambda x: array([(1 + sin(x*pi/4))*\
95                        (inflow_stage*(sin(2.5*x*pi)+0.7)),0,0]))
96
97
98    print 'Available boundary tags are', domain.get_boundary_tags()
99
100    #Set boundary conditions
101   
102    tags = {}
103    tags['left'] = Bw
104    tags['1'] = Time_boundary(domain=domain,
105                       f=lambda x: array([(1 + sin(x*pi/4))*\
106                        (0.15*(sin(2.5*x*pi)+0.7)),0,0]))
107    tags['wave'] = Bd
108    tags['internal'] = None
109    tags['levee'] = None
110    tags['0'] = Br
111    tags['wall'] = Br
112    tags['external'] = Br
113    tags['open'] = Br
114
115    domain.set_boundary(tags)
116
117
118    #print domain.quantities['elevation'].vertex_values
119    #print domain.quantities['level'].vertex_values
120         
121    domain.check_integrity()
122
123    ######################
124    #Evolution
125    for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime):
126        domain.write_time()
127   
128    print 'Done'
129
130   
Note: See TracBrowser for help on using the repository browser.