Example #1
0
    'right': Bt,  # outflow
    'top': Bt,  # outflow
    'left': Br
})

#line0 = [[382300.0,6354280.], [382300.0,6354300.]]
line0 = [[382275.0, 6354270.], [382255.0, 6354290.]]
import math

#velocity = [3.5/math.sqrt(2.0), 3.5/math.sqrt(2.0)]
#fixed_inflow = Inlet_operator(domain, line0, 19.7, verbose = False)

center = (382265.0, 6354280.0)
radius = 10.0
region0 = anuga.Region(domain, center=center, radius=radius)
fixed_inflow = Inlet_operator(domain, region0, 19.7, verbose=True)
#fixed_inflow = anuga.Inflow(domain,
#           center=(382300.0,6354290.0),
#           radius=15.00,
#           rate=19.7)
#domain.forcing_terms.append(fixed_inflow)
#hydrograph = anuga.Inflow(center=(382300.0,6354290.0),radius=30.0,rate=anuga.file_function('test_hydrograph2.tms', quantities=['hydrograph'])
#domain.forcing_terms.append(hydrograph)

#------------------------------------------------------------------------------
# Evolve system through time
#------------------------------------------------------------------------------

for t in domain.evolve(yieldstep=10, finaltime=1000):  #1000
    if myid == 0: print(domain.timestepping_statistics())
Example #2
0
                    use_velocity_head=False,
                    manning=0.013,
                    #logging = True,
                    #label = 'culvert_output',
                    verbose=False)
"""
line = [[3.0, 2.5], [14.0, 2.5],[5.5,4.0]]
Q = -25.0


def dynamic_Q (t,yieldstep):
    t = t+yieldstep
    return Q+t


inlet0 = Inlet_operator(domain, line,Q=0.0)

for t in domain.evolve(yieldstep=0.5, finaltime=20.0):
    Q = dynamic_Q(0,0.5)
    inlet0.set_Q(dynamic_Q(0,0.5))
    domain.print_timestepping_statistics()
    #domain.set_quantity('stage',None,None)
    #print(inlet0.timestepping_statistics())
    #Q = dynamic_Q(0,yieldstep=0.5)

    print(inlet0.get_Q(),"Q")
    print(inlet0.inlet.get_average_speed(),"avsp")
    print(inlet0.inlet.get_depths(),"dp")


                         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
if gate is not None:
    gate.set_culvert_height(0.0)

line = [[0.0, 5.0], [0.0, 10.0]]
Q = 1.0
in0 = Inlet_operator(domain, line, Q)

##-----------------------------------------------------------------------
## Setup boundary conditions
##-----------------------------------------------------------------------

## Inflow based on Flow Depth and Approaching Momentum
Br = anuga.Reflective_boundary(domain)  # Solid reflective wall

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

##-----------------------------------------------------------------------
## Evolve system through time
##-----------------------------------------------------------------------
barrier()
outflow_w = 1.0
outflow_q = 1.0


#Bd_out = anuga.Dirichlet_boundary([outflow_w, outflow_q, 0.]) # Constant outflow boundary values
def waveform(t):
    return outflow_w


Bd_out = anuga.Transmissive_n_momentum_zero_t_momentum_set_stage_boundary(
    domain, waveform)

# Inflow boundary -- use discharge inflow, and reflective wall (so we can control the discharge)
line = [[0., 0.], [0., W]]
Qin = 1.0 * W
Inlet_operator(domain, line, Qin)

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

#------------------------------------------------------------------------------
# Produce a documentation of parameters
#------------------------------------------------------------------------------
if myid == 0:
    parameter_file = open('parameters.tex', 'w')
    parameter_file.write('\\begin{verbatim}\n')
    from pprint import pprint
    pprint(domain.get_algorithm_parameters(), parameter_file, indent=4)
    parameter_file.write('\\end{verbatim}\n')
    parameter_file.close()
Example #5
0
def run_simulation(parallel=False,
                   control_data=None,
                   test_points=None,
                   verbose=False):
    success = True

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

    points, vertices, boundary = rectangular_cross(int(old_div(length, dx)),
                                                   int(old_div(width, dy)),
                                                   len1=length,
                                                   len2=width)

    domain = anuga.Domain(points, vertices, boundary)
    #domain.set_name('output_parallel_frac_op')                 # Output name
    domain.set_store(False)
    domain.set_default_order(2)

    ##-----------------------------------------------------------------------
    ## Distribute domain
    ##-----------------------------------------------------------------------

    if parallel:
        domain = distribute(domain)
        #domain.dump_triangulation("frac_op_domain.png")

##-----------------------------------------------------------------------
## Setup boundary conditions
##-----------------------------------------------------------------------

    domain.set_quantity('elevation', topography)
    domain.set_quantity('friction', 0.01)  # Constant friction
    domain.set_quantity('stage',
                        expression='elevation')  # Dry initial condition

    Bi = anuga.Dirichlet_boundary([5.0, 0.0, 0.0])
    Br = anuga.Reflective_boundary(domain)  # Solid reflective wall
    domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br})

    ##-----------------------------------------------------------------------
    ## Determine triangle index coinciding with test points
    ##-----------------------------------------------------------------------

    assert (test_points is not None)
    assert (len(test_points) == samples)

    tri_ids = []

    for point in test_points:
        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)

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

    if not parallel: control_data = []

    ################ Define Fractional Operators ##########################

    inlet0 = None
    inlet1 = None
    boyd_box0 = None

    inlet0 = Inlet_operator(domain,
                            line0,
                            Q0,
                            logging=False,
                            description='inlet0',
                            verbose=False)
    inlet1 = Inlet_operator(domain,
                            line1,
                            Q1,
                            logging=False,
                            description='inlet1',
                            verbose=False)

    # Enquiry point [ 19.    2.5] is contained in two domains in 4 proc case

    boyd_box0 = Boyd_box_operator(
        domain,
        end_points=[[9.0, 2.5], [19.0, 2.5]],
        losses=1.5,
        width=5.0,
        #apron=5.0,
        use_momentum_jet=True,
        use_velocity_head=False,
        manning=0.013,
        logging=False,
        description='boyd_box_0',
        verbose=False)

    if inlet0 is not None and verbose: inlet0.print_statistics()
    if inlet1 is not None and verbose: inlet1.print_statistics()
    if boyd_box0 is not None and verbose: boyd_box0.print_statistics()

    ##-----------------------------------------------------------------------
    ## Evolve system through time
    ##-----------------------------------------------------------------------

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

        #print domain.volumetric_balance_statistics()

        stage = domain.get_quantity('stage')

        if boyd_box0 is not None and verbose:
            boyd_box0.print_timestepping_statistics()

        #for i in range(samples):
        #    if tri_ids[i] >= 0:
        #        if verbose: print 'P%d tri %d, value = %s' %(myid, i, stage.centroid_values[tri_ids[i]])

        sys.stdout.flush()

        pass

    domain.sww_merge(delete_old=True)

    success = True

    ##-----------------------------------------------------------------------
    ## Assign/Test Control data
    ##-----------------------------------------------------------------------

    if not parallel:
        stage = domain.get_quantity('stage')

        for i in range(samples):
            assert (tri_ids[i] >= 0)
            control_data.append(stage.centroid_values[tri_ids[i]])

        if inlet0 is not None:
            control_data.append(inlet0.inlet.get_average_stage())
            control_data.append(inlet0.inlet.get_average_xmom())
            control_data.append(inlet0.inlet.get_average_ymom())
            control_data.append(inlet0.inlet.get_total_water_volume())
            control_data.append(inlet0.inlet.get_average_depth())

        if verbose: print('P%d control_data = %s' % (myid, control_data))
    else:
        stage = domain.get_quantity('stage')

        for i in range(samples):
            if tri_ids[i] >= 0:
                local_success = num.allclose(control_data[i],
                                             stage.centroid_values[tri_ids[i]])
                success = success and local_success
                if verbose:
                    print(
                        'P%d tri %d, control = %s, actual = %s, Success = %s' %
                        (myid, i, control_data[i],
                         stage.centroid_values[tri_ids[i]], local_success))
                if not local_success:
                    print(
                        'Ouput P%d tri %d, control = %s, actual = %s, Success = %s'
                        % (myid, i, control_data[i],
                           stage.centroid_values[tri_ids[i]], local_success))

        #assert success

        if inlet0 is not None:
            inlet_master_proc = inlet0.inlet.get_master_proc()
            average_stage = inlet0.inlet.get_global_average_stage()
            average_xmom = inlet0.inlet.get_global_average_xmom()
            average_ymom = inlet0.inlet.get_global_average_ymom()
            average_volume = inlet0.inlet.get_global_total_water_volume()
            average_depth = inlet0.inlet.get_global_average_depth()

            if myid == inlet_master_proc:
                if verbose:
                    print('P%d average stage, control = %s, actual = %s' %
                          (myid, control_data[samples], average_stage))

                    print('P%d average xmom, control = %s, actual = %s' %
                          (myid, control_data[samples + 1], average_xmom))

                    print('P%d average ymom, control = %s, actual = %s' %
                          (myid, control_data[samples + 2], average_ymom))

                    print('P%d average volume, control = %s, actual = %s' %
                          (myid, control_data[samples + 3], average_volume))

                    print('P%d average depth, control = %s, actual = %s' %
                          (myid, control_data[samples + 4], average_depth))

        #assert(success)

    return control_data, success
Example #6
0
Br = anuga.Reflective_boundary(domain)
Bd = anuga.Dirichlet_boundary([0, 0, 0])

domain.set_boundary({
    'interior': Br,
    'exterior': Bd,
    'west': Bd,
    'south': Bd,
    'north': Bd,
    'east': Bd
})

# ------------------------------------------------------------------------------
# Setup inject water
# ------------------------------------------------------------------------------

input1_anuga_region = Region(domain,
                             radius=1.0,
                             center=(305694.91, 6188013.94))
input1_anuga_inlet_op = Inlet_operator(
    domain, input1_anuga_region,
    Q=0.102)  # i made flow exactly the same as in DRAINS example

dt = 0.25  # yield step
ft = 400  # final timestep

for t in domain.evolve(yieldstep=dt, finaltime=ft):
    print('\n')
    domain.print_timestepping_statistics()
def run_simulation(parallel = False, control_data = None, test_points = None, verbose = False):
    success = True

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

    points, vertices, boundary = rectangular_cross(int(length/dx),
                                                   int(width/dy),
                                                   len1=length, 
                                                   len2=width)

    domain = anuga.Domain(points, vertices, boundary)   
    #domain.set_name('output_parallel_frac_op')                 # Output name
    domain.set_store(False)
    domain.set_default_order(2)

##-----------------------------------------------------------------------
## Distribute domain
##-----------------------------------------------------------------------

    if parallel:
        domain = distribute(domain)
        #domain.dump_triangulation("frac_op_domain.png")
    

##-----------------------------------------------------------------------
## Setup boundary conditions
##-----------------------------------------------------------------------
    
    domain.set_quantity('elevation', topography) 
    domain.set_quantity('friction', 0.01)         # Constant friction 
    domain.set_quantity('stage',
                        expression='elevation')   # Dry initial condition

    
    Bi = anuga.Dirichlet_boundary([5.0, 0.0, 0.0])
    Br = anuga.Reflective_boundary(domain)              # Solid reflective wall
    domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br})


##-----------------------------------------------------------------------
## Determine triangle index coinciding with test points
##-----------------------------------------------------------------------

    assert(test_points is not None)
    assert(len(test_points) == samples)

    tri_ids = []

    for point in test_points:
        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)

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

    if not parallel: control_data = []

    ################ Define Fractional Operators ##########################

    inlet0 = None
    inlet1 = None
    boyd_box0 = None
    
    inlet0 = Inlet_operator(domain, line0, Q0, logging=False, description='inlet0', verbose = False)
    inlet1 = Inlet_operator(domain, line1, Q1, logging=False, description='inlet1', verbose = False)
    
    # Enquiry point [ 19.    2.5] is contained in two domains in 4 proc case
    
    boyd_box0 = Boyd_box_operator(domain,
                                  end_points=[[9.0, 2.5],[19.0, 2.5]],
                                  losses=1.5,
                                  width=5.0,
                                  #apron=5.0,
                                  use_momentum_jet=True,
                                  use_velocity_head=False,
                                  manning=0.013,
                                  logging=False,
                                  description='boyd_box_0',
                                  verbose=False)
        
    if inlet0 is not None and verbose: inlet0.print_statistics()
    if inlet1 is not None and verbose: inlet1.print_statistics()
    if boyd_box0 is not None and verbose: boyd_box0.print_statistics()


    ##-----------------------------------------------------------------------
    ## Evolve system through time
    ##-----------------------------------------------------------------------

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

        #print domain.volumetric_balance_statistics()
    
        stage = domain.get_quantity('stage')


        if boyd_box0 is not None and verbose : boyd_box0.print_timestepping_statistics()
 
        #for i in range(samples):
        #    if tri_ids[i] >= 0:                
        #        if verbose: print 'P%d tri %d, value = %s' %(myid, i, stage.centroid_values[tri_ids[i]])
                    
        sys.stdout.flush()
 
        pass
    
    domain.sww_merge(delete_old=True)

    success = True

##-----------------------------------------------------------------------
## Assign/Test Control data
##-----------------------------------------------------------------------

    if not parallel:
        stage = domain.get_quantity('stage')

        for i in range(samples):
            assert(tri_ids[i] >= 0)
            control_data.append(stage.centroid_values[tri_ids[i]])
        
        if inlet0 is not None:
            control_data.append(inlet0.inlet.get_average_stage())
            control_data.append(inlet0.inlet.get_average_xmom())
            control_data.append(inlet0.inlet.get_average_ymom())
            control_data.append(inlet0.inlet.get_total_water_volume())
            control_data.append(inlet0.inlet.get_average_depth())

        if verbose: print 'P%d control_data = %s' %(myid, control_data)
    else:
        stage = domain.get_quantity('stage')
        
        for i in range(samples):
            if tri_ids[i] >= 0:
                local_success = num.allclose(control_data[i], stage.centroid_values[tri_ids[i]])
                success = success and local_success
                if verbose: 
                    print 'P%d tri %d, control = %s, actual = %s, Success = %s' %(myid, i, control_data[i], stage.centroid_values[tri_ids[i]], local_success) 
                if not local_success:
                    print 'Ouput P%d tri %d, control = %s, actual = %s, Success = %s' %(myid, i, control_data[i], stage.centroid_values[tri_ids[i]], local_success) 


        #assert success        
                
        if inlet0 is not None:
            inlet_master_proc = inlet0.inlet.get_master_proc()
            average_stage = inlet0.inlet.get_global_average_stage()
            average_xmom = inlet0.inlet.get_global_average_xmom()
            average_ymom = inlet0.inlet.get_global_average_ymom()
            average_volume = inlet0.inlet.get_global_total_water_volume()
            average_depth = inlet0.inlet.get_global_average_depth()

            if myid == inlet_master_proc:
                if verbose: 
                    print 'P%d average stage, control = %s, actual = %s' %(myid, control_data[samples], average_stage)

                    print 'P%d average xmom, control = %s, actual = %s' %(myid, control_data[samples+1], average_xmom)

                    print 'P%d average ymom, control = %s, actual = %s' %(myid, control_data[samples+2], average_ymom)

                    print 'P%d average volume, control = %s, actual = %s' %(myid, control_data[samples+3], average_volume)

                    print 'P%d average depth, control = %s, actual = %s' %(myid, control_data[samples+4], average_depth)


        #assert(success)

    return control_data, success
Bi = Dirichlet_boundary([-2.75, 0, 0])  # Inflow
Br = Reflective_boundary(domain)  # Solid reflective wall
Bo = Dirichlet_boundary([-5, 0, 0])  # Outflow

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

# ------------------------------------------------------------------------------
# Setup inject water
# ------------------------------------------------------------------------------

region_inlet = Region(domain, radius=1.0, center=(7., 2.))
region_outlet = Region(domain, radius=1.0, center=(17., 2.))

region_input = Region(domain, radius=1.0, center=(2., 2.))

op_input = Inlet_operator(domain, region_input, Q=0.25)

op_inlet = Inlet_operator(domain, region_inlet, Q=0.0, zero_velocity=True)
op_outlet = Inlet_operator(domain, region_outlet, Q=0.0,
                           zero_velocity=False)  #

x = domain.centroid_coordinates[:, 0]
indices = num.where(x < 10)
anuga.Set_stage(domain, stage=-2.75, indices=indices)()

from pyswmm import Simulation, Nodes, Links

sim = Simulation('./pipe_test.inp')
sim.start()
node_names = ['Inlet', 'Outlet']
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.")
Example #10
0
Bi = Dirichlet_boundary([-2.75, 0, 0])  # Inflow
Br = Reflective_boundary(domain)  # Solid reflective wall
Bo = Dirichlet_boundary([-5, 0, 0])  # Outflow

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

# ------------------------------------------------------------------------------
# Setup inject water
# ------------------------------------------------------------------------------

region_inlet = Region(domain, radius=1.0, center=(7., 2.))
region_outlet = Region(domain, radius=1.0, center=(17., 2.))

region_input = Region(domain, radius=1.0, center=(2., 2.))

op_input = Inlet_operator(domain, region_input, Q=0.25)

op_inlet = Inlet_operator(domain, region_inlet, Q=0.0, zero_velocity=True)
op_outlet = Inlet_operator(domain, region_outlet, Q=0.0,
                           zero_velocity=False)  #

x = domain.centroid_coordinates[:, 0]
indices = num.where(x < 10)
anuga.Set_stage(domain, stage=-2.75, indices=indices)()

from pyswmm import Simulation, Nodes, Links

sim = Simulation('./pipe_test.inp')
sim.start()
node_names = ['Inlet', 'Outlet']
              [floodplain_width/2. + chan_width/2.-0.01, flow_in_yval] \
              ]
    
    Qdata = [1., 1., 5., 9., 13., 17., 21.]+18*[21.]

    dtQdata=3600.
    def Qin(t):
        t_hour=t/dtQdata # Used for time index for Qdata
        indL=numpy.floor(t_hour).astype(int)
        indU=numpy.ceil(t_hour).astype(int)
        w1=(t_hour-1.0*indL)
        w2=(1.0*indU-t_hour)
        Qout=Qdata[indL]*w2+Qdata[indU]*w1
        return Qout
    
    Inlet_operator(domain, line1, Qin)
   
    if(verbose): 
        print('Discharge in = ', Qin) #,'Velocity at inlet should be ', Qin/(chan_width*chan_initial_depth), \
            #'for rectangular channels, and approximately that for trapezoidal ones'

    # Add 'pilot discharge' for left/right areas.
    # This is needed for comparison with hecras [since hecras channels cannot dry]
    Inlet_operator(domain, [[0.+1.0e-03, flow_in_yval], [10.-1.0e-03, flow_in_yval] ], 0.1)
    Inlet_operator(domain, [[30.+1.0e-03,flow_in_yval], [40.-1.0e-03, flow_in_yval] ], 0.1)


#------------------------------------------------------------------------------
#
# Setup boundary conditions
#
Bo = Dirichlet_boundary([-5, 0, 0])  # Outflow
domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br})

# ------------------------------------------------------------------------------
# Setup inject water
# ------------------------------------------------------------------------------

inlet1_anuga_region = Region(domain, radius=1.0, center=(7., 1.))
inlet2_anuga_region = Region(domain, radius=1.0, center=(7., 5.))
outlet_anuga_region = Region(domain, radius=1.0, center=(17., 3.))

input1_anuga_region = Region(domain, radius=1.0, center=(2., 1.))
# region_input2 = Region(domain, radius=1.0, center=(2., 5.))

inlet1_anuga_inlet_op = Inlet_operator(domain,
                                       inlet1_anuga_region,
                                       Q=0.0,
                                       zero_velocity=True)
inlet2_anuga_inlet_op = Inlet_operator(domain,
                                       inlet2_anuga_region,
                                       Q=0.0,
                                       zero_velocity=True)
outlet_anuga_inlet_op = Inlet_operator(domain,
                                       outlet_anuga_region,
                                       Q=0.0,
                                       zero_velocity=False)

input1_anuga_inlet_op = Inlet_operator(domain, input1_anuga_region,
                                       Q=1)  #only inlet1 has water inflow.
# op_input2 = Inlet_operator(domain, region_input2, Q=0.1)

x = domain.centroid_coordinates[:, 0]
Example #13
0
################ Define Fractional Operators ##########################
line0 = [[10.0, 10.0], [30.0, 10.0]]
#line0 = [[29.0, 10.0], [30.0, 10.0]]
poly1 = [[0.0, 10.0], [0.0, 15.0], [5.0, 15.0], [5.0, 10.0]]
Q0 = anuga.file_function('data/test_hydrograph.tms', quantities=['hydrograph'])
Q1 = 5.0

samples = 50

inlet0 = None
inlet1 = None
boyd_box0 = None

inlet0 = Inlet_operator(domain,
                        line0,
                        Q0,
                        logging=True,
                        description='inlet0',
                        verbose=False)
inlet1 = Inlet_operator(domain,
                        poly1,
                        Q1,
                        logging=True,
                        description='inlet1',
                        verbose=False)

# Enquiry point [ 19.    2.5] is contained in two domains in 4 proc case

boyd_box0 = Boyd_box_operator(domain,
                              end_points=[[9.0, 2.5], [19.0, 2.5]],
                              losses=1.5,
                              width=5.0,
Example #14
0
Br = Reflective_boundary(domain)  # Solid reflective wall
Bo = Dirichlet_boundary([-5, 0, 0])  # Outflow
domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br})

# ------------------------------------------------------------------------------
# Setup inject water
# ------------------------------------------------------------------------------

inlet1_anuga_region = Region(domain, radius=1.0, center=(7., 1.))
inlet2_anuga_region = Region(domain, radius=1.0, center=(7., 5.))
outlet_anuga_region = Region(domain, radius=1.0, center=(17., 3.))

input1_anuga_region = Region(domain, radius=1.0, center=(2., 1.))

inlet1_anuga_inlet_op = Inlet_operator(domain,
                                       inlet1_anuga_region,
                                       Q=0.0,
                                       zero_velocity=True)
inlet2_anuga_inlet_op = Inlet_operator(domain,
                                       inlet2_anuga_region,
                                       Q=0.0,
                                       zero_velocity=True)
outlet_anuga_inlet_op = Inlet_operator(domain,
                                       outlet_anuga_region,
                                       Q=0.0,
                                       zero_velocity=False)

input1_anuga_inlet_op = Inlet_operator(domain, input1_anuga_region,
                                       Q=1)  #only inlet1 has water inflow.

x = domain.centroid_coordinates[:, 0]
y = domain.centroid_coordinates[:, 1]
Example #15
0
Br = anuga.Reflective_boundary(domain)
Bd = anuga.Dirichlet_boundary([0, 0, 0])
#Bt = anuga.Flather_external_stage_zero_velocity_boundary()

domain.set_boundary({'inflow': Br, 'bottom': Br, 'outflow': Bd, 'top': Br})
#domain.set_boundary({'exterior' : Bd})

# ------------------------------------------------------------------------------
# Setup inject water
# ------------------------------------------------------------------------------
input_rate = 0.05  #  0.102 # i made inflow exactly the same as in DRAINS example
input1_anuga_region = Region(domain,
                             radius=1.0,
                             center=(305694.91, 6188013.94))
input1_anuga_inlet_op = Inlet_operator(domain,
                                       input1_anuga_region,
                                       Q=input_rate)

# ------------------------------------------------------------------------------
# Setup pipedream inlets
# ------------------------------------------------------------------------------
radius = 0.25

inlet1_anuga_region = Region(domain,
                             radius=radius,
                             center=(305698.51, 6188004.63))
inlet2_anuga_region = Region(domain,
                             radius=radius,
                             center=(305703.39, 6187999.00))
inlet3_anuga_region = Region(domain,
                             radius=radius,
Example #16
0
print('Available boundary tags', domain.get_boundary_tags())

Br = anuga.Reflective_boundary(domain)
Bd = anuga.Dirichlet_boundary([0, 0, 0])

domain.set_boundary({'west': Bd, 'south': Br, 'north': Bd, 'east': Bd})

inlet1_anuga_region = Region(domain,
                             radius=0.5,
                             center=(296660.390, 6180017.186))
outlet_anuga_region = Region(domain,
                             radius=0.5,
                             center=(296649.976, 6180038.872))

inlet1_anuga_inlet_op = Inlet_operator(domain,
                                       inlet1_anuga_region,
                                       Q=0.0,
                                       zero_velocity=True)
outlet_anuga_inlet_op = Inlet_operator(domain,
                                       outlet_anuga_region,
                                       Q=0.0,
                                       zero_velocity=False)

line = [[296669.258, 6179974.191], [296677.321, 6179976.449]]
Inlet_operator(domain, line, 1.0)

#------------------------------------------------------------------------------
# PIPEDREAM
#------------------------------------------------------------------------------

from pipedream_solver.hydraulics import SuperLink
import matplotlib.pyplot as plt
Example #17
0
# boundary, and allow water to 'pool' at the bottom of the domain.
#
#Bt = anuga.Transmissive_boundary(domain)
#Bts = anuga.Transmissive_momentum_set_stage_boundary(domain, dana-160.0)
#Bts = anuga.Transmissive_n_momentum_zero_t_momentum_set_stage_boundary(domain, lambda t: dana-40.0)
##BdIN = anuga.Dirichlet_boundary([dana, fluxin, 0.0])
#BdOUT = anuga.Dirichlet_boundary([dana-40., dana*uana, 0.0])

print dana - 40.

Br = anuga.Reflective_boundary(domain)  # Solid reflective wall
domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br})

line1 = [[0.0, 0.], [0.0, 100.]]
Qin = 0.1
inlet = Inlet_operator(domain, line1, Q=Qin)

#if inlet: print inlet.statistics()

stage = domain.quantities['stage']
elev = domain.quantities['elevation']

print(stage - elev).get_integral()

#------------------------------------------------------------------------------
# Produce a documentation of parameters
#------------------------------------------------------------------------------
if myid == 0:
    parameter_file = open('parameters.tex', 'w')
    parameter_file.write('\\begin{verbatim}\n')
    from pprint import pprint
Example #18
0
    ################ Define Fractional Operators ##########################
line0 = [[10.0, 10.0], [30.0, 10.0]]
#line0 = [[29.0, 10.0], [30.0, 10.0]]
poly1 = [[0.0, 10.0], [0.0, 15.0], [5.0, 15.0], [5.0, 10.0]]
Q0 = anuga.file_function('../data/test_hydrograph.tms', quantities=['hydrograph'])
Q1 = 5.0

samples = 50


inlet0 = None
inlet1 = None
boyd_box0 = None

inlet0 = Inlet_operator(domain, line0, Q0, logging=True, description='inlet0', verbose = False)
inlet1 = Inlet_operator(domain, poly1, Q1, logging=True, description='inlet1', verbose = False)

# Enquiry point [ 19.    2.5] is contained in two domains in 4 proc case

boyd_box0 = Boyd_box_operator(domain,
                              end_points=[[9.0, 2.5],[19.0, 2.5]],
                              losses=1.5,
                              width=5.0,
                              apron=5.0,
                              use_momentum_jet=True,
                              use_velocity_head=False,
                              manning=0.013,
                              logging=True,
                              description='boyd_box_0',
                              verbose=False)