source: development/stochastic_study/run_model.py @ 2648

Last change on this file since 2648 was 2535, checked in by ole, 19 years ago

Histogram of mesh areas

File size: 4.7 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
46domain = pmesh_to_domain_instance(project.mesh_filename, Domain,
47                                  use_cache=True,
48                                  verbose=True)
49
50print 'Number of triangles = ', len(domain)
51print 'The extent is ', domain.get_extent()
52print domain.statistics()
53
54import sys; sys.exit()
55
56
57domain.set_datadir('.')
58domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
59
60#domain.check_integrity()
61
62
63#------------------------------------------------------------------------------
64# Setup boundary conditions
65#------------------------------------------------------------------------------
66
67function = file_function(project.boundary_filename, domain, verbose = True)
68Bts = Transmissive_Momentum_Set_Stage_boundary(domain, function) #Input wave
69Br = Reflective_boundary(domain) #Wall
70
71# Bind boundary objects to tags
72domain.set_boundary({'wave': Bts, 'wall': Br})
73
74
75#------------------------------------------------------------------------------
76# Setup initial conditions
77#------------------------------------------------------------------------------
78domain.set_quantity('friction', 0.0)
79domain.set_quantity('stage', 0.0)
80
81# Get prefitted realisations
82
83finaltime = 22.5
84timestep = 0.05
85
86
87
88realisation = 0
89for filename in os.listdir('.'):
90    if filename.startswith(project.basename) and filename.endswith('.pck'):
91        print 'Reading %s' %filename
92        fid = open(filename)
93        V = cPickle.load(fid)
94        fid.close()
95
96        # For each column (each realisation)
97        for i in range(V.shape[1]):
98            domain.set_name(project.basename)         #Output name
99            domain.set_quantity('elevation', V[:,i])  #Assign bathymetry
100            domain.starttime = 0.0                    #Reset time
101
102            #---------------------------------------------------
103            # Evolve system through time
104            #---------------------------------------------------
105            print 'Running realisation %d of %d in block %s'\
106                  %(i, V.shape[1], filename)
107            t0 = time.time()
108            for t in domain.evolve(yieldstep = timestep, finaltime = finaltime):
109                domain.write_time()
110               
111       
112            print 'Realisation %d took %.2f seconds'\
113                  %(realisation, time.time()-t0)
114
115
116
117
118            #---------------------------------------------------
119            # Now extract the 3 timeseries (Ch 5-7-9) and store them
120            # in three files for this realisation
121            gauges = [[4.521, 1.196],  [4.521, 1.696],  [4.521, 2.196]] 
122            gauge_names = ['ch5', 'ch7', 'ch9']
123
124           
125            f = file_function(domain.filename + '.sww',
126                              quantities='stage',
127                              interpolation_points=gauges,
128                              verbose = True)
129
130
131            simulation_name = domain.filename + '_realisation_%d' %realisation
132
133            for k, name in enumerate(gauge_names):
134                fid = open(simulation_name + '_' + name + '.txt', 'w')
135                for t in f.T:
136                    #For all precomputed timesteps
137                    val = f(t, point_id = k)[0]
138                    fid.write('%f %f\n' %(t, val))
139
140                fid.close()
141
142                   
143
144            realisation += 1           
Note: See TracBrowser for help on using the repository browser.