source: anuga_work/development/continental_margin_0708/wave_value_tester_900.py @ 5599

Last change on this file since 5599 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.3 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
23from __future__ import division
24#------------------------------------------------------------------------------
25# Setup computational domain
26#------------------------------------------------------------------------------
27from anuga.pmesh.mesh_interface import create_mesh_from_regions
28
29name = 'wave_value_tester_900a'
30shelf = [50000]
31slope = [150000]
32wave = [-0.5]
33N = len (shelf)
34for i in range(N):
35    M = len (slope)
36    for k in range (M):
37        B = len(wave)
38        for l in range(B): 
39            length = (shelf[i]+slope[k])
40            width = 800.
41            A = 1
42            T = 2700
43            umask(002)
44            time = strftime('%Y%m%d_%H%M%S',gmtime())
45           ## output_dir = 'C:'+sep+'anuga_data'+sep+'topography'+sep+str(name)+sep+str(name)+'_'+str(wave[l])+'_'+str(shelf[i])+'_'+str(slope[k])+sep
46            output_dir = sep+'d'+sep+'sim'+sep+'1'+sep+'mpittard'+sep+'idealised_bathymetry_study'+sep+'wave_value_testers'+sep+str(name)+'_'+str(wave[l])+'_'+str(shelf[i])+'_'+str(slope[k])+sep
47
48            sww_file = str(name)
49            copy_code_files(output_dir,__file__,__file__)
50            start_screen_catcher(output_dir)
51            boundary_polygon = [[0,0],[length,0],[length,width],[0,width]]
52           
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=20000,
60                                     filename=meshname,
61                                     use_cache=False,
62                                     verbose=False)
63
64            domain = Domain(meshname, use_cache=True, verbose=True)
65
66            print 'Number of triangles = ', len(domain)
67            print 'The extent is ', domain.get_extent()
68            print domain.statistics()
69             
70            domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
71            domain.set_minimum_storable_height(0.01)
72            domain.set_default_order(2)
73            domain.set_name(sww_file)# Output name
74            domain.set_datadir(output_dir) 
75
76
77            #------------------------------------------------------------------------------
78            # Setup initial conditions
79            #------------------------------------------------------------------------------
80
81            def topography(x,y):
82                """Complex topography defined by a function of vectors x and y
83                """
84                o = 2500/(slope[k]*slope[k]/4)
85                print str(2500/(slope[k]*slope[k]/4))
86               
87                z = o*(x-(shelf[i]+slope[k]))*(x-(shelf[i]+slope[k]))-5125-10
88                S = len (x)
89                for j in range(S):
90
91                    if x[j] < shelf[i]:
92                        z[j] = -125/(shelf[i]*shelf[i])*x[j]*x[j]-10
93
94                    elif shelf[i] <= x[j] < (shelf[i]+slope[k]*0.5) :
95                          z[j] = (-o)*(x[j]-shelf[i])*(x[j]-shelf[i])-125-10
96                       
97                return z
98               
99
100
101            domain.set_quantity('elevation', topography) # Use function for elevation
102            domain.set_quantity('friction', 0)         # Constant friction   
103            domain.set_quantity('stage', 0)            # Constant negative initial stage
104            domain.tight_slope_limiters = 1
105
106            #------------------------------------------------------------------------------
107            # Setup boundary conditions
108            #------------------------------------------------------------------------------
109
110            from math import sin, pi, exp, cos, sqrt, cosh
111            Br = Reflective_boundary(domain)      # Solid reflective wall
112            Bt = Transmissive_boundary(domain)    # Continue all values on boundary
113            Bd = Dirichlet_boundary([0.,0.,0.])   # Constant boundary values
114       
115            g = 9.81
116            offshore_depth = 5145 
117            H_d_ratio = 0.0004
118            Xo = 100000
119            po = 130
120            def waveform(t):
121                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))
122         
123            Bf = Transmissive_Momentum_Set_Stage_boundary(domain, waveform)
124            # Associate boundary tags with boundary objects
125            domain.set_boundary({'left': Bd, 'right': Bf, 'top': Br, 'bottom': Br})
126
127
128            #------------------------------------------------------------------------------
129            # Evolve system through time
130            #------------------------------------------------------------------------------
131
132            for t in domain.evolve(yieldstep = 45, finaltime = (length/25)+2700+((length/50000)+1)*600+((shelf[i]/25000+1)*1000)): 
133                domain.write_time()     
134            for t in domain.evolve(yieldstep = 120, finaltime = (length/25)+2700+((length/50000)+1)*600+((shelf[i]/25000+1)*1000), 
135                                   skip_initial_step = True):
136                domain.write_time()
137
138            from anuga.shallow_water.data_manager import sww2dem
139            from os import sep
140
141            name = 'wave_value_tester_900a' 
142            time_dir = str(name)+'_'+str(wave[l])+'_50000_150000'
143            cellsize = 50
144            timestep = None
145            output_dir = sep+'d'+sep+'sim'+sep+'1'+sep+'mpittard'+sep+'idealised_bathymetry_study'+sep+'wave_value_testers'+sep
146            directory = output_dir
147            name = directory+time_dir+sep+str(name)
148            is_parallel = False
149            if is_parallel == True: nodes = 4
150            print 'output dir:', name
151
152            #var = [0,2,3] # stage, depth and speed
153            var = [0]
154
155            for which_var in var:
156                if which_var == 0:  # Stage
157                    outname = name + '_stage'
158                    quantityname = 'stage'
159
160                if which_var == 1:  # Absolute Momentum
161                    outname = name + '_momentum_i1'
162                    quantityname = '(xmomentum**2 + ymomentum**2)**0.5' 
163
164                if which_var == 2:  # Depth
165                    outname = name + '_depth'
166                    quantityname = 'stage-elevation' 
167
168                if which_var == 3:  # Speed
169                    outname = name + '_speed'
170                    quantityname = '(xmomentum**2 + ymomentum**2)**0.5/(stage-elevation+1.e-6/(stage-elevation))'  #Speed
171
172                if which_var == 4:  # Elevation
173                    outname = name + '_elevation'
174                    quantityname = 'elevation'  #Elevation
175
176                if is_parallel == True:
177                #    print 'is_parallel',is_parallel
178                    for i in range(0,nodes):
179                        namei = name + '_P%d_%d' %(i,nodes)
180                        outnamei = outname + '_P%d_%d' %(i,nodes)
181                        print 'start sww2dem for sww file %d' %(i)
182                        sww2dem(namei, basename_out = outnamei,
183                                    quantity = quantityname,
184                                    timestep = timestep,
185                                    cellsize = cellsize,     
186                                    easting_min = 0,
187                                    easting_max = 150000,
188                                    northing_min = 0,
189                                    northing_max = 400,       
190                                    reduction = max, 
191                                    verbose = True,
192                                    format = 'asc')
193                else:
194                    print 'start sww2dem'
195                    sww2dem(name, basename_out = outname,
196                                quantity = quantityname,
197                                timestep = timestep,
198                                cellsize = cellsize,     
199            ##                    easting_min = 0,
200            ##                    easting_max = 150000,
201            ##                    northing_min = 0,
202            ##                    northing_max = 400,     
203                                reduction = max, 
204                                verbose = True,
205                                format = 'asc')
206
Note: See TracBrowser for help on using the repository browser.