コード例 #1
0
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)
コード例 #2
0
def interpolate__grid_to_mesh( gridFile="dat/mshape_svd.dat", meshFile="msh/mesh2d/mesh.nodes", \
                               side="+", interpolation="cubic" ):

    if (side == "+"):
        omsFile = "dat/onmesh_right.dat"
        elmFile = "dat/mesh_right.elements"
    if (side == "-"):
        omsFile = "dat/onmesh_left.dat"
        elmFile = "dat/mesh_left.elements"
    if (side in ["+-", "-+"]):
        omsFile = "dat/onmesh_both.dat"
        elmFile = "dat/mesh_both.elements"

    # ------------------------------------------------- #
    # --- [1] load grid & mesh Data                 --- #
    # ------------------------------------------------- #
    import nkUtilities.load__pointFile as lpf
    grid = lpf.load__pointFile(inpFile=gridFile, returnType="structured")
    mesh = lpf.load__pointFile(inpFile=meshFile, returnType="point")
    gridData = grid[0, :, :, 0:3]
    meshData = mesh[:, 2:5]

    # ------------------------------------------------- #
    # --- [2] interpolation 2D                      --- #
    # ------------------------------------------------- #
    if (interpolation == "linear"):
        import nkInterpolator.interpolate__linear2D as li2
        ret = li2.interpolate__linear2D(gridData=gridData, pointData=meshData)
    elif (interpolation == "cubic"):
        import nkInterpolator.interpolate__bicubic as bic
        ret = bic.interpolate__bicubic(gridData=gridData, pointData=meshData)

    # ------------------------------------------------- #
    # --- [3] save in a File                        --- #
    # ------------------------------------------------- #
    #  -- [3-1] saving data                         --  #
    import nkUtilities.save__pointFile as spf
    spf.save__pointFile(outFile=omsFile, Data=ret)
    #  -- [3-2] copy mesh.elements                  --  #
    cmd = "cp msh/mesh2d/mesh.elements {0}".format(elmFile)
    print("\n" + "[make__poleSurface] copy mesh.elements... ")
    print(cmd + "\n")
    subprocess.call(cmd, shell=True)

    #  -- [3-3] save figure                         --  #
    import nkUtilities.cMapTri as cmt
    pngFile = "png/onmesh.png"
    cmt.cMapTri(xAxis=ret[:, 0],
                yAxis=ret[:, 1],
                cMap=ret[:, 2],
                pngFile=pngFile)

    return (ret)
コード例 #3
0
def interpolate__gridData_onto_line( Data=None, gridFile="dat/grid.dat", lineFile=None, \
                                     x1  =[ 0.0, 0.0 ], x2=[ 1.0, 1.0 ], nDiv=101, \
                                     x_=0, y_=1, v_=2 ):

    # -- for vector field. -- #
    # x_,y_,v_ = 0, 1, 5
    # -- 
    
    # ------------------------------------------------- #
    # --- [1] grid & line Loading                   --- #
    # ------------------------------------------------- #
    #  -- [1-1] grid Data Loading                   --  #
    if   ( Data is not None ):
        gridData = np.copy( Data )
    elif ( gridFile is not None ):
        import nkUtilities.load__pointFile as lpf
        gridData  = lpf.load__pointFile( inpFile=gridFile, returnType="structured" )
        gridData  = gridData[:,:,(x_,y_,v_)]
    else:
        print( "[interpolate__gridData_onto_line] no Data & no gridFile... [ERROR]" )
        sys.exit()
    gridData_ = ( np.reshape( gridData, (-1,3) ) )
    
    #  -- [1-2] line Data Loading                   --  #
    if ( lineFile is None ):
        lineData  = generate__line2d( x1=x1, x2=x2, nDiv=nDiv )
    else:
        lineData  = lpf.load__pointFile( inpFile=lineFile, returnType="point" )
    lineData_        = np.zeros( (lineData.shape[0],3) )
    lineData_[:,0:2] = np.copy( lineData[:,0:2] )
    
    # ------------------------------------------------- #
    # --- [2] linear Interpolation                  --- #
    # ------------------------------------------------- #
    import nkInterpolator.LinearInterp2D as li2
    ret = li2.LinearInterp2D( gridData    =gridData, pointData=lineData_, \
                              gridDataType="structured" )
    
    # ------------------------------------------------- #
    # --- [3] grid Data contouring                  --- #
    # ------------------------------------------------- #
    import nkUtilities.plot1D     as pl1
    import nkUtilities.LoadConfig as lcf
    config = lcf.LoadConfig()
    config["plt_xAutoRange"] = True
    config["plt_yAutoRange"] = True
    config["plt_xRange"]     = [ 0.0,+1.0]
    config["plt_yRange"]     = [-1.0,+0.0]
    pl1.plot1D( xAxis=ret[:,0], yAxis=ret[:,2], pngFile="interpolate__gridData_onto_line.png", config=config )
    return( ret )
コード例 #4
0
def convert__trajectory2vtp():

    # ------------------------------------------------- #
    # --- [1] preparation                           --- #
    # ------------------------------------------------- #

    import select__particles as sel
    selected = sel.load__selected()
    npt = selected.shape[0]

    inpFile = "prb/probe{0:06}.dat"
    outFile = "png/trajectory{0:06}.vtp"

    # ------------------------------------------------- #
    # --- [2] load trajectory                       --- #
    # ------------------------------------------------- #

    for ik in range(npt):

        # -- load data -- #
        Data = lpf.load__pointFile(inpFile=inpFile.format(ik + 1),
                                   returnType="point")
        Data = Data[:, 1:]

        # -- save data -- #
        vpl.convert__vtkPolyLine(Data=Data, outFile=outFile.format(ik + 1))
コード例 #5
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()
コード例 #6
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) )
コード例 #7
0
ファイル: extract__online.py プロジェクト: wfw-pgr/others
def extract__online():

    inpFile1 = "grid.dat"
    inpFile2 = "line.dat"

    grid_ = lpf.load__pointFile(inpFile=inpFile1, returnType="structured")
    line = lpf.load__pointFile(inpFile=inpFile2, returnType="point")

    grid = np.zeros((grid.shape[0], grid.shape[1], 3))
    grid[:, :, 0] = grid_[:, :, 0]
    grid[:, :, 1] = grid_[:, :, 1]
    grid[:, :, 2] = grid_[:, :, 5]

    import nkInterpolator.LinearInterp2D as li2
    Data = li2.LinearInterp2D(gridData=grid, pointData=line)

    return ()
コード例 #8
0
def convert__vtsFile():

    inpFile1 = "dat/result.dat"
    inpFile2 = "dat/coilfield.dat"
    import nkUtilities.load__pointFile as lpf
    Data1 = lpf.load__pointFile(inpFile=inpFile1, returnType="structured")
    Data2 = lpf.load__pointFile(inpFile=inpFile2, returnType="structured")

    Data = np.concatenate([Data1[:, :, :, 0:6], Data2[:, :, :, 3:6]], axis=3)
    print(Data.shape)

    import nkVTKRoutines.convert__vtkStructuredGrid as vts
    outFile = "png/out.vts"
    names = [
        "result_bx", "result_by", "result_bz", "source_bx", "source_by",
        "source_bz"
    ]
    vts.convert__vtkStructuredGrid(Data=Data, outFile=outFile, names=names)
コード例 #9
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()
コード例 #10
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))
コード例 #11
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)
コード例 #12
0
ファイル: display.py プロジェクト: wfw-pgr/xyzPois2D
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 )
コード例 #13
0
ファイル: mirror__ebfield.py プロジェクト: wfw-pgr/tRK4
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()
コード例 #14
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()
コード例 #15
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()
コード例 #16
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)
コード例 #17
0
ファイル: convert__spf2point.py プロジェクト: wfw-pgr/tRK4
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 )
コード例 #18
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                             --- #
    # ------------------------------------------------- #
    if (inpFile is None):
        print("[convert__spf2point.py] inpFile >>> ", end="")
        inpFile = str(input())

    import nkUtilities.load__pointFile as lpf
    Data = lpf.load__pointFile(inpFile=inpFile, returnType="structured")
    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]
    pData[:, ey_] = 0.0
    pData[:, ez_] = Data[:, 3]

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

    outFile = "dat/out.dat"
    import nkUtilities.save__pointFile as spf
    names = ["xp", "yp", "zp", "Ex", "Ey", "Ez"]
    spf.save__pointFile(outFile=outFile, Data=pData, names=names)
コード例 #19
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)
コード例 #20
0
def convert__meshFormat(direction=None, side="+"):

    if (side == "+"):
        inpFile = "dat/onmesh_right.dat"
    elif (side == "-"):
        inpFile = "dat/onmesh_left.dat"
    elif (side in ["+-", "-+"]):
        inpFile = "dat/onmesh_both.dat"
    else:
        print("[convert__meshFormat] side == {0} ??? ".format(side))
        sys.exit()

    if (direction is None):
        sys.exit(
            "[convert__meshFormat] direction ??? ( gmsh->elmer or elmer->gmsh ) "
        )
    if (not (direction in ["elmer->gmsh", "gmsh->elmer"])):
        sys.exit(
            "[convert__meshFormat] direction ??? ( gmsh->elmer or elmer->gmsh ) "
        )

    # ------------------------------------------------- #
    # --- [1] gmsh -> elmer mode                    --- #
    # ------------------------------------------------- #
    if (direction.lower() == "gmsh->elmer"):

        # -- use ElmerGrid command to convert -- #
        print()
        print(
            "[convert__meshFormat] convert .msh (Gmsh) File into Elmer-Format.... "
        )
        cmd = "ElmerGrid 14 2 msh/mesh2d.msh"
        print(cmd)
        subprocess.call(cmd.split())

    # ------------------------------------------------- #
    # --- [2] elmer -> gmsh mode                    --- #
    # ------------------------------------------------- #
    if (direction.lower() == "elmer->gmsh"):

        # -- copy original Elmer-Format       -- #
        print()
        print("[reconvert__meshFormat] re-convert Elmer-Format into Gmsh.... ")
        cmd = "mkdir -p msh/mesh3d"
        print(cmd)
        subprocess.call(cmd.split())
        cmd = "cp -r msh/mesh2d/* msh/mesh3d/"
        print(cmd)
        subprocess.call(cmd, shell=True)
        # -- modify nodes position            -- #
        import nkUtilities.load__pointFile as lpf
        nodFile = "msh/mesh3d/mesh.nodes"
        nodes = lpf.load__pointFile(inpFile=inpFile, returnType="point")
        mesh = lpf.load__pointFile(inpFile=nodFile, returnType="point")
        mesh[:, 2:5] = nodes[:, :]
        # -- rewrite back into nodFile        -- #
        fmt = ["%d", "%d", "%15.8e", "%15.8e", "%15.8e"]
        with open(nodFile, "w") as f:
            np.savetxt(f, mesh, fmt=fmt)
        # -- reconvert into gmsh Format       -- #
        os.chdir("msh/")
        cmd = "ElmerGrid 2 4 mesh3d"
        print(cmd)
        subprocess.call(cmd.split())
        os.chdir("../")
    return ()
コード例 #21
0
def generate__poleLayer(lc=0.0, side="+", z1=0.0, z2=0.7, z3=1.0, radius=1.0):

    # ------------------------------------------------- #
    # --- [1] preparation                           --- #
    # ------------------------------------------------- #
    #  -- [1-1] constants                           --  #
    eps = 1.e-10
    x_, y_, z_ = 0, 1, 2
    origin = [0.0, 0.0, 0.0]
    lineDim, surfDim = 1, 2

    #  -- [1-2] load point Data                     --  #
    if (side == "+"):
        nodFile = "dat/onmesh_right.dat"
        mshFile = "dat/mesh_right.elements"
    elif (side == "-"):
        nodFile = "dat/onmesh_left.dat"
        mshFile = "dat/mesh_left.elements"
    else:
        print("[generate__poleLayer] side == {0} ??? ERROR! ".format(side))
        sys.exit()

    #  -- [1-3] load point Data                     --  #
    import nkUtilities.load__pointFile as lpf
    pointData = lpf.load__pointFile(inpFile=nodFile, returnType="point")

    #  -- [1-4] load connectivities                 --  #
    with open(mshFile, "r") as f:
        connectivities = np.loadtxt(f)
    connectivities = np.array(connectivities[:, 3:], dtype=np.int64)
    connectivities = connectivities - 1

    # ------------------------------------------------- #
    # --- [2] check on Arc elements                 --- #
    # ------------------------------------------------- #
    check       = investigate__onArcElements( connectivities=connectivities, \
                                              pointData=pointData, radius=radius )
    onArc_check = check["onArc_check"]
    onArc_index = check["onArc_index"]
    other_index = check["other_index"]

    # ------------------------------------------------- #
    # --- [3] define side surface                   --- #
    # ------------------------------------------------- #
    generate__sideSurface( side=side, radius=radius, height=z1, \
                           pointData=pointData, connectivities=connectivities, \
                           onArc_check=onArc_check, onArc_index=onArc_index )

    # ------------------------------------------------- #
    # --- [4] define floor & ceiling sector         --- #
    # ------------------------------------------------- #
    import nkGmshRoutines.generate__sector180 as sec
    floor   = sec.generate__sector180( r1=0.0, r2=radius, zoffset=0.0, \
                                       side=side, defineSurf=True )
    ceiling = sec.generate__sector180( r1=0.0, r2=radius, zoffset=z1, \
                                       side=side, defineSurf=True )

    # ------------------------------------------------- #
    # --- [5] define diameter surface               --- #
    # ------------------------------------------------- #
    generate__diameterSurface(pointData=pointData, radius=radius, height=z1)

    # ------------------------------------------------- #
    # --- [6] investigate entity numbers            --- #
    # ------------------------------------------------- #
    entityNum = investigate__entitiesNumber(height=z1)

    # ------------------------------------------------- #
    # --- [7] define pole surface                   --- #
    # ------------------------------------------------- #
    pole_surfs = generate__poleSurface( onArc_index=onArc_index, onArc_check=onArc_check, \
                                        other_index=other_index, connectivities=connectivities, \
                                        pointData=pointData, entityNum=entityNum )

    # ------------------------------------------------- #
    # --- [8] volume difinition                     --- #
    # ------------------------------------------------- #
    #  -- [8-1] lower parts                         --  #
    lower_loop = [ entityNum["side_lower"], entityNum["onDia_lower"], \
                   entityNum["floor1"], entityNum["floor2"] ] + pole_surfs
    s_group_lw = gmsh.model.occ.addSurfaceLoop(lower_loop)
    lower_vol = gmsh.model.occ.addVolume([s_group_lw])
    #  -- [8-2] upper parts                         --  #
    upper_loop = [ entityNum["side_upper"], entityNum["onDia_upper"], \
                   entityNum["ceiling1"], entityNum["ceiling2"] ] + pole_surfs
    s_group_up = gmsh.model.occ.addSurfaceLoop(upper_loop)
    upper_vol = gmsh.model.occ.addVolume([s_group_up])

    # ------------------------------------------------- #
    # --- [9] pole Root section definition          --- #
    # ------------------------------------------------- #
    height = z2 - z1
    root_vol = sec.generate__sector180( r1=0.0, r2=radius, zoffset=z1, height=height, \
                                        side=side, defineVolu=True, fuse=True )

    # ------------------------------------------------- #
    # --- [10] post-process                         --- #
    # ------------------------------------------------- #
    gmsh.model.occ.synchronize()
    gmsh.model.occ.removeAllDuplicates()
    gmsh.model.occ.synchronize()
    ret = [lower_vol, upper_vol, root_vol]
    return (ret)
コード例 #22
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="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()
コード例 #23
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()
コード例 #24
0
ファイル: time_vs_energy.py プロジェクト: wfw-pgr/tRK4
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()
コード例 #25
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)
コード例 #26
0
def convert__spf2point(inpFile=None):

    #
    #  x => r direction
    #  y => t direction
    #
    xp_, yp_, zp_ = 0, 1, 2
    ex_, ey_, ez_ = 3, 4, 5
    bx_, by_, bz_ = 3, 4, 5

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

    if (inpFile is None):
        print(
            "[convert__spf2point.py] inpFile ( default: dat/superfish.dat ) >>> ",
            end="")
        inpFile = str(input())
        if (len(inpFile) == 0):
            inpFile = const["spfFile"]

    import nkUtilities.load__pointFile as lpf
    Data = lpf.load__pointFile(inpFile=inpFile, returnType="structured")
    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 (e) --- #
    # ------------------------------------------------- #
    pData = np.zeros((Data.shape[0], 6))
    pData[:, xp_] = Data[:, 1]
    pData[:, yp_] = 0.0
    pData[:, zp_] = Data[:, 0]
    pData[:, ex_] = Data[:, 4]
    pData[:, ey_] = 0.0
    pData[:, ez_] = Data[:, 3]

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

    outFile = const["efieldFile"]
    import nkUtilities.save__pointFile as spf
    names = ["xp", "yp", "zp", "Ex", "Ey", "Ez"]
    spf.save__pointFile(outFile=outFile, Data=pData, names=names)

    # ------------------------------------------------- #
    # --- [3] convert into field-type pointFile (b) --- #
    # ------------------------------------------------- #
    pData = np.zeros((Data.shape[0], 6))
    pData[:, xp_] = Data[:, 1]
    pData[:, yp_] = 0.0
    pData[:, zp_] = Data[:, 0]
    pData[:, bx_] = 0.0
    pData[:, by_] = Data[:, 6]
    pData[:, bz_] = 0.0

    pData[:, bx_:bz_] = pData[:, bx_:bz_] * const["mu0"]

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

    outFile = const["bfieldFile"]
    import nkUtilities.save__pointFile as spf
    names = ["xp", "yp", "zp", "Bx", "By", "Bz"]
    spf.save__pointFile(outFile=outFile, Data=pData, names=names)
コード例 #27
0
ファイル: trajectory__xy.py プロジェクト: wfw-pgr/tRK4
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()
コード例 #28
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()
コード例 #29
0
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)
コード例 #30
0
ファイル: feedback__mshape.py プロジェクト: wfw-pgr/others
# ------------------------------------------------- #
args = gar.genArgs()
num = args["integer"]

if (num is None):
    print("[feedback__mshape] num == ???  ( --integer xxx ) ")
    sys.exit()

# ------------------------------------------------- #
# --- [2] Load input Files                      --- #
# ------------------------------------------------- #
inpFile = "out/mshape_{0:04}.dat".format(num)
outFile = "dat/mshape_feedback.dat"

import nkUtilities.load__pointFile as lpf
Data = lpf.load__pointFile(inpFile=inpFile, returnType="structured")
LJ = Data.shape[0]
LI = Data.shape[1]

# ------------------------------------------------- #
# --- [3] extrapolate peripheral region         --- #
# ------------------------------------------------- #

for j in range(LJ):
    for i in range(LI):
        if (Data[j, i, 5] == 0.0):
            avg = 0.0
            num = 0
            if (i >= 1):
                if (round(Data[j, i - 1, 5]) == 1):
                    avg = avg + Data[j, i - 1, 2]