Exemplo n.º 1
0
    def setup(use_petsc=False,
              solver_type='classic',
              kernel_language='Python',
              outdir='./_output'):
        from clawpack import riemann

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

        if solver_type == 'classic':
            if kernel_language == 'Fortran':
                solver = pyclaw.ClawSolver1D(riemann.vc_advection_1D)
            elif kernel_language == 'Python':
                solver = pyclaw.ClawSolver1D(
                    riemann.vc_advection_1D_py.vc_advection_1D)
        elif solver_type == 'sharpclaw':
            if kernel_language == 'Fortran':
                solver = pyclaw.SharpClawSolver1D(riemann.vc_advection_1D)
            elif kernel_language == 'Python':
                solver = pyclaw.SharpClawSolver1D(
                    riemann.vc_advection_1D_py.vc_advection_1D)
            solver.weno_order = weno_order
        else:
            raise Exception('Unrecognized value of solver_type.')

        solver.kernel_language = kernel_language

        solver.limiters = pyclaw.limiters.tvd.MC
        solver.bc_lower[0] = pyclaw.BC.custom
        solver.user_bc_lower = custom_bc
        solver.bc_upper[0] = pyclaw.BC.custom
        solver.user_bc_upper = custom_bc
        solver.aux_bc_lower[0] = 2
        solver.aux_bc_upper[0] = 2

        xlower = -100.0
        xupper = 100.0
        mx = steps
        x = pyclaw.Dimension(xlower, xupper, mx, name='x')
        domain = pyclaw.Domain(x)
        num_aux = 1
        num_eqn = 1
        state = pyclaw.State(domain, num_eqn, num_aux)

        qinit(state)
        auxinit(state)

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

        claw.tfinal = 10.0
        claw.setplot = setplot
        claw.keep_copy = True

        # print claw.solution._get_solution_attribute
        return claw
Exemplo n.º 2
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
Exemplo n.º 3
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
Exemplo n.º 4
0
def setup(nx=100,
          kernel_language='Python',
          use_petsc=False,
          solver_type='classic',
          weno_order=5,
          outdir='./_output'):
    import numpy as np
    from clawpack import riemann

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

    if solver_type == 'classic':
        if kernel_language == 'Fortran':
            solver = pyclaw.ClawSolver1D(riemann.advection_1D)
        elif kernel_language == 'Python':
            solver = pyclaw.ClawSolver1D(riemann.advection_1D_py.advection_1D)
    elif solver_type == 'sharpclaw':
        if kernel_language == 'Fortran':
            solver = pyclaw.SharpClawSolver1D(riemann.advection_1D)
        elif kernel_language == 'Python':
            solver = pyclaw.SharpClawSolver1D(
                riemann.advection_1D_py.advection_1D)
        solver.weno_order = weno_order
    else:
        raise Exception('Unrecognized value of solver_type.')

    solver.kernel_language = kernel_language

    solver.bc_lower[0] = 2
    solver.bc_upper[0] = 2

    x = pyclaw.Dimension('x', 0.0, 1.0, nx)
    domain = pyclaw.Domain(x)
    num_eqn = 1
    state = pyclaw.State(domain, num_eqn)
    state.problem_data['u'] = 1.

    grid = state.grid
    xc = grid.x.centers
    beta = 100
    gamma = 0
    x0 = 0.75
    state.q[0, :] = np.exp(-beta * (xc - x0)**2) * np.cos(gamma * (xc - x0))

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

    if outdir is not None:
        claw.outdir = outdir
    else:
        claw.output_format = None

    claw.tfinal = 1.0

    return claw
Exemplo n.º 5
0
def wcblast(use_petsc=False,
            iplot=False,
            htmlplot=False,
            outdir='./_output',
            solver_type='classic'):
    """
    Solve the Euler equations of compressible fluid dynamics.
    This example involves a pair of interacting shock waves.
    The conserved quantities are density, momentum density, and total energy density.
    """

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

    if solver_type == 'sharpclaw':
        solver = pyclaw.SharpClawSolver1D()
    else:
        solver = pyclaw.ClawSolver1D()

    from clawpack import riemann
    solver.rp = riemann.rp1_euler_with_efix

    solver.num_waves = 3
    solver.bc_lower[0] = pyclaw.BC.wall
    solver.bc_upper[0] = pyclaw.BC.wall

    # Initialize domain
    mx = 500
    x = pyclaw.Dimension('x', 0.0, 1.0, mx)
    domain = pyclaw.Domain([x])
    num_eqn = 3
    state = pyclaw.State(domain, num_eqn)

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

    state.q[0, :] = 1.
    state.q[1, :] = 0.
    x = state.grid.x.centers
    state.q[2, :] = ((x < 0.1) * 1.e3 + (0.1 <= x) * (x < 0.9) * 1.e-2 +
                     (0.9 <= x) * 1.e2) / gamma1

    solver.limiters = 4

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

    # Solve
    status = claw.run()

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

    return claw.solution.q
Exemplo n.º 6
0
def setup(use_petsc=0,
          kernel_language='Fortran',
          outdir='./_output',
          solver_type='classic'):
    """
    Example python script for solving the 1d Burgers equation.
    """

    import numpy as np
    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 == 'sharpclaw':
        if kernel_language == 'Python':
            solver = pyclaw.SharpClawSolver1D(riemann.burgers_1D_py.burgers_1D)
        elif kernel_language == 'Fortran':
            solver = pyclaw.SharpClawSolver1D(riemann.burgers_1D)
    else:
        if kernel_language == 'Python':
            solver = pyclaw.ClawSolver1D(riemann.burgers_1D_py.burgers_1D)
        elif kernel_language == 'Fortran':
            solver = pyclaw.ClawSolver1D(riemann.burgers_1D)
        solver.limiters = pyclaw.limiters.tvd.vanleer

    solver.kernel_language = kernel_language

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

    #===========================================================================
    # Initialize domain and then initialize the solution associated to the domain
    #===========================================================================
    x = pyclaw.Dimension('x', 0.0, 1.0, 500)
    domain = pyclaw.Domain(x)
    num_eqn = 1
    state = pyclaw.State(domain, num_eqn)

    grid = state.grid
    xc = grid.x.centers
    state.q[0, :] = np.sin(np.pi * 2 * xc) + 0.50
    state.problem_data['efix'] = True

    #===========================================================================
    # Setup controller and controller parameters. Then solve the problem
    #===========================================================================
    claw = pyclaw.Controller()
    claw.tfinal = 0.5
    claw.solution = pyclaw.Solution(state, domain)
    claw.solver = solver
    claw.outdir = outdir

    return claw
Exemplo n.º 7
0
def setup(use_petsc=False,
          outdir='./_output',
          solver_type='classic',
          kernel_language='Python',
          disable_output=False):

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

    if kernel_language == 'Python':
        rs = riemann.euler_1D_py.euler_hllc_1D
    elif kernel_language == 'Fortran':
        rs = riemann.euler_hlle_1D

    if solver_type == 'sharpclaw':
        solver = pyclaw.SharpClawSolver1D(rs)
    elif solver_type == 'classic':
        solver = pyclaw.ClawSolver1D(rs)

    solver.kernel_language = kernel_language

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

    mx = 800
    x = pyclaw.Dimension(-1.0, 1.0, mx, name='x')
    domain = pyclaw.Domain([x])
    state = pyclaw.State(domain, num_eqn)

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

    x = state.grid.x.centers

    rho_l = 1.
    rho_r = 1. / 8
    p_l = 1.
    p_r = 0.1
    state.q[density, :] = (x < 0.) * rho_l + (x >= 0.) * rho_r
    state.q[momentum, :] = 0.
    velocity = state.q[momentum, :] / state.q[density, :]
    pressure = (x < 0.) * p_l + (x >= 0.) * p_r
    state.q[energy, :] = pressure / (
        gamma - 1.) + 0.5 * state.q[density, :] * velocity**2

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

    return claw
Exemplo n.º 8
0
def setup(kernel_language='Python',
          use_petsc=False,
          outdir='./_output',
          solver_type='classic'):

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

    solver = pyclaw.ClawSolver1D(riemann.shallow_1D_py.shallow_fwave_1d)
    solver.limiters = pyclaw.limiters.tvd.vanleer
    solver.kernel_language = "Python"
    solver.fwave = True
    solver.num_waves = 2
    solver.num_eqn = 2
    solver.bc_lower[0] = pyclaw.BC.wall
    solver.bc_upper[0] = pyclaw.BC.wall
    solver.aux_bc_lower[0] = pyclaw.BC.wall
    solver.aux_bc_upper[0] = pyclaw.BC.wall
    solver.step_source = stepSource
    # solver.dt = 0.00001

    x_star = numpy.sqrt(80.0 / 1e-2) - 1.2
    xlower = -x_star
    xupper = x_star
    x = pyclaw.Dimension(xlower, xupper, 500, name='x')
    domain = pyclaw.Domain(x)
    state = pyclaw.State(domain, 2, 1)

    # Gravitational constant
    state.problem_data['grav'] = 9.8
    state.problem_data['sea_level'] = 0.0

    xc = state.grid.x.centers
    # state.aux[0, :] = 0.8 * numpy.exp(-xc**2 / 0.2**2) - 1.0
    state.aux[0, :] = 1.e-2 * (xc**2) - 80
    ze = -((xc)**2) / 10
    state.q[0, :] = numpy.where(
        ze > -10., 40.e0 * numpy.exp(ze) - state.aux[0, :],
        numpy.where(state.aux[0, :] <= 0, -state.aux[0, :], 0.))
    state.q[1, :] = 0.0

    claw = pyclaw.Controller()
    claw.keep_copy = True
    claw.tfinal = 8.0
    claw.output_style = 1
    claw.num_output_times = 25
    claw.solution = pyclaw.Solution(state, domain)
    claw.solver = solver
    claw.setplot = setplot
    claw.write_aux_init = True

    if outdir is not None:
        claw.outdir = outdir
    else:
        claw.output_format = None

    return claw
Exemplo n.º 9
0
def setup(nx=100,
          kernel_language='Python',
          use_petsc=False,
          solver_type='classic',
          weno_order=5,
          time_integrator='SSP104',
          outdir='./_output'):

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

    if kernel_language == 'Fortran':
        riemann_solver = riemann.advection_1D
    elif kernel_language == 'Python':
        riemann_solver = riemann.advection_1D_py.advection_1D

    if solver_type == 'classic':
        solver = pyclaw.ClawSolver1D(riemann_solver)
    elif solver_type == 'sharpclaw':
        solver = pyclaw.SharpClawSolver1D(riemann_solver)
        solver.weno_order = weno_order
        solver.time_integrator = time_integrator
    else:
        raise Exception('Unrecognized value of solver_type.')

    solver.kernel_language = kernel_language

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

    x = pyclaw.Dimension('x', 0.0, 1.0, nx)
    domain = pyclaw.Domain(x)
    state = pyclaw.State(domain, solver.num_eqn)

    state.problem_data['u'] = 1.  # Advection velocity

    # Initial data
    xc = state.grid.x.centers
    beta = 100
    gamma = 0
    x0 = 0.75
    state.q[0, :] = np.exp(-beta * (xc - x0)**2) * np.cos(gamma * (xc - x0))

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

    if outdir is not None:
        claw.outdir = outdir
    else:
        claw.output_format = None

    claw.tfinal = 1.0
    claw.setplot = setplot

    return claw
Exemplo n.º 10
0
def advection(kernel_language='Python',iplot=False,htmlplot=False,
              use_petsc=False,solver_type='classic', weno_order=5,
              outdir='./_output'):
    """
    Example python script for solving the 1d advection equation.
    """
    import numpy as np

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

    if solver_type=='sharpclaw':
        solver = pyclaw.SharpClawSolver1D()
        solver.weno_order=weno_order
    else:
        solver = pyclaw.ClawSolver1D()

    solver.kernel_language = kernel_language
    from clawpack.riemann import rp_advection
    solver.num_waves = rp_advection.num_waves
    if solver.kernel_language=='Python':
        solver.rp = rp_advection.rp_advection_1d
    else:
        from clawpack import riemann
        solver.rp = riemann.rp1_advection

    solver.bc_lower[0] = 2
    solver.bc_upper[0] = 2

    x = pyclaw.Dimension('x',0.0,1.0,100)
    domain = pyclaw.Domain(x)
    num_eqn = 1
    state = pyclaw.State(domain,num_eqn)
    state.problem_data['u']=1.

    grid = state.grid
    xc=grid.x.centers
    beta=100; gamma=0; x0=0.75
    state.q[0,:] = np.exp(-beta * (xc-x0)**2) * np.cos(gamma * (xc - x0))

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

    if outdir is not None:
        claw.outdir = outdir
    else:
        claw.output_format = None

    claw.tfinal =1.0
    status = claw.run()

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

    return claw
Exemplo n.º 11
0
def shocktube(kernel_language='Fortran',
              solver_type='classic',
              use_petsc=False,
              outdir='shocktube_output',
              output_format='hdf5',
              disable_output=False,
              mx=10,
              my=10,
              mz=128,
              tfinal=1.0,
              num_output_times=10):

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

    if solver_type == 'classic':
        solver = pyclaw.ClawSolver3D(riemann.euler_3D)
        solver.dimensional_split = True
        solver.limiters = pyclaw.limiters.tvd.MC
        solver.cfl_max = 1.0
        solver.cfl_desired = 0.80
    elif solver_type == 'sharpclaw':
        solver = pyclaw.SharpClawSolver3D(riemann.euler_3D)
    else:
        raise Exception('Unrecognized solver_type.')

    domain = pyclaw.Domain((-1., -1., -1.), (1., 1., 1.), (mx, my, mz))

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

    grid = state.grid

    X, Y, Z = grid.p_centers

    pressure = 3. * (Z <= 0) + 1. * (Z > 0)
    state.q[density, :, :, :] = 3. * (Z <= 0) + 1. * (Z > 0)
    state.q[x_momentum, :, :, :] = 0.
    state.q[y_momentum, :, :, :] = 0.
    state.q[z_momentum, :, :, :] = 0.
    state.q[energy, :, :, :] = pressure / (gamma - 1.)

    solver.all_bcs = pyclaw.BC.extrap

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

    return claw
Exemplo n.º 12
0
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
Exemplo n.º 13
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)
Exemplo n.º 14
0
def setup(use_petsc=False,
          iplot=False,
          htmlplot=False,
          outdir='./_output',
          solver_type='sharpclaw',
          kernel_language='Fortran'):
    """
    Solve the Euler equations of compressible fluid dynamics.
    This example involves a shock wave impacting a sinusoidal density field.
    """
    from clawpack import riemann

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

    if solver_type == 'sharpclaw':
        solver = pyclaw.SharpClawSolver1D(riemann.euler_with_efix_1D)
        solver.time_integrator = 'RK'
        solver.a, solver.b, solver.c = a, b, c
        solver.cfl_desired = 0.6
        solver.cfl_max = 0.7
    else:
        solver = pyclaw.ClawSolver1D(riemann.euler_with_efix_1D)

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

    # Initialize domain
    mx = 400
    x = pyclaw.Dimension('x', -5.0, 5.0, mx)
    domain = pyclaw.Domain([x])
    state = pyclaw.State(domain, solver.num_eqn)

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

    xc = state.grid.x.centers
    epsilon = 0.2
    state.q[0, :] = (xc < -4.) * 3.857143 + (xc >= -4.) * (
        1 + epsilon * np.sin(5 * xc))
    velocity = (xc < -4.) * 2.629369
    state.q[1, :] = velocity * state.q[0, :]
    pressure = (xc < -4.) * 10.33333 + (xc >= -4.) * 1.
    state.q[2, :] = pressure / gamma1 + 0.5 * state.q[0, :] * velocity**2

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

    return claw
Exemplo n.º 15
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)
Exemplo n.º 16
0
def setup(use_petsc=0, outdir='./_output', solver_type='classic'):
    """
    Example python script for solving 1d traffic model:

    $$ q_t + umax( q(1-q) )_x = 0.$$
    """

    import numpy as np
    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 == 'sharpclaw':
        solver = pyclaw.SharpClawSolver1D(riemann.traffic_1D)
    else:
        solver = pyclaw.ClawSolver1D(riemann.traffic_1D)

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

    #===========================================================================
    # Initialize domain and then initialize the solution associated to the domain
    #===========================================================================
    x = pyclaw.Dimension('x', -1.0, 1.0, 500)
    domain = pyclaw.Domain(x)
    num_eqn = 1
    state = pyclaw.State(domain, num_eqn)

    grid = state.grid
    xc = grid.x.centers

    state.q[0, :] = 0.75 * (xc < 0) + 0.1 * (xc > 0.)

    state.problem_data['efix'] = True
    state.problem_data['umax'] = 1.

    #===========================================================================
    # Setup controller and controller parameters. Then solve the problem
    #===========================================================================
    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
Exemplo n.º 17
0
def setup(kernel_language='Fortran',
          solver_type='classic',
          use_petsc=False,
          outdir='./_output'):

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

    if kernel_language == 'Fortran':
        solver = pyclaw.ClawSolver1D(riemann.shallow_bathymetry_fwave_1D)
    elif kernel_language == 'Python':
        solver = pyclaw.ClawSolver1D(riemann.shallow_1D_py.shallow_fwave_1d)
        solver.kernel_language = 'Python'
    solver.limiters = pyclaw.limiters.tvd.vanleer
    solver.fwave = True
    solver.num_waves = 2
    solver.num_eqn = 2
    solver.bc_lower[0] = pyclaw.BC.extrap
    solver.bc_upper[0] = pyclaw.BC.extrap
    solver.aux_bc_lower[0] = pyclaw.BC.extrap
    solver.aux_bc_upper[0] = pyclaw.BC.extrap

    xlower = -1.0
    xupper = 1.0
    x = pyclaw.Dimension(xlower, xupper, 500, name='x')
    domain = pyclaw.Domain(x)
    state = pyclaw.State(domain, 2, 1)

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

    xc = state.grid.x.centers
    state.aux[0, :] = 0.8 * numpy.exp(-xc**2 / 0.2**2) - 1.0
    state.q[0, :] = 0.1 * numpy.exp(-(xc + 0.4)**2 / 0.2**2) - state.aux[0, :]
    state.q[1, :] = 0.0

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

    if outdir is not None:
        claw.outdir = outdir
    else:
        claw.output_format = None

    return claw
def setup(use_petsc=0,
          kernel_language='Python',
          outdir='./_output',
          solver_type='classic'):

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

    if kernel_language == 'Python':
        riemann_solver = adsolver
    elif kernel_language == 'Fortran':
        riemann_solver = riemann.burgers_1D

    if solver_type == 'sharpclaw':
        solver = pyclaw.SharpClawSolver1D(riemann_solver)
    else:
        solver = pyclaw.ClawSolver1D(riemann_solver)
        solver.limiters = pyclaw.limiters.tvd.vanleer

    solver.kernel_language = kernel_language

    solver.bc_lower[0] = pyclaw.BC.periodic
    #solver.user_bc_lower=custom_bc_one
    solver.bc_upper[0] = pyclaw.BC.periodic
    #solver.user_bc_upper=custom_bc_two
    solver.num_waves = 1
    solver.num_eqn = 1
    x = pyclaw.Dimension(0.0, 1.0, 500, name='x')
    domain = pyclaw.Domain(x)
    num_eqn = 1
    state = pyclaw.State(domain, num_eqn)

    xc = state.grid.x.centers
    state.q[0, :] = np.sin(np.pi * 2 * xc) + 0.50
    state.problem_data['efix'] = True
    state.problem_data['a'] = 1.0

    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',kernel_language='Python',outdir='./_output'):
    from clawpack import riemann

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

    if solver_type=='classic':
        if kernel_language == 'Fortran':
            solver = pyclaw.ClawSolver1D(riemann.vc_advection_1D)
        elif kernel_language=='Python': 
            solver = pyclaw.ClawSolver1D(riemann.vc_advection_1D_py.vc_advection_1D)
    elif solver_type=='sharpclaw':
        if kernel_language == 'Fortran':
            solver = pyclaw.SharpClawSolver1D(riemann.vc_advection_1D)
        elif kernel_language=='Python': 
            solver = pyclaw.SharpClawSolver1D(riemann.vc_advection_1D_py.vc_advection_1D)
        solver.weno_order=weno_order
    else: raise Exception('Unrecognized value of solver_type.')

    solver.kernel_language = kernel_language

    solver.limiters = pyclaw.limiters.tvd.MC
    solver.bc_lower[0] = 2
    solver.bc_upper[0] = 2
    solver.aux_bc_lower[0] = 2
    solver.aux_bc_upper[0] = 2

    xlower=0.0; xupper=1.0; mx=100
    x    = pyclaw.Dimension('x',xlower,xupper,mx)
    domain = pyclaw.Domain(x)
    num_aux=1
    num_eqn = 1
    state = pyclaw.State(domain,num_eqn,num_aux)

    qinit(state)
    auxinit(state)

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

    claw.tfinal = 1.0
    
    return claw
Exemplo n.º 20
0
def vc_advection(use_petsc=False,solver_type='classic',kernel_language='Python',iplot=False,htmlplot=False,outdir='./_output'):

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

    if solver_type=='sharpclaw':
        solver = pyclaw.SharpClawSolver1D()
    else:
        solver = pyclaw.ClawSolver1D()

    from clawpack import riemann
    solver.num_waves = riemann.rp_vc_advection.num_waves

    solver.kernel_language = kernel_language
    if solver.kernel_language=='Python': 
        solver.rp = riemann.rp_vc_advection.rp_vc_advection_1d
    elif solver.kernel_language=='Fortran':
        raise NotImplementedError('The 1D variable coefficient advection Riemann solver has not yet been ported.')

    solver.limiters = pyclaw.limiters.tvd.MC
    solver.bc_lower[0] = 2
    solver.bc_upper[0] = 2
    solver.aux_bc_lower[0] = 2
    solver.aux_bc_upper[0] = 2

    xlower=0.0; xupper=1.0; mx=100
    x    = pyclaw.Dimension('x',xlower,xupper,mx)
    domain = pyclaw.Domain(x)
    num_aux=1
    num_eqn = 1
    state = pyclaw.State(domain,num_eqn,num_aux)

    qinit(state)
    auxinit(state)

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

    claw.tfinal = 1.0
    status = claw.run()

    if htmlplot:  pyclaw.plot.html_plot(outdir=outdir)
    if iplot:     pyclaw.plot.interactive_plot(outdir=outdir)
Exemplo n.º 21
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
Exemplo n.º 22
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
Exemplo n.º 23
0
    def setup(use_petsc=0,
              kernel_language='Fortran',
              outdir='./_output',
              solver_type='classic'):

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

        if kernel_language == 'Python':
            riemann_solver = riemann.burgers_1D_py.burgers_1D
        elif kernel_language == 'Fortran':
            riemann_solver = riemann.burgers_1D

        if solver_type == 'sharpclaw':
            solver = pyclaw.SharpClawSolver1D(riemann_solver)
        else:
            solver = pyclaw.ClawSolver1D(riemann_solver)
            solver.limiters = pyclaw.limiters.tvd.vanleer

        solver.kernel_language = kernel_language

        solver.bc_lower[0] = pyclaw.BC.custom
        solver.user_bc_lower = custom_bc
        solver.bc_upper[0] = pyclaw.BC.custom
        solver.user_bc_upper = custom_bc

        x = pyclaw.Dimension(-100.0, 100.0, steps, name='x')
        domain = pyclaw.Domain(x)
        num_eqn = 1
        state = pyclaw.State(domain, num_eqn)

        xc = state.grid.x.centers
        state.q[0, :] = np.exp(-xc**2)
        state.problem_data['efix'] = True

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

        return claw
Exemplo n.º 24
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
Exemplo n.º 25
0
def setup(use_petsc=0, outdir='./_output', solver_type='classic', weno_order=5, N=1000):

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

    riemann_solver = riemann.cubic_1D

    if solver_type=='sharpclaw':
        solver = pyclaw.SharpClawSolver1D(riemann_solver)
        solver.weno_order = weno_order
    else:
        solver = pyclaw.ClawSolver1D(riemann_solver)
        solver.limiters = pyclaw.limiters.tvd.vanleer

    solver.cfl_max = 1.0
    solver.cfl_desired = 0.5

    solver.kernel_language = 'Fortran'

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

    x = pyclaw.Dimension(-1.0, 3.0, N, name='x')
    domain = pyclaw.Domain(x)
    num_eqn = 1
    state = pyclaw.State(domain, num_eqn)

    xc = state.grid.x.centers
    qL = 4.0
    qR = -2.0
    state.q[0,:] = (xc < -0.5) * qL + (xc >= -0.5) * qR

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

    return claw
Exemplo n.º 26
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
Exemplo n.º 27
0
def setup(use_petsc=0,outdir='./_output',solver_type='classic'):
    if use_petsc:
        import clawpack.petclaw as pyclaw
    else:
        from clawpack import pyclaw

    if solver_type=='sharpclaw':
        solver = pyclaw.SharpClawSolver1D(riemann.traffic_1D)
    else:
        solver = pyclaw.ClawSolver1D(riemann.traffic_1D)

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

    x = pyclaw.Dimension('x',-1.0,1.0,500)
    domain = pyclaw.Domain(x)
    num_eqn = 1
    state = pyclaw.State(domain,num_eqn)

    grid = state.grid
    xc=grid.p_centers[0]

    state.q[0,:] = 0.75*(xc<0) + 0.1*(xc>0.) 

    state.problem_data['efix']=True
    state.problem_data['umax']=1.

    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
Exemplo n.º 28
0
def setup(use_petsc=False,
          kernel_language='Fortran',
          outdir='./_output',
          solver_type='classic'):

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

    if kernel_language == 'Python':
        rs = riemann.shallow_1D_py.shallow_1D
    elif kernel_language == 'Fortran':
        rs = riemann.shallow_roe_with_efix_1D

    if solver_type == 'classic':
        solver = pyclaw.ClawSolver1D(rs)
        solver.limiters = pyclaw.limiters.tvd.vanleer
    elif solver_type == 'sharpclaw':
        solver = pyclaw.SharpClawSolver1D(rs)

    solver.kernel_language = kernel_language

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

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

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

    xc = state.grid.x.centers

    IC = 'dam-break'
    x0 = 0.

    if IC == 'dam-break':
        hl = 3.
        ul = 0.
        hr = 1.
        ur = 0.
        state.q[depth, :] = hl * (xc <= x0) + hr * (xc > x0)
        state.q[momentum, :] = hl * ul * (xc <= x0) + hr * ur * (xc > x0)
    elif IC == '2-shock':
        hl = 1.
        ul = 1.
        hr = 1.
        ur = -1.
        state.q[depth, :] = hl * (xc <= x0) + hr * (xc > x0)
        state.q[momentum, :] = hl * ul * (xc <= x0) + hr * ur * (xc > x0)
    elif IC == 'perturbation':
        eps = 0.1
        state.q[depth, :] = 1.0 + eps * np.exp(-(xc - x0)**2 / 0.5)
        state.q[momentum, :] = 0.

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

    return claw
Exemplo n.º 29
0
def setup(use_petsc=False,
          iplot=False,
          htmlplot=False,
          outdir='./_output',
          solver_type='sharpclaw',
          kernel_language='Fortran',
          use_char_decomp=False,
          tfluct_solver=True):

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

    if kernel_language == 'Python':
        rs = riemann.euler_1D_py.euler_roe_1D
    elif kernel_language == 'Fortran':
        rs = riemann.euler_with_efix_1D

    if solver_type == 'sharpclaw':
        solver = pyclaw.SharpClawSolver1D(rs)
        solver.time_integrator = 'RK'
        solver.a, solver.b, solver.c = a, b, c
        solver.cfl_desired = 0.6
        solver.cfl_max = 0.7
        if use_char_decomp:
            try:
                import sharpclaw1  # Import custom Fortran code
                solver.fmod = sharpclaw1
                solver.tfluct_solver = tfluct_solver  # Use total fluctuation solver for efficiency
                if solver.tfluct_solver:
                    try:
                        import euler_tfluct
                        solver.tfluct = euler_tfluct
                    except ImportError:
                        import logging
                        logger = logging.getLogger()
                        logger.error(
                            'Unable to load tfluct solver, did you run make?')
                        print 'Unable to load tfluct solver, did you run make?'
                        raise
            except ImportError:
                import logging
                logger = logging.getLogger()
                logger.error(
                    'Unable to load sharpclaw1 solver, did you run make?')
                print 'Unable to load sharpclaw1 solver, did you run make?'
                pass
            solver.lim_type = 2  # WENO reconstruction
            solver.char_decomp = 2  # characteristic-wise reconstruction
    else:
        solver = pyclaw.ClawSolver1D(rs)

    solver.kernel_language = kernel_language

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

    mx = 400
    x = pyclaw.Dimension(-5.0, 5.0, mx, name='x')
    domain = pyclaw.Domain([x])
    state = pyclaw.State(domain, num_eqn)

    state.problem_data['gamma'] = gamma

    if kernel_language == 'Python':
        state.problem_data['efix'] = False

    xc = state.grid.p_centers[0]
    epsilon = 0.2
    velocity = (xc < -4.) * 2.629369
    pressure = (xc < -4.) * 10.33333 + (xc >= -4.) * 1.

    state.q[density, :] = (xc < -4.) * 3.857143 + (xc >= -4.) * (
        1 + epsilon * np.sin(5 * xc))
    state.q[momentum, :] = velocity * state.q[density, :]
    state.q[energy, :] = pressure / (
        gamma - 1.) + 0.5 * state.q[density, :] * velocity**2

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

    return claw
Exemplo n.º 30
0
def setup(use_petsc=False,
          outdir='./_output',
          solver_type='classic',
          mx=30,
          my=30,
          mz=30,
          disable_output=False,
          problem='heterogeneous',
          **kwargs):
    """
    Example python script for solving the 3d 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.ClawSolver3D(riemann.vc_acoustics_3D)
        solver.limiters = pyclaw.limiters.tvd.MC
    elif solver_type == 'sharpclaw':
        solver = pyclaw.SharpClawSolver3D(riemann.vc_acoustics_3D)

    else:
        raise Exception('Unrecognized solver_type.')

    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.bc_lower[2] = pyclaw.BC.periodic
    solver.bc_upper[2] = 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
    solver.aux_bc_lower[2] = pyclaw.BC.periodic
    solver.aux_bc_upper[2] = pyclaw.BC.periodic

    zl = 1.0  # Impedance in left half
    cl = 1.0  # Sound speed in left half

    if problem == 'homogeneous':
        if solver_type == 'classic':
            solver.dimensional_split = True
        else:
            solver.lim_type = 1

        solver.limiters = [4]

        mx = mx
        my = my
        mz = mz  # Grid resolution

        zr = 1.0  # Impedance in right half
        cr = 1.0  # Sound speed in right half

    if problem == 'heterogeneous':
        if solver_type == 'classic':
            solver.dimensional_split = False

        solver.bc_lower[0] = pyclaw.BC.wall
        solver.bc_lower[1] = pyclaw.BC.wall
        solver.bc_lower[2] = pyclaw.BC.wall
        solver.aux_bc_lower[0] = pyclaw.BC.wall
        solver.aux_bc_lower[1] = pyclaw.BC.wall
        solver.aux_bc_lower[2] = pyclaw.BC.wall

        mx = mx
        my = my
        mz = mz  # Grid resolution

        zr = 2.0  # Impedance in right half
        cr = 2.0  # Sound speed in right half

    solver.limiters = pyclaw.limiters.tvd.MC

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

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

    X, Y, Z = state.grid.p_centers

    state.aux[0, :, :, :] = zl * (X < 0.) + zr * (X >= 0.)  # Impedance
    state.aux[1, :, :, :] = cl * (X < 0.) + cr * (X >= 0.)  # Sound speed

    # Set initial density
    x0 = -0.5
    y0 = 0.
    z0 = 0.
    if problem == 'homogeneous':
        r = np.sqrt((X - x0)**2)
        width = 0.2
        state.q[0, :, :, :] = (np.abs(r) <= width) * (1. + np.cos(np.pi *
                                                                  (r) / width))
    elif problem == 'heterogeneous':
        r = np.sqrt((X - x0)**2 + (Y - y0)**2 + (Z - z0)**2)
        width = 0.1
        state.q[0, :, :, :] = (np.abs(r - 0.3) <= width) * (
            1. + np.cos(np.pi * (r - 0.3) / width))
    else:
        raise Exception('Unrecognized problem name')

    # Set initial velocities to zero
    state.q[1, :, :, :] = 0.
    state.q[2, :, :, :] = 0.
    state.q[3, :, :, :] = 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 = 2.0

    return claw