def create_domain(self, flowalg):
        # Riverwall = list of lists, each with a set of x,y,z (and optional QFactor) values

        # Make the domain
        domain = anuga.create_domain_from_regions(
            boundaryPolygon,
            boundary_tags={
                'left': [0],
                'top': [1],
                'right': [2],
                'bottom': [3]
            },
            mesh_filename='test_boundaryfluxintegral.msh',
            maximum_triangle_area=200.,
            minimum_triangle_angle=28.0,
            use_cache=False,
            verbose=verbose)

        # 05/05/2014 -- riverwalls only work with DE0 and DE1
        domain.set_flow_algorithm(flowalg)
        domain.set_name('test_boundaryfluxintegral')

        domain.set_store_vertices_uniquely()

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

        # NOTE: Setting quantities at centroids is important for exactness of tests
        domain.set_quantity('elevation', topography, location='centroids')
        domain.set_quantity('friction', 0.03)
        domain.set_quantity('stage', topography, location='centroids')

        # Boundary conditions
        Br = anuga.Reflective_boundary(domain)
        Bd = anuga.Dirichlet_boundary([0., 0., 0.])
        domain.set_boundary({'left': Br, 'right': Bd, 'top': Br, 'bottom': Br})

        return domain
Example #2
0
def CreateDomain(topo_in, bound_in, datadir, inlet_btag, outlet_btag, res,
                 parlist):
    # Import Channel topography DEM
    # Create DEM from asc data
    anuga.asc2dem(topo_in + '.asc', use_cache=False, verbose=True)

    # Create DEM from asc data
    anuga.dem2pts(topo_in + '.dem', use_cache=False, verbose=True)

    # Define boundaries for mesh
    # Read in coordinate file
    bounding_polygon = anuga.read_polygon(bound_in + '.csv')
    print(inlet_btag)
    #Determine tag to assign as reflective exterior
    for i in numpy.arange(1, 4):
        print(i)
        if int(i) == int(inlet_btag):
            print(str(inlet_btag) + ' already taken')
        else:
            print(str(i) + ' used as exterior tag')
            break
    # Create mesh with bounding polygon
    domain = anuga.create_domain_from_regions(bounding_polygon,
                                              boundary_tags={
                                                  'inlet': [inlet_btag],
                                                  'exterior': [i],
                                                  'outlet': [outlet_btag]
                                              },
                                              maximum_triangle_area=res,
                                              mesh_filename=parlist + '.msh',
                                              use_cache=False,
                                              verbose=True)

    # Name domain and decide where to save
    domain.set_name(parlist)
    domain.set_datadir('.')
    return domain
    def create_domain(self, flowalg):
        # Riverwall = list of lists, each with a set of x,y,z (and optional QFactor) values

        # Make the domain
        domain = anuga.create_domain_from_regions(boundaryPolygon, 
                                 boundary_tags={'left': [0],
                                                'top': [1],
                                                'right': [2],
                                                'bottom': [3]},
                                   mesh_filename='test_boundaryfluxintegral.msh',
                                   maximum_triangle_area = 200.,
                                   minimum_triangle_angle = 28.0,
                                   use_cache=False,
                                   verbose=verbose)


        # 05/05/2014 -- riverwalls only work with DE0 and DE1
        domain.set_flow_algorithm(flowalg)
        domain.set_name('test_boundaryfluxintegral')

        domain.set_store_vertices_uniquely()
       
        def topography(x,y):
            return -x/150. 

        # NOTE: Setting quantities at centroids is important for exactness of tests
        domain.set_quantity('elevation',topography,location='centroids')     
        domain.set_quantity('friction',0.03)             
        domain.set_quantity('stage', topography,location='centroids')            
       
        # Boundary conditions
        Br=anuga.Reflective_boundary(domain)
        Bd=anuga.Dirichlet_boundary([0., 0., 0.])
        domain.set_boundary({'left': Br, 'right': Bd, 'top': Br, 'bottom':Br})

        return domain
Example #4
0
def run_model():
    """Run a tsunami simulation for a scenario."""

    # Read in boundary from ordered sts file
    event_sts = anuga.create_sts_boundary(project.event_sts)

    # Reading the landward defined points, this incorporates the original
    # clipping polygon minus the 100m contour
    landward_boundary = anuga.read_polygon(project.landward_boundary_file, do_complex_check=False)

    # Combine sts polyline with landward points
    bounding_polygon_sts = event_sts + landward_boundary

    # Number of boundary segments
    num_ocean_segments = len(event_sts) - 1
    # Number of landward_boundary points
    num_land_points = anuga.file_length(project.landward_boundary_file)

    # Boundary tags refer to project.landward_boundary_file
    # 4 points equals 5 segments start at N
    boundary_tags={'back': range(num_ocean_segments+1,
                                 num_ocean_segments+num_land_points),
                   'side': [num_ocean_segments,
                            num_ocean_segments+num_land_points],
                   'ocean': range(num_ocean_segments)}

    # Build mesh and domain
    log.debug('bounding_polygon_sts=%s' % str(bounding_polygon_sts))
    log.debug('boundary_tags=%s' % str(boundary_tags))
    log.debug('project.bounding_maxarea=%s' % str(project.bounding_maxarea))
    log.debug('project.interior_regions=%s' % str(project.interior_regions))
    log.debug('project.mesh_file=%s' % str(project.mesh_file))

    domain = anuga.create_domain_from_regions(bounding_polygon_sts,
                                boundary_tags=boundary_tags,
                                maximum_triangle_area=project.bounding_maxarea,
                                interior_regions=project.interior_regions,
                                mesh_filename=project.mesh_file,
                                use_cache=False,
                                verbose=False)

    domain.geo_reference.zone = project.zone_number
    log.info('\n%s' % domain.statistics())

    domain.set_name(project.scenario)
    domain.set_datadir(project.output_folder)
    domain.set_minimum_storable_height(0.01)  # Don't store depth less than 1cm

    # set overall friction before setting in interior regions
    domain.set_quantity('friction', project.friction)

    # set friction in interior regions, if any defined
    friction_list = []
    for (irtype, filename, friction) in project.interior_regions_list:
        if irtype.lower() == 'friction':
            friction_list.append([filename, friction])
    if friction_list:
        log.debug('friction_list=%s' % str(friction_list))
        poly_friction = []
        for (fname, friction) in friction_list:
            full_fname = os.path.join(project.polygons_folder, fname)
            log.debug('Reading friction polygon: %s' % full_fname)
            poly = anuga.read_polygon(full_fname)
            poly_friction.append((poly, friction))
            log.debug('poly=%s' % str(poly))
        domain.set_quantity('friction',
                            anuga.Polygon_function(poly_friction,
                                                   default=project.friction,
                                                   geo_reference=domain.geo_reference))

    # Set the initial stage in the offcoast region only
    if project.land_initial_conditions:
        IC = anuga.Polygon_function(project.land_initial_conditions,
                                    default=project.initial_tide,
                                    geo_reference=domain.geo_reference)
    else:
        IC = project.initial_tide

    domain.set_quantity('stage', IC, use_cache=True, verbose=False)
    domain.set_quantity('elevation',
                        filename=project.combined_elevation_file,
                        use_cache=True, verbose=False, alpha=project.alpha)

    # Setup boundary conditions
    log.debug('Set boundary - available tags: %s' % domain.get_boundary_tags())

    Br = anuga.Reflective_boundary(domain)
    Bt = anuga.Transmissive_stage_zero_momentum_boundary(domain)
    Bd = anuga.Dirichlet_boundary([project.initial_tide, 0, 0])
    Bf = anuga.Field_boundary(project.event_sts+'.sts',
                        domain, mean_stage=project.initial_tide, time_thinning=1,
## NICK debug                        default_boundary=anuga.Dirichlet_boundary([0, 0, 0]),
                        default_boundary=Bt,
                        boundary_polygon=bounding_polygon_sts,
                        use_cache=True, verbose=False)

    domain.set_boundary({'back': Br,
                         'side': Bt,
                         'ocean': Bf})

    # Evolve system through time
    t0 = time.time()
    for t in domain.evolve(yieldstep=project.yieldstep,
                           finaltime=project.finaltime,
                           skip_initial_step=False):
        log.info('\n%s' % domain.timestepping_statistics())
        log.info('\n%s' % domain.boundary_statistics(tags='ocean'))

    log.info('Simulation took %.2f seconds' % (time.time()-t0))
                  verbose=project.verbose)

    # Create pts file for onshore DEM
    anuga.dem2pts(project.name_stem+'.dem', use_cache=project.cache, 
                  verbose=project.verbose)

    #------------------------------------------------------------------------------
    # Create the triangular mesh and domain based on
    # overall clipping polygon with a tagged
    # boundary and interior regions as defined in project.py
    #------------------------------------------------------------------------------
    domain = anuga.create_domain_from_regions(project.bounding_polygon,
                                        boundary_tags={'top': [0],
                                                       'ocean_east': [1],
                                                       'bottom': [2],
                                                       'onshore': [3]},
                                        maximum_triangle_area=project.default_res,
                                        mesh_filename=project.meshname,
                                        interior_regions=project.interior_regions,
                                        use_cache=project.cache,
                                        verbose=project.verbose)

    # Print some stats about mesh and domain
    print 'Number of triangles = ', len(domain)
    print 'The extent is ', domain.get_extent()
    print domain.statistics()

    #------------------------------------------------------------------------------
    # Setup parameters of computational domain
    #------------------------------------------------------------------------------
    domain.set_name('cairns_' + project.scenario) # Name of sww file
    domain.set_datadir('.')                       # Store sww output here
Example #6
0
    # point_sw = [xleft, ybottom]
    # point_se = [xright, ybottom]
    # point_nw = [xleft, ytop]
    # point_ne = [xright, ytop]

    # bounding_polygon = [point_se,
    #                 point_ne,
    #                 point_nw,
    #                 point_sw]
    bounding_polygon = gpd.read_file('area/domain.shp')

    # domain= anuga.create_domain_from_regions(bounding_polygon, boundary_tags={'bottom':[0],}, maximum_triangle_area=0.001,verbose=True)
    domain = anuga.create_domain_from_regions(
        list(bounding_polygon.exterior[0].coords),
        boundary_tags={
            'bottom': [0],
        },
        maximum_triangle_area=0.0001,
        #             minimum_triangle_area=1
    )

    domain.set_name('excessive_rain_para')

    domain.set_quantity('elevation',
                        filename=topography_file,
                        location='centroids')  # Use function for elevation
    domain.set_quantity('friction', 0.3,
                        location='centroids')  # Constant friction
    domain.set_quantity('stage', expression='elevation',
                        location='centroids')  # Dry Bed

    domain.set_quantity('SS0', 0, location='centroids')
Example #7
0
# Create pts file for onshore DEM
anuga.dem2pts(name_stem+'.dem', use_cache=v_cache, verbose=v_verbose)

#------------------------------------------------------------------------------
# Create the triangular mesh and domain based on
# overall clipping polygon with a tagged
# boundary and interior regions as defined in project.py
#------------------------------------------------------------------------------
domain = anuga.create_domain_from_regions(bounding_polygon,
                                    boundary_tags={'land_sse': [0],
                                                   'land_s': [1],
                                                   'bottom': [2],
                                                   'ocean_wsw': [3],
                                                   'ocean_w': [4],
                                                   'ocean_wnw': [5],
                                                   'top': [6],
                                                   'land_nne': [7],
                                                   'land_ese': [8],
                                                   'land_se': [9]},
                                    maximum_triangle_area=default_res,
                                    mesh_filename=meshname,
                                    interior_regions=interior_regions,
                                    use_cache=v_cache,
                                    verbose=v_verbose)

# Print some stats about mesh and domain
print 'Number of triangles = ', len(domain)
print 'The extent is ', domain.get_extent()
print domain.statistics()

#------------------------------------------------------------------------------
# Setup parameters of computational domain
anuga.dem2pts(dem_cdf_file, use_cache=cache, verbose=verbose)

interior_regions = [] # this makes huge mesh [bounding_polygon, base_scale] ]

# name + list of segments
boundary_tags = { 'in': [0] } # {'in': [0], 'other': [1,2,3,4] }

#------------------------------------------------------------------------------
# Create the triangular mesh and domain based on
# overall clipping polygon with a tagged
# boundary and interior regions as defined in project.py
#------------------------------------------------------------------------------
domain = anuga.create_domain_from_regions(bounding_polygon,
                                    boundary_tags=boundary_tags,
                                    maximum_triangle_area=default_res,
                                    mesh_filename=mesh_file,
                                    interior_regions=interior_regions,
                                    use_cache=cache,
                                    verbose=verbose)


# Print some stats about mesh and domain
print 'Number of triangles = ', len(domain)
print 'The extent is ', domain.get_extent()
print domain.statistics()

domain.set_name(name) # Name of sww file
domain.set_datadir('.')                       # Store sww output here
#domain.set_minimum_storable_height(0.01)      # Store only depth > 1cm
domain.set_flow_algorithm('DE0')
Example #9
0
def generate_cairns_domain(gpu=False):
    #-----------------------------------------------------------------------
    # Preparation of topographic data
    # Convert ASC 2 DEM 2 PTS using source data 
    # and store result in source data
    #-----------------------------------------------------------------------
    # Create DEM from asc data
    anuga.asc2dem(project.name_stem+'.asc', use_cache=True, verbose=True)
    
    # Create pts file for onshore DEM
    anuga.dem2pts(project.name_stem+'.dem', use_cache=True, verbose=True)
    
    #-----------------------------------------------------------------------
    # Create the triangular mesh and domain based on 
    # overall clipping polygon with a tagged
    # boundary and interior regions as defined in project.py
    #-----------------------------------------------------------------------
    domain = anuga.create_domain_from_regions(project.bounding_polygon,
            boundary_tags={'top': [0],
            'ocean_east': [1],
            'bottom': [2],
            'onshore': [3]},
            maximum_triangle_area=project.default_res,
            mesh_filename=project.meshname,
            interior_regions=project.interior_regions,
            use_cache=True,
            verbose=True)

    if gpu :
        #domain.__class__ = GPU_domain
        domain = GPU_domain(domain=domain)
    # Print some stats about mesh and domain
    print 'Number of triangles = ', len(domain)
    #print 'The extent is ', domain.get_extent()
    #print domain.statistics()
                                        
    #-----------------------------------------------------------------------
    # Setup parameters of computational domain
    #-----------------------------------------------------------------------
    domain.set_name('cairns_' + project.scenario) # Name of sww file
    domain.set_datadir('.')                       # Store sww output here
    domain.set_minimum_storable_height(0.01)      # Store only depth > 1cm
    domain.set_flow_algorithm('tsunami')
    
    #-----------------------------------------------------------------------
    # Setup initial conditions
    #-----------------------------------------------------------------------
    tide = 0.0
    domain.set_quantity('stage', tide)
    domain.set_quantity('friction', 0.0)
    
    
    domain.set_quantity('elevation', 
                        filename=project.name_stem + '.pts',
                        use_cache=True,
                        verbose=True,
                        alpha=0.1)
    
    #-----------------------------------------------------------------------
    # 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, 
                                       domain=domain,
                                       verbose=True)
    
    #-----------------------------------------------------------------------
    # Setup boundary conditions
    #-----------------------------------------------------------------------
    print 'Available boundary tags', domain.get_boundary_tags()
    
    Bd = anuga.Dirichlet_boundary([tide, 0, 0]) # Mean water level
    Bs = anuga.Transmissive_stage_zero_momentum_boundary(domain) 
    # Neutral boundary
    
    if project.scenario == 'fixed_wave':
        # Huge 50m wave starting after 60 seconds and lasting 1 hour.
        Bw=anuga.Transmissive_n_momentum_zero_t_momentum_set_stage_boundary(
                            domain=domain, 
                            function=lambda t: [(60<t<3660)*50, 0, 0])
    
        domain.set_boundary({'ocean_east': Bw,
                             'bottom': Bs,
                             'onshore': Bd,
                             'top': Bs})
    
    if project.scenario == 'slide':
        # Boundary conditions for slide scenario
        domain.set_boundary({'ocean_east': Bd,
                             'bottom': Bd,
                             'onshore': Bd,
                             'top': Bd})
    
    
    if gpu:
        if '-gpu' in sys.argv:
            domain.using_gpu = True
            print " --> Enable GPU version"
    return domain
channel_polygon = [ [floodplain_width/2. - chan_width/2., +l0],
                    [floodplain_width/2. - chan_width/2., floodplain_length - l0],
                    [floodplain_width/2. + chan_width/2., floodplain_length - l0],
                    [floodplain_width/2. + chan_width/2., +l0]
                    ]
if myid == 0:
    # Define domain with appropriate boundary conditions
    domain = anuga.create_domain_from_regions( boundary_polygon, 
                                       boundary_tags={'left': [0],
                                                      'top1': [1],
                                                      'chan_out': [2],
                                                      'top2': [3],
                                                      'right': [4],
                                                      'bottom1': [5],
                                                      'chan_in': [6],
                                                      'bottom2': [7] },
                                       maximum_triangle_area = 0.5*l0*l0,
                                       minimum_triangle_angle = 28.0,
                                       mesh_filename = 'channel_floodplain.msh',
                                       interior_regions = [ ],
                                       #interior_regions = [\
                                       #    [channel_polygon, 0.5*l0*l0] ],
                                       use_cache=False,
                                       verbose=verbose)

    domain.set_name('channel_floodplain') # Output name
    domain.set_flow_algorithm(alg)

    #------------------------------------------------------------------------------
    # Setup initial conditions
    #------------------------------------------------------------------------------
Example #11
0
    [floodplain_width / 2. - chan_width / 2., floodplain_length - l0],
    [floodplain_width / 2. + chan_width / 2., floodplain_length - l0],
    [floodplain_width / 2. + chan_width / 2., +l0]
]
if myid == 0:
    # Define domain with appropriate boundary conditions
    domain = anuga.create_domain_from_regions(
        boundary_polygon,
        boundary_tags={
            'left': [0],
            'top1': [1],
            'chan_out': [2],
            'top2': [3],
            'right': [4],
            'bottom1': [5],
            'chan_in': [6],
            'bottom2': [7]
        },
        maximum_triangle_area=0.5 * l0 * l0,
        minimum_triangle_angle=28.0,
        mesh_filename='channel_floodplain.msh',
        interior_regions=[],
        #interior_regions = [\
        #    [channel_polygon, 0.5*l0*l0] ],
        use_cache=False,
        verbose=verbose)

    domain.set_name('channel_floodplain')  # Output name
    domain.set_flow_algorithm(alg)

    #------------------------------------------------------------------------------
    # Setup initial conditions
Example #12
0
    poly_from_box(35, 40, 3.5, 8.5),
]  # downstream box

building_tags = [
    {"upstream": [1]},  # Set segment[0], default others
    None,  # Use default interior tag
    {"downstream": [0, 1]},
]  # set segments[0,1],default others


# create a domain mesh, with 3 building holes in it
domain = anuga.create_domain_from_regions(
    boundary_poly,
    boundary_tags=boundary_tags,
    maximum_triangle_area=resolution,
    mesh_filename="building.msh",
    interior_holes=building_polys,
    hole_tags=building_tags,
    use_cache=True,  # to speed it up
    verbose=True,
)  # log output on

domain.set_name("buildings")  # Output name


# ------------------------------------------------------------------------------
# Setup initial conditions
# ------------------------------------------------------------------------------
def topography(x, y):
    return -x / 15  # gentle linear bed slope

Example #13
0
def run_chennai(sim_id):
    project_root = os.path.abspath(os.path.dirname(__file__))
    if not os.path.exists(project_root):
        os.makedirs(project_root)
    print "project_root = " + project_root

    inputs_dir = '%s/inputs/' % project_root
    if not os.path.exists(inputs_dir):
        os.makedirs(inputs_dir)
    print "inputs_dir = " + inputs_dir

    working_dir = '%s/working/%s/' % (project_root, sim_id)
    if not os.path.exists(working_dir):
        os.makedirs(working_dir)
    print "working_dir = " + working_dir

    outputs_dir = '%s/outputs/%s' % (project_root, sim_id)
    if not os.path.exists(outputs_dir):
        os.makedirs(outputs_dir)
    print "outputs_dir = " + outputs_dir

    # get data
    print "downloading data..."
    urllib.urlretrieve(
        'http://chennaifloodmanagement.org/uploaded/layers/utm44_1arc_v3.tif',
        inputs_dir + 'utm44_1arc_v3.tif'
    )

    print os.listdir(inputs_dir)

    # configure logging TODO: get this working!
    log_location = project_root + '/' + sim_id + '.log'
    open(log_location, 'a').close()
    log.console_logging_level = log.INFO
    log.log_logging_level = log.DEBUG
    log.log_filename = log_location
    print "# log.log_filename is: " + log.log_filename
    print "# log_location is: " + log_location
    log.debug('A message at DEBUG level')
    log.info('Another message, INFO level')

    print "# starting"
    bounding_polygon_01 = [
        [303382.14647903712, 1488780.8996663219],
        [351451.89152459265, 1499834.3704521982],
        [378957.03975921532, 1493150.8764886451],
        [422656.80798244767, 1504204.3472745214],
        [433196.16384805075, 1471300.9923770288],
        [421885.63560203766, 1413463.0638462803],
        [408261.59021479468, 1372590.9276845511],
        [371245.31595511554, 1427344.16669366],
        [316492.0769460068, 1417833.0406686035],
        [303382.14647903712, 1488780.8996663219]
    ]
    boundary_tags_01 = {
        'inland': [0, 1, 2, 6, 7, 8],
        'ocean': [3, 4, 5]
    }
    print "# Create domain:"
    print "# mesh_filename = " + working_dir + 'mesh_01.msh'
    domain = anuga.create_domain_from_regions(bounding_polygon=bounding_polygon_01,
                                              boundary_tags=boundary_tags_01,
                                              mesh_filename=working_dir + 'mesh_01.msh',
                                              maximum_triangle_area=100000,
                                              verbose=True)
    domain.set_name(sim_id)
    domain.set_datadir(outputs_dir)
    poly_fun_pairs = [
            [
                'Extent',
                inputs_dir + 'utm44_1arc_v3.tif'
            ]
    ]
    print "# create topography_function"
    print "input raster = " + inputs_dir + 'utm44_1arc_v3.tif'
    topography_function = qs.composite_quantity_setting_function(
        poly_fun_pairs,
        domain,
        nan_treatment='exception',
    )
    print topography_function
    print "# set_quantity elevation"
    domain.set_quantity('elevation', topography_function)  # Use function for elevation
    domain.set_quantity('friction', 0.03)  # Constant friction
    domain.set_quantity('stage', 1)  # Constant initial stage

    print "# all quantities set"

    print "# Setup boundary conditions"
    Br = anuga.Reflective_boundary(domain)  # Solid reflective wall
    Bt = anuga.Transmissive_boundary(domain)  # Continue all values on boundary
    Bd = anuga.Dirichlet_boundary([-20, 0., 0.])  # Constant boundary values
    Bi = anuga.Dirichlet_boundary([10.0, 0, 0])  # Inflow
    Bw = anuga.Time_boundary(
        domain=domain,  # Time dependent boundary
        function=lambda t: [(10 * sin(t * 2 * pi) - 0.3) * exp(-t), 0.0, 0.0]
    )

    print "# Associate boundary tags with boundary objects"
    domain.set_boundary({'inland': Br, 'ocean': Bd})
    print domain.get_boundary_tags()

    catchmentrainfall = Rainfall(
        domain=domain,
        rate=0.2
    )
    # # Note need path to File in String.
    # # Else assumed in same directory
    domain.forcing_terms.append(catchmentrainfall)

    print "# Evolve system through time"
    counter_timestep = 0
    for t in domain.evolve(yieldstep=300, finaltime=6000):
        counter_timestep += 1
        print counter_timestep
        print domain.timestepping_statistics()

    asc_out_momentum = outputs_dir + '/' + sim_id + '_momentum.asc'
    asc_out_depth = outputs_dir + '/' + sim_id + '_depth.asc'

    anuga.sww2dem(outputs_dir + '/' + sim_id + '.sww',
                  asc_out_momentum,
                  quantity='momentum',
                  number_of_decimal_places=3,
                  cellsize=30,
                  reduction=max,
                  verbose=True)
    anuga.sww2dem(outputs_dir + '/' + sim_id + '.sww',
                  asc_out_depth,
                  quantity='depth',
                  number_of_decimal_places=3,
                  cellsize=30,
                  reduction=max,
                  verbose=True)

    outputs =[asc_out_depth, asc_out_momentum]

    for output in outputs:
        print "# Convert ASCII grid to GeoTiff so geonode can import it"
        src_ds = gdal.Open(output)
        dst_filename = (output[:-3] + 'tif')

        print "# Create gtif instance"
        driver = gdal.GetDriverByName("GTiff")

        print "# Output to geotiff"
        dst_ds = driver.CreateCopy(dst_filename, src_ds, 0)

        print "# Properly close the datasets to flush the disk"
        dst_filename = None
        src_ds = None

    print "Done. Nice work."
Example #14
0
poly2 = [p12, p1, p4, p14, p15, p7, p10, p13]
poly3 = [p14, p5, p6, p15]

interiors = [[poly1, max_tri_area_inu], [poly2, max_tri_area_focus], [poly3, max_tri_area_base]]

# ------------------------------------------------------------------------------
###STEP-1 Mesh Creation
# ------------------------------------------------------------------------------

if p_stepMesh:
    dirStruct(domain_name)
    os.chdir(prj_output_dir)
    domain = anuga.create_domain_from_regions(bounding_polygon,
                                              boundary_tags,
                                              maximum_triangle_area=max_tri_area_base,
                                              mesh_filename=prj_output_dir + os.sep + mesh_file,
                                              interior_regions=interiors,
                                              use_cache=p_cache,
                                              verbose=p_verbose)
    domain.set_name(domain_name)
    domain.set_datadir(prj_output_dir)
    domain.set_flow_algorithm(flow_alg)
    domain.set_minimum_storable_height(p_minimum_storable_height)
    domain.set_quantity('elevation', topography, location='vertices')
    domain.set_quantity('friction', p_friction)
    domain.set_quantity('stage', initial_stage)

    # ------------------------------------------------------------------------------
    Br = anuga.Reflective_boundary(domain)  # Solid reflective wall
    Bt = anuga.Transmissive_boundary(domain)  # Continue all values on boundary
    Bs = anuga.Transmissive_stage_zero_momentum_boundary(domain)
Example #15
0
# Resolution for most of the mesh
base_resolution = 100.0  # m^2

# Resolution in particular area of interest
york_resolution = 50.0  # m^2

interior_regions = [[york_polygon, york_resolution]]

##

domain = anuga.create_domain_from_regions(
    bounding_polygon,
    boundary_tags={
        'bottom': [0],
        'right': [1],
        'top': [2],
        'left': [3]
    },
    maximum_triangle_area=base_resolution,
    interior_regions=interior_regions)

domain.set_name('york1')  # Name of sww file
dplotter = animate.Domain_plotter(domain)
plt.triplot(dplotter.triang, linewidth=0.4)
plt.show()

##

domain.set_quantity('elevation',
                    filename=topography_file,
                    location='centroids')  # Use function for elevation
Example #16
0
# Only create sequential domain on processor 0
#===============================================================================
if myid == 0:
    #------------------------------------------------------------------------------
    # Create the triangular mesh and domain based on
    # overall clipping polygon with a tagged
    # boundary and interior regions as defined in project.py
    #------------------------------------------------------------------------------
    print('project name: ', project.name_stem)
    domain = anuga.create_domain_from_regions(
        project.bounding_polygon,
        boundary_tags={
            'bottom': [0],
            'ocean_east': [1],
            'top': [2],
            'onshore': [3]
        },
        maximum_triangle_area=project.res_whole,
        mesh_filename=project.meshname,
        interior_regions=project.interior_regions,
        use_cache=True,
        verbose=True)

    # Print some stats about mesh and domain
    print('Number of triangles = ', len(domain))
    print('The extent is ', domain.get_extent())
    print(domain.statistics())

    #------------------------------------------------------------------------------
    # Setup parameters of computational domain
    #------------------------------------------------------------------------------
Example #17
0
# Import Channel topography DEM
# Create DEM from asc data
anuga.asc2dem(topo_in + '.asc', use_cache=False, verbose=True)

# Create DEM from asc data
anuga.dem2pts(topo_in + '.dem', use_cache=False, verbose=True)

# Define boundaries for mesh
# Read in coordinate file
bounding_polygon = anuga.read_polygon(bound_in + '.csv')
# Create mesh with bounding polygon
domain = anuga.create_domain_from_regions(bounding_polygon,
                                          boundary_tags={
                                              'inlet': [inlet_btag],
                                              'exterior': [ref_btag],
                                              'outlet': [outlet_btag]
                                          },
                                          maximum_triangle_area=res,
                                          mesh_filename=identifier + '.msh',
                                          use_cache=False,
                                          verbose=True)

# Name domain and decide where to save
domain.set_name(identifier)
domain.set_datadir('.')

# Set quantities for domain
# Set elevation from topography file
domain.set_quantity('elevation', filename=topo_in + '.pts')
# Set Manning Roughness of bed
domain.set_quantity('friction', 0.030)
# Set initial stage (if dry bed, set to elevation)
Example #18
0
# Create pts file for onshore DEM
anuga.dem2pts(name_stem+'.dem', use_cache=v_cache, verbose=v_verbose)

#------------------------------------------------------------------------------
# Create the triangular mesh and domain based on
# overall clipping polygon with a tagged
# boundary and interior regions as defined in project.py
#------------------------------------------------------------------------------
domain = anuga.create_domain_from_regions(busselton_extent,
                                    boundary_tags={'land_sse': [0],
                                                   'land_s': [1],
                                                   'bottom': [2],
                                                   'ocean_wsw': [3],
                                                   'ocean_w': [4],
                                                   'ocean_wnw': [5],
                                                   'top': [6],
                                                   'land_nne': [7],
                                                   'land_ese': [8],
                                                   'land_se': [9]},
                                    maximum_triangle_area=default_res,
                                    mesh_filename=meshname,
                                    use_cache=v_cache,
                                    verbose=v_verbose)

# Print some stats about mesh and domain
print 'Number of triangles = ', len(domain)
print 'The extent is ', domain.get_extent()
print domain.statistics()

#------------------------------------------------------------------------------
# Setup parameters of computational domain
Example #19
0
# Create sequential domain
#======================================
if(myid==0):
    # Boundary tags refer to project.landward_boundary
    # 4 points equals 5 segments start at N
    boundary_tags={'back': range(num_ocean_segments+1,
                             num_ocean_segments+num_land_points),
               'side': [num_ocean_segments,
                        num_ocean_segments+num_land_points],
               'ocean': range(num_ocean_segments)}

    # Build mesh and domain
    domain = anuga.create_domain_from_regions(bounding_polygon_sts,
                                    boundary_tags=boundary_tags,
                                    maximum_triangle_area=project.bounding_maxarea,
                                    interior_regions=project.interior_regions,
                                    mesh_filename=project.meshes,
                                    use_cache=False,
                                    verbose=verbose)
    log.critical(domain.statistics())

    # FIXME(Ole): How can we make this more automatic?
    domain.geo_reference.zone = project.zone


    domain.set_name(project.scenario_name)
    domain.set_datadir(project.output_run) 

    domain.set_flow_algorithm(alg)

    #-------------------------------------------------------------------------------
Example #20
0
InitialLandStage=6.

riverWall = { 'centralWall':
                           [ [wallLoc, 0.0, wallHeight],
                             [wallLoc, 100.0, wallHeight]] 
                        }

riverWall_Par = {'centralWall':{'Qfactor':1.0}}

domain = anuga.create_domain_from_regions(boundaryPolygon, 
                         boundary_tags={'left': [0],
                                        'top': [1],
                                        'right': [2],
                                        'bottom': [3]},
                           maximum_triangle_area = 10.0,
                           minimum_triangle_angle = 28.0,
                           interior_regions =[ ], #[ [higherResPolygon, 1.*1.*0.5],
                                                  #  [midResPolygon, 3.0*3.0*0.5]],
                           breaklines=tobreaklines(riverWall)+inlet1_poly+inlet2_poly,
                           regionPtArea=regionPtAreas,
                           use_cache=False,
                           verbose=False)


domain.set_name('run_pump')
domain.set_store_vertices_uniquely(True)


#=======================================
# Setup Initial conditions
#=======================================
Example #21
0
#------------------------------------------------------------------------------
# Do the domain creation on processor 0
#------------------------------------------------------------------------------
if myid == 0:
    # Create DEM from asc data
    anuga.asc2dem('11_fbe_c.asc', use_cache=False, verbose=True)

    # Create DEM from asc data
    anuga.dem2pts('11_fbe_c.dem', use_cache=False, verbose=True)

    bounding_polygon = anuga.read_polygon('channel.csv')

    domain = anuga.create_domain_from_regions(bounding_polygon,
                                              boundary_tags={'exterior': [1]},
                                              maximum_triangle_area=1,
                                              mesh_filename='11f.msh',
                                              use_cache=False,
                                              verbose=True)

    #Name domain
    domain.set_name('11_fbe_c')
    domain.set_datadir('.')

    #Set quantities for domain, set dry bed
    domain.set_quantity('elevation', filename='11_fbe_c.pts')
    domain.set_quantity('friction', 0.040)
    domain.set_quantity('stage', expression='elevation')

    #Define and set boundaries
    Br = anuga.Reflective_boundary(domain)  # Solid reflective wall
    Bt = anuga.Transmissive_boundary(domain)  # Continue all values on boundary
from anuga.operators.rate_operators import Rate_operator

#op1 = Rate_operator(domain, rate=lambda t: 10.0 if (t>=0.0) else 0.0, polygon=polygon2)
op2 = Rate_operator(domain, rate=lambda t: 10.0 if (t>=0.0) else 0.0, radius=1.0, center=(10.0, 3.0))

def dyn_t(t):
    return t+0.5
op1 = Rate_operator(domain, polygon=polygon1)
domain.set_starttime(-0.1)
boundary_tags={'bottom': [0],
                'right': [1],
                'top': [2],
                'left': [3]}
dodm = anuga.create_domain_from_regions(polygon2,boundary_tags,
                               maximum_triangle_area = 0.5,
                               )
from anuga import Region
region1 = Region(domain,radius = 1.0, center = (10.0, 3.0))
if isinstance(region1, Region):
    op2.region = region1
else:
    op2.region = Region(domain, poly=region1, expand_polygon=True)

if isinstance(polygon1, Region):
    op1.region = polygon1
else:
    op1.region = Region(domain, poly=polygon1, expand_polygon=True)


from self_try import get_circumference_indices
Example #23
0
def run_model():
    """Run a tsunami simulation for a scenario."""

    log.info('@'*90)
    log.info('@ Running simulation')
    log.info('@'*90)

    # Read in boundary from ordered sts file
    event_sts = anuga.create_sts_boundary(project.event_sts)

    # Reading the landward defined points, this incorporates the original
    # clipping polygon minus the 100m contour
    landward_boundary = anuga.read_polygon(project.landward_boundary)

    # Combine sts polyline with landward points
    bounding_polygon_sts = event_sts + landward_boundary

    # Number of boundary segments
    num_ocean_segments = len(event_sts) - 1
    # Number of landward_boundary points
    num_land_points = anuga.file_length(project.landward_boundary)

    # Boundary tags refer to project.landward_boundary
    # 4 points equals 5 segments start at N
    boundary_tags={'back': range(num_ocean_segments+1,
                                 num_ocean_segments+num_land_points),
                   'side': [num_ocean_segments,
                            num_ocean_segments+num_land_points],
                   'ocean': range(num_ocean_segments)}

    # Build mesh and domain
    log.debug('bounding_polygon_sts=%s' % str(bounding_polygon_sts))
    log.debug('boundary_tags=%s' % str(boundary_tags))
    log.debug('project.bounding_maxarea=%s' % str(project.bounding_maxarea))
    log.debug('project.interior_regions=%s' % str(project.interior_regions))
    log.debug('project.meshes=%s' % str(project.meshes))

    domain = anuga.create_domain_from_regions(bounding_polygon_sts,
                                boundary_tags=boundary_tags,
                                maximum_triangle_area=project.bounding_maxarea,
                                interior_regions=project.interior_regions,
                                mesh_filename=project.meshes,
                                use_cache=False,
                                verbose=False)

    domain.geo_reference.zone = project.zone
    log.info('\n%s' % domain.statistics())

    domain.set_name(project.scenario_name)
    domain.set_datadir(project.output_folder)
    domain.set_minimum_storable_height(0.01)  # Don't store depth less than 1cm

    # Set the initial stage in the offcoast region only
    if project.land_initial_conditions:
        IC = anuga.Polygon_function(project.land_initial_conditions,
                                    default=project.tide,
                                    geo_reference=domain.geo_reference)
    else:
        IC = project.tide

    domain.set_quantity('stage', IC, use_cache=True, verbose=False)
    domain.set_quantity('friction', project.friction)
    domain.set_quantity('elevation',
                        filename=project.combined_elevation_filestem+'.pts',
                        use_cache=True, verbose=False, alpha=project.alpha)

    # Setup boundary conditions
    log.debug('Set boundary - available tags: %s' % domain.get_boundary_tags())

    Br = anuga.Reflective_boundary(domain)
    Bt = anuga.Transmissive_stage_zero_momentum_boundary(domain)
    Bd = anuga.Dirichlet_boundary([project.tide, 0, 0])
    Bf = anuga.Field_boundary(project.event_sts+'.sts',
                        domain, mean_stage=project.tide, time_thinning=1,
                        default_boundary=anuga.Dirichlet_boundary([0, 0, 0]),
                        boundary_polygon=bounding_polygon_sts,
                        use_cache=True, verbose=False)

    domain.set_boundary({'back': Br,
                         'side': Bt,
                         'ocean': Bf})

    # Evolve system through time
    t0 = time.time()
    for t in domain.evolve(yieldstep=project.yieldstep,
                           finaltime=project.finaltime,
                           skip_initial_step=False):
        log.info('\n%s' % domain.timestepping_statistics())
        log.info('\n%s' % domain.boundary_statistics(tags='ocean'))

    log.info('Simulation took %.2f seconds' % (time.time()-t0))
Example #24
0
#======================================
if (myid == 0):
    # Boundary tags refer to project.landward_boundary
    # 4 points equals 5 segments start at N
    boundary_tags = {
        'back': range(num_ocean_segments + 1,
                      num_ocean_segments + num_land_points),
        'side': [num_ocean_segments, num_ocean_segments + num_land_points],
        'ocean': range(num_ocean_segments)
    }

    # Build mesh and domain
    domain = anuga.create_domain_from_regions(
        bounding_polygon_sts,
        boundary_tags=boundary_tags,
        maximum_triangle_area=project.bounding_maxarea,
        interior_regions=project.interior_regions,
        mesh_filename=project.meshes,
        use_cache=False,
        verbose=verbose)
    log.critical(domain.statistics())

    # FIXME(Ole): How can we make this more automatic?
    domain.geo_reference.zone = project.zone

    domain.set_name(project.scenario_name)
    domain.set_datadir(project.output_run)

    domain.set_flow_algorithm(alg)

    #-------------------------------------------------------------------------------
    # Setup initial conditions
# Place 3 buildings downstream
building_polys = [  poly_from_box(10, 15, 2.5, 7.5),        # upstream box
                    poly_from_box(22.5, 27.5, 1.5, 6.5),    # middle box
                    poly_from_box(35, 40, 3.5, 8.5)]        # downstream box
					
building_tags = [ { 'upstream'   : [1]},    # Set segment[0], default others
                  None,                     # Use default interior tag
		  { 'downstream' : [0,1]} ] # set segments[0,1],default others


# create a domain mesh, with 3 building holes in it
domain = anuga.create_domain_from_regions(boundary_poly,
                                            boundary_tags=boundary_tags,
                                            maximum_triangle_area = resolution,
                                            mesh_filename = 'building.msh',
                                            interior_holes = building_polys,
                                            hole_tags = building_tags,
                                            use_cache=True, # to speed it up
                                            verbose=True)   # log output on
 
domain.set_name('buildings')                 # Output name


#------------------------------------------------------------------------------
# Setup initial conditions
#------------------------------------------------------------------------------
def topography(x,y):
    return -x/15                             # gentle linear bed slope

domain.set_quantity('elevation', topography) # Use function for elevation
domain.set_quantity('friction', 0.03)        # Constant friction 
Example #26
0
                                        maximum_triangle_area=base_resolution,
                                        interior_regions=interior_regions
                                          )
"""
#domain = anuga.rectangular_cross_domain(10,5,len1 = 2.5, len2 = 1.0)
bounding_polygon = [[0.0, 0.0],
                    [20.0, 0.0],
                    [20.0, 10.0],
                    [0.0, 10.0]]

boundary_tags={'bottom': [0],
                'right': [1],
                'top': [2],
                'left': [3]}
domain = anuga.create_domain_from_regions(bounding_polygon,
                               boundary_tags,
                               maximum_triangle_area = 0.5,
                               )
domain.set_name("small_resolution1")
#domain.set_name('merewether1') # Name of sww file
#dplotter = anuga.Domain_plotter(domain)
#plt.triplot(dplotter.triang, linewidth = 0.4);

domain.set_quantity('elevation', 0.5)
domain.set_quantity('friction', 0.01)         # Constant friction
domain.set_quantity('stage',
                    expression='elevation')   # Dry initial condition
Bi = anuga.Dirichlet_boundary([2.0, 0, 0])         # Inflow
Bo = anuga.Dirichlet_boundary([-2, 0, 0])
Br = anuga.Reflective_boundary(domain)             # Solid reflective wall

domain.set_boundary({'left': Bi, 'right': Br, 'top': Br, 'bottom': Br})
Example #27
0
anuga.dem2pts(project.name_stem + '.dem',
              use_cache=project.cache,
              verbose=project.verbose)

#------------------------------------------------------------------------------
# Create the triangular mesh and domain based on overall clipping
# polygons with a tagged boundary and interior regions as defined
# in project.py
#------------------------------------------------------------------------------
domain = anuga.create_domain_from_regions(
    project.bounding_polygon,
    boundary_tags={
        'east': [0],
        'bottom_ocean': [1],
        'west': [2],
        'onshore': [3]
    },
    maximum_triangle_area=project.default_res,
    mesh_filename=project.meshname,
    interior_regions=project.interior_regions,
    use_cache=project.cache,
    verbose=project.verbose)
# Print some stats about mesh and domain
print 'Number of triangles = ', len(domain)
print 'The extent is ', domain.get_extent()
print domain.statistics()

#------------------------------------------------------------------------------
# Setup parameters of computational domain
#------------------------------------------------------------------------------
domain.set_name('pwrj_' + project.scenario)  # Name of sww file
Example #28
0
def generate_cairns_domain(gpu=False):
    #-----------------------------------------------------------------------
    # Preparation of topographic data
    # Convert ASC 2 DEM 2 PTS using source data
    # and store result in source data
    #-----------------------------------------------------------------------
    # Create DEM from asc data
    anuga.asc2dem(project.name_stem + '.asc', use_cache=True, verbose=True)

    # Create pts file for onshore DEM
    anuga.dem2pts(project.name_stem + '.dem', use_cache=True, verbose=True)

    #-----------------------------------------------------------------------
    # Create the triangular mesh and domain based on
    # overall clipping polygon with a tagged
    # boundary and interior regions as defined in project.py
    #-----------------------------------------------------------------------
    domain = anuga.create_domain_from_regions(
        project.bounding_polygon,
        boundary_tags={
            'top': [0],
            'ocean_east': [1],
            'bottom': [2],
            'onshore': [3]
        },
        maximum_triangle_area=project.default_res,
        mesh_filename=project.meshname,
        interior_regions=project.interior_regions,
        use_cache=True,
        verbose=True)

    if gpu:
        #domain.__class__ = GPU_domain
        domain = GPU_domain(domain=domain)
    # Print some stats about mesh and domain
    print 'Number of triangles = ', len(domain)
    #print 'The extent is ', domain.get_extent()
    #print domain.statistics()

    #-----------------------------------------------------------------------
    # Setup parameters of computational domain
    #-----------------------------------------------------------------------
    domain.set_name('cairns_' + project.scenario)  # Name of sww file
    domain.set_datadir('.')  # Store sww output here
    domain.set_minimum_storable_height(0.01)  # Store only depth > 1cm
    domain.set_flow_algorithm('tsunami')

    #-----------------------------------------------------------------------
    # Setup initial conditions
    #-----------------------------------------------------------------------
    tide = 0.0
    domain.set_quantity('stage', tide)
    domain.set_quantity('friction', 0.0)

    domain.set_quantity('elevation',
                        filename=project.name_stem + '.pts',
                        use_cache=True,
                        verbose=True,
                        alpha=0.1)

    #-----------------------------------------------------------------------
    # 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,
                                             domain=domain,
                                             verbose=True)

    #-----------------------------------------------------------------------
    # Setup boundary conditions
    #-----------------------------------------------------------------------
    print 'Available boundary tags', domain.get_boundary_tags()

    Bd = anuga.Dirichlet_boundary([tide, 0, 0])  # Mean water level
    Bs = anuga.Transmissive_stage_zero_momentum_boundary(domain)
    # Neutral boundary

    if project.scenario == 'fixed_wave':
        # Huge 50m wave starting after 60 seconds and lasting 1 hour.
        Bw = anuga.Transmissive_n_momentum_zero_t_momentum_set_stage_boundary(
            domain=domain, function=lambda t: [(60 < t < 3660) * 50, 0, 0])

        domain.set_boundary({
            'ocean_east': Bw,
            'bottom': Bs,
            'onshore': Bd,
            'top': Bs
        })

    if project.scenario == 'slide':
        # Boundary conditions for slide scenario
        domain.set_boundary({
            'ocean_east': Bd,
            'bottom': Bd,
            'onshore': Bd,
            'top': Bd
        })

    if gpu:
        if '-gpu' in sys.argv:
            domain.using_gpu = True
            print " --> Enable GPU version"
    return domain
Example #29
0
InitialLandStage=6.

riverWall = { 'centralWall':
                           [ [wallLoc, 0.0, wallHeight],
                             [wallLoc, 100.0, wallHeight]] 
                        }

riverWall_Par = {'centralWall':{'Qfactor':1.0}}

domain = anuga.create_domain_from_regions(boundaryPolygon, 
                         boundary_tags={'left': [0],
                                        'top': [1],
                                        'right': [2],
                                        'bottom': [3]},
                           maximum_triangle_area = 10.0,
                           minimum_triangle_angle = 28.0,
                           interior_regions =[ ], #[ [higherResPolygon, 1.*1.*0.5],
                                                  #  [midResPolygon, 3.0*3.0*0.5]],
                           breaklines=tobreaklines(riverWall)+inlet1_poly+inlet2_poly,
                           regionPtArea=regionPtAreas,
                           use_cache=False,
                           verbose=False)


domain.set_name('run_pump')
domain.set_store_vertices_uniquely(True)


#=======================================
# Setup Initial conditions
#=======================================
Example #30
0
# Create roughness raster from asc data
#anuga.asc2dem('11_man_c.asc', use_cache=False, verbose=True)

# Create roughness raster from asc data
#anuga.dem2pts('11_man_c.dem', use_cache=False,
#              verbose=True)

# In[3]:

bounding_polygon = anuga.read_polygon('extent.csv')
domain = anuga.create_domain_from_regions(bounding_polygon,
                                          boundary_tags={
                                              'top': [0],
                                              'right': [1],
                                              'bottom': [2],
                                              'left': [3]
                                          },
                                          maximum_triangle_area=1,
                                          mesh_filename='11f.msh',
                                          use_cache=False,
                                          verbose=True)

#domain = anuga.Domain(points, vertices, boundary)
domain.set_name('11_fbe_c')
domain.set_datadir('.')

domain.set_quantity('elevation', filename='11_fbe_c.pts')
#domain.set_quantity('friction',filename='11_man_c.pts')
domain.set_quantity('friction', 0.261)
domain.set_quantity('stage', expression='elevation')  # DRY BED