예제 #1
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
예제 #2
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
예제 #3
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
예제 #4
0
파일: wcblast.py 프로젝트: sconde/pyclaw
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
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
예제 #6
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
예제 #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
예제 #8
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
예제 #9
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
예제 #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
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
예제 #12
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)
예제 #13
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
예제 #14
0
파일: cubic.py 프로젝트: wilsonify/pyclaw
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
예제 #15
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
예제 #16
0
파일: dam_break.py 프로젝트: yoon-gu/pyclaw
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
예제 #17
0
파일: shocksine.py 프로젝트: yoon-gu/pyclaw
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
예제 #18
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
예제 #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
예제 #20
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
예제 #21
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
예제 #22
0
def em1D(mx=1024,
         num_frames=10,
         use_petsc=True,
         reconstruction_order=5,
         lim_type=2,
         cfl=1.0,
         conservative=True,
         chi3=0.0,
         chi2=0.0,
         nl=False,
         psi=True,
         em=True,
         before_step=False,
         debug=False,
         outdir='./_output',
         output_style=1):

    if use_petsc:
        import clawpack.petclaw as pyclaw
        import petsc4py.PETSc as MPI
    else:
        from clawpack import pyclaw

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

    if np.logical_and(use_petsc, MPI.COMM_WORLD.rank == 0):
        basics.set_outdirs(material, source, outdir=outdir, debug=debug)
    else:
        basics.set_outdirs(material, source, outdir=outdir, debug=debug)

    num_eqn = 2
    num_waves = 2
    num_aux = 4

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

    #   Solver settings
    solver = pyclaw.SharpClawSolver1D()
    solver.num_waves = num_waves
    solver.num_eqn = num_eqn
    solver.reconstruction_order = 5
    solver.lim_type = 2

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

    #   Import Riemann and Tfluct solvers
    if conservative:
        from emclaw.riemann import maxwell_1d_rp
    else:
        from emclaw.riemann import maxwell_1d_nc_rp as maxwell_1d_rp

    solver.tfluct_solver = True
    solver.fwave = True

    solver.rp = maxwell_1d_rp

    if solver.tfluct_solver:
        if conservative:
            from emclaw.riemann import maxwell_1d_tfluct
        else:
            from emclaw.riemann import maxwell_1d_nc_tfluct as maxwell_1d_tfluct

        solver.tfluct = maxwell_1d_tfluct

    solver.cfl_max = cfl + 0.5
    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
    state.problem_data['conservative'] = conservative

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

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

    if conservative:
        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
    claw.output_style = output_style

    return claw
예제 #23
0
파일: stegoton.py 프로젝트: sconde/pyclaw
def stegoton(use_petsc=0,kernel_language='Fortran',solver_type='classic',iplot=0,htmlplot=0,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$$
    """

    vary_Z=False

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

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

    solver.kernel_language = kernel_language
    from clawpack.riemann import rp_nonlinear_elasticity
    if kernel_language=='Python':
        solver.rp = rp_nonlinear_elasticity.rp_nonlinear_elasticity_1d
    elif kernel_language=='Fortran':
        from clawpack import riemann
        solver.rp = riemann.rp1_nonlinear_elasticity_fwave

    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)
    num_eqn = 2
    state = pyclaw.State(domain,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
    solver.num_waves=2

    if solver_type=='sharpclaw':
        solver.lim_type = 2
        solver.char_decomp=0

    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


    if vary_Z==True:
        #Zvalues = [1.0,1.2,1.4,1.6,1.8,2.0,2.2,2.4,2.6,2.8,3.0,3.5,4.0]
        Zvalues = [3.5,4.0]
        #a2values= [0.9766161130681, 1.0888194560100042, 1.1601786315361329, 1.20973731651806, 1.2462158254919984]

        for ii,Z in enumerate(Zvalues):
            a2=1.0 #a2values[ii]
            KB = Z
            rhoB = Z
            state.problem_data['KB'] = KB
            state.problem_data['rhoB'] = rhoB
            state.problem_data['trdone'] = False
            state.aux=setaux(xc,rhoB,KB,rhoA,KA,alpha,bc_lower,xupper=xupper)
            patch.x.bc_lower=2
            patch.x.bc_upper=2
            state.t = 0.0
            qinit(state,ic=2,a2=a2)
            init_solution = Solution(state,domain)
            claw.solution = init_solution
            claw.solution.t = 0.0

            claw.tfinal = tfinal
            claw.outdir = './_output_Z'+str(Z)+'_'+str(cellsperlayer)
            status = claw.run()

    else:
        # Solve
        status = claw.run()

    if htmlplot:  pyclaw.plot.html_plot(outdir=outdir)
    if iplot:     pyclaw.plot.interactive_plot(outdir=outdir)
예제 #24
0
파일: acoustics.py 프로젝트: yoon-gu/pyclaw
def acoustics(use_petsc=False,
              kernel_language='Fortran',
              solver_type='classic',
              iplot=False,
              htmlplot=False,
              outdir='./_output',
              weno_order=5):
    """
    This example solves the 1-dimensional acoustics equations in a homogeneous
    medium.
    """
    import numpy as np

    #=================================================================
    # Import the appropriate classes, depending on the options passed
    #=================================================================
    if use_petsc:
        import clawpack.petclaw as pyclaw
    else:
        from clawpack import pyclaw

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

    #========================================================================
    # Instantiate the solver and define the system of equations to be solved
    #========================================================================
    solver.kernel_language = kernel_language
    from clawpack.riemann import rp_acoustics
    solver.num_waves = rp_acoustics.num_waves
    if kernel_language == 'Python':
        solver.rp = rp_acoustics.rp_acoustics_1d

    solver.limiters = pyclaw.limiters.tvd.MC
    solver.bc_lower[0] = pyclaw.BC.wall
    solver.bc_upper[0] = pyclaw.BC.wall

    solver.cfl_desired = 1.0
    solver.cfl_max = 1.0

    #========================================================================
    # Instantiate the grid and set the boundary conditions
    #========================================================================
    x = pyclaw.Dimension('x', 0.0, 1.0, 200)
    grid = pyclaw.Grid(x)
    num_eqn = 2
    state = pyclaw.State(grid, num_eqn)

    #========================================================================
    # Set problem-specific variables
    #========================================================================
    rho = 1.0
    bulk = 1.0
    state.problem_data['rho'] = rho
    state.problem_data['bulk'] = bulk
    state.problem_data['zz'] = np.sqrt(rho * bulk)
    state.problem_data['cc'] = np.sqrt(bulk / rho)

    #========================================================================
    # Set the initial condition
    #========================================================================
    xc = grid.x.center
    state.q[0, :] = np.cos(2 * np.pi * xc)
    state.q[1, :] = 0.

    #========================================================================
    # Set up the controller object
    #========================================================================
    claw = pyclaw.Controller()
    claw.solution = pyclaw.Solution(state)
    claw.solver = solver
    claw.outdir = outdir
    claw.num_output_times = 40
    claw.tfinal = 2.0

    # Solve
    status = claw.run()

    # Plot results
    if htmlplot: pyclaw.plot.html_plot(outdir=outdir)
    if iplot: pyclaw.plot.interactive_plot(outdir=outdir)
예제 #25
0
def setup(use_petsc=False,
          outdir='./_output',
          solver_type='classic',
          kernel_language='Fortran',
          disable_output=False):

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

    if kernel_language == 'Python':
        raise Exception('Not implemented.')
    elif kernel_language == 'Fortran':
        rs = riemann.mhd_roe_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(-4.0, 4.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

    pressure = 1.0
    B1_l = 1.5
    B1_r = 1.5
    B2_l = 0.5
    B2_r = 1.6
    B3_l = 0.6
    B3_r = 0.2
    state.q[density, :] = 1.0
    state.q[momentum_1, :] = 0.0
    state.q[momentum_2, :] = 0.0
    state.q[momentum_3, :] = 0.0
    state.q[B_1, :] = (x < 0.) * B1_l + (x >= 0.) * B1_r
    state.q[B_2, :] = (x < 0.) * B2_l + (x >= 0.) * B2_r
    state.q[B_3, :] = (x < 0.) * B3_l + (x >= 0.) * B3_r
    state.q[energy, :] = pressure / (gamma - 1.) + 0.5 * (
        state.q[momentum_1, :]**2 + state.q[momentum_2, :]**2 +
        state.q[momentum_3, :]**2) / state.q[density, :] + 0.5 * (
            state.q[B_1, :]**2 + state.q[B_2, :]**2 + state.q[B_3, :]**2)

    claw = pyclaw.Controller()
    claw.tfinal = 1.0
    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
예제 #26
0
def setup(use_petsc=False,
          kernel_language='Fortran',
          solver_type='classic',
          outdir='./_output',
          weno_order=5,
          disable_output=False):
    """
    This example solves the 1-dimensional acoustics equations in a homogeneous
    medium.
    """
    from numpy import sqrt, exp, cos
    from clawpack import riemann

    #=================================================================
    # Import the appropriate classes, depending on the options passed
    #=================================================================
    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.acoustics_1D)
        elif kernel_language == 'Python':
            solver = pyclaw.ClawSolver1D(riemann.acoustics_1D_py.acoustics_1D)
    elif solver_type == 'sharpclaw':
        if kernel_language == 'Fortran':
            solver = pyclaw.SharpClawSolver1D(riemann.acoustics_1D)
        elif kernel_language == 'Python':
            solver = pyclaw.SharpClawSolver1D(
                riemann.acoustics_1D_py.acoustics_1D)
        solver.weno_order = weno_order
    else:
        raise Exception('Unrecognized value of solver_type.')

    #========================================================================
    # Instantiate the solver and define the system of equations to be solved
    #========================================================================
    solver.kernel_language = kernel_language

    solver.limiters = pyclaw.limiters.tvd.MC

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

    #========================================================================
    # Instantiate the domain and set the boundary conditions
    #========================================================================
    x = pyclaw.Dimension('x', 0.0, 1.0, 100)
    domain = pyclaw.Domain(x)
    num_eqn = 2
    state = pyclaw.State(domain, num_eqn)

    #========================================================================
    # Set problem-specific variables
    #========================================================================
    rho = 1.0
    bulk = 1.0

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

    #========================================================================
    # Set the initial condition
    #========================================================================
    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.

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

    #========================================================================
    # Set up the controller object
    #========================================================================
    claw = pyclaw.Controller()
    claw.solution = pyclaw.Solution(state, domain)
    claw.solver = solver
    claw.outdir = outdir
    claw.keep_copy = True
    claw.num_output_times = 5
    if disable_output:
        claw.output_format = None
    claw.tfinal = 1.0

    return claw
예제 #27
0
def setup(use_petsc=False,
          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':
        rs = riemann.advection_nonlinear_1D_py.advection_nonlinear_1D
    elif kernel_language == 'Fortran':
        print('No fortran solver available for advection_nonlinear_1D')
        pass

    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.custom
    solver.bc_upper[0] = pyclaw.BC.custom
    solver.user_bc_lower = lowerdirichlet
    solver.user_bc_upper = upperdirichlet

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

    # Gravitational constant
    state.problem_data['u_rel'] = np.array([1., 1 / 30.])
    state.problem_data['efix'] = False

    xc = state.grid.x.centers

    IC = 'dam-break'
    # IC = 'uniform-all'
    # IC = 'perturbation'
    x0 = xc[2]

    if IC == 'uniform-all':
        c0 = np.array([0.2, 0.0])
        # state defaults to empty. Convert to ones and fill with c0
        state.q = np.ones_like(state.q) * c0[:, np.newaxis]

    elif IC == 'dam-break':
        # I changed state.is_valid() to always return true for fortran contiguity
        cr0 = np.array([0.2, 0.0])
        cl0 = np.array([0.0, 0.0])
        state.q = np.ones_like(state.q)
        state.q = cl0[:,np.newaxis]*(xc <= x0)[np.newaxis,:] + \
                  cr0[:,np.newaxis]*(xc >  x0)[np.newaxis,:]
        state.q[0, -1] = 1.

# Change these later to reflect initial conditions
# 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':
        # x1 = x0
        x1 = 0.3
        x2 = 0.7
        eps = 0.1
        state.q[0, :] = eps * np.exp(-1 / eps * (xc - x1)**2)
        state.q[1, :] = eps * np.exp(-1 / eps * (xc - x1)**2)

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

    return claw
예제 #28
0
def setup(use_petsc=0,
          kernel_language='Fortran',
          solver_type='classic',
          outdir='./_output'):
    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.custom
    solver.bc_upper[0] = pyclaw.BC.extrap

    #Use the same BCs for the aux array
    solver.aux_bc_lower[0] = pyclaw.BC.extrap
    solver.aux_bc_upper[0] = pyclaw.BC.extrap

    xlower = 0.0
    xupper = 300.0
    cells_per_layer = 12
    mx = int(round(xupper - xlower)) * cells_per_layer
    x = pyclaw.Dimension(xlower, xupper, mx, name='x')
    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.1
    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'] = 999999999.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=1, a2=1.0, xupper=xupper)

    tfinal = 500.
    num_output_times = 20

    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.output_style = 1
    claw.num_output_times = num_output_times
    claw.tfinal = tfinal
    claw.solution = pyclaw.Solution(state, domain)
    claw.solver = solver
    claw.setplot = setplot
    claw.keep_copy = True

    return claw
예제 #29
0
def setup(use_petsc=False,
          outdir='./_output',
          solver_type='sharpclaw',
          kernel_language='Fortran'):

    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 = 'SSP33'
        solver.cfl_max = 0.65
        solver.cfl_desired = 0.6
        try:
            import sharpclaw1
            solver.fmod = sharpclaw1
            solver.tfluct_solver = True
            solver.lim_type = 1  # TVD reconstruction
            solver.char_decomp = 2  # characteristic-wise reconstructiong
        except ImportError:
            pass
    elif solver_type == 'classic':
        solver = pyclaw.ClawSolver1D(rs)
        solver.limiters = 4

    solver.kernel_language = kernel_language

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

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

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

    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

    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
예제 #30
0
def setup(use_petsc=False,
          kernel_language='Fortran',
          outdir='./_output',
          solver_type='classic',
          riemann_solver='roe',
          disable_output=False):
    if use_petsc:
        import clawpack.petclaw as pyclaw
    else:
        from clawpack import pyclaw

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

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

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

    solver.kernel_language = kernel_language

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

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

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

    xc = state.grid.x.centers

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

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

    return claw