Esempio n. 1
0
def shockbubble(use_petsc=False,outdir='./_output',solver_type='classic'):
    """
    Solve the Euler equations of compressible fluid dynamics.
    This example involves a bubble of dense gas that is impacted by a shock.
    """
    from clawpack import riemann

    if use_petsc:
        import clawpack.petclaw as pyclaw
    else:
        from clawpack import pyclaw

    if solver_type=='sharpclaw':
        solver = pyclaw.SharpClawSolver2D(riemann.euler_5wave_2D)
        solver.dq_src=dq_Euler_radial
        solver.weno_order=5
        solver.lim_type=2
    else:
        solver = pyclaw.ClawSolver2D(riemann.euler_5wave_2D)
        solver.dimensional_split = 0
        solver.transverse_waves = 2
        solver.limiters = [4,4,4,4,2]
        solver.step_source=step_Euler_radial

    solver.bc_lower[0]=pyclaw.BC.custom
    solver.bc_upper[0]=pyclaw.BC.extrap
    solver.bc_lower[1]=pyclaw.BC.wall
    solver.bc_upper[1]=pyclaw.BC.extrap

    #Aux variable in ghost cells doesn't matter
    solver.aux_bc_lower[0]=pyclaw.BC.extrap
    solver.aux_bc_upper[0]=pyclaw.BC.extrap
    solver.aux_bc_lower[1]=pyclaw.BC.extrap
    solver.aux_bc_upper[1]=pyclaw.BC.extrap

    # Initialize domain
    mx=160; my=40
    x = pyclaw.Dimension('x',0.0,2.0,mx)
    y = pyclaw.Dimension('y',0.0,0.5,my)
    domain = pyclaw.Domain([x,y])
    num_eqn = 5
    num_aux=1
    state = pyclaw.State(domain,num_eqn,num_aux)

    state.problem_data['gamma']= gamma
    state.problem_data['gamma1']= gamma1

    qinit(state)
    auxinit(state)

    solver.user_bc_lower=shockbc

    claw = pyclaw.Controller()
    claw.tfinal = 0.75
    claw.solution = pyclaw.Solution(state,domain)
    claw.solver = solver
    claw.num_output_times = 10
    claw.outdir = outdir

    return claw
Esempio n. 2
0
def setup(use_petsc=False, outdir='./_output', solver_type='classic'):
    """
    Example python script for solving the 2d advection equation.
    """
    from clawpack import riemann

    if use_petsc:
        import clawpack.petclaw as pyclaw
    else:
        from clawpack import pyclaw

    if solver_type == 'classic':
        solver = pyclaw.ClawSolver2D(riemann.advection_2D)
        solver.dimensional_split = 1
        solver.limiters = pyclaw.limiters.tvd.vanleer
    elif solver_type == 'sharpclaw':
        solver = pyclaw.SharpClawSolver2D(riemann.advection_2D)

    solver.bc_lower[0] = pyclaw.BC.periodic
    solver.bc_upper[0] = pyclaw.BC.periodic
    solver.bc_lower[1] = pyclaw.BC.periodic
    solver.bc_upper[1] = pyclaw.BC.periodic

    solver.cfl_max = 1.0
    solver.cfl_desired = 0.9

    #===========================================================================
    # Initialize domain, then initialize the solution associated to the domain and
    # finally initialize aux array
    #===========================================================================

    # Domain:
    mx = 50
    my = 50
    x = pyclaw.Dimension('x', 0.0, 1.0, mx)
    y = pyclaw.Dimension('y', 0.0, 1.0, my)
    domain = pyclaw.Domain([x, y])

    num_eqn = 1
    state = pyclaw.State(domain, num_eqn)

    state.problem_data['u'] = 0.5  # Parameters (global auxiliary variables)
    state.problem_data['v'] = 1.0

    # Initial solution
    # ================
    qinit(state)  # This function is defined above

    #===========================================================================
    # Set up controller and controller parameters
    #===========================================================================
    claw = pyclaw.Controller()
    claw.tfinal = 2.0
    claw.solution = pyclaw.Solution(state, domain)
    claw.solver = solver
    claw.outdir = outdir
    claw.setplot = setplot
    claw.keep_copy = True

    return claw
def setup(use_petsc=False,solver_type='classic', outdir='_output', kernel_language='Fortran',
        disable_output=False, mx=320, my=80, tfinal=0.6, num_output_times = 10):
    if use_petsc:
        import clawpack.petclaw as pyclaw
    else:
        from clawpack import pyclaw

    if solver_type=='sharpclaw':
        solver = pyclaw.SharpClawSolver2D(riemann.euler_5wave_2D)
        solver.dq_src = dq_Euler_radial
        solver.weno_order = 5
        solver.lim_type   = 2
    else:
        solver = pyclaw.ClawSolver2D(riemann.euler_5wave_2D)
        solver.step_source = step_Euler_radial
        solver.source_split = 1
        solver.limiters = [4,4,4,4,2]
        solver.cfl_max = 0.5
        solver.cfl_desired = 0.45

    x = pyclaw.Dimension(0.0,2.0,mx,name='x')
    y = pyclaw.Dimension(0.0,0.5,my,name='y')
    domain = pyclaw.Domain([x,y])

    num_aux=1
    state = pyclaw.State(domain,num_eqn,num_aux)
    state.problem_data['gamma']= gamma

    qinit(state)
    auxinit(state)

    solver.user_bc_lower = incoming_shock

    solver.bc_lower[0]=pyclaw.BC.custom
    solver.bc_upper[0]=pyclaw.BC.extrap
    solver.bc_lower[1]=pyclaw.BC.wall
    solver.bc_upper[1]=pyclaw.BC.extrap
    #Aux variable in ghost cells doesn't matter
    solver.aux_bc_lower[0]=pyclaw.BC.extrap
    solver.aux_bc_upper[0]=pyclaw.BC.extrap
    solver.aux_bc_lower[1]=pyclaw.BC.extrap
    solver.aux_bc_upper[1]=pyclaw.BC.extrap

    claw = pyclaw.Controller()
    claw.solution = pyclaw.Solution(state,domain)
    claw.solver = solver

    claw.keep_copy = True
    if disable_output:
        claw.output_format = None
    claw.tfinal = tfinal
    claw.num_output_times = num_output_times
    claw.outdir = outdir
    claw.setplot = setplot

    return claw
Esempio n. 4
0
def kpp(use_petsc=False,
        iplot=False,
        htmlplot=False,
        outdir='./_output',
        solver_type='classic'):
    """
    Example python script for solving the 2d KPP equations.
    """

    if use_petsc:
        import clawpack.petclaw as pyclaw
    else:
        from clawpack import pyclaw

    if solver_type == 'sharpclaw':
        solver = pyclaw.SharpClawSolver2D()
    else:
        solver = pyclaw.ClawSolver2D()

    from clawpack import riemann
    solver.rp = riemann.rp2_kpp

    solver.num_waves = 1
    solver.bc_lower[0] = pyclaw.BC.extrap
    solver.bc_upper[0] = pyclaw.BC.extrap
    solver.bc_lower[1] = pyclaw.BC.extrap
    solver.bc_upper[1] = pyclaw.BC.extrap

    # Initialize domain
    mx = 200
    my = 200
    x = pyclaw.Dimension('x', -2.0, 2.0, mx)
    y = pyclaw.Dimension('y', -2.0, 2.0, my)
    domain = pyclaw.Domain([x, y])
    num_eqn = 1
    state = pyclaw.State(domain, num_eqn)

    qinit(state)

    solver.dimensional_split = 1
    solver.cfl_max = 1.0
    solver.cfl_desired = 0.9
    solver.num_waves = 2
    solver.limiters = pyclaw.limiters.tvd.minmod

    claw = pyclaw.Controller()
    claw.tfinal = 1.0
    claw.solution = pyclaw.Solution(state, domain)
    claw.solver = solver
    claw.num_output_times = 10

    # Solve
    status = claw.run()

    if htmlplot: pyclaw.plot.html_plot(outdir=outdir)
    if iplot: pyclaw.plot.interactive_plot(outdir=outdir)
Esempio n. 5
0
    def __init__(self, shape=None, mx=160, my=40, use_petsc=False, **kwargs):

        super(PFASSTShockBubble, self).__init__()

        if use_petsc:
            import clawpack.petclaw as pyclaw
        else:
            import clawpack.pyclaw as pyclaw

        import clawpack.riemann as riemann

        solver = pyclaw.SharpClawSolver2D()
        solver.dq_src = dq_Euler_radial
        solver.weno_order = 5
        solver.lim_type = 2

        solver.rp = riemann.rp2_euler_5wave
        solver.cfl_max = 0.5
        solver.cfl_desired = 0.45
        solver.num_waves = 5
        solver.bc_lower[0] = pyclaw.BC.custom
        solver.bc_upper[0] = pyclaw.BC.extrap
        solver.bc_lower[1] = pyclaw.BC.wall
        solver.bc_upper[1] = pyclaw.BC.extrap

        solver.aux_bc_lower[0] = pyclaw.BC.extrap
        solver.aux_bc_upper[0] = pyclaw.BC.extrap
        solver.aux_bc_lower[1] = pyclaw.BC.extrap
        solver.aux_bc_upper[1] = pyclaw.BC.extrap

        # initialize domain
        x = pyclaw.Dimension('x', 0.0, 2.0, mx)
        y = pyclaw.Dimension('y', 0.0, 0.5, my)
        domain = pyclaw.Domain([x, y])
        state = pyclaw.State(domain, 5, 1)

        state.problem_data['gamma'] = gamma
        state.problem_data['gamma1'] = gamma1

        qinit(state)
        auxinit(state)

        solver.user_bc_lower = shockbc

        solution = pyclaw.Solution(state, domain)

        solver.setup(solution)

        self.solution = solution
        self.solver = solver
        self.state = state

        self.shape = (5 * mx * my, )
        self.size = 5 * mx * my
        self.qshape = (5, mx, my)
Esempio n. 6
0
def setup(use_petsc=False, outdir='./_output', solver_type='classic'):

    if use_petsc:
        import clawpack.petclaw as pyclaw
    else:
        from clawpack import pyclaw

    if solver_type == 'classic':
        solver = pyclaw.ClawSolver2D(riemann.advection_2D)
        solver.dimensional_split = 1
        solver.limiters = pyclaw.limiters.tvd.vanleer
    elif solver_type == 'sharpclaw':
        solver = pyclaw.SharpClawSolver2D(riemann.advection_2D)

    solver.bc_lower[0] = pyclaw.BC.periodic
    solver.bc_upper[0] = pyclaw.BC.periodic
    solver.bc_lower[1] = pyclaw.BC.periodic
    solver.bc_upper[1] = pyclaw.BC.periodic

    solver.cfl_max = 1.0
    solver.cfl_desired = 0.9

    # Domain:
    mx = 50
    my = 50
    x = pyclaw.Dimension(0.0, 1.0, mx, name='x')
    y = pyclaw.Dimension(0.0, 1.0, my, name='y')
    domain = pyclaw.Domain([x, y])

    num_eqn = 1
    state = pyclaw.State(domain, num_eqn)

    state.problem_data['u'] = 0.5  # Advection velocity
    state.problem_data['v'] = 1.0

    qinit(state)

    claw = pyclaw.Controller()
    claw.tfinal = 2.0
    claw.solution = pyclaw.Solution(state, domain)
    claw.solver = solver
    claw.outdir = outdir
    claw.setplot = setplot
    claw.keep_copy = True

    return claw
Esempio n. 7
0
def setup(use_petsc=False, outdir='./_output', solver_type='classic'):
    if use_petsc:
        import clawpack.petclaw as pyclaw
    else:
        from clawpack import pyclaw

    if solver_type == 'classic':
        solver = pyclaw.ClawSolver2D(riemann.shallow_roe_with_efix_2D)
        solver.limiters = pyclaw.limiters.tvd.MC
        solver.dimensional_split = 1
    elif solver_type == 'sharpclaw':
        solver = pyclaw.SharpClawSolver2D(riemann.shallow_roe_with_efix_2D)

    solver.bc_lower[0] = pyclaw.BC.extrap
    solver.bc_upper[0] = pyclaw.BC.wall
    solver.bc_lower[1] = pyclaw.BC.extrap
    solver.bc_upper[1] = pyclaw.BC.wall

    # Domain:
    xlower = -2.5
    xupper = 2.5
    mx = 150
    ylower = -2.5
    yupper = 2.5
    my = 150
    x = pyclaw.Dimension('x', xlower, xupper, mx)
    y = pyclaw.Dimension('y', ylower, yupper, my)
    domain = pyclaw.Domain([x, y])

    state = pyclaw.State(domain, solver.num_eqn)

    # Gravitational constant
    state.problem_data['grav'] = 1.0

    qinit(state)

    claw = pyclaw.Controller()
    claw.tfinal = 2.5
    claw.solution = pyclaw.Solution(state, domain)
    claw.solver = solver
    claw.outdir = outdir
    claw.num_output_times = 10
    claw.setplot = setplot
    claw.keep_copy = True

    return claw
Esempio n. 8
0
def setup(use_petsc=False, outdir='./_output', solver_type='classic'):
    """
    Example python script for solving the 2d KPP equations.
    """
    from clawpack import riemann

    if use_petsc:
        import clawpack.petclaw as pyclaw
    else:
        from clawpack import pyclaw

    if solver_type == 'sharpclaw':
        solver = pyclaw.SharpClawSolver2D(riemann.kpp_2D)
    else:
        solver = pyclaw.ClawSolver2D(riemann.kpp_2D)

    solver.bc_lower[0] = pyclaw.BC.extrap
    solver.bc_upper[0] = pyclaw.BC.extrap
    solver.bc_lower[1] = pyclaw.BC.extrap
    solver.bc_upper[1] = pyclaw.BC.extrap

    # Initialize domain
    mx = 200
    my = 200
    x = pyclaw.Dimension('x', -2.0, 2.0, mx)
    y = pyclaw.Dimension('y', -2.0, 2.0, my)
    domain = pyclaw.Domain([x, y])
    state = pyclaw.State(domain, solver.num_eqn)

    qinit(state)

    solver.dimensional_split = 1
    solver.cfl_max = 1.0
    solver.cfl_desired = 0.9
    solver.limiters = pyclaw.limiters.tvd.minmod

    claw = pyclaw.Controller()
    claw.tfinal = 1.0
    claw.solution = pyclaw.Solution(state, domain)
    claw.solver = solver
    claw.num_output_times = 10
    claw.setplot = setplot
    claw.keep_copy = True

    return claw
Esempio n. 9
0
def setup(use_petsc=False, outdir='./_output', solver_type='classic'):

    if use_petsc:
        import clawpack.petclaw as pyclaw
    else:
        from clawpack import pyclaw

    if solver_type == 'sharpclaw':
        solver = pyclaw.SharpClawSolver2D(riemann.kpp_2D)
    else:
        solver = pyclaw.ClawSolver2D(riemann.kpp_2D)
        solver.dimensional_split = 1
        solver.cfl_max = 1.0
        solver.cfl_desired = 0.9
        solver.limiters = pyclaw.limiters.tvd.minmod

    solver.bc_lower[0] = pyclaw.BC.extrap
    solver.bc_upper[0] = pyclaw.BC.extrap
    solver.bc_lower[1] = pyclaw.BC.extrap
    solver.bc_upper[1] = pyclaw.BC.extrap

    # Initialize domain
    mx = 200
    my = 200
    x = pyclaw.Dimension(-2.0, 2.0, mx, name='x')
    y = pyclaw.Dimension(-2.0, 2.0, my, name='y')
    domain = pyclaw.Domain([x, y])
    state = pyclaw.State(domain, solver.num_eqn)

    # Initial data
    X, Y = state.grid.p_centers
    r = np.sqrt(X**2 + Y**2)
    state.q[0, :, :] = 0.25 * np.pi + 3.25 * np.pi * (r <= 1.0)

    claw = pyclaw.Controller()
    claw.tfinal = 1.0
    claw.solution = pyclaw.Solution(state, domain)
    claw.solver = solver
    claw.setplot = setplot
    claw.keep_copy = True

    return claw
Esempio n. 10
0
def shockbubble(use_petsc=False,
                kernel_language='Fortran',
                solver_type='classic',
                iplot=False,
                htmlplot=False,
                outdir='_output',
                disable_output=False):
    """
    Solve the Euler equations of compressible fluid dynamics.
    This example involves a bubble of dense gas that is impacted by a shock.
    """

    if use_petsc:
        import clawpack.petclaw as pyclaw
    else:
        from clawpack import pyclaw

    if kernel_language != 'Fortran':
        raise Exception(
            'Unrecognized value of kernel_language for Euler Shockbubble')

    if solver_type == 'sharpclaw':
        solver = pyclaw.SharpClawSolver2D()
        solver.dq_src = dq_Euler_radial
        solver.weno_order = 5
        solver.lim_type = 2
    else:
        solver = pyclaw.ClawSolver2D()
        solver.limiters = [4, 4, 4, 4, 2]
        solver.step_source = step_Euler_radial

    # Initialize domain
    mx = 160
    my = 40
    x = pyclaw.Dimension('x', 0.0, 2.0, mx)
    y = pyclaw.Dimension('y', 0.0, 0.5, my)
    domain = pyclaw.Domain([x, y])
    num_eqn = 5
    num_aux = 1
    state = pyclaw.State(domain, num_eqn, num_aux)

    state.problem_data['gamma'] = gamma
    state.problem_data['gamma1'] = gamma1

    tfinal = 0.2

    qinit(state)
    auxinit(state)
    initial_solution = pyclaw.Solution(state, domain)

    from clawpack import riemann
    solver.rp = riemann.rp2_euler_5wave
    solver.cfl_max = 0.5
    solver.cfl_desired = 0.45
    solver.num_waves = 5
    solver.dt_initial = 0.005
    solver.user_bc_lower = shockbc
    solver.source_split = 1
    solver.bc_lower[0] = pyclaw.BC.custom
    solver.bc_upper[0] = pyclaw.BC.extrap
    solver.bc_lower[1] = pyclaw.BC.wall
    solver.bc_upper[1] = pyclaw.BC.extrap
    #Aux variable in ghost cells doesn't matter
    solver.aux_bc_lower[0] = pyclaw.BC.extrap
    solver.aux_bc_upper[0] = pyclaw.BC.extrap
    solver.aux_bc_lower[1] = pyclaw.BC.extrap
    solver.aux_bc_upper[1] = pyclaw.BC.extrap

    claw = pyclaw.Controller()
    claw.keep_copy = True
    if disable_output:
        claw.output_format = None
    # The output format MUST be set to petsc!
    claw.tfinal = tfinal
    claw.solution = initial_solution
    claw.solver = solver
    claw.num_output_times = 1
    claw.outdir = outdir

    # Solve
    status = claw.run()

    if htmlplot: pyclaw.plot.html_plot(file_format=claw.output_format)
    if iplot: pyclaw.plot.interactive_plot(file_format=claw.output_format)

    return claw.frames[claw.num_output_times].state
Esempio n. 11
0
def psystem2D(iplot=False,kernel_language='Fortran',htmlplot=False,
              outdir='./_output',solver_type='classic',
              disable_output=False):

    """
    Solve the p-system in 2D with variable coefficients
    """
    ####################################
    ######### MAIN PARAMETERS ##########
    ####################################
    # Domain
    x_lower=0.0; x_upper=200.00
    y_lower=0.0; y_upper=1.0
    # cells per layer
    Nx=64
    Ny=256
    mx=(x_upper-x_lower)*Nx; my=(y_upper-y_lower)*Ny
    # Initial condition parameters
    A=10.
    x0=0.0 # Center of initial perturbation
    y0=0.25 # Center of initial perturbation
    varx=5.0; vary=5.0 # Width of initial perturbation

    # Boundary conditions
    bc_x_lower=pyclaw.BC.wall; bc_x_upper=pyclaw.BC.extrap
    bc_y_lower=pyclaw.BC.periodic; bc_y_upper=pyclaw.BC.periodic

    #change x BCs to periodic
    change_BCs=1
    t_change_BCs=50

    # Turning off 1st half of the domain. Useful in rect domains
    turnZero_half_2D=1 #flag
    t_turnZero=50
    
    tfinal = 1000
    num_output_times = 1000

    # restart options
    restart_from_frame = 670

    if solver_type=='classic':
        solver = pyclaw.ClawSolver2D()
    elif solver_type=='sharpclaw':
        solver = pyclaw.SharpClawSolver2D()

    if kernel_language != 'Fortran':
        raise Exception('Unrecognized value of kernel_language for 2D psystem')

    from clawpack import riemann
    solver.rp = riemann.rp2_psystem

    solver.num_waves = 2
    solver.limiters = pyclaw.limiters.tvd.MC

    solver.bc_lower[0]=bc_x_lower
    solver.bc_upper[0]=bc_x_upper
    solver.bc_lower[1]=bc_y_lower
    solver.bc_upper[1]=bc_y_upper
    solver.aux_bc_lower[0]=bc_x_lower
    solver.aux_bc_upper[0]=bc_x_upper
    solver.aux_bc_lower[1]=bc_y_lower
    solver.aux_bc_upper[1]=bc_y_upper

    solver.fwave = True
    solver.before_step = b4step
    if solver_type=='classic':
        solver.cfl_max = 0.45
        solver.cfl_desired = 0.4
        solver.dimensional_split=False
    elif solver_type=='sharpclaw':
        solver.cfl_max = 2.5
        solver.cfl_desired = 2.45
        
    #controller
    claw = pyclaw.Controller()
    claw.tfinal = tfinal
    claw.solver = solver
    claw.outdir = outdir
    claw.num_output_times = num_output_times

    if restart_from_frame is not None:
        claw.solution = pyclaw.Solution(restart_from_frame, file_format='petsc',read_aux=False)
        claw.solution.state.mp = 1
        claw.solution.state.mF = 1
        grid = claw.solution.domain.grid
        claw.solution.state.aux = setaux(grid.x.centers,grid.y.centers)
        #claw.num_output_times = num_output_times - restart_from_frame 
        claw.start_frame = restart_from_frame
    else:
        ####################################
        ####################################
        ####################################
        #Creation of Domain
        x = pyclaw.Dimension('x',x_lower,x_upper,mx)
        y = pyclaw.Dimension('y',y_lower,y_upper,my)
        domain = pyclaw.Domain([x,y])
        num_eqn = 3
        num_aux = 4
        state = pyclaw.State(domain,num_eqn,num_aux)
        state.mF = 1
        #Set global parameters
        state.problem_data = {}
        state.problem_data['turnZero_half_2D'] = turnZero_half_2D
        state.problem_data['t_turnZero'] = t_turnZero
        state.problem_data['change_BCs'] = change_BCs
        state.problem_data['t_change_BCs'] = t_change_BCs
        state.mp = 1

        grid = state.grid
        state.aux = setaux(grid.x.centers,grid.y.centers)
        #Initial condition
        qinit(state,A,x0,y0,varx,vary)

        claw.solution = pyclaw.Solution(state,domain)
        claw.num_output_times = num_output_times

    claw.compute_p = compute_p
    if disable_output:
        claw.output_format = None
    claw.compute_F = compute_F
    claw.solution.state.keep_gauges = True
    claw.solution.state.grid.add_gauges([[25.0,0.75],[50.0,0.75],[75.0,0.75],[25.0,1.25],[50.0,1.25],[75.0,1.25]])
    solver.compute_gauge_values = gauge_pfunction
    claw.write_aux_init = False

    #Solve
    status = claw.run()

    if iplot:    pyclaw.plot.interactive_plot()
    if htmlplot: pyclaw.plot.html_plot()

    return claw.solution.state
Esempio n. 12
0
def shockbubble(use_petsc=False, solver_type='sharpclaw', kernel_language='Fortran',
                dt=0.001, tfinal=0.02, outdir='test', restart=False):
    """Solve the Euler equations of compressible fluid dynamics.

    This example involves a bubble of dense gas that is impacted by a
    shock.

    """

    from clawpack import riemann

    if use_petsc:
        import clawpack.petclaw as pyclaw
    else:
        from clawpack import pyclaw

    if kernel_language != 'Fortran':
        raise Exception('Unrecognized value of kernel_language for Euler Shockbubble')

    if solver_type=='sharpclaw':
        solver = pyclaw.SharpClawSolver2D()
        solver.dq_src=dq_Euler_radial
        solver.weno_order=5
        solver.lim_type=2
    else:
        solver = pyclaw.ClawSolver2D()
        solver.limiters = [4,4,4,4,2]
        solver.step_source=step_Euler_radial
        solver.source_split = 1

    solver.rp          = riemann.rp2_euler_5wave
    solver.cfl_max     = 0.5
    solver.cfl_desired = 0.45
    solver.num_waves   = 5
    solver.dt_initial  = 0.005

    solver.user_bc_lower = shockbc
    solver.bc_lower[0] = pyclaw.BC.custom
    solver.bc_upper[0] = pyclaw.BC.extrap
    solver.bc_lower[1] = pyclaw.BC.wall
    solver.bc_upper[1] = pyclaw.BC.extrap

    # aux variable in ghost cells doesn't matter
    solver.aux_bc_lower[0] = pyclaw.BC.extrap
    solver.aux_bc_upper[0] = pyclaw.BC.extrap
    solver.aux_bc_lower[1] = pyclaw.BC.extrap
    solver.aux_bc_upper[1] = pyclaw.BC.extrap

    # initial condition or restart
    if restart:

        initial_solution = pyclaw.Solution(1, path=restart)
        initial_solution.t = 0.0

        for state in initial_solution.states:
            state.problem_data['gamma'] = gamma
            state.problem_data['gamma1'] = gamma1
            auxinit(state)

    else:

        mx, my = 160, 40
        x = pyclaw.Dimension('x', 0.0, 2.0, mx)
        y = pyclaw.Dimension('y', 0.0, 0.5, my)
        num_eqn = 5
        num_aux = 1
        
        domain  = pyclaw.Domain([x, y])
        state   = pyclaw.State(domain, num_eqn, num_aux)

        state.problem_data['gamma']  = gamma
        state.problem_data['gamma1'] = gamma1

        auxinit(state)
        qinit(state)
        
        initial_solution = pyclaw.Solution(state, domain)


    solver.dt_variable = False
    solver.dt_initial  = dt
    solver.max_steps   = 1e9

    claw = pyclaw.Controller()
    claw.keep_copy = True
    claw.tfinal    = tfinal
    claw.solution  = initial_solution
    claw.solver    = solver
    claw.outdir    = outdir
    claw.num_output_times = int(tfinal/dt)

    # Solve
    status = claw.run()

    return claw.frames[claw.num_output_times].state
Esempio n. 13
0
def advection2D(iplot=False,
                use_petsc=False,
                htmlplot=False,
                outdir='./_output',
                solver_type='classic'):
    """
    Example python script for solving the 2d advection equation.
    """
    #===========================================================================
    # Import libraries
    #===========================================================================
    if use_petsc:
        import clawpack.petclaw as pyclaw
    else:
        from clawpack import pyclaw

    #===========================================================================
    # Setup solver and solver parameters
    #===========================================================================
    if solver_type == 'classic':
        solver = pyclaw.ClawSolver2D()
        solver.dimensional_split = 1
        solver.limiters = pyclaw.limiters.tvd.vanleer
    elif solver_type == 'sharpclaw':
        solver = pyclaw.SharpClawSolver2D()

    from clawpack import riemann
    solver.rp = riemann.rp2_advection

    solver.bc_lower[0] = pyclaw.BC.periodic
    solver.bc_upper[0] = pyclaw.BC.periodic
    solver.bc_lower[1] = pyclaw.BC.periodic
    solver.bc_upper[1] = pyclaw.BC.periodic

    solver.num_waves = 1

    solver.cfl_max = 1.0
    solver.cfl_desired = 0.9

    #===========================================================================
    # Initialize domain, then initialize the solution associated to the domain and
    # finally initialize aux array
    #===========================================================================

    # Domain:
    mx = 50
    my = 50
    x = pyclaw.Dimension('x', 0.0, 1.0, mx)
    y = pyclaw.Dimension('y', 0.0, 1.0, my)
    domain = pyclaw.Domain([x, y])

    num_eqn = 1
    state = pyclaw.State(domain, num_eqn)

    state.problem_data['u'] = 0.5  # Parameters (global auxiliary variables)
    state.problem_data['v'] = 1.0

    # Initial solution
    # ================
    qinit(state)  # This function is defined above

    #===========================================================================
    # Set up controller and controller parameters
    #===========================================================================
    claw = pyclaw.Controller()
    claw.tfinal = 2.0
    claw.solution = pyclaw.Solution(state, domain)
    claw.solver = solver
    claw.outdir = outdir

    #===========================================================================
    # Solve the problem
    #===========================================================================
    status = claw.run()

    #===========================================================================
    # Plot results
    #===========================================================================
    if htmlplot: pyclaw.plot.html_plot(outdir=outdir)
    if iplot: pyclaw.plot.interactive_plot(outdir=outdir)

    return claw
Esempio n. 14
0
def setup(kernel_language='Fortran',
          use_petsc=False,
          outdir='./_output',
          solver_type='classic',
          time_integrator='SSP104',
          ptwise=False,
          disable_output=False):
    """
    Example python script for solving the 2d acoustics equations.
    """
    if use_petsc:
        from clawpack import petclaw as pyclaw
    else:
        from clawpack import pyclaw

    if solver_type == 'classic':
        if ptwise:
            solver = pyclaw.ClawSolver2D(riemann.acoustics_2D_ptwise)
        else:
            solver = pyclaw.ClawSolver2D(riemann.acoustics_2D)
        solver.dimensional_split = True
        solver.cfl_max = 0.5
        solver.cfl_desired = 0.45
        solver.limiters = pyclaw.limiters.tvd.MC
    elif solver_type == 'sharpclaw':
        solver = pyclaw.SharpClawSolver2D(riemann.acoustics_2D)
        solver.time_integrator = time_integrator
        if solver.time_integrator == 'SSP104':
            solver.cfl_max = 0.5
            solver.cfl_desired = 0.45
        elif solver.time_integrator == 'SSPMS32':
            solver.cfl_max = 0.2
            solver.cfl_desired = 0.16
        else:
            raise Exception(
                'CFL desired and CFL max have not been provided for the particular time integrator.'
            )

    solver.bc_lower[0] = pyclaw.BC.extrap
    solver.bc_upper[0] = pyclaw.BC.extrap
    solver.bc_lower[1] = pyclaw.BC.extrap
    solver.bc_upper[1] = pyclaw.BC.extrap

    mx = 100
    my = 100
    x = pyclaw.Dimension(-1.0, 1.0, mx, name='x')
    y = pyclaw.Dimension(-1.0, 1.0, my, name='y')
    domain = pyclaw.Domain([x, y])

    num_eqn = 3
    state = pyclaw.State(domain, num_eqn)

    rho = 1.0  # Material density
    bulk = 4.0  # Material bulk modulus
    cc = np.sqrt(bulk / rho)  # sound speed
    zz = rho * cc  # impedance
    state.problem_data['rho'] = rho
    state.problem_data['bulk'] = bulk
    state.problem_data['zz'] = zz
    state.problem_data['cc'] = cc

    solver.dt_initial = np.min(
        domain.grid.delta) / state.problem_data['cc'] * solver.cfl_desired

    qinit(state)

    claw = pyclaw.Controller()
    claw.keep_copy = True
    if disable_output:
        claw.output_format = None
    claw.solution = pyclaw.Solution(state, domain)
    claw.solver = solver
    claw.outdir = outdir
    claw.num_output_times = 10
    claw.tfinal = 0.12
    claw.setplot = setplot

    return claw
Esempio n. 15
0
def setup(kernel_language='Fortran',
          use_petsc=False,
          outdir='./_output',
          solver_type='classic',
          disable_output=False):
    """
    Example python script for solving the 2d acoustics equations.
    """
    from clawpack import riemann

    if use_petsc:
        import clawpack.petclaw as pyclaw
    else:
        from clawpack import pyclaw

    if solver_type == 'classic':
        solver = pyclaw.ClawSolver2D(riemann.vc_acoustics_2D)
        solver.dimensional_split = False
        solver.limiters = pyclaw.limiters.tvd.MC
    elif solver_type == 'sharpclaw':
        solver = pyclaw.SharpClawSolver2D(riemann.vc_acoustics_2D)

    solver.bc_lower[0] = pyclaw.BC.wall
    solver.bc_upper[0] = pyclaw.BC.extrap
    solver.bc_lower[1] = pyclaw.BC.wall
    solver.bc_upper[1] = pyclaw.BC.extrap
    solver.aux_bc_lower[0] = pyclaw.BC.wall
    solver.aux_bc_upper[0] = pyclaw.BC.extrap
    solver.aux_bc_lower[1] = pyclaw.BC.wall
    solver.aux_bc_upper[1] = pyclaw.BC.extrap

    # Initialize domain
    mx = 200
    my = 200
    x = pyclaw.Dimension('x', -1.0, 1.0, mx)
    y = pyclaw.Dimension('y', -1.0, 1.0, my)
    domain = pyclaw.Domain([x, y])

    num_eqn = 3
    num_aux = 2  # density, sound speed
    state = pyclaw.State(domain, num_eqn, num_aux)

    # Cell centers coordinates
    grid = state.grid
    Y, X = np.meshgrid(grid.y.centers, grid.x.centers)

    # Set aux arrays
    rhol = 4.0
    rhor = 1.0
    bulkl = 4.0
    bulkr = 4.0
    cl = np.sqrt(bulkl / rhol)
    cr = np.sqrt(bulkr / rhor)
    state.aux[0, :, :] = rhol * (X < 0.) + rhor * (X >= 0.)  # Density
    state.aux[1, :, :] = cl * (X < 0.) + cr * (X >= 0.)  # Sound speed

    # Set initial condition
    x0 = -0.5
    y0 = 0.
    r = np.sqrt((X - x0)**2 + (Y - y0)**2)
    width = 0.1
    rad = 0.25
    state.q[0, :, :] = (np.abs(r - rad) <= width) * (1. +
                                                     np.cos(np.pi *
                                                            (r - rad) / width))
    state.q[1, :, :] = 0.
    state.q[2, :, :] = 0.

    claw = pyclaw.Controller()
    claw.keep_copy = True
    if disable_output:
        claw.output_format = None
    claw.solution = pyclaw.Solution(state, domain)
    claw.solver = solver
    claw.outdir = outdir
    claw.num_output_times = 20
    claw.write_aux_init = True

    # Solve
    claw.tfinal = 0.6

    return claw
Esempio n. 16
0
def setup(kernel_language='Fortran',
          use_petsc=False,
          outdir='./_output',
          solver_type='classic',
          time_integrator='SSP104',
          lim_type=2,
          num_output_times=20,
          disable_output=False,
          num_cells=200):
    from clawpack import riemann

    if use_petsc:
        import clawpack.petclaw as pyclaw
    else:
        from clawpack import pyclaw

    riemann_solver = riemann.acoustics_mapped_2D

    if solver_type == 'classic':
        solver = pyclaw.ClawSolver2D(riemann_solver)
        solver.dimensional_split = False
        solver.limiters = pyclaw.limiters.tvd.MC
    elif solver_type == 'sharpclaw':
        solver = pyclaw.SharpClawSolver2D(riemann_solver)
        solver.time_integrator = time_integrator

    solver.bc_lower[0] = pyclaw.BC.custom
    solver.user_bc_lower = incoming_square_wave
    solver.bc_upper[0] = pyclaw.BC.extrap
    solver.bc_lower[1] = pyclaw.BC.extrap
    solver.bc_upper[1] = pyclaw.BC.extrap

    solver.aux_bc_lower[0] = pyclaw.BC.extrap
    solver.aux_bc_upper[0] = pyclaw.BC.extrap
    solver.aux_bc_lower[1] = pyclaw.BC.extrap
    solver.aux_bc_upper[1] = pyclaw.BC.extrap

    x = pyclaw.Dimension(0., 1.0, num_cells, name='x')
    y = pyclaw.Dimension(0., 1.0, num_cells, name='y')
    domain = pyclaw.Domain([x, y])

    num_eqn = 3
    num_aux = 9  # geometry (7), impedance, sound speed
    state = pyclaw.State(domain, num_eqn, num_aux)
    state.grid.mapc2p = inclusion_mapping

    a_x, a_y, length_left, b_x, b_y, length_bottom, area = compute_geometry(
        state.grid)

    state.aux[0, :, :] = a_x
    state.aux[1, :, :] = a_y
    state.aux[2, :, :] = length_left
    state.aux[3, :, :] = b_x
    state.aux[4, :, :] = b_y
    state.aux[5, :, :] = length_bottom
    state.aux[6, :, :] = area
    state.index_capa = 6  # aux[6,:,:] holds the capacity function

    grid = state.grid
    xp, yp = grid.p_centers
    state.aux[7, :, :] = 1.0  # Impedance
    state.aux[8, :, :] = 1.0  # Sound speed

    for i, circle in enumerate(circles):
        # Set impedance and sound speed in each inclusion
        radius = circle[0][0]
        x0, y0 = circle[1]
        distance = np.sqrt((xp - x0)**2 + (yp - y0)**2)
        in_circle = np.where(distance <= radius)
        state.aux[7][in_circle] = impedance[i]
        state.aux[8][in_circle] = sound_speed[i]

    # Set initial condition
    state.q[0, :, :] = 0.
    state.q[1, :, :] = 0.
    state.q[2, :, :] = 0.

    claw = pyclaw.Controller()
    claw.keep_copy = True
    if disable_output:
        claw.output_format = None
    claw.solution = pyclaw.Solution(state, domain)
    claw.solver = solver
    claw.outdir = outdir
    claw.tfinal = 0.9
    claw.num_output_times = num_output_times
    claw.write_aux_init = True
    claw.setplot = setplot
    if use_petsc:
        claw.output_options = {'format': 'binary'}

    return claw
Esempio n. 17
0
def setup(kernel_language='Fortran',
          use_petsc=False,
          outdir='./_output',
          solver_type='classic',
          disable_output=False,
          cells_per_layer=30,
          tfinal=18.):

    if use_petsc:
        import clawpack.petclaw as pyclaw
    else:
        from clawpack import pyclaw

    # material parameters
    KA = 1.
    rhoA = 1.
    KB = 4.
    rhoB = 4.
    stress_rel = 2

    # Domain
    x_lower = 0.25
    x_upper = 20.25
    y_lower = 0.25
    y_upper = 20.25
    # cells per layer
    mx = int((x_upper - x_lower) * cells_per_layer)
    my = int((y_upper - y_lower) * cells_per_layer)
    # Initial condition parameters
    initial_amplitude = 10.
    x0 = 0.25  # Center of initial perturbation
    y0 = 0.25  # Center of initial perturbation
    varx = 0.5
    vary = 0.5  # Width of initial perturbation

    num_output_times = 10

    if solver_type == 'classic':
        solver = pyclaw.ClawSolver2D(riemann.psystem_2D)
        solver.dimensional_split = False
        solver.cfl_max = 0.9
        solver.cfl_desired = 0.8
        solver.limiters = pyclaw.limiters.tvd.superbee
    elif solver_type == 'sharpclaw':
        solver = pyclaw.SharpClawSolver2D(riemann.psystem_2D)

    if kernel_language != 'Fortran':
        raise Exception('Unrecognized value of kernel_language for 2D psystem')

    # Boundary conditions
    solver.bc_lower[0] = pyclaw.BC.wall
    solver.bc_upper[0] = pyclaw.BC.extrap
    solver.bc_lower[1] = pyclaw.BC.wall
    solver.bc_upper[1] = pyclaw.BC.extrap
    solver.aux_bc_lower[0] = pyclaw.BC.wall
    solver.aux_bc_upper[0] = pyclaw.BC.extrap
    solver.aux_bc_lower[1] = pyclaw.BC.wall
    solver.aux_bc_upper[1] = pyclaw.BC.extrap

    solver.fwave = True
    solver.before_step = b4step

    #controller
    claw = pyclaw.Controller()
    claw.tfinal = tfinal
    claw.solver = solver
    claw.outdir = outdir

    # restart options
    restart_from_frame = None

    if restart_from_frame is None:
        x = pyclaw.Dimension(x_lower, x_upper, mx, name='x')
        y = pyclaw.Dimension(y_lower, y_upper, my, name='y')
        domain = pyclaw.Domain([x, y])
        num_eqn = 3
        num_aux = 4
        state = pyclaw.State(domain, num_eqn, num_aux)
        state.mF = 1
        state.mp = 1

        grid = state.grid
        state.aux = setaux(grid.x.centers, grid.y.centers, KA, KB, rhoA, rhoB,
                           stress_rel)
        #Initial condition
        qinit(state, initial_amplitude, x0, y0, varx, vary)

        claw.solution = pyclaw.Solution(state, domain)
        claw.num_output_times = num_output_times

    else:
        claw.solution = pyclaw.Solution(restart_from_frame,
                                        format='petsc',
                                        read_aux=False)
        claw.solution.state.mp = 1
        grid = claw.solution.domain.grid
        claw.solution.state.aux = setaux(grid.x.centers, grid.y.centers)
        claw.num_output_times = num_output_times - restart_from_frame
        claw.start_frame = restart_from_frame

    #claw.p_function = p_function
    if disable_output:
        claw.output_format = None
    claw.compute_F = total_energy
    claw.compute_p = compute_stress
    claw.write_aux_init = False

    grid.add_gauges([[0.25, 0.25], [17.85, 1.25], [3.25, 18.75],
                     [11.75, 11.75]])
    solver.compute_gauge_values = gauge_stress
    state.keep_gauges = True
    claw.setplot = setplot
    claw.keep_copy = True

    return claw
Esempio n. 18
0
def advection_annulus(use_petsc=False,
                      iplot=0,
                      htmlplot=False,
                      outdir='./_output',
                      solver_type='classic'):
    #===========================================================================
    # Import libraries
    #===========================================================================
    if use_petsc:
        import clawpack.petclaw as pyclaw
    else:
        from clawpack import pyclaw

    #===========================================================================
    # Setup solver and solver parameters
    #===========================================================================
    if solver_type == 'classic':
        solver = pyclaw.ClawSolver2D()
        solver.dimensional_split = 0
        solver.transverse_waves = 2
        solver.order = 2
    elif solver_type == 'sharpclaw':
        solver = pyclaw.SharpClawSolver2D()

    from clawpack import riemann
    solver.rp = riemann.rp2_vc_advection
    solver.num_waves = 1

    solver.bc_lower[0] = pyclaw.BC.extrap
    solver.bc_upper[0] = pyclaw.BC.extrap
    solver.bc_lower[1] = pyclaw.BC.periodic
    solver.bc_upper[1] = pyclaw.BC.periodic

    solver.aux_bc_lower[0] = pyclaw.BC.custom
    solver.aux_bc_upper[0] = pyclaw.BC.custom
    solver.user_aux_bc_lower = velocities_lower
    solver.user_aux_bc_upper = velocities_upper
    solver.aux_bc_lower[1] = pyclaw.BC.periodic
    solver.aux_bc_upper[1] = pyclaw.BC.periodic

    solver.dt_initial = 0.1
    solver.cfl_max = 0.5
    solver.cfl_desired = 0.2

    solver.limiters = pyclaw.limiters.tvd.vanleer

    #===========================================================================
    # Initialize domain and state, then initialize the solution associated to the
    # state and finally initialize aux array
    #===========================================================================
    # Domain:
    xlower = 0.2
    xupper = 1.0
    mx = 40

    ylower = 0.0
    yupper = np.pi * 2.0
    my = 120

    x = pyclaw.Dimension('x', xlower, xupper, mx)
    y = pyclaw.Dimension('y', ylower, yupper, my)
    domain = pyclaw.Domain([x, y])
    domain.grid.mapc2p = mapc2p_annulus  # Override default_mapc2p function implemented in geometry.py

    # State:
    num_eqn = 1  # Number of equations
    state = pyclaw.State(domain, num_eqn)

    # Set initial solution
    # ====================
    qinit(state, mx, my)  # This function is defined above

    # Set auxiliary array
    # ===================
    state.aux = setaux(state, mx, my)  # This function is defined above
    state.index_capa = 2

    #===========================================================================
    # Set up controller and controller parameters
    #===========================================================================
    claw = pyclaw.Controller()
    claw.keep_copy = False
    claw.output_style = 1
    claw.num_output_times = 10
    claw.tfinal = 1.0
    claw.solution = pyclaw.Solution(state, domain)
    claw.solver = solver
    claw.outdir = outdir

    #===========================================================================
    # Solve the problem
    #===========================================================================
    status = claw.run()

    #===========================================================================
    # Plot results
    #===========================================================================
    if htmlplot: pyclaw.plot.html_plot(outdir=outdir)
    if iplot: pyclaw.plot.interactive_plot(outdir=outdir)
Esempio n. 19
0
def acoustics2D(iplot=False,
                kernel_language='Fortran',
                htmlplot=False,
                use_petsc=False,
                outdir='./_output',
                solver_type='classic',
                disable_output=False):
    """
    Example python script for solving the 2d acoustics equations.
    """

    if use_petsc:
        from clawpack import petclaw as pyclaw
    else:
        from clawpack import pyclaw

    if solver_type == 'classic':
        solver = pyclaw.ClawSolver2D()
        solver.dimensional_split = True
    elif solver_type == 'sharpclaw':
        solver = pyclaw.SharpClawSolver2D()

    if kernel_language != 'Fortran':
        raise Exception(
            'Unrecognized value of kernel_language for 2D acoustics')

    from clawpack.riemann import rp2_acoustics
    solver.rp = rp2_acoustics

    solver.cfl_max = 0.5
    solver.cfl_desired = 0.45

    solver.num_waves = 2
    solver.limiters = pyclaw.limiters.tvd.MC

    solver.bc_lower[0] = pyclaw.BC.extrap
    solver.bc_upper[0] = pyclaw.BC.extrap
    solver.bc_lower[1] = pyclaw.BC.extrap
    solver.bc_upper[1] = pyclaw.BC.extrap

    # Initialize domain
    mx = 100
    my = 100
    x = pyclaw.Dimension('x', -1.0, 1.0, mx)
    y = pyclaw.Dimension('y', -1.0, 1.0, my)
    domain = pyclaw.Domain([x, y])

    num_eqn = 3
    state = pyclaw.State(domain, num_eqn)

    rho = 1.0
    bulk = 4.0
    cc = np.sqrt(bulk / rho)
    zz = rho * cc
    state.problem_data['rho'] = rho
    state.problem_data['bulk'] = bulk
    state.problem_data['zz'] = zz
    state.problem_data['cc'] = cc

    qinit(state)

    claw = pyclaw.Controller()
    claw.keep_copy = True
    if disable_output:
        claw.output_format = None
    claw.solution = pyclaw.Solution(state, domain)
    solver.dt_initial = np.min(
        domain.grid.delta) / state.problem_data['cc'] * solver.cfl_desired

    claw.solver = solver
    claw.outdir = outdir

    num_output_times = 10

    claw.num_output_times = num_output_times

    # Solve
    claw.tfinal = 0.12
    status = claw.run()

    if htmlplot:
        pyclaw.plot.html_plot(outdir=outdir, file_format=claw.output_format)
    if iplot:
        pyclaw.plot.interactive_plot(outdir=outdir,
                                     file_format=claw.output_format)

    return claw.frames[-1].state
Esempio n. 20
0
def setup(aux_time_dep=True,
          kernel_language='Fortran',
          use_petsc=False,
          outdir='./_output',
          solver_type='classic',
          time_integrator='SSP104',
          lim_type=2,
          disable_output=False,
          num_cells=(n_x, 1)):
    """
    Example python script for solving the 2d acoustics equations.
    """
    from clawpack import riemann

    if use_petsc:
        import clawpack.petclaw as pyclaw
    else:
        from clawpack import pyclaw

    if solver_type == 'classic':
        solver = pyclaw.ClawSolver2D(riemann.vc_acoustics_2D)
        solver.dimensional_split = False
        solver.limiters = pyclaw.limiters.tvd.MC
    elif solver_type == 'sharpclaw':
        solver = pyclaw.SharpClawSolver2D(riemann.vc_acoustics_2D)
        solver.time_integrator = time_integrator
        if time_integrator == 'SSPLMMk2':
            solver.lmm_steps = 3
            solver.cfl_max = 0.25
            solver.cfl_desired = 0.24

    solver.bc_lower[0] = pyclaw.BC.periodic
    solver.bc_upper[0] = pyclaw.BC.periodic
    solver.bc_lower[1] = pyclaw.BC.periodic
    solver.bc_upper[1] = pyclaw.BC.periodic
    solver.aux_bc_lower[0] = pyclaw.BC.periodic
    solver.aux_bc_upper[0] = pyclaw.BC.periodic
    solver.aux_bc_lower[1] = pyclaw.BC.periodic
    solver.aux_bc_upper[1] = pyclaw.BC.periodic

    #uses parameters initialized at the start of the code to define space size and resolution
    x = pyclaw.Dimension(ax, bx, num_cells[0], name='x')
    y = pyclaw.Dimension(ay, by, num_cells[1], name='y')
    domain = pyclaw.Domain([x, y])

    num_eqn = 3
    num_aux = 2  # For the electromagnetic case the auxiliary variables are mu and epsilon
    state = pyclaw.State(domain, num_eqn, num_aux)

    grid = state.grid
    X, Y = grid.p_centers

    #
    #    N_pl=1000
    #    X_pl,T_pl = np.mgrid[ax:bx:1000*1j, t_0:t_F:1000*1j];
    #    p_MG=plt.pcolor(X_pl,T_pl,f_u(X_pl,0.0,T_pl,c_1,c_2))
    #    plt.savefig("_plots/Checkerboard.png",dpi=1000)

    #    state.aux[0,:,:] = gamma/f_u(X,Y,0.0,c_1,c_2) # Density
    ##    state.aux[1,:,:] = f_u(X,Y,0.0,c_1  ,c_2  )    # Sound speed
    #    state.aux[1,:,:] = f_u(X,Y,0.0,c_1  ,c_2)    # Sound speed

    #sets initial material properties
    state.aux[0, :, :] = f_u(X, Y, 0.0, rho_1, rho_2)  # Density
    #    state.aux[1,:,:] = f_u(X,Y,0.0,c_1  ,c_2  )    # Sound speed
    state.aux[1, :, :] = f_u(X, Y, 0.0, c_1, c_2)  # Sound speed

    x0 = -0.5
    y0 = 0.
    r = np.sqrt((X - x0)**2 + (Y - y0)**
                2)  # calculates a radial distance to a specified point (x0,y0)
    width = 0.10
    rad = 0.25
    state.q[0, :, :] = f_bump(
        X, 0.0, 0.25)  # sets the initial condition along the x direction

    #use just one of these
    #for asymmetric initial condition
    state.q[1, :, :] = f_bump(X, 0.0, 0.25)
    #for less asymmetric initial condition
    #    state.q[1,:,:] = 0.5*f_bump(X,0.0,0.25)
    #for symmetric initial condition
    #    state.q[1,:,:] = 0.0

    state.q[2, :, :] = 0.0

    #!!Sets Local Material Properties State, outputs current wave state to buffer, calculates current energy and outputs it to CSV with current time step for plotting
    def DoBefore(solver, state):
        #TotEnergy = total_energy(state)

        #        state.aux[0,:,:] = f_u(X,Y,state.t,rho_1,rho_2)# Density
        ##        state.aux[1,:,:] = f_u(X,Y,state.t,c_1  ,c_2  ) # Sound speed
        #        state.aux[0,:,:] = gamma/f_u(X,Y,state.t,c_1  ,c_2  ) # Matching Impedances
        state.aux[0, :, :] = f_u(X, Y, state.t, rho_1, rho_2)  # Density
        state.aux[1, :, :] = f_u(X, Y, state.t, c_1, c_2)  # Sound speed
        #These must somehow differ from what is used to calculate energy later in add_plots
        #print '{0},{1}'.format(state.t, TotEnergy) #original output for CSV, moved to setplot so that this doesn't have to be done ten thousand times
        #Prevstep = state.q

    solver.before_step = DoBefore

    claw = pyclaw.Controller()
    claw.keep_copy = True
    if disable_output:
        claw.output_format = None
    claw.solution = pyclaw.Solution(state, domain)
    claw.solver = solver
    claw.outdir = outdir
    claw.tfinal = t_F
    claw.num_output_times = timeInterfaceNum * 50  #sets how many graphs are produced: this one allows scale-up to longer timescales when
    #outputting energy over time
    #    claw.num_output_times = 100 #sets how many graphs are produced
    claw.write_aux_init = True
    claw.write_aux = True
    claw.setplot = setplot
    if use_petsc:
        claw.output_options = {'format': 'binary'}

    return claw
Esempio n. 21
0
def setup(use_petsc=False,
          kernel_language='Fortran',
          solver_type='classic',
          outdir='_output',
          disable_output=False,
          mx=320,
          my=80,
          tfinal=0.6,
          num_output_times=10):
    """
    Solve the Euler equations of compressible fluid dynamics.
    This example involves a bubble of dense gas that is impacted by a shock.
    """
    from clawpack import riemann

    if use_petsc:
        import clawpack.petclaw as pyclaw
    else:
        from clawpack import pyclaw

    if kernel_language != 'Fortran':
        raise Exception(
            'Unrecognized value of kernel_language for Euler Shockbubble')

    if solver_type == 'sharpclaw':
        solver = pyclaw.SharpClawSolver2D(riemann.euler_5wave_2D)
        solver.dq_src = dq_Euler_radial
        solver.weno_order = 5
        solver.lim_type = 2
    else:
        solver = pyclaw.ClawSolver2D(riemann.euler_5wave_2D)
        solver.limiters = [4, 4, 4, 4, 2]
        solver.step_source = step_Euler_radial

    # Initialize domain
    x = pyclaw.Dimension('x', 0.0, 2.0, mx)
    y = pyclaw.Dimension('y', 0.0, 0.5, my)
    domain = pyclaw.Domain([x, y])

    num_aux = 1
    state = pyclaw.State(domain, solver.num_eqn, num_aux)
    state.problem_data['gamma'] = gamma
    state.problem_data['gamma1'] = gamma1

    qinit(state)
    auxinit(state)

    solver.cfl_max = 0.5
    solver.cfl_desired = 0.45
    solver.dt_initial = 0.005
    solver.user_bc_lower = shockbc
    solver.source_split = 1
    solver.bc_lower[0] = pyclaw.BC.custom
    solver.bc_upper[0] = pyclaw.BC.extrap
    solver.bc_lower[1] = pyclaw.BC.wall
    solver.bc_upper[1] = pyclaw.BC.extrap
    #Aux variable in ghost cells doesn't matter
    solver.aux_bc_lower[0] = pyclaw.BC.extrap
    solver.aux_bc_upper[0] = pyclaw.BC.extrap
    solver.aux_bc_lower[1] = pyclaw.BC.extrap
    solver.aux_bc_upper[1] = pyclaw.BC.extrap

    claw = pyclaw.Controller()
    claw.solution = pyclaw.Solution(state, domain)
    claw.solver = solver

    claw.keep_copy = True
    if disable_output:
        claw.output_format = None
    claw.tfinal = tfinal
    claw.num_output_times = num_output_times
    claw.outdir = outdir
    claw.setplot = setplot

    return claw
Esempio n. 22
0
def shallow2D(use_petsc=False,
              outdir='./_output',
              solver_type='classic',
              disable_output=False):
    #===========================================================================
    # Import libraries
    #===========================================================================
    import numpy as np
    import clawpack.peanoclaw as peanoclaw
    import clawpack.riemann as riemann

    if use_petsc:
        import clawpack.petclaw as pyclaw
    else:
        import clawpack.pyclaw as pyclaw

    #===========================================================================
    # Setup solver and solver parameters
    #===========================================================================
    subdivisionFactor = 6
    if solver_type == 'classic':
        solver = pyclaw.ClawSolver2D(riemann.shallow_roe_with_efix_2D)
        solver.limiters = pyclaw.limiters.tvd.MC
        solver.dimensional_split = 1
    elif solver_type == 'sharpclaw':
        solver = pyclaw.SharpClawSolver2D(riemann.shallow_roe_with_efix_2D)
    peanoSolver = peanoclaw.Solver(solver, (1. / 3.) / subdivisionFactor, init)

    solver.dt_initial = 1.0

    solver.bc_lower[0] = pyclaw.BC.wall
    solver.bc_upper[0] = pyclaw.BC.wall
    solver.bc_lower[1] = pyclaw.BC.wall
    solver.bc_upper[1] = pyclaw.BC.wall

    #===========================================================================
    # Initialize domain and state, then initialize the solution associated to the
    # state and finally initialize aux array
    #===========================================================================

    # Domain:
    from clawpack.pyclaw import geometry
    print(geometry.__file__)
    xlower = 0.0
    xupper = 1.0
    mx = subdivisionFactor
    ylower = 0.0
    yupper = 1.0
    my = subdivisionFactor
    x = pyclaw.Dimension('x', xlower, xupper, mx)
    y = pyclaw.Dimension('y', ylower, yupper, my)
    domain = geometry.Domain([x, y])

    num_eqn = 3  # Number of equations
    state = pyclaw.State(domain, num_eqn)

    grav = 1.0  # Parameter (global auxiliary variable)
    state.problem_data['grav'] = grav

    #===========================================================================
    # Set up controller and controller parameters
    #===========================================================================
    claw = pyclaw.Controller()
    claw.tfinal = 0.1
    claw.solution = peanoclaw.solution.Solution(state, domain)
    claw.solver = peanoSolver
    claw.outdir = outdir
    if disable_output:
        claw.output_format = None
    claw.num_output_times = 5

    return claw
Esempio n. 23
0
def shallow2D(use_petsc=False,
              iplot=0,
              htmlplot=False,
              outdir='./_output',
              solver_type='classic'):
    #===========================================================================
    # Import libraries
    #===========================================================================
    if use_petsc:
        import clawpack.petclaw as pyclaw
    else:
        from clawpack import pyclaw

    #===========================================================================
    # Setup solver and solver parameters
    #===========================================================================
    if solver_type == 'classic':
        solver = pyclaw.ClawSolver2D()
        solver.limiters = pyclaw.limiters.tvd.MC
        solver.dimensional_split = 1
    elif solver_type == 'sharpclaw':
        solver = pyclaw.SharpClawSolver2D()

    from clawpack import riemann
    solver.rp = riemann.rp2_shallow_roe_with_efix
    solver.num_waves = 3

    solver.bc_lower[0] = pyclaw.BC.extrap
    solver.bc_upper[0] = pyclaw.BC.wall
    solver.bc_lower[1] = pyclaw.BC.extrap
    solver.bc_upper[1] = pyclaw.BC.wall

    #===========================================================================
    # Initialize domain and state, then initialize the solution associated to the
    # state and finally initialize aux array
    #===========================================================================

    # Domain:
    xlower = -2.5
    xupper = 2.5
    mx = 150
    ylower = -2.5
    yupper = 2.5
    my = 150
    x = pyclaw.Dimension('x', xlower, xupper, mx)
    y = pyclaw.Dimension('y', ylower, yupper, my)
    domain = pyclaw.Domain([x, y])

    num_eqn = 3  # Number of equations
    state = pyclaw.State(domain, num_eqn)

    grav = 1.0  # Parameter (global auxiliary variable)
    state.problem_data['grav'] = grav

    # Initial solution
    # ================
    # Riemann states of the dam break problem
    damRadius = 0.5
    hl = 2.
    ul = 0.
    vl = 0.
    hr = 1.
    ur = 0.
    vr = 0.

    qinit(state, hl, ul, vl, hr, ur, vr,
          damRadius)  # This function is defined above

    #===========================================================================
    # Set up controller and controller parameters
    #===========================================================================
    claw = pyclaw.Controller()
    claw.tfinal = 2.5
    claw.solution = pyclaw.Solution(state, domain)
    claw.solver = solver
    claw.outdir = outdir
    claw.num_output_times = 10

    #===========================================================================
    # Solve the problem
    #===========================================================================
    status = claw.run()

    #===========================================================================
    # Plot results
    #===========================================================================
    if iplot:
        pyclaw.plot.interactive_plot(outdir=outdir,
                                     file_format=claw.output_format)
    if htmlplot:
        pyclaw.plot.html_plot(outdir=outdir, file_format=claw.output_format)
Esempio n. 24
0
def setup(kernel_language='Fortran',use_petsc=False,outdir='./_output',solver_type='classic',  disable_output=False):
    """
    Example python script for solving the 2d acoustics equations.
    """
    from clawpack import riemann
    if use_petsc:
        from clawpack import petclaw as pyclaw
    else:
        from clawpack import pyclaw

    if solver_type=='classic':
        solver=pyclaw.ClawSolver2D(riemann.acoustics_2D)
        solver.dimensional_split=True
    elif solver_type=='sharpclaw':
        solver=pyclaw.SharpClawSolver2D(riemann.acoustics_2D)

    solver.cfl_max = 0.5
    solver.cfl_desired = 0.45

    solver.limiters = pyclaw.limiters.tvd.MC

    solver.bc_lower[0]=pyclaw.BC.extrap
    solver.bc_upper[0]=pyclaw.BC.extrap
    solver.bc_lower[1]=pyclaw.BC.extrap
    solver.bc_upper[1]=pyclaw.BC.extrap

    # Initialize domain
    mx=100; my=100
    x = pyclaw.Dimension('x',-1.0,1.0,mx)
    y = pyclaw.Dimension('y',-1.0,1.0,my)
    domain = pyclaw.Domain([x,y])

    num_eqn = 3
    state = pyclaw.State(domain,num_eqn)

    rho = 1.0
    bulk = 4.0
    cc = np.sqrt(bulk/rho)
    zz = rho*cc
    state.problem_data['rho']= rho
    state.problem_data['bulk']=bulk
    state.problem_data['zz']= zz
    state.problem_data['cc']=cc

    qinit(state)

    claw = pyclaw.Controller()
    claw.keep_copy = True
    if disable_output:
        claw.output_format = None
    claw.solution = pyclaw.Solution(state,domain)
    solver.dt_initial=np.min(domain.grid.delta)/state.problem_data['cc']*solver.cfl_desired

    claw.solver = solver
    claw.outdir = outdir

    num_output_times = 10
    
    claw.num_output_times = num_output_times

    claw.tfinal = 0.12

    return claw
Esempio n. 25
0
def setup(kernel_language='Fortran',
          use_petsc=False,
          outdir='./_output',
          solver_type='classic',
          time_integrator='SSP104',
          lim_type=2,
          disable_output=False,
          num_cells=(200, 200)):
    """
    Example python script for solving the 2d acoustics equations.
    """
    from clawpack import riemann

    if use_petsc:
        import clawpack.petclaw as pyclaw
    else:
        from clawpack import pyclaw

    if solver_type == 'classic':
        solver = pyclaw.ClawSolver2D(riemann.vc_acoustics_2D)
        solver.dimensional_split = False
        solver.limiters = pyclaw.limiters.tvd.MC
    elif solver_type == 'sharpclaw':
        solver = pyclaw.SharpClawSolver2D(riemann.vc_acoustics_2D)
        solver.time_integrator = time_integrator
        if time_integrator == 'SSPMS32':
            solver.cfl_max = 0.25
            solver.cfl_desired = 0.24

    solver.bc_lower[0] = pyclaw.BC.wall
    solver.bc_upper[0] = pyclaw.BC.extrap
    solver.bc_lower[1] = pyclaw.BC.wall
    solver.bc_upper[1] = pyclaw.BC.extrap
    solver.aux_bc_lower[0] = pyclaw.BC.wall
    solver.aux_bc_upper[0] = pyclaw.BC.extrap
    solver.aux_bc_lower[1] = pyclaw.BC.wall
    solver.aux_bc_upper[1] = pyclaw.BC.extrap

    x = pyclaw.Dimension('x', -1.0, 1.0, num_cells[0])
    y = pyclaw.Dimension('y', -1.0, 1.0, num_cells[1])
    domain = pyclaw.Domain([x, y])

    num_eqn = 3
    num_aux = 2  # density, sound speed
    state = pyclaw.State(domain, num_eqn, num_aux)

    grid = state.grid
    X, Y = grid.p_centers

    rho_left = 4.0  # Density in left half
    rho_right = 1.0  # Density in right half
    bulk_left = 4.0  # Bulk modulus in left half
    bulk_right = 4.0  # Bulk modulus in right half
    c_left = np.sqrt(bulk_left / rho_left)  # Sound speed (left)
    c_right = np.sqrt(bulk_right / rho_right)  # Sound speed (right)
    state.aux[0, :, :] = rho_left * (X < 0.) + rho_right * (X >= 0.)  # Density
    state.aux[1, :, :] = c_left * (X < 0.) + c_right * (X >= 0.)  # Sound speed

    # Set initial condition
    x0 = -0.5
    y0 = 0.
    r = np.sqrt((X - x0)**2 + (Y - y0)**2)
    width = 0.1
    rad = 0.25
    state.q[0, :, :] = (np.abs(r - rad) <= width) * (1. +
                                                     np.cos(np.pi *
                                                            (r - rad) / width))
    state.q[1, :, :] = 0.
    state.q[2, :, :] = 0.

    claw = pyclaw.Controller()
    claw.keep_copy = True
    if disable_output:
        claw.output_format = None
    claw.solution = pyclaw.Solution(state, domain)
    claw.solver = solver
    claw.outdir = outdir
    claw.tfinal = 0.6
    claw.num_output_times = 20
    claw.write_aux_init = True
    claw.setplot = setplot
    if use_petsc:
        claw.output_options = {'format': 'binary'}

    return claw
Esempio n. 26
0
def setup(use_petsc=False,outdir='./_output',solver_type='classic'):
    from clawpack import riemann

    if use_petsc:
        import clawpack.petclaw as pyclaw
    else:
        from clawpack import pyclaw

    if solver_type == 'classic':
        solver = pyclaw.ClawSolver2D(riemann.vc_advection_2D)
        solver.dimensional_split = False
        solver.transverse_waves = 2
        solver.order = 2
    elif solver_type == 'sharpclaw':
        solver = pyclaw.SharpClawSolver2D(riemann.vc_advection_2D)

    solver.bc_lower[0] = pyclaw.BC.extrap
    solver.bc_upper[0] = pyclaw.BC.extrap
    solver.bc_lower[1] = pyclaw.BC.periodic
    solver.bc_upper[1] = pyclaw.BC.periodic

    solver.aux_bc_lower[0] = pyclaw.BC.custom
    solver.aux_bc_upper[0] = pyclaw.BC.custom
    solver.user_aux_bc_lower = ghost_velocities_lower
    solver.user_aux_bc_upper = ghost_velocities_upper
    solver.aux_bc_lower[1] = pyclaw.BC.periodic
    solver.aux_bc_upper[1] = pyclaw.BC.periodic

    solver.dt_initial = 0.1
    solver.cfl_max = 0.5
    solver.cfl_desired = 0.4

    solver.limiters = pyclaw.limiters.tvd.vanleer

    r_lower = 0.2
    r_upper = 1.0
    m_r = 40

    theta_lower = 0.0
    theta_upper = np.pi*2.0
    m_theta = 120

    r     = pyclaw.Dimension('r',    r_lower,r_upper,m_r)
    theta = pyclaw.Dimension('theta',theta_lower,theta_upper,m_theta)
    domain = pyclaw.Domain([r,theta])
    domain.grid.mapc2p = mapc2p_annulus

    num_eqn = 1
    state = pyclaw.State(domain,num_eqn)

    qinit(state)

    dx, dy = state.grid.delta
    p_corners = state.grid.p_edges
    state.aux = edge_velocities_and_area(p_corners[0],p_corners[1],dx,dy)
    state.index_capa = 2 # aux[2,:,:] holds the capacity function

    claw = pyclaw.Controller()
    claw.tfinal = 1.0
    claw.solution = pyclaw.Solution(state,domain)
    claw.solver = solver
    claw.outdir = outdir
    claw.setplot = setplot
    claw.keep_copy = True

    return claw
Esempio n. 27
0
def setup(use_petsc=False,outdir='./_output',solver_type='classic'):
    #===========================================================================
    # Import libraries
    #===========================================================================
    from clawpack import riemann

    if use_petsc:
        import clawpack.petclaw as pyclaw
    else:
        from clawpack import pyclaw

    #===========================================================================
    # Setup solver and solver parameters
    #===========================================================================
    if solver_type == 'classic':
        solver = pyclaw.ClawSolver2D(riemann.shallow_roe_with_efix_2D)
        solver.limiters = pyclaw.limiters.tvd.MC
        solver.dimensional_split=1
    elif solver_type == 'sharpclaw':
        solver = pyclaw.SharpClawSolver2D(riemann.shallow_roe_with_efix_2D)

    solver.bc_lower[0] = pyclaw.BC.extrap
    solver.bc_upper[0] = pyclaw.BC.wall
    solver.bc_lower[1] = pyclaw.BC.extrap
    solver.bc_upper[1] = pyclaw.BC.wall

    #===========================================================================
    # Initialize domain and state, then initialize the solution associated to the 
    # state and finally initialize aux array
    #===========================================================================

    # Domain:
    xlower = -2.5
    xupper = 2.5
    mx = 150
    ylower = -2.5
    yupper = 2.5
    my = 150
    x = pyclaw.Dimension('x',xlower,xupper,mx)
    y = pyclaw.Dimension('y',ylower,yupper,my)
    domain = pyclaw.Domain([x,y])

    state = pyclaw.State(domain,solver.num_eqn)

    grav = 1.0 # Parameter (global auxiliary variable)
    state.problem_data['grav'] = grav

    # Initial solution
    # ================
    # Riemann states of the dam break problem
    damRadius = 0.5
    hl = 2.
    ul = 0.
    vl = 0.
    hr = 1.
    ur = 0.
    vr = 0.
    
    qinit(state,hl,ul,vl,hr,ur,vr,damRadius) # This function is defined above

    #===========================================================================
    # Set up controller and controller parameters
    #===========================================================================
    claw = pyclaw.Controller()
    claw.tfinal = 2.5
    claw.solution = pyclaw.Solution(state,domain)
    claw.solver = solver
    claw.outdir = outdir
    claw.num_output_times = 10

    return claw
Esempio n. 28
0
def shallow2D(use_petsc=False,iplot=0,htmlplot=False,outdir='./_output',solver_type='classic',amr_type=None):
    #===========================================================================
    # Import libraries
    #===========================================================================
    from clawpack import riemann

    if use_petsc:
        import clawpack.petclaw as pyclaw
    else:
        from clawpack import pyclaw

    #===========================================================================
    # Setup solver and solver parameters
    #===========================================================================
    if solver_type == 'classic':
        solver = pyclaw.ClawSolver2D(riemann.shallow_roe_with_efix_2D)
        solver.limiters = pyclaw.limiters.tvd.MC
        solver.dimensional_split=1
    elif solver_type == 'sharpclaw':
        solver = pyclaw.SharpClawSolver2D(riemann.shallow_roe_with_efix_2D)

    solver.bc_lower[0] = pyclaw.BC.wall
    solver.bc_upper[0] = pyclaw.BC.wall
    solver.bc_lower[1] = pyclaw.BC.wall
    solver.bc_upper[1] = pyclaw.BC.wall

    #===========================================================================
    # Initialize domain and state, then initialize the solution associated to the 
    # state and finally initialize aux array
    #===========================================================================

    # resolution of each grid
    mgrid = 6

    # number of initial AMR grids in each dimension
    msubgrid = 9

    if amr_type is not None:
        m = mgrid
    else:
        # number of Domain grid cells expressed as the product of
        # grid resolution and the number of AMR sub-grids for
        # easy comparison between the two methods
        m = mgrid*msubgrid
    
    mx = m
    my = m

    # Domain:
    xlower = 0
    xupper = 1
    ylower = 0
    yupper = 1

    x = pyclaw.Dimension('x',xlower,xupper,mx)
    y = pyclaw.Dimension('y',ylower,yupper,my)
    domain = pyclaw.Domain([x,y])

    state = pyclaw.State(domain,solver.num_eqn)

    grav = 1.0 # Parameter (global auxiliary variable)
    state.problem_data['grav'] = grav

    # Initial solution
    # ================
    # Riemann states of the dam break problem
    damRadius = 0.25 #0.5
    hl = 2.
    ul = 0.
    vl = 0.
    hr = 1.
    ur = 0.
    vr = 0.

    qinit(state,hl,ul,vl,hr,ur,vl,damRadius) # This function is defined above

    # this closure is used by AMR-style codes
    def qinit_callback(state):
        qinit(state,hl,ul,vl,hr,ur,vl,damRadius)

    #===========================================================================
    # Set up controller and controller parameters
    #===========================================================================
    claw = pyclaw.Controller()
    claw.tfinal = 3e-1 #3e-1 #0.03

    if amr_type is not None:        
        if amr_type == 'peano':
            import peanoclaw as amrclaw
            claw.solver = amrclaw.Solver(solver
                                        ,1/(mgrid*msubgrid)
                                        ,qinit_callback
                                        #,refinement_criterion=refinement_criterion_time_dependent
                                        #,refinement_criterion=refinement_criterion
                                        #,refinement_criterion=refinement_criterion_gradient
                                        )
            claw.solution = amrclaw.Solution(state, domain)
        else:
            raise Exception('unsupported amr_type %s' % amr_type)
    else:
        claw.solver = solver
        claw.solution = pyclaw.Solution(state,domain)
        
    #claw.keep_copy = True
    #claw.outdir = outdir
 
    claw.keep_copy = False
    claw.output_format = None
    claw.outdir = None

    claw.num_output_times = 10

    #===========================================================================
    # Plot results
    #===========================================================================
    if htmlplot:  pyclaw.plot.html_plot(outdir=outdir)
    if iplot:     pyclaw.plot.interactive_plot(outdir=outdir)

    return claw
Esempio n. 29
0
def psystem2D(iplot=False,
              kernel_language='Fortran',
              htmlplot=False,
              use_petsc=False,
              outdir='./_output',
              solver_type='classic',
              disable_output=False):
    """
    Solve the p-system in 2D with variable coefficients
    """
    if use_petsc:
        import clawpack.petclaw as pyclaw
    else:
        from clawpack import pyclaw

    ####################################
    ######### MAIN PARAMETERS ##########
    ####################################
    # Domain
    x_lower = 0.25
    x_upper = 20.25
    y_lower = 0.25
    y_upper = 20.25
    # cells per layer
    Ng = 10
    mx = (x_upper - x_lower) * Ng
    my = (y_upper - y_lower) * Ng
    # Initial condition parameters
    A = 10.
    x0 = 0.25  # Center of initial perturbation
    y0 = 0.25  # Center of initial perturbation
    varx = 0.5
    vary = 0.5  # Width of initial perturbation

    # Boundary conditions
    bc_x_lower = pyclaw.BC.wall
    bc_x_upper = pyclaw.BC.extrap
    bc_y_lower = pyclaw.BC.wall
    bc_y_upper = pyclaw.BC.extrap

    # Turning off 1st half of the domain. Useful in rect domains
    turnZero_half_2D = 0  #flag
    t_turnZero = 50
    num_output_times = 10
    # restart options
    restart_from_frame = None

    if solver_type == 'classic':
        solver = pyclaw.ClawSolver2D()
    elif solver_type == 'sharpclaw':
        solver = pyclaw.SharpClawSolver2D()

    if kernel_language != 'Fortran':
        raise Exception('Unrecognized value of kernel_language for 2D psystem')

    from clawpack import riemann
    solver.rp = riemann.rp2_psystem

    solver.num_waves = 2
    solver.limiters = pyclaw.limiters.tvd.superbee

    solver.bc_lower[0] = bc_x_lower
    solver.bc_upper[0] = bc_x_upper
    solver.bc_lower[1] = bc_y_lower
    solver.bc_upper[1] = bc_y_upper
    solver.aux_bc_lower[0] = bc_x_lower
    solver.aux_bc_upper[0] = bc_x_upper
    solver.aux_bc_lower[1] = bc_y_lower
    solver.aux_bc_upper[1] = bc_y_upper

    solver.fwave = True
    solver.cfl_max = 0.9
    solver.cfl_desired = 0.8
    solver.before_step = b4step
    solver.dimensional_split = False

    #controller
    claw = pyclaw.Controller()
    claw.tfinal = 40.0
    claw.solver = solver
    claw.outdir = outdir

    if restart_from_frame is not None:
        claw.solution = pyclaw.Solution(restart_from_frame,
                                        format='petsc',
                                        read_aux=False)
        claw.solution.state.mp = 1
        grid = claw.solution.domain.grid
        claw.solution.state.aux = setaux(grid.x.centers, grid.y.centers)
        claw.num_output_times = num_output_times - restart_from_frame
        claw.start_frame = restart_from_frame
    else:
        ####################################
        ####################################
        ####################################
        #Creation of Domain
        x = pyclaw.Dimension('x', x_lower, x_upper, mx)
        y = pyclaw.Dimension('y', y_lower, y_upper, my)
        domain = pyclaw.Domain([x, y])
        num_eqn = 3
        num_aux = 4
        state = pyclaw.State(domain, num_eqn, num_aux)
        state.mF = 3
        #Set global parameters
        state.problem_data = {}
        state.problem_data['turnZero_half_2D'] = turnZero_half_2D
        state.problem_data['t_turnZero'] = t_turnZero
        state.mp = 1

        grid = state.grid
        state.aux = setaux(grid.x.centers, grid.y.centers)
        #Initial condition
        qinit(state, A, x0, y0, varx, vary)

        claw.solution = pyclaw.Solution(state, domain)
        claw.num_output_times = num_output_times

    #claw.p_function = p_function
    if disable_output:
        claw.output_format = None
    claw.compute_F = compute_F
    state.keep_gauges = True
    grid.add_gauges([[0.25, 0.25], [17.85, 1.25], [3.25, 18.75],
                     [11.75, 11.75]])
    solver.compute_gauge_values = gauge_pfunction
    claw.write_aux_init = False

    #Solve
    status = claw.run()

    if iplot: pyclaw.plot.interactive_plot()
    if htmlplot: pyclaw.plot.html_plot()

    return claw.solution.state
Esempio n. 30
0
def setup(use_petsc=False,
          kernel_language='Fortran',
          outdir='./_output',
          solver_type='classic',
          riemann_solver='roe',
          disable_output=False):
    if use_petsc:
        import clawpack.petclaw as pyclaw
    else:
        from clawpack import pyclaw

    if kernel_language == 'Python':
        if riemann_solver.lower() == 'roe':
            raise Exception('Python Roe solver not implemented.')
        elif riemann_solver.lower() == 'hlle':
            rs = riemann.shallow_1D_py.shallow_hll_1D
    elif kernel_language == 'Fortran':
        if riemann_solver.lower() == 'roe':
            rs = riemann.shallow_roe_with_efix_1D
        elif riemann_solver.lower() == 'hlle':
            rs = riemann.shallow_hlle_1D

    if solver_type == 'classic':
        solver = pyclaw.ClawSolver1D(rs)
        solver.limiters = pyclaw.limiters.tvd.vanleer
    elif solver_type == 'sharpclaw':
        solver = pyclaw.SharpClawSolver1D(rs)
    if use_petsc:
        import clawpack.petclaw as pyclaw
    else:
        from clawpack import pyclaw

    if solver_type == 'sharpclaw':
        solver = pyclaw.SharpClawSolver2D(riemann.euler_5wave_2D)
        solver.dq_src = dq_swe
        solver.weno_order = 5
        solver.lim_type = 2
    else:
        # solver = pyclaw.ClawSolver2D(riemann.euler_5wave_2D)
        solver.step_source = step_swe
        solver.source_split = 1
        # solver.limiters = [11, 11] # 11 for A-R limiter
        solver.limiters = [4, 4]  # 4 for MC limiter
        solver.cfl_max = 0.36
        solver.cfl_desired = 0.35

    solver.kernel_language = kernel_language

    solver.bc_lower[0] = pyclaw.BC.periodic
    solver.bc_upper[0] = pyclaw.BC.periodic

    x = pyclaw.Dimension(xlower, xupper, mx, name='x')
    domain = pyclaw.Domain(x)
    state = pyclaw.State(domain, num_eqn)

    # Gravitational constant
    state.problem_data['grav'] = 9.81
    state.problem_data['dry_tolerance'] = 1e-5
    state.problem_data['sea_level'] = 0.0

    xc = state.grid.x.centers

    # I.C.: spatially varying disturbance
    state.q[depth, :] = normal_depth * (
        1.0 + dist_amp * np.sin(2.0 * np.pi * xc / wave_length))
    state.q[momentum, :] = normal_velocity * normal_depth * (
        1.0 + dist_amp * np.sin(2.0 * np.pi * xc / wave_length))

    claw = pyclaw.Controller()
    claw.keep_copy = True
    if disable_output:
        claw.output_format = None
    claw.output_style = 1
    claw.tfinal = sim_time
    claw.num_output_times = int(
        sim_time / output_interval)  # conversion between two output styles
    claw.solution = pyclaw.Solution(state, domain)
    claw.solver = solver
    claw.outdir = outdir
    claw.setplot = setplot

    return claw