Exemplo n.º 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,
        )
Exemplo n.º 2
0
Arquivo: job.py Projeto: jeandet/PHARE
ElectromagDiagnostics(
    diag_type="E",                  # available : ("E", "B")
    write_every=10,
    compute_every=5,
    start_teration=0,
    last_iteration=990,
    path = 'ElectromagDiagnostics1'   # where output files will be written, [default: name]
)


FluidDiagnostics(
    diag_type="density",            # choose in (rho_s, flux_s)
    write_every=10,                 # write on disk every x iterations
    compute_every=5,                # compute diagnostics every x iterations ( x <= write_every)
    start_iteration=0,              # iteration at which diag is enabled
    last_iteration=990,             # iteration at which diag is turned off
    population_name="protons"       # name of the population for which the diagnostics is made
  #,path = 'FluidDiagnostics1'      # where output files will be written, [default: name]
)


FluidDiagnostics(
    diag_type="bulkVelocity",
    write_every=10,
    compute_every=5,
    start_iteration=0,
    last_iteration=990,
    population_name="background"
)
Exemplo n.º 3
0
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,
        )
Exemplo n.º 4
0
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,
        )
Exemplo n.º 5
0
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,
        )
Exemplo n.º 6
0
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,
            )
Exemplo n.º 7
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
Exemplo n.º 8
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,
            )
Exemplo n.º 9
0
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,
            )