Changeset 896


Ignore:
Timestamp:
Feb 15, 2005, 5:25:14 PM (20 years ago)
Author:
ole
Message:

Fiddle

Location:
inundation/ga/storm_surge/pyvolution
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • inundation/ga/storm_surge/pyvolution/data_manager.py

    r894 r896  
    10101010               minlat = None, maxlat =None,
    10111011               minlon = None, maxlon =None,
    1012                mint = None, maxt = None, mean_stage = 0):
     1012               mint = None, maxt = None, mean_stage = 0,
     1013               origin = (0,0,0)):
    10131014    """Convert 'Ferret' NetCDF format for wave propagation to
    10141015    sww format native to pyvolution.
     
    10211022    assumed to be given in the GDA94 datum.
    10221023
    1023 
    10241024    min's and max's: If omitted - full extend is used.
    10251025    To include a value min may equal it, while max must exceed it.
     1026
     1027    origin is a 3-tuple with geo referenced
     1028    UTM coordinates (zone, easting, northing) 
    10261029    """
    10271030
     
    11951198    volumes = array(volumes)       
    11961199
    1197     origin = (min(x), min(y))
    1198     outfile.minx = origin[0]
    1199     outfile.miny = origin[1]   
    1200 
    1201     #print x - origin[0]
    1202     #print y - origin[1]
    1203 
    1204     #print len(x)
    1205     #print number_of_points
    1206    
    1207     outfile.variables['x'][:] = x - origin[0]
    1208     outfile.variables['y'][:] = y - origin[1]
     1200    if origin == None:
     1201        zone = refzone       
     1202        xllcorner = min(x)
     1203        yllcorner = min(y)
     1204    else:
     1205        zone = origin[0]
     1206        xllcorner = origin[1]
     1207        yllcorner = origin[2]               
     1208
     1209   
     1210    outfile.xllcorner = xllcorner
     1211    outfile.yllcorner = yllcorner
     1212    outfile.zone = zone
     1213
     1214    outfile.variables['x'][:] = x - xllcorner
     1215    outfile.variables['y'][:] = y - yllcorner
    12091216    outfile.variables['z'][:] = 0.0
    12101217    outfile.variables['elevation'][:] = 0.0   
  • inundation/ga/storm_surge/pyvolution/test_shallow_water.py

    r862 r896  
    23992399        from util import mean
    24002400        domain1.reduction = mean
    2401         domain1.smooth = True #FIXME: This may be a requirement for the
    2402                               #interpolation process
     2401        domain1.smooth = False  #Exact result
     2402
     2403        domain1.default_order = 2
     2404        domain1.store = True   
     2405        domain1.set_datadir('.')
     2406        domain1.set_name('spatio_temporal_boundary_source' + str(time.time()))
     2407       
     2408        #FIXME: This is extremely important!
     2409        #How can we test if they weren't stored?
     2410        domain1.quantities_to_be_stored = ['stage', 'xmomentum', 'ymomentum']
     2411
     2412               
     2413        #Bed-slope and friction at vertices (and interpolated elsewhere)
     2414        domain1.set_quantity('elevation', 0)
     2415        domain1.set_quantity('friction', 0)     
     2416
     2417        # Boundary conditions
     2418        Br = Reflective_boundary(domain1)
     2419        Bd = Dirichlet_boundary([0.3,0,0])
     2420        domain1.set_boundary({'left': Bd, 'top': Bd, 'right': Br, 'bottom': Br})
     2421        #Initial condition
     2422        domain1.set_quantity('stage', 0)
     2423        domain1.check_integrity()
     2424
     2425        finaltime = 5
     2426        #Evolution  (full domain - large steps)
     2427        for t in domain1.evolve(yieldstep = 0.671, finaltime = finaltime):
     2428            pass
     2429            #domain1.write_time()
     2430
     2431        cv1 = domain1.quantities['stage'].centroid_values
     2432       
     2433       
     2434        #Create an triangle shaped domain (reusing coordinates from domain 1),
     2435        #formed from the lower and right hand  boundaries and
     2436        #the sw-ne diagonal
     2437        #from domain 1. Call it domain2
     2438       
     2439        points = [ [0,0], [1.0/3,0], [1.0/3,1.0/3],
     2440                   [2.0/3,0], [2.0/3,1.0/3], [2.0/3,2.0/3],
     2441                   [1,0], [1,1.0/3], [1,2.0/3], [1,1]]
     2442       
     2443        vertices = [ [1,2,0],
     2444                     [3,4,1], [2,1,4], [4,5,2],
     2445                     [6,7,3], [4,3,7], [7,8,4], [5,4,8], [8,9,5]]       
     2446
     2447        boundary = { (0,1):'bottom', (1,1):'bottom', (4,1): 'bottom',
     2448                     (4,2):'right', (6,2):'right', (8,2):'right',
     2449                     (0,0):'diagonal', (3,0):'diagonal', (8,0):'diagonal'}   
     2450                     
     2451        domain2 = Domain(points, vertices, boundary)
     2452       
     2453        domain2.reduction = domain1.reduction
     2454        domain2.smooth = False
     2455        domain2.default_order = 2
     2456       
     2457        #Bed-slope and friction at vertices (and interpolated elsewhere)
     2458        domain2.set_quantity('elevation', 0)
     2459        domain2.set_quantity('friction', 0)
     2460        domain2.set_quantity('stage', 0)       
     2461
     2462        # Boundary conditions
     2463        Br = Reflective_boundary(domain2)       
     2464        Bf = Spatio_temporal_boundary(domain1.filename + '.' + domain1.format,
     2465                                      domain2)
     2466        domain2.set_boundary({'right':Br, 'bottom':Br, 'diagonal':Bf})
     2467        domain2.check_integrity()       
     2468       
     2469
     2470
     2471        #Evolution (small steps)
     2472        for t in domain2.evolve(yieldstep = 0.0711, finaltime = finaltime):
     2473            pass
     2474
     2475       
     2476        #Use output from domain1 as spatio-temporal boundary for domain2
     2477        #and verify that results at right hand side are close. 
     2478
     2479        cv2 = domain2.quantities['stage'].centroid_values
     2480
     2481        #print take(cv1, (12,14,16))  #Right
     2482        #print take(cv2, (4,6,8))
     2483        #print take(cv1, (0,6,12))  #Bottom     
     2484        #print take(cv2, (0,1,4))
     2485        #print take(cv1, (0,8,16))  #Diag       
     2486        #print take(cv2, (0,3,8))
     2487
     2488        assert allclose( take(cv1, (0,8,16)), take(cv2, (0,3,8))) #Diag
     2489        assert allclose( take(cv1, (0,6,12)), take(cv2, (0,1,4))) #Bottom
     2490        assert allclose( take(cv1, (12,14,16)), take(cv2, (4,6,8))) #RHS
     2491
     2492        #Cleanup
     2493        os.remove(domain1.filename + '.' + domain1.format)       
     2494       
     2495       
     2496
     2497    def test_spatio_temporal_boundary_2(self):
     2498        """Test that boundary values can be read from file and interpolated
     2499        in both time and space.
     2500        This is a more basic test, verifying that boundary object
     2501        produces the expected results
     2502
     2503
     2504        """
     2505        import time
     2506       
     2507        #Create sww file of simple propagation from left to right
     2508        #through rectangular domain
     2509       
     2510        from mesh_factory import rectangular
     2511
     2512        #Create basic mesh
     2513        points, vertices, boundary = rectangular(3, 3)
     2514
     2515        #Create shallow water domain
     2516        domain1 = Domain(points, vertices, boundary)
     2517       
     2518        from util import mean
     2519        domain1.reduction = mean
     2520        domain1.smooth = True #To mimic MOST output
    24032521
    24042522        domain1.default_order = 2
     
    24262544        finaltime = 5
    24272545        #Evolution  (full domain - large steps)
    2428         for t in domain1.evolve(yieldstep = 0.671, finaltime = finaltime):
     2546        for t in domain1.evolve(yieldstep = 1, finaltime = finaltime):
    24292547            pass
    24302548            #domain1.write_time()
    24312549
    2432         cv1 = domain1.quantities['stage'].centroid_values
    2433        
    2434        
    2435         #Create an triangle shaped domain (reusing coordinates from domain 1),
     2550       
     2551        #Create an triangle shaped domain (coinciding with some
     2552        #coordinates from domain 1),
    24362553        #formed from the lower and right hand  boundaries and
    24372554        #the sw-ne diagonal
     
    24532570       
    24542571        domain2.reduction = domain1.reduction
    2455         domain2.smooth = True
    2456         domain2.default_order = 2
    2457        
    2458         #Bed-slope and friction at vertices (and interpolated elsewhere)
    2459         domain2.set_quantity('elevation', 0)
    2460         domain2.set_quantity('friction', 0)
    2461         domain2.set_quantity('stage', 0)       
    2462 
    2463         # Boundary conditions
    2464         Br = Reflective_boundary(domain2)       
    2465         Bf = Spatio_temporal_boundary(domain1.filename + '.' + domain1.format,
    2466                                       domain2)
    2467         domain2.set_boundary({'right':Br, 'bottom':Br, 'diagonal':Bf})
    2468         domain2.check_integrity()       
    2469        
    2470 
    2471 
    2472         #Evolution (small steps)
    2473         for t in domain2.evolve(yieldstep = 0.0711, finaltime = finaltime):
    2474             pass
    2475 
    2476        
    2477         #Use output from domain1 as spatio-temporal boundary for domain2
    2478         #and verify that results at right hand side are close. 
    2479 
    2480         cv2 = domain2.quantities['stage'].centroid_values
    2481 
    2482         #print take(cv1, (12,14,16))  #Right
    2483         #print take(cv2, (4,6,8))
    2484         #print take(cv1, (0,6,12))  #Bottom     
    2485         #print take(cv2, (0,1,4))
    2486         #print take(cv1, (0,8,16))  #Diag       
    2487         #print take(cv2, (0,3,8))
    2488 
    2489         assert allclose( take(cv1, (0,8,16)), take(cv2, (0,3,8))) #Diag
    2490         assert allclose( take(cv1, (0,6,12)), take(cv2, (0,1,4))) #Bottom
    2491         assert allclose( take(cv1, (12,14,16)), take(cv2, (4,6,8))) #RHS
    2492 
    2493         #Cleanup
    2494         os.remove(domain1.filename + '.' + domain1.format)       
    2495        
    2496        
    2497 
    2498     def test_spatio_temporal_boundary_2(self):
    2499         """Test that boundary values can be read from file and interpolated
    2500         in both time and space.
    2501         This is a more basic test, verifying that boundary object
    2502         produces the expected results
    2503 
    2504 
    2505         """
    2506         import time
    2507        
    2508         #Create sww file of simple propagation from left to right
    2509         #through rectangular domain
    2510        
    2511         from mesh_factory import rectangular
    2512 
    2513         #Create basic mesh
    2514         points, vertices, boundary = rectangular(3, 3)
    2515 
    2516         #Create shallow water domain
    2517         domain1 = Domain(points, vertices, boundary)
    2518        
    2519         from util import mean
    2520         domain1.reduction = mean
    2521         domain1.smooth = True #FIXME: This may be a requirement for the
    2522                               #interpolation process
    2523 
    2524         domain1.default_order = 2
    2525         domain1.store = True   
    2526         domain1.set_datadir('.')
    2527         domain1.set_name('spatio_temporal_boundary_source' + str(time.time()))
    2528        
    2529         #FIXME: This is extremely important!
    2530         #How can we test if they weren't stored?
    2531         domain1.quantities_to_be_stored = ['stage', 'xmomentum', 'ymomentum']
    2532 
    2533                
    2534         #Bed-slope and friction at vertices (and interpolated elsewhere)
    2535         domain1.set_quantity('elevation', 0)
    2536         domain1.set_quantity('friction', 0)     
    2537 
    2538         # Boundary conditions
    2539         Br = Reflective_boundary(domain1)
    2540         Bd = Dirichlet_boundary([0.3,0,0])     
    2541         domain1.set_boundary({'left': Bd, 'top': Bd, 'right': Br, 'bottom': Br})
    2542         #Initial condition
    2543         domain1.set_quantity('stage', 0)
    2544         domain1.check_integrity()
    2545 
    2546         finaltime = 5
    2547         #Evolution  (full domain - large steps)
    2548         for t in domain1.evolve(yieldstep = 1, finaltime = finaltime):
    2549             pass
    2550             #domain1.write_time()
    2551 
    2552        
    2553         #Create an triangle shaped domain (reusing coordinates from domain 1),
    2554         #formed from the lower and right hand  boundaries and
    2555         #the sw-ne diagonal
    2556         #from domain 1. Call it domain2
    2557        
    2558         points = [ [0,0], [1.0/3,0], [1.0/3,1.0/3],
    2559                    [2.0/3,0], [2.0/3,1.0/3], [2.0/3,2.0/3],
    2560                    [1,0], [1,1.0/3], [1,2.0/3], [1,1]]
    2561        
    2562         vertices = [ [1,2,0],
    2563                      [3,4,1], [2,1,4], [4,5,2],
    2564                      [6,7,3], [4,3,7], [7,8,4], [5,4,8], [8,9,5]]       
    2565 
    2566         boundary = { (0,1):'bottom', (1,1):'bottom', (4,1): 'bottom',
    2567                      (4,2):'right', (6,2):'right', (8,2):'right',
    2568                      (0,0):'diagonal', (3,0):'diagonal', (8,0):'diagonal'}   
    2569                      
    2570         domain2 = Domain(points, vertices, boundary)
    2571        
    2572         domain2.reduction = domain1.reduction
    2573         domain2.smooth = True
     2572        domain2.smooth = False
    25742573        domain2.default_order = 2
    25752574       
     
    25942593        points = concatenate( (reshape(x, shp), reshape(y, shp)), axis=1)       
    25952594        #The diagonal points of domain 1 are 0, 5, 10, 15
    2596         #print points[0], points[5], points[15]
     2595       
     2596        #print points[0], points[5], points[10], points[15]
    25972597        assert allclose( take(points, [0,5,10,15]),
    25982598                         [[0,0], [1.0/3, 1.0/3], [2.0/3, 2.0/3], [1,1]]) 
  • inundation/ga/storm_surge/pyvolution/test_util.py

    r886 r896  
    358358        from util import mean
    359359        domain1.reduction = mean
    360         domain1.smooth = True #NOTE: This is a strict requirement for the
    361                               #interpolation process
     360        domain1.smooth = True #NOTE: Mimic sww output where each vertex has
     361                              # only one value.
    362362
    363363        domain1.default_order = 2
Note: See TracChangeset for help on using the changeset viewer.