source: trunk/anuga_core/examples/checkpointing/runCheckpoint.py @ 9680

Last change on this file since 9680 was 9675, checked in by steve, 10 years ago

Updating anuga manual

File size: 5.7 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
39mesh_filename = "merimbula_10785_1.tsh"
40x0 = 756000.0
41x1 = 756500.0
42yieldstep = 50
43
44
45
46#--------------------------------------------------------------------------
47# Setup procedures
48#--------------------------------------------------------------------------
49class Set_Stage:
50    """Set an initial condition with constant water height, for x0<x<x1
51    """
52
53    def __init__(self, x0=0.25, x1=0.5, h=1.0):
54        self.x0 = x0
55        self.x1 = x1
56        self.= h
57
58    def __call__(self, x, y):
59        return self.h*((x>self.x0)&(x<self.x1))+1.0
60
61
62class Set_Elevation:
63    """Set an elevation
64    """
65
66    def __init__(self, h=1.0):
67        self.x0 = x0
68        self.x1 = x1
69        self.= h
70
71    def __call__(self, x, y):
72        return x/self.h
73   
74def wave(t):
75    from math import sin
76    return sin(t/200) 
77
78#------------------------------------------------------------------------------
79# Use a try statement to read in previous checkpoint file and if not possible
80# just go ahead as normal and produce domain as usual.
81#
82# Though in the part of the code where you create the domain as normal,
83# remember to turn on checkpointing via
84# domain.set_checkpointing(checkpoint_time = 5) (see code below)
85#------------------------------------------------------------------------------
86try:
87       
88    from anuga import load_checkpoint_file
89   
90    domain = load_checkpoint_file(domain_name = domain_name, 
91                                  checkpoint_dir = checkpoint_dir)
92
93except:
94    #--------------------------------------------------------------------------
95    # Normal Setup of Domain on processor 0
96    #--------------------------------------------------------------------------
97    if myid == 0:
98        domain = create_domain_from_file(mesh_filename)
99        domain.set_quantity('stage', Set_Stage(x0, x1, 1.0))
100
101        domain.set_name(domain_name)
102        domain.set_store(True)
103
104        domain.set_store_vertices_smoothly(False)
105    else:
106        domain = None
107   
108    #--------------------------------------------------------------------------
109    # Distribute sequential domain on processor 0 to other processors
110    #--------------------------------------------------------------------------
111   
112    if myid == 0 and verbose: print 'DISTRIBUTING DOMAIN'
113    domain = distribute(domain, verbose=verbose)
114   
115    #--------------------------------------------------------------------------
116    # On all processors, setup evolve parameters for domains on all processors
117    # (all called "domain"
118    #--------------------------------------------------------------------------
119   
120    domain.set_flow_algorithm('DE0')
121    domain.set_store_centroids()
122   
123    domain.set_quantities_to_be_stored({'elevation':1,
124                                        'friction':1,
125                                        'stage':2,
126                                        'xmomentum':2,
127                                        'ymomentum':2})
128                                     
129    #------------------------------------------------------------------------------
130    # Setup boundary conditions
131    # This must currently happen *after* domain has been distributed
132    #------------------------------------------------------------------------------
133    Br = Reflective_boundary(domain)      # Solid reflective wall
134   
135    Bts = Transmissive_n_momentum_zero_t_momentum_set_stage_boundary(domain, wave)
136   
137    domain.set_boundary({'outflow' :Br, 'inflow' :Br, 'inner' :Br, 
138                         'exterior' :Br, 'open' :Bts})
139   
140   
141    #-----------------------------------------------------------------------------
142    # Turn on checkpointing every 5 sec (just for testing, more reasonable to
143    # set to 15 minutes = 15*60 sec
144    #-----------------------------------------------------------------------------
145    if useCheckpointing:
146        domain.set_checkpointing(checkpoint_time = 5)
147
148
149
150#------------------------------------------------------------------------------
151# Evolution
152#------------------------------------------------------------------------------
153if myid == 0 and verbose: print 'EVOLVE'
154
155barrier()
156import time
157t0 = time.time()
158
159
160for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime):
161    if myid == 0: domain.write_time()
162   
163
164barrier()
165
166for p in range(numprocs):
167    if myid == p:
168        print 'Processor %g ' %myid
169        print 'That took %.2f seconds' %(time.time()-t0)
170        print 'Communication time %.2f seconds'%domain.communication_time
171        print 'Reduction Communication time %.2f seconds' \
172               %domain.communication_reduce_time
173        print 'Broadcast time %.2f seconds'%domain.communication_broadcast_time
174    else:
175        pass
176
177    barrier()
178
179
180#--------------------------------------------------
181# Merge the individual sww files into one file
182# But don't delete the sub domain sww files
183#--------------------------------------------------
184domain.sww_merge()
185
186
187finalize()
Note: See TracBrowser for help on using the repository browser.