source: anuga_validation/automated_validation_tests/okushiri_tank_validation/validate_okushiri.py @ 3757

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

Work towards automated validation of ANUGA using okushiri

File size: 5.2 KB
Line 
1"""Automated validation of ANUGA.
2
3This script runs the benchmark on a regular grid and verifies that
4the predicted timeseries at selected gauges are close enought to the observed
5timeseries provided from the experiment.
6
7See anuga_validation/okushiri_2005 for scripts that produce simulations at
8greater resolution.
9
10"""
11
12# Module imports
13from Numeric import array, zeros, Float, allclose
14
15from anuga.utilities.numerical_tools import ensure_numeric
16from anuga.shallow_water import Domain
17from anuga.shallow_water import Reflective_boundary
18from anuga.shallow_water import Transmissive_Momentum_Set_Stage_boundary
19from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
20from anuga.abstract_2d_finite_volumes.util import file_function
21
22import project
23
24try:
25    import pylab
26except:
27    plotting = False
28else:
29    plotting = True
30   
31
32finaltime = 22.5
33timestep = 0.05
34
35#-------------------------
36# Create Domain
37#-------------------------
38N = 50
39#N = 10
40points, vertices, boundary = rectangular_cross(N, N/5*3,
41                                               len1=5.448, len2=3.402)
42domain = Domain(points, vertices, boundary)
43
44domain.set_name('okushiri_automated_validation')
45domain.set_default_order(2)
46domain.set_minimum_storable_height(0.001)
47domain.check_integrity()
48
49
50#-------------------------
51# Initial Conditions
52#-------------------------
53domain.set_quantity('friction', 0.0)
54domain.set_quantity('stage', 0.0)
55domain.set_quantity('elevation',
56                    filename=project.bathymetry_filename[:-4] + '.pts',
57                    alpha=0.02,                   
58                    verbose=True,
59                    use_cache=True)
60
61#-------------------------
62# Boundary Conditions
63#-------------------------
64Br = Reflective_boundary(domain)
65
66function = file_function(project.boundary_filename[:-4] + '.tms',
67                         domain,
68                         verbose=True)
69Bts = Transmissive_Momentum_Set_Stage_boundary(domain, function)
70domain.set_boundary({'left': Bts, 'right': Br, 'bottom': Br, 'top': Br})
71
72
73#-------------------------
74# Set up validation data
75#-------------------------
76gauge_locations = [[0.000, 1.696]]  #Boundary
77gauge_locations += [[4.521, 1.196], [4.521, 1.696], [4.521, 2.196]] #Ch 5-7-9
78
79#Boundary input wave
80filename = project.boundary_filename[:-4] + '.tms'
81print 'Reading', filename
82from Scientific.IO.NetCDF import NetCDFFile
83from Numeric import allclose
84fid = NetCDFFile(filename, 'r')#
85
86input_time = fid.variables['time'][:]
87input_stage = fid.variables['stage'][:]
88
89
90# reference gauge timeseries
91reference_time = []
92ch5 = []
93ch7 = []
94ch9 = []
95fid = open('output_ch5-7-9.txt')
96lines = fid.readlines()
97fid.close()
98#for i, line in enumerate(lines[1:]):
99for line in lines[1:]:
100    fields = line.split()
101
102    reference_time.append(float(fields[0]))
103    ch5.append(float(fields[1])/100)   #cm2m
104    ch7.append(float(fields[2])/100)   #cm2m
105    ch9.append(float(fields[3])/100)   #cm2m
106
107    if fields[0] == str(finaltime): break   
108   
109
110assert reference_time[0] == 0.0
111assert reference_time[-1] == finaltime
112
113reference_gauge_values = [ensure_numeric(input_stage),
114                          ensure_numeric(ch5),
115                          ensure_numeric(ch7),
116                          ensure_numeric(ch9)] 
117
118
119
120predicted_gauge_values = [[], [], [], []]
121
122
123#-------------------------
124# Evolve through time
125#-------------------------
126import time
127t0 = time.time()
128
129for j, t in enumerate(domain.evolve(yieldstep = timestep,
130                                    finaltime = finaltime)):
131    domain.write_time()
132
133    # Record gauge values
134    stage = domain.get_quantity('stage')
135    for i, (x, y) in enumerate(gauge_locations):
136        w = stage.get_values(interpolation_points=[[x,y]])[0]
137        predicted_gauge_values[i].append(w)
138
139        #print 'difference', x, y,\
140        #      predicted_gauge_values[i][j] - reference_gauge_values[i][j]
141   
142
143#-------------------------
144# Validate
145#-------------------------
146for i, (x, y) in enumerate(gauge_locations):       
147    predicted_gauge_values[i] = ensure_numeric(predicted_gauge_values[i])
148
149    print predicted_gauge_values[i].shape
150    print reference_gauge_values[i].shape
151    #print predicted_gauge_values.shape
152    #print reference_gauge_values.shape   
153   
154    sqsum = sum((predicted_gauge_values[i].flat - \
155                 reference_gauge_values[i].flat)**2)
156    denom = sum(reference_gauge_values[i].flat**2)
157
158    print i, sqsum, sqsum/denom
159
160    msg = 'Rms error is %f' %(sqsum/denom)
161    print msg
162   
163    assert sqsum/denom < 0.01, msg
164   
165
166    if plotting is True:
167       
168        from pylab import *
169
170        ion()
171        hold(False)
172        plot(reference_time, reference_gauge_values[i], 'r.-',
173             reference_time, predicted_gauge_values[i], 'k-')
174        title('Gauge %s' %name)
175        xlabel('time(s)')
176        ylabel('stage (m)')   
177        legend(('Observed', 'Modelled'), shadow=True, loc='upper left')
178        savefig(name, dpi = 300)
179       
180        raw_input('Next')
181       
182
183if plotting is True:
184    show()
185   
186
187print 'That took %.2f seconds' %(time.time()-t0)
Note: See TracBrowser for help on using the repository browser.