source: trunk/anuga_work/development/reef_0708/steep_smflat_900.py @ 7884

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