def run_simulation(parallel=False):


    domain = create_domain_from_file(mesh_filename)
    domain.set_quantity('stage', Set_Stage(756000.0, 756500.0, 2.0))

    #--------------------------------------------------------------------------
    # Create parallel domain if requested
    #--------------------------------------------------------------------------

    if parallel:
        if myid == 0 and verbose: print 'DISTRIBUTING PARALLEL DOMAIN'
        domain = distribute(domain)

    #------------------------------------------------------------------------------
    # Setup boundary conditions
    # This must currently happen *after* domain has been distributed
    #------------------------------------------------------------------------------
    domain.store = False
    Br = Reflective_boundary(domain)      # Solid reflective wall

    domain.set_boundary({'outflow' :Br, 'inflow' :Br, 'inner' :Br, 'exterior' :Br, 'open' :Br})

    #------------------------------------------------------------------------------
    # Evolution
    #------------------------------------------------------------------------------
    if parallel:
        if myid == 0 and verbose: print 'PARALLEL EVOLVE'
    else:
        if verbose: print 'SEQUENTIAL EVOLVE'

    for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime):
        pass
def run_simulation(parallel=False, verbose=False):

    #--------------------------------------------------------------------------
    # Setup computational domain and quantities
    #--------------------------------------------------------------------------
    domain = rectangular_cross_domain(M, N)
    domain.set_name('odomain')                    # Set sww filename
    domain.set_datadir('.')   
    domain.set_quantity('elevation', topography) # Use function for elevation
    domain.set_quantity('friction', 0.0)         # Constant friction 
    domain.set_quantity('stage', expression='elevation') # Dry initial stage
    
    domain.set_quantities_to_be_stored({'elevation': 2,'stage': 2,'xmomentum': 2,'ymomentum': 2})
    domain.set_store_vertices_uniquely(False)
    domain.set_flow_algorithm('DE1')
    georef = Geo_reference(zone=56,xllcorner=100000.0,yllcorner=200000.0)
    domain.set_georeference(georef)
        
    #--------------------------------------------------------------------------
    # Create pickled partition
    #--------------------------------------------------------------------------
    if myid == 0:
        if verbose: print 'DUMPING PARTITION DATA'
        sequential_distribute_dump(domain, numprocs, verbose=verbose, parameters=new_parameters)    

    #--------------------------------------------------------------------------
    # Create the parallel domains
    #--------------------------------------------------------------------------
    if parallel:
        
        if myid == 0 and verbose : print 'DISTRIBUTING TO PARALLEL DOMAIN'
        pdomain = distribute(domain, verbose=verbose, parameters=new_parameters)
        pdomain.set_name('pdomain')
        
        if myid == 0 and verbose : print 'LOADING IN PARALLEL DOMAIN'
        sdomain = sequential_distribute_load(filename='odomain', verbose = verbose)
        sdomain.set_name('sdomain')
        

        assert domain.get_datadir() == pdomain.get_datadir()
        assert domain.get_store() == pdomain.get_store()
        assert domain.get_store_centroids() == pdomain.get_store_centroids()
        assert domain.smooth == pdomain.smooth
        assert domain.reduction == pdomain.reduction
        assert domain.minimum_storable_height == pdomain.minimum_storable_height
        assert domain.get_flow_algorithm() == pdomain.get_flow_algorithm()
        assert domain.get_minimum_allowed_height() == pdomain.get_minimum_allowed_height()
        assert domain.geo_reference == pdomain.geo_reference
        
        assert domain.get_datadir() == sdomain.get_datadir()
        assert domain.get_store() == sdomain.get_store()
        assert domain.get_store_centroids() == sdomain.get_store_centroids()
        assert domain.smooth == sdomain.smooth
        assert domain.reduction == sdomain.reduction
        assert domain.minimum_storable_height == sdomain.minimum_storable_height
        assert domain.get_flow_algorithm() == sdomain.get_flow_algorithm()
        assert domain.get_minimum_allowed_height() == sdomain.get_minimum_allowed_height()
        assert domain.geo_reference == sdomain.geo_reference
Exemplo n.º 3
0
def run_simulation(parallel=False):

    domain = create_domain_from_file(mesh_filename)
    domain.set_quantity('stage', Set_Stage(756000.0, 756500.0, 2.0))

    #--------------------------------------------------------------------------
    # Create parallel domain if requested
    #--------------------------------------------------------------------------

    if parallel:
        if myid == 0 and verbose: print('DISTRIBUTING PARALLEL DOMAIN')
        domain = distribute(domain)

    #------------------------------------------------------------------------------
    # Setup boundary conditions
    # This must currently happen *after* domain has been distributed
    #------------------------------------------------------------------------------
    domain.store = False
    Br = Reflective_boundary(domain)  # Solid reflective wall

    domain.set_boundary({
        'outflow': Br,
        'inflow': Br,
        'inner': Br,
        'exterior': Br,
        'open': Br
    })

    #------------------------------------------------------------------------------
    # Evolution
    #------------------------------------------------------------------------------
    if parallel:
        if myid == 0 and verbose: print('PARALLEL EVOLVE')
    else:
        if verbose: print('SEQUENTIAL EVOLVE')

    for t in domain.evolve(yieldstep=yieldstep, finaltime=finaltime):
        pass
Exemplo n.º 4
0
def run_simulation(parallel=False, verbose=False):

    #--------------------------------------------------------------------------
    # Setup computational domain and quantities
    #--------------------------------------------------------------------------
    if myid == 0:
        domain = rectangular_cross_domain(M, N)
        domain.set_name('odomain')                    # Set sww filename
        domain.set_datadir('.')   
        domain.set_quantity('elevation', topography) # Use function for elevation
        domain.set_quantity('friction', 0.0)         # Constant friction 
        domain.set_quantity('stage', expression='elevation') # Dry initial stage
    else:
        domain = None
        
    #--------------------------------------------------------------------------
    # Create pickled partition
    #--------------------------------------------------------------------------
    if myid == 0:
        if verbose: print 'DUMPING PARTITION DATA'
        sequential_distribute_dump(domain, numprocs, verbose=verbose, parameters=new_parameters)    

    #--------------------------------------------------------------------------
    # Create the parallel domains
    #--------------------------------------------------------------------------
    if parallel:
        
        if myid == 0 and verbose : print 'DISTRIBUTING TO PARALLEL DOMAIN'
        pdomain = distribute(domain, verbose=verbose, parameters=new_parameters)
        pdomain.set_name('pdomain')
        
        if myid == 0 and verbose : print 'LOADING IN PARALLEL DOMAIN'
        sdomain = sequential_distribute_load(filename='odomain', verbose = verbose)
        sdomain.set_name('sdomain')
        
    if myid == 0 and verbose: print 'EVOLVING pdomain'    
    setup_and_evolve(pdomain, verbose=verbose)
 
    if myid == 0 and verbose: print 'EVOLVING sdomain'   
    setup_and_evolve(sdomain, verbose=verbose)
    
    if myid == 0:
        if verbose: print 'EVOLVING odomain'   
        setup_and_evolve(domain, verbose=verbose)
    

    if myid == 0 and verbose:
        parameter_file=open('odomain.txt', 'w')
        from pprint import pprint
        pprint(domain.get_algorithm_parameters(),parameter_file,indent=4)
        parameter_file.close()

        parameter_file=open('sdomain.txt', 'w')
        from pprint import pprint
        pprint(sdomain.get_algorithm_parameters(),parameter_file,indent=4)
        parameter_file.close()

        parameter_file=open('pdomain.txt', 'w')
        from pprint import pprint
        pprint(pdomain.get_algorithm_parameters(),parameter_file,indent=4)
        parameter_file.close()        
    
    assert num.allclose(pdomain.quantities['stage'].centroid_values, sdomain.quantities['stage'].centroid_values)
    assert num.allclose(pdomain.quantities['stage'].vertex_values, sdomain.quantities['stage'].vertex_values)
    
    assert num.allclose(pdomain.vertex_coordinates, sdomain.vertex_coordinates)
    assert num.allclose(pdomain.centroid_coordinates, sdomain.centroid_coordinates)
    
    

    #---------------------------------
    # Now compare the merged sww files
    #---------------------------------
    if myid == 0:
        if verbose: print 'COMPARING SWW FILES'
        
        odomain_v = util.get_output('odomain.sww')
        odomain_c = util.get_centroids(odomain_v)

        pdomain_v = util.get_output('pdomain.sww')
        pdomain_c = util.get_centroids(pdomain_v)
        
        sdomain_v = util.get_output('sdomain.sww')
        sdomain_c = util.get_centroids(sdomain_v)

        # Test some values against the original ordering
        
        if verbose:
            
            order = 2
            print 'PDOMAIN CENTROID VALUES'
            print num.linalg.norm(odomain_c.x-pdomain_c.x,ord=order)
            print num.linalg.norm(odomain_c.y-pdomain_c.y,ord=order)
            print num.linalg.norm(odomain_c.stage[-1]-pdomain_c.stage[-1],ord=order)
            print num.linalg.norm(odomain_c.xmom[-1]-pdomain_c.xmom[-1],ord=order)
            print num.linalg.norm(odomain_c.ymom[-1]-pdomain_c.ymom[-1],ord=order)
            print num.linalg.norm(odomain_c.xvel[-1]-pdomain_c.xvel[-1],ord=order)
            print num.linalg.norm(odomain_c.yvel[-1]-pdomain_c.yvel[-1],ord=order)        
            
             
            print 'SDOMAIN CENTROID VALUES'        
            print num.linalg.norm(odomain_c.x-sdomain_c.x,ord=order)
            print num.linalg.norm(odomain_c.y-sdomain_c.y,ord=order)
            print num.linalg.norm(odomain_c.stage[-1]-sdomain_c.stage[-1],ord=order)
            print num.linalg.norm(odomain_c.xmom[-1]-sdomain_c.xmom[-1],ord=order)
            print num.linalg.norm(odomain_c.ymom[-1]-sdomain_c.ymom[-1],ord=order)
            print num.linalg.norm(odomain_c.xvel[-1]-sdomain_c.xvel[-1],ord=order)
            print num.linalg.norm(odomain_c.yvel[-1]-sdomain_c.yvel[-1],ord=order)
            
            print 'PDOMAIN VERTEX VALUES'        
            print num.linalg.norm(odomain_v.stage[-1]-pdomain_v.stage[-1],ord=order)
            print num.linalg.norm(odomain_v.xmom[-1]-pdomain_v.xmom[-1],ord=order)
            print num.linalg.norm(odomain_v.ymom[-1]-pdomain_v.ymom[-1],ord=order)
            print num.linalg.norm(odomain_v.xvel[-1]-pdomain_v.xvel[-1],ord=order)
            print num.linalg.norm(odomain_v.yvel[-1]-pdomain_v.yvel[-1],ord=order)
            
            print 'SDOMAIN VERTEX VALUES'     
            print num.linalg.norm(odomain_v.stage[-1]-sdomain_v.stage[-1],ord=order)
            print num.linalg.norm(odomain_v.xmom[-1]-sdomain_v.xmom[-1],ord=order)
            print num.linalg.norm(odomain_v.ymom[-1]-sdomain_v.ymom[-1],ord=order)
            print num.linalg.norm(odomain_v.xvel[-1]-sdomain_v.xvel[-1],ord=order)
            print num.linalg.norm(odomain_v.yvel[-1]-sdomain_v.yvel[-1],ord=order)
            
            
            

        assert num.allclose(odomain_c.stage,pdomain_c.stage)
        assert num.allclose(odomain_c.xmom,pdomain_c.xmom)
        assert num.allclose(odomain_c.ymom,pdomain_c.ymom)
        assert num.allclose(odomain_c.xvel,pdomain_c.xvel)
        assert num.allclose(odomain_c.yvel,pdomain_c.yvel)
        
        assert num.allclose(odomain_v.x,pdomain_v.x)
        assert num.allclose(odomain_v.y,pdomain_v.y)
                
        assert num.linalg.norm(odomain_v.x-pdomain_v.x,ord=0) == 0
        assert num.linalg.norm(odomain_v.y-pdomain_v.y,ord=0) == 0
        assert num.linalg.norm(odomain_v.stage[-1]-pdomain_v.stage[-1],ord=0) < 100
        assert num.linalg.norm(odomain_v.xmom[-1]-pdomain_v.xmom[-1],ord=0) < 100 
        assert num.linalg.norm(odomain_v.ymom[-1]-pdomain_v.ymom[-1],ord=0) < 100
        assert num.linalg.norm(odomain_v.xvel[-1]-pdomain_v.xvel[-1],ord=0) < 100
        assert num.linalg.norm(odomain_v.yvel[-1]-pdomain_v.yvel[-1],ord=0) < 100     
        
        assert num.allclose(odomain_c.x,sdomain_c.x)
        assert num.allclose(odomain_c.y,sdomain_c.y)
        assert num.allclose(odomain_c.stage,sdomain_c.stage)
        assert num.allclose(odomain_c.xmom,sdomain_c.xmom)
        assert num.allclose(odomain_c.ymom,sdomain_c.ymom)
        assert num.allclose(odomain_c.xvel,sdomain_c.xvel)
        assert num.allclose(odomain_c.yvel,sdomain_c.yvel)
        
        assert num.allclose(odomain_v.x,sdomain_v.x)
        assert num.allclose(odomain_v.y,sdomain_v.y)
        
        order = 0
        assert num.linalg.norm(odomain_v.x-sdomain_v.x,ord=order) == 0
        assert num.linalg.norm(odomain_v.y-sdomain_v.y,ord=order) == 0
        assert num.linalg.norm(odomain_v.stage[-1]-sdomain_v.stage[-1],ord=order) < 100
        assert num.linalg.norm(odomain_v.xmom[-1]-sdomain_v.xmom[-1],ord=order) < 100
        assert num.linalg.norm(odomain_v.ymom[-1]-sdomain_v.ymom[-1],ord=order) < 100
        assert num.linalg.norm(odomain_v.xvel[-1]-sdomain_v.xvel[-1],ord=order) < 100
        assert num.linalg.norm(odomain_v.yvel[-1]-sdomain_v.yvel[-1],ord=order) < 100        
                
        # COMPARE CENTROID PDOMAIN SDOMAIN  
        assert num.allclose(pdomain_c.x,sdomain_c.x)
        assert num.allclose(pdomain_c.y,sdomain_c.y)
        assert num.allclose(pdomain_c.stage[-1],sdomain_c.stage[-1])
        assert num.allclose(pdomain_c.xmom[-1],sdomain_c.xmom[-1])
        assert num.allclose(pdomain_c.ymom[-1],sdomain_c.ymom[-1])
        assert num.allclose(pdomain_c.xvel[-1],sdomain_c.xvel[-1])
        assert num.allclose(pdomain_c.yvel[-1],sdomain_c.yvel[-1])
            
            
        # COMPARE VERTEX PDOMAIN SDOMAIN
        assert num.allclose(pdomain_v.x,sdomain_v.x)
        assert num.allclose(pdomain_v.y,sdomain_v.y)
        assert num.allclose(pdomain_v.stage[-1],sdomain_v.stage[-1])
        assert num.allclose(pdomain_v.xmom[-1],sdomain_v.xmom[-1])
        assert num.allclose(pdomain_v.ymom[-1],sdomain_v.ymom[-1])
        assert num.allclose(pdomain_v.xvel[-1],sdomain_v.xvel[-1])
        assert num.allclose(pdomain_v.yvel[-1],sdomain_v.yvel[-1])   
        
        
        import os
        os.remove('odomain.sww')
        os.remove('pdomain.sww')
        os.remove('sdomain.sww')
        os.remove('odomain_P4_0.pickle')
        os.remove('odomain_P4_1.pickle')
        os.remove('odomain_P4_2.pickle')
        os.remove('odomain_P4_3.pickle')
                                                         len1=length,
                                                         len2=width)
    domain = anuga.Domain(points, vertices, boundary)
    domain.set_name()  # Output name
    domain.set_flow_algorithm('DE0')
    domain.set_store_vertices_uniquely(True)
    domain.set_quantity('elevation', topography)
    domain.set_quantity('friction', 0.01)  # Constant friction
    domain.set_quantity('stage',
                        expression='elevation')  # Dry initial condition

else:

    domain = None

domain = distribute(domain, verbose=True)

#domain.set_store_vertices_uniquely(False)

gate = Boyd_box_operator(domain,
                         end_points=[[9.0, 2.5], [13.0, 2.5]],
                         losses=1.5,
                         width=1.5,
                         height=0.0001,
                         apron=5.0,
                         use_momentum_jet=True,
                         use_velocity_head=False,
                         manning=0.013,
                         verbose=False)

# Close the gate
Exemplo n.º 6
0
    domain.set_name('channel3')  # Output name
    domain.set_flow_algorithm('DE0')
    domain.print_statistics()

    domain.set_quantity('elevation', topography)  # elevation is a function
    domain.set_quantity('friction', 0.01)  # Constant friction
    domain.set_quantity('stage',
                        expression='elevation')  # Dry initial condition
else:
    domain = None

#------------------------------------------------------------------------------
# Distribute domain on processor 0 to to other processors
#------------------------------------------------------------------------------
#parameters = dict(ghost_layer_width=3)
domain = anuga.distribute(domain, verbose=True)

#------------------------------------------------------------------------------
# Setup boundary conditions
#------------------------------------------------------------------------------
Bi = anuga.Dirichlet_boundary([0.4, 0, 0])  # Inflow
Br = anuga.Reflective_boundary(domain)  # Solid reflective wall
Bo = anuga.Dirichlet_boundary([-5, 0, 0])  # Outflow

domain.set_boundary({'left': Bi, 'right': Bo, 'top': Br, 'bottom': Br})

#------------------------------------------------------------------------------
# Evolve system through time
#------------------------------------------------------------------------------
for t in domain.evolve(yieldstep=0.1, finaltime=16.0):
    if anuga.myid == 0:
    domain = None

#------------------------------------------------------------------------------
# Print out polygon points and ids as check
#------------------------------------------------------------------------------

if myid == 0:
    print '>>>>> erosion polygon1 contains ', polygon1
    print '>>>>> erosion polygon2 contains ', polygon2

#------------------------------------------------------------------------------
# Distribute the domain onto the n partitions
#------------------------------------------------------------------------------

domain = distribute(domain)

domain.set_store_vertices_uniquely(True)
domain.set_quantities_to_be_stored({
    'elevation': 2,
    'stage': 2,
    'xmomentum': 2,
    'ymomentum': 2
})

#------------------------------------------------------------------------------
# Setup boundary conditions on the distributed domain
#------------------------------------------------------------------------------
Bi = anuga.Dirichlet_boundary([1.2, 0, 0])  # Inflow at depth
Br = anuga.Reflective_boundary(domain)  # Solid reflective side walls
Bo = anuga.Dirichlet_boundary([-5, 0, 0])  # uncontrolled outflow
Exemplo n.º 8
0
    args = anuga.get_args()
    alg = args.alg
    verbose = args.verbose
    domain.set_flow_algorithm(alg)

    #------------------------------------------------------------------------------
    # Setup initial conditions
    #------------------------------------------------------------------------------
    domain.set_quantity('elevation',0.0)
    domain.set_quantity('friction', 0.0)
    domain.set_quantity('stage', height)

else:
    domain = None

domain = anuga.distribute(domain)

#-----------------------------------------------------------------------------
# Setup boundary conditions
#------------------------------------------------------------------------------
Br = anuga.Reflective_boundary(domain)      # Solid reflective wall

# Associate boundary tags with boundary objects
domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br})

#-------------------------------------------------------------------------
# Produce a documentation of parameters
#-------------------------------------------------------------------------
from anuga.validation_utilities import save_parameters_tex
save_parameters_tex(domain)
Exemplo n.º 9
0
def start_sim(run_id, Runs, scenario_name, Scenario, session, **kwargs):
    yieldstep = kwargs['yieldstep']
    finaltime = kwargs['finaltime']
    logger = logging.getLogger(run_id)
    max_triangle_area = kwargs['max_triangle_area']
    logger.info('Starting hydrata_project')

    if run_id == 'local_run':
        base_dir = os.getcwd()
    else:
        base_dir = os.getcwd() + '/base_dir/%s/' % run_id

    outname = run_id
    meshname = base_dir + 'outputs/' + run_id + '.msh'

    def get_filename(data_type, file_type):
        files = os.listdir('%sinputs/%s' % (base_dir, data_type))
        filename = '%sinputs/%s/%s' % (
            base_dir, data_type, [f for f in files if f[-4:] == file_type][0])
        return filename

    boundary_data_filename = get_filename('boundary_data', '.shp')
    elevation_data_filename = get_filename('elevation_data', '.tif')
    try:
        structures_filename = get_filename('structures', '.shp')
    except OSError as e:
        structures_filename = None
    try:
        rain_data_filename = get_filename('rain_data', '.shp')
    except OSError as e:
        rain_data_filename = None
    try:
        inflow_data_filename = get_filename('inflow_data', '.shp')
    except OSError as e:
        inflow_data_filename = None
    try:
        friction_data_filename = get_filename('friction_data', '.shp')
    except OSError as e:
        friction_data_filename = None

    logger.info('boundary_data_filename: %s' % boundary_data_filename)
    logger.info('structures_filename: %s' % structures_filename)
    logger.info('rain_data_filename: %s' % rain_data_filename)
    logger.info('inflow_data_filename: %s' % inflow_data_filename)
    logger.info('friction_data_filename: %s' % friction_data_filename)
    logger.info('elevation_data_filename: %s' % elevation_data_filename)

    # create a list of project files
    vector_filenames = [
        boundary_data_filename, structures_filename, rain_data_filename,
        inflow_data_filename, friction_data_filename
    ]

    # set the projection system for ANUGA calculations from the geotiff elevation data
    elevation_data_gdal = gdal.Open(elevation_data_filename)
    project_spatial_ref = osr.SpatialReference()
    project_spatial_ref.ImportFromWkt(elevation_data_gdal.GetProjectionRef())
    project_spatial_ref_epsg_code = int(
        project_spatial_ref.GetAttrValue("AUTHORITY", 1))

    # check the spatial reference system of the project files matches that of the calculation
    for filename in vector_filenames:
        if filename:
            prj_text = open(filename[:-4] + '.prj').read()
            srs = osr.SpatialReference()
            srs.ImportFromESRI([prj_text])
            srs.AutoIdentifyEPSG()
            logger.info('filename is: %s' % filename)
            logger.info('EPSG is: %s' % srs.GetAuthorityCode(None))
            if str(srs.GetAuthorityCode(None)) != str(
                    project_spatial_ref_epsg_code):
                logger.warning('warning spatial refs are not maching: %s, %s' %
                               (srs.GetAuthorityCode(None),
                                project_spatial_ref_epsg_code))

    logger.info('Setting up structures...')
    if structures_filename:
        structures = []
        logger.info('processing structures from :%s' % structures_filename)
        ogr_shapefile = ogr.Open(structures_filename)
        ogr_layer = ogr_shapefile.GetLayer(0)
        ogr_layer_feature = ogr_layer.GetNextFeature()
        while ogr_layer_feature:
            structure = json.loads(ogr_layer_feature.GetGeometryRef().
                                   ExportToJson())['coordinates'][0]
            structures.append(structure)
            ogr_layer_feature = None
            ogr_layer_feature = ogr_layer.GetNextFeature()

        logger.info('structures: %s' % structures)
    else:
        logger.warning('warning: no structures found.')
        structures = None

    logger.info('Setting up friction...')
    frictions = []
    if friction_data_filename:
        logger.info('processing frictions from :%s' % friction_data_filename)
        ogr_shapefile = ogr.Open(friction_data_filename)
        ogr_layer = ogr_shapefile.GetLayer(0)
        ogr_layer_feature = ogr_layer.GetNextFeature()
        while ogr_layer_feature:
            friction_poly = json.loads(ogr_layer_feature.GetGeometryRef().
                                       ExportToJson())['coordinates'][0]
            friction_value = float(ogr_layer_feature.GetField('mannings'))
            friction_couple = [friction_poly, friction_value]
            frictions.append(friction_couple)
            ogr_layer_feature = None
            ogr_layer_feature = ogr_layer.GetNextFeature()

        frictions.append(['All', 0.04])
        logger.info('frictions: %s' % frictions)
    else:
        frictions.append(['All', 0.04])
        logger.info('warning: no frictions found.')

    logger.info('Setting up boundary conditions...')
    ogr_shapefile = ogr.Open(boundary_data_filename)
    ogr_layer = ogr_shapefile.GetLayer(0)
    ogr_layer_definition = ogr_layer.GetLayerDefn()
    logger.info('ogr_layer_definition.GetGeomType: %s' %
                ogr_layer_definition.GetGeomType())
    boundary_tag_index = 0
    bdy_tags = {}
    bdy = {}

    ogr_layer_feature = ogr_layer.GetNextFeature()
    while ogr_layer_feature:
        boundary_tag_key = ogr_layer_feature.GetField('bdy_tag_k')
        boundary_tag_value = ogr_layer_feature.GetField('bdy_tag_v')
        bdy_tags[boundary_tag_key] = [
            boundary_tag_index * 2, boundary_tag_index * 2 + 1
        ]
        bdy[boundary_tag_key] = boundary_tag_value
        geom = ogr_layer_feature.GetGeometryRef().GetPoints()
        ogr_layer_feature = None
        ogr_layer_feature = ogr_layer.GetNextFeature()
        boundary_tag_index = boundary_tag_index + 1
        logger.info('bdy_tags: %s' % bdy_tags)
    logger.info('bdy: %s' % bdy)

    boundary_data = su.read_polygon(boundary_data_filename)

    create_mesh_from_regions(boundary_data,
                             boundary_tags=bdy_tags,
                             maximum_triangle_area=max_triangle_area,
                             interior_regions=None,
                             interior_holes=structures,
                             filename=meshname,
                             use_cache=False,
                             verbose=True)

    domain = Domain(meshname, use_cache=False, verbose=True)
    domain.set_name(outname)
    domain.set_datadir(base_dir + '/outputs')
    logger.info(domain.statistics())
    poly_fun_pairs = [['Extent', elevation_data_filename.encode("utf-8")]]
    topography_function = qs.composite_quantity_setting_function(
        poly_fun_pairs,
        domain,
        nan_treatment='exception',
    )
    friction_function = qs.composite_quantity_setting_function(
        frictions, domain)
    domain.set_quantity('friction', friction_function, verbose=True)
    domain.set_quantity('stage', 0.0)
    domain.set_quantity('elevation',
                        topography_function,
                        verbose=True,
                        alpha=0.99)
    domain.set_minimum_storable_height(0.005)

    logger.info('Applying rainfall...')
    if rain_data_filename:
        ogr_shapefile = ogr.Open(rain_data_filename)
        ogr_layer = ogr_shapefile.GetLayer(0)
        rainfall = 0
        ogr_layer_feature = ogr_layer.GetNextFeature()
        while ogr_layer_feature:
            rainfall = float(ogr_layer_feature.GetField('rate_mm_hr'))
            polygon = su.read_polygon(rain_data_filename)
            logger.info("applying Polygonal_rate_operator with rate, polygon:")
            logger.info(rainfall)
            logger.info(polygon)
            Polygonal_rate_operator(domain,
                                    rate=rainfall,
                                    factor=1.0e-6,
                                    polygon=polygon,
                                    default_rate=0.0)
            ogr_layer_feature = None
            ogr_layer_feature = ogr_layer.GetNextFeature()

    logger.info('Applying surface inflows...')
    if inflow_data_filename:
        ogr_shapefile = ogr.Open(inflow_data_filename)
        ogr_layer = ogr_shapefile.GetLayer(0)
        ogr_layer_definition = ogr_layer.GetLayerDefn()
        ogr_layer_feature = ogr_layer.GetNextFeature()
        while ogr_layer_feature:
            in_fixed = float(ogr_layer_feature.GetField('in_fixed'))
            line = ogr_layer_feature.GetGeometryRef().GetPoints()
            logger.info("applying Inlet_operator with line, in_fixed:")
            logger.info(line)
            logger.info(in_fixed)
            Inlet_operator(domain, line, in_fixed, verbose=False)
            ogr_layer_feature = None
            ogr_layer_feature = ogr_layer.GetNextFeature()

    logger.info('Applying Boundary Conditions...')
    logger.info('Available boundary tags: %s' % domain.get_boundary_tags())

    Br = anuga.Reflective_boundary(domain)
    Bd = anuga.Dirichlet_boundary([0.0, 0.0, 0.0])
    Bt = anuga.Transmissive_boundary(domain)

    for key, value in bdy.iteritems():
        if value == 'Br':
            bdy[key] = Br
        elif value == 'Bd':
            bdy[key] = Bd
        elif value == 'Bt':
            bdy[key] = Bt
        else:
            logger.info(
                'No matching boundary condition exists - please check your shapefile attributes in: %s'
                % boundary_data_filename)

    # set a default value for exterior & interior boundary if it is not already set
    try:
        bdy['exterior']
    except KeyError:
        bdy['exterior'] = Br
    try:
        bdy['interior']
    except KeyError:
        bdy['interior'] = Br

    logger.info('bdy: %s' % bdy)

    domain.set_boundary(bdy)

    domain = distribute(domain)
    logger.info('Beginning evolve phase...')
    for t in domain.evolve(yieldstep, finaltime):
        domain.write_time()
        print domain.timestepping_statistics()
        logger.info(domain.timestepping_statistics(track_speeds=True))
        percentage_complete = round(domain.time / domain.finaltime, 3) * 100
        logger.info('%s percent complete' % percentage_complete)
        if run_id != 'local_run':
            write_percentage_complete(run_id, Runs, scenario_name, Scenario,
                                      session, percentage_complete)
    domain.sww_merge(delete_old=True)
    barrier()
    finalize()
    sww_file = base_dir + '/outputs/' + run_id + '.sww'
    sww_file = sww_file.encode(
        'utf-8',
        'ignore')  # sometimes run_id gets turned to a unicode object by celery
    util.Make_Geotif(swwFile=sww_file,
                     output_quantities=['depth', 'velocity'],
                     myTimeStep='max',
                     CellSize=max_triangle_area,
                     lower_left=None,
                     upper_right=None,
                     EPSG_CODE=project_spatial_ref_epsg_code,
                     proj4string=None,
                     velocity_extrapolation=True,
                     min_allowed_height=1.0e-05,
                     output_dir=(base_dir + '/outputs/'),
                     bounding_polygon=boundary_data,
                     internal_holes=structures,
                     verbose=False,
                     k_nearest_neighbours=3,
                     creation_options=[])
    logger.info("Done. Nice work.")
    domain.set_name()                 # Output name
    domain.set_flow_algorithm('DE0')
    domain.set_store_vertices_uniquely(True)
    domain.set_quantity('elevation', topography)
    domain.set_quantity('friction', 0.01)         # Constant friction
    domain.set_quantity('stage',
                        expression='elevation')   # Dry initial condition



else:

    domain = None


domain = distribute(domain, verbose = True)

#domain.set_store_vertices_uniquely(False)


gate = Boyd_box_operator(domain,
                            end_points=[[9.0, 2.5],[13.0, 2.5]],
                            losses=1.5,
                            width=1.5,
                            height = 0.0001,
                            apron=5.0,
                            use_momentum_jet=True,
                            use_velocity_head=False,
                            manning=0.013,
                            verbose=False)
def run_simulation(parallel=False, G = None, seq_interpolation_points=None, verbose=False):

    #--------------------------------------------------------------------------
    # Setup computational domain and quantities
    #--------------------------------------------------------------------------
    domain = rectangular_cross_domain(M, N)
    domain.set_quantity('elevation', topography) # Use function for elevation
    domain.set_quantity('friction', 0.0)         # Constant friction 
    domain.set_quantity('stage', expression='elevation') # Dry initial stage

    #--------------------------------------------------------------------------
    # Create the parallel domain
    #--------------------------------------------------------------------------
    if parallel:
        if myid == 0 and verbose : print 'DISTRIBUTING PARALLEL DOMAIN'
        domain = distribute(domain, verbose=False)

    #--------------------------------------------------------------------------
    # Setup domain parameters
    #--------------------------------------------------------------------------
    domain.set_name('runup')                    # Set sww filename
    domain.set_datadir('.')                     # Set output dir

    domain.set_flow_algorithm('2_0')
    domain.set_quantities_to_be_stored(None)


    #------------------------------------------------------------------------------
    # Setup boundary conditions
    # This must currently happen *AFTER* domain has been distributed
    #------------------------------------------------------------------------------

    Br = Reflective_boundary(domain)      # Solid reflective wall
    Bd = Dirichlet_boundary([-0.2,0.,0.]) # Constant boundary values

    # Associate boundary tags with boundary objects
    domain.set_boundary({'left': Br, 'right': Bd, 'top': Br, 'bottom': Br})

    #------------------------------------------------------------------------------
    # Find which sub_domain in which the interpolation points are located 
    #
    # Sometimes the interpolation points sit exactly
    # between two centroids, so in the parallel run we
    # reset the interpolation points to the centroids
    # found in the sequential run
    #------------------------------------------------------------------------------
    interpolation_points = [[0.4,0.5], [0.6,0.5], [0.8,0.5], [0.9,0.5]]


    gauge_values = []
    tri_ids = []
    for i, point in enumerate(interpolation_points):
        gauge_values.append([]) # Empty list for timeseries

        #if is_inside_polygon(point, domain.get_boundary_polygon()):
        #print "Point ", myid, i, point
        try:
            k = domain.get_triangle_containing_point(point)
            if domain.tri_full_flag[k] == 1:
                tri_ids.append(k)
            else:
                tri_ids.append(-1)            
        except:
            tri_ids.append(-2)

        #print "  tri_ids ",myid, i, tri_ids[-1]
        
    if verbose: print 'P%d has points = %s' %(myid, tri_ids)


    c_coord = domain.get_centroid_coordinates()
    interpolation_points = []
    for id in tri_ids:
        if id<1:
            if verbose: print 'WARNING: Interpolation point not within the domain!'
        interpolation_points.append(c_coord[id,:])
            
    #------------------------------------------------------------------------------
    # Evolve system through time
    #------------------------------------------------------------------------------
    time = []

    if parallel:
        if myid == 0 and verbose: print 'PARALLEL EVOLVE'
    else:
        if myid == 0 and verbose: print 'SEQUENTIAL EVOLVE'
    

    for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime):
        if myid == 0 and verbose : domain.write_time()

        # Record time series at known points
        time.append(domain.get_time())

        stage = domain.get_quantity('stage')

        for i in range(4):
            if tri_ids[i] > -1:
                gauge_values[i].append(stage.centroid_values[tri_ids[i]])


    #----------------------------------------
    # Setup test arrays during sequential run
    #----------------------------------------
    if not parallel:
        G = []
        for i in range(4):
            G.append(gauge_values[i])

    success = True

    for i in range(4):
        if tri_ids[i] > -1:
            #print num.max(num.array(gauge_values[i])- num.array(G[i]))
            success = success and num.allclose(gauge_values[i], G[i])

    assert_(success)
    
    return G, interpolation_points
def run_simulation(parallel=False, verbose=False):

    #--------------------------------------------------------------------------
    # Setup computational domain and quantities
    #--------------------------------------------------------------------------
    if myid == 0:
        anuga.create_mesh_from_regions(
            boundaryPolygon,
            boundary_tags={
                'left': [0],
                'top': [1],
                'right': [2],
                'bottom': [3]
            },
            maximum_triangle_area=1.0e+20,
            minimum_triangle_angle=28.0,
            filename='runup.msh',
            interior_regions=[[higherResPolygon, 1. * 1. * 0.5],
                              [midResPolygon, 3.0 * 3.0 * 0.5]],
            breaklines=list(riverWall.values()),
            use_cache=False,
            verbose=verbose,
            regionPtArea=regionPtAreas)

        sdomain = anuga.create_domain_from_file('runup.msh')

        sdomain.set_flow_algorithm(alg)

        sdomain.set_name('s_riverwall')
        sdomain.set_datadir('.')
        sdomain.set_store_vertices_uniquely()

        #------------------
        # Define topography
        #------------------

        def topography(x, y):
            return -x / 150. * scale_me

        def stagefun(x, y):
            stg = -0.5 * scale_me
            return stg

        sdomain.set_quantity('elevation',
                             topography)  # Use function for elevation
        sdomain.set_quantity('friction', 0.03)  # Constant friction
        sdomain.set_quantity('stage',
                             stagefun)  # Constant negative initial stage
    else:
        sdomain = None

    #--------------------------------------------------------------------------
    # Create the parallel domains
    #--------------------------------------------------------------------------
    if parallel:

        if myid == 0 and verbose: print('DISTRIBUTING TO PARALLEL DOMAIN')
        pdomain = distribute(sdomain, verbose=verbose)
        pdomain.set_name('p_riverwall')
        pdomain.set_store_vertices_uniquely()

    if myid == 0 and verbose:
        print(60 * '=')
        print('EVOLVING pdomain')
        print(60 * '=')

    setup_and_evolve(pdomain, verbose=verbose)

    barrier()

    if myid == 0:
        if verbose:
            print(60 * '=')
            print('EVOLVING sdomain')
            print(60 * '=')
        setup_and_evolve(sdomain, verbose=verbose)

    barrier()

    #---------------------------------
    # Now compare the merged sww files
    #---------------------------------
    if myid == 0:
        if verbose: print('COMPARING SWW FILES')

        sdomain_v = util.get_output('s_riverwall.sww')
        sdomain_c = util.get_centroids(sdomain_v)

        pdomain_v = util.get_output('p_riverwall.sww')
        pdomain_c = util.get_centroids(pdomain_v)

        # Test some values against the original ordering

        if verbose:

            order = 0
            print('PDOMAIN CENTROID VALUES')
            print(num.linalg.norm(sdomain_c.x - pdomain_c.x, ord=order))
            print(num.linalg.norm(sdomain_c.y - pdomain_c.y, ord=order))
            print(
                num.linalg.norm(sdomain_c.stage[-1] - pdomain_c.stage[-1],
                                ord=order))
            print(
                num.linalg.norm(sdomain_c.xmom[-1] - pdomain_c.xmom[-1],
                                ord=order))
            print(
                num.linalg.norm(sdomain_c.ymom[-1] - pdomain_c.ymom[-1],
                                ord=order))
            print(
                num.linalg.norm(sdomain_c.xvel[-1] - pdomain_c.xvel[-1],
                                ord=order))
            print(
                num.linalg.norm(sdomain_c.yvel[-1] - pdomain_c.yvel[-1],
                                ord=order))

        assert num.allclose(sdomain_c.stage, pdomain_c.stage)
        assert num.allclose(sdomain_c.xmom, pdomain_c.xmom)
        assert num.allclose(sdomain_c.ymom, pdomain_c.ymom)
        assert num.allclose(sdomain_c.xvel, pdomain_c.xvel)
        assert num.allclose(sdomain_c.yvel, pdomain_c.yvel)

        assert num.allclose(sdomain_v.x, pdomain_v.x)
        assert num.allclose(sdomain_v.y, pdomain_v.y)

        import os
        os.remove('s_riverwall.sww')
        os.remove('p_riverwall.sww')
        os.remove('runup.msh')
def run_simulation(parallel=False, verbose=False):

    #--------------------------------------------------------------------------
    # Setup computational domain and quantities
    #--------------------------------------------------------------------------
    if myid == 0:
        anuga.create_mesh_from_regions(boundaryPolygon, 
                                 boundary_tags={'left': [0],
                                                'top': [1],
                                                'right': [2],
                                                'bottom': [3]},
                                   maximum_triangle_area = 1.0e+20,
                                   minimum_triangle_angle = 28.0,
                                   filename = 'runup.msh',
                                   interior_regions = [ [higherResPolygon, 1.*1.*0.5],
                                                        [midResPolygon, 3.0*3.0*0.5]],
                                   breaklines=riverWall.values(),
                                   use_cache=False,
                                   verbose=verbose,
                                   regionPtArea=regionPtAreas)
        
        sdomain=anuga.create_domain_from_file('runup.msh')
        
        
        sdomain.set_flow_algorithm(alg)
        
        
        sdomain.set_name('s_riverwall')                         
        sdomain.set_datadir('.')                         
        sdomain.set_store_vertices_uniquely()
        
        #------------------
        # Define topography
        #------------------
        
        def topography(x,y):
            return -x/150.*scale_me 
        
        def stagefun(x,y):
            stg=-0.5*scale_me
            return stg 
        
        sdomain.set_quantity('elevation',topography)     # Use function for elevation
        sdomain.set_quantity('friction',0.03)             # Constant friction
        sdomain.set_quantity('stage', stagefun)              # Constant negative initial stage
    else:
        sdomain = None
        
    #--------------------------------------------------------------------------
    # Create the parallel domains
    #--------------------------------------------------------------------------
    if parallel:
        
        if myid == 0 and verbose : print 'DISTRIBUTING TO PARALLEL DOMAIN'
        pdomain = distribute(sdomain, verbose=verbose)
        pdomain.set_name('p_riverwall')
        pdomain.set_store_vertices_uniquely()
        
        
    if myid == 0 and verbose: 
        print 60*'='
        print 'EVOLVING pdomain'
        print 60*'='
            
    setup_and_evolve(pdomain, verbose=verbose)
 
    barrier()
   
    if myid == 0:
        if verbose: 
            print 60*'='
            print 'EVOLVING sdomain'
            print 60*'='  
        setup_and_evolve(sdomain, verbose=verbose)
      
    barrier()
    
    #---------------------------------
    # Now compare the merged sww files
    #---------------------------------
    if myid == 0:
        if verbose: print 'COMPARING SWW FILES'
        
        sdomain_v = util.get_output('s_riverwall.sww')
        sdomain_c = util.get_centroids(sdomain_v)

        pdomain_v = util.get_output('p_riverwall.sww')
        pdomain_c = util.get_centroids(pdomain_v)
        

        # Test some values against the original ordering
        
        if verbose:
            
            order = 0
            print 'PDOMAIN CENTROID VALUES'
            print num.linalg.norm(sdomain_c.x-pdomain_c.x,ord=order)
            print num.linalg.norm(sdomain_c.y-pdomain_c.y,ord=order)
            print num.linalg.norm(sdomain_c.stage[-1]-pdomain_c.stage[-1],ord=order)
            print num.linalg.norm(sdomain_c.xmom[-1]-pdomain_c.xmom[-1],ord=order)
            print num.linalg.norm(sdomain_c.ymom[-1]-pdomain_c.ymom[-1],ord=order)
            print num.linalg.norm(sdomain_c.xvel[-1]-pdomain_c.xvel[-1],ord=order)
            print num.linalg.norm(sdomain_c.yvel[-1]-pdomain_c.yvel[-1],ord=order)        
            
        assert num.allclose(sdomain_c.stage,pdomain_c.stage)
        assert num.allclose(sdomain_c.xmom,pdomain_c.xmom)
        assert num.allclose(sdomain_c.ymom,pdomain_c.ymom)
        assert num.allclose(sdomain_c.xvel,pdomain_c.xvel)
        assert num.allclose(sdomain_c.yvel,pdomain_c.yvel)
        
        assert num.allclose(sdomain_v.x,pdomain_v.x)
        assert num.allclose(sdomain_v.y,pdomain_v.y)
        
        
        import os
        os.remove('s_riverwall.sww')
        os.remove('p_riverwall.sww')
        os.remove('runup.msh')
Exemplo n.º 14
0
    domain.set_flow_algorithm('DE0')
    print domain.statistics()


    
    domain.set_quantity('elevation', topography)           # elevation is a function
    domain.set_quantity('friction', 0.01)                  # Constant friction
    domain.set_quantity('stage', expression='elevation')   # Dry initial condition
else:
    domain = None

#------------------------------------------------------------------------------
# Distribute domain on processor 0 to to other processors
#------------------------------------------------------------------------------
#parameters = dict(ghost_layer_width=3)
domain = anuga.distribute(domain, verbose= True)


#------------------------------------------------------------------------------
# Setup boundary conditions
#------------------------------------------------------------------------------
Bi = anuga.Dirichlet_boundary([0.4, 0, 0])          # Inflow
Br = anuga.Reflective_boundary(domain)              # Solid reflective wall
Bo = anuga.Dirichlet_boundary([-5, 0, 0])           # Outflow

domain.set_boundary({'left': Bi, 'right': Bo, 'top': Br, 'bottom': Br})

#------------------------------------------------------------------------------
# Evolve system through time
#------------------------------------------------------------------------------
for t in domain.evolve(yieldstep=0.1, finaltime=16.0):
Exemplo n.º 15
0
    Stage = domain.quantities['stage'].centroid_values
    Stage[:] = Stage + uZ

    #domain.add_quantity('stage',
    #                   function=okada_deformation,
    #                   verbose=project.verbose,
    #                   location='centroids')

    domain.set_quantity('friction', 0.0)
else:
    domain = None

#-------------------------------------------------------------------------------
# Distribute domain
#-------------------------------------------------------------------------------
domain = distribute(domain, verbose=project.verbose)

#===============================================================================
# Parallel Section
#===============================================================================

domain.set_quantities_to_be_stored({
    'stage': 2,
    'xmomentum': 2,
    'ymomentum': 2,
    'elevation': 2
})
domain.set_quantities_to_be_monitored(['stage', 'xmomentum', 'ymomentum'])

if myid == 0: print('running project:', project.scenario)
#------------------------------------------------------------------------------
Exemplo n.º 16
0
def run_simulation(parallel=False, G = None, seq_interpolation_points=None, verbose=False):

    #--------------------------------------------------------------------------
    # Setup computational domain and quantities
    #--------------------------------------------------------------------------
    domain = rectangular_cross_domain(M, N)


    domain.set_quantity('elevation', topography) # Use function for elevation
    domain.set_quantity('friction', 0.0)         # Constant friction
    domain.set_quantity('stage', expression='elevation') # Dry initial stage

    domain.set_low_froude(1)

    domain.set_name('runup')                    # Set sww filename
    domain.set_datadir('.')                     # Set output dir

    #--------------------------------------------------------------------------
    # Create the parallel domain
    #--------------------------------------------------------------------------
    if parallel:
        if myid == 0 and verbose : print('DISTRIBUTING PARALLEL DOMAIN')
        domain = distribute(domain, verbose=False)

    #--------------------------------------------------------------------------
    # Setup domain parameters
    #--------------------------------------------------------------------------


    domain.set_quantities_to_be_stored(None)


    #------------------------------------------------------------------------------
    # Setup boundary conditions
    # This must currently happen *AFTER* domain has been distributed
    #------------------------------------------------------------------------------

    Br = Reflective_boundary(domain)      # Solid reflective wall
    Bd = Dirichlet_boundary([-0.2,0.,0.]) # Constant boundary values

    # Associate boundary tags with boundary objects
    domain.set_boundary({'left': Br, 'right': Bd, 'top': Br, 'bottom': Br})

    #------------------------------------------------------------------------------
    # Find which sub_domain in which the interpolation points are located
    #
    # Sometimes the interpolation points sit exactly
    # between two centroids, so in the parallel run we
    # reset the interpolation points to the centroids
    # found in the sequential run
    #------------------------------------------------------------------------------
    interpolation_points = [[0.4,0.5], [0.6,0.5], [0.8,0.5], [0.9,0.5]]


    gauge_values = []
    tri_ids = []
    for i, point in enumerate(interpolation_points):
        gauge_values.append([]) # Empty list for timeseries

        #if is_inside_polygon(point, domain.get_boundary_polygon()):
        #print "Point ", myid, i, point
        try:
            k = domain.get_triangle_containing_point(point)
            if domain.tri_full_flag[k] == 1:
                tri_ids.append(k)
            else:
                tri_ids.append(-1)
        except:
            tri_ids.append(-2)

        #print "  tri_ids ",myid, i, tri_ids[-1]

    if verbose: print('P%d has points = %s' %(myid, tri_ids))


    c_coord = domain.get_centroid_coordinates()
    interpolation_points = []
    for id in tri_ids:
        if id<1:
            if verbose: print('WARNING: Interpolation point not within the domain!')
        interpolation_points.append(c_coord[id,:])

    #------------------------------------------------------------------------------
    # Evolve system through time
    #------------------------------------------------------------------------------
    time = []

    if parallel:
        if myid == 0 and verbose: print('PARALLEL EVOLVE')
    else:
        if myid == 0 and verbose: print('SEQUENTIAL EVOLVE')


    for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime):
        if myid == 0 and verbose : domain.write_time()

        # Record time series at known points
        time.append(domain.get_time())

        stage = domain.get_quantity('stage')

        for i in range(4):
            if tri_ids[i] > -1:
                gauge_values[i].append(stage.centroid_values[tri_ids[i]])


    #----------------------------------------
    # Setup test arrays during sequential run
    #----------------------------------------
    if not parallel:
        G = []
        for i in range(4):
            G.append(gauge_values[i])

    success = True

    for i in range(4):
        if tri_ids[i] > -1:
            #print num.max(num.array(gauge_values[i])- num.array(G[i]))
            success = success and num.allclose(gauge_values[i], G[i])

    assert_(success)

    return G, interpolation_points
Exemplo n.º 17
0
def run_simulation(parallel=False, verbose=False):

    #--------------------------------------------------------------------------
    # Setup computational domain and quantities
    #--------------------------------------------------------------------------
    domain = rectangular_cross_domain(M, N)
    domain.set_name('odomain')  # Set sww filename
    domain.set_datadir('.')
    domain.set_quantity('elevation', topography)  # Use function for elevation
    domain.set_quantity('friction', 0.0)  # Constant friction
    domain.set_quantity('stage', expression='elevation')  # Dry initial stage

    domain.set_quantities_to_be_stored({
        'elevation': 2,
        'stage': 2,
        'xmomentum': 2,
        'ymomentum': 2
    })
    domain.set_store_vertices_uniquely(False)
    domain.set_flow_algorithm('DE1')
    georef = Geo_reference(zone=56, xllcorner=100000.0, yllcorner=200000.0)
    domain.set_georeference(georef)

    #--------------------------------------------------------------------------
    # Create pickled partition
    #--------------------------------------------------------------------------
    if myid == 0:
        if verbose: print 'DUMPING PARTITION DATA'
        sequential_distribute_dump(domain,
                                   numprocs,
                                   verbose=verbose,
                                   parameters=new_parameters)

    #--------------------------------------------------------------------------
    # Create the parallel domains
    #--------------------------------------------------------------------------
    if parallel:

        if myid == 0 and verbose: print 'DISTRIBUTING TO PARALLEL DOMAIN'
        pdomain = distribute(domain,
                             verbose=verbose,
                             parameters=new_parameters)
        pdomain.set_name('pdomain')

        if myid == 0 and verbose: print 'LOADING IN PARALLEL DOMAIN'
        sdomain = sequential_distribute_load(filename='odomain',
                                             verbose=verbose)
        sdomain.set_name('sdomain')

        assert domain.get_datadir() == pdomain.get_datadir()
        assert domain.get_store() == pdomain.get_store()
        assert domain.get_store_centroids() == pdomain.get_store_centroids()
        assert domain.smooth == pdomain.smooth
        assert domain.reduction == pdomain.reduction
        assert domain.minimum_storable_height == pdomain.minimum_storable_height
        assert domain.get_flow_algorithm() == pdomain.get_flow_algorithm()
        assert domain.get_minimum_allowed_height(
        ) == pdomain.get_minimum_allowed_height()
        assert domain.geo_reference == pdomain.geo_reference

        assert domain.get_datadir() == sdomain.get_datadir()
        assert domain.get_store() == sdomain.get_store()
        assert domain.get_store_centroids() == sdomain.get_store_centroids()
        assert domain.smooth == sdomain.smooth
        assert domain.reduction == sdomain.reduction
        assert domain.minimum_storable_height == sdomain.minimum_storable_height
        assert domain.get_flow_algorithm() == sdomain.get_flow_algorithm()
        assert domain.get_minimum_allowed_height(
        ) == sdomain.get_minimum_allowed_height()
        assert domain.geo_reference == sdomain.geo_reference
Exemplo n.º 18
0
    #--------------------------------------------------------------------------
    args = anuga.get_args()
    alg = args.alg
    verbose = args.verbose
    domain.set_flow_algorithm(alg)

    #-------------------------------------------------------------------------
    # Setup initial conditions
    #-------------------------------------------------------------------------
    domain.set_quantity('elevation',0.0)
    domain.set_quantity('friction', 0.0)
    domain.set_quantity('stage', height)
else:
    domain = None

domain = anuga.distribute(domain)

#-----------------------------------------------------------------------------
# Setup boundary conditions
#------------------------------------------------------------------------------
Br = anuga.Reflective_boundary(domain)      # Solid reflective wall

# Associate boundary tags with boundary objects
domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br})

#-------------------------------------------------------------------------
# Produce a documentation of parameters
#-------------------------------------------------------------------------
from anuga.validation_utilities import save_parameters_tex
save_parameters_tex(domain)
Exemplo n.º 19
0
        domain = create_domain_from_file(mesh_filename)
        domain.set_quantity('stage', Set_Stage(x0, x1, 1.0))

        domain.set_name(domain_name)
        domain.set_store(True)

        domain.set_store_vertices_smoothly(False)
    else:
        domain = None

    #--------------------------------------------------------------------------
    # Distribute sequential domain on processor 0 to other processors
    #--------------------------------------------------------------------------

    if myid == 0 and verbose: print 'DISTRIBUTING DOMAIN'
    domain = distribute(domain, verbose=verbose)

    #--------------------------------------------------------------------------
    # On all processors, setup evolve parameters for domains on all processors
    # (all called "domain"
    #--------------------------------------------------------------------------

    domain.set_flow_algorithm('DE0')
    domain.set_store_centroids()

    domain.set_quantities_to_be_stored({
        'elevation': 1,
        'friction': 1,
        'stage': 2,
        'xmomentum': 2,
        'ymomentum': 2
Exemplo n.º 20
0
                        filename=project.name_stem + '.pts',
                        use_cache=project.cache,
                        verbose=project.verbose,
                        alpha=0.1)



else:
    domain = None



#------------------------------------------------------------------------------
# Now produce parallel domain
#------------------------------------------------------------------------------
domain = distribute(domain,verbose=project.verbose)

domain.set_store_vertices_uniquely(False)

#------------------------------------------------------------------------------
# Setup information for slide scenario (to be applied 1 min into simulation
#------------------------------------------------------------------------------
if project.scenario == 'slide':
    # Function for submarine slide
    tsunami_source = anuga.slide_tsunami(length=35000.0,
                                   depth=project.slide_depth,
                                   slope=6.0,
                                   thickness=500.0, 
                                   x0=project.slide_origin[0], 
                                   y0=project.slide_origin[1], 
                                   alpha=0.0, 
Exemplo n.º 21
0
        domain = create_domain_from_file(mesh_filename)
        domain.set_quantity('stage', Set_Stage(x0, x1, 1.0))

        domain.set_name(domain_name)
        domain.set_store(True)

        domain.set_store_vertices_smoothly(False)
    else:
        domain = None
    
    #--------------------------------------------------------------------------
    # Distribute sequential domain on processor 0 to other processors
    #--------------------------------------------------------------------------
    
    if myid == 0 and verbose: print 'DISTRIBUTING DOMAIN'
    domain = distribute(domain, verbose=verbose)
    
    #--------------------------------------------------------------------------
    # On all processors, setup evolve parameters for domains on all processors
    # (all called "domain"
    #--------------------------------------------------------------------------
    
    domain.set_flow_algorithm('DE0')
    domain.set_store_centroids()
    
    domain.set_quantities_to_be_stored({'elevation':1,
                                        'friction':1,
                                        'stage':2,
                                        'xmomentum':2,
                                        'ymomentum':2})
                                     
    
    #------------------------------------------------------------------------------
    # Setup initial conditions
    #------------------------------------------------------------------------------
    domain.set_quantity('friction', 0.0)
    domain.set_quantity('stage', stage_flat)
    domain.set_quantity('elevation', bed_elevation)
    
else:
    
    domain = None
    
#-----------------------------------------------------------------------------
# Parallel Domain
#-----------------------------------------------------------------------------
domain = distribute(domain)    

#-----------------------------------------------------------------------------
# Setup boundary conditions
#------------------------------------------------------------------------------
from math import sin, pi, exp
Br = anuga.Reflective_boundary(domain)      # Solid reflective wall
#Bt = anuga.Transmissive_boundary(domain)    # Continue all values on boundary 
#Bd = anuga.Dirichlet_boundary([1,0.,0.]) # Constant boundary values

# Associate boundary tags with boundary objects
domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br})



Exemplo n.º 23
0
def run_simulation(parallel=False, verbose=False):

    #--------------------------------------------------------------------------
    # Setup computational domain and quantities
    #--------------------------------------------------------------------------
    domain = rectangular_cross_domain(M, N)
    domain.set_name('odomain')                    # Set sww filename
    domain.set_datadir('.')   
    domain.set_quantity('elevation', topography) # Use function for elevation
    domain.set_quantity('friction', 0.0)         # Constant friction 
    domain.set_quantity('stage', expression='elevation') # Dry initial stage
    
    domain.set_quantities_to_be_stored({'elevation': 2,'stage': 2,'xmomentum': 2,'ymomentum': 2})
    domain.set_store_vertices_uniquely(False)
    domain.set_flow_algorithm('DE1')
    georef = Geo_reference(zone=56,xllcorner=100000.0,yllcorner=200000.0)
    domain.set_georeference(georef)
        
    #--------------------------------------------------------------------------
    # Create pickled partition
    #--------------------------------------------------------------------------
    if myid == 0:
        if verbose: print('DUMPING PARTITION DATA')
        sequential_distribute_dump(domain, numprocs, verbose=verbose, parameters=new_parameters)    

    #--------------------------------------------------------------------------
    # Create the parallel domains
    #--------------------------------------------------------------------------
    if parallel:
        
        if myid == 0 and verbose : print('DISTRIBUTING TO PARALLEL DOMAIN')
        pdomain = distribute(domain, verbose=verbose, parameters=new_parameters)
        pdomain.set_name('pdomain')
        
        if myid == 0 and verbose : print('LOADING IN PARALLEL DOMAIN')
        sdomain = sequential_distribute_load(filename='odomain', verbose = verbose)
        sdomain.set_name('sdomain')
        
        if myid == 0 and verbose : print('TESTING AGAINST SEQUENTIAL DOMAIN')
        assert domain.get_datadir() == pdomain.get_datadir()
        assert domain.get_store() == pdomain.get_store()
        assert domain.get_store_centroids() == pdomain.get_store_centroids()
        assert domain.smooth == pdomain.smooth
        assert domain.reduction == pdomain.reduction
        assert domain.minimum_storable_height == pdomain.minimum_storable_height
        assert domain.get_flow_algorithm() == pdomain.get_flow_algorithm()
        assert domain.get_minimum_allowed_height() == pdomain.get_minimum_allowed_height()
        assert domain.geo_reference == pdomain.geo_reference
        
        assert domain.get_datadir() == sdomain.get_datadir()
        assert domain.get_store() == sdomain.get_store()
        assert domain.get_store_centroids() == sdomain.get_store_centroids()
        assert domain.smooth == sdomain.smooth
        assert domain.reduction == sdomain.reduction
        assert domain.minimum_storable_height == sdomain.minimum_storable_height
        assert domain.get_flow_algorithm() == sdomain.get_flow_algorithm()
        assert domain.get_minimum_allowed_height() == sdomain.get_minimum_allowed_height()
        assert domain.geo_reference == sdomain.geo_reference

        if myid == 0 and verbose : print('REMOVING DATA FILES')
        if myid == 0:
            import os
            #os.remove('odomain.sww')
            #os.remove('pdomain.sww')
            #os.remove('sdomain.sww')
            try:
                os.remove('odomain_P4_0.pickle')
                os.remove('odomain_P4_1.pickle')
                os.remove('odomain_P4_2.pickle')
                os.remove('odomain_P4_3.pickle')
                import glob
                [ os.remove(fl) for fl in glob.glob('*.npy') ]
            except: 
                if verbose: print('remove files failed')

        if myid == 0 and verbose : print('FINISHED')