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

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

new UA friction scenario - elevation calculated by a function, initial stage of 0.06

File size: 7.3 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
49def elevation_function(x,y):
50    from Numeric import zeros, size, Float
51    slope = 4 # note, get in gen mesh as well!
52   
53    z = zeros(size(x), Float)
54    for i in range(len(x)):
55        if x[i] < slope:
56            z[i] = 0.0
57        else:
58            z[i] = (x[i]-slope)*0.1
59    return z
60
61def main(friction, outputdir_name=None, is_trial_run=False):
62    basename = 'zz' + str(friction)
63    if is_trial_run is True:
64        outputdir_name += '_test'
65        yieldstep = 1
66        finaltime = 15.1
67        maximum_triangle_area=0.01
68    else:
69        yieldstep = 0.02
70        finaltime = 15.1
71        maximum_triangle_area=0.0001
72       
73        maximum_triangle_area=0.001
74       
75
76    rank = pypar.rank()  #My id
77    if 0 == rank:
78        pro_instance = project.Project(['data','flumes','dam_2007'],
79                                        outputdir_name=outputdir_name)
80        print "The output dir is", pro_instance.outputdir
81        copy_code_files(pro_instance.outputdir,__file__,
82                        dirname(project.__file__) \
83                        + sep + project.__name__+'.py')
84        copy (pro_instance.codedir + 'run_dam.py',
85              pro_instance.outputdir + 'run_dam.py')
86        copy (pro_instance.codedir + 'create_mesh.py',
87              pro_instance.outputdir + 'create_mesh.py')
88    else:
89        # wait for a bit..I don't know if I need this
90        # I do it to avoid crashes from the project code,
91        # which checks if I dir is created, and if it isn't
92        #creates it.
93        for i in range(5000):
94            pass       
95        pro_instance = project.Project(['data','flumes','dam_2007'],
96                                       outputdir_name=outputdir_name)
97           
98    mesh_filename = pro_instance.meshdir + basename + '.msh'
99
100    #--------------------------------------------------------------------------
101    # Copy scripts to output directory and capture screen
102    # output to file
103    #--------------------------------------------------------------------------
104
105    # creates copy of code in output dir
106    if is_trial_run is False:
107        start_screen_catcher(pro_instance.outputdir, rank, pypar.size())
108
109    print 'USER:    ', pro_instance.user
110    #-------------------------------------------------------------------------
111    # Create the triangular mesh
112    #-------------------------------------------------------------------------
113
114    # this creates the mesh
115    #gate_position = 12.0
116    create_mesh.generate(mesh_filename,
117                         maximum_triangle_area=maximum_triangle_area)
118
119    head,tail = path.split(mesh_filename)
120    copy (mesh_filename,
121          pro_instance.outputdir + tail )
122    #-------------------------------------------------------------------------
123    # Setup computational domain
124    #-------------------------------------------------------------------------
125    domain = Domain(mesh_filename, use_cache = False, verbose = True)
126   
127
128    print 'Number of triangles = ', len(domain)
129    print 'The extent is ', domain.get_extent()
130    print domain.statistics()
131
132   
133    domain.set_name(basename)
134    domain.set_datadir(pro_instance.outputdir)
135    domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
136    domain.set_minimum_storable_height(0.001)
137    #domain.set_store_vertices_uniquely(True)  # for writting to sww
138
139    #-------------------------------------------------------------------------
140    # Setup initial conditions
141    #-------------------------------------------------------------------------
142
143    domain.set_quantity('stage', 0.06) # initial
144    domain.set_quantity('friction', friction) 
145    domain.set_quantity('elevation', elevation_function)
146
147   
148    print 'Available boundary tags', domain.get_boundary_tags()
149    domain.set_region('dam','stage',0.6,
150                                 location = 'unique vertices') 
151    #domain.set_region(Set_region('dam','stage',0.2,
152    #                             location = 'unique vertices'))
153
154    Br = Reflective_boundary(domain)
155    #Bd = Dirichlet_boundary([0,0,0])  # to drain the water out.
156    domain.set_boundary( {'wall': Br, 'edge': Br} )
157
158    #-------------------------------------------------------------------------
159    # Evolve system through time
160    #-------------------------------------------------------------------------
161    t0 = time.time()
162
163    for t in domain.evolve(yieldstep, finaltime):
164   
165        domain.write_time()
166        print 'That took %.2f seconds' %(time.time()-t0)
167        print 'finished'
168
169    points = [[2.8,0.225],  #-1.8m from SWL
170              [5.1,0.225],  #0.5m from SWL
171              [6.6,0.225],  #2m from SWL
172              [6.95,0.255], #2.35m from SWL
173              [7.6,0.255],  #3m from SWL
174              [8.1,0.255],  #3.5m from SWL
175              [9.1,0.255]  #4.5m from SWL
176              ]
177
178#     points = [[gate_position - 0.65,0.2],
179#               [gate_position - 0.55,0.2],
180#               [gate_position - 0.45,0.2],
181#               [gate_position - 0.35,0.2],
182#               [gate_position - 0.25,0.2]
183#               ]
184
185    #-------------------------------------------------------------------------
186    # Calculate gauge info
187    #-------------------------------------------------------------------------
188
189    interpolate_sww2csv(pro_instance.outputdir + basename +".sww",
190                        points,
191                        pro_instance.outputdir + "depth_manning_"+str(friction)+".csv",
192                        pro_instance.outputdir + "velocity_x.csv",
193                        pro_instance.outputdir + "velocity_y.csv")
194 
195    return pro_instance
196
197#-------------------------------------------------------------
198if __name__ == "__main__":
199    rank = pypar.rank()  #My id
200    size = pypar.size() #Number of MPI processes
201    node = pypar.get_processor_name()
202    frictions = [0.0, 0.005, 0.0075, 0.01, 0.0125, 0.014, 0.015,
203                 0.016, 0.017, 0.018,
204                 0.019, 0.02,
205                 0.0225, 0.025, 0.03, 0.035, 0.04] # 17 processes
206    frictions = [0.0, 0.014]
207    for i, friction in enumerate(frictions):
208        if i%size == rank:
209            print "I am processor %d of %d on node %s" %(rank, size, node)
210            main(friction, is_trial_run = True,
211                 outputdir_name='friction_UA_new_meshII_0.06_stageIII')
Note: See TracBrowser for help on using the repository browser.