source: anuga_work/development/friction_UA_flume_2006/parallel_run_dam.py @ 5395

Last change on this file since 5395 was 5370, checked in by duncan, 16 years ago

Hinwood scenario

File size: 7.2 KB
Line 
1"""Script for running a dam break simulation of U of Aberdeen's dam break tank.
2
3
4Ole Nielsen and Duncan Gray, GA - 2006
5
6To run:
7Do
8lamboot -v ./.machines
9
10e.g.
11mpirun -c 4 python parallel_run_dam.py
12
13
14
15"""
16
17
18#----------------------------------------------------------------------------
19# Import necessary modules
20#----------------------------------------------------------------------------
21
22# Standard modules
23import time
24from time import localtime, strftime
25import sys
26from shutil import copy
27from os import path, sep
28from os.path import dirname  #, basename
29
30
31import pypar
32
33# Related major packages
34from anuga.shallow_water import Domain, Reflective_boundary, \
35                            Dirichlet_boundary, Time_boundary, File_boundary
36from anuga.abstract_2d_finite_volumes.region import Set_region
37from anuga.fit_interpolate.interpolate import interpolate_sww2csv
38from anuga.abstract_2d_finite_volumes.util import start_screen_catcher, \
39     copy_code_files
40
41
42# Scenario specific imports
43import project                 # Definition of file names and polygons
44import create_mesh
45
46def elevation_function(x,y):
47    from Numeric import zeros, size, Float
48    slope = 4 # note, get in gen mesh as well!
49   
50    z = zeros(size(x), Float)
51    for i in range(len(x)):
52        if x[i] < slope:
53            z[i] = 0.0
54        else:
55            z[i] = (x[i]-slope)*0.1
56    return z
57
58def main(friction, outputdir_name=None, is_trial_run=False):
59    basename = 'zz' + str(friction)
60    if is_trial_run is True:
61        outputdir_name += '_test'
62        yieldstep = 1
63        finaltime = 15.1
64        maximum_triangle_area=0.01
65    else:
66        yieldstep = 0.02
67        finaltime = 15.1
68        maximum_triangle_area=0.0001
69       
70        maximum_triangle_area=0.001
71       
72
73    rank = pypar.rank()  #My id
74    if 0 == rank:
75        pro_instance = project.Project(['data','flumes','dam_2007'],
76                                        outputdir_name=outputdir_name)
77        print "The output dir is", pro_instance.outputdir
78        copy_code_files(pro_instance.outputdir,__file__,
79                        dirname(project.__file__) \
80                        + sep + project.__name__+'.py')
81        copy (pro_instance.codedir + 'parallel_run_dam.py',
82              pro_instance.outputdir + 'parallel_run_dam.py')
83        copy (pro_instance.codedir + 'create_mesh.py',
84              pro_instance.outputdir + 'create_mesh.py')
85    else:
86        # wait for a bit..I don't know if I need this
87        # I do it to avoid crashes from the project code,
88        # which checks if I dir is created, and if it isn't
89        #creates it.
90        for i in range(5000):
91            pass       
92        pro_instance = project.Project(['data','flumes','dam_2007'],
93                                       outputdir_name=outputdir_name)
94           
95    mesh_filename = pro_instance.meshdir + basename + '.msh'
96
97    #--------------------------------------------------------------------------
98    # Copy scripts to output directory and capture screen
99    # output to file
100    #--------------------------------------------------------------------------
101
102    # creates copy of code in output dir
103    if is_trial_run is False:
104        start_screen_catcher(pro_instance.outputdir, rank, pypar.size())
105
106    print 'USER:    ', pro_instance.user
107    #-------------------------------------------------------------------------
108    # Create the triangular mesh
109    #-------------------------------------------------------------------------
110
111    # this creates the mesh
112    #gate_position = 12.0
113    create_mesh.generate(mesh_filename,
114                         maximum_triangle_area=maximum_triangle_area)
115
116    head,tail = path.split(mesh_filename)
117    copy (mesh_filename,
118          pro_instance.outputdir + tail )
119    #-------------------------------------------------------------------------
120    # Setup computational domain
121    #-------------------------------------------------------------------------
122    domain = Domain(mesh_filename, use_cache = False, verbose = True)
123   
124
125    print 'Number of triangles = ', len(domain)
126    print 'The extent is ', domain.get_extent()
127    print domain.statistics()
128
129   
130    domain.set_name(basename)
131    domain.set_datadir(pro_instance.outputdir)
132    domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
133    domain.set_minimum_storable_height(0.001)
134    #domain.set_store_vertices_uniquely(True)  # for writting to sww
135
136    #-------------------------------------------------------------------------
137    # Setup initial conditions
138    #-------------------------------------------------------------------------
139
140    domain.set_quantity('stage', 0.06)
141    domain.set_quantity('friction', friction) 
142    domain.set_quantity('elevation', elevation_function)
143
144   
145    print 'Available boundary tags', domain.get_boundary_tags()
146    domain.set_region('dam','stage',0.6,
147                                 location = 'unique vertices') 
148    #domain.set_region(Set_region('dam','stage',0.2,
149    #                             location = 'unique vertices'))
150
151    Br = Reflective_boundary(domain)
152    #Bd = Dirichlet_boundary([0,0,0])  # to drain the water out.
153    domain.set_boundary( {'wall': Br, 'edge': Br} )
154
155    #-------------------------------------------------------------------------
156    # Evolve system through time
157    #-------------------------------------------------------------------------
158    t0 = time.time()
159
160    for t in domain.evolve(yieldstep, finaltime):
161   
162        domain.write_time()
163        print 'That took %.2f seconds' %(time.time()-t0)
164        print 'finished'
165
166    points = [[2.8,0.225],  #-1.8m from SWL
167              [5.1,0.225],  #0.5m from SWL
168              [6.6,0.225],  #2m from SWL
169              [6.95,0.255], #2.35m from SWL
170              [7.6,0.255],  #3m from SWL
171              [8.2,0.255],  #3.5m from SWL
172              [9.2,0.255]  #4.5m from SWL
173              ]
174
175#     points = [[gate_position - 0.65,0.2],
176#               [gate_position - 0.55,0.2],
177#               [gate_position - 0.45,0.2],
178#               [gate_position - 0.35,0.2],
179#               [gate_position - 0.25,0.2]
180#               ]
181
182    #-------------------------------------------------------------------------
183    # Calculate gauge info
184    #-------------------------------------------------------------------------
185
186    interpolate_sww2csv(pro_instance.outputdir + basename +".sww",
187                        points,
188                        pro_instance.outputdir + "depth_manning_"+str(friction)+".csv",
189                        pro_instance.outputdir + "velocity_x.csv",
190                        pro_instance.outputdir + "velocity_y.csv")
191 
192    return pro_instance
193
194#-------------------------------------------------------------
195if __name__ == "__main__":
196    rank = pypar.rank()  #My id
197    size = pypar.size() #Number of MPI processes
198    node = pypar.get_processor_name()
199    frictions = [0.0, 0.005, 0.0075, 0.01, 0.0125, 0.014, 0.015,
200                 0.016, 0.017, 0.018,
201                 0.019, 0.02,
202                 0.0225, 0.025, 0.03, 0.035, 0.04] # 17 processes
203    #frictions = [0.0, 0.014]
204    for i, friction in enumerate(frictions):
205        if i%size == rank:
206            print "I am processor %d of %d on node %s" %(rank, size, node)
207            main(friction, is_trial_run = False,
208                 outputdir_name='UA_flume_built_from_scratch_0.06_stage_rough')
Note: See TracBrowser for help on using the repository browser.