Changeset 3722


Ignore:
Timestamp:
Oct 10, 2006, 11:47:18 AM (18 years ago)
Author:
ole
Message:

Work on automated okushiri island validation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_validation/automated_validation_tests/okushiri_tank_validation/validate_okushiri.py

    r3718 r3722  
    1 """Validation of the AnuGA implementation of the shallow water wave equation.
     1"""Automated validation of ANUGA.
    22
    3 This script sets up LWRU2 benchmark with initial condition stated
     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.
    46
    5 See also
     7See anuga_validation/okushiri_2005 for scripts that produce simulations at
     8greater resolution.
    69
    7 http://www.cee.cornell.edu/longwave/index.cfm?page=benchmark&problem=2
    8 
    9 Depth at western boundary is d = 13.5 cm
    1010"""
    1111
     
    1313from Numeric import array, zeros, Float, allclose
    1414
     15from anuga.utilities.numerical_tools import ensure_numeric
    1516from anuga.shallow_water import Domain
    1617from anuga.shallow_water import Reflective_boundary
    1718from anuga.shallow_water import Transmissive_Momentum_Set_Stage_boundary
     19from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
    1820from anuga.abstract_2d_finite_volumes.util import file_function
    1921
    2022import project
    2123
     24finaltime = 22.5
     25timestep = 0.05
    2226
    2327#-------------------------
    2428# Create Domain
    2529#-------------------------
     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)
    2635
    27 use_variable_mesh = True #Use large variable mesh generated by create_mesh.py
    28 #use_variable_mesh = False #Use small structured mesh for speed
    29 
    30 if use_variable_mesh is True:
    31     print 'Creating domain from', project.mesh_filename
    32 
    33     domain = Domain(project.mesh_filename, use_cache=True, verbose=True)
    34 else:
    35     print 'Creating regular from regular mesh'
    36     N = 150
    37     points, vertices, boundary = rectangular_cross(N, N/5*3,
    38                                                    len1=5.448, len2=3.402)
    39     domain = Domain(points, vertices, boundary)
    40 
    41 domain.set_name('lwru2')
     36domain.set_name('okushiri_automated_validation')
    4237domain.set_default_order(2)
    4338domain.set_minimum_storable_height(0.001)
    4439domain.check_integrity()
    45 print domain.statistics()
    4640
    4741
     
    6559                         domain,
    6660                         verbose=True)
    67 
    6861Bts = Transmissive_Momentum_Set_Stage_boundary(domain, function)
    69 
    70 if use_variable_mesh is True:
    71     domain.set_boundary({'wave': Bts, 'wall': Br})
    72 else:
    73     domain.set_boundary({'left': Bts, 'right': Br, 'bottom': Br, 'top': Br})
     62domain.set_boundary({'left': Bts, 'right': Br, 'bottom': Br, 'top': Br})
    7463
    7564
    7665#-------------------------
    77 # Evolve through time
     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
    78117#-------------------------
    79118import time
    80119t0 = time.time()
    81120
    82 w_max = 0
    83 for t in domain.evolve(yieldstep = 0.05, finaltime = 22.5):
     121for j, t in enumerate(domain.evolve(yieldstep = timestep,
     122                                    finaltime = finaltime)):
    84123    domain.write_time()
    85124
    86     w = domain.get_maximum_inundation_elevation()
    87     x, y = domain.get_maximum_inundation_location()
    88     print '  Coastline elevation = %.2f at (x,y)=(%.2f, %.2f)' %(w, x, y)
    89     print
     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]
    90132   
    91     if w > w_max:
    92         w_max = w
    93         x_max = x
    94         y_max = y
    95133
     134#-------------------------
     135# Validate
     136#-------------------------
     137for i, (x, y) in enumerate(gauge_locations):       
     138    predicted_gauge_values[i] = ensure_numeric(predicted_gauge_values[i])
    96139
    97 print '**********************************************'
    98 print 'Max coastline elevation = %.2f at (%.2f, %.2f)' %(w_max, x_max, y_max)
    99 print '**********************************************'
    100140   
    101    
     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   
    102174
    103175print 'That took %.2f seconds' %(time.time()-t0)
Note: See TracChangeset for help on using the changeset viewer.