コード例 #1
0
ファイル: test_peano_solver.py プロジェクト: cr2940/pyclaw-1
def test_initialization():
    from pyclaw.clawpack.clawpack import ClawSolver2D

    solver = ClawSolver2D()

    import peanoclaw
    peano_solver = peanoclaw.Solver(solver, 1.0)

    import inspect
    for member in inspect.getmembers(peano_solver):
        if (not member[0].startswith("_") and not inspect.ismethod(member[1])):
            print((member[0]))
    for member in inspect.getmembers(solver):
        if (not member[0].startswith("_") and not inspect.ismethod(member[1])):
            print((member[0]))
コード例 #2
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
コード例 #3
0
def test_3x3_grid():
    r"""This test simply solves a 3x3 grid, once with PyClaw and once as one patch 
    with PeanoClaw. In the end it checks if the resulting qbcs match.
    """
    #===========================================================================
    # Import libraries
    #===========================================================================
    import numpy as np
    import pyclaw
    import peanoclaw

    #===========================================================================
    # Setup solver and solver parameters for PyClaw run
    #===========================================================================
    pyclaw_solver = setup_solver()
    
    #===========================================================================
    # Setup solver and solver parameters for PeanoClaw run
    #===========================================================================
    peanoclaw_solver = setup_solver()
    peano_solver = peanoclaw.Solver(peanoclaw_solver, 1.0)

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

    # Domain:
    xlower = 0.0
    xupper = 1.0
    mx = 3
    ylower = 0.0
    yupper = 1.0
    my = 3
    x = pyclaw.Dimension(xlower,xupper,mx,name='x')
    y = pyclaw.Dimension(ylower,yupper,my,name='y')
    domain = pyclaw.Domain([x,y])

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

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

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

    tfinal = 1.0
    #===========================================================================
    # Set up controller and controller parameters for PyClaw run
    #===========================================================================
    pyclaw_controller = pyclaw.Controller()
    pyclaw_controller.tfinal = tfinal
    pyclaw_controller.solution = pyclaw.Solution(pyclaw_state,domain)
    pyclaw_controller.solver = pyclaw_solver
    pyclaw_controller.num_output_times = 1
    
    pyclaw_controller.run()
    
    #===========================================================================
    # Set up controller and controller parameters for PyClaw run
    #===========================================================================
    peanoclaw_controller = pyclaw.Controller()
    peanoclaw_controller.tfinal = tfinal
    peanoclaw_controller.solution = pyclaw.Solution(peanoclaw_state,domain)
    peanoclaw_controller.solver = peano_solver
    peanoclaw_controller.num_output_times = 1
    
    peanoclaw_controller.run()
    
    assert(np.max(np.abs(pyclaw_solver.qbc - peanoclaw_solver.qbc)) < 1e-9)
コード例 #4
0
ファイル: shockbubble.py プロジェクト: unterwegerK/peanoclaw
def shockbubble(use_petsc=False,
                iplot=False,
                htmlplot=False,
                outdir='./_output',
                solver_type='classic',
                amr_type=None):
    """
    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.SharpClawSolver3D(riemann.euler_3D)
        solver.weno_order = 5
        solver.lim_type = 2
    else:
        solver = pyclaw.ClawSolver3D(riemann.euler_3D)
        solver.dimensional_split = 1
        # solver.transverse_waves = 3
        solver.limiters = 4
        solver.cfl_max = 0.2
        solver.cfl_desired = 0.15
        solver.order = 2
        solver.dt_initial = 1  # 0.000125

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

    # Initialize domain
    factor = 1  #2.0/3.0+1e-10#1.5+1e-10
    mx = int(12 * factor)
    my = int(6 * factor)
    mz = int(6 * factor)

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

    if amr_type is None:
        # 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
        mx = mx * msubgrid
        my = my * msubgrid
        mz = mz * msubgrid

    x = pyclaw.Dimension('x', 0.0, 2.0, mx)
    y = pyclaw.Dimension('y', -0.5, 0.5, my)
    z = pyclaw.Dimension('z', -0.5, 0.5, mz)
    domain = pyclaw.Domain([x, y, z])
    num_eqn = 5
    state = pyclaw.State(domain, num_eqn)

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

    qinit(state)
    print np.min(state.q[0, ...].reshape(-1))

    solver.user_bc_lower = shockbc

    claw = pyclaw.Controller()
    claw.tfinal = 0.5  #1
    claw.num_output_times = 10  #50
    claw.outdir = outdir
    claw.output_format = None

    if amr_type is not None:
        if amr_type == 'peano':
            import peanoclaw as amrclaw
            claw.solver = amrclaw.Solver(
                solver,
                (x.upper - x.lower) / (mx * msubgrid),
                qinit
                #,refinement_criterion=refinement_criterion_gradient
                ,
                internal_settings=amrclaw.InternalSettings(
                    enable_peano_logging=True,
                    fork_level_increment=1,
                    use_dimensional_splitting_optimization=True))
            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)

    return claw