Example #1
0
def mirror__ebfield(inpFile=None):

    x_, y_, z_ = 0, 1, 2
    vx_, vy_, vz_ = 3, 4, 5

    # ------------------------------------------------- #
    # --- [0] preparation                           --- #
    # ------------------------------------------------- #

    if (inpFile is None):

        print("[mirror__ebfield.py] inpFile ( def. dat/efield.dat ) >> ??? ")
        inpFile = input()

        if (len(inpFile) == 0):
            print("[mirror__ebfield.py] def. dat/efield.dat ")
            inpFile = "dat/efield.dat"

    # ------------------------------------------------- #
    # --- [1] load field                            --- #
    # ------------------------------------------------- #

    import nkUtilities.load__pointFile as lpf
    Data = lpf.load__pointFile(inpFile=inpFile, returnType="structured")
    ret = np.copy(Data)
    ret[:, :, :, 3:6] = np.copy(Data[::-1, :, :, 3:6])

    Data_ = np.reshape(Data, (-1, 6))
    ret_ = np.reshape(ret, (-1, 6))

    config = lcf.load__config()
    pngFile = "png/before_mirror.png"
    cmt.cMapTri( xAxis=Data_[:,z_], yAxis=Data_[:,x_], cMap=Data_[:,vz_], \
              pngFile=pngFile, config=config )

    config = lcf.load__config()
    pngFile = "png/after_mirror.png"
    cmt.cMapTri( xAxis=ret_[:,z_], yAxis=ret_[:,x_], cMap=ret_[:,vz_], \
              pngFile=pngFile, config=config )

    # ------------------------------------------------- #
    # --- [2] save mirrored file                    --- #
    # ------------------------------------------------- #

    outFile = "dat/mirrored.dat"
    import nkUtilities.save__pointFile as spf
    spf.save__pointFile(outFile=outFile, Data=ret)
    print()
    print("[mirror_ebfield.py] outFile :: {0} ".format(outFile))
    print("[mirror_ebfield.py] mv {0} some_file_name ".format(outFile))
    print()
Example #2
0
def display__sf7():

    x_, y_, z_ = 0, 1, 2
    bx_, by_, bz_ = 3, 4, 5

    # ------------------------------------------------- #
    # --- [1] Arguments                             --- #
    # ------------------------------------------------- #
    import nkUtilities.load__constants as lcn
    cnfFile = "dat/parameter.conf"
    const = lcn.load__constants(inpFile=cnfFile)

    config = lcf.load__config()
    datFile = const["bfieldFile"]
    pngFile = "png/bfield_{0}.png"

    # ------------------------------------------------- #
    # --- [2] Fetch Data                            --- #
    # ------------------------------------------------- #
    import nkUtilities.load__pointFile as lpf
    Data = lpf.load__pointFile(inpFile=datFile, returnType="point")

    # ------------------------------------------------- #
    # --- [3] config Settings                       --- #
    # ------------------------------------------------- #
    cfs.configSettings(configType="cMap_def", config=config)
    config["FigSize"] = (8, 3)
    config["cmp_position"] = [0.16, 0.12, 0.97, 0.88]
    config["xTitle"] = "Z (m)"
    config["yTitle"] = "R (m)"
    config["xMajor_Nticks"] = 8
    config["yMajor_Nticks"] = 3
    config["cmp_xAutoRange"] = True
    config["cmp_yAutoRange"] = True
    config["cmp_xRange"] = [-5.0, +5.0]
    config["cmp_yRange"] = [-5.0, +5.0]
    config["vec_AutoScale"] = True
    config["vec_AutoRange"] = True
    config["vec_AutoScaleRef"] = 200.0
    config["vec_nvec_x"] = 24
    config["vec_nvec_y"] = 6
    config["vec_interpolation"] = "nearest"

    # ------------------------------------------------- #
    # --- [4] plot Figure                           --- #
    # ------------------------------------------------- #
    cmt.cMapTri( xAxis=Data[:,z_], yAxis=Data[:,x_], cMap=Data[:,bz_], \
                 pngFile=pngFile.format( "Bz" ), config=config )
    cmt.cMapTri( xAxis=Data[:,z_], yAxis=Data[:,x_], cMap=Data[:,bx_], \
                 pngFile=pngFile.format( "Br" ), config=config )

    absB = np.sqrt(Data[:, bz_]**2 + Data[:, bx_]**2)
    fig = cmt.cMapTri(pngFile=pngFile.format("Bv"), config=config)
    fig.add__cMap(xAxis=Data[:, z_], yAxis=Data[:, x_], cMap=absB)
    fig.add__vector ( xAxis=Data[:,z_], yAxis=Data[:,x_], \
                      uvec=Data[:,bz_], vvec=Data[:,bx_], color="blue" )
    fig.save__figure()
Example #3
0
 def __init__(self,
              xAxis=None,
              yAxis=None,
              label=None,
              pngFile=None,
              config=None):
     # ------------------------------------------------- #
     # --- 引数の引き渡し                            --- #
     # ------------------------------------------------- #
     self.xAxis = xAxis
     self.yAxis = yAxis
     self.label = []
     self.DataRange = None
     self.xticks = None
     self.yticks = None
     self.config = config
     # ------------------------------------------------- #
     # --- コンフィグの設定                          --- #
     # ------------------------------------------------- #
     if (self.config is None): self.config = lcf.load__config()
     if (label is not None): self.label.append(label)
     if (pngFile is not None): self.config["pngFile"] = pngFile
     # ------------------------------------------------- #
     # --- 描画領域の作成                            --- #
     # ------------------------------------------------- #
     #  -- 描画領域                                  --  #
     pos = self.config["plt_position"]
     self.fig = plt.figure(figsize=self.config["FigSize"])
     self.ax1 = self.fig.add_axes(
         [pos[0], pos[1], pos[2] - pos[0], pos[3] - pos[1]])
     self.set__axis()
     self.set__grid()
     # ------------------------------------------------- #
     # --- 速攻描画                                  --- #
     # ------------------------------------------------- #
     instantOut = False
     #  -- もし yAxis が渡されていたら,即,描く      --  #
     if (self.yAxis is not None):
         #   - xAxis がなければインデックスで代用    -   #
         if (self.xAxis is None):
             self.xAxis = np.arange(float(self.yAxis.size))
         instantOut = True
         #   - プロット描きだし                      -   #
         self.add__plot(self.xAxis, self.yAxis, label=label)
         self.set__axis()
         if (self.config["leg_sw"]): self.add__legend()
     #  -- カーソル (x) がある時.                   --  #
     if (self.config["cursor_x"] is not None):
         self.add__cursor(xAxis=self.config["cursor_x"])
         instantOut = True
     #  -- カーソル (y) がある時.                   --  #
     if (self.config["cursor_y"] is not None):
         self.add__cursor(yAxis=self.config["cursor_y"])
         instantOut = True
     #  -- もし 何かを描いてたら,出力する.         --  #
     if (instantOut):
         self.save__figure(pngFile=self.config["pngFile"])
def child_langmuir_law():

    Va_min = 0.0
    Va_max = 500e3
    nVa = 101

    de_min = 10.0e-3
    de_max = 50.0e-3
    nde = 5

    pngFile = "png/child_langmuir.png"

    # ------------------------------------------------- #
    # --- [1] calculation                           --- #
    # ------------------------------------------------- #

    epsilon = 8.854187e-12
    qe = 1.602176e-19
    me = 9.109383e-31
    Va = np.linspace(Va_min, Va_max, nVa)
    de = np.linspace(de_min, de_max, nde)
    Jcl = np.zeros((nVa, nde))

    for ide in range(nde):
        Jcl[:, ide] = 4.0 * epsilon / 9.0 * np.sqrt(
            2.0 * qe / me) * Va**(3.0 / 2.0) / de[ide]**2

    Amm2_unit = 1.e-6
    kV_unit = 1.e-3
    Jcl_ = Jcl * Amm2_unit
    Va_ = Va * kV_unit
    # ------------------------------------------------- #
    # --- [2] plot characteristic                   --- #
    # ------------------------------------------------- #

    import nkUtilities.plot1D as pl1
    import nkUtilities.load__config as lcf

    config = lcf.load__config()
    config["xTitle"] = "V (kV)"
    config["yTitle"] = "J (A/mm^2)"
    config["plt_xAutoRange"] = False
    config["plt_yAutoRange"] = False
    config["plt_xRange"] = [0.0, 500.0]
    config["plt_yRange"] = [0.0, 2.0]
    config["plt_linewidth"] = 2.0
    config["xMajor_Nticks"] = 6
    config["yMajor_Nticks"] = 6

    fig = pl1.plot1D(config=config, pngFile=pngFile)
    for ide in range(nde):
        hlabel = "d={0:.5}".format(de[ide])
        fig.add__plot(xAxis=Va_, yAxis=Jcl_[:, ide], label=hlabel)
    fig.add__legend()
    fig.set__axis()
    fig.save__figure()
Example #5
0
def show__profile():

    # ------------------------------------------------- #
    # --- [1] Arguments                             --- #
    # ------------------------------------------------- #
    config = lcf.load__config()
    datFile = "dat/2a_Rs.dat"
    pngFile = datFile.replace("dat", "png")

    # ------------------------------------------------- #
    # --- [2] Fetch Data                            --- #
    # ------------------------------------------------- #
    import nkUtilities.load__pointFile as lpf
    Data = lpf.load__pointFile(inpFile=datFile, returnType="point")
    xr_ = Data[:, 0]
    yr_ = Data[:, 1]
    from scipy import interpolate
    f = interpolate.interp1d(xr_, yr_, kind="cubic")
    xAxis = np.linspace(22, 30, 5)
    yAxis = f(xAxis)

    # ------------------------------------------------- #
    # --- [3] config Settings                       --- #
    # ------------------------------------------------- #
    cfs.configSettings(configType="plot1D_def", config=config)
    config["plt_position"] = [0.24, 0.24, 0.94, 0.94]
    config["FigSize"] = (2.5, 2.5)
    config["xTitle"] = "2a (mm)"
    config["yTitle"] = "Rs (M" + "$\Omega$" + "/m)"
    config["plt_xAutoRange"] = False
    config["plt_yAutoRange"] = False
    # config["plt_yAutoRange"] = True
    config["plt_xRange"] = [+20.0, +32.0]
    config["plt_yRange"] = [+40, +64]
    config["plt_linewidth"] = 1.8
    config["xMajor_Nticks"] = 7
    config["yMajor_Nticks"] = 7
    config["xMinor_Nticks"] = 1
    config["yMinor_Nticks"] = 1
    config["plt_color"] = "Orange"
    config["plt_marker"] = "o"

    # ------------------------------------------------- #
    # --- [4] plot Figure                           --- #
    # ------------------------------------------------- #
    fig = pl1.plot1D(config=config, pngFile=pngFile)
    fig.add__plot(xAxis=xAxis, yAxis=yAxis)
    fig.set__axis()
    fig.save__figure()
Example #6
0
def beam_loading_curve():

    # ------------------------------------------------- #
    # --- [1] make beam loading curve               --- #
    # ------------------------------------------------- #
    import nkUtilities.load__constants as lcn
    cnsFile    = "dat/parameter.conf"
    const      = lcn.load__constants( inpFile=cnsFile )
    Ibeam      = np.linspace( const["Ibeam_Min"], const["Ibeam_Max"], const["Ibeam_num"] )
    P0_RFs     = np.linspace( const["P0_RF_Min"], const["P0_RF_Max"], const["P0_RF_num"] )
    BeamCurve  = np.zeros( (const["Ibeam_num"],const["P0_RF_num"]) )
    tau_attenuation = const["alpha_attenuation"] * const["length_cavity"]
    
    for ik,P0_RF in enumerate( P0_RFs ):
        term1  = np.sqrt( const["shunt_impedance"]*const["length_cavity"]*P0_RF*( 1.0 - np.exp( -2.0*tau_attenuation ) ) )
        term2  = Ibeam*const["shunt_impedance"]*const["length_cavity"] / 2.0 * ( 1.0 - 2.0*tau_attenuation*np.exp( -2.0*tau_attenuation ) / ( 1.0 - np.exp( -2.0*tau_attenuation ) ) )
        BeamCurve[:,ik] = ( term1 - term2 )

    outFile    = "dat/beam_loading_curve.dat"
    import nkUtilities.save__pointFile as spf
    spf.save__pointFile( outFile=outFile, Data=BeamCurve )


    # ------------------------------------------------- #
    # --- [2] config settings                       --- #
    # ------------------------------------------------- #
    import nkUtilities.load__config as lcf
    config                   = lcf.load__config()
    config["xTitle"]         = "Beam Current (mA)"
    config["yTitle"]         = "Beam Energy (MeV)"
    config["plt_xAutoRange"] = False
    config["plt_yAutoRange"] = False
    config["plt_xRange"]     = [ 0.0, 300  ]
    config["plt_yRange"]     = [ 0.0, 30.0 ]
    pngFile                  = "png/beam_loading_curve.png"

    
    # ------------------------------------------------- #
    # --- [3] plot                                  --- #
    # ------------------------------------------------- #
    Ibeam     = Ibeam     / const["current_unit"]
    BeamCurve = BeamCurve / const["energy_unit"]
    import nkUtilities.plot1D as pl1
    fig = pl1.plot1D( config=config, pngFile=pngFile )
    for ik in range( const["P0_RF_num"] ):
        fig.add__plot( xAxis=Ibeam, yAxis=BeamCurve[:,ik] )
    fig.set__axis()
    fig.save__figure()
Example #7
0
def display__phasespace():

    x_, y_, z_ = 1, 2, 3
    vx_, vy_, vz_ = 4, 5, 6
    MeV = 1.e+6

    # ------------------------------------------------- #
    # --- [1] load config & data                    --- #
    # ------------------------------------------------- #
    #  -- [2-1]  load config                         -- #
    cnsFile = "dat/parameter.conf"
    import nkUtilities.load__constants as lcn
    const = lcn.load__constants(inpFile=cnsFile)

    #  -- [2-2]  load data & energy calculation      -- #
    inpFile = "prb/collected.dat"
    with open(inpFile, "r") as f:
        Data = np.loadtxt(f)
    Data = Data[np.where(Data[:, x_] < 0.010)]
    Data = Data[np.where(Data[:, 13] > 0.0)]
    Data[:, vx_:vz_ + 1] = Data[:, vx_:vz_ + 1] / const["cv"]

    # ------------------------------------------------- #
    # --- [3] ploting                               --- #
    # ------------------------------------------------- #
    #  -- [3-1]  settings                           --  #
    pngFile = "png/phasespace_{0}.png"
    config = lcf.load__config()
    config["FigSize"] = (5, 5)
    config["plt_marker"] = "o"
    config["plt_markersize"] = 0.3
    config["plt_linewidth"] = 0.0

    #  -- [3-2]  xAxis                              --  #
    fig = pl1.plot1D(pngFile=pngFile.format("x_vx"), config=config)
    fig.add__plot(xAxis=Data[:, x_], yAxis=Data[:, vx_])
    fig.set__axis()
    fig.save__figure()
    #  -- [3-3]  yAxis                              --  #
    fig = pl1.plot1D(pngFile=pngFile.format("y_vy"), config=config)
    fig.add__plot(xAxis=Data[:, y_], yAxis=Data[:, vy_])
    fig.set__axis()
    fig.save__figure()
    #  -- [3-4]  zAxis                              --  #
    fig = pl1.plot1D(pngFile=pngFile.format("z_vz"), config=config)
    fig.add__plot(xAxis=Data[:, z_], yAxis=Data[:, vz_])
    fig.set__axis()
    fig.save__figure()
Example #8
0
def display():
    # ------------------------------------------------- #
    # --- [1] Arguments                             --- #
    # ------------------------------------------------- #
    config = lcf.load__config()
    datFile = "dat/superfish.dat"
    pngFile = "png/alongAxis.png"

    # ------------------------------------------------- #
    # --- [2] Fetch Data                            --- #
    # ------------------------------------------------- #
    import nkUtilities.load__pointFile as lpf
    Data = lpf.load__pointFile(inpFile=datFile, returnType="point")
    eps = 1.e-8
    val = 1.e-3
    index = np.where(np.abs(Data[:, 1] - val) <= eps)
    Data = Data[index][:]
    xAxis = Data[:, 0] - 0.5 * (Data[0, 0] + Data[-1, 0])
    Ez = Data[:, 3] * 1.e-6
    Er = Data[:, 4] / (val * 100.0) * 1.e-6
    # Hp    = Data[:,6] / ( val * 100.0 )

    # ------------------------------------------------- #
    # --- [3] config Settings                       --- #
    # ------------------------------------------------- #
    cfs.configSettings(configType="plot1D_def", config=config)
    config["FigSize"] = (4, 4)
    config["yTitle"] = "Ez (MV/m), Er/r (MV/m/cm)"
    config["xTitle"] = "Z (m)"
    config["plt_xAutoRange"] = False
    config["plt_yAutoRange"] = False
    config["plt_xRange"] = [-0.0, +0.05]
    config["plt_yRange"] = [-0.0, +3.0]
    config["plt_linewidth"] = 1.8
    config["xMajor_Nticks"] = 6
    config["yMajor_Nticks"] = 4

    # ------------------------------------------------- #
    # --- [4] plot Figure                           --- #
    # ------------------------------------------------- #
    fig = pl1.plot1D(config=config, pngFile=pngFile)
    fig.add__plot(xAxis=xAxis, yAxis=Er, label="Er/r")
    fig.add__plot(xAxis=xAxis, yAxis=Ez, label="Ez")
    # fig.add__plot( xAxis=xAxis, yAxis=Hp, label="Hp" )
    fig.add__legend()
    fig.set__axis()
    fig.save__figure()
Example #9
0
def display__initialAxisymmField():

    x_ , y_ , z_  = 0, 1, 2
    vx_, vy_, vz_ = 3, 4, 5
    
    # ------------------------------------------------- #
    # --- [1] Load Config & Eigenmode               --- #
    # ------------------------------------------------- #

    import nkUtilities.load__constants as lcn
    cnsFile  = "dat/parameter.conf"
    const    = lcn.load__constants( inpFile=cnsFile )

    import nkUtilities.load__pointFile as lpf
    efield   = lpf.load__pointFile( inpFile=const["EFieldFile"], returnType="structured" )
    bfield   = lpf.load__pointFile( inpFile=const["BFieldFile"], returnType="structured" )

    config   = lcf.load__config()
    pngFile  = "png/field_init_{0}.png"
    

    # ------------------------------------------------- #
    # --- [2] prepare cos & sin theta               --- #
    # ------------------------------------------------- #
    time      = np.linspace( const["tw_tStart"], const["tw_tEnd"], const["tw_tDiv"] )
    theta     = 2.0*np.pi*const["freq"] * time + const["phase_delay"]
    costh     = np.cos( theta )
    
    # ------------------------------------------------- #
    # --- [2] convert into vts File                 --- #
    # ------------------------------------------------- #

    import nkVTKRoutines.convert__vtkStructuredGrid as vts
    import nkUtilities.save__pointFile              as spf
    vtsFile   = "png/wave{0:04}.vts"
    Data      = np.zeros( (efield.shape[0],efield.shape[1],efield.shape[2],9) )
    
    # --  [2-2] Main Loop                           --  #
    for ik in range( const["tw_tDiv"] ):
        # --  [3-3] wave data synthesize            --  #
        wave          = np.zeros_like( Data )
        wave[...,0:3] = np.copy( efield[...,0:3] )
        wave[...,3:6] = efield[...,3:]*costh[ik]
        wave[...,6:9] = bfield[...,3:]*costh[ik]
        # --  [3-4] save as vts file                --  #
        vts.convert__vtkStructuredGrid( Data=wave, outFile=vtsFile.format(ik) )
Example #10
0
def display__xyzE_histogram():

    bins_x, bins_y, bins_z, bins_e     = 100, 100, 100, 100
    range_x, range_y, range_z, range_e = None, None, None, None
    
    pngFile       = "png/histogram_{0}.png"    
    MeV           = 1.e+6
    x_ , y_ , z_  = 1, 2, 3
    vx_, vy_, vz_ = 4, 5, 6

    # ------------------------------------------------- #
    # --- [1] load config & data                    --- #
    # ------------------------------------------------- #
    #  -- [1-1]  load config                         -- #
    cnsFile = "dat/parameter.conf"
    import nkUtilities.load__constants as lcn
    const   = lcn.load__constants( inpFile=cnsFile )
    config  = lcf.load__config()

    #  -- [1-2]  load data & energy calculation      -- #
    inpFile = "prb/collected.dat"
    with open( inpFile, "r" ) as f:
        Data = np.loadtxt( f )

    #  -- [1-3] energy calculation                   -- #
    beta   = np.sqrt( Data[:,vx_]**2 + Data[:,vy_]**2 + Data[:,vz_]**2 ) / const["cv"]
    gamma  = 1.0 / ( np.sqrt( 1.0 - beta**2 ) )
    energy = ( gamma - 1.0 ) * const["mp"] * const["cv"]**2 / np.abs( const["qe"] ) / MeV

    # ------------------------------------------------- #
    # --- [2] draw histogram                        --- #
    # ------------------------------------------------- #
    #  -- [2-1] Number of particles                 --  #
    config["yTitle"] = "Number of particles"

    #  -- [2-2] Number of particles                 --  #
    import nkUtilities.make__histogram as hst
    config["xTitle"] = "X (m)"
    hist_x, bound_x = hst.make__histogram( Data=Data[:,x_], bins=bins_x, range=range_x, \
                                           config=config, pngFile=pngFile.format( "x" ) )
    config["xTitle"] = "Y (m)"
    hist_y, bound_y = hst.make__histogram( Data=Data[:,y_], bins=bins_y, range=range_y, \
                                           config=config, pngFile=pngFile.format( "y" ) )
    config["xTitle"] = "Z (m)"
    hist_z, bound_z = hst.make__histogram( Data=Data[:,z_], bins=bins_z, range=range_z, \
                                           config=config, pngFile=pngFile.format( "z" ) )
Example #11
0
def make__histogram( Data=None, bins=None, range=None, \
                     color=None, alpha=None, width=None, \
                     pngFile=None, draw=True, config=None,  ):

    # ------------------------------------------------- #
    # --- [1] Arguments                             --- #
    # ------------------------------------------------- #

    if (Data is None): sys.exit("[draw__histogram.py] Data == ???")
    if (config is None): config = lcf.load__config()
    if (bins is None): bins = config["histo_bins"]

    # ------------------------------------------------- #
    # --- [2] make histogram                        --- #
    # ------------------------------------------------- #

    hist, bound = np.histogram(Data, bins=bins, range=range)
    axis = 0.5 * (bound[:-1] + bound[1:])

    # ------------------------------------------------- #
    # --- [3] plotting                              --- #
    # ------------------------------------------------- #
    if (draw):
        if (pngFile is None):
            print(
                "[make__histogram.py] make__histogram.py :: None pngFile  .. --> out.png"
            )
            pngFile = "out.png"

        fig = pl1.plot1D(pngFile=pngFile, config=config)
        fig.add__bar(
            xAxis=axis,
            yAxis=hist,
            alpha=alpha,
            color=color,
        )
        fig.set__axis()
        fig.save__figure()

    # ------------------------------------------------- #
    # --- [4] return                                --- #
    # ------------------------------------------------- #
    return (hist, axis)
Example #12
0
def display():
    # ------------------------------------------------- #
    # --- [1] Arguments                             --- #
    # ------------------------------------------------- #
    config   = lcf.load__config()
    datFile1 = "dat/result.dat"
    datFile2 = "dat/source.dat"
    pngFile1 = datFile1.replace( "dat", "png" )
    pngFile2 = datFile2.replace( "dat", "png" )

    # ------------------------------------------------- #
    # --- [2] Fetch Data                            --- #
    # ------------------------------------------------- #
    import nkUtilities.load__pointFile as lpf
    Data1  = lpf.load__pointFile( inpFile=datFile1, returnType="point" )
    xAxis1 = Data1[:,0]
    yAxis1 = Data1[:,1]
    zAxis1 = Data1[:,2]
    
    Data2  = lpf.load__pointFile( inpFile=datFile2, returnType="point" )
    xAxis2 = Data2[:,0]
    yAxis2 = Data2[:,1]
    zAxis2 = Data2[:,2]
    
    # ------------------------------------------------- #
    # --- [3] config Settings                       --- #
    # ------------------------------------------------- #
    cfs.configSettings( configType="cMap_def", config=config )
    config["FigSize"]        = (5,5)
    config["cmp_position"]   = [0.16,0.12,0.97,0.88]
    config["xTitle"]         = "X (m)"
    config["yTitle"]         = "Y (m)"
    config["cmp_xAutoRange"] = True
    config["cmp_yAutoRange"] = True
    config["cmp_xRange"]     = [-5.0,+5.0]
    config["cmp_yRange"]     = [-5.0,+5.0]

    # ------------------------------------------------- #
    # --- [4] plot Figure                           --- #
    # ------------------------------------------------- #
    cmt.cMapTri( xAxis=xAxis1, yAxis=yAxis1, cMap=zAxis1, pngFile=pngFile1, config=config )
    cmt.cMapTri( xAxis=xAxis2, yAxis=yAxis2, cMap=zAxis2, pngFile=pngFile2, config=config )
Example #13
0
def display():
    # ------------------------------------------------- #
    # --- [1] Arguments                             --- #
    # ------------------------------------------------- #
    config = lcf.load__config()
    datFile = "dat/bfield_biot.dat"
    pngFile = datFile.replace("dat", "png")

    # ------------------------------------------------- #
    # --- [2] Fetch Data                            --- #
    # ------------------------------------------------- #
    import nkUtilities.load__pointFile as lpf
    Data = lpf.load__pointFile(inpFile=datFile, returnType="point")
    xAxis = Data[:, 0]
    yAxis = Data[:, 1]
    zAxis = Data[:, 5]

    # ------------------------------------------------- #
    # --- [3] config Settings                       --- #
    # ------------------------------------------------- #
    cfs.configSettings(configType="cMap_def", config=config)
    config["FigSize"] = (5, 5)
    config["cmp_position"] = [0.16, 0.12, 0.97, 0.88]
    config["xTitle"] = "X (m)"
    config["yTitle"] = "Y (m)"
    config["cmp_xAutoRange"] = True
    config["cmp_yAutoRange"] = True
    config["cmp_xRange"] = [-5.0, +5.0]
    config["cmp_yRange"] = [-5.0, +5.0]

    # ------------------------------------------------- #
    # --- [4] plot Figure                           --- #
    # ------------------------------------------------- #
    cmt.cMapTri(xAxis=xAxis,
                yAxis=yAxis,
                cMap=zAxis,
                pngFile=pngFile,
                config=config)
def display__initialAxisymmField():

    x_, y_, z_ = 0, 1, 2
    vx_, vy_, vz_ = 3, 4, 5

    # ------------------------------------------------- #
    # --- [1] Load Config & Eigenmode               --- #
    # ------------------------------------------------- #

    import nkUtilities.load__constants as lcn
    cnsFile = "dat/parameter.conf"
    const = lcn.load__constants(inpFile=cnsFile)

    import nkUtilities.load__pointFile as lpf
    efield = lpf.load__pointFile(inpFile=const["EFieldFile"],
                                 returnType="point")
    bfield = lpf.load__pointFile(inpFile=const["BFieldFile"],
                                 returnType="point")

    config = lcf.load__config()
    pngFile = "png/field_init_{0}.png"

    # ------------------------------------------------- #
    # --- [2] config Settings                       --- #
    # ------------------------------------------------- #
    cfs.configSettings(configType="cMap_def", config=config)
    config["FigSize"] = (8, 4)
    config["cmp_position"] = [0.16, 0.12, 0.97, 0.88]
    config["xTitle"] = "Z (m)"
    config["yTitle"] = "R (m)"
    config["cmp_xAutoRange"] = True
    config["cmp_yAutoRange"] = True
    config["cmp_xRange"] = [-5.0, +5.0]
    config["cmp_yRange"] = [-5.0, +5.0]

    config["vec_AutoScale"] = True
    config["vec_AutoRange"] = True
    config["vec_AutoScaleRef"] = 200.0
    config["vec_nvec_x"] = 24
    config["vec_nvec_y"] = 6
    config["vec_interpolation"] = "nearest"

    # ------------------------------------------------- #
    # --- [4] plot Figure                           --- #
    # ------------------------------------------------- #

    xAxis = np.copy(efield[:, z_])
    yAxis = np.copy(efield[:, x_])

    cmt.cMapTri( xAxis=xAxis, yAxis=yAxis, cMap=efield[:,vz_], \
                 pngFile=pngFile.format( "Ez" ), config=config )
    cmt.cMapTri( xAxis=xAxis, yAxis=yAxis, cMap=efield[:,vx_], \
                 pngFile=pngFile.format( "Er" ), config=config )
    cmt.cMapTri( xAxis=xAxis, yAxis=yAxis, cMap=bfield[:,vy_], \
                 pngFile=pngFile.format( "Hp" ), config=config )

    fig = cmt.cMapTri(pngFile=pngFile.format("Ev"), config=config)
    fig.add__contour(xAxis=xAxis, yAxis=yAxis, Cntr=bfield[:, vy_])
    fig.add__cMap(xAxis=xAxis, yAxis=yAxis, cMap=bfield[:, vy_])
    fig.add__vector ( xAxis=xAxis, yAxis=yAxis, uvec=efield[:,vz_], vvec=efield[:,vx_], \
                      color="blue" )
    fig.save__figure()

    # ------------------------------------------------- #
    # --- [5] 1D plot                               --- #
    # ------------------------------------------------- #

    config["xTitle"] = "Z (m)"
    config["yTitle"] = "E (V/m)"

    val = 0.005
    eps = 1.e-10
    index = np.where((efield[:, x_] >= val - eps)
                     & (efield[:, x_] <= val + eps))
    xAxis = np.copy(efield[index][:, z_])
    ez = np.copy(efield[index][:, vz_])
    ex = np.copy(efield[index][:, vx_])

    import nkUtilities.plot1D as pl1

    fig = pl1.plot1D(config=config, pngFile=pngFile.format("1D"))
    fig.add__plot(xAxis=xAxis, yAxis=ez, color="royalblue", label="Ez")
    fig.add__plot(xAxis=xAxis, yAxis=ex, color="magenta", label="Ex")
    fig.add__legend()
    fig.set__axis()
    fig.save__figure()
Example #15
0
def time_vs_energy(nums=None):

    t_ = 0
    x_, y_, z_ = 1, 2, 3
    vx_, vy_, vz_ = 4, 5, 6
    ex_, ey_, ez_ = 7, 8, 9
    bx_, by_, bz_ = 10, 11, 12

    cnsFile = "dat/particle.conf"
    import nkUtilities.load__constants as lcn
    pconst = lcn.load__constants(inpFile=cnsFile)

    # ------------------------------------------------- #
    # --- [1] Arguments                             --- #
    # ------------------------------------------------- #
    if (nums is None):
        print(
            "[time_vs_energy] please input particle number : ( def. :: all ) >>> ",
            end="")
        nums = input()
        if (len(nums) == 0):
            nums = list(range(1, pconst["npt"] + 1))
            # import glob
            # files = glob.glob( "prb/probe*.dat" )
            # nums  = [ int(num+1) for num in range( len(files) ) ]
        else:
            nums = [int(num) for num in nums.split()]

    pngFile = "png/time_vs_energy.png"
    config = lcf.load__config()
    cnsFile = "dat/parameter.conf"
    const = lcn.load__constants(inpFile=cnsFile)

    # ------------------------------------------------- #
    # --- [2] config Settings                       --- #
    # ------------------------------------------------- #
    cfs.configSettings(configType="plot1D_def", config=config)
    config["xTitle"] = "Time (s)"
    config["yTitle"] = "Energy (MeV)"
    config["plt_xAutoRange"] = True
    config["plt_yAutoRange"] = True
    config["plt_xRange"] = [-5.0, +5.0]
    config["plt_yRange"] = [-5.0, +5.0]
    config["plt_linewidth"] = 1.0
    config["xMajor_Nticks"] = 5
    config["yMajor_Nticks"] = 5
    config["plt_marker"] = None

    import nkUtilities.generate__colors as col
    colors = col.generate__colors(nColors=len(nums))

    # ------------------------------------------------- #
    # --- [4] plot Figure                           --- #
    # ------------------------------------------------- #
    fig = pl1.plot1D(config=config, pngFile=pngFile)
    for ik, num in enumerate(nums):
        inpFile = "prb/probe{0:06}.dat".format(num)
        Data = lpf.load__pointFile(inpFile=inpFile, returnType="point")
        xAxis = Data[:, t_]
        beta = np.sqrt(Data[:, vx_]**2 + Data[:, vy_]**2 +
                       Data[:, vz_]**2) / const["cv"]
        gamma = 1.0 / (np.sqrt(1.0 - beta**2))
        yAxis = (gamma -
                 1.0) * const["mp"] * const["cv"]**2 / const["qe"] / 1.e6

        fig.add__plot(xAxis=xAxis, yAxis=yAxis, color=colors[ik])

    fig.set__axis()
    fig.save__figure()
Example #16
0
def generalFilter( xAxis=None, yAxis=None, config=None, returnType="list" ):
    
    # ------------------------------------------------- #
    # --- Arguments                                 --- #
    # ------------------------------------------------- #
    if ( yAxis  is None ): sys.exit( "[generalFilter] None yAxis" )
    if ( config is None ): config = lcf.load__config()
    if ( xAxis  is None ): xAxis  = np.arange( yAxis.size )
    
    # ------------------------------------------------- #
    # --- メジアンフィルタリング                    --- #
    # ------------------------------------------------- #
    if ( config["filter.median"] is not None ):
        if ( config["filter.median" ] >= 3 ):
            import filters.medianFilter as med
            yAxis = med.medianFilter( Data=yAxis, width=config["filter.median"] )
        
    # ------------------------------------------------- #
    # --- フーリエフィルタリング                    --- #
    # ------------------------------------------------- #
    if ( config["filter.fourier"] is not None ):
        if ( config["filter.fourier"] > 0.0 ):
            import filters.fourierFilter as frf
            yAxis = frf.fourierFilter( Data=yAxis, fCutoff=config["filter.fourier"] )
        
    # ------------------------------------------------- #
    # --- ガウシアンフィルタリング                  --- #
    # ------------------------------------------------- #
    if ( config["filter.gaussian"] is not None ):
        if ( config["filter.gaussian"] > 0.0 ):
            import scipy.ndimage.filters as gfl
            yAxis = gfl.gaussian_filter1d( yAxis, config["filter.gaussian"] )
            
    # ------------------------------------------------- #
    # --- スプライン 内挿                           --- #
    # ------------------------------------------------- #
    if ( config["filter.spline"] is not None ):
        if ( config["filter.spline"] > 0 ):
            import scipy.interpolate
            splinefunc = scipy.interpolate.interp1d( xAxis, yAxis, kind='cubic')
            x_interp   = np.linspace( np.min( xAxis ), np.max( xAxis ), \
                                      config["filter.spline"] )
            y_interp   = splinefunc( x_interp )
            xAxis      = x_interp
            yAxis      = y_interp
            
    # ------------------------------------------------- #
    # --- 線形フィルタリング                        --- #
    # ------------------------------------------------- #
    if ( config["filter.linear"] is not None ):
        if ( config["filter.linear"] > 0.0 ):
            import Filter.nxLinearFilter1D as lnf
            yAxis = lnf.nxLinearFilter1D( Data=yAxis, alpha=config["filter.linear"], \
                                          nFilter=config["filter.ntimes"] )
        
    # ------------------------------------------------- #
    # --- 返却                                      --- #
    # ------------------------------------------------- #
    if   ( returnType.lower() == "dict" ):
        ret = { "xAxis":xAxis, "yAxis":yAxis }
    elif ( returnType.lower() == "list" ):
        ret = [ xAxis, yAxis ]
    elif ( returnType.lower() == "array" ):
        ret = np.cocatenate( [ xAxis[:,None], yAxis[:,None] ] )
    return( ret )
Example #17
0
def time_vs_probeData(nums=None, axis=None):

    t_ = 0
    x_, y_, z_ = 1, 2, 3
    vx_, vy_, vz_ = 4, 5, 6
    ex_, ey_, ez_ = 7, 8, 9
    bx_, by_, bz_ = 10, 11, 12

    cnsFile = "dat/particle.conf"
    import nkUtilities.load__constants as lcn
    pconst = lcn.load__constants(inpFile=cnsFile)

    # ------------------------------------------------- #
    # --- [1] Arguments                             --- #
    # ------------------------------------------------- #
    if (nums is None):
        print(
            "[trajectory__tx] please input particle number : ( e.g. :: 1 2 3, 1-4, [empty::all] ) >>> ",
            end="")
        nums = input()
        if (len(nums) == 0):
            nums = list(range(1, pconst["npt"] + 1))
        elif (len(nums.split("-")) == 2):
            imin = int((nums.split("-")[0]).strip())
            imax = int((nums.split("-")[0]).strip())
            nums = list(range(imin, imax + 1))
        else:
            nums = [int(num) for num in nums.split()]

    if (axis is None):
        print(
            "[trajectory__tx] please input axis ( x/y/z )  : ( e.g. :: x     ) >>> ",
            end="")
        axis = input()

    if ( not( axis.lower() in ["x" ,"y" ,"z" ,"vx","vy","vz",\
                               "ex","ey","ez","bx","by","bz"] ) ):
        print("[trajectory__tx] axis != x/y/z   [ERROR] ")
        sys.exit()

    pngFile = "png/time_vs_{0}.png".format(axis)
    config = lcf.load__config()

    # ------------------------------------------------- #
    # --- [2] config Settings                       --- #
    # ------------------------------------------------- #
    cfs.configSettings(configType="plot1D_def", config=config)
    config["xTitle"] = "Time (s)"
    config["yTitle"] = yTitle
    config["plt_xAutoRange"] = True
    config["plt_yAutoRange"] = True
    config["plt_xRange"] = [-5.0, +5.0]
    config["plt_yRange"] = [-5.0, +5.0]
    config["plt_linewidth"] = 1.0
    config["xMajor_Nticks"] = 5
    config["yMajor_Nticks"] = 5
    config["plt_marker"] = None

    import nkUtilities.generate__colors as col
    colors = col.generate__colors(nColors=len(nums))

    # ------------------------------------------------- #
    # --- [3] axis settings                         --- #
    # ------------------------------------------------- #
    if (axis.lower() == "x"):
        p_ = x_
        yTitle = "x (m)"
        config["plt_xAutoRange"] = False
        config["plt_xRange"] = [0.0, 0.020]
    elif (axis.lower() == "y"):
        p_ = y_
        yTitle = "y (m)"
    elif (axis.lower() == "z"):
        p_ = z_
        yTitle = "z (m)"
    elif (axis.lower() == "vx"):
        p_ = vx_
        yTitle = "vx (m/s)"
    elif (axis.lower() == "vy"):
        p_ = vy_
        yTitle = "vy (m/s)"
    elif (axis.lower() == "vz"):
        p_ = vz_
        yTitle = "vz (m/s)"
    elif (axis.lower() == "ex"):
        p_ = ex_
        yTitle = "ex (V/m)"
    elif (axis.lower() == "ey"):
        p_ = ey_
        yTitle = "ey (V/m)"
    elif (axis.lower() == "ez"):
        p_ = ez_
        yTitle = "ez (V/m)"
    elif (axis.lower() == "bx"):
        p_ = bx_
        yTitle = "bx (T)"
    elif (axis.lower() == "by"):
        p_ = by_
        yTitle = "by (T)"
    elif (axis.lower() == "bz"):
        p_ = bz_
        yTitle = "bz (T)"

    # ------------------------------------------------- #
    # --- [4] plot Figure                           --- #
    # ------------------------------------------------- #
    fig = pl1.plot1D(config=config, pngFile=pngFile)
    for ik, num in enumerate(nums):
        inpFile = "prb/probe{0:06}.dat".format(num)
        Data = lpf.load__pointFile(inpFile=inpFile, returnType="point")
        xAxis = Data[:, t_]
        yAxis = Data[:, p_]
        fig.add__plot(xAxis=xAxis, yAxis=yAxis, color=colors[ik])
    fig.set__axis()
    fig.save__figure()
Example #18
0
def plot__particle_statistic():

    x_ , y_ , z_  = 1, 2, 3
    vx_, vy_, vz_ = 4, 5, 6
    MeV           = 1.e+6

    # ------------------------------------------------- #
    # --- [1] load config & data                    --- #
    # ------------------------------------------------- #
    
    cnsFile = "dat/parameter.conf"
    import nkUtilities.load__constants as lcn
    const = lcn.load__constants( inpFile=cnsFile )

    inpFile = "prb/collected.dat"
    with open( inpFile, "r" ) as f:
        Data = np.loadtxt( f )
    xpos   = Data[:,x_]
    ypos   = Data[:,y_]
    zpos   = Data[:,z_]
    vx     = Data[:,vx_]
    vy     = Data[:,vy_]
    vz     = Data[:,vz_]
    beta   = np.sqrt( vx**2 + vy**2 + vz**2 ) / const["cv"]
    gamma  = 1.0 / ( np.sqrt( 1.0 - beta**2 ) )
    energy = ( gamma - 1.0 ) * const["mp"] * const["cv"]**2 / const["qe"] / MeV


    # ------------------------------------------------- #
    # --- [2] distribution at target_time           --- #
    # ------------------------------------------------- #

    pngFile = "png/p_pos_histogram_{0}.png"

    #  -- [2-1]  xpos  -- #
    import matplotlib.pyplot as plt
    fig = plt.figure()
    ax  = fig.add_subplot()
    ax.hist( xpos, bins=300 )
    fig.savefig( pngFile.format("x") )
    print( "[collect__particles.py] outFile :: {0} ".format( pngFile.format("x") ) )

    #  -- [2-2]  ypos  -- #
    import matplotlib.pyplot as plt
    fig = plt.figure()
    ax  = fig.add_subplot()
    ax.hist( ypos, bins=300 )
    fig.savefig( pngFile.format("y") )
    print( "[collect__particles.py] outFile :: {0} ".format( pngFile.format("y") ) )

    #  -- [2-3]  zpos  -- #
    import matplotlib.pyplot as plt
    fig = plt.figure()
    ax  = fig.add_subplot()
    ax.hist( zpos, bins=300 )
    fig.savefig( pngFile.format("z") )
    print( "[collect__particles.py] outFile :: {0} ".format( pngFile.format("z") ) )

    
    # ------------------------------------------------- #
    # --- [3] plot particls positions               --- #
    # ------------------------------------------------- #

    #  -- [3-0]  common settings   -- #
    import nkUtilities.plot1D       as pl1
    import nkUtilities.load__config as lcf
    config = lcf.load__config()
    config["plt_linewidth"] = 0.0
    config["plt_marker"]    = "o"
    pngFile                 = "png/dist_at_time_{0}.png"

    #  -- [3-1]  xy dist  -- #
    config["xTitle"] = "x (m)"
    config["yTitle"] = "y (m)"
    fig = pl1.plot1D( xAxis=xpos, yAxis=ypos, config=config, pngFile=pngFile.format( "x" ) )

    #  -- [3-2]  zx dist  -- #
    config["xTitle"] = "z (m)"
    config["yTitle"] = "x (m)"
    fig = pl1.plot1D( xAxis=zpos, yAxis=xpos, config=config, pngFile=pngFile.format( "y" ) )

    #  -- [3-3]  zy dist  -- #
    config["xTitle"] = "z (m)"
    config["yTitle"] = "y (m)"
    fig = pl1.plot1D( xAxis=zpos, yAxis=ypos, config=config, pngFile=pngFile.format( "z" ) )


    # ------------------------------------------------- #
    # --- [4] energy dist.                          --- #
    # ------------------------------------------------- #
    #  -- [4-0]  config  settings    -- #
    config["plt_xAutoRange"] = False
    config["plt_yAutoRange"] = False
    config["plt_xRange"]     = [0.0,0.8]
    config["plt_yRange"]     = [0.0,0.2]
    config["xTitle"]         = "z (m)"
    config["yTitle"]         = "Energy (MeV)"
    #  -- [4-1]  plot energy dist.   -- #
    pngFile = "png/dist_at_time_z_energy.png"
    fig     = pl1.plot1D( xAxis=zpos, yAxis=energy, config=config, pngFile=pngFile )
Example #19
0
def trajectory__xy(nums=None, plain=None):

    x_, y_, z_ = 1, 2, 3

    # ------------------------------------------------- #
    # --- [1] Arguments                             --- #
    # ------------------------------------------------- #
    if (nums is None):
        print(
            "[trajectory__tx] please input particle number            >> ( e.g. :: 1 2 3 )"
        )
        nums = input()
        nums = [int(num) for num in nums.split()]

    if (plain is None):
        print(
            "[trajectory__tx] please input plain (xy/yx/yz/zy/zx/xz/) >> ( e.g. :: xy    )"
        )
        plain = input()

    if (not (plain.lower() in ["xy", "yz", "zx", "yx", "zy", "xz"])):
        print("[trajectory__tx] plain != (xy/yx/yz/zy/zx/xz/)  [ERROR] ")
        sys.exit()

    pngFile = "png/trajectory__{0}.png".format(plain)
    config = lcf.load__config()

    # ------------------------------------------------- #
    # --- [2] axis settings                         --- #
    # ------------------------------------------------- #

    if (plain.lower() == "xy"):
        a1_, a2_ = x_, y_
        xTitle, yTitle = "X (m)", "Y (m)"
    elif (plain.lower() == "yx"):
        a1_, a2_ = y_, x_
        xTitle, yTitle = "Y (m)", "X (m)"
    elif (plain.lower() == "yz"):
        a1_, a2_ = y_, z_
        xTitle, yTitle = "Y (m)", "Z (m)"
    elif (plain.lower() == "zy"):
        a1_, a2_ = z_, y_
        xTitle, yTitle = "Z (m)", "Y (m)"
    elif (plain.lower() == "zx"):
        a1_, a2_ = z_, x_
        xTitle, yTitle = "Z (m)", "X (m)"
    elif (plain.lower() == "xz"):
        a1_, a2_ = x_, z_
        xTitle, yTitle = "X (m)", "Z (m)"

    # ------------------------------------------------- #
    # --- [3] config Settings                       --- #
    # ------------------------------------------------- #
    cfs.configSettings(configType="plot1D_def", config=config)
    config["xTitle"] = xTitle
    config["yTitle"] = yTitle
    config["plt_xAutoRange"] = True
    config["plt_yAutoRange"] = True
    config["plt_xRange"] = [-5.0, +5.0]
    config["plt_yRange"] = [-5.0, +5.0]
    config["plt_linewidth"] = 1.0
    config["xMajor_Nticks"] = 5
    config["yMajor_Nticks"] = 5

    import nkUtilities.generate__colors as col
    colors = col.generate__colors(nColors=len(nums))

    # ------------------------------------------------- #
    # --- [4] plot Figure                           --- #
    # ------------------------------------------------- #
    fig = pl1.plot1D(config=config, pngFile=pngFile)
    for ik, num in enumerate(nums):
        # inpFile = "trk/track{0:06}.dat".format( num )
        inpFile = "prb/probe{0:06}.dat".format(num)
        Data = lpf.load__pointFile(inpFile=inpFile, returnType="point")
        xAxis = Data[:, a1_]
        yAxis = Data[:, a2_]
        fig.add__plot(xAxis=xAxis, yAxis=yAxis, color=colors[ik])
    fig.set__axis()
    fig.save__figure()
Example #20
0
def display__axisymmField(inpFile=None):

    x_, y_, z_ = 0, 1, 2
    vx_, vy_, vz_ = 3, 4, 5

    # ------------------------------------------------- #
    # --- [1] Load Config & Eigenmode               --- #
    # ------------------------------------------------- #

    import nkUtilities.load__constants as lcn
    cnsFile = "dat/parameter.conf"
    pngFile = "png/{0}field_{1}_{2}.png"
    config = lcf.load__config()
    const = lcn.load__constants(inpFile=cnsFile)

    eflist = const["EFieldListFile"]
    bflist = const["BFieldListFile"]

    with open(eflist, "r") as f:
        efiles = f.readlines()
    with open(bflist, "r") as f:
        bfiles = f.readlines()

    # ------------------------------------------------- #
    # --- [2] config Settings                       --- #
    # ------------------------------------------------- #
    cfs.configSettings(configType="cMap_def", config=config)
    config["FigSize"] = (8, 4)
    config["cmp_position"] = [0.16, 0.12, 0.97, 0.88]
    config["xTitle"] = "Z (m)"
    config["yTitle"] = "R (m)"
    config["cmp_xAutoRange"] = True
    config["cmp_yAutoRange"] = True
    config["cmp_xRange"] = [-5.0, +5.0]
    config["cmp_yRange"] = [-5.0, +5.0]

    config["vec_AutoScale"] = True
    config["vec_AutoRange"] = True
    config["vec_AutoScaleRef"] = 200.0
    config["vec_nvec_x"] = 24
    config["vec_nvec_y"] = 6
    config["vec_interpolation"] = "nearest"

    # ------------------------------------------------- #
    # --- [4] plot Figure ( efield )                --- #
    # ------------------------------------------------- #

    for ik, efile in enumerate(efiles):

        import nkUtilities.load__pointFile as lpf
        efield = lpf.load__pointFile(inpFile=efile.strip(), returnType="point")

        xAxis = np.copy(efield[:, z_])
        yAxis = np.copy(efield[:, x_])
        absE = np.sqrt(efield[:, vx_]**2 + efield[:, vz_]**2)

        cmt.cMapTri( xAxis=xAxis, yAxis=yAxis, cMap=efield[:,vz_], \
                     pngFile=pngFile.format( "e", ik, "Ez" ), config=config )
        cmt.cMapTri( xAxis=xAxis, yAxis=yAxis, cMap=efield[:,vx_], \
                     pngFile=pngFile.format( "e", ik, "Er" ), config=config )

        fig = cmt.cMapTri(pngFile=pngFile.format(
            "e",
            ik,
            "Ev",
        ),
                          config=config)
        fig.add__cMap(xAxis=xAxis, yAxis=yAxis, cMap=absE)
        fig.add__vector ( xAxis=xAxis, yAxis=yAxis, uvec=efield[:,vz_], vvec=efield[:,vx_], \
                          color="blue" )
        fig.save__figure()

    # ------------------------------------------------- #
    # --- [5] plot Figure ( bfield )                --- #
    # ------------------------------------------------- #

    for ik, bfile in enumerate(bfiles):

        import nkUtilities.load__pointFile as lpf
        bfield = lpf.load__pointFile(inpFile=bfile.strip(), returnType="point")

        xAxis = np.copy(bfield[:, z_])
        yAxis = np.copy(bfield[:, x_])

        cmt.cMapTri( xAxis=xAxis, yAxis=yAxis, cMap=bfield[:,vy_], \
                     pngFile=pngFile.format( "b", ik, "Hp" ), config=config )
Example #21
0
def display__beamline(color="blue", colormode="energy", eRange=None):

    eRange = [15e6, 30e6]

    # ------------------------------------------------- #
    # --- [1] Preparation                           --- #
    # ------------------------------------------------- #
    #  -- [1-1] input / output                      --  #
    x_, y_, z_ = 1, 2, 3
    vx_, vy_, vz_ = 4, 5, 6
    config = lcf.load__config()
    cnsFile = "dat/parameter.conf"
    const = lcn.load__constants(inpFile=cnsFile)
    pngFile = "png/beamline.png"
    inpFile = "prb/probe{0:06}.dat"

    #  -- [1-2] load__selected                      --  #
    import select__particles as spf
    FileList = spf.load__selected()
    nFile = (FileList.shape[0])

    #  -- [1-3] eRange                              --  #
    if (eRange is not None):
        eMin, eMax = eRange[0], eRange[1]
        AutoRange = False
    else:
        eMin, eMax = 1.e64, 0.0
        AutoRange = True

    # ------------------------------------------------- #
    # --- [2] calculate energy                      --- #
    # ------------------------------------------------- #
    if (colormode == "single"):
        colors = np.repeat(color, nFile)

    elif (colormode == "random"):
        import matplotlib.pyplot as plt
        colors = plt.get_cmap("jet")
        colors = colors(np.linspace(0.0, 1.0, nFile))

    elif (colormode == "energy"):

        energy_list = []
        colors = []
        for ik, num in enumerate(FileList):
            #  -- load     --  #
            Data = lpf.load__pointFile(inpFile=inpFile.format(num))
            #  -- energy   --  #
            beta = np.sqrt(Data[:, vx_]**2 + Data[:, vy_]**2 +
                           Data[:, vz_]**2) / const["cv"]
            gamma = 1.0 / (np.sqrt(1.0 - beta**2))
            energy = (gamma - 1.0) * const["mp"] * const["cv"]**2 / np.abs(
                const["qe"])
            #  -- eMax     --  #
            if (AutoRange):
                eMin = np.min([eMin, np.min(energy)])
                eMax = np.max([eMax, np.max(energy)])

            #  -- packing  --  #
            energy_list.append(energy)
        print("[display__beamline]  ( eMin, eMax ) = ( {0}, {1} ) ".format(
            eMin, eMax))
        for ik, henergy in enumerate(energy_list):
            henergy = (henergy - eMin) / (eMax - eMin)
            henergy[np.where(henergy < 0.0)] = 0.0
            henergy[np.where(henergy > 1.0)] = 1.0
            colors.append(henergy)

    # ------------------------------------------------- #
    # --- [3] config Settings                       --- #
    # ------------------------------------------------- #
    config["FigSize"] = (8.0, 2.0)
    config["plt_position"] = [0.16, 0.24, 0.94, 0.94]
    config["xTitle"] = "Z (m)"
    config["yTitle"] = "R (m)"
    config["plt_xAutoRange"] = False
    config["plt_yAutoRange"] = False
    config["plt_xRange"] = [-0.5, +3.0]
    config["plt_yRange"] = [-0.000, +0.020]
    config["plt_linewidth"] = 0.2
    config["xMajor_Nticks"] = 8
    config["yMajor_Nticks"] = 3

    # ------------------------------------------------- #
    # --- [4] plot Figure                           --- #
    # ------------------------------------------------- #
    fig = pl1.plot1D(config=config, pngFile=pngFile)
    for ik, num in enumerate(FileList):
        Data = lpf.load__pointFile(inpFile=inpFile.format(num))
        if (colormode in ["energy"]):
            fig.add__colorline(xAxis=Data[:, z_],
                               yAxis=Data[:, x_],
                               color=colors[ik],
                               cmap="jet")
        else:
            fig.add__plot(xAxis=Data[:, z_],
                          yAxis=Data[:, x_],
                          color=colors[ik])
    fig.set__axis()
    fig.save__figure()
Example #22
0
# ========================================================= #
# === matplotlib 共通 パラメータ セッティング           === #
# ========================================================= #
import matplotlib.pyplot as plt
import nkUtilities.load__config as lcf

config = lcf.load__config()

# ------------------------------------------------- #
# --- 全体設定                                  --- #
# ------------------------------------------------- #
plt.style.use('seaborn-white')
plt.rcParams['figure.dpi'] = config["densityPNG"]

# ------------------------------------------------- #
# --- 画像 サイズ / 余白 設定                   --- #
# ------------------------------------------------- #
# -- 相対座標  --  #
plt.rcParams['figure.subplot.left'] = 0.0
plt.rcParams['figure.subplot.bottom'] = 0.0
plt.rcParams['figure.subplot.right'] = 1.0
plt.rcParams['figure.subplot.top'] = 1.0
plt.rcParams['figure.subplot.wspace'] = 0.0
plt.rcParams['figure.subplot.hspace'] = 0.0
# -- 余白設定  --  #
plt.rcParams['axes.xmargin'] = 0
plt.rcParams['axes.ymargin'] = 0

# ------------------------------------------------- #
# --- フォント 設定                             --- #
# ------------------------------------------------- #
Example #23
0
def configSettings(configType=None, config=None):

    # ------------------------------------------------- #
    # --- [1] Arguments                             --- #
    # ------------------------------------------------- #
    if (configType is None): configType = "cMap2D_def"
    if (config is None): config = lcf.load__config()

    # ------------------------------------------------- #
    # --- [2] 1次元プロット用 デフォルト設定        --- #
    # ------------------------------------------------- #
    if (configType.lower() in ["plot.def", "plot_def", "plot1d_def"]):
        config["FigSize"] = (6, 6)
        config["plt_position"] = [0.12, 0.12, 0.92, 0.92]
        config["plt_linewidth"] = 1.0
        config["plt_linestyle"] = "--"
        config["plt_marker"] = None
        config["plt_markersize"] = 4.0
        config["plt_markerwidth"] = 1.0
        config["xTitle"] = "x"
        config["yTitle"] = "y"
        config["grid_sw"] = True
        config["xMajor_Nticks"] = 5
        config["yMajor_Nticks"] = 5
        config["xTitle_FontSize"] = 16
        config["yTitle_FontSize"] = 16
        config["xMajor_FontSize"] = 10
        config["yMajor_FontSize"] = 10
        config["leg_location"] = "best"
        config["leg_FontSize"] = 12

    # ------------------------------------------------- #
    # --- [3] マーカープロット設定                  --- #
    # ------------------------------------------------- #
    if (configType.lower() in ["plot.marker", "plot_marker", "plot1d_mark"]):
        config["plt_marker"] = "o"
        config["plt_markersize"] = 4.0
        config["plt_markerwidth"] = 1.0

    # ------------------------------------------------- #
    # --- [4] 対数プロット用設定                    --- #
    # ------------------------------------------------- #
    if (configType.lower() in ["plot.log", "plot_log", "plot1D_log"]):
        config["plt_xlog"] = True
        config["plt_ylog"] = True
        config["grid_sw"] = True
        config["grid_color"] = "dimgray"
        config["grid_width"] = 0.6
        config["grid_style"] = "-"
        config["MinorGrid_sw"] = True
        config["MinorGrid_color"] = "gray"
        config["MinorGrid_width"] = 0.3
        config["MinorGrid_style"] = "-"

    # ------------------------------------------------- #
    # --- [5] 2次元カラーマップ用設定               --- #
    # ------------------------------------------------- #
    if (configType.lower() in ["cmap.def", "cmap_def", "cmap2d_def"]):
        config["FigSize"] = (6, 6)
        config[
            "xMajor_FontSize"] = 14  # it is better to set bigger than plot1d
        config["yMajor_FontSize"] = 14
        config["xTitle_FontSize"] = 20
        config["yTitle_FontSize"] = 20
        config["cmp_position"] = [0.14, 0.14, 0.84, 0.84]
        config["cmp_AutoLevel"] = True
        config["cmp_xAutoRange"] = True
        config["cmp_yAutoRange"] = True
        config["cmp_xAutoTicks"] = True
        config["cmp_yAutoTicks"] = True
        config["cmp_nLevels"] = 255
        config["cmp_ColorTable"] = "jet"
        config["clb_position"] = [0.50, 0.89, 0.88, 0.91]
        config["clb_title"] = None
        config["clb_FontSize"] = 14
        config["clb_title_pos"] = [0.65, 0.935]
        config["grid_sw"] = True
        config["grid_minor_sw"] = True
        config["grid_alpha"] = 0.9
        config["grid_color"] = "darkgrey"
        config["grid_linestyle"] = ":"
        config["grid_linewidth"] = 0.8
        config["grid_minor_color"] = "darkgrey"
        config["grid_minor_style"] = ":"
        config["grid_minor_width"] = 0.6
        config["grid_minor_alpha"] = 0.9

    # ------------------------------------------------- #
    # --- [6] 2次元コンターマップ用設定             --- #
    # ------------------------------------------------- #
    if (configType.lower() in ["contour.def", "contour_def"]):
        config["cnt_nLevels"] = 30
        config["cnt_AutoLevel"] = True
        config["cnt_color"] = "grey"
        config["cnt_linewidth"] = 1.0

    # ------------------------------------------------- #
    # --- [7] ベクトルプロット用標準設定            --- #
    # ------------------------------------------------- #
    if (configType.lower() in ["vector.def", "vector_def"]):
        config["vec_nvec_x"] = 12
        config["vec_nvec_y"] = 12
        config["vec_color"] = "springgreen"
        config["vec_AutoScale"] = True
        config["vec_scale"] = 1.0
        config["vec_width"] = 0.01
        config["vec_headwidth"] = 2.5
        config["vec_headlength"] = 4.5
        config["vec_pivot"] = "mid"

    # ------------------------------------------------- #
    # --- [8] 軸 消去設定                           --- #
    # ------------------------------------------------- #
    if (configType.lower() in ["noaxis"]):
        config["xTitle"] = ""
        config["yTitle"] = ""
        config["xMajor_NoLabel"] = True
        config["yMajor_NoLabel"] = True
        config["MinimalOut"] = True
        config["clb_nLabel"] = 0
        config["clb_sw"] = False

    # ------------------------------------------------- #
    # --- [9] 2nd Axis Settings                     --- #
    # ------------------------------------------------- #
    if (configType.lower() in ["plot.ax2"]):
        config["FigSize"] = (6, 6)
        config["plt_position"] = [0.14, 0.14, 0.86, 0.86]
        config["grid_sw"] = True
        config["xTitle_FontSize"] = 16
        config["yTitle_FontSize"] = 16
        config["xMajor_FontSize"] = 10
        config["yMajor_FontSize"] = 10
        config["leg_location"] = "best"
        config["leg_FontSize"] = 12
        config["ax2.yMajor.nticks"] = 7
        config["ax2.yAutoRange"] = True
        config["ax2.yMinor.sw"] = False
        config["ax2.yMinor.ntikcs"] = 2
        config["ax2.legend.position"] = [0.65, 0.75]

    return (config)
Example #24
0
def display__particles():

    # ------------------------------------------------- #
    # --- [1] Arguments                             --- #
    # ------------------------------------------------- #
    config = lcf.load__config()
    datFile = "dat/particles.dat"
    vtkFile = "png/particles.vtu"
    pngFile = (datFile.replace("dat", "png")).replace(".png", "_{0}.png")

    # ------------------------------------------------- #
    # --- [2] Fetch Data                            --- #
    # ------------------------------------------------- #
    import nkUtilities.load__pointFile as lpf
    Data = lpf.load__pointFile(inpFile=datFile, returnType="point")
    xAxis = Data[:, 0]
    yAxis = Data[:, 1]
    zAxis = Data[:, 2]

    # ------------------------------------------------- #
    # --- [3] config Settings                       --- #
    # ------------------------------------------------- #
    cfs.configSettings(configType="plot1D_def", config=config)
    cfs.configSettings(configType="plot1D_mark", config=config)
    config["xTitle"] = "X (m)"
    config["yTitle"] = "Y (m)"
    config["plt_xAutoRange"] = True
    config["plt_yAutoRange"] = True
    config["plt_xRange"] = [-5.0, +5.0]
    config["plt_yRange"] = [-5.0, +5.0]
    config["plt_linewidth"] = 1.0
    config["xMajor_Nticks"] = 5
    config["yMajor_Nticks"] = 5
    config["plt_linewidth"] = 0.0

    # ------------------------------------------------- #
    # --- [4] x-y plot Figure                       --- #
    # ------------------------------------------------- #
    config["xTitle"] = "X (m)"
    config["yTitle"] = "Y (m)"
    fig = pl1.plot1D(config=config, pngFile=pngFile.format("xy"))
    fig.add__plot(xAxis=xAxis, yAxis=yAxis)
    fig.add__legend()
    fig.set__axis()
    fig.save__figure()

    # ------------------------------------------------- #
    # --- [5] y-z plot Figure                       --- #
    # ------------------------------------------------- #
    config["xTitle"] = "Y (m)"
    config["yTitle"] = "Z (m)"
    fig = pl1.plot1D(config=config, pngFile=pngFile.format("yz"))
    fig.add__plot(xAxis=yAxis, yAxis=zAxis)
    fig.add__legend()
    fig.set__axis()
    fig.save__figure()

    # ------------------------------------------------- #
    # --- [6] z-x plot Figure                       --- #
    # ------------------------------------------------- #
    config["xTitle"] = "X (m)"
    config["yTitle"] = "Z (m)"
    fig = pl1.plot1D(config=config, pngFile=pngFile.format("xz"))
    fig.add__plot(xAxis=xAxis, yAxis=zAxis)
    fig.add__legend()
    fig.set__axis()
    fig.save__figure()

    # ------------------------------------------------- #
    # --- [7] convert particles plot into vtk       --- #
    # ------------------------------------------------- #
    import nkVTKRoutines.scatter__vtkPoint as sct
    sct.scatter__vtkPoint(Data=Data, vtkFile=vtkFile)
Example #25
0
 def __init__( self, \
               xAxis      = None, yAxis      = None, \
               cMap       = None, Cntr       = None, \
               xvec       = None, yvec       = None, \
               pngFile    = None, config     = None ):
     # ------------------------------------------------- #
     # --- 引数の引き渡し                            --- #
     # ------------------------------------------------- #
     self.xAxis = xAxis
     self.yAxis = yAxis
     self.cMap = cMap
     self.Cntr = Cntr
     self.xvec = xvec
     self.yvec = yvec
     self.config = config
     # ------------------------------------------------- #
     # --- コンフィグの設定                          --- #
     # ------------------------------------------------- #
     if (self.config is None): self.config = lcf.load__config()
     if (pngFile is not None): self.config["pngFile"] = pngFile
     # ------------------------------------------------- #
     # --- レベルの設定  ( カラー / コンター )       --- #
     # ------------------------------------------------- #
     self.cmpLevels = np.linspace(self.config["cmp_MaxMin"][0],
                                  self.config["cmp_MaxMin"][1],
                                  self.config["cmp_nLevels"])
     self.cntLevels = np.linspace(self.config["cnt_MaxMin"][0],
                                  self.config["cnt_MaxMin"][1],
                                  self.config["cnt_nLevels"])
     # ------------------------------------------------- #
     # --- 描画領域の作成                            --- #
     # ------------------------------------------------- #
     #  -- 描画領域                                  --  #
     cmppos = self.config["cmp_position"]
     self.fig = plt.figure(figsize=self.config["FigSize"])
     self.ax1 = self.fig.add_axes([
         cmppos[0], cmppos[1], cmppos[2] - cmppos[0], cmppos[3] - cmppos[1]
     ])
     #  -- 格子の描画 on/off                         --  #
     if (self.config["grid_sw"]): self.ax1.grid(b=None)
     # ------------------------------------------------- #
     # --- x軸 - y軸の作成                           --- #
     # ------------------------------------------------- #
     #  -- もし,引数に x,y 変数が渡されてない場合,インデックスで代用 -- #
     if ((self.xAxis is None) and (self.cMap is not None)):
         self.xAxis = np.arange((self.cMap.shape[0]))
     if ((self.yAxis is None) and (self.cMap is not None)):
         self.yAxis = np.arange((self.cMap.shape[1]))
     #  -- AutoRange (x)  --  #
     if ((self.config["cmp_xAutoRange"]) and (self.xAxis is not None)):
         self.config["cmp_xRange"] = [self.xAxis[0], self.xAxis[-1]]
     #  -- AutoRange (y)  --  #
     if ((self.config["cmp_yAutoRange"]) and (self.yAxis is not None)):
         self.config["cmp_yRange"] = [self.yAxis[0], self.yAxis[-1]]
     # ------------------------------------------------- #
     # --- 速攻描画                                  --- #
     # ------------------------------------------------- #
     instantOut = False
     #  -- もし cMap が渡されていたら,即,描く      --  #
     if (self.cMap is not None):
         self.add__cMap( xAxis   = self.xAxis, yAxis   = self.yAxis,     \
                         cMap    = self.cMap,  levels  = self.cmpLevels  )
         if (self.config["clb_sw"]): self.set__colorBar()
         instantOut = True
     #  -- もし Cntrが渡されていたら,即,描く       --  #
     if (self.Cntr is not None):
         self.add__contour( xAxis   = self.xAxis, yAxis   = self.yAxis,     \
                            Cntr    = self.Cntr,  levels  = self.cntLevels  )
         if (self.config["cnt_Separatrix"]): self.add__separatrix()
         instantOut = True
     # -- もし xvec, yvec が渡されていたら,即,描く --  #
     if ((self.xvec is not None) and (self.yvec is not None)):
         self.add__vector( xAxis = self.xAxis, yAxis = self.yAxis, \
                           uvec  = self.xvec,  vvec  = self.yvec,  )
     # -- もし 何かを描いてたら,出力する.          --  #
     if (instantOut):
         self.writeFigure(pngFile=self.config["pngFile"])
Example #26
0
def display__sf7():

    # ------------------------------------------------- #
    # --- [1] Arguments                             --- #
    # ------------------------------------------------- #
    import nkUtilities.load__constants as lcn
    cnfFile = "dat/parameter.conf"
    const = lcn.load__constants(inpFile=cnfFile)

    config = lcf.load__config()
    datFile = const["spfFile"]
    pngFile = (const["spfFile"].replace("dat",
                                        "png")).replace(".png", "_{0}.png")

    # ------------------------------------------------- #
    # --- [2] Fetch Data                            --- #
    # ------------------------------------------------- #
    import nkUtilities.load__pointFile as lpf
    Data = lpf.load__pointFile(inpFile=datFile, returnType="point")
    xAxis = Data[:, 0]
    yAxis = Data[:, 1]
    zAxis = Data[:, 2]
    Ez = Data[:, 3]
    Er = Data[:, 4]
    Ea = Data[:, 5]
    Hp = Data[:, 6]

    # ------------------------------------------------- #
    # --- [3] config Settings                       --- #
    # ------------------------------------------------- #
    cfs.configSettings(configType="cMap_def", config=config)
    config["FigSize"] = (8, 3)
    config["cmp_position"] = [0.16, 0.12, 0.97, 0.88]
    config["xTitle"] = "Z (m)"
    config["yTitle"] = "R (m)"
    config["xMajor_Nticks"] = 8
    config["yMajor_Nticks"] = 3
    config["cmp_xAutoRange"] = True
    config["cmp_yAutoRange"] = True
    config["cmp_xRange"] = [-5.0, +5.0]
    config["cmp_yRange"] = [-5.0, +5.0]
    config["vec_AutoScale"] = True
    config["vec_AutoRange"] = True
    config["vec_AutoScaleRef"] = 200.0
    config["vec_nvec_x"] = 24
    config["vec_nvec_y"] = 6
    config["vec_interpolation"] = "nearest"

    # ------------------------------------------------- #
    # --- [4] plot Figure                           --- #
    # ------------------------------------------------- #
    cmt.cMapTri(xAxis=xAxis,
                yAxis=yAxis,
                cMap=Ez,
                pngFile=pngFile.format("Ez"),
                config=config)
    cmt.cMapTri(xAxis=xAxis,
                yAxis=yAxis,
                cMap=Er,
                pngFile=pngFile.format("Er"),
                config=config)
    cmt.cMapTri(xAxis=xAxis,
                yAxis=yAxis,
                cMap=Ea,
                pngFile=pngFile.format("Ea"),
                config=config)
    cmt.cMapTri(xAxis=xAxis,
                yAxis=yAxis,
                cMap=Hp,
                pngFile=pngFile.format("Hp"),
                config=config)

    fig = cmt.cMapTri(pngFile=pngFile.format("Ev"), config=config)
    fig.add__contour(xAxis=xAxis, yAxis=yAxis, Cntr=Hp)
    fig.add__cMap(xAxis=xAxis, yAxis=yAxis, cMap=Hp)
    fig.add__vector(xAxis=xAxis, yAxis=yAxis, uvec=Ez, vvec=Er, color="blue")
    fig.save__figure()
def display__axial_interaction(time=0.0, nRepeat=1):

    x_, y_, z_ = 0, 1, 2
    vx_, vy_, vz_ = 3, 4, 5

    # ------------------------------------------------- #
    # --- [1] Load Config & Eigenmode               --- #
    # ------------------------------------------------- #

    import nkUtilities.load__constants as lcn
    cnsFile = "dat/parameter.conf"
    pngFile = "png/axial/axial_interaction_{0}.png"
    config = lcf.load__config()
    const = lcn.load__constants(inpFile=cnsFile)

    import nkUtilities.load__pointFile as lpf
    wave1 = lpf.load__pointFile(inpFile=const["tw_cosEigenFile"],
                                returnType="point")
    wave2 = lpf.load__pointFile(inpFile=const["tw_sinEigenFile"],
                                returnType="point")

    val = 0.0
    eps = 1.e-10
    index1 = np.where(np.abs(wave1[:, x_] - val) <= eps)
    index2 = np.where(np.abs(wave2[:, x_] - val) <= eps)
    wave1 = wave1[index1]
    wave2 = wave2[index2]
    zAxis = wave1[:, z_]
    ez1 = wave1[:, vz_]
    ez2 = wave2[:, vz_]

    ez1Stack = np.copy(ez1)
    ez2Stack = np.copy(ez2)
    zStack = np.copy(zAxis)
    zLeng = np.max(zAxis) - np.min(zAxis)
    for ik in range(1, nRepeat):
        ez1_ = (np.copy(ez1))[1:]
        ez2_ = (np.copy(ez2))[1:]
        zAxis_ = (np.copy(zAxis) + zLeng * float(ik))[1:]
        ez1Stack = np.concatenate([ez1Stack, ez1_])
        ez2Stack = np.concatenate([ez2Stack, ez2_])
        zStack = np.concatenate([zStack, zAxis_])
    zAxis = zStack
    ez1 = ez1Stack
    ez2 = ez2Stack

    # ------------------------------------------------- #
    # --- [2] prepare cos & sin theta               --- #
    # ------------------------------------------------- #
    theta = 2.0 * np.pi * const["tw_frequency"] * time + const["tw_phase"]
    costh = +np.cos(theta)
    sinth = +np.sin(theta)

    # ------------------------------------------------- #
    # --- [3] config Settings                       --- #
    # ------------------------------------------------- #
    config["FigSize"] = (10, 3)
    config["cmp_position"] = [0.12, 0.16, 0.97, 0.92]
    config["xTitle"] = "Z (m)"
    config["yTitle"] = "Ez (V/m)"
    config["plt_xAutoRange"] = False
    config["plt_yAutoRange"] = False
    config["plt_xRange"] = [0.0, 1.40]
    config["plt_yRange"] = [-6.e+6, 6.e+6]
    config["xMajor_Nticks"] = 6

    # ------------------------------------------------- #
    # --- [4] collect particles                     --- #
    # ------------------------------------------------- #
    import collect__particles as clp
    ret = clp.collect__particles(target_time=time)
    npt = ret.shape[0]
    height = 3.e6
    ppos = np.linspace(-height, +height, npt)
    zpos = ret[:, 3]

    # ------------------------------------------------- #
    # --- [4] plot Figure ( bfield )                --- #
    # ------------------------------------------------- #
    stime = "t{0:.3f}ns".format(time / 1e-9)
    Ez = ez1 * costh + ez2 * sinth
    fig = pl1.plot1D(config=config, pngFile=pngFile.format(stime))
    fig.add__plot(xAxis=zAxis, yAxis=Ez)
    fig.add__plot(xAxis=zpos, yAxis=ppos, marker="o")
    fig.set__axis()
    fig.save__figure()
Example #28
0
def display__axial_wavePropagation(inpFile=None):

    x_, y_, z_ = 0, 1, 2
    vx_, vy_, vz_ = 3, 4, 5

    # ------------------------------------------------- #
    # --- [1] Load Config & Eigenmode               --- #
    # ------------------------------------------------- #

    import nkUtilities.load__constants as lcn
    cnsFile = "dat/parameter.conf"
    pngFile = "png/axial_wavePropagation.png"
    config = lcf.load__config()
    const = lcn.load__constants(inpFile=cnsFile)

    import nkUtilities.load__pointFile as lpf
    wave1 = lpf.load__pointFile(inpFile=const["tw_cosEigenFile"],
                                returnType="point")
    wave2 = lpf.load__pointFile(inpFile=const["tw_sinEigenFile"],
                                returnType="point")

    val = 0.0
    eps = 1.e-10
    index1 = np.where(np.abs(wave1[:, x_] - val) <= eps)
    index2 = np.where(np.abs(wave2[:, x_] - val) <= eps)
    wave1 = wave1[index1]
    wave2 = wave2[index2]
    zAxis = wave1[:, z_]
    ez1 = wave1[:, vz_]
    ez2 = wave2[:, vz_]

    # ------------------------------------------------- #
    # --- [2] prepare cos & sin theta               --- #
    # ------------------------------------------------- #
    flag__easyplot = True
    if (flag__easyplot):
        const["tw_timeStart"] = 0.0
        const["tw_nCycle"] = 1
        const["tw_nTime"] = 12

    t_period = 1.0 / (const["tw_frequency"])
    tStart = const["tw_timeStart"]
    tEnd = const["tw_timeStart"] + t_period * const["tw_nCycle"]
    time = np.linspace(tStart, tEnd, const["tw_nTime"])
    theta = 2.0 * np.pi * const["tw_frequency"] * time + const["tw_phase"]
    costh = +np.cos(theta)
    sinth = +np.sin(theta)

    # ------------------------------------------------- #
    # --- [3] config Settings                       --- #
    # ------------------------------------------------- #
    config["FigSize"] = (8, 4)
    config["cmp_position"] = [0.16, 0.12, 0.97, 0.88]
    config["xTitle"] = "Z (m)"
    config["yTitle"] = "Ez (V/m)"
    config["plt_xAutoRange"] = False
    config["plt_yAutoRange"] = False
    config["plt_xRange"] = [0.0, 0.15]
    config["plt_yRange"] = [-6.e+6, 6.e+6]
    config["xMajor_Nticks"] = 6

    # ------------------------------------------------- #
    # --- [4] plot Figure ( bfield )                --- #
    # ------------------------------------------------- #

    fig = pl1.plot1D(config=config, pngFile=pngFile)
    import matplotlib.cm
    colors = matplotlib.cm.jet(np.linspace(0, 1, const["tw_nTime"]))
    for ik in range(const["tw_nTime"]):
        Ez = ez1 * costh[ik] + ez2 * sinth[ik]
        fig.add__plot(xAxis=zAxis,
                      yAxis=Ez,
                      label="t={0:.3}".format(time[ik] / 1e-9),
                      color=colors[ik])
    fig.add__legend()
    fig.set__axis()
    fig.save__figure()