Ejemplo n.º 1
0
def generate_channel1_domain(gpu=True):
    #--------------------------------------------------------------------------
    # Setup computational domain
    #--------------------------------------------------------------------------

    #points, vertices, boundary = anuga.rectangular_cross(10, 1,
    #                                               len1=10.0, len2=5.0) # Mesh
    points, vertices, boundary = anuga.rectangular_cross(1,
                                                         4,
                                                         len1=0.1,
                                                         len2=0.1)  # Mesh

    if gpu:
        domain = GPU_domain(points, vertices, boundary)  # Create domain
        for i in range(len(sys.argv)):
            if sys.argv[i] == '-gpu':
                domain.using_gpu = True
                print " --> Enable GPU version"
            elif sys.argv[i] == '-fs':
                finaltime = float(sys.argv[i + 1])
                print " --> Finaltime is reset as %f" % finaltime
            elif sys.argv[i] == '-test':
                domain.cotesting = True
                print " --> Enable Cotesting"
            elif sys.argv[i] == '-ustore':
                domain.store = True
                print " --> Disable storing"
    else:
        domain = anuga.Domain(points, vertices, boundary)  # Create domain
    domain.set_name('channel1')  # Output name

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

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

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

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

    return domain
Ejemplo n.º 2
0
def generate_channel1_domain(gpu=True):
    # --------------------------------------------------------------------------
    # Setup computational domain
    # --------------------------------------------------------------------------

    # points, vertices, boundary = anuga.rectangular_cross(10, 1,
    #                                               len1=10.0, len2=5.0) # Mesh
    points, vertices, boundary = anuga.rectangular_cross(1, 4, len1=0.1, len2=0.1)  # Mesh

    if gpu:
        domain = GPU_domain(points, vertices, boundary)  # Create domain
        for i in range(len(sys.argv)):
            if sys.argv[i] == "-gpu":
                domain.using_gpu = True
                print " --> Enable GPU version"
            elif sys.argv[i] == "-fs":
                finaltime = float(sys.argv[i + 1])
                print " --> Finaltime is reset as %f" % finaltime
            elif sys.argv[i] == "-test":
                domain.cotesting = True
                print " --> Enable Cotesting"
            elif sys.argv[i] == "-ustore":
                domain.store = True
                print " --> Disable storing"
    else:
        domain = anuga.Domain(points, vertices, boundary)  # Create domain
    domain.set_name("channel1")  # Output name

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

    domain.set_quantity("elevation", topography)  # Use function for elevation
    domain.set_quantity("friction", 0.01)  # Constant friction
    domain.set_quantity("stage", expression="elevation")  # Dry bed

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

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

    return domain
    def test_estimate_time_mem(self):
        points, vertices, boundary = anuga.rectangular_cross(10, 5,
                                               len1=10.0, len2=5.0) # Mesh

        domain = anuga.Domain(points, vertices, boundary)  # Create domain
        tri_num =  len(domain)
        yieldstep = 360
        finaltime = 3600
        
        time, memory = estimate_time_mem(domain, yieldstep, finaltime, 
                          use_test_constants=True, log_results=False)

        
        actual = system_constants[TEST_CON]['tri_a_T'] * tri_num ** 2 + \
             system_constants[TEST_CON]['tri_b_T'] * tri_num + \
              system_constants[TEST_CON]['tim_a_T'] * finaltime + \
              system_constants[TEST_CON]['fil_a_T'] * finaltime/yieldstep + \
               system_constants[TEST_CON]['cons_T']
        self.assertEqual(time, actual)
Ejemplo n.º 4
0
def generate_domain():
    #--------------------------------------------------------------------------
    # Setup computational domain
    #--------------------------------------------------------------------------
    length = 10.
    width = 5.
    dx = dy = 1.  # Resolution: Length of subdivisions on both axes

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

    domain = anuga.Domain(points, vertices, boundary)
    domain.set_name('channel2')  # Output name

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

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

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

    domain.set_boundary({'left': Bi, 'right': Br, 'top': Br, 'bottom': Br})
    import sys
    if len(sys.argv) > 1 and "gpu" in sys.argv:
        domain.using_gpu = True
    else:
        domain.using_gpu = False
    print sys.argv, "gpu" in sys.argv
    return domain
Ejemplo n.º 5
0
def generate_domain():
    #--------------------------------------------------------------------------
    # Setup computational domain
    #--------------------------------------------------------------------------
    length = 10.
    width = 5.
    dx = dy = 1.           # Resolution: Length of subdivisions on both axes
    
    points, vertices, boundary = anuga.rectangular_cross(int(length/dx),
                                    int(width/dy), len1=length, len2=width)
                                            
    domain = anuga.Domain(points, vertices, boundary)   
    domain.set_name('channel2')                 # Output name
    
    #--------------------------------------------------------------------------
    # Setup initial conditions
    #--------------------------------------------------------------------------
    def topography(x,y):
        return -x/10                             # linear bed slope
    
    domain.set_quantity('elevation', topography) # Use function for elevation
    domain.set_quantity('friction', 0.01)        # Constant friction 
    domain.set_quantity('stage',
                        expression='elevation')  # Dry initial condition
    
    #--------------------------------------------------------------------------
    # Setup boundary conditions
    #--------------------------------------------------------------------------
    Bi = anuga.Dirichlet_boundary([0.4, 0, 0])   # Inflow
    Br = anuga.Reflective_boundary(domain)       # Solid reflective wall
    Bo = anuga.Dirichlet_boundary([-5, 0, 0])    # Outflow
    
    domain.set_boundary({'left': Bi, 'right': Br, 'top': Br, 'bottom': Br})
    import sys
    if len(sys.argv) > 1 and "gpu" in sys.argv:
        domain.using_gpu = True
    else:
        domain.using_gpu = False
    print sys.argv, "gpu" in sys.argv
    return domain
    def test_estimate_time_mem(self):
        points, vertices, boundary = anuga.rectangular_cross(10,
                                                             5,
                                                             len1=10.0,
                                                             len2=5.0)  # Mesh

        domain = anuga.Domain(points, vertices, boundary)  # Create domain
        tri_num = len(domain)
        yieldstep = 360
        finaltime = 3600

        time, memory = estimate_time_mem(domain,
                                         yieldstep,
                                         finaltime,
                                         use_test_constants=True,
                                         log_results=False)

        actual = system_constants[TEST_CON]['tri_a_T'] * tri_num ** 2 + \
            system_constants[TEST_CON]['tri_b_T'] * tri_num + \
            system_constants[TEST_CON]['tim_a_T'] * finaltime + \
            (system_constants[TEST_CON]['fil_a_T'] * finaltime / yieldstep) + \
            system_constants[TEST_CON]['cons_T']
        self.assertEqual(time, actual)
Ejemplo n.º 7
0
def generate_channel1_domain(gpu=True):
    #--------------------------------------------------------------------------
    # Setup computational domain
    #--------------------------------------------------------------------------

    #points, vertices, boundary = anuga.rectangular_cross(10, 1,
    #                                               len1=10.0, len2=5.0) # Mesh
    points, vertices, boundary = anuga.rectangular_cross(90, 90,
                                                   len1=0.1, len2=0.1) # Mesh
    
    if gpu:
        domain = HMPP_domain(points, vertices, boundary)  # Create domain
    else:
        domain = anuga.Domain(points, vertices, boundary)  # Create domain
    domain.set_name('channel1')                  # Output name
    
    #--------------------------------------------------------------------------
    # Setup initial conditions
    #--------------------------------------------------------------------------
    def topography(x, y):
        return -x/10                             # linear bed slope
    
    domain.set_quantity('elevation', topography) # Use function for elevation
    domain.set_quantity('friction', 0.01)        # Constant friction 
    domain.set_quantity('stage',                 # Dry bed
                        expression='elevation')  
    
    #--------------------------------------------------------------------------
    # Setup boundary conditions
    #--------------------------------------------------------------------------
    Bi = anuga.Dirichlet_boundary([0.4, 0, 0])         # Inflow
    Br = anuga.Reflective_boundary(domain)             # Solid reflective wall
    
    domain.set_boundary({'left': Bi, 'right': Br, 'top': Br, 'bottom': Br})


    return domain
Ejemplo n.º 8
0
Water driven up a linear slope and time varying boundary,
similar to a beach environment
"""

#------------------------------------------------------------------------------
# Import necessary modules
#------------------------------------------------------------------------------
import anuga

from math import sin, pi, exp

#------------------------------------------------------------------------------
# Setup computational domain
#------------------------------------------------------------------------------
points, vertices, boundary = anuga.rectangular_cross(10, 10) # Basic mesh

domain = anuga.Domain(points, vertices, boundary)   # Create domain
domain.set_name('runup')                            # Output to file runup.sww
domain.set_datadir('.')                             # Use current folder

#------------------------------------------------------------------------------
# Setup initial conditions
#------------------------------------------------------------------------------
def topography(x, y):
    return -x/2                              # linear bed slope
    #return x*(-(2.0-x)*.5)                  # curved bed slope

domain.set_quantity('elevation', topography) # Use function for elevation
domain.set_quantity('friction', 0.1)         # Constant friction 
domain.set_quantity('stage', -0.4)           # Constant negative initial stage
Ejemplo n.º 9
0
def generate_channel3_domain(gpu=True):
    #-----------------------------------------------------------------------
    # Setup computational domain
    #-----------------------------------------------------------------------
    length = 40.
    width = 5.
    dx = dy = .1           # Resolution: Length of subdivisions on both axes
    
    points, vertices, boundary = anuga.rectangular_cross(int(length/dx),
                                        int(width/dy), len1=length, len2=width)
    if gpu:
        domain = GPU_domain(points, vertices, boundary )
        if '-gpu' in sys.argv:
            domain.using_gpu = True
            print " --> Enable GPU version"
        for i in range(len(sys.argv)):
            if sys.argv[i] == '-fs':
                global finaltime
                finaltime = float(sys.argv[i+1])
                print " --> Finaltime is reset as %f" % finaltime

    else:
        domain = anuga.Domain(points, vertices, boundary)
    domain.set_name('channel3')                  # Output name
    #print domain.statistics()
    
    #-----------------------------------------------------------------------
    # Setup initial conditions
    #-----------------------------------------------------------------------
    def topography(x,y):
        """Complex topography defined by a function of vectors x and y."""
    
        z = -x/10
    
        N = len(x)
        for i in range(N):
            # Step
            if 10 < x[i] < 12:
                z[i] += 0.4 - 0.05*y[i]
    
            # Constriction
            if 27 < x[i] < 29 and y[i] > 3:
                z[i] += 2
    
            # Pole
            if (x[i] - 34)**2 + (y[i] - 2)**2 < 0.4**2:
                z[i] += 2
    
        return z
    
    domain.set_quantity('elevation', topography)    # elevation is a function
    domain.set_quantity('friction', 0.01)                  # Constant friction
    domain.set_quantity('stage', expression='elevation') # Dry initial condition
    
    #-----------------------------------------------------------------------
    # Setup boundary conditions
    #-----------------------------------------------------------------------
    Bi = anuga.Dirichlet_boundary([0.4, 0, 0])          # Inflow
    Br = anuga.Reflective_boundary(domain)              # Solid reflective wall
    Bo = anuga.Dirichlet_boundary([-5, 0, 0])           # Outflow
    
    domain.set_boundary({'left': Bi, 'right': Bo, 'top': Br, 'bottom': Br})
    return domain
def elevation(x,y):
    return h0*x/L


def stage(x,y):
    w,z,u = analytical_sol(x/L,0.0)
    return h0*w


#===============================================================================
# Create sequential domain
#===============================================================================
if myid == 0:
    # structured mesh
    points, vertices, boundary = anuga.rectangular_cross(int(0.8*L/dx), int(W/dy), 0.8*L, W, (-0.5*L, -0.5*W))
    domain = Domain(points, vertices, boundary) 
    domain.set_name(output_file)                
    domain.set_datadir(output_dir)

    domain.set_flow_algorithm(alg)

    #------------------------------------------------------------------------------
    # Setup initial conditions
    #------------------------------------------------------------------------------
    domain.set_quantity('friction', 0.0)
    domain.set_quantity('stage', stage)
    domain.set_quantity('elevation', elevation)
    
else:
    domain = None
Ejemplo n.º 11
0
    def test_runup_sinusoid(self):
        """ Run a version of the validation test runup_sinusoid
        to ensure limiting solution has small velocity
        """

        points, vertices, boundary = anuga.rectangular_cross(20,20, len1=1., len2=1.)


        domain=Domain(points,vertices,boundary)    # Create Domain
        domain.set_flow_algorithm('DE0')
        
        domain.set_name('runup_sinusoid_v2')                         # Output to file runup.sww
        domain.set_datadir('.')                          # Use current folder
        domain.set_quantities_to_be_stored({'stage': 2, 'xmomentum': 2, 'ymomentum': 2, 'elevation': 1})
        #domain.set_store_vertices_uniquely(True)
        #------------------
        # Define topography
        #------------------
        scale_me=1.0

        def topography(x,y):
            return (-x/2.0 +0.05*num.sin((x+y)*50.0))*scale_me

        def stagefun(x,y):
            stge=-0.2*scale_me #+0.01*(x>0.9)
            return stge

        domain.set_quantity('elevation',topography)     # Use function for elevation
        domain.get_quantity('elevation').smooth_vertex_values()
        domain.set_quantity('friction',0.03)            # Constant friction


        domain.set_quantity('stage', stagefun)             # Constant negative initial stage
        domain.get_quantity('stage').smooth_vertex_values()


        #--------------------------
        # Setup boundary conditions
        #--------------------------
        Br=anuga.Reflective_boundary(domain)                 # Solid reflective wall
        Bd=anuga.Dirichlet_boundary([-0.1*scale_me,0.,0.])   # Constant boundary values -- not used in this example

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

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

        for t in domain.evolve(yieldstep=7.0,finaltime=7.0):
            #print domain.timestepping_statistics()
            xx = domain.quantities['xmomentum'].centroid_values
            yy = domain.quantities['ymomentum'].centroid_values
            dd = domain.quantities['stage'].centroid_values - domain.quantities['elevation'].centroid_values
            #dd_raw=1.0*dd
            dd = (dd)*(dd>1.0e-03)+1.0e-03
            vv = ( (xx/dd)**2 + (yy/dd)**2)**0.5
            vv = vv*(dd>1.0e-03)
            #print 'Peak velocity is: ', vv.max(), vv.argmax()
            #print 'Volume is', sum(dd_raw*domain.areas)


        #print vv.max()

        assert num.all(vv<1.01e-01)
Ejemplo n.º 12
0
output_file = 'dam_break'

#anuga.copy_code_files(output_dir,__file__)
#start_screen_catcher(output_dir+'_')


#------------------------------------------------------------------------------
# Setup domain
#------------------------------------------------------------------------------
dx = 0.25
dy = dx
L = 20.
W = 5.

# structured mesh
points, vertices, boundary = anuga.rectangular_cross(int(L/dx), int(W/dy), L, W, (-L/2.0, -W/2.0))

#domain = anuga.Domain(points, vertices, boundary) 
domain = Domain(points, vertices, boundary) 

domain.set_name(output_file)                
domain.set_datadir(output_dir) 

#------------------------------------------------------------------------------
# Setup Algorithm, either using command line arguments
# or override manually yourself
#------------------------------------------------------------------------------
from anuga.utilities.argparsing import parse_standard_args
alg = parse_standard_args()
domain.set_flow_algorithm(alg)
Qin=20.
fluxin=Qin/100. #The momentum flux at the upstream boundary ( = discharge / width)
uana= 2.15843634571 # analytical Xvelocity
dana= 0.0926596702273 # analytical water depth
slope = -0.1
mannings = 0.03

args = anuga.get_args()
alg = args.alg
verbose = args.verbose

#------------------------------------------------------------------------------
# Setup sequential computational domain
#------------------------------------------------------------------------------
if myid == 0:
	points, vertices, boundary = rectangular_cross(50, 50, len1=100.0, len2=100.0)
	domain = Domain(points, vertices, boundary) # Create domain
	domain.set_name('channel') # Output name

	domain.set_flow_algorithm(alg)
	domain.set_store_centroids(True)
	
	#------------------------------------------------------------------------------
	# Setup initial conditions
	#------------------------------------------------------------------------------
	
	def topography(x, y):
		return x*slope # linear bed slope
	
	def init_stage(x,y):
		stg= x*slope+0.01 # Constant depth: 1 cm.
Ejemplo n.º 14
0
l1 = 60.*1000.
l2 = dy
nx =int(l1/dx)
ny =int(l2/dy)


# Beach slope of 1/10
def topography(x,y):
	return -(x-200.)/10. 

#--------------------------------------------------------------------------------
# Create Sequential Domain
#--------------------------------------------------------------------------------
if myid == 0:
	print ' Building mesh (alternative non-uniform mesh could be much more efficient)'
	points, vertices, boundary = anuga.rectangular_cross(nx,ny, len1=l1,len2=l2, origin=(-200., 0.))
	
	print 'Creating Domain'
	domain=anuga.Domain(points,vertices,boundary)    # Create Domain
	domain.set_name('runup_v2')                         # Output to file runup.sww
	domain.set_datadir('.')                          # Use current folder
	domain.set_quantities_to_be_stored({'stage': 2, 'xmomentum': 2, 'ymomentum': 2, 'elevation': 1})
	

	domain.set_flow_algorithm(alg)

	#------------------
	# Define Initial conditions
	#------------------
	
	
Ejemplo n.º 15
0
Water driven up a linear slope and time varying boundary,
similar to a beach environment
"""

#------------------------------------------------------------------------------
# Import necessary modules
#------------------------------------------------------------------------------
import anuga

from math import sin, pi, exp

#------------------------------------------------------------------------------
# Setup computational domain
#------------------------------------------------------------------------------
points, vertices, boundary = anuga.rectangular_cross(10, 10)  # Basic mesh

domain = anuga.Domain(points, vertices, boundary)  # Create domain
domain.set_name('runup')  # Output to file runup.sww
domain.set_datadir('.')  # Use current folder


#------------------------------------------------------------------------------
# Setup initial conditions
#------------------------------------------------------------------------------
def topography(x, y):
    return -x / 2  # linear bed slope
    #return x*(-(2.0-x)*.5)                  # curved bed slope


domain.set_quantity('elevation', topography)  # Use function for elevation
Ejemplo n.º 16
0
def runOkushiri(par, n):
    # ------------------------------------------------------------------------------
    # Setup computational domain
    # ------------------------------------------------------------------------------
    xleft = 0
    xright = 5.448
    ybottom = 0
    ytop = 3.402

    # rectangular cross mesh
    points, vertices, boundary = anuga.rectangular_cross(
        int(n), int(n), xright - xleft, ytop - ybottom, (xleft, ybottom))

    newpoints = points.copy()

    # make refinement in x direction
    x = np.multiply([0., 0.1, 0.2, 0.335, 0.925, 1.], max(points[:, 0]))
    y = [0., 3., 4.25, 4.7, 5.3, max(points[:, 0])]
    f1 = interp1d(x, y, kind='quadratic')
    newpoints[:, 0] = f1(points[:, 0])

    # make refinement in y direction
    x = np.multiply([0., .125, .3, .7, .9, 1.], max(points[:, 1]))
    y = [0., 1.25, 1.75, 2.15, 2.65, max(points[:, 1])]
    f2 = interp1d(x, y, kind='quadratic')
    newpoints[:, 1] = f2(points[:, 1])

    c = abs(newpoints[:, 0] - 5.0) + .5 * abs(newpoints[:, 1] - 1.95)
    c = 0.125 * c

    points[:, 0] = c * points[:, 0] + (1 - c) * newpoints[:, 0]
    points[:, 1] = c * points[:, 1] + (1 - c) * newpoints[:, 1]

    # create domain
    domain = anuga.Domain(points, vertices, boundary)

    # don't store .sww file
    # domain.set_quantities_to_be_stored(None)

    # ------------------------------------------------------------------------------
    # Initial Conditions
    # ------------------------------------------------------------------------------
    domain.set_quantity('friction', 0.01)  # 0.0
    domain.set_quantity('stage', 0.0)
    domain.set_quantity(
        'elevation',
        filename='/home/rehmemk/git/anugasgpp/Okushiri/data/bathymetry.pts',
        alpha=0.02)

    # ------------------------------------------------------------------------------
    # Set simulation parameters
    # ------------------------------------------------------------------------------
    domain.set_name('output_okushiri')  # Output name
    domain.set_minimum_storable_height(0.001)  # Don't store w < 0.001m
    domain.set_flow_algorithm('DE0')

    # ------------------------------------------------------------------------------
    # Modify input wave
    # ------------------------------------------------------------------------------
    # rescale input parameter
    try:
        dummy = len(par)
    except:
        par = [par]
    par = np.dot(2, par)

    # load wave data
    # shutil.copyfile('boundary_wave_header.txt', 'boundary_wave_input.txt')
    data = np.loadtxt(
        '/home/rehmemk/git/anugasgpp/Okushiri/data/boundary_wave_original.txt',
        skiprows=1)
    t = data[:, 0]
    y = data[:, 1]
    energy = np.trapz(y**2, t)

    # define bumps [create input wave based on parameters]
    def bump(c):
        theta = c[0]
        position = c[1]
        weight = c[2]
        ybump = weight * np.exp(-.5 * (t - position)**2 * theta**-2)
        return ybump

    nbump = len(par)
    residual = y.copy()
    c = np.zeros((nbump, 3))
    for k in range(nbump):
        maxid = np.argmax(np.abs(residual))
        c0 = np.array([1.5, t[maxid], residual[maxid]])

        def cost(c):
            ybump = bump(c)
            cost = np.sqrt(np.mean((ybump - residual)**2))
            return cost

        c[k, :] = fmin(cost, c0, disp=False)
        residual -= bump(c[k, :])

    # deform wave
    ynew = residual.copy()
    for k in range(nbump):
        ynew += par[k] * bump(c[k, :])
    energynew = np.trapz(ynew**2, t)
    ynew = np.sqrt(energy / energynew) * ynew

    # write data
    data[:, 1] = ynew.copy()
    import scipy
    wave_function = scipy.interpolate.interp1d(t,
                                               ynew,
                                               kind='zero',
                                               fill_value='extrapolate')

    # MR: uncomment to plot input wave
    # points = np.linspace(-10, 30, 10000)
    # evals = np.zeros(len(points))
    # for i in range(len(evals)):
    #     evals[i] = wave_function(points[i])
    # plt.figure()
    # # plt.plot(points, evals)
    # # plt.plot(t, residual, 'r')
    # for k in range(nbump):
    #     plt.plot(t, par[k]*bump(c[k, :]), label='bum {}'.format(k))
    # plt.title('Okushiri Input Wave')
    # plt.show()

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

    # Create boundary function from input wave [replaced by wave function]

    # Create and assign boundary objects
    Bts = anuga.Transmissive_momentum_set_stage_boundary(domain, wave_function)
    Br = anuga.Reflective_boundary(domain)
    domain.set_boundary({'left': Bts, 'right': Br, 'top': Br, 'bottom': Br})

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

    # area for gulleys
    x1 = 4.85
    x2 = 5.25
    y1 = 2.05
    y2 = 1.85

    # gauges
    gauges = [[4.521, 1.196], [4.521, 1.696], [4.521, 2.196]]

    # index in gulley area
    x = domain.centroid_coordinates[:, 0]
    y = domain.centroid_coordinates[:, 1]
    v = np.sqrt((x - x1) ** 2 + (y - y1) ** 2) + \
        np.sqrt((x - x2) ** 2 + (y - y2) ** 2) < 0.5

    dplotter = Domain_plotter(domain, min_depth=0.001)

    k = 0
    # original number of timesteps is 451
    numTimeSteps = int(
        np.loadtxt(
            '/home/rehmemk/git/anugasgpp/Okushiri/data/numTimeSteps.txt'))
    meanstage = np.nan * np.ones((1, numTimeSteps))
    yieldstep = 0.05
    finaltime = (numTimeSteps - 1) * yieldstep
    meanlayer = 0

    # Do the actual calculation
    # for t in domain.evolve(yieldstep=yieldstep, finaltime=finaltime):
    #     # domain.write_time()

    #     # stage [=height of water]
    #     stage = domain.quantities['stage'].centroid_values[v]
    #     # averaging for smoothness
    #     meanstage[0, k] = np.mean(stage)
    #     # k is time
    #     k += 1

    # # PLOTTING

    # # Make movie of each timestep
    #     dplotter.save_depth_frame()
    # anim = dplotter.make_depth_animation()
    # anim.save('okushiri_%i.mp4' % n)
    # meanlayer = meanstage - meanstage[0, 0]

    # Plot the domain
    plt.figure()
    xya = np.loadtxt(
        '/home/rehmemk/git/anugasgpp/Okushiri/plots/Benchmark_2_Bathymetry.xya',
        skiprows=1,
        delimiter=',')
    X = xya[:, 0].reshape(393, 244)
    Y = xya[:, 1].reshape(393, 244)
    Z = xya[:, 2].reshape(393, 244)
    # Remove the white part of the seismic
    # Steves original code uses cmap('gist_earth')
    from matplotlib.colors import LinearSegmentedColormap
    interval = np.hstack([np.linspace(0.0, 0.3), np.linspace(0.5, 1.0)])
    colors = plt.cm.seismic(interval)
    my_cmap = LinearSegmentedColormap.from_list('name', colors)
    # Multiply heights by 400 so that we getreal scale, not model scale
    N1, N2 = np.shape(Z)
    for n1 in range(N1):
        for n2 in range(N2):
            Z[n1, n2] *= 400
    plt.contourf(X, Y, Z, 20, cmap=my_cmap)
    # plt.title('Bathymetry')
    cbar = plt.colorbar()
    cbar.ax.tick_params(labelsize=colorbarfontsize)
    # cbar.set_label('elevation', rotation=270)
    import matplotlib.patches
    from matplotlib.patches import Ellipse
    # plt.plot(x1, y1, 'o')
    # plt.plot(x2, y2, 'o')
    ellipse = Ellipse(((x2 + x1) / 2., (y1 + y2) / 2.),
                      width=0.5,
                      height=0.2,
                      angle=-20,
                      edgecolor='k',
                      fill=False,
                      label='area of interest',
                      linewidth=4)
    plt.gca().add_patch(ellipse)
    # plt.plot(gauges[0][0], gauges[0][1], 'ok')
    # plt.plot(gauges[1][0], gauges[1][1], 'ok')
    # plt.plot(gauges[2][0], gauges[2][1], 'ok', markersize=8, label='gauge')

    # plt.axis('off')
    plt.legend(loc='upper left', fontsize=legendfontsize)
    plt.gca().tick_params(axis='both', which='major', labelsize=tickfontsize)
    plt.tight_layout()
    # ---------------- hack to get ellpse shaped ellipse in legend------------
    import matplotlib.patches as mpatches
    from matplotlib.legend_handler import HandlerPatch
    colors = ["k"]
    texts = ["area of interest"]

    class HandlerEllipse(HandlerPatch):
        def create_artists(self, legend, orig_handle, xdescent, ydescent,
                           width, height, fontsize, trans):
            center = 0.5 * width - 0.5 * xdescent, 0.5 * height - 0.5 * ydescent
            p = mpatches.Ellipse(xy=center,
                                 width=width + xdescent,
                                 height=height + ydescent)
            self.update_prop(p, orig_handle, legend)
            p.set_transform(trans)
            return [p]

    c = [
        mpatches.Circle((0.5, 0.5),
                        1,
                        facecolor='None',
                        edgecolor='k',
                        linewidth=3) for i in range(len(texts))
    ]
    plt.legend(c,
               texts,
               bbox_to_anchor=(0., 1.),
               loc='upper left',
               ncol=1,
               fontsize=16,
               handler_map={mpatches.Circle: HandlerEllipse()})
    # ----------------------------
    plt.savefig('okushiri_domain.pdf')

    # Plot the triangle mesh
    plt.figure()
    mittelblau = (0. / 255, 81. / 255, 158. / 255)
    plt.triplot(dplotter.triang, linewidth=0.3, color=mittelblau)
    plt.axis('off')
    plt.tight_layout()
    plt.savefig('okushiri_mesh_%i.pdf' % n)
    # Plot the domain and the triangle mesh
    plt.figure()
    plt.tripcolor(dplotter.triang,
                  facecolors=dplotter.elev,
                  edgecolors='k',
                  cmap='gist_earth')
    plt.colorbar()
    plt.tight_layout()
    plt.savefig('okushiri_domainandmesh_%i.pdf' % n)

    # make video from sww file
    # swwplotter = SWW_plotter('output_okushiri.sww', min_depth=0.001)
    # lilo = len(swwplotter.time)
    # for k in range(lilo):
    #     if k % 10 == 0:
    #         print ' '
    #     swwplotter.save_stage_frame(frame=k, vmin=-0.02, vmax=0.1)
    #     print '(', swwplotter.time[k], k, ')',
    # print ' '
    # swwanim = swwplotter.make_stage_animation()
    # swwanim.save('okushiri_fromswwfile.mp4')

    return meanlayer
Ejemplo n.º 17
0
def distibute_three_processors():
    """
    Do a parallel test of distributing a rectangle onto 3 processors
   
    """
    
	# FIXME: Need to update expected values on macos
    if sys.platform == 'darwin':
    	return

    import pypar

    myid = pypar.rank()
    numprocs = pypar.size()

    if not numprocs == 3: return

    #print numprocs

    barrier()

    if myid == 0:

        points, vertices, boundary = rectangular_cross(2,2)

        domain = Domain(points, vertices, boundary)


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

        #----------------------------------------------------------------------------------
        # Test pmesh_divide_metis
        #----------------------------------------------------------------------------------
        nodes, triangles, boundary, triangles_per_proc, quantities = pmesh_divide_metis(domain,numprocs)

        assert_(num.allclose(nodes,points))

        true_vertices = [[0, 9, 1], [3, 9, 0], [4, 9, 3], [1, 9, 4], [1, 10, 2], [4, 10, 1], [5, 10, 4], [2, 10, 5], [3, 11, 4], [6, 11, 3], [7, 11, 6], [4, 11, 7], [4, 12, 5], [7, 12, 4], [8, 12, 7], [5, 12, 8]]

        true_triangles = [[4, 9, 3], [4, 12, 5], [7, 12, 4], [8, 12, 7], [5, 12, 8], [0, 9, 1], [1, 9, 4], [1, 10, 2], [4, 10, 1], [5, 10, 4], [2, 10, 5], [3, 9, 0], [3, 11, 4], [6, 11, 3], [7, 11, 6], [4, 11, 7]]

        assert_(num.allclose(vertices,true_vertices))
        assert_(num.allclose(triangles,true_triangles))

        assert_(num.allclose(triangles_per_proc,[5,6,5]))


        #----------------------------------------------------------------------------------
        # Test build_submesh
        #----------------------------------------------------------------------------------
        submesh = build_submesh(nodes, triangles, boundary, quantities, triangles_per_proc)


        assert_(num.allclose(submesh['full_nodes'][0],[[3.0, 0.5, 0.0], [4.0, 0.5, 0.5], [5.0, 0.5, 1.0], [7.0, 1.0, 0.5], [8.0, 1.0, 1.0], [9.0, 0.25, 0.25], [12.0, 0.75, 0.75]]))
        assert_(num.allclose(submesh['full_nodes'][1],[[0.0, 0.0, 0.0], [1.0, 0.0, 0.5], [2.0, 0.0, 1.0], [4.0, 0.5, 0.5], [5.0, 0.5, 1.0], [9.0, 0.25, 0.25], [10.0, 0.25, 0.75]]))
        assert_(num.allclose(submesh['full_nodes'][2],[[0.0, 0.0, 0.0], [3.0, 0.5, 0.0], [4.0, 0.5, 0.5], [6.0, 1.0, 0.0], [7.0, 1.0, 0.5], [9.0, 0.25, 0.25], [11.0, 0.75, 0.25]]))


        assert_(num.allclose(submesh['ghost_nodes'][0],[[0.0, 0.0, 0.0], [1.0, 0.0, 0.5], [2.0, 0.0, 1.0], [6.0, 1.0, 0.0], [10.0, 0.25, 0.75], [11.0, 0.75, 0.25]]))
        assert_(num.allclose(submesh['ghost_nodes'][1],[[3.0, 0.5, 0.0], [7.0, 1.0, 0.5], [8.0, 1.0, 1.0], [11.0, 0.75, 0.25], [12.0, 0.75, 0.75]]))
        assert_(num.allclose(submesh['ghost_nodes'][2],[[1.0, 0.0, 0.5], [5.0, 0.5, 1.0], [8.0, 1.0, 1.0], [12.0, 0.75, 0.75]]))



        true_full_triangles = [num.array([[ 4,  9,  3],
                                          [ 4, 12,  5],
                                          [ 7, 12,  4],
                                          [ 8, 12,  7],
                                          [ 5, 12,  8]]),
                               num.array([[ 0,  9,  1],
                                          [ 1,  9,  4],
                                          [ 1, 10,  2],
                                          [ 4, 10,  1],
                                          [ 5, 10,  4],
                                          [ 2, 10,  5]]),
                               num.array([[ 3,  9,  0],
                                          [ 3, 11,  4],
                                          [ 6, 11,  3],
                                          [ 7, 11,  6],
                                          [ 4, 11,  7]])]


        assert_(num.allclose(submesh['full_triangles'][0],true_full_triangles[0]))
        assert_(num.allclose(submesh['full_triangles'][1],true_full_triangles[1]))
        assert_(num.allclose(submesh['full_triangles'][2],true_full_triangles[2]))

        true_ghost_triangles = [num.array([[ 5,  0,  9,  1],
                                           [ 6,  1,  9,  4],
                                           [ 8,  4, 10,  1],
                                           [ 9,  5, 10,  4],
                                           [10,  2, 10,  5],
                                           [11,  3,  9,  0],
                                           [12,  3, 11,  4],
                                           [13,  6, 11,  3],
                                           [14,  7, 11,  6],
                                           [15,  4, 11,  7]]),
                                num.array([[ 0,  4,  9,  3],
                                           [ 1,  4, 12,  5],
                                           [ 2,  7, 12,  4],
                                           [ 4,  5, 12,  8],
                                           [11,  3,  9,  0],
                                           [12,  3, 11,  4]]),
                                num.array([[ 0,  4,  9,  3],
                                           [ 1,  4, 12,  5],
                                           [ 2,  7, 12,  4],
                                           [ 3,  8, 12,  7],
                                           [ 5,  0,  9,  1],
                                           [ 6,  1,  9,  4]])]



        assert_(num.allclose(submesh['ghost_triangles'][0],true_ghost_triangles[0]))
        assert_(num.allclose(submesh['ghost_triangles'][1],true_ghost_triangles[1]))
        assert_(num.allclose(submesh['ghost_triangles'][2],true_ghost_triangles[2]))

        true_full_commun = [{0: [1, 2], 1: [1, 2], 2: [1, 2], 3: [2], 4: [1]}, {5: [0, 2], 6: [0, 2], 7: [], 8: [0], 9: [0], 10: [0]}, {11: [0, 1], 12: [0, 1], 13: [0], 14: [0], 15: [0]}]

        assert_(true_full_commun == submesh['full_commun'])


        true_ghost_commun = [num.array([[ 5,  1],
                                        [ 6,  1],
                                        [ 8,  1],
                                        [ 9,  1],
                                        [10,  1],
                                        [11,  2],
                                        [12,  2],
                                        [13,  2],
                                        [14,  2],
                                        [15,  2]]),
                             num.array([[ 0,  0],
                                        [ 1,  0],
                                        [ 2,  0],
                                        [ 4,  0],
                                        [11,  2],
                                        [12,  2]]),
                             num.array([[0, 0],
                                        [1, 0],
                                        [2, 0],
                                        [3, 0],
                                        [5, 1],
                                        [6, 1]])]

        assert_(num.allclose(submesh['ghost_commun'][0],true_ghost_commun[0]))
        assert_(num.allclose(submesh['ghost_commun'][1],true_ghost_commun[1]))
        assert_(num.allclose(submesh['ghost_commun'][2],true_ghost_commun[2]))



    barrier()
    #--------------------------------
    # Now do the comunnication part
    #--------------------------------


    if myid == 0:
        #----------------------------------------------------------------------------------
        # Test send_submesh
        #----------------------------------------------------------------------------------
        for p in range(1, numprocs):
            send_submesh(submesh, triangles_per_proc, p, verbose=False)

        #----------------------------------------------------------------------------------
        # Test extract_submesh
        #----------------------------------------------------------------------------------
        points, vertices, boundary, quantities, \
                ghost_recv_dict, full_send_dict, tri_map, node_map, tri_l2g, node_l2g, \
                ghost_layer_width =\
        extract_submesh(submesh, triangles_per_proc)


        true_points =  [[0.5, 0.0], [0.5, 0.5], [0.5, 1.0], [1.0, 0.5], [1.0, 1.0], [0.25, 0.25], [0.75, 0.75], [0.0, 0.0], [0.0, 0.5], [0.0, 1.0], [1.0, 0.0], [0.25, 0.75], [0.75, 0.25]]

        true_vertices = [[1, 5, 0], [1, 6, 2], [3, 6, 1], [4, 6, 3], [2, 6, 4], [7, 5, 8], [8, 5, 1], [1, 11, 8], [2, 11, 1], [9, 11, 2], [0, 5, 7], [0, 12, 1], [10, 12, 0], [3, 12, 10], [1, 12, 3]]


        true_ghost_recv = {1: [num.array([5, 6, 7, 8, 9]), num.array([ 5,  6,  8,  9, 10])], 2: [num.array([10, 11, 12, 13, 14]), num.array([11, 12, 13, 14, 15])]}


        true_full_send = {1: [num.array([0, 1, 2, 4]), num.array([0, 1, 2, 4])], 2: [num.array([0, 1, 2, 3]), num.array([0, 1, 2, 3])]}

        assert_(num.allclose(ghost_layer_width,  2))
        assert_(num.allclose(points,   true_points))
        assert_(num.allclose(vertices, true_vertices))
        assert_(num.allclose(ghost_recv_dict[1],true_ghost_recv[1]))
        assert_(num.allclose(ghost_recv_dict[2],true_ghost_recv[2]))
        assert_(num.allclose(full_send_dict[1],true_full_send[1]))
        assert_(num.allclose(full_send_dict[2],true_full_send[2]))

        #print triangles_per_proc

    else:
        #----------------------------------------------------------------------------------
        # Test rec_submesh
        #----------------------------------------------------------------------------------
        points, vertices, boundary, quantities, \
                ghost_recv_dict, full_send_dict, \
                no_full_nodes, no_full_trigs, tri_map, node_map, tri_l2g, node_l2g, \
                ghost_layer_width  = \
                rec_submesh(0, verbose=False)    

        if myid == 1:


            true_points =  [[0.0, 0.0], [0.0, 0.5], [0.0, 1.0], [0.5, 0.5], [0.5, 1.0], [0.25, 0.25], [0.25, 0.75], [0.5, 0.0], [1.0, 0.5], [1.0, 1.0], [0.75, 0.25], [0.75, 0.75]] 

            true_vertices =  [[0, 5, 1], [1, 5, 3], [1, 6, 2], [3, 6, 1], [4, 6, 3], [2, 6, 4], [3, 5, 7], [3, 11, 4], [8, 11, 3], [4, 11, 9], [7, 5, 0], [7, 10, 3]]

            true_ghost_recv =  {0: [num.array([6, 7, 8, 9]), num.array([0, 1, 2, 4])], 2: [num.array([10, 11]), num.array([11, 12])]}

            true_full_send =  {0: [num.array([0, 1, 3, 4, 5]), num.array([ 5,  6,  8,  9, 10])], 2: [num.array([0, 1]), num.array([5, 6])]}

            true_tri_map  = num.array([ 6,  7,  8, -1,  9,  0, 1,  2,  3,  4,  5, 10, 11])

            true_node_map = num.array([ 0,  1,  2,  7,  3,  4, -1,  8,  9,  5,  6, 10, 11])

            assert_(num.allclose(ghost_layer_width,  2))
            assert_(num.allclose(tri_map,   true_tri_map))
            assert_(num.allclose(node_map,   true_node_map))
            assert_(num.allclose(points,   true_points))
            assert_(num.allclose(vertices, true_vertices))
            assert_(num.allclose(ghost_recv_dict[0],true_ghost_recv[0]))
            assert_(num.allclose(ghost_recv_dict[2],true_ghost_recv[2]))
            assert_(num.allclose(full_send_dict[0],true_full_send[0]))
            assert_(num.allclose(full_send_dict[2],true_full_send[2])) 


        if myid == 2:

            true_points =   [[0.0, 0.0], [0.5, 0.0], [0.5, 0.5], [1.0, 0.0], [1.0, 0.5], [0.25, 0.25], [0.75, 0.25], [0.0, 0.5], [0.5, 1.0], [1.0, 1.0], [0.75, 0.75]]

            true_vertices =  [[1, 5, 0], [1, 6, 2], [3, 6, 1], [4, 6, 3], [2, 6, 4], [2, 5, 1], [2, 10, 8], [4, 10, 2], [9, 10, 4], [0, 5, 7], [7, 5, 2]]

            true_ghost_recv =   {0: [num.array([5, 6, 7, 8]), num.array([0, 1, 2, 3])], 1: [num.array([ 9, 10]), num.array([5, 6])]}

            true_full_send =   {0: [num.array([0, 1, 2, 3, 4]), num.array([11, 12, 13, 14, 15])], 1: [num.array([0, 1]), num.array([11, 12])]}

            true_tri_map  = num.array([5, 6, 7, 8, -1, 9, 10, -1, -1, -1, -1, 0, 1, 2, 3, 4, -1])

            true_node_map = num.array([ 0,  7, -1,  1,  2,  8 , 3,  4,  9,  5, -1,  6, 10])

            assert_(num.allclose(ghost_layer_width,  2))
            assert_(num.allclose(tri_map,   true_tri_map))
            assert_(num.allclose(node_map,   true_node_map))
            assert_(num.allclose(points,   true_points))
            assert_(num.allclose(vertices, true_vertices))
            assert_(num.allclose(ghost_recv_dict[0],true_ghost_recv[0]))
            assert_(num.allclose(ghost_recv_dict[1],true_ghost_recv[1]))
            assert_(num.allclose(full_send_dict[0],true_full_send[0]))
            assert_(num.allclose(full_send_dict[1],true_full_send[1])) 
Ejemplo n.º 18
0
fluxin = Qin / 100.  #The momentum flux at the upstream boundary ( = discharge / width)
uana = 2.15843634571  # analytical Xvelocity
dana = 0.0926596702273  # analytical water depth
slope = -0.1
mannings = 0.03

args = anuga.get_args()
alg = args.alg
verbose = args.verbose

#------------------------------------------------------------------------------
# Setup sequential computational domain
#------------------------------------------------------------------------------
if myid == 0:
    points, vertices, boundary = rectangular_cross(50,
                                                   50,
                                                   len1=100.0,
                                                   len2=100.0)
    domain = Domain(points, vertices, boundary)  # Create domain
    domain.set_name('channel')  # Output name

    domain.set_flow_algorithm(alg)
    domain.set_store_centroids(True)

    #------------------------------------------------------------------------------
    # Setup initial conditions
    #------------------------------------------------------------------------------


    def topography(x, y):
        return x * slope  # linear bed slope
mann=0.03 # Manning's coef
bedslope=-0.1
uana= ( mann**(-2.)*abs(bedslope)*fluxin**(4./3.) )**(3./10.) # Velocity
dana= fluxin/uana # Depth



args = anuga.get_args()
alg = args.alg
verbose = args.verbose

#------------------------------------------------------------------------------
# Setup sequential computational domain
#------------------------------------------------------------------------------
if myid == 0:
	points, vertices, boundary = rectangular_cross(40, 10, len1=400.0, len2=100.0)
	domain = Domain(points, vertices, boundary) # Create domain
	domain.set_name('channel') # Output name
	
	domain.set_flow_algorithm(alg)

	
	#------------------------------------------------------------------------------
	# Setup initial conditions
	#------------------------------------------------------------------------------

	
	def topography(x, y):
		return -x/10. # linear bed slope
	
	def init_stage(x,y):
output_file = 'dam_break'

#anuga.copy_code_files(output_dir,__file__)
#start_screen_catcher(output_dir+'_')

#------------------------------------------------------------------------------
# Setup domain
#------------------------------------------------------------------------------
dx = 0.25
dy = dx
L = 20.
W = 5.

# structured mesh
points, vertices, boundary = anuga.rectangular_cross(int(old_div(L, dx)),
                                                     int(old_div(W, dy)), L, W,
                                                     (-L / 2.0, -W / 2.0))

#domain = anuga.Domain(points, vertices, boundary)
domain = Domain(points, vertices, boundary)

domain.set_name(output_file)
domain.set_datadir(output_dir)

#------------------------------------------------------------------------------
# Setup Algorithm, either using command line arguments
# or override manually yourself
#------------------------------------------------------------------------------
from anuga.utilities.argparsing import parse_standard_args
alg = parse_standard_args()
domain.set_flow_algorithm(alg)
#-------------------------------------------------------------------------------
# Domain
#-------------------------------------------------------------------------------
n = 75#50
m = 75#50
lenx = 8000.0
leny = 8000.0
origin = (-4000.0, -4000.0)



#===============================================================================
# Create Sequential Domain
#===============================================================================
if myid == 0:
    points, elements, boundary = anuga.rectangular_cross(m, n, lenx, leny, origin)
    domain = anuga.Domain(points, elements, boundary)


    domain.set_name(output_file)                
    domain.set_datadir(output_dir)
    
    domain.set_flow_algorithm(alg)

    
    #-------------------------------------------------------------------------------
    # Initial conditions
    #-------------------------------------------------------------------------------
    t = 0.0
    D0 = 1000.
    L = 2500.
Ejemplo n.º 22
0
def elevation(x, y):
    return h0 * x / L


def stage(x, y):
    w, z, u = analytical_sol(x / L, 0.0)
    return h0 * w


#===============================================================================
# Create sequential domain
#===============================================================================
if myid == 0:
    # structured mesh
    points, vertices, boundary = anuga.rectangular_cross(
        int(0.8 * L / dx), int(W / dy), 0.8 * L, W, (-0.5 * L, -0.5 * W))
    domain = Domain(points, vertices, boundary)
    domain.set_name(output_file)
    domain.set_datadir(output_dir)

    domain.set_flow_algorithm(alg)

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

else:
    domain = None
args = anuga.get_args()
alg = args.alg
verbose = args.verbose

m = 200
n = 10
lenx = 40.0
leny = 2.0
origin = (-20.0, -1.0)


# -------------------------------------------------------------------------------
# Sequential Domain
# -------------------------------------------------------------------------------
if myid == 0:
    points, elements, boundary = anuga.rectangular_cross(m, n, lenx, leny, origin)
    domain = anuga.Domain(points, elements, boundary)
    domain.set_name(output_file)
    domain.set_datadir(output_dir)
    # domain.set_minimum_allowed_height(0.01)

    domain.set_flow_algorithm(alg)

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

    # Parameters for analytical solution
    D0 = 4.0
    L = 10.0
    A = 2.0
    z = elevation(x,y)
    return h+z

#DIMENSIONLESS PARAMETERS
eps = a/h0
T = Tp*sqrt(g*h0)/L
A = eps/j0(4.0*pi/T)

#===============================================================================
# Create sequential domain
#===============================================================================
if myid == 0:
    # structured mesh

    points, vertices, boundary = \
      anuga.rectangular_cross(int(1.1*L/dx), int(W/dy), 1.1*L, W, (0.0, 0.0))

    domain = Domain(points, vertices, boundary) 
    domain.set_name(output_file)                
    domain.set_datadir(output_dir)

    domain.set_flow_algorithm(alg)


    #------------------------------------------------------------------------------
    # Setup initial conditions
    #------------------------------------------------------------------------------
    domain.set_quantity('friction', 0.0)
    domain.set_quantity('elevation', elevation)
    domain.set_quantity('height', height)
    domain.set_quantity('stage', stage)
Ejemplo n.º 25
0
import anuga
import numpy
from math import sin, pi, exp
from anuga import Domain
from anuga import myid, finalize, distribute


args = anuga.get_args()
alg = args.alg
verbose = args.verbose

if myid == 0:
    # ---------
    # Setup computational domain
    # ---------
    points, vertices, boundary = anuga.rectangular_cross(100, 3, len1=1.0, len2=0.03)
    domain = Domain(points, vertices, boundary)  # Create Domain
    domain.set_name("runup")  # Output to file runup.sww
    domain.set_datadir(".")  # Use current folder
    domain.set_quantities_to_be_stored({"stage": 2, "xmomentum": 2, "ymomentum": 2, "elevation": 1})
    domain.set_flow_algorithm(alg)

    # ------------------
    # Define topography
    # ------------------
    def topography(x, y):
        return -x / 2  # Linear bed slope

    def stagefun(x, y):
        return -0.45  # Stage
Ejemplo n.º 26
0
mann = 0.03  # Manning's coef
bedslope = -0.1
uana = (mann**(-2.) * abs(bedslope) * fluxin**(4. / 3.))**(3. / 10.
                                                           )  # Velocity
dana = fluxin / uana  # Depth

args = anuga.get_args()
alg = args.alg
verbose = args.verbose

#------------------------------------------------------------------------------
# Setup sequential computational domain
#------------------------------------------------------------------------------
if myid == 0:
    points, vertices, boundary = rectangular_cross(40,
                                                   10,
                                                   len1=400.0,
                                                   len2=100.0)
    domain = Domain(points, vertices, boundary)  # Create domain
    domain.set_name('channel')  # Output name

    domain.set_flow_algorithm(alg)

    #------------------------------------------------------------------------------
    # Setup initial conditions
    #------------------------------------------------------------------------------


    def topography(x, y):
        return -x / 10.  # linear bed slope

    def init_stage(x, y):
Ejemplo n.º 27
0
def generate_channel3_domain(gpu=True):
    #-----------------------------------------------------------------------
    # Setup computational domain
    #-----------------------------------------------------------------------
    length = 40.
    width = 5.
    dx = dy = .1  # Resolution: Length of subdivisions on both axes

    points, vertices, boundary = anuga.rectangular_cross(int(length / dx),
                                                         int(width / dy),
                                                         len1=length,
                                                         len2=width)
    if gpu:
        domain = GPU_domain(points, vertices, boundary)
        if '-gpu' in sys.argv:
            domain.using_gpu = True
            print " --> Enable GPU version"
        for i in range(len(sys.argv)):
            if sys.argv[i] == '-fs':
                global finaltime
                finaltime = float(sys.argv[i + 1])
                print " --> Finaltime is reset as %f" % finaltime

    else:
        domain = anuga.Domain(points, vertices, boundary)
    domain.set_name('channel3')  # Output name

    #print domain.statistics()

    #-----------------------------------------------------------------------
    # Setup initial conditions
    #-----------------------------------------------------------------------
    def topography(x, y):
        """Complex topography defined by a function of vectors x and y."""

        z = -x / 10

        N = len(x)
        for i in range(N):
            # Step
            if 10 < x[i] < 12:
                z[i] += 0.4 - 0.05 * y[i]

            # Constriction
            if 27 < x[i] < 29 and y[i] > 3:
                z[i] += 2

            # Pole
            if (x[i] - 34)**2 + (y[i] - 2)**2 < 0.4**2:
                z[i] += 2

        return z

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

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

    domain.set_boundary({'left': Bi, 'right': Bo, 'top': Br, 'bottom': Br})
    return domain
Ejemplo n.º 28
0
import anuga
import numpy
from math import sin, pi, exp
from anuga import Domain
from anuga import myid, finalize, distribute

args = anuga.get_args()
alg = args.alg
verbose = args.verbose

if myid == 0:
    #---------
    #Setup computational domain
    #---------
    points, vertices, boundary = anuga.rectangular_cross(100,
                                                         3,
                                                         len1=1.0,
                                                         len2=0.03)
    domain = Domain(points, vertices, boundary)  # Create Domain
    domain.set_name('runup')  # Output to file runup.sww
    domain.set_datadir('.')  # Use current folder
    domain.set_quantities_to_be_stored({
        'stage': 2,
        'xmomentum': 2,
        'ymomentum': 2,
        'elevation': 1
    })
    domain.set_flow_algorithm(alg)

    #------------------
    # Define topography
    #------------------
def distibute_three_processors():
    """
    Do a parallel test of distributing a rectangle onto 3 processors

    """

    # FIXME: Need to update expected values on macos
    if sys.platform == 'darwin':
        return

    # FIXME: Need to update expected values on macos
    #if sys.platform == 'win32':
    #	return

    from anuga.utilities import parallel_abstraction as pypar

    myid = pypar.rank()
    numprocs = pypar.size()

    if not numprocs == 3:
        return

    try:
        import pymetis
        metis_version = 5
    except:
        metis_version = 4

    #print numprocs

    #barrier()

    if myid == 0:

        nodes_0, triangles_0, boundary_0 = rectangular_cross(2, 2)

        domain = Domain(nodes_0, triangles_0, boundary_0)

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

        #----------------------------------------------------------------------------------
        # Test pmesh_divide_metis
        #----------------------------------------------------------------------------------
        vertices, triangles, boundary, triangles_per_proc, quantities = pmesh_divide_metis(
            domain, numprocs)

        if False:
            print_seq_values(vertices, triangles, triangles_per_proc)

        true_seq_values = get_true_seq_values(metis_version=metis_version)

        if False:
            print("True Seq Values = \\")
            pprint(true_seq_values)

        assert_allclose(vertices, true_seq_values['vertices'])
        assert_allclose(triangles, true_seq_values['triangles'])
        assert_allclose(triangles_per_proc,
                        true_seq_values['triangles_per_proc'])

        #----------------------------------------------------------------------------------
        # Test build_submesh
        #----------------------------------------------------------------------------------
        submesh = build_submesh(vertices, triangles, boundary, quantities,
                                triangles_per_proc)

        if False:
            print('submesh_values = \\')
            print_submesh_values(submesh)

        true_values = get_true_submesh_values(metis_version)

        assert_allclose(submesh['full_nodes'][0], true_values['full_nodes_0'])
        assert_allclose(submesh['full_nodes'][1], true_values['full_nodes_1'])
        assert_allclose(submesh['full_nodes'][2], true_values['full_nodes_2'])

        assert_allclose(submesh['ghost_nodes'][0],
                        true_values['ghost_nodes_0'])
        assert_allclose(submesh['ghost_nodes'][1],
                        true_values['ghost_nodes_1'])
        assert_allclose(submesh['ghost_nodes'][2],
                        true_values['ghost_nodes_2'])

        assert_allclose(submesh['full_triangles'][0],
                        true_values['full_triangles_0'])
        assert_allclose(submesh['full_triangles'][1],
                        true_values['full_triangles_1'])
        assert_allclose(submesh['full_triangles'][2],
                        true_values['full_triangles_2'])

        assert_allclose(submesh['ghost_triangles'][0],
                        true_values['ghost_triangles_0'])
        assert_allclose(submesh['ghost_triangles'][1],
                        true_values['ghost_triangles_1'])
        assert_allclose(submesh['ghost_triangles'][2],
                        true_values['ghost_triangles_2'])

        assert_allclose(submesh['ghost_commun'][0],
                        true_values['ghost_commun_0'])
        assert_allclose(submesh['ghost_commun'][1],
                        true_values['ghost_commun_1'])
        assert_allclose(submesh['ghost_commun'][2],
                        true_values['ghost_commun_2'])

        assert_(submesh['full_commun'] == true_values['full_commun'])

    barrier()
    #--------------------------------
    # Now do the comunnication part
    #--------------------------------

    if myid == 0:

        points, vertices, boundary, quantities, \
                    ghost_recv_dict, full_send_dict, tri_map, node_map, tri_l2g, node_l2g, \
                    ghost_layer_width =\
                    extract_submesh(submesh, triangles_per_proc)

        #----------------------------------------------------------------------------------
        # Test send_submesh
        #----------------------------------------------------------------------------------
        for p in range(1, numprocs):
            send_submesh(submesh, triangles_per_proc, p, verbose=False)
    else:
        #----------------------------------------------------------------------------------
        # Test rec_submesh
        #----------------------------------------------------------------------------------
        points, triangles, boundary, quantities, \
                ghost_recv_dict, full_send_dict, \
                no_full_nodes, no_full_trigs, tri_map, node_map, tri_l2g, node_l2g, \
                ghost_layer_width = \
                rec_submesh(0, verbose=False)

    barrier()

    #--------------------------------
    # Now do the test
    #--------------------------------
    if myid == 0:

        if False:
            print('extract_values = \\')
            print_extract_submesh(points, triangles, ghost_recv_dict, \
                                  full_send_dict, tri_map, node_map, ghost_layer_width)

        true_values = get_true_extract_submesh(metis_version)

        assert_allclose(points, true_values['points'])
        assert_allclose(triangles, true_values['triangles'])
        assert_allclose(ghost_recv_dict[1], true_values['ghost_recv_dict_1'])
        assert_allclose(ghost_recv_dict[2], true_values['ghost_recv_dict_2'])
        assert_allclose(full_send_dict[1], true_values['full_send_dict_1'])
        assert_allclose(full_send_dict[2], true_values['full_send_dict_2'])
        assert_allclose(tri_map, true_values['tri_map'])
        assert_allclose(node_map, true_values['node_map'])
        assert_allclose(ghost_layer_width, true_values['ghost_layer_width'])

    if myid == 1:

        if False:
            print("rec_submesh_1 = \\")
            print_rec_submesh_1(points, triangles, ghost_recv_dict, full_send_dict, \
                         tri_map, node_map, ghost_layer_width)

        true_values = get_true_rec_submesh_1(metis_version)

        if False:
            print('true_rec_values_1 = \\')
            pprint(true_values)

        assert_allclose(points, true_values['points'])
        assert_allclose(triangles, true_values['triangles'])
        assert_allclose(ghost_recv_dict[0], true_values['ghost_recv_dict_0'])
        assert_allclose(ghost_recv_dict[2], true_values['ghost_recv_dict_2'])
        assert_allclose(full_send_dict[0], true_values['full_send_dict_0'])
        assert_allclose(full_send_dict[2], true_values['full_send_dict_2'])
        assert_allclose(tri_map, true_values['tri_map'])
        assert_allclose(node_map, true_values['node_map'])
        assert_allclose(ghost_layer_width, true_values['ghost_layer_width'])

    if myid == 2:

        if False:
            print("rec_submesh_2 = \\")
            print_rec_submesh_2(points, triangles, ghost_recv_dict, full_send_dict, \
                         tri_map, node_map, ghost_layer_width)

        true_values = get_true_rec_submesh_2(metis_version)

        if False:
            print('true_rec_values_2 = \\')
            pprint(true_values)

        assert_allclose(points, true_values['points'])
        assert_allclose(triangles, true_values['triangles'])
        assert_allclose(ghost_recv_dict[0], true_values['ghost_recv_dict_0'])
        assert_allclose(ghost_recv_dict[1], true_values['ghost_recv_dict_1'])
        assert_allclose(full_send_dict[0], true_values['full_send_dict_0'])
        assert_allclose(full_send_dict[1], true_values['full_send_dict_1'])
        assert_allclose(tri_map, true_values['tri_map'])
        assert_allclose(node_map, true_values['node_map'])
        assert_allclose(ghost_layer_width, true_values['ghost_layer_width'])

    finalize()

#===============================================================================
# Setup and Run Model
#===============================================================================


#------------------------------------------------------------------------------
# Setup computational domain
#------------------------------------------------------------------------------
print ' Set up Domain first...'
length = 24.
width = 5.
dx = dy = 0.2 #.1           # Resolution: Length of subdivisions on both axes

points, vertices, boundary = rectangular_cross(int(length/dx), int(width/dy),
                                               len1=length, len2=width)
domain = Domain(points, vertices, boundary)
domain.set_flow_algorithm('DE1')
domain.set_name('flat_fill_slice_erosion') # Output name
print domain.statistics()

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



domain.set_quantity('elevation', topography)           # elevation is a function
domain.set_quantity('friction', 0.01)                  # Constant friction
domain.set_quantity('stage', expression='elevation')   # Dry initial condition
Ejemplo n.º 31
0
# Beach slope of 1/10
def topography(x, y):
    return -(x - 200.) / 10.


#--------------------------------------------------------------------------------
# Create Sequential Domain
#--------------------------------------------------------------------------------
if myid == 0:
    print(
        ' Building mesh (alternative non-uniform mesh could be much more efficient)'
    )
    points, vertices, boundary = anuga.rectangular_cross(nx,
                                                         ny,
                                                         len1=l1,
                                                         len2=l2,
                                                         origin=(-200., 0.))

    print('Creating Domain')
    domain = anuga.Domain(points, vertices, boundary)  # Create Domain
    domain.set_name('runup_v2')  # Output to file runup.sww
    domain.set_datadir('.')  # Use current folder
    domain.set_quantities_to_be_stored({
        'stage': 2,
        'xmomentum': 2,
        'ymomentum': 2,
        'elevation': 1
    })

    domain.set_flow_algorithm(alg)
Ejemplo n.º 32
0
poly1nsbase = 0.5  # set poly no scour base level in m
poly2nsbase = 0.3

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

if myid == 0:
    print '>>>>> DUNE EROSION TEST SCRIPT V2'
    print '>>>>> Setting  up Domain on processor 0...'
    length = 36.
    width = 5.
    dx = dy = 0.1  # Resolution: Length of subdivisions on both axes
    print '>>>>> Domain has L = %f, W = %f, dx=dy= %f' % (length, width, dx)
    points, vertices, boundary = anuga.rectangular_cross(int(length / dx),
                                                         int(width / dy),
                                                         len1=length,
                                                         len2=width)

    domain = anuga.Domain(points, vertices, boundary)
    domain.set_flow_algorithm('DE0')
    domain.set_name('sanddune_testV2SR')  # Output name
    domain.set_quantity('elevation', topography)  # elevation is a function
    domain.set_quantity('friction', 0.01)  # Constant friction
    domain.set_quantity('stage',
                        expression='elevation')  # Dry initial condition

    print domain.statistics()

    # get the indices of triangles in each erosion poly so can setup nsbase_ in domain
    poly1ind = (Region(domain, polygon=polygon1)).indices
    poly2ind = (Region(domain, polygon=polygon2)).indices
def distibute_three_processors():
    """
    Do a parallel test of distributing a rectangle onto 3 processors
    """


    myid = par.rank()
    par.numprocs = par.size()

    if not par.numprocs == 3: return

    #print par.numprocs

    par.barrier()

    if myid == 0:

        points, vertices, boundary = rectangular_cross(2,2)

        domain = Domain(points, vertices, boundary)


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

        #----------------------------------------------------------------------------------
        # Test pmesh_divide_metis
        #----------------------------------------------------------------------------------
        nodes, triangles, boundary, triangles_per_proc, quantities = pmesh_divide_metis(domain,par.numprocs)

        assert_(num.allclose(nodes,points))

        true_vertices = [[0, 9, 1], [3, 9, 0], [4, 9, 3], [1, 9, 4], [1, 10, 2], [4, 10, 1], [5, 10, 4], [2, 10, 5], [3, 11, 4], [6, 11, 3], [7, 11, 6], [4, 11, 7], [4, 12, 5], [7, 12, 4], [8, 12, 7], [5, 12, 8]]

        true_triangles = [[4, 9, 3], [4, 12, 5], [7, 12, 4], [8, 12, 7], [5, 12, 8], [0, 9, 1], [1, 9, 4], [1, 10, 2], [4, 10, 1], [5, 10, 4], [2, 10, 5], [3, 9, 0], [3, 11, 4], [6, 11, 3], [7, 11, 6], [4, 11, 7]]

        assert_(num.allclose(vertices,true_vertices))
        assert_(num.allclose(triangles,true_triangles))

        assert_(num.allclose(triangles_per_proc,[5,6,5]))


        #----------------------------------------------------------------------------------
        # Test build_submesh
        #----------------------------------------------------------------------------------
        submesh = build_submesh(nodes, triangles, boundary, quantities, triangles_per_proc)


        assert_(num.allclose(submesh['full_nodes'][0],[[3.0, 0.5, 0.0], [4.0, 0.5, 0.5], [5.0, 0.5, 1.0], [7.0, 1.0, 0.5], [8.0, 1.0, 1.0], [9.0, 0.25, 0.25], [12.0, 0.75, 0.75]]))
        assert_(num.allclose(submesh['full_nodes'][1],[[0.0, 0.0, 0.0], [1.0, 0.0, 0.5], [2.0, 0.0, 1.0], [4.0, 0.5, 0.5], [5.0, 0.5, 1.0], [9.0, 0.25, 0.25], [10.0, 0.25, 0.75]]))
        assert_(num.allclose(submesh['full_nodes'][2],[[0.0, 0.0, 0.0], [3.0, 0.5, 0.0], [4.0, 0.5, 0.5], [6.0, 1.0, 0.0], [7.0, 1.0, 0.5], [9.0, 0.25, 0.25], [11.0, 0.75, 0.25]]))


        assert_(num.allclose(submesh['ghost_nodes'][0],[[0.0, 0.0, 0.0], [1.0, 0.0, 0.5], [2.0, 0.0, 1.0], [6.0, 1.0, 0.0], [10.0, 0.25, 0.75], [11.0, 0.75, 0.25]]))
        assert_(num.allclose(submesh['ghost_nodes'][1],[[3.0, 0.5, 0.0], [7.0, 1.0, 0.5], [8.0, 1.0, 1.0], [11.0, 0.75, 0.25], [12.0, 0.75, 0.75]]))
        assert_(num.allclose(submesh['ghost_nodes'][2],[[1.0, 0.0, 0.5], [5.0, 0.5, 1.0], [8.0, 1.0, 1.0], [12.0, 0.75, 0.75]]))



        true_full_triangles = [num.array([[ 4,  9,  3],
                                          [ 4, 12,  5],
                                          [ 7, 12,  4],
                                          [ 8, 12,  7],
                                          [ 5, 12,  8]]),
                               num.array([[ 0,  9,  1],
                                          [ 1,  9,  4],
                                          [ 1, 10,  2],
                                          [ 4, 10,  1],
                                          [ 5, 10,  4],
                                          [ 2, 10,  5]]),
                               num.array([[ 3,  9,  0],
                                          [ 3, 11,  4],
                                          [ 6, 11,  3],
                                          [ 7, 11,  6],
                                          [ 4, 11,  7]])]


        assert_(num.allclose(submesh['full_triangles'][0],true_full_triangles[0]))
        assert_(num.allclose(submesh['full_triangles'][1],true_full_triangles[1]))
        assert_(num.allclose(submesh['full_triangles'][2],true_full_triangles[2]))

        true_ghost_triangles = [num.array([[ 5,  0,  9,  1],
                                           [ 6,  1,  9,  4],
                                           [ 8,  4, 10,  1],
                                           [ 9,  5, 10,  4],
                                           [10,  2, 10,  5],
                                           [11,  3,  9,  0],
                                           [12,  3, 11,  4],
                                           [13,  6, 11,  3],
                                           [14,  7, 11,  6],
                                           [15,  4, 11,  7]]),
                                num.array([[ 0,  4,  9,  3],
                                           [ 1,  4, 12,  5],
                                           [ 2,  7, 12,  4],
                                           [ 4,  5, 12,  8],
                                           [11,  3,  9,  0],
                                           [12,  3, 11,  4]]),
                                num.array([[ 0,  4,  9,  3],
                                           [ 1,  4, 12,  5],
                                           [ 2,  7, 12,  4],
                                           [ 3,  8, 12,  7],
                                           [ 5,  0,  9,  1],
                                           [ 6,  1,  9,  4]])]



        assert_(num.allclose(submesh['ghost_triangles'][0],true_ghost_triangles[0]))
        assert_(num.allclose(submesh['ghost_triangles'][1],true_ghost_triangles[1]))
        assert_(num.allclose(submesh['ghost_triangles'][2],true_ghost_triangles[2]))

        true_full_commun = [{0: [1, 2], 1: [1, 2], 2: [1, 2], 3: [2], 4: [1]}, {5: [0, 2], 6: [0, 2], 7: [], 8: [0], 9: [0], 10: [0]}, {11: [0, 1], 12: [0, 1], 13: [0], 14: [0], 15: [0]}]

        assert_(true_full_commun == submesh['full_commun'])


        true_ghost_commun = [num.array([[ 5,  1],
                                        [ 6,  1],
                                        [ 8,  1],
                                        [ 9,  1],
                                        [10,  1],
                                        [11,  2],
                                        [12,  2],
                                        [13,  2],
                                        [14,  2],
                                        [15,  2]]),
                             num.array([[ 0,  0],
                                        [ 1,  0],
                                        [ 2,  0],
                                        [ 4,  0],
                                        [11,  2],
                                        [12,  2]]),
                             num.array([[0, 0],
                                        [1, 0],
                                        [2, 0],
                                        [3, 0],
                                        [5, 1],
                                        [6, 1]])]

        assert_(num.allclose(submesh['ghost_commun'][0],true_ghost_commun[0]))
        assert_(num.allclose(submesh['ghost_commun'][1],true_ghost_commun[1]))
        assert_(num.allclose(submesh['ghost_commun'][2],true_ghost_commun[2]))



    par.barrier()
    #--------------------------------
    # Now do the comunnication part
    #--------------------------------


    if myid == 0:
        #----------------------------------------------------------------------------------
        # Test send_submesh
        #----------------------------------------------------------------------------------
        for p in range(1, par.numprocs):
            send_submesh(submesh, triangles_per_proc, p, verbose=False)

        #----------------------------------------------------------------------------------
        # Test extract_submesh
        #----------------------------------------------------------------------------------
        points, vertices, boundary, quantities, \
                ghost_recv_dict, full_send_dict, tri_map, node_map, ghost_layer_width =\
        extract_submesh(submesh, triangles_per_proc)


        true_points =  [[0.5, 0.0], [0.5, 0.5], [0.5, 1.0], [1.0, 0.5], [1.0, 1.0], [0.25, 0.25], [0.75, 0.75], [0.0, 0.0], [0.0, 0.5], [0.0, 1.0], [1.0, 0.0], [0.25, 0.75], [0.75, 0.25]]

        true_vertices = [[1, 5, 0], [1, 6, 2], [3, 6, 1], [4, 6, 3], [2, 6, 4], [7, 5, 8], [8, 5, 1], [1, 11, 8], [2, 11, 1], [9, 11, 2], [0, 5, 7], [0, 12, 1], [10, 12, 0], [3, 12, 10], [1, 12, 3]]


        true_ghost_recv = {1: [num.array([5, 6, 7, 8, 9]), num.array([ 5,  6,  8,  9, 10])], 2: [num.array([10, 11, 12, 13, 14]), num.array([11, 12, 13, 14, 15])]}


        true_full_send = {1: [num.array([0, 1, 2, 4]), num.array([0, 1, 2, 4])], 2: [num.array([0, 1, 2, 3]), num.array([0, 1, 2, 3])]}

        assert_(num.allclose(ghost_layer_width,  2))
        assert_(num.allclose(points,   true_points))
        assert_(num.allclose(vertices, true_vertices))
        assert_(num.allclose(ghost_recv_dict[1],true_ghost_recv[1]))
        assert_(num.allclose(ghost_recv_dict[2],true_ghost_recv[2]))
        assert_(num.allclose(full_send_dict[1],true_full_send[1]))
        assert_(num.allclose(full_send_dict[2],true_full_send[2]))

        #print triangles_per_proc

    else:
        #----------------------------------------------------------------------------------
        # Test rec_submesh
        #----------------------------------------------------------------------------------
        points, vertices, boundary, quantities, \
                ghost_recv_dict, full_send_dict, \
                no_full_nodes, no_full_trigs, tri_map, node_map, ghost_layer_width  = \
                rec_submesh(0, verbose=False)

        if myid == 1:


            true_points =  [[0.0, 0.0], [0.0, 0.5], [0.0, 1.0], [0.5, 0.5], [0.5, 1.0], [0.25, 0.25], [0.25, 0.75], [0.5, 0.0], [1.0, 0.5], [1.0, 1.0], [0.75, 0.25], [0.75, 0.75]]

            true_vertices =  [[0, 5, 1], [1, 5, 3], [1, 6, 2], [3, 6, 1], [4, 6, 3], [2, 6, 4], [3, 5, 7], [3, 11, 4], [8, 11, 3], [4, 11, 9], [7, 5, 0], [7, 10, 3]]

            true_ghost_recv =  {0: [num.array([6, 7, 8, 9]), num.array([0, 1, 2, 4])], 2: [num.array([10, 11]), num.array([11, 12])]}

            true_full_send =  {0: [num.array([0, 1, 3, 4, 5]), num.array([ 5,  6,  8,  9, 10])], 2: [num.array([0, 1]), num.array([5, 6])]}

            true_tri_map  = num.array([ 6,  7,  8, -1,  9,  0, 1,  2,  3,  4,  5, 10, 11])

            true_node_map = num.array([ 0,  1,  2,  7,  3,  4, -1,  8,  9,  5,  6, 10, 11])

            assert_(num.allclose(ghost_layer_width,  2))
            assert_(num.allclose(tri_map,   true_tri_map))
            assert_(num.allclose(node_map,   true_node_map))
            assert_(num.allclose(points,   true_points))
            assert_(num.allclose(vertices, true_vertices))
            assert_(num.allclose(ghost_recv_dict[0],true_ghost_recv[0]))
            assert_(num.allclose(ghost_recv_dict[2],true_ghost_recv[2]))
            assert_(num.allclose(full_send_dict[0],true_full_send[0]))
            assert_(num.allclose(full_send_dict[2],true_full_send[2]))


        if myid == 2:

            true_points =   [[0.0, 0.0], [0.5, 0.0], [0.5, 0.5], [1.0, 0.0], [1.0, 0.5], [0.25, 0.25], [0.75, 0.25], [0.0, 0.5], [0.5, 1.0], [1.0, 1.0], [0.75, 0.75]]

            true_vertices =  [[1, 5, 0], [1, 6, 2], [3, 6, 1], [4, 6, 3], [2, 6, 4], [2, 5, 1], [2, 10, 8], [4, 10, 2], [9, 10, 4], [0, 5, 7], [7, 5, 2]]

            true_ghost_recv =   {0: [num.array([5, 6, 7, 8]), num.array([0, 1, 2, 3])], 1: [num.array([ 9, 10]), num.array([5, 6])]}

            true_full_send =   {0: [num.array([0, 1, 2, 3, 4]), num.array([11, 12, 13, 14, 15])], 1: [num.array([0, 1]), num.array([11, 12])]}

            true_tri_map  = num.array([5, 6, 7, 8, -1, 9, 10, -1, -1, -1, -1, 0, 1, 2, 3, 4, -1])

            true_node_map = num.array([ 0,  7, -1,  1,  2,  8 , 3,  4,  9,  5, -1,  6, 10])

            assert_(num.allclose(ghost_layer_width,  2))
            assert_(num.allclose(tri_map,   true_tri_map))
            assert_(num.allclose(node_map,   true_node_map))
            assert_(num.allclose(points,   true_points))
            assert_(num.allclose(vertices, true_vertices))
            assert_(num.allclose(ghost_recv_dict[0],true_ghost_recv[0]))
            assert_(num.allclose(ghost_recv_dict[1],true_ghost_recv[1]))
            assert_(num.allclose(full_send_dict[0],true_full_send[0]))
            assert_(num.allclose(full_send_dict[1],true_full_send[1]))
        elif 1400.0 <= x[i] < 1500.0:
            z[i] = 0.0
        elif 1500.0 <= x[i] < 1700.0:
            z[i] = 3.0
        elif 1700.0 <= x[i] < 1800.0:
            z[i] = -0.03*(x[i]-1700) + 3.0
        else:
            z[i] = (4.5/40000)*(x[i]-1800)*(x[i]-1800) + 2.0
    return z 

#------------------------------------------------------------------------------
# Setup sequential domain
#------------------------------------------------------------------------------
if myid == 0:
    # structured mesh
    points, vertices, boundary = anuga.rectangular_cross(int(L/dx), int(W/dy), L, W, (0.0, 0.0))
 
    domain = Domain(points, vertices, boundary) 
    
    domain.set_name(output_file)                
    domain.set_datadir(output_dir) 
    domain.set_flow_algorithm(alg)
    
    #------------------------------------------------------------------------------
    # Setup initial conditions
    #------------------------------------------------------------------------------
    domain.set_quantity('friction', 0.0)
    domain.set_quantity('stage', stage_flat)
    domain.set_quantity('elevation', bed_elevation)
    
else:
Ejemplo n.º 35
0
def run(par,
        n,
        withNormalization,
        withResidual,
        wave_type='bumps',
        minimum_allowed_height=1e-5):
    # ------------------------------------------------------------------------------
    # Setup computational domain
    # ------------------------------------------------------------------------------
    xleft = 0
    xright = 5.448
    ybottom = 0
    ytop = 3.402

    # rectangular cross mesh
    points, vertices, boundary = anuga.rectangular_cross(
        int(n), int(n), xright - xleft, ytop - ybottom, (xleft, ybottom))

    newpoints = points.copy()

    # make refinement in x direction
    x = np.multiply([0., 0.1, 0.2, 0.335, 0.925, 1.], max(points[:, 0]))
    y = [0., 3., 4.25, 4.7, 5.3, max(points[:, 0])]
    f1 = interp1d(x, y, kind='linear')
    newpoints[:, 0] = f1(points[:, 0])

    # make refinement in y direction
    x = np.multiply([0., .125, .3, .7, .9, 1.], max(points[:, 1]))
    y = [0., 1.25, 1.75, 2.15, 2.65, max(points[:, 1])]
    f2 = interp1d(x, y, kind='linear')
    newpoints[:, 1] = f2(points[:, 1])

    c = abs(newpoints[:, 0] - 5.0) + .5 * abs(newpoints[:, 1] - 1.95)
    c = 0.125 * c

    points[:, 0] = c * points[:, 0] + (1 - c) * newpoints[:, 0]
    points[:, 1] = c * points[:, 1] + (1 - c) * newpoints[:, 1]

    # create domain
    domain = anuga.Domain(points, vertices, boundary)

    # don't store .sww file
    domain.set_quantities_to_be_stored(None)

    # ------------------------------------------------------------------------------
    # Initial Conditions
    # ------------------------------------------------------------------------------
    domain.set_quantity('friction', 0.01)  # 0.0
    domain.set_quantity('stage', 0.0)
    domain.set_quantity(
        'elevation',
        filename='/home/rehmemk/git/anugasgpp/Okushiri/data/bathymetry.pts',
        alpha=0.02)

    # ------------------------------------------------------------------------------
    # Set simulation parameters
    # ------------------------------------------------------------------------------
    domain.set_name('output_okushiri')  # Output name
    # domain.set_minimum_storable_height(0.001)  # Don't store w < 0.001m
    domain.set_minimum_storable_height(1.0)  # Don't store w < 0.001m
    domain.set_flow_algorithm('DE0')

    # ------------------------------------------------------------------------------
    # Modify input wave
    # ------------------------------------------------------------------------------
    # rescale input parameter
    try:
        dummy = len(par)
    except:
        par = [par]
    par = np.dot(2, par)

    if wave_type == 'bumps':
        wave_function, _, _ = wave_functions.heights_wave(
            par, withResidual, withNormalization)
    elif wave_type == 'original':
        wave_function = wave_functions.original_wave_interpolant()
    elif wave_type == 'cubic':
        wave_function, _, _ = wave_functions.cubic_heights_wave(
            par, withResidual, withNormalization)
    else:
        print(f'Error. Wave type {wave_type} unknown')

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

    # Create boundary function from input wave [replaced by wave function]

    # Create and assign boundary objects
    Bts = anuga.Transmissive_momentum_set_stage_boundary(domain, wave_function)
    Br = anuga.Reflective_boundary(domain)
    domain.set_boundary({'left': Bts, 'right': Br, 'top': Br, 'bottom': Br})

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

    # this prevents problems w.r.t. divisions by zero
    # It might decrease the acheivable accuracy
    domain.set_minimum_allowed_height(minimum_allowed_height)  # default 1e-5

    # area for gulleys
    x1 = 4.85
    x2 = 5.25
    y1 = 2.05
    y2 = 1.85

    # index in gulley area
    x = domain.centroid_coordinates[:, 0]
    y = domain.centroid_coordinates[:, 1]
    v = np.sqrt((x - x1) ** 2 + (y - y1) ** 2) + \
        np.sqrt((x - x2) ** 2 + (y - y2) ** 2) < 0.5

    # three gauges and a point somewhere on the boundary that could be used for verification
    # get id's of the corresponding triangles
    gauge = [[4.521, 1.196], [4.521, 1.696], [4.521, 2.196]]
    bdyloc = [0.00001, 2.5]
    g5_id = domain.get_triangle_containing_point(gauge[0])
    g7_id = domain.get_triangle_containing_point(gauge[1])
    g9_id = domain.get_triangle_containing_point(gauge[2])
    bc_id = domain.get_triangle_containing_point(bdyloc)

    k = 0
    # original number of timesteps is 451
    numTimeSteps = 451
    sumstage = np.nan * np.ones(numTimeSteps)
    stage_g5 = np.nan * np.ones(numTimeSteps)
    stage_g7 = np.nan * np.ones(numTimeSteps)
    stage_g9 = np.nan * np.ones(numTimeSteps)
    stage_bc = np.nan * np.ones(numTimeSteps)
    yieldstep = 0.05
    finaltime = (numTimeSteps - 1) * yieldstep
    for t in domain.evolve(yieldstep=yieldstep, finaltime=finaltime):
        # domain.write_time()

        # stage [=height of water]
        stage = domain.quantities['stage'].centroid_values[v]
        stage_g5[k] = domain.quantities['stage'].centroid_values[g5_id]
        stage_g7[k] = domain.quantities['stage'].centroid_values[g7_id]
        stage_g9[k] = domain.quantities['stage'].centroid_values[g9_id]
        stage_bc[k] = domain.quantities['stage'].centroid_values[bc_id]
        # averaging for smoothness
        sumstage[k] = np.sum(stage)
        # k is time
        k += 1

    # number of triangles which are active for the designated runup area
    numActiveTriangles = anuga.collect_value(np.count_nonzero(v))
    averageStage = sumstage / numActiveTriangles
    # normalizing to zero level
    # averageStage -= averageStage[0]

    return [averageStage, stage_g5, stage_g7, stage_g9, stage_bc]