Changeset 3850
- Timestamp:
- Oct 24, 2006, 4:56:49 PM (19 years ago)
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/abstract_2d_finite_volumes/domain.py
r3846 r3850 641 641 """ 642 642 if name.endswith('.sww'): 643 name = name[ -4:]643 name = name[:-4] 644 644 645 645 self.simulation_name = name -
anuga_core/source/anuga/abstract_2d_finite_volumes/util.py
r3700 r3850 235 235 236 236 #Get variables 237 if verbose: print 'Get variables'237 #if verbose: print 'Get variables' 238 238 time = fid.variables['time'][:] 239 239 … … 318 318 triangles, 319 319 interpolation_points, 320 verbose =verbose)320 verbose=verbose) 321 321 322 322 -
anuga_core/source/anuga/fit_interpolate/general_fit_interpolate.py
r3689 r3850 73 73 a mesh origin, since geospatial has its own mesh origin. 74 74 """ 75 75 76 76 #Convert input to Numeric arrays 77 77 triangles = ensure_numeric(triangles, Int) … … 79 79 geo_reference = mesh_origin) 80 80 81 #Don't pass geo_reference to mesh. It doesn't work. 81 #Don't pass geo_reference to mesh. It doesn't work. (Still??) 82 83 if verbose: print 'FitInterpolate: Building mesh' 82 84 self.mesh = Mesh(vertex_coordinates, triangles) 83 85 self.mesh.check_integrity() 86 87 if verbose: print 'FitInterpolate: Building quad tree' 84 88 self.root = build_quadtree(self.mesh, 85 89 max_points_per_cell = max_vertices_per_cell) -
anuga_core/source/anuga/fit_interpolate/interpolate.py
r3768 r3850 405 405 time, 406 406 quantities, 407 quantity_names =None,408 vertex_coordinates =None,409 triangles =None,410 interpolation_points =None,411 verbose =False):407 quantity_names=None, 408 vertex_coordinates=None, 409 triangles=None, 410 interpolation_points=None, 411 verbose=False): 412 412 """Initialise object and build spatial interpolation if required 413 413 """ … … 417 417 418 418 419 #from anuga.abstract_2d_finite_volumes.util import mean, ensure_numeric420 419 from anuga.config import time_format 421 420 import types 422 421 423 422 424 # Check temporal info423 # Check temporal info 425 424 time = ensure_numeric(time) 426 425 msg = 'Time must be a monotonuosly ' … … 429 428 430 429 431 # Check if quantities is a single array only430 # Check if quantities is a single array only 432 431 if type(quantities) != types.DictType: 433 432 quantities = ensure_numeric(quantities) … … 438 437 439 438 440 # Use keys if no names are specified439 # Use keys if no names are specified 441 440 if quantity_names is None: 442 441 quantity_names = quantities.keys() 443 442 444 443 445 # Check spatial info444 # Check spatial info 446 445 if vertex_coordinates is None: 447 446 self.spatial = False … … 454 453 455 454 456 #Save for use with statistics 457 455 # Save for use with statistics 458 456 self.quantities_range = {} 459 457 for name in quantity_names: … … 462 460 463 461 self.quantity_names = quantity_names 464 #self.quantities = quantities #Takes too much memory465 462 self.vertex_coordinates = vertex_coordinates 466 463 self.interpolation_points = interpolation_points … … 470 467 471 468 472 # Precomputed spatial interpolation if requested469 # Precomputed spatial interpolation if requested 473 470 if interpolation_points is not None: 474 471 if self.spatial is False: … … 491 488 self.precomputed_values[name] = zeros((p, m), Float) 492 489 493 #Build interpolator 490 # Build interpolator 491 if verbose: print 'Building interpolation matrix' 494 492 interpol = Interpolate(vertex_coordinates, 495 493 triangles, … … 497 495 #self.interpolation_points, 498 496 #alpha = 0, 499 verbose =verbose)497 verbose=verbose) 500 498 501 499 if verbose: print 'Interpolate' -
anuga_core/source/anuga/fit_interpolate/search_functions.py
r2201 r3850 8 8 from Numeric import dot 9 9 10 from numerical_tools import get_machine_precision 10 11 11 12 def search_tree_of_vertices(root, mesh, x): … … 83 84 sigma1 = dot((x-xi2), n1)/dot((xi1-xi2), n1) 84 85 85 #FIXME: Maybe move out to test or something 86 epsilon = 1.0e-6 87 assert abs(sigma0 + sigma1 + sigma2 - 1.0) < epsilon 86 # Integrity check - machine precision is too hard, but at 87 # least check that we are within a couple of orders of magnitude 88 epsilon = get_machine_precision() 89 msg = 'abs(sigma0+sigma1+sigma2-1) = %.15e, 100*eps = %.15e'\ 90 %(abs(sigma0+sigma1+sigma2-1), 100*epsilon) 91 assert abs(sigma0 + sigma1 + sigma2 - 1.0) < 100*epsilon, msg 88 92 89 93 #Check that this triangle contains the data point 90 94 91 #Sigmas can get negative within 92 #machine precision on some machines (e.g nautilus) 93 #Hence the small eps 94 eps = 1.0e-15 95 if sigma0 >= -eps and sigma1 >= -eps and sigma2 >= -eps: 95 # Sigmas are allowed to get negative within 96 # machine precision on some machines (e.g nautilus) 97 if sigma0 >= -epsilon and sigma1 >= -epsilon and sigma2 >= -epsilon: 96 98 element_found = True 97 99 break -
anuga_core/source/anuga/load_mesh/loadASCII.py
r3603 r3850 76 76 # Needs to be defined 77 77 ##FIXME (DSG-DSG) if the ascii file isn't .xya give a better error message. 78 79 # FIXME (Ole): Has this stuff been superseded by geospatial data? 80 # Much of this code is also there 78 81 79 82 -
anuga_core/source/anuga/utilities/numerical_tools.py
r3849 r3850 10 10 #(this should move to somewhere central) 11 11 #try: 12 # from scipy import ArrayType, array, sum, innerproduct, ravel, sqrt, searchsorted, sort, concatenate, Float, arange 12 # from scipy import ArrayType, array, sum, innerproduct, ravel, sqrt, 13 # searchsorted, sort, concatenate, Float, arange 13 14 #except: 14 15 # #print 'Could not find scipy - using Numeric' 15 # from Numeric import ArrayType, array, sum, innerproduct, ravel, sqrt, searchsorted, sort, concatenate, Float, arange 16 from Numeric import ArrayType, array, sum, innerproduct, ravel, sqrt, searchsorted, sort, concatenate, Float, arange 16 # from Numeric import ArrayType, array, sum, innerproduct, ravel, sqrt, 17 #searchsorted, sort, concatenate, Float, arange 18 19 from Numeric import ArrayType, array, sum, innerproduct, ravel, sqrt,\ 20 searchsorted, sort, concatenate, Float, arange 17 21 18 22 # Getting an infinite number to use when using Numeric … … 31 35 """ 32 36 33 error_msg = 'Input to acos is outside allowed domain [-1.0, 1.0]. I got %.12f' %x 37 error_msg = 'Input to acos is outside allowed domain [-1.0, 1.0].'+\ 38 'I got %.12f' %x 34 39 warning_msg = 'Changing argument to acos from %.18f to %.1f' %(x, sign(x)) 35 40 36 # FIXME(Ole): Need function to compute machine precision as this is also 37 # used in fit_interpolate/search_functions.py 38 39 40 eps = 1.0e-15 # Machine precision 41 eps = get_machine_precision() # Machine precision 41 42 if x < -1.0: 42 43 if x < -1.0 - eps: … … 50 51 raise ValueError, errmsg 51 52 else: 52 print 'NOTE: changing argument to acos from %.18f to 1.0' %x 53 print 'NOTE: changing argument to acos from %.18f to 1.0' %x 53 54 x = 1.0 54 55 … … 148 149 y = x 149 150 151 x = ensure_numeric(x) 152 y = ensure_numeric(y) 150 153 assert(len(x)==len(y)) 151 N = len(x) 152 154 155 N = len(x) 153 156 cx = x - mean(x) 154 157 cy = y - mean(y) -
anuga_validation/okushiri_2005/create_okushiri.py
r3845 r3850 16 16 """ 17 17 18 print 'Preparing time boundary from %s' %filename 18 textversion = filename[:-4] + '.txt' 19 20 print 'Preparing time boundary from %s' %textversion 19 21 from Numeric import array 20 22 21 fid = open( filename)23 fid = open(textversion) 22 24 23 25 #Skip first line … … 43 45 from Scientific.IO.NetCDF import NetCDFFile 44 46 45 outfile = filename[:-4] + '.tms' 46 print 'Writing to', outfile 47 fid = NetCDFFile(outfile, 'w') 47 print 'Writing to', filename 48 fid = NetCDFFile(filename, 'w') 48 49 49 50 fid.institution = 'Geoscience Australia' … … 69 70 if __name__ == "__main__": 70 71 72 71 73 #Preparing points 72 74 #(Only when using original Benchmark_2_Bathymetry.txt file) 75 # FIXME: Replace by using geospatial data 76 # 73 77 #from anuga.abstract_2d_finite_volumes.data_manager import xya2pts 74 78 #xya2pts(project.bathymetry_filename, verbose = True, -
anuga_validation/okushiri_2005/extract_timeseries.py
r3845 r3850 5 5 """ 6 6 7 from Numeric import allclose 8 from Scientific.IO.NetCDF import NetCDFFile 9 10 from anuga.abstract_2d_finite_volumes.util import file_function 11 from anuga.utilities.numerical_tools import\ 12 ensure_numeric, cov, get_machine_precision 13 14 import project 15 16 try: 17 from pylab import ion, hold, plot, title, legend, xlabel, ylabel, savefig 18 except: 19 plotting = False 20 else: 21 plotting = True 7 22 8 23 9 from anuga.caching import cache 10 11 12 13 14 gauges = [[0.000, 1.696]] #Boundary 15 gauges += [[4.521, 1.196], [4.521, 1.696], [4.521, 2.196]] #Ch 5-7-9 16 17 gauge_names = ['Boundary', 'ch5', 'ch7', 'ch9'] 18 24 #------------------------- 25 # Basic data 26 #------------------------- 19 27 20 28 finaltime = 22.5 21 29 timestep = 0.05 22 30 23 #Read reference data 31 gauge_locations = [[0.000, 1.696]] # Boundary gauge 32 gauge_locations += [[4.521, 1.196], [4.521, 1.696], [4.521, 2.196]] #Ch 5-7-9 33 gauge_names = ['Boundary', 'ch5', 'ch7', 'ch9'] 24 34 25 #Input wave 26 filename = 'Benchmark_2_input.tms' 27 print 'Reading', filename 28 from Scientific.IO.NetCDF import NetCDFFile 29 from Numeric import allclose 30 fid = NetCDFFile(filename, 'r')# 35 validation_data = {} 36 for key in gauge_names: 37 validation_data[key] = [] 31 38 32 input_time = fid.variables['time'][:] 33 input_stage = fid.variables['stage'][:] 39 40 expected_covariances = {'Boundary': 5.288392008865989e-05, 41 'ch5': 1.166748190444681e-04, 42 'ch7': 1.121816242516758e-04, 43 'ch9': 1.249543278366778e-04} 34 44 35 45 36 #gauges 46 #------------------------- 47 # Read validation dataa 48 #------------------------- 49 50 print 'Reading', project.boundary_filename 51 fid = NetCDFFile(project.boundary_filename, 'r') 52 input_time = fid.variables['time'][:] 53 validation_data['Boundary'] = fid.variables['stage'][:] 54 37 55 reference_time = [] 38 ch5 = [] 39 ch7 = [] 40 ch9 = [] 41 filename = 'output_ch5-7-9.txt' 42 fid = open(filename) 56 fid = open(project.validation_filename) 43 57 lines = fid.readlines() 44 58 fid.close() 59 45 60 for i, line in enumerate(lines[1:]): 46 61 if i == len(input_time): break 47 62 48 63 fields = line.split() 49 64 50 reference_time.append(float(fields[0])) 51 ch5.append(float(fields[1])/100) #cm2m52 ch7.append(float(fields[2])/100) #cm2m53 ch9.append(float(fields[3])/100) #cm2m65 reference_time.append(float(fields[0])) # Record reference time 66 for j, key in enumerate(gauge_names[1:]): # Omit boundary gauge 67 value = float(fields[1:][j]) # Omit time 68 validation_data[key].append(value/100) # Convert cm2m 54 69 55 70 56 from anuga.abstract_2d_finite_volumes.util import file_function 57 from anuga.utilities.numerical_tools import ensure_numeric 58 gauge_values = [ensure_numeric(input_stage), 59 ensure_numeric(ch5), 60 ensure_numeric(ch7), 61 ensure_numeric(ch9)] #Reference values 62 63 64 65 #Read model output 66 #filename = 'output.sww' 67 filename = 'lwru2.sww' 68 #filename = 'lwru2_.05s.sww' 69 70 #f = file_function(filename, 71 # quantities = 'stage', 72 # interpolation_points = gauges, 73 # verbose = True) 74 75 f = cache(file_function,filename, 76 {'quantities': 'stage', 77 'interpolation_points': gauges, 78 'verbose': True}, 79 #evaluate = True, 80 dependencies = [filename], 81 verbose = True) 82 83 84 85 86 #Checks 87 #print reference_time 88 #print input_time 71 # Checks 89 72 assert reference_time[0] == 0.0 90 73 assert reference_time[-1] == finaltime 91 74 assert allclose(reference_time, input_time) 92 75 76 for key in gauge_names: 77 validation_data[key] = ensure_numeric(validation_data[key]) 93 78 94 79 95 #Validation 80 #-------------------------------------------------- 81 # Read and interpolate model output 82 #-------------------------------------------------- 83 #f = file_function('okushiri_new_limiters.sww', 84 #f = file_function('okushiri_as2005_with_mxspd=0.1.sww', 85 f = file_function(project.output_filename, 86 quantities='stage', 87 interpolation_points=gauge_locations, 88 use_cache=True, 89 verbose=True) 96 90 97 91 92 #-------------------------------------------------- 93 # Compare model output to validation data 94 #-------------------------------------------------- 95 96 eps = get_machine_precision() 98 97 for k, name in enumerate(gauge_names): 99 98 sqsum = 0 100 99 denom = 0 101 100 model = [] 101 print 102 102 print 'Validating ' + name 103 observed_timeseries = validation_data[name] 103 104 for i, t in enumerate(reference_time): 104 ref = gauge_values[k][i] 105 val = f(t, point_id = k)[0] 106 model.append(val) 105 model.append(f(t, point_id=k)[0]) 107 106 108 sqsum += (ref - val)**2109 denom += ref**2107 res = cov(observed_timeseries, model) 108 print 'Covariance = %.18e' %res 110 109 111 print sqsum 112 print sqsum/denom 110 if res < expected_covariances[name]-eps: 111 print 'Result is better than expected by: %.18e'\ 112 %(res-expected_covariances[name]) 113 print 'Result = %.18e' %res 114 print 'Expect = %.18e' %expected_covariances[name] 115 elif res > expected_covariances[name]+eps: 116 print 'FAIL: %.18e' %res 117 else: 118 pass 113 119 114 from pylab import *115 ion()116 hold(False)117 plot(reference_time, gauge_values[k], 'r.-',118 reference_time, model, 'k-')119 title('Gauge %s' %name)120 xlabel('time(s)')121 ylabel('stage (m)')122 legend(('Observed', 'Modelled'), shadow=True, loc='upper left')123 savefig(name, dpi = 300)124 120 125 raw_input('Next') 126 show() 121 if plotting is True: 122 ion() 123 hold(False) 124 125 plot(reference_time, validation_data[name], 'r.-', 126 reference_time, model, 'k-') 127 title('Gauge %s' %name) 128 xlabel('time(s)') 129 ylabel('stage (m)') 130 legend(('Observed', 'Modelled'), shadow=True, loc='upper left') 131 savefig(name, dpi = 300) 132 133 raw_input('Next') 127 134 128 135 129 136 130 #from pylab import *131 #plot(time, stage)132 #show() -
anuga_validation/okushiri_2005/project.py
r3845 r3850 2 2 """ 3 3 4 boundary_filename = 'Benchmark_2_input.txt' 5 bathymetry_filename = 'Benchmark_2_Bathymetry.txt' 4 # Given boundary wave 5 boundary_filename = 'Benchmark_2_input.tms' 6 7 # Observed timeseries 8 validation_filename = 'output_ch5-7-9.txt' 9 10 # A simple conversion from txt file to the more compact NetCDF format 11 bathymetry_filename = 'Benchmark_2_Bathymetry.pts' 12 13 # Triangular mesh 6 14 mesh_filename = 'Benchmark_2.msh' 7 15 8 output_filename = 'okushiri.sww' 16 # Model output 17 output_filename = 'okushiri_old_limiters.sww' 9 18 10 19 -
anuga_validation/okushiri_2005/run_okushiri.py
r3845 r3850 42 42 domain.set_quantity('stage', 0.0) 43 43 domain.set_quantity('elevation', 44 filename = project.bathymetry_filename[:-4] + '.pts',45 alpha =0.02,46 verbose =True,47 use_cache =True)44 filename=project.bathymetry_filename, 45 alpha=0.02, 46 verbose=True, 47 use_cache=True) 48 48 49 49 … … 51 51 # Domain parameters 52 52 #------------------------- 53 domain.set_name(project.output_filename) 54 domain.set_default_order(2) 55 domain.set_minimum_storable_height(0.001) 56 domain.set_maximum_allowed_speed(0.1) # Allow a little runoff (0.1 is OK) 57 58 # Set old (pre Sep 2006) defaults for limiters 59 #domain.beta_w = 0.9 60 #domain.beta_w_dry = 0.9 61 #domain.beta_uh = 0.9 62 #domain.beta_uh_dry = 0.9 63 #domain.beta_vh = 0.9 64 #domain.beta_vh_dry = 0.9 65 66 #domain.check_integrity() 67 #print domain.statistics() 68 53 domain.set_name(project.output_filename) # Name of output sww file 54 domain.set_default_order(2) # Apply second order scheme 55 domain.set_all_limiters(0.9) # Maximal second order scheme (old lim) 56 domain.set_minimum_storable_height(0.001) # Don't store w < 0.001m 57 domain.set_maximum_allowed_speed(0.1) # Allow a little runoff (0.1 is OK) 69 58 70 59 … … 74 63 75 64 # Create boundary function from timeseries provided in file 76 function = file_function(project.boundary_filename [:-4] + '.tms',65 function = file_function(project.boundary_filename, 77 66 domain, verbose=True) 78 67
Note: See TracChangeset
for help on using the changeset viewer.