コード例 #1
0
ファイル: ion_ion_beam1d.py プロジェクト: rochSmets/PHARE
def main():
    from pybindlibs.cpp import mpi_rank

    config()
    simulator = Simulator(gv.sim)
    simulator.initialize()
    simulator.run()

    if mpi_rank() == 0:

        times, first_mode, ampl, gamma, damped_mode, omega \
                = growth_b_right_hand(os.path.join(os.curdir, "ion_ion_beam1d"))

        fig, (ax1, ax2) = plt.subplots(2, 1)

        ax1.set_title("Right Hand Resonant mode (Beam instability)")
        ax1.stem(times, first_mode, linefmt='-k', basefmt=' ', use_line_collection=True)
        ax1.plot(times, yaebx(times, ampl, gamma), color='r', linestyle='-', marker='')
        ax1.text(0.04, 0.80, "From Gary et al., 1985 (ApJ : 10.1086/162797)", transform=ax1.transAxes)
        ax1.set_ylabel("Most unstable mode")
        ax1.set_title("Right Hand Resonant mode (Beam instability)")
        ax1.text(0.30, 0.50, "gamma = {:5.3f}... expected 0.09".format(gamma), transform=ax1.transAxes)

        ax2.plot(times, damped_mode, color='g', linestyle='', marker='o')
        ax2.set_xlabel("Time")
        ax2.set_ylabel("Real mode")
        ax2.text(0.48, 0.30, "~ 3 periods until t=50", transform=ax2.transAxes)
        ax2.text(0.40, 0.20, "omega (real) = {:5.3f}... expected 0.19".format(omega), transform=ax2.transAxes)

        fig.savefig("ion_ion_beam1d.png")

        # compare with the values given gary et al. 1985
        assert np.fabs(gamma-0.09) < 2e-2
コード例 #2
0
def main():
    config()
    simulator = Simulator(gv.sim)
    simulator.initialize()
    simulator.run()

    if cpp.mpi_rank() == 0:
        b = hierarchy_from(h5_filename="phare_outputs/EM_B.h5")
        plot(b)
コード例 #3
0
def main():

    for name,config in zip(("uni", "td"),(config_uni, config_td)):
        params=[{"vx":-1,"diagdir":name + "_vxm2"},
                {"vx":2,"diagdir":name + "_vx2"}]
        for param in params:
            if param["vx"] >-1:
                continue
            print("-----------------------------------")
            print(param)
            print("-----------------------------------")
            config(**param)
            simulator = Simulator(gv.sim)
            simulator.initialize()
            simulator.run()
            gv.sim = None
コード例 #4
0
def main():

    cases = [0.01,0.05,0.1,0.3,0.5,0.75,1,2]

    dls = [0.2, 0.1]
    nbrcells = [100,200]
    nbrdts = [25000, 100000]

    for vth in cases:
        for dl, nbrcell, nbrdt in zip(dls, nbrcells, nbrdts):
            uniform(vth, dl, nbrcell, nbrdt)
            simulator = Simulator(gv.sim)
            simulator.initialize()
            simulator.run()
            gv.sim = None



    paths = glob("*vth*")
    runs_vth = {}
    Bnrj_vth = {}
    K_vth = {}
    times_vth={}

    #extract vth and dx from the name of the directory
    vthdx = np.asarray(sorted([[float(x) for x in path.split("/")[-1].strip("vth").split("dx")] for path in paths],
                   key=lambda x:x[1]))

    paths = sorted(paths, key=lambda path: float(paths[0].split("/")[-1].strip("vth").split("dx")[1]))

    #now for each directory, extract magnetic and kinetic energies
    for path in paths:
        runs_vth[path], Bnrj_vth[path], K_vth[path], times_vth[path] = energies(path)


    # we want to plot things as a function of the thermal velocity
    # for dx=0.1 and 0.2 so extract their values
    vth0p2 = np.asarray([x[0] for x in vthdx if x[1] == 0.2])
    vth0p1 = np.asarray([x[0] for x in vthdx if x[1] == 0.1])

    # we will plot the variation of the kinetic energy
    # relative to is "initial value", by "initial" we mean
    # its average over some time interval at the start of the run.
    # here we take 3,4 because before there is some kind of irrelevant transient
    K0 = {}
    for path,K in K_vth.items():
            it1, it2 = avg_interval(3,4, times_vth[path])
            K0[path] = np.mean(K[it1:it2+1])


    # calculate the relative variation of kinetic enery for both cases
    rel_K0p2 = np.asarray([np.abs(K[-1]-K0[path])/K0[path]*100 for path,K in K_vth.items() if "dx0.2" in path])
    rel_K0p1 = np.asarray([np.abs(K[-1]-K0[path])/K0[path]*100 for path,K in K_vth.items() if "dx0.1" in path])

    fig, ax = plt.subplots()
    id2 = np.argsort(vth0p2)
    id1 = np.argsort(vth0p1)
    ax.plot(vth0p2[id2], rel_K0p2[id2], marker="o", label="dx = 0.2 (dt=0.002, 25k steps)")
    ax.plot(vth0p1[id1], rel_K0p1[id1], marker="o", label="dx = 0.1 (dt=5e-4, 100k steps)")
    ax.set_xscale("log")
    ax.set_yscale("log")
    ax.set_ylabel(r"$\Delta K$ (%)")
    ax.set_xlabel("Vth")
    ax.set_title("kinetic energy evolution as a function of Vth")
    ax.legend()

    fig.tight_layout()
    fig.savefig("K.png")
コード例 #5
0
ファイル: shock.py プロジェクト: PHAREHUB/pharebook
def main():
    config()
    simulator = Simulator(gv.sim)
    simulator.initialize()
    simulator.run()
コード例 #6
0
ファイル: harris_2d.py プロジェクト: PhilipDeegan/PHARE
def main():
    config()
    s = Simulator(gv.sim, post_advance=post_advance)
    s.initialize()
    post_advance(0)
    s.run()
コード例 #7
0
ファイル: dispersion.py プロジェクト: rochSmets/PHARE
def main():
    fromNoise()
    simulator = Simulator(gv.sim)
    simulator.initialize()
    simulator.run()