예제 #1
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
예제 #2
0
def em3D(mx=64,
         my=64,
         mz=64,
         num_frames=10,
         cfl=1.0,
         outdir='./_output',
         use_petsc=True,
         before_step=False,
         debug=False,
         nl=False,
         psi=True):
    import clawpack.petclaw as pyclaw
    import petsc4py.PETSc as MPI

    if np.logical_and(debug, MPI.COMM_WORLD.rank == 0):
        material.dump()
        source.dump()

    num_eqn = 6
    num_waves = 4
    num_aux = 12

    #   grid pre calculations and domain setup
    _, _, _, dt, tf = basics.grid_basic(
        [[x_lower, x_upper, mx], [y_lower, y_upper, my],
         [z_lower, z_upper, mz]],
        cfl=cfl,
        co=material.co,
        v=source.v)

    x = pyclaw.Dimension(
        x_lower,
        x_upper,
        mx,
        name='x',
    )
    y = pyclaw.Dimension(
        y_lower,
        y_upper,
        my,
        name='y',
    )
    z = pyclaw.Dimension(
        z_lower,
        z_upper,
        mz,
        name='z',
    )

    domain = pyclaw.Domain([x, y, z])

    #   Solver settings
    solver = pyclaw.SharpClawSolver3D()
    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
    from emclaw.riemann import maxwell_3d_nc_rp as maxwell_3d_rp
    from emclaw.riemann import maxwell_3d_nc_tfluct as maxwell_3d_tfluct

    solver.tfluct_solver = True
    solver.fwave = True

    solver.rp = maxwell_3d_rp
    solver.tfluct = maxwell_3d_tfluct

    solver.cfl_max = cfl + 0.5
    solver.cfl_desired = cfl
    solver.reflect_index = [1, 0, 5]

    #   boundary conditions
    solver.bc_lower[0] = pyclaw.BC.wall
    solver.bc_lower[1] = pyclaw.BC.wall
    solver.bc_lower[2] = pyclaw.BC.wall
    solver.bc_upper[0] = pyclaw.BC.wall
    solver.bc_upper[1] = pyclaw.BC.wall
    solver.bc_upper[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
    solver.aux_bc_upper[0] = pyclaw.BC.wall
    solver.aux_bc_upper[1] = pyclaw.BC.wall
    solver.aux_bc_upper[2] = pyclaw.BC.wall

    #   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'] = material.chi2
    state.problem_data['chi3'] = material.chi3
    state.problem_data['co'] = material.co
    state.problem_data['zo'] = material.zo
    state.problem_data['eo'] = material.eo
    state.problem_data['mo'] = material.mo
    state.problem_data['dx'] = state.grid.x.delta
    state.problem_data['dy'] = state.grid.y.delta
    state.problem_data['dz'] = state.grid.z.delta
    state.problem_data['nl'] = nl
    state.problem_data['psi'] = psi

    source._delta[0] = state.grid.x.delta
    source._delta[1] = state.grid.y.delta
    source._delta[2] = state.grid.z.delta

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

    #   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
예제 #3
0
def em2D(mx=128,
         my=128,
         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,
         heading='x',
         shape='off',
         transversal_shape='plane',
         wavelength=1.0,
         average_source=False,
         debug=False,
         outdir='./_output',
         output_style=1,
         output_format='hdf5',
         write_aux=True,
         disable_output=False,
         keep_copy=True,
         verbosity=3):

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

    source = Source2D(material, shape=shape, wavelength=wavelength)
    source.amplitude[1] = source.amplitude[2] = 1000.0 / material.zo

    if shape == 'off':
        source.offset.fill(5.0)
        if heading == 'xy':
            source.offset[0] = sy / 2.0
            source.offset[1] = sx / 2.0
    else:
        source.offset[0] = -5.0
        source.offset[1] = sy / 2.0
        source.transversal_offset = sy / 2.0
        source.transversal_width = sy
        source.transversal_shape = transversal_shape
    source.setup()
    source.heading = heading
    source.averaged = average_source

    #   grid pre calculations and domain setup
    _, _, dt, tf = basics.grid_basic(
        [[x_lower, x_upper, mx], [y_lower, y_upper, my]],
        cfl=cfl,
        co=material.co,
        v=source.v)

    if (debug and MPI.COMM_WORLD.rank == 0):
        material.dump()
        source.dump()

    num_eqn = 3
    num_waves = 2
    num_aux = 6

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

    #   Solver settings
    solver = pyclaw.SharpClawSolver2D()
    solver.num_waves = num_waves
    solver.num_eqn = num_eqn
    solver.reconstruction_order = reconstruction_order
    solver.lim_type = lim_type
    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_2d_rp
    else:
        from emclaw.riemann import maxwell_2d_nc_rp as maxwell_2d_rp

    solver.tfluct_solver = True
    solver.fwave = True

    solver.rp = maxwell_2d_rp

    if solver.tfluct_solver:
        if conservative:
            from emclaw.riemann import maxwell_2d_tfluct
        else:
            from emclaw.riemann import maxwell_2d_nc_tfluct as maxwell_2d_tfluct

    solver.tfluct = maxwell_2d_tfluct

    solver.cfl_max = cfl + 0.5
    solver.cfl_desired = cfl
    solver.reflect_index = [1, 0]

    #   boundary conditions
    if shape == 'off':
        solver.bc_lower[0] = pyclaw.BC.wall
        solver.aux_bc_lower[0] = pyclaw.BC.wall
    else:
        solver.bc_lower[0] = pyclaw.BC.custom
        solver.aux_bc_lower[0] = pyclaw.BC.custom
        solver.user_bc_lower = source.scattering_bc
        solver.user_aux_bc_lower = material.setaux_lower

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

    solver.aux_bc_lower[1] = pyclaw.BC.wall
    solver.aux_bc_upper[0] = pyclaw.BC.wall
    solver.aux_bc_upper[1] = pyclaw.BC.wall

    #   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'] = material.chi2
    state.problem_data['chi3'] = material.chi3
    state.problem_data['vac1'] = material.eo
    state.problem_data['vac2'] = material.eo
    state.problem_data['vac3'] = 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['dy'] = state.grid.y.delta
    state.problem_data['nl'] = nl
    state.problem_data['psi'] = psi

    source._dx = state.grid.x.delta
    source._dy = state.grid.y.delta

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

    if conservative:
        state.q = state.q * state.aux[0:3, :, :]


#   controller
    claw = pyclaw.Controller()
    claw.solution = pyclaw.Solution(state, domain)
    claw.solver = solver
    claw.keep_copy = keep_copy
    claw.tfinal = tf
    claw.num_output_times = num_frames
    claw.output_style = output_style
    if np.logical_or(disable_output, output_format == None):
        claw.output_format = None
    else:
        claw.output_format = output_format
        claw.outdir = outdir
        claw.write_aux_always = write_aux

    if verbosity == False: verbosity = 0
    claw.verbosity = verbosity

    return claw