source: anuga_validation/automated_validation_tests/urs_mux_files_validation/run_Bf.py @ 4408

Last change on this file since 4408 was 4408, checked in by nick, 17 years ago

update to automated tests

File size: 9.8 KB
Line 
1"""
2
3this test compares the gauge data from a boundary sww file which is precomputed and
4stored in this directory, and the same gauge location from a simple model that uses
5the same boundary sww file for its boundary conditions
6
7Basically tests that file_boundary and evolve is working correctly
8"""
9
10#------------------------------------------------------------------------------
11# Import necessary modules
12#------------------------------------------------------------------------------
13
14# Standard modules
15from os import sep,getcwd, access, F_OK, mkdir, getenv
16from os.path import dirname, basename,abspath
17from shutil import copy
18import time, sys, os, tempfile
19#import sys
20#import os
21#import tempfile
22
23# Related major packages
24from anuga.shallow_water import Domain,Dirichlet_boundary,File_boundary,Transmissive_boundary, Field_boundary
25#from anuga.shallow_water.shallow_water_domain import Field_boundary
26from Numeric import allclose, array
27from anuga.pmesh.mesh_interface import create_mesh_from_regions
28from anuga.abstract_2d_finite_volumes.util import start_screen_catcher, copy_code_files, sww2timeseries, get_data_from_file
29#from anuga.caching import myhash
30# Application specific imports
31
32#------------------------------------------------------------------------------
33# Copy scripts to time stamped output directory and capture screen
34# output to file
35#------------------------------------------------------------------------------
36out_dir = dirname(abspath(__file__))+sep
37#print'temp_name'
38fileName="temp"
39#import sys
40#sys.exit()
41meshes_dir_name = 'small.tsh' # this will be local
42
43tide = 2.4
44
45
46#EVOLVED MODEL
47
48#--------------------------------------------------------------------------
49# Create the triangular mesh based on overall clipping polygon with a
50# tagged
51# boundary and interior regions defined in project.py along with
52# resolutions (maximal area of per triangle) for each polygon
53#--------------------------------------------------------------------------
54
55#all = [[469000,7760000],[470000,7758000],[468000,7758000]]
56#all = [[470000,7760000],[469000,7758000],[468000,7760000]]
57
58#all_large = [[474000,7764000],[474000,7756000],[466000,7756000],[466000,7764000]]
59#all = [[470000,7764000],[470000,7756000],[466000,7756000],[466000,7764000]]
60all = [[465184,7764500],[470397,7764510],[470407,7758988],[465195,7758979]]
61# N, W, S, E
62
63create_mesh_from_regions(all,
64#                             boundary_tags={'ocean': [0,1,2]},
65#                             boundary_tags={'ocean': [ 2],'side': [0, 1]},
66                             boundary_tags={'ocean': [ 0],'side': [1, 3], 'back': [2]},
67                             maximum_triangle_area=50000,
68                             filename=meshes_dir_name,
69                             use_cache=False,
70#                             verbose=True
71                             )
72
73#-------------------------------------------------------------------------
74# Setup computational domain
75#-------------------------------------------------------------------------
76#print 'Setup computational domain'
77domain = Domain( meshes_dir_name, verbose=True)
78
79from anuga.shallow_water.data_manager import urs2sww
80boundaries_dir_name = 'o_test'
81
82# convert MUX urs files to an SWW file output
83#print 'boundary file is: ',boundaries_dir_name
84'''
85from caching import cache
86cache(urs2sww,
87          (boundaries_dir_name,
88           boundaries_dir_name),
89          {'verbose': False,
90           'mint': 9200, 'maxt': 11200,
91#           'origin': domain.geo_reference.get_origin(),
92           'fail_on_NaN': False},
93           verbose = True,
94           )
95'''
96urs2sww(boundaries_dir_name,boundaries_dir_name,
97           mint=9200, maxt= 11200,
98#           'origin': domain.geo_reference.get_origin(),
99           fail_on_NaN= False,
100           verbose=True)
101   
102#-------------------------------------------------------------------------
103# Setup initial conditions
104#-------------------------------------------------------------------------
105
106#print 'Start Set quantity'
107
108domain.set_quantity('elevation', -42.3)
109
110#print 'Finished Set quantity'
111
112#------------------------------------------------------
113# Set domain parameters
114#------------------------------------------------------
115
116domain.set_quantity('stage', tide)
117domain.set_quantity('friction', 0.01)
118domain.set_name(fileName)
119domain.set_datadir(out_dir)
120
121#-------------------------------------------------------------------------
122# Setup boundary conditions
123#-------------------------------------------------------------------------
124#Bf = File_boundary(out_dir + 'o_test_8500_12000.sww',
125#                  domain, time_thinning=24, use_cache=True, verbose=True)
126Bf = Field_boundary(out_dir + 'o_test.sww',
127                  domain, mean_stage=tide, use_cache=True, verbose=False)
128
129#print 'finished reading boundary file'
130
131#Br = Reflective_boundary(domain)
132Bt = Transmissive_boundary(domain)
133Bd = Dirichlet_boundary([tide,0,0])
134
135#print'set_boundary'
136
137domain.set_boundary({'back': Bt,
138                     'side': Bd,
139                    'ocean': Bf
140                    })
141#print'finish set boundary'
142
143#----------------------------------------------------------------------------
144# Evolve system through time
145#----------------------------------------------------------------------------
146
147#remove mesh file!!! and o_test.sww
148t0 = time.time()
149
150for t in domain.evolve(yieldstep = 60, finaltime = 1920):
151    domain.write_time()
152    domain.write_boundary_statistics()
153
154
155
156#Gets timeseries from boundary sww and evolved sww
157home = getenv('INUNDATIONHOME') #Sandpit's parent dir   
158#user = get_user_name()
159data = 'data'
160state = 'western_australia'
161scenario_name = 'dampier.sww'
162
163scenario = 'dampier_tsunami_scenario_2006'
164#scenario = 'test_dampier'
165an = 'anuga'
166bo = 'boundaries'
167
168run_time = 'blank'
169#run_time = project.run_time
170production_dirs = {run_time: 'URS evolved data'#,
171                   #'boundaries': 'URS boundary condition'
172                   }
173
174topo = 'topographies'
175out = 'outputs'
176urs = 'urs'
177gridded = '1_10000'
178
179
180#gauge_boundary_filename = 'boundary_gauge_near_top.csv'
181gauge_boundary_filename = 'gauges_time_series_b_near_top.csv'
182gauge_evolved_filename = 'gauges_time_series_near_top.csv'
183
184boundary_dir_filename = os.path.join(out_dir,gauge_boundary_filename)
185#print'boundary_dir_filename',boundary_dir_filename
186
187evolved_dir_filename= os.path.join(out_dir,gauge_evolved_filename)
188
189#print'boundary_dir_filename',boundary_dir_filename
190#print'evolved_dir_filename',evolved_dir_filename
191                                     
192swwfiles = {}
193swwfile = out_dir + fileName + '.sww'
194swwfiles[swwfile] = run_time
195#print"swwfiles",swwfiles,"shallow_water"
196       
197texname, elev_output = sww2timeseries(swwfiles,
198                                      out_dir+sep+"gauges.csv",
199                                      production_dirs,
200                                      report = False,
201                                      plot_quantity = ['stage', 'xmomentum', 'ymomentum'],
202                                      surface = False,
203                                      time_min = None,
204                                      time_max = None,
205                                      title_on = False,
206                                      use_cache = True,
207                                      verbose = False)
208                                     
209swwfiles = {}
210swwfile = out_dir + boundaries_dir_name + '.sww'
211swwfiles[swwfile] = run_time
212#print"swwfiles",swwfiles,"shallow_water"
213       
214texname, elev_output = sww2timeseries(swwfiles,
215                                      out_dir+sep+"boundary_gauges.csv",
216                                      production_dirs,
217                                      report = False,
218                                      plot_quantity = ['stage', 'xmomentum', 'ymomentum'],
219                                      surface = False,
220                                      time_min = None,
221                                      time_max = None,
222                                      title_on = False,
223                                      use_cache = True,
224                                      verbose = False)
225
226#makes the csv files from the evolved model
227e_header, e_data = get_data_from_file(evolved_dir_filename)
228
229e_time = e_data[:,0]
230e_stage = e_data[:,1]
231e_momentum = e_data[:,2]
232e_speed = e_data[:,3]
233e_elevation = e_data[:,4]
234
235#print'boundary_dir_filename',boundary_dir_filename
236b_header, b_data = get_data_from_file(boundary_dir_filename)
237
238b_time = b_data[:,0]
239b_stage = b_data[:,1]
240b_momentum = b_data[:,2]
241b_speed = b_data[:,3]
242b_elevation = b_data[:,4]
243
244
245# compares the 2 models
246j=0
247k=0
248b_sample = []
249e_sample = []
250for i in range(len(b_time)):
251#    if j<(len(e_time)) and b_time[i] == e_time[j]:
252    if j<(len(e_time)) and k<(len(e_time)) and b_time[i] == e_time[j]:
253        b_sample.append(float(tide+b_stage[i]))
254        e_sample.append(float(e_stage[k]))
255#        if k <len(e_time): print 'time e equal b:', b_time[i],i, j, b_stage[i], b_sample[i], e_stage[k],(len(e_time)-1)
256        j = j +1
257        k = k +1
258
259
260#print len(b_sample), len(e_stage),e_stage,type(e_stage)
261e_stage = e_stage.tolist()
262e_stage.pop()
263#e_stage.pop()
264 
265#print len(b_sample), len(e_stage),e_stage
266
267
268#assert allclose (b_sample, e_stage, 0.2, 0.2)
269print "test successful" 
270print 'fileName',fileName+'.sww'
271os.remove(fileName+'.sww')
272#print 'evolved_dir_filename',evolved_dir_filename
273os.remove('gauges_time_series_near_top.csv')
274os.remove('gauges_time_series_b_near_top.csv')
275os.remove('gauges_t0.csv')
276os.remove('gauges_maxmins.csv')
277os.remove(meshes_dir_name)
278
279
280assert allclose (b_sample, e_sample, 0.5, 0.5)
281
282
283
284
285
286
287
288                             
289                             
290                                         
291
292
293
294
295
Note: See TracBrowser for help on using the repository browser.