Ejemplo n.º 1
0
def stress(current_data):
    import numpy as np
    from psystem_2d import setaux

    aux = setaux(current_data.x[:, 0], current_data.y[0, :])
    q = current_data.q
    return np.exp(aux[1, ...] * q[0, ...]) - 1.0
Ejemplo n.º 2
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=(x_upper-x_lower)*cells_per_layer; 
    my=(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

    # Boundary conditions
    bc_x_lower=pyclaw.BC.wall; bc_x_upper=pyclaw.BC.extrap
    bc_y_lower=pyclaw.BC.wall; bc_y_upper=pyclaw.BC.extrap

    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')

    solver.bc_lower     = [bc_x_lower, bc_y_lower]
    solver.bc_upper     = [bc_x_upper, bc_y_upper]
    solver.aux_bc_lower = [bc_x_lower, bc_y_lower]
    solver.aux_bc_upper = [bc_x_upper, bc_y_upper]

    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',x_lower,x_upper,mx)
        y = pyclaw.Dimension('y',y_lower,y_upper,my)
        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
Ejemplo n.º 3
0
def stress(current_data):
    import numpy as np
    from psystem_2d import setaux
    aux = setaux(current_data.x[:, 0], current_data.y[0, :])
    q = current_data.q
    return np.exp(aux[1, ...] * q[0, ...]) - 1.
Ejemplo n.º 4
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 = (x_upper - x_lower) * cells_per_layer
    my = (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