source: trunk/anuga_core/demos/checkpointing/runCheckpoint.py @ 9293

Last change on this file since 9293 was 9269, checked in by steve, 11 years ago

Doing a bit of updating to user_manual

File size: 5.4 KB
Line 
1
2"""Run parallel shallow water domain.
3
4with check pointing
5"""
6
7
8
9#------------------------------------------------------------------------------
10# Import necessary modules
11#------------------------------------------------------------------------------
12
13import os
14import sys
15import time
16import numpy as num
17
18#------------------------
19# ANUGA Modules
20#------------------------
21from anuga import Reflective_boundary
22from anuga import Transmissive_n_momentum_zero_t_momentum_set_stage_boundary
23
24from anuga import create_domain_from_file
25
26from anuga import distribute, myid, numprocs, finalize, barrier
27
28
29#--------------------------------------------------------------------------
30# Setup parameters
31#--------------------------------------------------------------------------
32
33verbose = False
34domain_name = 'checkpoint'
35checkpoint_dir = 'CHECKPOINTS'
36finaltime = 1000.0
37useCheckpointing = True
38
39
40mesh_filename = "merimbula_17156.tsh"   ; x0 = 756000.0 ; x1 = 756500.0; yieldstep = 50
41
42
43
44#--------------------------------------------------------------------------
45# Setup procedures
46#--------------------------------------------------------------------------
47class Set_Stage:
48    """Set an initial condition with constant water height, for x0<x<x1
49    """
50
51    def __init__(self, x0=0.25, x1=0.5, h=1.0):
52        self.x0 = x0
53        self.x1 = x1
54        self.= h
55
56    def __call__(self, x, y):
57        return self.h*((x>self.x0)&(x<self.x1))+1.0
58
59
60class Set_Elevation:
61    """Set an elevation
62    """
63
64    def __init__(self, h=1.0):
65        self.x0 = x0
66        self.x1 = x1
67        self.= h
68
69    def __call__(self, x, y):
70        return x/self.h
71   
72def wave(t):
73    from math import sin
74    return 10*sin(t/60) 
75
76#------------------------------------------------------------------------------
77# Try to read in previous checkpoint file and if not possible
78# just go ahead as normal and produce domain as usual
79#------------------------------------------------------------------------------
80try:
81       
82    from anuga import load_checkpoint_file
83   
84    domain = load_checkpoint_file(domain_name = domain_name, checkpoint_dir = checkpoint_dir)
85
86except:
87    #--------------------------------------------------------------------------
88    # Setup Domain only on processor 0
89    #--------------------------------------------------------------------------
90    if myid == 0:
91        domain = create_domain_from_file(mesh_filename)
92        domain.set_quantity('stage', Set_Stage(x0, x1, 1.0))
93
94        domain.set_name(domain_name)
95        domain.set_store(True)
96
97        domain.set_store_vertices_smoothly(False)
98    else:
99        domain = None
100   
101    #--------------------------------------------------------------------------
102    # Distribute sequential domain on processor 0 to other processors
103    #--------------------------------------------------------------------------
104   
105    if myid == 0 and verbose: print 'DISTRIBUTING DOMAIN'
106    domain = distribute(domain, verbose=verbose)
107   
108    #--------------------------------------------------------------------------
109    # On all processors, setup evolve parameters for domains on all processors
110    # (all called "domain"
111    #--------------------------------------------------------------------------
112   
113    domain.set_flow_algorithm('DE0')
114    domain.set_store_centroids()
115   
116    domain.set_quantities_to_be_stored({'elevation':1,
117                                        'friction':1,
118                                        'stage':2,
119                                        'xmomentum':2,
120                                        'ymomentum':2})
121                                     
122    #------------------------------------------------------------------------------
123    # Setup boundary conditions
124    # This must currently happen *after* domain has been distributed
125    #------------------------------------------------------------------------------
126    Br = Reflective_boundary(domain)      # Solid reflective wall
127   
128    Bts = Transmissive_n_momentum_zero_t_momentum_set_stage_boundary(domain, wave)
129   
130    domain.set_boundary({'outflow' :Br, 'inflow' :Br, 'inner' :Br, 'exterior' :Br, 'open' :Bts})
131   
132   
133    #-----------------------------------------------------------------------------
134    # Turn on checkpointing every 5 sec (just for testing, more reasonable to
135    # set to 15 minutes = 15*60 sec
136    #-----------------------------------------------------------------------------
137    if useCheckpointing:
138        domain.set_checkpointing(checkpoint_time = 5)
139
140
141
142#------------------------------------------------------------------------------
143# Evolution
144#------------------------------------------------------------------------------
145if myid == 0 and verbose: print 'EVOLVE'
146
147barrier()
148import time
149t0 = time.time()
150
151
152for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime):
153    if myid == 0: domain.write_time()
154   
155
156barrier()
157
158for p in range(numprocs):
159    if myid == p:
160        print 'Processor %g ' %myid
161        print 'That took %.2f seconds' %(time.time()-t0)
162        print 'Communication time %.2f seconds'%domain.communication_time
163        print 'Reduction Communication time %.2f seconds'%domain.communication_reduce_time
164        print 'Broadcast time %.2f seconds'%domain.communication_broadcast_time
165    else:
166        pass
167
168    barrier()
169
170
171#--------------------------------------------------
172# Merge the individual sww files into one file
173#--------------------------------------------------
174domain.sww_merge()
175
176
177#domain.dump_triangulation()
178
179finalize()
Note: See TracBrowser for help on using the repository browser.