コード例 #1
0
def withTagging(**kwargs):

    Simulation(smallest_patch_size=20,
               largest_patch_size=20,
               time_step_nbr=2000,
               final_time=20.,
               boundary_types="periodic",
               cells=200,
               dl=1.0,
               refinement="tagging",
               max_nbr_levels=3,
               diag_options={
                   "format": "phareh5",
                   "options": {
                       "dir": kwargs["diagdir"],
                       "mode": "overwrite"
                   }
               })

    MaxwellianFluidModel(bx=bx,
                         by=by,
                         bz=bz,
                         protons={
                             "charge": 1,
                             "density": density,
                             **vvv
                         })

    ElectronModel(closure="isothermal", Te=0.12)

    sim = ph.global_vars.sim

    timestamps = all_timestamps(sim)

    for quantity in ["E", "B"]:
        ElectromagDiagnostics(
            quantity=quantity,
            write_timestamps=timestamps,
            compute_timestamps=timestamps,
        )

    for quantity in ["density", "bulkVelocity"]:
        FluidDiagnostics(
            quantity=quantity,
            write_timestamps=timestamps,
            compute_timestamps=timestamps,
        )
コード例 #2
0
def uniform(vth, dl, cells, nbr_steps):

    Simulation(
        smallest_patch_size=20,
        largest_patch_size=20,
        time_step_nbr=nbr_steps,
        final_time=50.,
        boundary_types="periodic",
        cells=cells,
        dl=dl,
        diag_options={"format": "phareh5",
                      "options": {"dir": "vth{}dx{}".format(vth,dl),
                                  "mode":"overwrite"}}
    )

    def density(x):
        return 1.

    def by(x):
        return 0.

    def bz(x):
        return 0.

    def bx(x):
        return 1.

    def vx(x):
        return 0.

    def vy(x):
        return 0.

    def vz(x):
        return 0.

    def vthx(x):
        return vth

    def vthy(x):
        return vth

    def vthz(x):
        return vth


    vvv = {
        "vbulkx": vx, "vbulky": vy, "vbulkz": vz,
        "vthx": vthx, "vthy": vthy, "vthz": vthz
    }

    MaxwellianFluidModel(
        bx=bx, by=by, bz=bz,
        protons={"charge": 1, "density": density, **vvv}
    )

    ElectronModel(closure="isothermal", Te=0.)

    sim = ph.global_vars.sim

    timestamps = np.arange(0, sim.final_time, 50*sim.time_step)

    for quantity in ["B"]:
        ElectromagDiagnostics(
            quantity=quantity,
            write_timestamps=timestamps,
            compute_timestamps=timestamps,
        )

    for name in ["domain", "levelGhost", "patchGhost"]:
        ParticleDiagnostics(quantity=name,
                            compute_timestamps=timestamps,
                            write_timestamps=timestamps,
                            population_name="protons")
コード例 #3
0
ファイル: job.py プロジェクト: jeandet/PHARE

#------------------------------------
#     configure the simulation
#------------------------------------

Simulation(
    time_step_nbr=1000,                   # number of time steps (not specified if time_step and final_time provided)
    final_time=1.,                        # simulation final time (not specified if time_step and time_step_nbr given)
    boundary_types="periodic",            # boundary condition, string or tuple, length == len(cell) == len(dl)
    cells=80,                             # integer or tuple length == dimension
    dl=0.1,                               # mesh size of the root level, float or tuple
    path='test5'                          # directory where INI file and diagnostics directories will be
    # time_step = 0.005,                  # simulation time step (not specified if time_step_nbr and final_time given)
    # domain_size = 8.,                   # float or tuple, not specified if dl and cells are
    # interp_order = 1,                   # interpolation order, [default = 1] can be 1, 2, 3 or 4
    # layout = "yee",                     # grid layout, [default="yee"]
    # origin = 0.,                        # position of the origin of the domain, float or tuple (length = dimension)
    # particle_pusher = "modified_boris", # particle pusher method, [default = "modified_boris"]
    # refined_particle_nbr = 2,           # number of refined particle a particle is split into [default : ]
    # diag_export_format = 'ascii',       # export format of the diagnostics [default = 'ascii']
    # refinement = {"level":[0,1],        # AMR parameters
    #                "extent_ratio":[0.4, 0.6],
    #                "refinement_iterations":[0, 3]},

) # end Simulation





コード例 #4
0
ファイル: alfven_wave1d.py プロジェクト: PhilipDeegan/PHARE
def config():

    # configure the simulation

    Simulation(
        smallest_patch_size=50,
        largest_patch_size=50,
        time_step_nbr=
        100000,  # number of time steps (not specified if time_step and final_time provided)
        final_time=
        1000,  # simulation final time (not specified if time_step and time_step_nbr provided)
        boundary_types=
        "periodic",  # boundary condition, string or tuple, length == len(cell) == len(dl)
        cells=1000,  # integer or tuple length == dimension
        dl=1,  # mesh size of the root level, float or tuple
        hyper_resistivity=0.001,
        refinement_boxes={"L0": {
            "B0": [(450, ), (550, )]
        }},
        diag_options={
            "format": "phareh5",
            "options": {
                "dir": ".",
                "mode": "overwrite"
            }
        })

    def density(x):
        return 1.

    def by(x):
        from pyphare.pharein.global_vars import sim
        L = sim.simulation_domain()
        return 0.01 * np.cos(2 * np.pi * x / L[0])

    def bz(x):
        from pyphare.pharein.global_vars import sim
        L = sim.simulation_domain()
        return 0.01 * np.sin(2 * np.pi * x / L[0])

    def bx(x):
        return 1.

    def vx(x):
        return 0.

    def vy(x):
        from pyphare.pharein.global_vars import sim
        L = sim.simulation_domain()
        return 0.01 * np.cos(2 * np.pi * x / L[0])

    def vz(x):
        from pyphare.pharein.global_vars import sim
        L = sim.simulation_domain()
        return 0.01 * np.sin(2 * np.pi * x / L[0])

    def vthx(x):
        return 0.01

    def vthy(x):
        return 0.01

    def vthz(x):
        return 0.01

    vvv = {
        "vbulkx": vx,
        "vbulky": vy,
        "vbulkz": vz,
        "vthx": vthx,
        "vthy": vthy,
        "vthz": vthz
    }

    MaxwellianFluidModel(bx=bx,
                         by=by,
                         bz=bz,
                         protons={
                             "charge": 1,
                             "density": density,
                             **vvv
                         })

    ElectronModel(closure="isothermal", Te=0.0)

    timestamps = all_timestamps(gv.sim)

    for quantity in ["E", "B"]:
        ElectromagDiagnostics(
            quantity=quantity,
            write_timestamps=timestamps,
            compute_timestamps=timestamps,
        )

    for quantity in ["density", "bulkVelocity"]:
        FluidDiagnostics(
            quantity=quantity,
            write_timestamps=timestamps,
            compute_timestamps=timestamps,
        )
コード例 #5
0
ファイル: ion_ion_beam1d.py プロジェクト: rochSmets/PHARE
def config():

    # most unstable mode at k=0.19, that is lambda = 33
    # hence the length of the box is 33, and the fourier mode will be 1

    Simulation(
        smallest_patch_size=20,
        largest_patch_size=60,
        final_time=50,
        time_step=0.0005,
        boundary_types="periodic",
        cells=165,
        dl=0.2,
        hyper_resistivity = 0.01,
        refinement_boxes={"L0": {"B0": [( 50, ), (110, )]},
                          "L1": {"B0": [(140, ), (180, )]} },
        diag_options={"format": "phareh5",
                      "options": {"dir": "ion_ion_beam1d", "mode": "overwrite"}}
    )

    def densityMain(x):
        return 1.

    def densityBeam(x):
        return .01

    def bx(x):
        return 1.

    def by(x):
        return 0.

    def bz(x):
        return 0.

    def vB(x):
        return 5.

    def v0(x):
        return 0.

    def vth(x):
        return np.sqrt(0.1)


    vMain = {
        "vbulkx": v0, "vbulky": v0, "vbulkz": v0,
        "vthx": vth, "vthy": vth, "vthz": vth
    }


    vBulk = {
        "vbulkx": vB, "vbulky": v0, "vbulkz": v0,
        "vthx": vth, "vthy": vth, "vthz": vth
    }


    MaxwellianFluidModel(
        bx=bx, by=by, bz=bz,
        main={"charge": 1, "density": densityMain, **vMain},
        beam={"charge": 1, "density": densityBeam, **vBulk}
    )

    ElectronModel(closure="isothermal", Te=0.0)

    sim = ph.global_vars.sim

    timestamps = np.arange(0, sim.final_time, 1.)

    for quantity in ["B"]:
        ElectromagDiagnostics(
            quantity=quantity,
            write_timestamps=timestamps,
            compute_timestamps=timestamps,
        )
コード例 #6
0
import numpy as np

# configure the simulation

Simulation(
    smallest_patch_size=20,
    largest_patch_size=20,
    time_step_nbr=
    300,  # number of time steps (not specified if time_step and final_time provided)
    time_step=
    .001,  # simulation final time (not specified if time_step and time_step_nbr provided)
    boundary_types=
    "periodic",  # boundary condition, string or tuple, length == len(cell) == len(dl)
    cells=40,  # integer or tuple length == dimension
    dl=0.3,  # mesh size of the root level, float or tuple
    #max_nbr_levels=2,          # (default=1) max nbr of levels in the AMR hierarchy
    #refinement = "tagging",
    refinement_boxes={"L0": {
        "B0": [(10, ), (20, )]
    }},
    diag_options={
        "format": "phareh5",
        "options": {
            "dir": "phare_outputs",
            "mode": "overwrite"
        }
    })


def density(x):
    return 1.
コード例 #7
0
ファイル: shock.py プロジェクト: PHAREHUB/pharebook
def config():
    """ Configure the simulation

    This function defines the Simulation object,
    user initialization model and diagnostics.
    """
    Simulation(
        smallest_patch_size=20,
        largest_patch_size=20,
        time_step_nbr=
        6000,  # number of time steps (not specified if time_step and final_time provided)
        final_time=
        30,  # simulation final time (not specified if time_step and time_step_nbr provided)
        boundary_types=
        "periodic",  # boundary condition, string or tuple, length == len(cell) == len(dl)
        cells=2500,  # integer or tuple length == dimension
        dl=0.2,  # mesh size of the root level, float or tuple
        #max_nbr_levels=1,          # (default=1) max nbr of levels in the AMR hierarchy
        nesting_buffer=0,
        refinement_boxes={"L0": {
            "B0": [(125, ), (750, )]
        }},
        diag_options={
            "format": "phareh5",
            "options": {
                "dir": "shock_20dx_dx02_refined",
                "mode": "overwrite"
            }
        })

    def density(x):
        from pyphare.pharein.global_vars import sim
        L = sim.simulation_domain()[0]
        v1 = 1
        v2 = 1.
        return v1 + (v2 - v1) * (S(x, L * 0.2, 1) - S(x, L * 0.8, 1))

    def S(x, x0, l):
        return 0.5 * (1 + np.tanh((x - x0) / l))

    def bx(x):
        return 0.

    def by(x):
        from pyphare.pharein.global_vars import sim
        L = sim.simulation_domain()[0]
        v1 = 0.125
        v2 = 4.0
        return v1 + (v2 - v1) * (S(x, L * 0.2, 1) - S(x, L * 0.8, 1))

    def bz(x):
        return 0.

    def T(x):
        return 0.1

    def vx(x):
        from pyphare.pharein.global_vars import sim
        L = sim.simulation_domain()[0]
        v1 = 0.
        v2 = 0.
        return v1 + (v2 - v1) * (S(x, L * 0.25, 1) - S(x, L * 0.75, 1))

    def vy(x):
        return 0.

    def vz(x):
        return 0.

    def vthx(x):
        return T(x)

    def vthy(x):
        return T(x)

    def vthz(x):
        return T(x)

    vvv = {
        "vbulkx": vx,
        "vbulky": vy,
        "vbulkz": vz,
        "vthx": vthx,
        "vthy": vthy,
        "vthz": vthz
    }

    MaxwellianFluidModel(bx=bx,
                         by=by,
                         bz=bz,
                         protons={
                             "charge": 1,
                             "density": density,
                             **vvv
                         })

    ElectronModel(closure="isothermal", Te=0.12)

    sim = ph.global_vars.sim

    timestamps = np.arange(0, sim.final_time + sim.time_step, sim.time_step)

    for quantity in ["E", "B"]:
        ElectromagDiagnostics(
            quantity=quantity,
            write_timestamps=timestamps,
            compute_timestamps=timestamps,
        )

    for quantity in ["density", "bulkVelocity"]:
        FluidDiagnostics(
            quantity=quantity,
            write_timestamps=timestamps,
            compute_timestamps=timestamps,
        )
コード例 #8
0
ファイル: td1d.py プロジェクト: rochSmets/PHARE
def config():
    """ Configure the simulation

    This function defines the Simulation object,
    user initialization model and diagnostics.
    """
    Simulation(
        smallest_patch_size=20,
        largest_patch_size=20,
        time_step_nbr=
        2000,  # number of time steps (not specified if time_step and final_time provided)
        final_time=
        20.,  # simulation final time (not specified if time_step and time_step_nbr provided)
        boundary_types=
        "periodic",  # boundary condition, string or tuple, length == len(cell) == len(dl)
        cells=500,  # integer or tuple length == dimension
        dl=1.,  # mesh size of the root level, float or tuple
        refinement_boxes={
            "L0": {
                "B0": [(80, ), (180, )]
            },
            "L1": {
                "B0": [(200, ), (300, )]
            }
        },
        diag_options={
            "format": "phareh5",
            "options": {
                "dir": "td_noflow",
                "mode": "overwrite"
            }
        })

    def density(x):
        return 1.

    def S(x, x0, l):
        return 0.5 * (1 + np.tanh((x - x0) / l))

    def bx(x):
        return 0.

    def by(x):
        from pyphare.pharein.global_vars import sim
        L = sim.simulation_domain()[0]
        v1 = -1
        v2 = 1.
        return v1 + (v2 - v1) * (S(x, L * 0.25, 1) - S(x, L * 0.75, 1))

    def bz(x):
        return 0.5

    def b2(x):
        return bx(x)**2 + by(x)**2 + bz(x)**2

    def T(x):
        K = 1
        return 1 / density(x) * (K - b2(x) * 0.5)

    def vx(x):
        return 0.

    def vy(x):
        return 0.

    def vz(x):
        return 0.

    def vthx(x):
        return T(x)

    def vthy(x):
        return T(x)

    def vthz(x):
        return T(x)

    vvv = {
        "vbulkx": vx,
        "vbulky": vy,
        "vbulkz": vz,
        "vthx": vthx,
        "vthy": vthy,
        "vthz": vthz
    }

    MaxwellianFluidModel(bx=bx,
                         by=by,
                         bz=bz,
                         protons={
                             "charge": 1,
                             "density": density,
                             **vvv
                         })

    ElectronModel(closure="isothermal", Te=0.12)

    sim = ph.global_vars.sim

    dt_dump = 0.1
    n_dump = int(sim.final_time / dt_dump) + 1
    timestamps = np.linspace(0, sim.final_time, n_dump)

    for quantity in ["E", "B"]:
        ElectromagDiagnostics(
            quantity=quantity,
            write_timestamps=timestamps,
            compute_timestamps=timestamps,
        )

    for quantity in ["density", "bulkVelocity"]:
        FluidDiagnostics(
            quantity=quantity,
            write_timestamps=timestamps,
            compute_timestamps=timestamps,
        )
コード例 #9
0
ファイル: job.py プロジェクト: rochSmets/PHARE
from pyphare.pharein import ElectromagDiagnostics
from pyphare.pharein import ElectronModel

# configure the simulation

Simulation(
    smallest_patch_size=10,
    largest_patch_size=64,
    time_step_nbr=
    1000,  # number of time steps (not specified if time_step and final_time provided)
    final_time=
    1.,  # simulation final time (not specified if time_step and time_step_nbr provided)
    boundary_types=
    "periodic",  # boundary condition, string or tuple, length == len(cell) == len(dl)
    cells=65,  # integer or tuple length == dimension
    dl=1. / 65,  # mesh size of the root level, float or tuple
    refinement_boxes={"L0": {
        "B0": [(10, ), (50, )]
    }},
    diag_options={
        "format": "phareh5",
        "options": {
            "dir": "phare_outputs",
            "mode": "overwrite"
        }
    })

density = lambda x: 2.

bx, by, bz = (lambda x: 1 for i in range(3))
ex, ey, ez = (lambda x: 1 for i in range(3))
コード例 #10
0
ファイル: td1dtagged.py プロジェクト: nicolasaunai/PHARE
def config():
    """ Configure the simulation

    This function defines the Simulation object,
    user initialization model and diagnostics.
    """
    Simulation(
        smallest_patch_size=10,
        largest_patch_size=20,
        time_step_nbr=2000,        # number of time steps (not specified if time_step and final_time provided)
        final_time=20,             # simulation final time (not specified if time_step and time_step_nbr provided)
        boundary_types="periodic", # boundary condition, string or tuple, length == len(cell) == len(dl)
        cells=400,                # integer or tuple length == dimension
        dl=0.5,                  # mesh size of the root level, float or tuple
        max_nbr_levels=3,          # (default=1) max nbr of levels in the AMR hierarchy
        nesting_buffer=2,
        refinement = "tagging",
        diag_options={"format": "phareh5", "options": {"dir": "refine_dx05_lvl3","mode":"overwrite"}}
    )


    def density(x):
        return 1.


    def S(x,x0,l):
        return 0.5*(1+np.tanh((x-x0)/l))


    def bx(x):
        return 0.


    def by(x):
        from pyphare.pharein.global_vars import sim
        L = sim.simulation_domain()[0]
        v1=-1
        v2=1.
        return v1 + (v2-v1)*(S(x,L*0.25,1) -S(x, L*0.75, 1))


    def bz(x):
        return 0.5


    def b2(x):
        return bx(x)**2 + by(x)**2 + bz(x)**2


    def T(x):
        K = 1
        return 1/density(x)*(K - b2(x)*0.5)


    def vx(x):
        return 1.


    def vy(x):
        return 0.


    def vz(x):
        return 0.


    def vthx(x):
        return T(x)


    def vthy(x):
        return T(x)


    def vthz(x):
        return T(x)


    vvv = {
        "vbulkx": vx, "vbulky": vy, "vbulkz": vz,
        "vthx": vthx, "vthy": vthy, "vthz": vthz
    }

    MaxwellianFluidModel(
        bx=bx, by=by, bz=bz,
        protons={"charge": 1, "density": density, **vvv}
    )

    ElectronModel(closure="isothermal", Te=0.12)



    timestamps = all_timestamps(gv.sim)



    for quantity in ["E", "B"]:
        ElectromagDiagnostics(
            quantity=quantity,
            write_timestamps=timestamps,
            compute_timestamps=timestamps,
        )


    for quantity in ["density", "bulkVelocity"]:
        FluidDiagnostics(
            quantity=quantity,
            write_timestamps=timestamps,
            compute_timestamps=timestamps,
            )
コード例 #11
0
ファイル: harris_2d.py プロジェクト: PhilipDeegan/PHARE
def config():

    Simulation(
        smallest_patch_size=15,
        largest_patch_size=25,
        time_step_nbr=1000,
        time_step=0.001,
        # boundary_types="periodic",
        cells=(100, 100),
        dl=(0.2, 0.2),
        refinement_boxes={},
        hyper_resistivity=0.001,
        resistivity=0.001,
        diag_options={
            "format": "phareh5",
            "options": {
                "dir": diag_outputs,
                "mode": "overwrite"
            }
        },
        strict=True,
    )

    def density(x, y):
        from pyphare.pharein.global_vars import sim
        L = sim.simulation_domain()[1]
        return 0.2 + 1. / np.cosh((y - L * 0.3) / 0.5)**2 + 1. / np.cosh(
            (y - L * 0.7) / 0.5)**2

    def S(y, y0, l):
        return 0.5 * (1. + np.tanh((y - y0) / l))

    def by(x, y):
        from pyphare.pharein.global_vars import sim
        Lx = sim.simulation_domain()[0]
        Ly = sim.simulation_domain()[1]
        w1 = 0.2
        w2 = 1.0
        x0 = (x - 0.5 * Lx)
        y1 = (y - 0.3 * Ly)
        y2 = (y - 0.7 * Ly)
        w3 = np.exp(-(x0 * x0 + y1 * y1) / (w2 * w2))
        w4 = np.exp(-(x0 * x0 + y2 * y2) / (w2 * w2))
        w5 = 2.0 * w1 / w2
        return (w5 * x0 * w3) + (-w5 * x0 * w4)

    def bx(x, y):
        from pyphare.pharein.global_vars import sim
        Lx = sim.simulation_domain()[0]
        Ly = sim.simulation_domain()[1]
        w1 = 0.2
        w2 = 1.0
        x0 = (x - 0.5 * Lx)
        y1 = (y - 0.3 * Ly)
        y2 = (y - 0.7 * Ly)
        w3 = np.exp(-(x0 * x0 + y1 * y1) / (w2 * w2))
        w4 = np.exp(-(x0 * x0 + y2 * y2) / (w2 * w2))
        w5 = 2.0 * w1 / w2
        v1 = -1
        v2 = 1.
        return v1 + (v2 - v1) * (S(y, Ly * 0.3, 0.5) - S(y, Ly * 0.7, 0.5)) + (
            -w5 * y1 * w3) + (+w5 * y2 * w4)

    def bz(x, y):
        return 0.

    def b2(x, y):
        return bx(x, y)**2 + by(x, y)**2 + bz(x, y)**2

    def T(x, y):
        K = 1
        temp = 1. / density(x, y) * (K - b2(x, y) * 0.5)
        assert np.all(temp > 0)
        return temp

    def vx(x, y):
        return 0.

    def vy(x, y):
        return 0.

    def vz(x, y):
        return 0.

    def vthx(x, y):
        return np.sqrt(T(x, y))

    def vthy(x, y):
        return np.sqrt(T(x, y))

    def vthz(x, y):
        return np.sqrt(T(x, y))

    vvv = {
        "vbulkx": vx,
        "vbulky": vy,
        "vbulkz": vz,
        "vthx": vthx,
        "vthy": vthy,
        "vthz": vthz,
        "nbr_part_per_cell": 100
    }

    MaxwellianFluidModel(
        bx=bx,
        by=by,
        bz=bz,
        protons={
            "charge": 1,
            "density": density,
            **vvv, "init": {
                "seed": 12334
            }
        },
    )

    ElectronModel(closure="isothermal", Te=0.0)

    sim = ph.global_vars.sim
    dt = 10 * sim.time_step
    nt = sim.final_time / dt + 1
    timestamps = (dt * np.arange(nt))

    for quantity in ["E", "B"]:
        ElectromagDiagnostics(
            quantity=quantity,
            write_timestamps=timestamps,
            compute_timestamps=timestamps,
        )
コード例 #12
0
def config(diag_outputs, model_init={}, refinement_boxes=None):
    ph.global_vars.sim = None

    Simulation(
        smallest_patch_size=10,
        largest_patch_size=20,
        time_step_nbr= 1,
        final_time= 0.001,
        #boundary_types="periodic",
        cells=(50, 100),
        dl=(0.40, 0.40),
        #refinement="tagging",
        #max_nbr_levels = 3,
        refinement_boxes=refinement_boxes,
        hyper_resistivity=0.0050,
        resistivity=0.001,
        diag_options={"format": "phareh5",
                      "options": {"dir": diag_outputs,
                                  "mode":"overwrite", "fine_dump_lvl_max": 10}}
    )
    def density(x, y):
        from pyphare.pharein.global_vars import sim
        Lx = sim.simulation_domain()[0]
        return 1.

    def bx(x, y):
        return 0.1

    def by(x, y):
        from pyphare.pharein.global_vars import sim
        Lx = sim.simulation_domain()[0]
        Ly = sim.simulation_domain()[1]
        return 0.2

    def bz(x, y):
        return 1.

    def T(x, y):
        return 1.

    def vx(x, y):
        return 1.0

    def vy(x, y):
        return 0.

    def vz(x, y):
        return 0.

    def vthx(x, y):
        return np.sqrt(T(x, y))

    def vthy(x, y):
        return np.sqrt(T(x, y))

    def vthz(x, y):
        return np.sqrt(T(x, y))

    vvv = {
        "vbulkx": vx, "vbulky": vy, "vbulkz": vz,
        "vthx": vthx, "vthy": vthy, "vthz": vthz,
        "nbr_part_per_cell":100,
        "init": model_init,
    }

    MaxwellianFluidModel(
        bx=bx, by=by, bz=bz,
        protons={"charge": 1, "density": density,  **vvv}
    )

    ElectronModel(closure="isothermal", Te=0.0)
    sim = ph.global_vars.sim
    dt =  1*sim.time_step
    nt = sim.final_time/dt+1
    timestamps = dt * np.arange(nt)

    for quantity in ["E", "B"]:
        ElectromagDiagnostics(
            quantity=quantity,
            write_timestamps=timestamps,
            compute_timestamps=timestamps,
        )

    for quantity in ["density", "bulkVelocity"]:
        FluidDiagnostics(
            quantity=quantity,
            write_timestamps=timestamps,
            compute_timestamps=timestamps,
            )

    return sim
コード例 #13
0
def config_uni(**kwargs):
    """ Configure the simulation

    This function defines the Simulation object,
    user initialization model and diagnostics.
    """
    Simulation(
        smallest_patch_size=20,
        largest_patch_size=20,
        time_step_nbr=2000,        # number of time steps (not specified if time_step and final_time provided)
        final_time=20.,             # simulation final time (not specified if time_step and time_step_nbr provided)
        boundary_types="periodic", # boundary condition, string or tuple, length == len(cell) == len(dl)
        cells=500,                # integer or tuple length == dimension
        dl=1.0,                  # mesh size of the root level, float or tuple
        refinement_boxes={"L0": {"B0": [(100, ), (200, )]},
                          "L1":{"B0":[(300,),(350,)]}},
        diag_options={"format": "phareh5", "options": {"dir": kwargs["diagdir"],"mode":"overwrite"}}
    )


    def density(x):
        return 1.

    def bx(x):
        return 0.

    def by(x):
        return 1.

    def bz(x):
        return 0.5


    def vx(x):
        return kwargs["vx"]

    def vy(x):
        return 0.

    def vz(x):
        return 0.


    def vthx(x):
        return 0.1


    def vthy(x):
        return 0.1


    def vthz(x):
        return 0.1


    vvv = {
        "vbulkx": vx, "vbulky": vy, "vbulkz": vz,
        "vthx": vthx, "vthy": vthy, "vthz": vthz
    }

    MaxwellianFluidModel(
        bx=bx, by=by, bz=bz,
        protons={"charge": 1, "density": density, **vvv}
    )

    ElectronModel(closure="isothermal", Te=0.12)



    timestamps = all_timestamps(gv.sim)



    for quantity in ["E", "B"]:
        ElectromagDiagnostics(
            quantity=quantity,
            write_timestamps=timestamps,
            compute_timestamps=timestamps,
        )


    for quantity in ["density", "bulkVelocity"]:
        FluidDiagnostics(
            quantity=quantity,
            write_timestamps=timestamps,
            compute_timestamps=timestamps,
            )
コード例 #14
0
def setup(**kwargs):
    from pyphare.pharein import Simulation, MaxwellianFluidModel
    from pyphare.pharein import ElectronModel, ElectromagDiagnostics, FluidDiagnostics
    import matplotlib as mpl

    mpl.use("Agg")

    def getFn(key):
        return kwargs.get(key, globals()["_" + key])

    density = getFn("density")
    bx, by, bz = getFn("bx"), getFn("by"), getFn("bz")
    vx, vy, vz = getFn("vx"), getFn("vy"), getFn("vz")
    vthx, vthy, vthz = getFn("vthx"), getFn("vthy"), getFn("vthz")

    ndim = kwargs.get("ndim", 1)
    interp = kwargs.get("ndim", 1)
    smallest_patch_size = kwargs.get("smallest_patch_size", 20)
    largest_patch_size = kwargs.get("largest_patch_size", 20)
    time_step_nbr = kwargs.get("time_step_nbr", 100)
    final_time = kwargs.get("final_time", 0.1)
    cells = [kwargs.get("cells", 100)] * ndim
    dl = [kwargs.get("dl", 0.2)] * ndim
    Te = kwargs.get("Te", 0.12)
    charge = kwargs.get("charge", 1)
    ppc = kwargs.get("ppc", 10)
    boundary_types = [kwargs.get("boundary_types", "periodic")] * ndim
    diag_dir = kwargs.get("diag_dir", ".")

    Simulation(
        interp_order=interp,
        smallest_patch_size=smallest_patch_size,
        largest_patch_size=largest_patch_size,
        time_step_nbr=time_step_nbr,
        final_time=final_time,
        boundary_types=boundary_types,
        cells=cells,
        dl=dl,
        diag_options={
            "format": "phareh5",
            "options": {
                "dir": diag_dir,
                "mode": "overwrite"
            },
        },
    )
    MaxwellianFluidModel(
        bx=bx,
        by=by,
        bz=bz,
        protons={
            "charge": charge,
            "density": density,
            "nbr_part_per_cell": ppc,
            **{
                "vbulkx": vx,
                "vbulky": vy,
                "vbulkz": vz,
                "vthx": vthx,
                "vthy": vthy,
                "vthz": vthz,
            },
        },
    )
    ElectronModel(closure="isothermal", Te=Te)
コード例 #15
0
ファイル: dispersion.py プロジェクト: rochSmets/PHARE
def fromNoise():

    # in this configuration there are no prescribed waves
    # and only eigen modes existing in the simulation noise
    # will be visible

    Simulation(
        smallest_patch_size=20,
        largest_patch_size=20,

        # the following time step number
        # and final time mean that the
        # smallest frequency will be 2/100
        # and the largest 2/dt  = 2e3
        time_step_nbr=100000,
        final_time=100.,

        boundary_types="periodic",

        # smallest wavelength will be 2*0.2=0.4
        # and largest 50
        cells=500,
        dl=0.2,
        diag_options={"format": "phareh5",
                      "options": {"dir": "dispersion",
                                  "mode":"overwrite"}}
    )

    def density(x):
        return 1.


    def by(x):
        return 0.


    def bz(x):
        return 0.


    def bx(x):
        return 1.


    def vx(x):
        return 0.


    def vy(x):
        return 0.

    def vz(x):
        return 0.


    def vthx(x):
        return 0.01


    def vthy(x):
        return 0.01


    def vthz(x):
        return 0.01


    vvv = {
        "vbulkx": vx, "vbulky": vy, "vbulkz": vz,
        "vthx": vthx, "vthy": vthy, "vthz": vthz
    }

    MaxwellianFluidModel(
        bx=bx, by=by, bz=bz,
        protons={"charge": 1, "density": density, **vvv}
    )

    ElectronModel(closure="isothermal", Te=0.)


    sim = ph.global_vars.sim

    timestamps = np.arange(0, sim.final_time +sim.time_step, sim.time_step)

    for quantity in ["E", "B"]:
        ElectromagDiagnostics(
            quantity=quantity,
            write_timestamps=timestamps,
            compute_timestamps=timestamps,
        )
コード例 #16
0
ファイル: dispersion.py プロジェクト: rochSmets/PHARE
def prescribedModes():

    # in this configuration there user prescribed
    # wavelength, at which more energy is thus expected
    # than in modes naturally present in the simulation noise

    Simulation(
        smallest_patch_size=20,
        largest_patch_size=20,

        # the following time step number
        # and final time mean that the
        # smallest frequency will be 2/100
        # and the largest 2/dt  = 2e3
        time_step_nbr=100000,
        final_time=100.,

        boundary_types="periodic",

        # smallest wavelength will be 2*0.2=0.4
        # and largest 50
        cells=500,
        dl=0.2,
        diag_options={"format": "phareh5", "options": {"dir": "dispersion",
                                                       "mode":"overwrite"}}
    )

    def density(x):
        return 1.


    def by(x):
        from pyphare.pharein.global_vars import sim
        L = sim.simulation_domain()
        return 0.1*np.cos(2*np.pi*x/L[0])


    def bz(x):
        from pyphare.pharein.global_vars import sim
        L = sim.simulation_domain()
        return -0.1*np.sin(2*np.pi*x/L[0])


    def bx(x):
        return 1.


    def vx(x):
        return 0.


    def vy(x):
        from pyphare.pharein.global_vars import sim
        L = sim.simulation_domain()
        return 0.1*np.cos(2*np.pi*x/L[0])

    def vz(x):
        from pyphare.pharein.global_vars import sim
        L = sim.simulation_domain()
        return 0.1*np.sin(2*np.pi*x/L[0])


    def vthx(x):
        return 0.01


    def vthy(x):
        return 0.01


    def vthz(x):
        return 0.01


    vvv = {
        "vbulkx": vx, "vbulky": vy, "vbulkz": vz,
        "vthx": vthx, "vthy": vthy, "vthz": vthz
    }

    MaxwellianFluidModel(
        bx=bx, by=by, bz=bz,
        protons={"charge": 1, "density": density, **vvv}
    )

    ElectronModel(closure="isothermal", Te=0.)



    sim = ph.global_vars.sim

    timestamps = np.arange(0, sim.final_time +sim.time_step, sim.time_step)



    for quantity in ["E", "B"]:
        ElectromagDiagnostics(
            quantity=quantity,
            write_timestamps=timestamps,
            compute_timestamps=timestamps,
        )


    for quantity in ["density", "bulkVelocity"]:
        FluidDiagnostics(
            quantity=quantity,
            write_timestamps=timestamps,
            compute_timestamps=timestamps,
            )