source: development/stochastic_study/run_model.py @ 2878

Last change on this file since 2878 was 2866, checked in by ole, 18 years ago

Implemented Domain(meshfile) variant widely, updated documentation and added more statistics

File size: 4.9 KB
Line 
1"""Stochastic study of the ANUGA implementation of the
2shallow water wave equation.
3
4This script runs the model for one realisation of bathymetry as
5given in the file bathymetry.txt and outputs a full simulation is \
6sww NetCDF format.
7
8The left boundary condition is a timeseries defined in
9NetCDF file: input_wave.tms
10
11Note: This scripts needs create_mesh.py to have been run
12
13Suresh Kumar and Ole Nielsen 2006
14"""
15
16
17#------------------------------------------------------------------------------
18# Import necessary modules
19#------------------------------------------------------------------------------
20
21# Standard modules
22import os
23import time
24import cPickle
25
26# Related major packages
27from pyvolution.shallow_water import Domain
28from pyvolution.shallow_water import Reflective_boundary
29from pyvolution.shallow_water import Transmissive_Momentum_Set_Stage_boundary
30from pyvolution.pmesh2domain import pmesh_to_domain_instance
31from pyvolution.data_manager import xya2pts
32from pyvolution.util import file_function
33from caching.caching import cache
34
35# Application specific imports
36import project                 # Definition of file names and polygons
37
38
39
40
41#-----------------------------------------------------------------------------
42# Setup computational domain
43#-----------------------------------------------------------------------------
44print 'Creating domain from', project.mesh_filename
45
46#domain = pmesh_to_domain_instance(project.mesh_filename, Domain,
47#                                  use_cache=True,
48#                                  verbose=True)
49
50domain = Domain(project.mesh_filename,
51                use_cache=True,
52                verbose=True)               
53               
54
55print 'Number of triangles = ', len(domain)
56print 'The extent is ', domain.get_extent()
57print domain.statistics()
58
59import sys; sys.exit()
60
61
62domain.set_datadir('.')
63domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
64
65#domain.check_integrity()
66
67
68#------------------------------------------------------------------------------
69# Setup boundary conditions
70#------------------------------------------------------------------------------
71
72function = file_function(project.boundary_filename, domain, verbose = True)
73Bts = Transmissive_Momentum_Set_Stage_boundary(domain, function) #Input wave
74Br = Reflective_boundary(domain) #Wall
75
76# Bind boundary objects to tags
77domain.set_boundary({'wave': Bts, 'wall': Br})
78
79
80#------------------------------------------------------------------------------
81# Setup initial conditions
82#------------------------------------------------------------------------------
83domain.set_quantity('friction', 0.0)
84domain.set_quantity('stage', 0.0)
85
86# Get prefitted realisations
87
88finaltime = 22.5
89timestep = 0.05
90
91
92
93realisation = 0
94for filename in os.listdir('.'):
95    if filename.startswith(project.basename) and filename.endswith('.pck'):
96        print 'Reading %s' %filename
97        fid = open(filename)
98        V = cPickle.load(fid)
99        fid.close()
100
101        # For each column (each realisation)
102        for i in range(V.shape[1]):
103            domain.set_name(project.basename)         #Output name
104            domain.set_quantity('elevation', V[:,i])  #Assign bathymetry
105            domain.starttime = 0.0                    #Reset time
106
107            #---------------------------------------------------
108            # Evolve system through time
109            #---------------------------------------------------
110            print 'Running realisation %d of %d in block %s'\
111                  %(i, V.shape[1], filename)
112            t0 = time.time()
113            for t in domain.evolve(yieldstep = timestep, finaltime = finaltime):
114                domain.write_time()
115               
116       
117            print 'Realisation %d took %.2f seconds'\
118                  %(realisation, time.time()-t0)
119
120
121
122
123            #---------------------------------------------------
124            # Now extract the 3 timeseries (Ch 5-7-9) and store them
125            # in three files for this realisation
126            gauges = [[4.521, 1.196],  [4.521, 1.696],  [4.521, 2.196]] 
127            gauge_names = ['ch5', 'ch7', 'ch9']
128
129           
130            f = file_function(domain.filename + '.sww',
131                              quantities='stage',
132                              interpolation_points=gauges,
133                              verbose = True)
134
135
136            simulation_name = domain.filename + '_realisation_%d' %realisation
137
138            for k, name in enumerate(gauge_names):
139                fid = open(simulation_name + '_' + name + '.txt', 'w')
140                for t in f.T:
141                    #For all precomputed timesteps
142                    val = f(t, point_id = k)[0]
143                    fid.write('%f %f\n' %(t, val))
144
145                fid.close()
146
147                   
148
149            realisation += 1           
Note: See TracBrowser for help on using the repository browser.