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

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

Work on automated okushiri island validation

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