source: anuga_work/development/reef_0708/gradual_lagoon_med.py @ 5066

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