Changeset 620 for inundation/ga/storm_surge
- Timestamp:
- Nov 24, 2004, 12:25:21 PM (20 years ago)
- Location:
- inundation/ga/storm_surge
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/analytical solutions/Analytical_solution_contracting_channel_import_mesh.py
r616 r620 45 45 domain.filename = 'contracting_channel_first-order' 46 46 47 #Decide which quantities are to be stored at each timestep 48 domain.quantities_to_be_stored = ['level', 'xmomentum', 'ymomentum'] 49 47 50 #Reduction operation for get_vertex_values 48 51 from util import mean -
inundation/ga/storm_surge/pyvolution/data_manager.py
r480 r620 215 215 'number_of_points')) 216 216 217 fid.createVariable('uh', self.precision, 218 ('number_of_timesteps', 219 'number_of_points')) 220 221 fid.createVariable('vh', self.precision, 222 ('number_of_timesteps', 223 'number_of_points')) 217 224 218 225 #Close … … 240 247 y = fid.variables['y'] 241 248 z = fid.variables['z'] 249 250 volumes = fid.variables['volumes'] 251 252 # Get X, Y and bed elevation Z 253 Q = domain.quantities['elevation'] 254 X,Y,Z,V = Q.get_vertex_values(xy=True, 255 precision = self.precision) 256 257 258 259 x[:] = X.astype(self.precision) 260 y[:] = Y.astype(self.precision) 261 z[:] = Z.astype(self.precision) 262 263 volumes[:] = V 264 265 #Close 266 fid.close() 267 268 269 def store_timestep(self, names): 270 """Store time and named quantities to file 271 """ 272 from Scientific.IO.NetCDF import NetCDFFile 273 import types 274 from time import sleep 275 276 277 #Get NetCDF 278 retries = 0 279 file_open = False 280 while not file_open and retries < 10: 281 try: 282 fid = NetCDFFile(self.filename, 'a') #Open existing file 283 except IOError: 284 #This could happen if someone was reading the file. 285 #In that case, wait a while and try again 286 msg = 'Warning (store_timestep): File %s could not be opened'\ 287 %self.filename 288 msg += ' - trying again' 289 print msg 290 retries += 1 291 sleep(1) 292 else: 293 file_open = True 294 295 if not file_open: 296 msg = 'File %s could not be opened for append' %self.filename 297 raise msg 298 299 300 domain = self.domain 301 302 # Get the variables 303 time = fid.variables['time'] 304 stage = fid.variables['stage'] 305 uh = fid.variables['uh'] 306 vh = fid.variables['vh'] 307 i = len(time) 308 309 #Store time 310 time[i] = self.domain.time 311 312 313 if type(names) not in [types.ListType, types.TupleType]: 314 names = [names] 315 316 for name in names: 317 # Get quantity 318 Q = domain.quantities[name] 319 A,V = Q.get_vertex_values(xy=False, 320 precision = self.precision) 321 322 #FIXME: Make this more general and rethink naming 323 if name == 'level': 324 stage[i,:] = A.astype(self.precision) 325 elif name == 'xmomentum': 326 uh[i,:] = A.astype(self.precision) 327 elif name == 'ymomentum': 328 vh[i,:] = A.astype(self.precision) 329 330 331 #Flush and close 332 fid.sync() 333 fid.close() 334 335 336 #Class for handling checkpoints data 337 class Data_format_cpt(Data_format): 338 """Interface to native NetCDF format (.cpt) 339 """ 340 341 342 def __init__(self, domain, mode = 'w'): 343 from Scientific.IO.NetCDF import NetCDFFile 344 from Numeric import Int, Float, Float 345 346 self.precision = Float #Use full precision 347 348 Data_format.__init__(self, domain, 'sww', mode) 349 350 351 # NetCDF file definition 352 fid = NetCDFFile(self.filename, mode) 353 354 if mode == 'w': 355 #Create new file 356 fid.institution = 'Geoscience Australia' 357 fid.description = 'Checkpoint data' 358 #fid.smooth = domain.smooth 359 fid.order = domain.default_order 360 361 # dimension definitions 362 fid.createDimension('number_of_volumes', self.number_of_volumes) 363 fid.createDimension('number_of_vertices', 3) 364 365 #Store info at all vertices (no smoothing) 366 fid.createDimension('number_of_points', 3*self.number_of_volumes) 367 fid.createDimension('number_of_timesteps', None) #extensible 368 369 # variable definitions 370 371 #Mesh 372 fid.createVariable('x', self.precision, ('number_of_points',)) 373 fid.createVariable('y', self.precision, ('number_of_points',)) 374 #fid.createVariable('z', self.precision, ('number_of_points',)) 375 376 fid.createVariable('volumes', Int, ('number_of_volumes', 377 'number_of_vertices')) 378 379 fid.createVariable('time', self.precision, 380 ('number_of_timesteps',)) 381 382 #Allocate space for all quantities 383 for name in domain.quantities.keys(): 384 fid.createVariable(name, self.precision, 385 ('number_of_timesteps', 386 'number_of_points')) 387 388 #Close 389 fid.close() 390 391 392 def store_checkpoint(self): 393 """ 394 Write x,y coordinates of triangles. 395 Write connectivity ( 396 constituting 397 the bed elevation. 398 """ 399 400 from Scientific.IO.NetCDF import NetCDFFile 401 402 from Numeric import concatenate 403 404 domain = self.domain 405 406 #Get NetCDF 407 fid = NetCDFFile(self.filename, 'a') #Open existing file for append 408 409 # Get the variables 410 x = fid.variables['x'] 411 y = fid.variables['y'] 242 412 243 413 volumes = fid.variables['volumes'] … … 311 481 312 482 313 #Class for handling checkpoints data314 class Data_format_cpt(Data_format):315 """Interface to native NetCDF format (.cpt)316 """317 318 319 def __init__(self, domain, mode = 'w'):320 from Scientific.IO.NetCDF import NetCDFFile321 from Numeric import Int, Float, Float322 323 self.precision = Float #Use full precision324 325 Data_format.__init__(self, domain, 'sww', mode)326 327 328 # NetCDF file definition329 fid = NetCDFFile(self.filename, mode)330 331 if mode == 'w':332 #Create new file333 fid.institution = 'Geoscience Australia'334 fid.description = 'Checkpoint data'335 #fid.smooth = domain.smooth336 fid.order = domain.default_order337 338 # dimension definitions339 fid.createDimension('number_of_volumes', self.number_of_volumes)340 fid.createDimension('number_of_vertices', 3)341 342 #Store info at all vertices (no smoothing)343 fid.createDimension('number_of_points', 3*self.number_of_volumes)344 fid.createDimension('number_of_timesteps', None) #extensible345 346 # variable definitions347 348 #Mesh349 fid.createVariable('x', self.precision, ('number_of_points',))350 fid.createVariable('y', self.precision, ('number_of_points',))351 #fid.createVariable('z', self.precision, ('number_of_points',))352 353 fid.createVariable('volumes', Int, ('number_of_volumes',354 'number_of_vertices'))355 356 fid.createVariable('time', self.precision,357 ('number_of_timesteps',))358 359 #Allocate space for all quantities360 for name in domain.quantities.keys():361 fid.createVariable(name, self.precision,362 ('number_of_timesteps',363 'number_of_points'))364 365 #Close366 fid.close()367 368 369 def store_checkpoint(self):370 """371 Write x,y coordinates of triangles.372 Write connectivity (373 constituting374 the bed elevation.375 """376 377 from Scientific.IO.NetCDF import NetCDFFile378 379 from Numeric import concatenate380 381 domain = self.domain382 383 #Get NetCDF384 fid = NetCDFFile(self.filename, 'a') #Open existing file for append385 386 # Get the variables387 x = fid.variables['x']388 y = fid.variables['y']389 390 volumes = fid.variables['volumes']391 392 # Get X, Y and bed elevation Z393 Q = domain.quantities['elevation']394 X,Y,Z,V = Q.get_vertex_values(xy=True,395 precision = self.precision)396 397 398 399 x[:] = X.astype(self.precision)400 y[:] = Y.astype(self.precision)401 z[:] = Z.astype(self.precision)402 403 volumes[:] = V404 405 #Close406 fid.close()407 408 409 def store_timestep(self, name):410 """Store time and named quantity to file411 """412 from Scientific.IO.NetCDF import NetCDFFile413 from time import sleep414 415 #Get NetCDF416 retries = 0417 file_open = False418 while not file_open and retries < 10:419 try:420 fid = NetCDFFile(self.filename, 'a') #Open existing file421 except IOError:422 #This could happen if someone was reading the file.423 #In that case, wait a while and try again424 msg = 'Warning (store_timestep): File %s could not be opened'\425 %self.filename426 msg += ' - trying again'427 print msg428 retries += 1429 sleep(1)430 else:431 file_open = True432 433 if not file_open:434 msg = 'File %s could not be opened for append' %self.filename435 raise msg436 437 438 domain = self.domain439 440 # Get the variables441 time = fid.variables['time']442 stage = fid.variables['stage']443 i = len(time)444 445 #Store stage446 time[i] = self.domain.time447 448 # Get quantity449 Q = domain.quantities[name]450 A,V = Q.get_vertex_values(xy=False,451 precision = self.precision)452 453 stage[i,:] = A.astype(self.precision)454 455 #Flush and close456 fid.sync()457 fid.close()458 459 460 483 461 484 -
inundation/ga/storm_surge/pyvolution/shallow_water.py
r614 r620 52 52 self.reduction = min #Looks better near steep slopes 53 53 54 54 self.quantities_to_be_stored = ['level'] 55 56 55 57 #Establish shortcuts to relevant quantities (for efficiency) 56 58 #self.w = self.quantities['level'] … … 172 174 #Store model data, e.g. for subsequent visualisation 173 175 if self.store is True: 174 self.store_timestep('level') 176 #self.store_timestep(['level', 'xmomentum', 'ymomentum']) 177 self.store_timestep(self.quantities_to_be_stored) 178 175 179 #FIXME: Could maybe be taken from specified list 176 180 #of 'store every step' quantities 177 178 181 179 182 #Pass control on to outer loop for more specific actions
Note: See TracChangeset
for help on using the changeset viewer.