def load__field():

    # ------------------------------------------------- #
    # --- [1] load ems_pst.field & source.dat       --- #
    # ------------------------------------------------- #

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

    import nkUtilities.load__pointFile as lpf
    inpFile = "dat/ems_pst.field"
    BField = lpf.load__pointFile(inpFile=inpFile, returnType="point")
    inpFile = "dat/source_wofield.dat"
    source = lpf.load__pointFile(inpFile=inpFile, returnType="structured")

    # ------------------------------------------------- #
    # --- [2] store in grid                         --- #
    # ------------------------------------------------- #

    import nkBasicAlgs.store__inGrid3D as sig
    BField_   = sig.store__inGrid3D( Data=BField, x1MinMaxNum=const["x1MinMaxNum"], \
                                     x2MinMaxNum=const["x2MinMaxNum"], \
                                     x3MinMaxNum=const["x3MinMaxNum"],  )
    source[:, :, :, 3:6] = BField_[:, :, :, 3:6]

    # ------------------------------------------------- #
    # --- [3] save as source.dat                    --- #
    # ------------------------------------------------- #

    import nkUtilities.save__pointFile as spf
    outFile = "dat/source.dat"
    spf.save__pointFile(outFile=outFile, Data=source)
Ejemplo n.º 2
0
def make__in7():

    # -- execute this script to generate grided field -- #
    # -- sf7 : post processor for poisson-superfish   -- #
    # -- in7 : input file for sf7                     -- #

    # ------------------------------------------------- #
    # --- [1] load config file                      --- #
    # ------------------------------------------------- #

    import nkUtilities.load__constants as lcn
    cnfFile = "dat/parameter.conf"
    const   = lcn.load__constants( inpFile=cnfFile )
    
    # ------------------------------------------------- #
    # --- [2] write in file                         --- #
    # ------------------------------------------------- #

    
    line1 = "rect noscreen\n"
    line2 = "{0} {1} {2} {3}\n".format( const["sf7_xMinMaxNum"][0], const["sf7_yMinMaxNum"][0], \
                                        const["sf7_xMinMaxNum"][1], const["sf7_yMinMaxNum"][1]  )
    line3 = "{0} {1}\n".format( int( const["sf7_xMinMaxNum"][2]-1 ), \
                                int( const["sf7_yMinMaxNum"][2]-1 ) )
    line4 = "end\n"
    # line3 :: number of space should be prescribed == Not number of nodes.

    text  = line1 + line2 + line3 + line4

    with open( const["in7File"], "w" ) as f:
        f.write( text )
    print( "[make__in7.py] outFile :: {0} ".format( const["in7File"] ) )
Ejemplo n.º 3
0
def select__particles_judge():

    # ------------------------------------------------- #
    # --- [1] preparation                           --- #
    # ------------------------------------------------- #
    #  -- [1-1] probe file                          --  #
    outFile = "dat/selected.dat"
    inpFile = "prb/probe{0:06}.dat"

    #  -- [1-2] load constants                      --  #
    cnsFile = "dat/particle.conf"
    import nkUtilities.load__constants as lcn
    const   = lcn.load__constants( inpFile=cnsFile )
    
    # ------------------------------------------------- #
    # --- [2] select probe File                     --- #
    # ------------------------------------------------- #

    with open( outFile, "w" ) as f:
        # -- [2-1] write header                     --  #
        f.write( "# FileNumber\n" )

        # -- [2-2] judge and save result            --  #
        for ik in range( const["npt"] ):
            Data      = lpf.load__pointFile( inpFile=inpFile.format( ik+1 ), returnType="point" )
            if ( judge__particles( Data=Data ) is True ):
                f.write( "{0}\n".format( ik+1 ) )
    
    # ------------------------------------------------- #
    # --- [3] save as file                          --- #
    # ------------------------------------------------- #
    return()
Ejemplo n.º 4
0
def into__namelist(inpFile="dat/parameter.conf", outFile="dat/input.lst"):

    # ------------------------------------------------- #
    # --- [1] load constants info                   --- #
    # ------------------------------------------------- #
    const = lcn.load__constants(inpFile=inpFile)
    keys     = [ "EFieldListFile", "BFieldListFile", "EFieldParamFile", "BFieldParamFile", \
                 "particleFile"  , "popoutFile"    , "probeFileBase"  , "bpmFile", \
                 "flag__axisymmetry"  , "flag__popoutBoundary", \
                 "flag__probeField"   , "flag__beamposmonitor", \
                 "particleBoundary__x", "particleBoundary__y" , "particleBoundary__z", \
                 "type__iterMax" , "type__dt", "iterMax", "dt", "alpha_wci", "alpha_CFL", \
                 "t_simuStart"   , "t_simuEnd", "t_probeStart", "t_probeStep", "t_probeEnd", \
                 "bpm_direction" , "bpm_screen_pos", "mp", "qe" ]

    print(keys)

    # ------------------------------------------------- #
    # --- [2] save constants in File                --- #
    # ------------------------------------------------- #
    snl.save__namelist(outFile=outFile, const=const, keys=keys)
    print()
    print("[into__namelist.py]  inpFile :: {0} ".format(inpFile))
    print("[into__namelist.py]  converted into... ")
    print("[into__namelist.py]  outFile :: {0} ".format(outFile))
    print()
    return ()
Ejemplo n.º 5
0
def generate__line_coord():

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

    # ------------------------------------------------- #
    # --- [2] generate radial line                  --- #
    # ------------------------------------------------- #
    rval  = np.linspace( const["r1"], const["r2"], const["nData"] )
    angle = const["theta"] / 360.0 * 2.0 * np.pi
    xg    = np.cos( angle ) * rval
    yg    = np.sin( angle ) * rval
    zg    = np.zeros( ( const["nData"], ) )

    Data  = np.concatenate( [ arr[:,np.newaxis] for arr in (xg,yg,zg) ], axis=-1 )

    # ------------------------------------------------- #
    # --- [3] save in file                          --- #
    # ------------------------------------------------- #
    import nkUtilities.save__pointFile as spf
    outFile   = "dat/out.dat"
    spf.save__pointFile( outFile=outFile, Data=Data )
    
    return()
Ejemplo n.º 6
0
def select__particles_array():

    # ------------------------------------------------- #
    # --- [1] preparation                           --- #
    # ------------------------------------------------- #
    #  -- [1-1] probe file                          --  #
    outFile = "dat/selected.dat"

    #  -- [1-2] args                                --  #
    import nkUtilities.genArgs as gar
    args    = gar.genArgs()
    array   = None
    if ( args["array"] is not None ):
        array = [ int( val ) for val in args["array"] ]
        
    #  -- [1-3] load constants                      --  #
    if ( array is None ):
        import nkUtilities.load__constants as lcn
        cnsFile = "dat/parameter.conf"
        const   = lcn.load__constants( inpFile=cnsFile )
        array = [ int( val ) for val in const["post.select.pt.array"] ]
        
    #  -- [1-3] write all particles num             --  #
    with open( outFile, "w" ) as f:
        # -- [1-3-1] write header                   --  #
        f.write( "# FileNumber\n" )
        # -- [1-3-2] judge and save result          --  #
        for ipt in array:
            f.write( "{0}\n".format( ipt ) )
    return()
Ejemplo n.º 7
0
def make__answer():

    # ------------------------------------------------- #
    # --- [1] coordinate settings                   --- #
    # ------------------------------------------------- #

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

    import nkUtilities.equiSpaceGrid as esg
    grid     = esg.equiSpaceGrid( x1MinMaxNum=const["x1MinMaxNum"], x2MinMaxNum=const["x2MinMaxNum"], \
                                  x3MinMaxNum=const["x3MinMaxNum"], returnType = "point" )
    BField = np.zeros((grid.shape[0], 6))
    BField[:, 0:3] = grid

    # ------------------------------------------------- #
    # --- [2] coil position settings                --- #
    # ------------------------------------------------- #

    x_, y_, z_ = 0, 1, 2
    theta = np.linspace(0.0, 2.0 * np.pi, const["ntheta"])
    coil_x = const["coil_center"][x_] + np.cos(theta)
    coil_y = const["coil_center"][y_] + np.sin(theta)
    coil_z1 = +const["coil_center"][z_] + theta * 0.0
    coil_z2 = -const["coil_center"][z_] + theta * 0.0
    coil1 = np.concatenate(
        [coil_x[:, None], coil_y[:, None], coil_z1[:, None]], axis=1)
    coil2 = np.concatenate(
        [coil_x[:, None], coil_y[:, None], coil_z2[:, None]], axis=1)

    # ------------------------------------------------- #
    # --- [3] coil field                            --- #
    # ------------------------------------------------- #

    import nkPhysicsRoutines.calc__biotSavartBField as bsf
    field1 = bsf.calc__biotSavartBField(bfield=BField,
                                        coils=coil1,
                                        I0=const["I0"])
    field2 = bsf.calc__biotSavartBField(bfield=BField,
                                        coils=coil2,
                                        I0=const["I0"])
    field = np.zeros((field1.shape[0], field1.shape[1]))
    field[:, 0:3] = field1[:, 0:3]
    field[:, 3:6] = field1[:, 3:6] + field2[:, 3:6]

    shape        = ( int( const["x3MinMaxNum"][2] ), int( const["x2MinMaxNum"][2] ), \
                     int( const["x1MinMaxNum"][2] ), 6 )
    field = np.reshape(field, shape)

    # ------------------------------------------------- #
    # --- [4] save point Field                      --- #
    # ------------------------------------------------- #

    outFile = "dat/coilfield.dat"
    import nkUtilities.save__pointFile as spf
    spf.save__pointFile(outFile=outFile, Data=field)

    return ()
Ejemplo n.º 8
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()
Ejemplo n.º 9
0
def histogram__energy(div=11, eRange=None):

    # inpFile = "dat/particles.dat"
    # pngFile = "png/histogram__initParticles.png"

    inpFile = "bpm/screen_bpm.dat"
    pngFile = "png/histogram__bpmParticles.png"

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

    # ------------------------------------------------- #
    # --- [1] load constants & data                 --- #
    # ------------------------------------------------- #

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

    # ------------------------------------------------- #
    # --- [2] make hist of particle's energy        --- #
    # ------------------------------------------------- #

    Data = lpf.load__pointFile(inpFile=inpFile, returnType="point")

    vabs = np.sqrt(Data[:, vx_]**2 + Data[:, vy_]**2 + Data[:, vz_]**2)
    beta = vabs / const["cv"]
    print(np.min(beta), np.max(beta))
    Th = 1.0 / (np.sqrt(1.0 - beta**2)) - 1.0
    hEk = const["mp"] * const["cv"]**2 / const["qe"] * Th

    # histogram, bins = np.histogram( hEk, bins=div, range=eRange )
    # haxis = ( 0.5 * ( bins + np.roll( bins, 1 ) ) )[1:]
    # haxis = haxis / 1000.0

    import matplotlib.pyplot as plt
    fig, ax = plt.subplots(1)
    # ax.set_facecolor( "lightcyan" )
    ax.grid(zorder=1, color="gray")
    ax.hist( hEk, bins=div, range=eRange, rwidth=0.7, color="royalblue", \
             edgecolor="white", linewidth=1.8, zorder=2 )
    fig.savefig(pngFile)
Ejemplo n.º 10
0
def interpret__config(inpFile="dat/parameter.conf", outFile="dat/input.conf"):

    # ------------------------------------------------- #
    # --- [1] load constants info                   --- #
    # ------------------------------------------------- #
    const = lcn.load__constants(inpFile=inpFile)
    keys = lcn.load__constants(inpFile=inpFile, returnKeys=True)
    print(keys)

    # ------------------------------------------------- #
    # --- [2] save constants in File                --- #
    # ------------------------------------------------- #
    scn.save__constants(outFile=outFile, const=const, keys=keys)
    print()
    print("[interpret__config.py]  inpFile :: {0} ".format(inpFile))
    print("[interpret__config.py]  converted into... ")
    print("[interpret__config.py]  outFile :: {0} ".format(outFile))
    print()
    return ()
Ejemplo n.º 11
0
def make__poleSurface():

    # ------------------------------------------------- #
    # --- [1] load constants                        --- #
    # ------------------------------------------------- #
    cnsFile = "dat/parameter.conf"
    import nkUtilities.load__constants as lcn
    const = lcn.load__constants(inpFile=cnsFile)
    lc1 = const["geometry.pole_lc_top"]
    lc2 = const["geometry.pole_lc_bot"]
    radius = const["geometry.r_pole"]
    side = const["geometry.side"]

    # ------------------------------------------------- #
    # --- [2] interpolation / gmsh <-> elmer        --- #
    # ------------------------------------------------- #
    nop = True

    if (side in ["+", "+-", "-+"]):
        generate__mesh_to_interpolate(lc1=lc1,
                                      lc2=lc2,
                                      radius=radius,
                                      side="+")
        convert__meshFormat(direction="gmsh->elmer")
        ret = interpolate__grid_to_mesh(side="+")
        nop = False

    if (side in ["-", "+-", "-+"]):
        generate__mesh_to_interpolate(lc1=lc1,
                                      lc2=lc2,
                                      radius=radius,
                                      side="-")
        convert__meshFormat(direction="gmsh->elmer")
        ret = interpolate__grid_to_mesh(side="-")
        nop = False

    if (side in ["+-", "-+"]):
        generate__mesh_to_interpolate(lc1=lc1,
                                      lc2=lc2,
                                      radius=radius,
                                      side="+-")
        convert__meshFormat(direction="gmsh->elmer")
        ret = interpolate__grid_to_mesh(side="+-")
        nop = False

    if (nop):
        print("[make__poleSurface.py] no Operation !!! ERROR !!! ")
    else:
        convert__meshFormat(direction="elmer->gmsh", side=side)

    return ()
Ejemplo n.º 12
0
def show__waveCondition():

    # ------------------------------------------------- #
    # --- [1] constants                             --- #
    # ------------------------------------------------- #

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

    # ------------------------------------------------- #
    # --- [2] calculate amplitude                   --- #
    # ------------------------------------------------- #

    omega = 2.0 * np.pi * const["tw_frequency"]
    tau = 1.0 / const["tw_frequency"]
    vphT = const["beta_wave"] * const["cv"] * tau
    P_loss = omega * const["Ustored"] / const["Qvalue"]
    amplitude_factor = np.sqrt(const["P_input"] / P_loss)
    energy_gain = np.sqrt(const["Lcavity"] * const["rsh"] * const["P_input"])

    # ------------------------------------------------- #
    # --- [3] display                               --- #
    # ------------------------------------------------- #

    print()
    print("[calculate__power_of_wave] frequency     :: {0}".format(
        const["tw_frequency"]))
    print("[calculate__power_of_wave]     omega     :: {0}".format(omega))
    print("[calculate__power_of_wave]         T     :: {0}".format(tau))
    print("[calculate__power_of_wave]   Lcavity     :: {0}".format(
        const["Lcavity"]))
    print("[calculate__power_of_wave]   vph * T     :: {0}".format(vphT))
    print()
    print("[calculate__power_of_wave]   Ustored     :: {0}".format(
        const["Ustored"]))
    print("[calculate__power_of_wave]    Qvalue     :: {0}".format(
        const["Qvalue"]))
    print("[calculate__power_of_wave]       rsh     :: {0}".format(
        const["rsh"]))
    print("[calculate__power_of_wave]   P_input     :: {0}".format(
        const["P_input"]))
    print("[calculate__power_of_wave] t_transit     :: {0}".format(
        const["t_transit_time"]))
    print()
    print("[calculate__power_of_wave]    P_loss     :: {0}".format(P_loss))
    print("[calculate__power_of_wave] amplitude     :: {0}".format(
        amplitude_factor))
    print(
        "[calculate__power_of_wave] energy_gain   :: {0}".format(energy_gain))
    print()
Ejemplo n.º 13
0
def load__config( config=None ):

    # ------------------------------------------------- #
    # --- [1] Arguments                             --- #
    # ------------------------------------------------- #
    if ( config is None ):
        dirname = os.path.dirname( os.path.abspath( __file__ ) )
        config  = os.path.join( dirname, "default.conf" )
        
    # ------------------------------------------------- #
    # --- [2] load constants                        --- #
    # ------------------------------------------------- #
    const   = lcn.load__constants( inpFile=config )
    return( const )
Ejemplo n.º 14
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()
Ejemplo n.º 15
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()
Ejemplo n.º 16
0
def make__batch():

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

    line1 = "cd/d {0}\n".format(const["cur_dir"])
    line2 = "start /w /min %SFDIR%automesh maglens\n"
    line3 = "start /w /min %SFDIR%pandira  maglens\n"
    line4 = "start /w /min %SFDIR%sf7 maglens.in7 maglens.t35\n"
    line5 = "exit\n"

    with open(const["batchFile"], "w") as f:
        f.write(line1 + line2 + line3 + line4 + line5)
    print("[make__batch.py] outFile :: {0} ".format(const["batchFile"]))
    print()
Ejemplo n.º 17
0
def sequencial__TEmode():

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

    # ------------------------------------------------- #
    # --- [2] calculate TE mode at each time        --- #
    # ------------------------------------------------- #

    timearr = np.linspace(const["tMin"], const["tMax"], const["LT"])

    for ik in range(const["LT"]):
        waveguide__TEmode(time=timearr[ik], kstep=ik)
Ejemplo n.º 18
0
def generate__samplewave():

    # ------------------------------------------------- #
    # --- [1] Load Config                           --- #
    # ------------------------------------------------- #

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

    import nkUtilities.equiSpaceGrid as esg
    x1MinMaxNum = const["x1MinMaxNum"]
    x2MinMaxNum = const["x2MinMaxNum"]
    x3MinMaxNum = const["x3MinMaxNum"]
    grid        = esg.equiSpaceGrid( x1MinMaxNum=x1MinMaxNum, x2MinMaxNum=x2MinMaxNum, \
                                     x3MinMaxNum=x3MinMaxNum, returnType = "point" )
    kx, ky      = const["sample_kx"], const["sample_ky"]
    wave1       = np.cos( grid[:,0] * 2.0*np.pi*kx ) + np.sin( grid[:,1] *2.0*np.pi*ky )
    wave2       = np.sin( grid[:,0] * 2.0*np.pi*kx ) + np.cos( grid[:,1] *2.0*np.pi*ky )
    wave1_      = np.concatenate( (grid,wave1[:,None]), axis=1 )
    wave2_      = np.concatenate( (grid,wave2[:,None]), axis=1 )
    size        = (int(x3MinMaxNum[2]),int(x2MinMaxNum[2]),int(x1MinMaxNum[2]),4)
    wave1       = np.reshape( wave1_, size )
    wave2       = np.reshape( wave2_, size )
    
    # ------------------------------------------------- #
    # --- [2] save in File                          --- #
    # ------------------------------------------------- #

    import nkUtilities.save__pointFile as spf
    wavFile1   = "dat/sample_wave1.dat"
    wavFile2   = "dat/sample_wave2.dat"
    spf.save__pointFile( outFile=wavFile1, Data=wave1 )
    spf.save__pointFile( outFile=wavFile2, Data=wave2 )
    
    # ------------------------------------------------- #
    # --- [3] display eigen mode                    --- #
    # ------------------------------------------------- #

    import nkUtilities.cMapTri as cmt
    pngFile1    = "png/sample_wave1.png"
    pngFile2    = "png/sample_wave2.png"
    cmt.cMapTri( xAxis=wave1_[...,0], yAxis=wave1_[...,1], cMap=wave1_[...,3], pngFile=pngFile1 )
    cmt.cMapTri( xAxis=wave2_[...,0], yAxis=wave2_[...,1], cMap=wave2_[...,3], pngFile=pngFile2 )

    return()
Ejemplo n.º 19
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" ) )
Ejemplo n.º 20
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) )
Ejemplo n.º 21
0
def generate__particleSample():

    xp_, yp_, zp_ = 0, 1, 2
    vx_, vy_, vz_ = 3, 4, 5

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

    # ------------------------------------------------- #
    # --- [1] particle generation                   --- #
    # ------------------------------------------------- #

    #  -- [1-1] systematic components (xp)          --  #
    Data = np.zeros((const["npt"], 6))
    Data[:, xp_] = np.linspace(const["xMin"], const["xMax"], const["npt"])
    Data[:, yp_] = np.linspace(const["yMin"], const["yMax"], const["npt"])
    Data[:, zp_] = np.linspace(const["zMin"], const["zMax"], const["npt"])
    #  -- [1-2] systematic components (vp)          --  #
    Data[:, vx_] = const["cv"] * const["beta_x"]
    Data[:, vy_] = const["cv"] * const["beta_y"]
    Data[:, vz_] = const["cv"] * const["beta_z"]

    #  -- [1-3] random components (xp)              --  #
    Data[:,
         xp_] = Data[:, xp_] + np.random.randn(const["npt"]) * const["sigma_x"]
    Data[:,
         yp_] = Data[:, yp_] + np.random.randn(const["npt"]) * const["sigma_y"]
    Data[:,
         zp_] = Data[:, zp_] + np.random.randn(const["npt"]) * const["sigma_z"]
    #  -- [1-4] random components (vp)              --  #
    Data[:, vx_] = Data[:, vx_] + np.random.randn(
        const["npt"]) * const["cv"] * const["sigma_vx"]
    Data[:, vy_] = Data[:, vy_] + np.random.randn(
        const["npt"]) * const["cv"] * const["sigma_vy"]
    Data[:, vz_] = Data[:, vz_] + np.random.randn(
        const["npt"]) * const["cv"] * const["sigma_vz"]

    # ------------------------------------------------- #
    # --- [2] save in outFile                       --- #
    # ------------------------------------------------- #
    outFile = "dat/particles.dat"
    import nkUtilities.save__pointFile as spf
    spf.save__pointFile(outFile=outFile, Data=Data)

    return ()
Ejemplo n.º 22
0
def convert__spf2point( inpFile=None ):

    #
    #  x => r direction
    #  y => t direction
    #
    xp_, yp_, zp_  = 0, 1, 2
    ex_, ey_, ez_  = 3, 4, 5
    
    # ------------------------------------------------- #
    # --- [1] arguments                             --- #
    # ------------------------------------------------- #
    cnsFile    = "dat/field.conf"
    import nkUtilities.load__constants as lcn
    const = lcn.load__constants( inpFile=cnsFile )
    
    if ( inpFile is None ):
        inpFile = const["superfishFile"]
        
    import nkUtilities.load__pointFile as lpf
    Data       = lpf.load__pointFile( inpFile=inpFile, returnType="structured" )
    print( Data.shape )
    LK, LJ, LI = Data.shape[0], Data.shape[1], Data.shape[2]
    Data       = np.reshape( Data, (LK*LJ*LI,7) )

    # ------------------------------------------------- #
    # --- [2] convert into field-type pointFile     --- #
    # ------------------------------------------------- #
    pData          = np.zeros( (Data.shape[0],6) )
    pData[:,xp_]   = Data[:,1]
    pData[:,yp_]   = 0.0
    pData[:,zp_]   = Data[:,0]
    pData[:,ex_]   = Data[:,4] * const["efield_factor"]
    pData[:,ey_]   = 0.0       * const["efield_factor"]
    pData[:,ez_]   = Data[:,3] * const["efield_factor"]

    index          = np.lexsort( ( pData[:,xp_], pData[:,yp_], pData[:,zp_]) )
    pData          = pData[index]
    pData          = np.reshape( pData, (LI,1,LJ,6) )

    import nkUtilities.save__pointFile as spf
    names = ["xp","yp","zp","Ex","Ey","Ez"]
    spf.save__pointFile( outFile=const["efieldFile"], Data=pData, names=names )
Ejemplo n.º 23
0
def generate__travellingWave():

    # ------------------------------------------------- #
    # --- [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
    wave1 = lpf.load__pointFile(inpFile=const["wavFile1"],
                                returnType="structured")
    wave2 = lpf.load__pointFile(inpFile=const["wavFile2"],
                                returnType="structured")

    # ------------------------------------------------- #
    # --- [2] prepare cos & sin theta               --- #
    # ------------------------------------------------- #
    time = np.linspace(const["t_start"], const["t_end"], const["nTime"])
    theta = 2.0 * np.pi * const["frequency"] * 1.e6 * time + const["phase"]
    costh = np.cos(theta)
    sinth = np.sin(theta)

    # ------------------------------------------------- #
    # --- [3] save in File                          --- #
    # ------------------------------------------------- #
    # --  [3-1] preparation                         --  #
    import nkVTKRoutines.convert__vtkStructuredGrid as vts
    import nkUtilities.save__pointFile as spf
    datFile = "dat/wave{0:04}.dat"
    vtsFile = "png/wave{0:04}.vts"

    # --  [3-2] Main Loop                           --  #
    for ik in range(const["nTime"]):
        # --  [3-3] wave data synthesize            --  #
        wave = np.zeros_like(wave1)
        wave[..., 0:3] = wave1[..., 0:3]
        wave[..., 3:] = wave1[..., 3:] * costh[ik] + wave2[..., 3:] * sinth[ik]
        # --  [3-4] save as vts file                --  #
        vts.convert__vtkStructuredGrid(Data=wave, outFile=vtsFile.format(ik))
        # --  [3-5] save as dat file                --  #
        spf.save__pointFile(outFile=datFile.format(ik), Data=wave)
Ejemplo n.º 24
0
def generate__travellingWave():

    # ------------------------------------------------- #
    # --- [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
    wave1 = lpf.load__pointFile(inpFile=const["tw_cosEigenFile"],
                                returnType="structured")
    wave2 = lpf.load__pointFile(inpFile=const["tw_sinEigenFile"],
                                returnType="structured")

    # ------------------------------------------------- #
    # --- [2] prepare cos & sin theta               --- #
    # ------------------------------------------------- #
    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] save in File                          --- #
    # ------------------------------------------------- #
    # --  [3-1] preparation                         --  #
    import nkVTKRoutines.convert__vtkStructuredGrid as vts
    import nkUtilities.save__pointFile as spf
    vtsFile = "png/wave{0:04}.vts"

    # --  [3-2] Main Loop                           --  #
    for ik in range(const["tw_nTime"]):
        # --  [3-3] wave data synthesize            --  #
        wave = np.zeros_like(wave1)
        wave[..., 0:3] = wave1[..., 0:3]
        wave[..., 3:] = wave1[..., 3:] * costh[ik] + wave2[..., 3:] * sinth[ik]
        # --  [3-4] save as vts file                --  #
        vts.convert__vtkStructuredGrid(Data=wave, outFile=vtsFile.format(ik))
Ejemplo n.º 25
0
def select__allparticles():

    # ------------------------------------------------- #
    # --- [1] preparation                           --- #
    # ------------------------------------------------- #
    #  -- [1-1] probe file                          --  #
    outFile = "dat/selected.dat"

    #  -- [1-2] load constants                      --  #
    cnsFile = "dat/particle.conf"
    import nkUtilities.load__constants as lcn
    const   = lcn.load__constants( inpFile=cnsFile )

    #  -- [1-3] write all particles num             --  #
    with open( outFile, "w" ) as f:
        # -- [1-3-1] write header                   --  #
        f.write( "# FileNumber\n" )
        # -- [1-3-2] judge and save result          --  #
        for ik in range( const["npt"] ):
            f.write( "{0}\n".format( ik+1 ) )
    return()
Ejemplo n.º 26
0
def expand__pole_cs(inpFile=None, outFile=None):

    # ------------------------------------------------- #
    # --- [1] Arguments                             --- #
    # ------------------------------------------------- #
    if (inpFile is None): inpFile = "dat/pole_cs.dat"
    if (outFile is None): outFile = "dat/gridData.dat"
    cnsFile = "dat/expand.conf"
    import nkUtilities.load__constants as lcn
    const = lcn.load__constants(inpFile=cnsFile)

    # ------------------------------------------------- #
    # --- [2] Load Settings                         --- #
    # ------------------------------------------------- #

    x1MinMaxNum = const["x1MinMaxNum"]
    x2MinMaxNum = const["x2MinMaxNum"]
    radius = const["radius"]

    with open(inpFile, "r") as f:
        pole = np.loadtxt(f)

    ra = pole[:, 0]
    fa = pole[:, 2]

    # ------------------------------------------------- #
    # --- [3] expand rz Profile >> axi-symmetric    --- #
    # ------------------------------------------------- #

    ret         = axi.expand__axisymmetric( ra=ra, fa=fa, radius=radius, \
                                            x1MinMaxNum=x1MinMaxNum, x2MinMaxNum=x2MinMaxNum )

    # ------------------------------------------------- #
    # --- [4] save result                           --- #
    # ------------------------------------------------- #

    import nkUtilities.save__pointFile as spf
    spf.save__pointFile(outFile=outFile, Data=ret)
Ejemplo n.º 27
0
def generate__bFieldSample():

    x_, y_, z_ = 0, 1, 2
    vx_, vy_, vz_ = 0, 1, 2

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

    # ------------------------------------------------- #
    # --- [2] grid generation                       --- #
    # ------------------------------------------------- #
    import nkUtilities.equiSpaceGrid as esg
    x1MinMaxNum = [
        const["xMin_bfield"], const["xMax_bfield"], const["LI_bfield"]
    ]
    x2MinMaxNum = [
        const["yMin_bfield"], const["yMax_bfield"], const["LJ_bfield"]
    ]
    x3MinMaxNum = [
        const["zMin_bfield"], const["zMax_bfield"], const["LK_bfield"]
    ]
    ret             = esg.equiSpaceGrid( x1MinMaxNum=x1MinMaxNum, x2MinMaxNum=x2MinMaxNum, \
                                         x3MinMaxNum=x3MinMaxNum, returnType = "structured" )
    bfield = np.zeros_like((ret))
    bfield[..., vz_] = const["strength_bfield"]

    Data = np.concatenate((ret, bfield), axis=3)

    # ------------------------------------------------- #
    # --- [3] save in File                          --- #
    # ------------------------------------------------- #
    outFile = "dat/bfield_sample.dat"
    import nkUtilities.save__pointFile as spf
    spf.save__pointFile(outFile=outFile, Data=Data)
Ejemplo n.º 28
0
def generate__axisymm_coord():

    cnfFile     = "dat/parameter.conf"
    outFile     = "dat/axisymm_coord.dat"
    
    import nkUtilities.load__constants as lcn
    const       = lcn.load__constants( inpFile=cnfFile )
    
    import nkUtilities.equiSpaceGrid as esg
    x1MinMaxNum = [ const["rMin"], const["rMax"], const["LI"] ]
    x2MinMaxNum = [ 0.0, 0.0,  1 ]
    x3MinMaxNum = [ const["zMin"], const["zMax"], const["LK"] ]
    ret         = esg.equiSpaceGrid( x1MinMaxNum=x1MinMaxNum, x2MinMaxNum=x2MinMaxNum, \
                                     x3MinMaxNum=x3MinMaxNum, returnType = "point" )

    # ------------------------------------------------- #
    # --- [3] save in file                          --- #
    # ------------------------------------------------- #
    
    with open( outFile, "w" ) as f:
        np.savetxt( f, ret )
    
    return()
def calculate__field():

    # ------------------------------------------------- #
    # --- [1] coordinate settings                   --- #
    # ------------------------------------------------- #

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

    # ------------------------------------------------- #
    # --- [2] coil position settings                --- #
    # ------------------------------------------------- #

    x_, y_, z_ = 0, 1, 2
    theta = np.linspace(0.0, 2.0 * np.pi, const["ntheta"])
    coil_x = const["coil_center"][x_] + np.cos(theta)
    coil_y = const["coil_center"][y_] + np.sin(theta)
    coil_z1 = +const["coil_center"][z_] + theta * 0.0
    coil_z2 = -const["coil_center"][z_] + theta * 0.0
    coil1 = np.concatenate(
        [coil_x[:, None], coil_y[:, None], coil_z1[:, None]], axis=1)
    coil2 = np.concatenate(
        [coil_x[:, None], coil_y[:, None], coil_z2[:, None]], axis=1)

    # ------------------------------------------------- #
    # --- [3] load BField coordinate                --- #
    # ------------------------------------------------- #

    inpFile = "dat/ems_pst.coord"
    import nkUtilities.load__pointFile as lpf
    coord = lpf.load__pointFile(inpFile=inpFile, returnType="point")
    BField = np.zeros((coord.shape[0], 6))
    BField[:, 0:3] = coord

    # ------------------------------------------------- #
    # --- [4] coil field                            --- #
    # ------------------------------------------------- #

    import nkPhysicsRoutines.calc__biotSavartBField as bsf
    field1 = bsf.calc__biotSavartBField(bfield=BField,
                                        coils=coil1,
                                        I0=const["I0"])
    field2 = bsf.calc__biotSavartBField(bfield=BField,
                                        coils=coil2,
                                        I0=const["I0"])
    field = np.zeros((field1.shape[0], field1.shape[1]))
    field[:, 0:3] = field1[:, 0:3]
    field[:, 3:6] = field1[:, 3:6] + field2[:, 3:6]

    # shape        = ( int( const["x3MinMaxNum"][2] ), int( const["x2MinMaxNum"][2] ), \
    #                  int( const["x1MinMaxNum"][2] ), 6 )
    # field        = np.reshape( field, shape )

    # ------------------------------------------------- #
    # --- [5] save point Field                      --- #
    # ------------------------------------------------- #

    outFile = "dat/ems_pst.field"
    import nkUtilities.save__pointFile as spf
    spf.save__pointFile(outFile=outFile, Data=field)
Ejemplo n.º 30
0
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()