Changeset 1657
- Timestamp:
- Jul 29, 2005, 3:33:32 PM (20 years ago)
- Location:
- inundation/ga/storm_surge
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pmesh/load_mesh/loadASCII.py
r1467 r1657 997 997 msg = 'Could not open file %s ' %ofile 998 998 raise IOError, msg 999 1000 1001 1002 1003 1004 1005 1006 1007 999 except IOError: 1008 1000 # Catch this to add an error message -
inundation/ga/storm_surge/pyvolution/data_manager.py
r1654 r1657 1 """Functions to store and retrieve data for the Shallow Water Wave equation. 2 There are two kinds of data 3 4 1: Constant data: Vertex coordinates and field values. Stored once 5 2: Variable data: Conserved quantities. Stored once per timestep. 6 7 All data is assumed to reside at vertex locations. 8 9 10 Formats used within ANUGA: 1 """datamanager.py - input output for AnuGA 2 3 4 This module takes care of reading and writing datafiles such as topograhies, 5 model output, etc 6 7 8 Formats used within AnuGA: 11 9 12 10 .sww: Netcdf format for storing model output … … 209 207 #Class for storing output to e.g. visualisation 210 208 class Data_format_sww(Data_format): 211 """Interface to native NetCDF format (.sww) 209 """Interface to native NetCDF format (.sww) for storing model output 210 211 There are two kinds of data 212 213 1: Constant data: Vertex coordinates and field values. Stored once 214 2: Variable data: Conserved quantities. Stored once per timestep. 215 216 All data is assumed to reside at vertex locations. 212 217 """ 213 218 -
inundation/ga/storm_surge/pyvolution/general_mesh.py
r1632 r1657 180 180 if obj is True, the x/y pairs are returned in a 3*N x 2 array. 181 181 FIXME, we might make that the default. 182 FIXME Maybe use keyword: continuous? 182 183 183 184 -
inundation/ga/storm_surge/pyvolution/generic_boundary_conditions.py
r1102 r1657 125 125 """ 126 126 127 #FIXME: Is this still necessary 127 128 128 129 def __init__(self, filename, domain): … … 170 171 171 172 The full solution history is not exactly the same as if 172 the models were couple :173 the models were coupled: 173 174 File boundary must read and interpolate from *smoothed* version 174 175 as stored in sww and cannot work with the discontinuos triangles. -
inundation/ga/storm_surge/pyvolution/quantity.py
r1632 r1657 410 410 assert A.shape[0] == len(indexes) 411 411 vertex_list = indexes 412 412 413 #Go through list of unique vertices 413 for i_index, unique_vert_id in enumerate(vertex_list):414 for i_index, unique_vert_id in enumerate(vertex_list): 414 415 triangles = self.domain.vertexlist[unique_vert_id] 415 416 -
inundation/ga/storm_surge/pyvolution/shallow_water.py
r1642 r1657 94 94 95 95 #Reduction operation for get_vertex_values 96 #from util import mean97 #self.reduction = mean98 self.reduction = min #Looks better near steep slopes96 from util import mean 97 self.reduction = mean 98 #self.reduction = min #Looks better near steep slopes 99 99 100 100 self.quantities_to_be_stored = ['stage'] -
inundation/ga/storm_surge/pyvolution/test_least_squares.py
r1632 r1657 831 831 832 832 f = interp.fit(z) 833 #f will be different from answer rdue to smoothing833 #f will be different from answer due to smoothing 834 834 assert allclose(f, answer,atol=5) 835 835 … … 923 923 answer = linear_function(data_points2) 924 924 assert allclose(z1, answer) 925 926 927 928 925 929 926 930 -
inundation/ga/storm_surge/pyvolution/test_quantity.py
r1504 r1657 8 8 from config import epsilon 9 9 from Numeric import allclose, array, ones, Float 10 11 12 #Aux for least_squares example 13 def linear_function(point): 14 point = array(point) 15 return point[:,0]+point[:,1] 10 16 11 17 … … 248 254 [[1,0,20], [1,20,4], [4,20,50], [30,1,4]]) 249 255 256 250 257 def test_set_vertex_values_using_general_interface(self): 251 258 quantity = Quantity(self.mesh4) … … 266 273 [2.5, 3.5, 2]]) 267 274 275 276 277 278 def test_set_vertex_values_using_least_squares(self): 279 from least_squares import Interpolation, fit_to_mesh 280 281 quantity = Quantity(self.mesh4) 282 283 #Get (enough) datapoints 284 data_points = [[ 0.66666667, 0.66666667], 285 [ 1.33333333, 1.33333333], 286 [ 2.66666667, 0.66666667], 287 [ 0.66666667, 2.66666667], 288 [ 0.0, 1.0], 289 [ 0.0, 3.0], 290 [ 1.0, 0.0], 291 [ 1.0, 1.0], 292 [ 1.0, 2.0], 293 [ 1.0, 3.0], 294 [ 2.0, 1.0], 295 [ 3.0, 0.0], 296 [ 3.0, 1.0]] 297 298 299 interp = Interpolation(quantity.domain.coordinates, quantity.domain.triangles, 300 data_points, alpha=0.0) 301 302 z = linear_function(data_points) 303 answer = linear_function(quantity.domain.coordinates) 304 305 f = interp.fit(z) 306 307 #print "f",f 308 #print "answer",answer 309 assert allclose(f, answer) 310 311 312 quantity.set_values(f) 313 314 315 answer = linear_function(quantity.domain.get_vertex_coordinates(obj = True)) 316 #print quantity.vertex_values, answer 317 assert allclose(quantity.vertex_values.flat, answer) 318 319 #Now try using the general interface 320 321 vertex_attributes = fit_to_mesh(quantity.domain.coordinates, 322 quantity.domain.triangles, 323 data_points, 324 z, 325 alpha = 0, 326 verbose=False) 327 328 #print vertex_attributes 329 quantity.set_values(vertex_attributes) 330 assert allclose(quantity.vertex_values.flat, answer) 268 331 269 332 -
inundation/ga/storm_surge/validation/LWRU2/lwru2.py
r1654 r1657 7 7 http://www.cee.cornell.edu/longwave/index.cfm?page=benchmark&problem=2 8 8 9 10 9 """ 11 10 12 ###################### 11 13 12 # Module imports 14 15 from pyvolution.shallow_water import Domain, Reflective_boundary,\ 16 Dirichlet_boundary,Transmissive_boundary, Constant_height, Constant_stage 17 13 from pyvolution.shallow_water import Domain, Reflective_boundary, File_boundary 18 14 from pyvolution.mesh_factory import rectangular 19 15 from Numeric import array, zeros, Float, allclose 20 16 17 picklefile = 'domain.pck' 18 from cPickle import dump, load 19 20 try: 21 fid = open(picklefile) 22 domain = load(fid) 23 print 'Read pickled domain' 24 except: 25 26 #Preparing points 27 from pyvolution.data_manager import xya2pts 28 xya2pts('bathymetry.txt', verbose = True) 21 29 22 30 23 #Preparing points 24 from pyvolution.data_manager import xya2pts 25 xya2pts('Benchmark_2_Bathymetry.txt', verbose = True) 31 ####################### 32 # Domain 33 print 'Creating domain' 34 points, vertices, boundary = rectangular(200, 200/5*3, 35 len1=5.448, len2=3.402) 36 domain = Domain(points, vertices, boundary) 37 38 domain.check_integrity() 39 domain.default_order = 2 40 41 print "Number of triangles = ", len(domain) 42 domain.store = True #Store for visualisation purposes 43 44 import sys, os 45 base = os.path.basename(sys.argv[0]) 46 domain.filename, _ = os.path.splitext(base) 47 48 #LS code to be included in set_quantity 49 from pyvolution import util, least_squares 50 points, attributes = util.read_xya('bathymetry.pts') 51 52 #Fit attributes to mesh 53 vertex_attributes = least_squares.fit_to_mesh(domain.coordinates, 54 domain.triangles, 55 points, 56 attributes['elevation'], 57 verbose=True) 58 59 print 'Initial values' 60 domain.set_quantity('elevation', vertex_attributes) 61 domain.set_quantity('friction', 0.0) 62 domain.set_quantity('stage', 0.0) 63 64 65 fid = open('domain.pck', 'w') 66 dump(domain, fid) 67 fid.close() 26 68 27 69 28 70 29 #######################30 # Domain31 #32 33 34 print 'Creating domain'35 #Create basic mesh36 #37 #The initial condition extends 50km off shore38 #and 5,000m is allowed on shore for wetting39 #(only about 200m is expected, though)40 41 #points, vertices, boundary = rectangular(400, 40,42 # len1=55000, len2=5000,43 # origin = (-5000, 0.0))44 45 points, vertices, boundary = rectangular(100, 100,46 len1=5.448, len2=3.402)47 48 49 #Create shallow water domain50 domain = Domain(points, vertices, boundary)51 52 domain.check_integrity()53 domain.default_order = 254 55 #Output params56 domain.smooth = True57 domain.reduction = min #Looks a lot better on top of steep slopes58 print "Number of triangles = ", len(domain)59 60 domain.visualise = False61 domain.store = True #Store for visualisation purposes62 domain.format = 'sww' #Native netcdf visualisation format63 64 import sys, os65 base = os.path.basename(sys.argv[0])66 domain.filename, _ = os.path.splitext(base)67 68 69 #LS code to be included in set_quantity70 from pyvolution import util, least_squares71 72 points, attributes = util.read_xya('Benchmark_2_Bathymetry.pts')73 74 #Fit attributes to mesh75 vertex_attributes = least_squares.fit_to_mesh(domain.coordinates,76 domain.triangles,77 points,78 attributes['elevation'],79 verbose=True)80 81 82 print 'Initial values'83 domain.set_quantity('elevation', vertex_attributes)84 #domain.set_quantity('elevation', 'Benchmark_2_Bathymetry.pts')85 domain.set_quantity('friction', 0.0)86 domain.set_quantity('stage', 0.0)87 88 #import sys; sys.exit()89 90 #print domain.quantities['stage'].centroid_values91 71 92 72 ###################### … … 95 75 print 'Boundaries' 96 76 Br = Reflective_boundary(domain) 97 Bt = Transmissive_boundary(domain) 98 99 #Constant inflow 100 Bd = Dirichlet_boundary([0.0, 0.0, 0.0]) 77 Bf = File_boundary('input_wave.txt', domain) 101 78 102 79 #Set boundary conditions 103 domain.set_boundary({'left': B r, 'right': Bt, 'bottom': Bt, 'top': Bt})80 domain.set_boundary({'left': Bf, 'right': Br, 'bottom': Br, 'top': Br}) 104 81 105 82 … … 108 85 t0 = time.time() 109 86 110 111 112 113 pt = [] 114 xes = [] 115 y = 2500 116 x0 = -100 117 step = 50 118 for i in range(1000): 119 x = x0+i*step 120 xes.append(x) 121 pt.append( [x,y] ) 122 123 from pylab import * 124 from pyvolution.least_squares import Interpolation 125 126 127 V = domain.get_vertex_coordinates(obj=True) 128 T = domain.get_triangles(obj=True) 129 130 I = Interpolation(V, 131 T, 132 point_coordinates = pt, 133 verbose = True) 134 135 136 f = domain.quantities['elevation'].vertex_values.flat 137 z = I.interpolate( f ) 138 139 print 'xxxxx' 140 141 ion() 142 hold(False) 143 f = domain.quantities['stage'].vertex_values.flat 144 y = I.interpolate( f ) 145 plot(xes, y, '-b', xes, z, '-k') 146 set( gca(), Ylim=(-10,10) ) 147 148 raw_input('go') 149 for t in domain.evolve(yieldstep = 1, finaltime = 300.0): 150 151 f = domain.quantities['stage'].vertex_values.flat 152 y = I.interpolate( f ) 153 ioff() 154 plot(xes, y, '-b', xes, z, '-k') 155 ion() 156 set( gca(), Ylim=(-10,10) ) 157 158 159 #print y[:], y.shape 160 161 87 for t in domain.evolve(yieldstep = 0.1, finaltime = 22.5): 162 88 domain.write_time() 163 89 164 90 165 91 print 'That took %.2f seconds' %(time.time()-t0) 166 show() 92
Note: See TracChangeset
for help on using the changeset viewer.