Exemplo n.º 1
0
    Qdata = [3., 3., 3., 3., 3., 3., 4., 5., 6., 6., 6., 6., 6., 7., 8., 9., 10., 10., 10., 10., 10.,\
           11., 12., 13., 14., 15., 15., 15., 15., 16., 17., 18., 19., 20., 21., 23., 25.,\
           30., 35.,40., 45., 50., 55., 60., 65., 70., 70., 70., 70.]+10*[70.]

    dtQdata = 300.

    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)

# Set up bridge
bridge_in = [ [floodplain_width/2. - chan_width/2.+0.01, bridge_ds-0.01],\
              [floodplain_width/2. + chan_width/2.-0.01, bridge_ds-0.01] ]
bridge_out = [ [floodplain_width/2. - chan_width/2.+0.01, bridge_us+0.01],\
               [floodplain_width/2. + chan_width/2.-0.01, bridge_us+0.01] ]

hecras_discharge_function = hecras_internal_boundary_function(
    'hecras_bridge_table_high_deck.csv', allow_sign_reversal=True)

bridge = Internal_boundary_operator(domain,
                                    hecras_discharge_function,
                                    exchange_lines=[bridge_in, bridge_out],
                                    enquiry_gap=0.01,
                                    use_velocity_head=False,
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_boyd_pipe_op')                 # Output name
    domain.set_store(False)
    domain.set_default_order(2)

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

    if parallel:
        domain = distribute(domain)
        #domain.dump_triangulation("boyd_pipe_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_pipe0 = None
    
    inlet0 = Inlet_operator(domain, line0, Q0, verbose = False)
    inlet1 = Inlet_operator(domain, line1, Q1, verbose = False)
    
    # Enquiry point [ 19.    2.5] is contained in two domains in 4 proc case
    
    boyd_pipe0 = Boyd_pipe_operator(domain,
                                  end_points=[[9.0, 2.5],[19.0, 2.5]],
                                  losses=1.5,
                                  diameter=5.0,
                                  apron=5.0,
                                  use_momentum_jet=True,
                                  use_velocity_head=False,
                                  manning=0.013,
                                  verbose=False)
        
    if inlet0 is not None and verbose: inlet0.print_statistics()
    if inlet1 is not None and verbose: inlet1.print_statistics()
    if boyd_pipe0 is not None and verbose: boyd_pipe0.print_statistics()

#    if parallel:
#        factory = Parallel_operator_factory(domain, verbose = True)
#
#        inlet0 = factory.inlet_operator_factory(line0, Q0)
#        inlet1 = factory.inlet_operator_factory(line1, Q1)
#        
#        boyd_box0 = factory.boyd_box_operator_factory(end_points=[[9.0, 2.5],[19.0, 2.5]],
#                                          losses=1.5,
#                                          width=1.5,
#                                          apron=5.0,
#                                          use_momentum_jet=True,
#                                          use_velocity_head=False,
#                                          manning=0.013,
#                                          verbose=False)
#
#    else:
#        inlet0 = Inlet_operator(domain, line0, Q0)
#        inlet1 = Inlet_operator(domain, line1, Q1)
#
#        # 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=1.5,
#                          apron=5.0,
#                          use_momentum_jet=True,
#                          use_velocity_head=False,
#                          manning=0.013,
#                          verbose=False)
    
    #######################################################################

    ##-----------------------------------------------------------------------
    ## 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_pipe0 is not None and verbose : boyd_pipe0.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

    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 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)

    if parallel:
        finalize()

    return control_data
Exemplo n.º 3
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 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, verbose=False, label='Inlet_0')
    inlet1 = Inlet_operator(domain, line1, Q1, verbose=False, label='Inlet_1')

    # 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,
                                  label='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:
        print("++++", myid)
        boyd_box0.print_statistics()

#    if parallel:
#        factory = Parallel_operator_factory(domain, verbose = True)
#
#        inlet0 = factory.inlet_operator_factory(line0, Q0)
#        inlet1 = factory.inlet_operator_factory(line1, Q1)
#
#        boyd_box0 = factory.boyd_box_operator_factory(end_points=[[9.0, 2.5],[19.0, 2.5]],
#                                          losses=1.5,
#                                          width=1.5,
#                                          apron=5.0,
#                                          use_momentum_jet=True,
#                                          use_velocity_head=False,
#                                          manning=0.013,
#                                          verbose=False)
#
#    else:
#        inlet0 = Inlet_operator(domain, line0, Q0)
#        inlet1 = Inlet_operator(domain, line1, Q1)
#
#        # 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=1.5,
#                          apron=5.0,
#                          use_momentum_jet=True,
#                          use_velocity_head=False,
#                          manning=0.013,
#                          verbose=False)

#######################################################################

##-----------------------------------------------------------------------
## 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:
            if myid == boyd_box0.master_proc:
                print('master_proc ', myid)
                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 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))

    return control_data, success
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)
    #rm *.swwdomain.set_name('output_parallel_inlet_operator')                 # 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, verbose=False, default=0.0)
    inlet1 = Inlet_operator(domain, line1, Q1, 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=40.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 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