예제 #1
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
예제 #2
0
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