source: anuga_core/source/anuga/shallow_water/xtest_Bf.py @ 4360

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

Mux to sww tests almost finished
added field_boundary to _init_

File size: 9.6 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
84from caching import cache
85cache(urs2sww,
86          (boundaries_dir_name,
87           boundaries_dir_name), 
88          {'verbose': False,
89           'mint': 9200, 'maxt': 11200,
90#           'origin': domain.geo_reference.get_origin(),
91           'fail_on_NaN': False},
92           verbose = False,
93           )
94   
95#-------------------------------------------------------------------------
96# Setup initial conditions
97#-------------------------------------------------------------------------
98
99#print 'Start Set quantity'
100
101domain.set_quantity('elevation', -42.3)
102
103#print 'Finished Set quantity'
104
105#------------------------------------------------------
106# Set domain parameters
107#------------------------------------------------------
108
109domain.set_quantity('stage', tide)
110domain.set_quantity('friction', 0.01)
111domain.set_name(fileName)
112domain.set_datadir(out_dir)
113
114#-------------------------------------------------------------------------
115# Setup boundary conditions
116#-------------------------------------------------------------------------
117#Bf = File_boundary(out_dir + 'o_test_8500_12000.sww',
118#                  domain, time_thinning=24, use_cache=True, verbose=True)
119Bf = Field_boundary(out_dir + 'o_test.sww',
120                  domain, mean_stage=tide, use_cache=True, verbose=False)
121
122#print 'finished reading boundary file'
123
124#Br = Reflective_boundary(domain)
125Bt = Transmissive_boundary(domain)
126Bd = Dirichlet_boundary([tide,0,0])
127
128#print'set_boundary'
129
130domain.set_boundary({'back': Bt,
131                     'side': Bd,
132                    'ocean': Bf
133                    })
134#print'finish set boundary'
135
136#----------------------------------------------------------------------------
137# Evolve system through time
138#----------------------------------------------------------------------------
139
140#remove mesh file!!! and o_test.sww
141t0 = time.time()
142
143for t in domain.evolve(yieldstep = 60, finaltime = 1920):
144    domain.write_time()
145#    domain.write_boundary_statistics()
146
147
148
149#Gets timeseries from boundary sww and evolved sww
150home = getenv('INUNDATIONHOME') #Sandpit's parent dir   
151#user = get_user_name()
152data = 'data'
153state = 'western_australia'
154scenario_name = 'dampier.sww'
155
156scenario = 'dampier_tsunami_scenario_2006'
157#scenario = 'test_dampier'
158an = 'anuga'
159bo = 'boundaries'
160
161run_time = 'blank'
162#run_time = project.run_time
163production_dirs = {run_time: 'URS evolved data'#,
164                   #'boundaries': 'URS boundary condition'
165                   }
166
167topo = 'topographies'
168out = 'outputs'
169urs = 'urs'
170gridded = '1_10000'
171
172
173#gauge_boundary_filename = 'boundary_gauge_near_top.csv'
174gauge_boundary_filename = 'gauges_time_series_b_near_top.csv'
175gauge_evolved_filename = 'gauges_time_series_near_top.csv'
176
177boundary_dir_filename = os.path.join(out_dir,gauge_boundary_filename)
178#print'boundary_dir_filename',boundary_dir_filename
179
180evolved_dir_filename= os.path.join(out_dir,gauge_evolved_filename)
181
182#print'boundary_dir_filename',boundary_dir_filename
183#print'evolved_dir_filename',evolved_dir_filename
184                                     
185swwfiles = {}
186swwfile = out_dir + fileName + '.sww'
187swwfiles[swwfile] = run_time
188#print"swwfiles",swwfiles,"shallow_water"
189       
190texname, elev_output = sww2timeseries(swwfiles,
191                                      out_dir+sep+"gauges.csv",
192                                      production_dirs,
193                                      report = False,
194                                      plot_quantity = ['stage', 'xmomentum', 'ymomentum'],
195                                      surface = False,
196                                      time_min = None,
197                                      time_max = None,
198                                      title_on = False,
199                                      use_cache = True,
200                                      verbose = False)
201                                     
202swwfiles = {}
203swwfile = out_dir + boundaries_dir_name + '.sww'
204swwfiles[swwfile] = run_time
205#print"swwfiles",swwfiles,"shallow_water"
206       
207texname, elev_output = sww2timeseries(swwfiles,
208                                      out_dir+sep+"boundary_gauges.csv",
209                                      production_dirs,
210                                      report = False,
211                                      plot_quantity = ['stage', 'xmomentum', 'ymomentum'],
212                                      surface = False,
213                                      time_min = None,
214                                      time_max = None,
215                                      title_on = False,
216                                      use_cache = True,
217                                      verbose = False)
218
219#makes the csv files from the evolved model
220e_header, e_data = get_data_from_file(evolved_dir_filename)
221
222e_time = e_data[:,0]
223e_stage = e_data[:,1]
224e_momentum = e_data[:,2]
225e_speed = e_data[:,3]
226e_elevation = e_data[:,4]
227
228#print'boundary_dir_filename',boundary_dir_filename
229b_header, b_data = get_data_from_file(boundary_dir_filename)
230
231b_time = b_data[:,0]
232b_stage = b_data[:,1]
233b_momentum = b_data[:,2]
234b_speed = b_data[:,3]
235b_elevation = b_data[:,4]
236
237
238# compares the 2 models
239j=0
240k=0
241b_sample = []
242e_sample = []
243for i in range(len(b_time)):
244#    if j<(len(e_time)) and b_time[i] == e_time[j]:
245    if j<(len(e_time)) and k<(len(e_time)) and b_time[i] == e_time[j]:
246        b_sample.append(float(tide+b_stage[i]))
247        e_sample.append(float(e_stage[k]))
248#        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)
249        j = j +1
250        k = k +1
251
252
253#print len(b_sample), len(e_stage),e_stage,type(e_stage)
254e_stage = e_stage.tolist()
255e_stage.pop()
256#e_stage.pop()
257 
258#print len(b_sample), len(e_stage),e_stage
259
260
261#assert allclose (b_sample, e_stage, 0.2, 0.2)
262print "test successful" 
263os.remove(fileName+'.sww')
264#print 'evolved_dir_filename',evolved_dir_filename
265os.remove('gauges_time_series_near_top.csv')
266os.remove('gauges_time_series_b_near_top.csv')
267os.remove('gauges_t0.csv')
268os.remove('gauges_maxmins.csv')
269os.remove(meshes_dir_name)
270
271
272assert allclose (b_sample, e_sample, 0.5, 0.5)
273
274
275
276
277
278
279
280                             
281                             
282                                         
283
284
285
286
287
Note: See TracBrowser for help on using the repository browser.