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

Last change on this file since 4113 was 4109, checked in by duncan, 18 years ago

saving current scenario

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