Exemplo n.º 1
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(0.0, 1.0, nx, name='x')
    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.º 2
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.º 3
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.º 4
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.º 5
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.º 6
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.advection_color_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.advection_color_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(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 = 1.0
    claw.setplot = setplot
    claw.keep_copy = True

    return claw
Exemplo n.º 7
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.º 8
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.º 9
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
Exemplo n.º 10
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.º 11
0
def setup(use_petsc=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.
    """
    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)
    else:
        solver = pyclaw.ClawSolver1D(riemann.euler_with_efix_1D)

    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
    claw.setplot = setplot
    claw.keep_copy = True

    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
Exemplo n.º 13
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.º 14
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.º 15
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.º 16
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.º 17
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
Exemplo n.º 18
0
def oscillatory_wind(num_cells, eigen_method, **kargs):
    r"""docstring for oscillatory_wind"""

    # Construct output and plot directory paths
    prefix = 'ml_e%s_n%s' % (eigen_method, num_cells)
    name = 'multilayer/oscillatory_wind'
    outdir, plotdir, log_path = runclaw.create_output_paths(
        name, prefix, **kargs)

    # Redirect loggers
    # This is not working for all cases, see comments in runclaw.py
    for logger_name in [
            'pyclaw.io', 'pyclaw.solution', 'plot', 'pyclaw.solver', 'f2py',
            'data'
    ]:
        runclaw.replace_stream_handlers(logger_name,
                                        log_path,
                                        log_file_append=False)

    # Load in appropriate PyClaw version
    if kargs.get('use_petsc', False):
        import clawpack.petclaw as pyclaw
    else:
        import clawpack.pyclaw as pyclaw

    # =================
    # = Create Solver =
    # =================
    if kargs.get('solver_type', 'classic') == 'classic':
        solver = pyclaw.ClawSolver1D(riemann_solver=layered_shallow_water_1D)
    else:
        raise NotImplementedError(
            'Classic is currently the only supported solver.')

    # Solver method parameters
    solver.cfl_desired = 0.9
    solver.cfl_max = 1.0
    solver.max_steps = 5000
    solver.fwave = True
    solver.kernel_language = 'Fortran'
    solver.limiters = 3
    solver.source_split = 1

    # Boundary conditions
    # Here we implement our own wall boundary conditions for the multi-layer
    # equations
    solver.bc_lower[0] = 0
    solver.bc_upper[0] = 0
    solver.user_bc_lower = ml.bc.wall_qbc_lower
    solver.user_bc_upper = ml.bc.wall_qbc_upper
    solver.aux_bc_lower[0] = 1
    solver.aux_bc_upper[0] = 1

    # Set the before step functioning including the wind forcing
    wind_func = lambda state: ml.aux.set_oscillatory_wind(
        state, A=5.0, N=2.0, omega=2.0, t_length=10.0)
    solver.before_step = lambda solver, solution: ml.step.before_step(
        solver, solution, wind_func=wind_func, raise_on_richardson=True)

    # Use simple friction source term
    solver.step_source = ml.step.friction_source

    # ============================
    # = Create Initial Condition =
    # ============================
    num_layers = 2

    x = pyclaw.Dimension(0.0, 1.0, num_cells)
    domain = pyclaw.Domain([x])
    state = pyclaw.State(domain, 2 * num_layers, 3 + num_layers)
    state.aux[ml.aux.kappa_index, :] = 0.0

    # Set physics data
    state.problem_data['g'] = 9.8
    state.problem_data['manning'] = 0.0
    state.problem_data['rho_air'] = 1.15
    state.problem_data['rho'] = [1025.0, 1045.0]
    state.problem_data['r'] = \
                     state.problem_data['rho'][0] / state.problem_data['rho'][1]
    state.problem_data['one_minus_r'] = 1.0 - state.problem_data['r']
    state.problem_data['num_layers'] = num_layers

    # Set method parameters, this ensures it gets to the Fortran routines
    state.problem_data['eigen_method'] = eigen_method
    state.problem_data['dry_tolerance'] = 1e-3
    state.problem_data['inundation_method'] = 2
    state.problem_data['entropy_fix'] = False

    solution = pyclaw.Solution(state, domain)
    solution.t = 0.0

    # Set aux arrays including bathymetry, wind field and linearized depths
    ml.aux.set_jump_bathymetry(solution.state, 0.5, [-1.0, -1.0])
    wind_func(solution.state)
    ml.aux.set_h_hat(solution.state, 0.5, [0.0, -0.25], [0.0, -0.25])

    # Set sea at rest initial condition
    ml.qinit.set_quiescent_init_condition(solution.state)

    # ================================
    # = Create simulation controller =
    # ================================
    controller = pyclaw.Controller()
    controller.solution = solution
    controller.solver = solver

    # Output parameters
    controller.output_style = 1
    controller.tfinal = 10.0
    controller.num_output_times = 160
    controller.write_aux_init = True
    controller.outdir = outdir
    controller.keep_copy = True
    controller.write_aux_always = True

    # ==================
    # = Run Simulation =
    # ==================
    try:
        state = controller.run()
    except ml.step.RichardsonExceededError as e:
        print e
        # print "Writing out last solution available to frame %s." % str(len(controller.frames))
        # e.solution.write(len(controller.frames),path=controller.outdir,write_aux=True)

    # ============
    # = Plotting =
    # ============
    plot_kargs = {
        'xlower': solution.state.grid.x.lower,
        'xupper': solution.state.grid.x.upper,
        'rho': solution.state.problem_data['rho'],
        'dry_tolerance': solution.state.problem_data['dry_tolerance']
    }
    plot(setplot="./setplot_oscillatory.py",
         outdir=outdir,
         plotdir=plotdir,
         htmlplot=kargs.get('htmlplot', False),
         iplot=kargs.get('iplot', False),
         file_format=controller.output_format,
         **plot_kargs)
Exemplo n.º 19
0
def setup(use_petsc=False,
          kernel_language='Fortran',
          solver_type='classic',
          outdir='./_output',
          ptwise=False,
          weno_order=5,
          time_integrator='SSP104',
          disable_output=False,
          output_style=1):

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

    if kernel_language == 'Fortran':
        if ptwise:
            riemann_solver = riemann.acoustics_1D_ptwise
        else:
            riemann_solver = riemann.acoustics_1D

    elif kernel_language == 'Python':
        riemann_solver = riemann.acoustics_1D_py.acoustics_1D

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

    solver.kernel_language = kernel_language

    x = pyclaw.Dimension(0.0, 1.0, 100, name='x')
    domain = pyclaw.Domain(x)
    num_eqn = 2
    state = pyclaw.State(domain, num_eqn)

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

    rho = 1.0  # Material density
    bulk = 1.0  # Material bulk modulus

    state.problem_data['rho'] = rho
    state.problem_data['bulk'] = bulk
    state.problem_data['zz'] = sqrt(rho * bulk)  # Impedance
    state.problem_data['cc'] = sqrt(bulk / rho)  # Sound speed

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

    solver.dt_initial = domain.grid.delta[0] / state.problem_data['cc'] * 0.1

    claw = pyclaw.Controller()
    claw.solution = pyclaw.Solution(state, domain)
    claw.solver = solver
    claw.outdir = outdir
    claw.output_style = output_style
    if output_style == 1:
        claw.tfinal = 1.0
        claw.num_output_times = 10
    elif output_style == 3:
        claw.nstep = 1
        claw.num_output_times = 1
    claw.keep_copy = True
    if disable_output:
        claw.output_format = None
    claw.setplot = setplot

    return claw
Exemplo n.º 20
0
def dry_state(num_cells, eigen_method, entropy_fix, **kargs):
    r"""Run and plot a multi-layer dry state problem"""

    # Construct output and plot directory paths
    name = 'multilayer/dry_state'
    prefix = 'ml_e%s_m%s_fix' % (eigen_method, num_cells)

    if entropy_fix:
        prefix = "".join((prefix, "T"))
    else:
        prefix = "".join((prefix, "F"))
    outdir, plotdir, log_path = runclaw.create_output_paths(
        name, prefix, **kargs)

    # Redirect loggers
    # This is not working for all cases, see comments in runclaw.py
    for logger_name in [
            'pyclaw.io', 'pyclaw.solution', 'plot', 'pyclaw.solver', 'f2py',
            'data'
    ]:
        runclaw.replace_stream_handlers(logger_name,
                                        log_path,
                                        log_file_append=False)

    # Load in appropriate PyClaw version
    if kargs.get('use_petsc', False):
        import clawpack.petclaw as pyclaw
    else:
        import clawpack.pyclaw as pyclaw

    # =================
    # = Create Solver =
    # =================
    if kargs.get('solver_type', 'classic') == 'classic':
        solver = pyclaw.ClawSolver1D(riemann_solver=layered_shallow_water_1D)
    else:
        raise NotImplementedError(
            'Classic is currently the only supported solver.')

    # Solver method parameters
    solver.cfl_desired = 0.9
    solver.cfl_max = 1.0
    solver.max_steps = 5000
    solver.fwave = True
    solver.kernel_language = 'Fortran'
    solver.limiters = 3
    solver.source_split = 1

    # Boundary conditions
    solver.bc_lower[0] = 1
    solver.bc_upper[0] = 1
    solver.aux_bc_lower[0] = 1
    solver.aux_bc_upper[0] = 1

    # Set the before step function
    solver.before_step = lambda solver, solution: ml.step.before_step(
        solver, solution)

    # Use simple friction source term
    solver.step_source = ml.step.friction_source

    # ============================
    # = Create Initial Condition =
    # ============================
    num_layers = 2

    x = pyclaw.Dimension(0.0, 1.0, num_cells)
    domain = pyclaw.Domain([x])
    state = pyclaw.State(domain, 2 * num_layers, 3 + num_layers)
    state.aux[ml.aux.kappa_index, :] = 0.0

    # Set physics data
    state.problem_data['g'] = 9.8
    state.problem_data['manning'] = 0.0
    state.problem_data['rho_air'] = 1.15e-3
    state.problem_data['rho'] = [0.95, 1.0]
    state.problem_data['r'] =   \
                     state.problem_data['rho'][0] / state.problem_data['rho'][1]
    state.problem_data['one_minus_r'] = 1.0 - state.problem_data['r']
    state.problem_data['num_layers'] = num_layers

    # Set method parameters, this ensures it gets to the Fortran routines
    state.problem_data['eigen_method'] = eigen_method
    state.problem_data['dry_tolerance'] = 1e-3
    state.problem_data['inundation_method'] = 2
    state.problem_data['entropy_fix'] = entropy_fix

    solution = pyclaw.Solution(state, domain)
    solution.t = 0.0

    # Set aux arrays including bathymetry, wind field and linearized depths
    ml.aux.set_jump_bathymetry(solution.state, 0.5, [-1.0, -1.0])
    ml.aux.set_no_wind(solution.state)
    ml.aux.set_h_hat(solution.state, 0.5, [0.0, -0.5], [0.0, -1.0])

    # Set sea at rest initial condition
    q_left = [
        0.5 * state.problem_data['rho'][0], 0.0,
        0.5 * state.problem_data['rho'][1], 0.0
    ]
    q_right = [1.0 * state.problem_data['rho'][0], 0.0, 0.0, 0.0]
    ml.qinit.set_riemann_init_condition(solution.state, 0.5, q_left, q_right)

    # ================================
    # = Create simulation controller =
    # ================================
    controller = pyclaw.Controller()
    controller.solution = solution
    controller.solver = solver

    # Output parameters
    controller.output_style = 3
    controller.nstepout = 1
    controller.num_output_times = 100
    controller.write_aux_init = True
    controller.outdir = outdir
    controller.write_aux = True

    # ==================
    # = Run Simulation =
    # ==================
    state = controller.run()

    # ============
    # = Plotting =
    # ============
    plot_kargs = {
        'rho': solution.state.problem_data['rho'],
        'dry_tolerance': solution.state.problem_data['dry_tolerance']
    }
    plot.plot(setplot="./setplot_drystate.py",
              outdir=outdir,
              plotdir=plotdir,
              htmlplot=kargs.get('htmlplot', False),
              iplot=kargs.get('iplot', False),
              file_format=controller.output_format,
              **plot_kargs)
Exemplo n.º 21
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.º 22
0
def em1D(mx=1024,
         num_frames=5,
         cfl=1.0,
         outdir='./_output',
         before_step=True,
         debug=False,
         chi3=0.0,
         chi2=0.0,
         nl=False,
         psi=True,
         em=True,
         homogeneous=True):

    import clawpack.petclaw as pyclaw
    import petsc4py.PETSc as MPI

    if not homogeneous:
        if nl:
            material.chi3_e = chi3
            material.chi2_e = chi2
            if em:
                material.chi3_m = chi3
                material.chi2_m = chi2

    if MPI.COMM_WORLD.rank == 0:
        material._outdir = outdir
        source._outdir = outdir
        material._dump_to_latex()
        source._dump_to_latex()

    num_eqn = 2
    num_waves = 2
    num_aux = 4

    #   grid pre calculations and domain setup
    dx, dt, tf = grid_basic(x_lower, x_upper, mx, cfl)
    x = pyclaw.Dimension('x', x_lower, x_upper, mx)
    domain = pyclaw.Domain([x])

    #   Solver settings
    solver = pyclaw.SharpClawSolver1D()
    solver.num_waves = num_waves
    solver.num_eqn = num_eqn
    solver.weno_order = 5

    solver.dt_variable = True
    solver.dt_initial = dt / 2.0
    solver.dt_max = dt
    solver.max_steps = int(2 * tf / dt)

    #   Set the source
    if not psi:
        print 'using dq_src'
        solver.dq_src = dq_source

#   Import Riemann and Tfluct solvers
    if homogeneous:
        import maxwell_1d_rp
    else:
        import maxwell_1d_nl_rp as maxwell_1d_rp

    solver.tfluct_solver = False
    solver.fwave = True

    solver.rp = maxwell_1d_rp

    if solver.tfluct_solver:
        if homogeneous:
            import maxwell_1d_tfluct
        else:
            import maxwell_1d_nl_tfluct as maxwell_1d_tfluct

        solver.tfluct = maxwell_1d_tfluct

    solver.cfl_max = cfl + 0.05
    solver.cfl_desired = cfl

    #   boundary conditions
    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.reflect_index = [0]

    #   before step configure
    if before_step:
        solver.call_before_step_each_stage = True
        solver.before_step = material.update_aux


#   state setup
    state = pyclaw.State(domain, num_eqn, num_aux)

    state.problem_data['chi2_e'] = material.chi2_e
    state.problem_data['chi3_e'] = material.chi3_e
    state.problem_data['chi2_m'] = material.chi2_m
    state.problem_data['chi3_m'] = material.chi3_m
    state.problem_data['eo'] = material.eo
    state.problem_data['mo'] = material.mo
    state.problem_data['co'] = material.co
    state.problem_data['zo'] = material.zo
    state.problem_data['dx'] = state.grid.x.delta
    state.problem_data['nl'] = nl
    state.problem_data['psi'] = psi

    source._dx = state.grid.x.delta
    material._dx = state.grid.x.delta

    #   array initialization
    source.init(state)
    material.init(state)

    state.q = state.q * state.aux[0:2, :]

    #   controller
    claw = pyclaw.Controller()
    claw.tfinal = tf
    claw.num_output_times = num_frames
    claw.solver = solver
    claw.solution = pyclaw.Solution(state, domain)
    claw.outdir = outdir
    claw.write_aux_always = True

    return claw
Exemplo n.º 23
0
def internal_lapping(num_cells, eigen_method, **kargs):
    r"""docstring for oscillatory_wind"""

    # Construct output and plot directory paths
    prefix = 'ml_e%s_n%s' % (eigen_method, num_cells)
    name = 'lapping'
    outdir, plotdir, log_path = runclaw.create_output_paths(
        name, prefix, **kargs)

    # Redirect loggers
    # This is not working for all cases, see comments in runclaw.py
    for logger_name in ['io', 'solution', 'plot', 'evolve', 'f2py', 'data']:
        runclaw.replace_stream_handlers(logger_name,
                                        log_path,
                                        log_file_append=False)

    # Load in appropriate PyClaw version
    if kargs.get('use_petsc', False):
        import clawpack.petclaw as pyclaw
    else:
        import clawpack.pyclaw as pyclaw

    # =================
    # = Create Solver =
    # =================
    if kargs.get('solver_type', 'classic') == 'classic':
        solver = pyclaw.ClawSolver1D()
    else:
        raise NotImplementedError(
            'Classic is currently the only supported solver.')

    # Solver method parameters
    solver.cfl_desired = 0.9
    solver.cfl_max = 1.0
    solver.max_steps = 5000
    solver.fwave = True
    solver.kernel_language = 'Fortran'
    solver.num_waves = 4
    solver.limiters = 3
    solver.source_split = 1

    # Boundary conditions
    solver.bc_lower[0] = 1
    solver.bc_upper[0] = 1
    solver.aux_bc_lower[0] = 1
    solver.aux_bc_upper[0] = 1

    # Set the Riemann solver
    solver.rp = riemann.rp1_layered_shallow_water

    # Set the before step functioning including the wind forcing
    solver.before_step = lambda solver, solution: ml.step.before_step(
        solver, solution)

    # Use simple friction source term
    solver.step_source = ml.step.friction_source

    # ============================
    # = Create Initial Condition =
    # ============================
    num_layers = 2

    x = pyclaw.Dimension('x', 0.0, 1.0, num_cells)
    domain = pyclaw.Domain([x])
    state = pyclaw.State(domain, 2 * num_layers, 3 + num_layers)
    state.aux[ml.aux.kappa_index, :] = 0.0

    # Set physics data
    state.problem_data['g'] = 9.8
    state.problem_data['manning'] = 0.022
    state.problem_data['rho_air'] = 1.15e-3
    state.problem_data['rho'] = [0.95, 1.0]
    state.problem_data[
        'r'] = state.problem_data['rho'][0] / state.problem_data['rho'][1]
    state.problem_data['one_minus_r'] = 1.0 - state.problem_data['r']
    state.problem_data['num_layers'] = num_layers

    # Set method parameters, this ensures it gets to the Fortran routines
    state.problem_data['eigen_method'] = eigen_method
    state.problem_data['dry_tolerance'] = 1e-3
    state.problem_data['inundation_method'] = 2
    state.problem_data['entropy_fix'] = False

    solution = pyclaw.Solution(state, domain)
    solution.t = 0.0

    # Set aux arrays including bathymetry, wind field and linearized depths
    ml.aux.set_sloped_shelf_bathymetry(solution.state, 0.4, 0.6, -1.0, -0.2)
    ml.aux.set_no_wind(solution.state)
    ml.aux.set_h_hat(solution.state, 0.5, [0.0, -0.6], [0.0, -0.6])

    # Set initial condition
    ml.qinit.set_gaussian_init_condition(solution.state,
                                         0.2,
                                         0.2,
                                         0.01,
                                         internal_layer=True)

    # ================================
    # = Create simulation controller =
    # ================================
    controller = pyclaw.Controller()
    controller.solution = solution
    controller.solver = solver

    # Output parameters
    controller.output_style = 1
    controller.tfinal = 2.0
    controller.num_output_times = 50
    controller.write_aux_init = True
    controller.outdir = outdir
    controller.write_aux = True

    # ==================
    # = Run Simulation =
    # ==================
    state = controller.run()

    # ============
    # = Plotting =
    # ============
    plot_kargs = {
        'rho': solution.state.problem_data['rho'],
        'dry_tolerance': solution.state.problem_data['dry_tolerance']
    }
    plot(setplot_path="./setplot_lapping.py",
         outdir=outdir,
         plotdir=plotdir,
         htmlplot=kargs.get('htmlplot', False),
         iplot=kargs.get('iplot', False),
         file_format=controller.output_format,
         **plot_kargs)
Exemplo n.º 24
0
def setup(use_petsc=0,kernel_language='Fortran',solver_type='classic',outdir='./_output'):
    """
    Stegoton problem.
    Nonlinear elasticity in periodic medium.
    See LeVeque & Yong (2003).

    $$\\epsilon_t - u_x = 0$$
    $$\\rho(x) u_t - \\sigma(\\epsilon,x)_x = 0$$
    """
    from clawpack import riemann

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

    if kernel_language=='Python':
        rs = riemann.nonlinear_elasticity_1D_py.nonlinear_elasticity_1D
    elif kernel_language=='Fortran':
        rs = riemann.nonlinear_elasticity_fwave_1D

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

    solver.kernel_language = kernel_language

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

    #Use the same BCs for the aux array
    solver.aux_bc_lower = solver.bc_lower
    solver.aux_bc_upper = solver.bc_upper

    xlower=0.0; xupper=600.0
    cellsperlayer=6; mx=int(round(xupper-xlower))*cellsperlayer
    x = pyclaw.Dimension('x',xlower,xupper,mx)
    domain = pyclaw.Domain(x)
    state = pyclaw.State(domain,solver.num_eqn)

    #Set global parameters
    alpha = 0.5
    KA    = 1.0
    KB    = 4.0
    rhoA  = 1.0
    rhoB  = 4.0
    state.problem_data = {}
    state.problem_data['t1']    = 10.0
    state.problem_data['tw1']   = 10.0
    state.problem_data['a1']    = 0.0
    state.problem_data['alpha'] = alpha
    state.problem_data['KA'] = KA
    state.problem_data['KB'] = KB
    state.problem_data['rhoA'] = rhoA
    state.problem_data['rhoB'] = rhoB
    state.problem_data['trtime'] = 250.0
    state.problem_data['trdone'] = False

    #Initialize q and aux
    xc=state.grid.x.centers
    state.aux=setaux(xc,rhoB,KB,rhoA,KA,alpha,xlower=xlower,xupper=xupper)
    qinit(state,ic=2,a2=1.0,xupper=xupper)

    tfinal=500.; num_output_times = 10;

    solver.max_steps = 5000000
    solver.fwave = True 
    solver.before_step = b4step 
    solver.user_bc_lower=moving_wall_bc
    solver.user_bc_upper=zero_bc

    claw = pyclaw.Controller()
    claw.keep_copy = False
    claw.output_style = 1
    claw.num_output_times = num_output_times
    claw.tfinal = tfinal
    claw.solution = pyclaw.Solution(state,domain)
    claw.solver = solver

    return claw
Exemplo n.º 25
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
Exemplo n.º 26
0
def euler3d(kernel_language='Fortran',solver_type='classic',\
            use_petsc=False,outdir='./_output',\
            output_format='hdf5',file_prefix='equil',disable_output=False,\
            mx=mxyz[0],my=mxyz[1],mz=mxyz[2],\
            tfinal=64.0,num_output_times=1):

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

    if solver_type == 'classic':
        solver = pyclaw.ClawSolver3D()
        solver.dimensional_split = True
        solver.limiters = pyclaw.limiters.tvd.minmod
        solver.num_ghost = 2
        solver.order = 2
        solver.fwave = True
    elif solver_type == 'sharpclaw':
        solver = pyclaw.SharpClawSolver3D()
    else:
        raise Exception('Unrecognized solver_type.')

    import logging
    solver.logger.setLevel(logging.DEBUG)

    import euler_3d_gmap
    solver.rp = euler_3d_gmap
    solver.num_eqn = 5
    solver.num_waves = 3
    solver.cfl_max = 0.6
    solver.cfl_desired = 0.5
    solver.dt_initial = 1.e-0
    solver.max_steps = 10000

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

    num_aux = 15
    state = pyclaw.State(domain, solver.num_eqn, num_aux)
    state.problem_data['gamma'] = gamma
    state.problem_data['g_r'] = gR
    state.problem_data['gravity'] = gravityTerm
    state.problem_data['gravityflux'] = gravityEflux

    # Grids
    mbc = solver.num_ghost
    grid = state.grid

    # Computational Grid Sizes
    dxc = domain.grid.delta[0]
    dyc = domain.grid.delta[1]
    dzc = domain.grid.delta[2]
    pmx, pmy, pmz = grid.num_cells[0], grid.num_cells[1], grid.num_cells[2]

    # Computational Grid Centers and Edges
    centers = grid.c_centers  # centers (Comp.)
    centersBC = grid.c_centers_with_ghost(mbc)  # centers w Ghost (Comp.)
    edgesBC = grid.c_edges_with_ghost(mbc)  # edges w Ghost (Comp.)

    # Grid Centers Without Boundary Cells (1D Slice) - Comp. and Phys.
    xcc = grid.x.centers  # x centers (Comp.)
    ycc = grid.y.centers  # y centers (Comp.)
    zcc = grid.z.centers  # z centers (Comp.)
    xcp, ycp, zcp = mg.mapc2pwrapper(xcc, ycc, zcc, pmz, xyzMin, xyzMax,
                                     mapType)

    # Grid Centers Without Boundary Cells (3D Arrays)
    Xcc, Ycc, Zcc = centers[0][:][:][:], centers[1][:][:][:], centers[
        2][:][:][:]
    Xcp, Ycp, Zcp = mg.mapc2pwrapper(Xcc, Ycc, Zcc, pmz, xyzMin, xyzMax,
                                     mapType)
    Xcp = np.reshape(Xcp, [pmx, pmy, pmz], order='F')  # x centers (Phys.)
    Ycp = np.reshape(Ycp, [pmx, pmy, pmz], order='F')  # y centers (Phys.)
    Zcp = np.reshape(Zcp, [pmx, pmy, pmz], order='F')  # z centers (Phys.)

    # Grid Edges With Boundary Cells (1D Slice along z)- Comp. and Phys.
    xecZ = edgesBC[0][0][0][:]  # x edges along z (Comp.)
    yecZ = edgesBC[1][0][0][:]  # y edges along z (Comp.)
    zecZ = edgesBC[2][0][0][:]  # z edges along z (Comp.)
    xepZ, yepZ, zepZ = mg.mapc2pwrapper(xecZ, yecZ, zecZ, pmz, xyzMin, xyzMax,
                                        mapType)

    # Grid Centers With Boundary Cells (1D Slice along z) - Comp. and Phys.
    global zcpZ
    xccZ = centersBC[0][0][0][:]  # x centers along z (Comp.)
    yccZ = centersBC[1][0][0][:]  # y centers along z (Comp.)
    zccZ = centersBC[2][0][0][:]  # z centers along z (Comp.)
    xcpZ, ycpZ, zcpZ = mg.mapc2pwrapper(xccZ, yccZ, zccZ, pmz, xyzMin, xyzMax,
                                        mapType)

    if np.sqrt(xepZ[0]**2 + yepZ[0]**2 + zepZ[0]**2) <= 0:
        print "WARNING: z may go below Earth's surface", " zepZ: ", zepZ[0:10]

    # Create vectors for 1D pressure and density column with boundary cells
    mz0 = pmz + 2 * mbc
    global p0, rho0, Mavg
    p0 = np.zeros([mz0], dtype='float', order='F')
    rho0 = np.zeros([mz0], dtype='float', order='F')
    Mavg = np.zeros([mz0], dtype='float', order='F')

    # Set the equilibrium pressure such that dp/dz = -rho*gR
    p0, rho0, Mavg = setEquilibriumAtmosphere(p0, rho0, Mavg)

    # Modify the equilibrium such that dp/dz = -rho*gR is held numerically
    p0 = modifyEquilibriumAtmosphere(zepZ, p0, rho0)

    # Set the auxiliary variables
    xlower, ylower, zlower = edgesBC[0][0][0][0], edgesBC[1][0][0][0], edgesBC[
        2][0][0][0]
    dxc, dyc, dzc = domain.grid.delta[0], domain.grid.delta[
        1], domain.grid.delta[2]

    global auxtmp
    auxtmp = np.zeros([num_aux, pmx + 2 * mbc, pmy + 2 * mbc, pmz + 2 * mbc],
                      dtype='float',
                      order='F')
    auxtmp = mg.setauxiliaryvariables(num_aux, mbc, pmx, pmy, pmz, xlower,
                                      ylower, zlower, dxc, dyc, dzc, xyzMin,
                                      xyzMax, mapType)
    state.aux[:, :, :, :] = auxtmp[:, mbc:-mbc, mbc:-mbc, mbc:-mbc]

    # Set Index for Capcaity Function in state.aux (Python 0-based)
    state.index_capa = 12

    # Set the state variables (Initial Conditions)

    # Initialize p,T,velSqrd
    p = np.zeros([pmx, pmy, pmz], dtype='float', order='F')
    T = np.zeros([pmx, pmy, pmz], dtype='float', order='F')
    velSqrd = np.zeros([pmx, pmy, pmz], dtype='float', order='F')

    # Density
    for i in range(pmx):
        for j in range(pmy):
            # NEEDS TO BE FIXED WHEN MPI SLICES NORMAL TO Z
            state.q[0, i, j, :] = rho0[mbc:pmz + mbc]

    # Momentum
    state.q[1, :, :, :] = 0.  # x-momentum (rho*u)
    state.q[2, :, :, :] = 0.  # y-momentum (rho*v)
    state.q[3, :, :, :] = 0.  # z-momentum (rho*w)

    # Velocity Squared (u**2+v**2+w**2)
    velSqrd[:, :, :] = (state.q[1, :, :, :]**2 + state.q[2, :, :, :]**2 +
                        state.q[3, :, :, :]**2) / state.q[0, :, :, :]**2

    # Energy
    for i in range(pmx):
        for j in range(pmy):
            # NEEDS TO BE FIXED WHEN MPI SLICES NORMAL TO Z
            p[i, j, :] = p0[mbc:pmz + mbc]
    state.q[4, :, :, :] = p / gamma1 + 0.5 * state.q[
        0, :, :, :] * velSqrd + state.q[0, :, :, :] * (
            gR) * Zcp[:, :, :] * gFlux

    # Add Temperature Perturbation
    T = p / state.q[0, :, :, :]
    L = np.sqrt((Xcp - xSphere)**2 + (Ycp - ySphere)**2 + (Zcp - zSphere)**2)
    for i in range(pmx):
        for j in range(pmy):
            for k in range(pmz):
                if L[i, j, k] <= rSphere:
                    mu = Mavg[k + mbc] / nAvogadro
                    T[i, j, k] += TSphere * (kBoltzmann /
                                             mu) * (1.0 - L[i, j, k] / rSphere)
                    p[i, j, k] = T[i, j, k] * state.q[0, i, j, k]
    state.q[4, :, :, :] = p / gamma1 + 0.5 * state.q[
        0, :, :, :] * velSqrd + state.q[0, :, :, :] * (
            gR) * Zcp[:, :, :] * gFlux  # energy (e)

    # Setup Boundary Conditions

    # X - Boundary Conditions
    solver.bc_lower[0] = pyclaw.BC.extrap
    solver.bc_upper[0] = pyclaw.BC.extrap

    # Y - Boundary Conditions
    solver.bc_lower[1] = pyclaw.BC.extrap
    solver.bc_upper[1] = pyclaw.BC.extrap

    # Z - Boundary Conditions
    solver.bc_lower[2] = pyclaw.BC.custom
    solver.bc_upper[2] = pyclaw.BC.custom
    solver.user_bc_lower = customBCLowerZ
    solver.user_bc_upper = customBCUpperZ

    # Aux - Boundary Conditions
    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
    solver.aux_bc_lower[2] = pyclaw.BC.custom
    solver.aux_bc_upper[2] = pyclaw.BC.custom
    solver.user_aux_bc_lower = customAuxBCLowerZ
    solver.user_aux_bc_upper = customAuxBCUpperZ

    # Solver Parameters
    claw = pyclaw.Controller()
    claw.verbosity = 4
    claw.solution = pyclaw.Solution(state, domain)
    claw.solver = solver
    claw.output_format = output_format
    claw.output_file_prefix = file_prefix
    claw.keep_copy = False
    if disable_output:
        claw.output_format = None
    claw.tfinal = tfinal
    claw.num_output_times = num_output_times
    claw.outdir = outdir
    #state.mp = 1
    #claw.compute_p = outputDensity

    return claw
Exemplo n.º 27
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.º 28
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
Exemplo n.º 29
0
def setup(use_petsc=False,
          kernel_language='Fortran',
          outdir='./_output',
          solver_type='sharpclaw',
          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.dq_src = dq_swe
        # solver.dq_src = fortran_src_wrapper # use fortran subroutine
        # solver.call_before_step_each_stage = False # default is False
        solver.weno_order = 5
        solver.lim_type = 2  # weno resonstruction
        solver.cfl_max = 0.21
        solver.cfl_desired = 0.20
    else:
        # solver = pyclaw.ClawSolver2D(riemann.euler_5wave_2D)
        solver.step_source = step_swe
        solver.source_split = 1  # Godunov splitting
        # 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

    # to remove maximum time step restriction using a sufficiently large number
    solver.max_steps = 1000000000

    solver.kernel_language = kernel_language

    solver.user_bc_lower = incoming_sin

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

    solver.before_step = b4step

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

    # Auxiliary array
    solver.aux_bc_lower[0] = pyclaw.BC.periodic
    solver.aux_bc_upper[0] = pyclaw.BC.periodic

    # 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.: normal flow
    state.q[depth, :] = normal_depth
    state.q[momentum, :] = normal_velocity * normal_depth

    # X = state.grid.x.centers
    # state.p_centers does not work, dont know why
    # state.aux[0,:] = channel_slope*(1.0 + dist_amp * np.sin(2.0 * np.pi * X/wave_length))
    # state.aux[0,:] = bathymetry(X)

    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
Exemplo n.º 30
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