source: anuga_work/development/reef_0708/gradual_lgflat.py @ 5442

Last change on this file since 5442 was 5442, checked in by ole, 16 years ago

Retired h-limiter and beta_h as per ticket:194.
All unit tests and validation tests pass.

File size: 9.4 KB
Line 
1"""Simple water flow example using ANUGA
2
3Water driven up a linear slope and time varying boundary,
4similar to a beach environment
5"""
6
7
8#------------------------------------------------------------------------------
9# Import necessary modules
10#------------------------------------------------------------------------------
11
12from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
13from anuga.shallow_water import Domain
14from anuga.shallow_water import Reflective_boundary
15from anuga.shallow_water import Dirichlet_boundary
16from anuga.shallow_water import Time_boundary
17from anuga.shallow_water import Transmissive_boundary
18from anuga.shallow_water import Transmissive_Momentum_Set_Stage_boundary
19from anuga.shallow_water.data_manager import start_screen_catcher, copy_code_files
20from time import strftime, gmtime
21from os import sep, environ, getenv, getcwd,umask
22from anuga.utilities.polygon import Polygon_function
23#------------------------------------------------------------------------------
24# Setup computational domain
25#------------------------------------------------------------------------------
26from anuga.pmesh.mesh_interface import create_mesh_from_regions
27
28name ='gradual_lgflat'
29wave = [1, -1] #1 returns leading depression N-wave
30               #-1 returns leading crest N-wave
31crest =[50, 450]
32crestdepth = [2, -2, -6]
33N = len (crest)
34for i in range(N):
35    M = len (crestdepth)
36    for k in range (M):
37        B = len(wave)
38        for l in range(B):
39            length = (crest[i]+2500)
40            width = 20.
41            A = 1
42            T = 2700
43            umask(002)
44            time = strftime('%Y%m%d_%H%M%S',gmtime())
45
46##            output_dir = 'c:'+sep+'anuga_data'+sep
47            output_dir = sep+'d'+sep+'xrd'+sep+'gem'+sep+'5'+sep+'nhi'+sep+'inundation'+sep+'data'+sep+'idealised_bathymetry_study'+sep+'final_models'+sep+'general'+sep+'gradual_lgflat'+sep+str(wave[l])+'_'+str(length)+'_'+str(A)+'_'+str(T)+'_'+str(crestdepth[k])+'_'+str(name)+sep
48            sww_file = str(name)
49            copy_code_files(output_dir,__file__,__file__)
50
51            start_screen_catcher(output_dir)
52            dx = dy = .5           # Resolution: Length of subdivisions on both axes
53            boundary_polygon = [[0,0],[length,0],[length,width],[0,width]]
54            interior_polygon = [[140,0],[2280+crest[i],0],[2280+crest[i],20],[140,20]]
55            interior_polygon2 =[[2290+crest[i],0],[2499+crest[i],0],[2499+crest[i],20],[2290+crest[i],20]]
56            interior_regions = [[interior_polygon, 8], [interior_polygon2, 50]]
57            meshname = str(name)+'.msh'
58            create_mesh_from_regions(boundary_polygon,
59                                     boundary_tags={'bottom': [0],
60                                                    'right': [1],
61                                                    'top': [2],
62                                                    'left': [3]},
63                                     maximum_triangle_area=50,
64                                     filename=meshname,
65                                     interior_regions=interior_regions,
66                                     use_cache=False,
67                                     verbose=False)
68
69            domain = Domain(meshname, use_cache=False, verbose=True)
70
71            print 'Number of triangles = ', len(domain)
72            print 'The extent is ', domain.get_extent()
73            print domain.statistics()
74             
75            domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
76            domain.set_minimum_storable_height(0.01)
77            domain.set_default_order(2) # Second order spatial approximation
78            domain.set_name(sww_file)   # Output name
79            domain.set_datadir(output_dir) 
80
81
82            #------------------------------------------------------------------------------
83            # Setup initial conditions
84            #------------------------------------------------------------------------------
85
86            def topography(x,y):
87                """Complex topography defined by a function of vectors x and y
88                """
89
90                z =(-0.026*x)+(0.026*(2220+crest[i]))+crestdepth[k]-4       
91                N = len (x)
92                for j in range(N):
93
94                    if x[j] < 180:
95                        z[j] = -4+crestdepth[k] 
96                   
97                    elif 179 < x[j] < 200:
98                        z[j] = 0.2*x[j]-40+crestdepth[k]
99                        #Reef Flat
100                    elif 199 < x[j] < 2200:
101                        z[j] = -0.5+crestdepth[k]
102                        ##Crest
103                    elif 2199 < x[j] < (2200+crest[i]):
104                        z[j] = +crestdepth[k]
105                       
106    ##                     
107                     #Curve down
108                    elif (2199+crest[i]) < x[j] < (2220+crest[i]):
109                        z[j] = -0.01*(x[j]-(2199+crest[i]))*(x[j]-(2199+crest[i]))+crestdepth[k]
110                       
111                return z
112               
113
114
115            domain.set_quantity('elevation', topography) # Use function for elevation
116    ##        domain.set_quantity('friction', 0)         # Constant friction
117            domain.set_quantity('friction', Polygon_function( [(boundary_polygon, 0.05),(interior_polygon ,0.2), (interior_polygon2 , 0.05)] ) )#changing friction over two polygons
118            domain.set_quantity('stage', 0.)            # Constant negative initial stage
119            domain.tight_slope_limiters = 1
120
121            #------------------------------------------------------------------------------
122            # Setup boundary conditions
123            #------------------------------------------------------------------------------
124
125            from math import sin, pi, exp, cos, cosh, sqrt
126            Br = Reflective_boundary(domain)      # Solid reflective wall
127            Bt = Transmissive_boundary(domain)    # Continue all values on boundary
128            Bd = Dirichlet_boundary([0.,0.,0.]) # Constant boundary values
129            Bw = Time_boundary(domain=domain,     # Time dependent boundary 
130                               f=lambda t: [sin(2*pi*(t)/1010), -37, 0.0])
131            g = 9.81
132            offshore_depth = 17
133            H_d_ratio = 0.116
134            Xo = 17500
135            po = 0.0002
136            def waveform(t):
137                return wave[l]*offshore_depth*(sqrt(g/offshore_depth)*t-Xo/offshore_depth)*sqrt(H_d_ratio*po)*H_d_ratio/cosh(sqrt(3*H_d_ratio*po/4)*(sqrt(g/offshore_depth)*t-Xo/offshore_depth))/cosh(sqrt(3*H_d_ratio*po/4)*(sqrt(g/offshore_depth)*t-Xo/offshore_depth))
138            Bf = Transmissive_Momentum_Set_Stage_boundary(domain, waveform)
139            # Associate boundary tags with boundary objects
140            domain.set_boundary({'left': Bd, 'right': Bf, 'top': Br, 'bottom': Br})
141
142
143            #------------------------------------------------------------------------------
144            # Evolve system through time
145            #------------------------------------------------------------------------------
146
147            for t in domain.evolve(yieldstep = 5 , finaltime = length*2):
148                domain.write_time()
149                print   domain.timestepping_statistics(track_speeds=True)
150                """
151            Generate time series of nominated "gauges"
152            Note, this script will only work if pylab is installed on the platform
153
154            Inputs:
155
156            production dirs: dictionary of production directories with a
157                             association to that simulation run, eg high tide,
158                             magnitude, etc.
159                               
160            Outputs:
161
162            * figures stored in same directory as sww file
163            * time series data stored in csv files in same directory as sww file
164            * elevation at nominated gauges (elev_output)
165            """
166
167            from os import getcwd, sep, altsep, mkdir, access, F_OK, remove
168            from anuga.abstract_2d_finite_volumes.util import sww2timeseries
169
170            # nominate directory location of sww file with associated attribute
171            production_dirs = {output_dir: str(name)}
172
173            # Generate figures
174            swwfiles = {}
175            for label_id in production_dirs.keys():
176                file_loc = label_id
177                swwfile = file_loc + str(name)+'.sww'
178                swwfiles[swwfile] = label_id
179                print 'hello', swwfile
180            texname, elev_output = sww2timeseries(swwfiles,
181                                                   sep+'d'+sep+'cit'+sep+'1'+sep+'cit'+sep+'natural_hazard_impacts'+sep+'inundation'+sep+'sandpits'+sep+'jbrowning'+sep+'anuga'+sep+'anuga_work'+sep+'development'+sep+'idealised_bathymetry_study'+sep+'final_models'+sep+'general'+sep+'gauges_lgflat.csv',
182                                                  production_dirs,
183                                                  report = False,
184                                                  reportname = '',
185                                                  plot_quantity = ['stage', 'speed'],
186                                                  generate_fig = False,
187                                                  surface = False,
188                                                  time_min = None,
189                                                  time_max = None,
190                                                  #time_unit = 'secs',
191                                                  title_on = True,
192                                                  verbose = True)
193##            remove(output_dir+sep+str(name)+'.sww')
194
195
196
Note: See TracBrowser for help on using the repository browser.