Ejemplo n.º 1
0
def make__superfish_sample():

    # ------------------------------------------------- #
    # --- [1] load constants                        --- #
    # ------------------------------------------------- #
    LI, LJ, LK = 21, 21, 1
    import nkUtilities.equiSpaceGrid as esg
    x1MinMaxNum = [ 0.0, 1.0, LI ]
    x2MinMaxNum = [ 0.0, 1.0, LJ ]
    x3MinMaxNum = [ 0.0, 0.0, LK ]
    ret         = esg.equiSpaceGrid( x1MinMaxNum=x1MinMaxNum, x2MinMaxNum=x2MinMaxNum, \
                                     x3MinMaxNum=x3MinMaxNum, returnType = "point" )
    Data        = np.zeros( (ret.shape[0],7) )
    names       = ["xp","yp","zp","Ez","Er","|E|","Hp"]
    Data[:,0:3] = np.copy( ret[:,:] )
    Data[:,3]   = 1.e+6
    Data[:,4]   = 0.0
    Data[:,5]   = np.sqrt( Data[:,3]**2 + Data[:,4]**2 )
    Data[:,6]   = 0.0

    
    Data        = np.reshape( Data, (LK,LJ,LI,7) )
    outFile     = "dat/superfish_sample.dat"
    import nkUtilities.save__pointFile as spf
    spf.save__pointFile( outFile=outFile, Data=Data )
    
    return()
Ejemplo n.º 2
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.º 3
0
def prepare__laplacian(xCnt=0.0, yCnt=0.0, x1MinMaxNum=None, x2MinMaxNum=None):

    # ------------------------------------------------- #
    # --- [1] parameters                            --- #
    # ------------------------------------------------- #
    r1 = 0.2
    r2 = 0.4
    c1 = 1.e-9
    c2 = 3.e-6
    xCnt = 0.00
    yCnt = -0.60

    # ------------------------------------------------- #
    # --- [2] grid making                           --- #
    # ------------------------------------------------- #
    import nkUtilities.equiSpaceGrid as esg
    if (x1MinMaxNum is None): x1MinMaxNum = [0.0, +1.8, 121]
    if (x2MinMaxNum is None): x2MinMaxNum = [-1.8, +1.8, 241]
    ret         = esg.equiSpaceGrid( x1MinMaxNum=x1MinMaxNum, x2MinMaxNum=x2MinMaxNum, \
                                     returnType = "structured" )
    xg = np.ravel(ret[:, :, 0])
    yg = np.ravel(ret[:, :, 1])
    LI = ret.shape[1]
    LJ = ret.shape[0]
    radii = np.sqrt((xg - xCnt)**2 + (yg - yCnt)**2)

    # ------------------------------------------------- #
    # --- [3] distribution                          --- #
    # ------------------------------------------------- #
    ret = rFunc(radii=radii, c1=c1, c2=c2, r1=r1, r2=r2)
    print(ret.shape)

    # ------------------------------------------------- #
    # --- [4] output results                        --- #
    # ------------------------------------------------- #
    import nkUtilities.save__pointFile as spf
    outFile = "out.dat"
    print(ret.shape)
    shape = (LJ, LI, 1)
    Data = np.reshape(ret, shape)
    spf.save__pointFile(outFile=outFile, Data=Data, shape=shape)

    import nkUtilities.cMapTri as cmt
    pngFile = "out.png"
    import nkUtilities.LoadConfig as lcf
    config = lcf.LoadConfig()
    config["cmp_AutoLevel"] = False
    config["cmp_MaxMin"] = [1.e-10, 5.e-6]
    cmt.cMapTri(xAxis=xg, yAxis=yg, cMap=ret, pngFile=pngFile, config=config)
Ejemplo n.º 4
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.º 5
0
def expand__axisymmetric(ra=None,
                         fa=None,
                         x1MinMaxNum=None,
                         x2MinMaxNum=None,
                         radius=None):

    # ------------------------------------------------- #
    # --- [1] Arguments                             --- #
    # ------------------------------------------------- #
    if (ra is None): sys.exit("[expand__axisymmertic] ra          == ???")
    if (fa is None): sys.exit("[expand__axisymmertic] fa          == ???")
    if (x1MinMaxNum is None):
        sys.exit("[expand__axisymmertic] x1MinMaxNum == ???")
    if (x2MinMaxNum is None):
        sys.exit("[expand__axisymmertic] x2MinMaxNum == ???")
    if (radius is None):
        radius = min(x1MinMaxNum[1], x2MinMaxNum[1])

    # ------------------------------------------------- #
    # --- [2] grid making                           --- #
    # ------------------------------------------------- #
    import nkUtilities.equiSpaceGrid as esg
    x3MinMaxNum = [0.0, 0.0, 1]
    grid          = esg.equiSpaceGrid( x1MinMaxNum=x1MinMaxNum, x2MinMaxNum=x2MinMaxNum, \
                                       x3MinMaxNum=x3MinMaxNum, returnType = "point" )
    radii = np.sqrt(grid[:, 0]**2 + grid[:, 1]**2)
    index = np.where(radii < radius)
    rp = radii[index]

    # ------------------------------------------------- #
    # --- [3] interpolation                         --- #
    # ------------------------------------------------- #
    import nkInterpolator.LinearInterp1D as li1
    ret = li1.LinearInterp1D(xa=ra, fa=fa, xp=rp)
    grid[index, 2] = ret

    # ------------------------------------------------- #
    # --- [4] return                                --- #
    # ------------------------------------------------- #
    return (grid)
Ejemplo n.º 6
0
def make__sample():

    x_, y_, z_ = 0, 1, 2
    outFile = "dat/source.dat"
    import nkUtilities.equiSpaceGrid as esg
    x1MinMaxNum = [0.0, 1.0, 11]
    x2MinMaxNum = [0.0, 1.0, 11]
    x3MinMaxNum = [0.0, 0.0, 1]
    ret           = esg.equiSpaceGrid( x1MinMaxNum=x1MinMaxNum, x2MinMaxNum=x2MinMaxNum, \
                                       x3MinMaxNum=x3MinMaxNum, returnType = "structured" )
    aval, bval = 1.0, 2.0
    ret[:, :, :, z_] = aval * ret[:, :, :, x_] + bval * ret[:, :, :, y_]
    ret[:, 1:-1, 1:-1, z_] = 3.0 * ret[:, 1:-1, 1:-1, z_]**2
    ret[:, 0, :, z_] = 0.0
    ret[:, -1, :, z_] = 0.0
    ret[:, :, 0, z_] = 0.0
    ret[:, :, -1, z_] = 0.0

    import nkUtilities.save__pointFile as spf
    spf.save__pointFile(outFile=outFile, Data=ret)

    return ()
def generate__sampleSurface():

    x_, y_, z_ = 0, 1, 2
    xMin, xMax, LI = -1.0, +1.0, +31
    yMin, yMax, LJ = -1.0, +1.0, +31

    # ------------------------------------------------- #
    # --- [1] coordinate                            --- #
    # ------------------------------------------------- #
    import nkUtilities.equiSpaceGrid as esg
    x1MinMaxNum = [xMin, xMax, LI]
    x2MinMaxNum = [yMin, yMax, LJ]
    x3MinMaxNum = [0.0, 0.0, 1]
    grid        = esg.equiSpaceGrid( x1MinMaxNum=x1MinMaxNum, x2MinMaxNum=x2MinMaxNum, \
                                     x3MinMaxNum=x3MinMaxNum, returnType = "structured" )

    # ------------------------------------------------- #
    # --- [2] function                              --- #
    # ------------------------------------------------- #
    def surf_func(xpos, ypos, radius=1.0):
        radii_h = (xpos**2 + ypos**2) / radius
        phi = np.arctan2(ypos, xpos)
        zpos = 0.1 * (1.0 - radii_h) + 0.3
        return (zpos)

    # ------------------------------------------------- #
    # --- [3] save sample surface                   --- #
    # ------------------------------------------------- #
    grid[:, :, :, z_] = surf_func(grid[:, :, :, x_], grid[:, :, :, y_])
    grid = np.reshape(grid, (1, LJ, LI, 3))
    mshape = np.zeros((1, LJ, LI, 6))
    mshape[..., 0:3] = grid
    mshape[..., 3] = grid[..., 2]
    mshape[..., 4] = 0
    mshape[..., 5] = 1.0
    outFile = "dat/mshape_svd.dat"
    import nkUtilities.save__pointFile as spf
    spf.save__pointFile(outFile=outFile, Data=mshape)
Ejemplo n.º 8
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.º 9
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()
Ejemplo n.º 10
0
def waveguide__TEmode(time=0.0, kstep=0):

    # ------------------------------------------------- #
    # --- [1] parameters                            --- #
    # ------------------------------------------------- #

    import nkUtilities.load__constants as lcn
    inpFile = "dat/parameter.conf"
    const = lcn.load__constants(inpFile=inpFile)
    mu = 4.0 * np.pi * 1e-7
    cv = 3.0e8
    omega = 2.0 * np.pi * const["freq"]
    Hmn = const["Hmn"]

    # ------------------------------------------------- #
    # --- [2] grid making                           --- #
    # ------------------------------------------------- #

    x_, y_, z_ = 0, 1, 2
    x1MinMaxNum = [0.0, const["wg_a"], const["LI"]]
    x2MinMaxNum = [0.0, const["wg_b"], const["LJ"]]
    x3MinMaxNum = [0.0, const["wg_c"], const["LK"]]
    grid        = esg.equiSpaceGrid( x1MinMaxNum=x1MinMaxNum, x2MinMaxNum=x2MinMaxNum, \
                                     x3MinMaxNum=x3MinMaxNum, returnType = "structured" )
    xg = grid[..., 0]
    yg = grid[..., 1]
    zg = grid[..., 2]

    k0 = omega / cv
    kx = const["mmode"] * np.pi / const["wg_a"]
    ky = const["nmode"] * np.pi / const["wg_b"]
    kc = np.sqrt(kx**2 + ky**2)
    beta = np.sqrt(k0**2 - kc**2)

    wt = omega * time
    kxx = kx * xg
    kyy = ky * yg
    exp_wt_bz_r = np.cos(wt - beta * zg)
    exp_wt_bz_i = np.sin(wt - beta * zg)

    lambda_g = 2.0 * np.pi / beta

    print(" omega    :: {0}".format(omega))
    print(" k0       :: {0}".format(k0))
    print(" kx       :: {0}".format(kx))
    print(" ky       :: {0}".format(ky))
    print(" kc       :: {0}".format(kc))
    print(" beta     :: {0}".format(beta))
    print(" lambda_g :: {0}".format(lambda_g))

    # ------------------------------------------------- #
    # --- [3] TE mode wave                          --- #
    # ------------------------------------------------- #

    Ez_Re = 0.0 * exp_wt_bz_r
    Hz_Re = Hmn * np.cos(kxx) * np.cos(kyy) * exp_wt_bz_r
    Ex_Re = omega * ky * mu / kc**2 * Hmn * np.cos(kxx) * np.sin(
        kyy) * exp_wt_bz_i * (-1)
    Ey_Re = omega * kx * mu / kc**2 * Hmn * np.sin(kxx) * np.cos(
        kyy) * exp_wt_bz_i
    Hx_Re = beta * kx / kc**2 * Hmn * np.sin(kxx) * np.cos(
        kyy) * exp_wt_bz_i * (-1)
    Hy_Re = beta * ky / kc**2 * Hmn * np.cos(kxx) * np.sin(
        kyy) * exp_wt_bz_i * (-1)

    # ------------------------------------------------- #
    # --- [4] colormap of the Amplitude             --- #
    # ------------------------------------------------- #

    import nkBasicAlgs.pileupArray as pil
    Data = pil.pileupArray(
        (xg, yg, zg, Ex_Re, Ey_Re, Ez_Re, Hx_Re, Hy_Re, Hz_Re))
    DataLabel = ["xg", "yz", "zg", "Ex", "Ey", "Ez", "Hx", "Hy", "Hz"]

    import nkVTKRoutines.vtkDataConverter as vdc
    outFile = "dat/TEwave_{0:04}.vts".format(kstep)
    cvt1        = vdc.vtkDataConverter( vtkFile=outFile, Data=Data, \
                                        tag="data", DataType="structured", DataLabel=DataLabel )
    if (DataFormat.lower() == "ascii"):
        writer.SetDataModeToAscii()
    if (DataFormat.lower() == "binary"):
        writer.SetDataModeToBinary()
    writer.SetFileName(outFile)
    writer.SetInputData(unstructData)
    writer.Write()
    print("[save__vtkUnstructuredGrid] output :: {0} ".format(outFile))
    return ()


# ========================================================= #
# ===   実行部                                          === #
# ========================================================= #

if (__name__ == "__main__"):

    x_, y_, z_, f_ = 0, 1, 2, 3
    import nkUtilities.equiSpaceGrid as esg
    x1MinMaxNum = [-1.0, 1.0, 41]
    x2MinMaxNum = [-1.0, 1.0, 31]
    x3MinMaxNum = [-1.0, 1.0, 21]
    ret               = esg.equiSpaceGrid( x1MinMaxNum=x1MinMaxNum, x2MinMaxNum=x2MinMaxNum, \
                                           x3MinMaxNum=x3MinMaxNum, returnType = "point" )
    Data = np.zeros((ret.shape[0], 5))
    Data[:, x_:z_ + 1] = ret[:, x_:z_ + 1]
    Data[:, f_] = np.sqrt(ret[:, x_]**2 + ret[:, y_]**2)
    Data[:, 4] = np.exp(-0.5 * (ret[:, x_]**2 + ret[:, y_]**2))

    convert__vtkUnstructuredGrid(Data=Data)
Ejemplo n.º 12
0
def field_expansion():

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

    #  -- [1-2] Load field file                     --  #
    import nkUtilities.load__pointFile as lpf
    inpFile = "dat/extended_idealField.dat"
    data2d = lpf.load__pointFile(inpFile=inpFile, returnType="structured")
    bz = np.copy(data2d[:, :, 3])

    # ------------------------------------------------- #
    # --- [2] calculate derivative                  --- #
    # ------------------------------------------------- #

    dx = ((params["xMax"] - params["xMin"]) / float(params["LI"] - 1))
    dy = ((params["yMax"] - params["yMin"]) / float(params["LJ"] - 1))
    dz = ((params["zMax"] - params["zMin"]) / float(params["LK"] - 1))
    dxInv = 1.0 / dx
    dyInv = 1.0 / dy
    dzInv = 1.0 / dz

    dbzdx = (np.roll(bz, +1, axis=1) - np.roll(bz, -1, axis=1)) * dxInv * 0.5
    dbzdy = (np.roll(bz, +1, axis=0) - np.roll(bz, -1, axis=0)) * dyInv * 0.5
    d2bzdx2 = (np.roll(bz, +1, axis=1) + np.roll(bz, -1, axis=1) -
               2.0 * bz) * dxInv**2
    d2bzdy2 = (np.roll(bz, +1, axis=0) + np.roll(bz, -1, axis=0) -
               2.0 * bz) * dyInv**2
    d2bzdz2 = -d2bzdx2 - d2bzdy2

    # ------------------------------------------------- #
    # --- [3] euler integral                        --- #
    # ------------------------------------------------- #

    x_, y_, z_ = 0, 1, 2
    b3d = np.zeros((params["LK"], params["LJ"], params["LI"], 3))
    n_kplus = int((params["LK"] - 1) / 2)
    kmid = int((params["LK"] - 1) / 2)

    b3d[kmid, :, :, x_] = 0.0
    b3d[kmid, :, :, y_] = 0.0
    b3d[kmid, :, :, z_] = bz

    for ik in range(1, n_kplus + 1):
        b3d[kmid + ik, :, :, x_] = dbzdx * float(ik) * dz
        b3d[kmid + ik, :, :, y_] = dbzdy * float(ik) * dz
        b3d[kmid + ik, :, :, z_] = bz + 0.5 * d2bzdz2 * (float(ik) * dz)**2
    for ik in range(1, n_kplus + 1):
        b3d[kmid - ik, :, :, x_] = -b3d[kmid + ik, :, :, x_]
        b3d[kmid - ik, :, :, y_] = -b3d[kmid + ik, :, :, y_]
        b3d[kmid - ik, :, :, z_] = +b3d[kmid + ik, :, :, z_]

    # ------------------------------------------------- #
    # --- [4] edge care                             --- #
    # ------------------------------------------------- #
    #  -- [4-1] copy edge                           --  #
    b3d[:, 0, :, :] = b3d[:, 1, :, :]
    b3d[:, -1, :, :] = b3d[:, -2, :, :]
    b3d[:, :, 0, :] = b3d[:, :, 1, :]
    b3d[:, :, -1, :] = b3d[:, :, -2, :]

    # ------------------------------------------------- #
    # --- [5] save in file                          --- #
    # ------------------------------------------------- #

    #  -- [5-1]  save as .dat file                  --  #
    x_, y_, z_, bx_, by_, bz_ = 0, 1, 2, 3, 4, 5
    Data = np.zeros((params["LK"], params["LJ"], params["LI"], 6))

    import nkUtilities.equiSpaceGrid as esg
    x1MinMaxNum = [params["xMin"], params["xMax"], params["LI"]]
    x2MinMaxNum = [params["yMin"], params["yMax"], params["LJ"]]
    x3MinMaxNum = [params["zMin"], params["zMax"], params["LK"]]
    ret         = esg.equiSpaceGrid( x1MinMaxNum=x1MinMaxNum, x2MinMaxNum=x2MinMaxNum, \
                                     x3MinMaxNum=x3MinMaxNum, returnType = "structured" )
    Data[:, :, :, x_] = ret[:, :, :, x_]
    Data[:, :, :, y_] = ret[:, :, :, y_]
    Data[:, :, :, z_] = ret[:, :, :, z_]
    Data[:, :, :, bx_] = b3d[:, :, :, x_]
    Data[:, :, :, by_] = b3d[:, :, :, y_]
    Data[:, :, :, bz_] = b3d[:, :, :, z_]

    import nkUtilities.save__pointFile as spf
    outFile = "dat/out.dat"
    names = ["xp", "yp", "zp", "bx", "by", "bz"]
    spf.save__pointFile(outFile=outFile,
                        Data=Data,
                        shape=Data.shape,
                        names=names)

    #  -- [5-2]  save as .png file                  --  #
    import nkUtilities.cMapTri as cmt
    for ik in range(params["LK"]):
        hData = np.reshape(Data[ik, :, :, :], (-1, 6))
        cmt.cMapTri( xAxis=hData[:,x_], yAxis=hData[:,y_], cMap=hData[:,bx_], \
                     pngFile="png/bx_k={0}.png".format( ik ) )
        cmt.cMapTri( xAxis=hData[:,x_], yAxis=hData[:,y_], cMap=hData[:,by_], \
                     pngFile="png/by_k={0}.png".format( ik ) )
        cmt.cMapTri( xAxis=hData[:,x_], yAxis=hData[:,y_], cMap=hData[:,bz_], \
                     pngFile="png/bz_k={0}.png".format( ik ) )
Ejemplo n.º 13
0
def make__regenShapeFile():

    # ------------------------------------------------- #
    # --- [1] Load parameter File                   --- #
    # ------------------------------------------------- #

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

    x_, y_, z_ = 0, 1, 2
    i_, s_, f_ = 3, 4, 5
    dx1 = (const["x1Max"] - const["x1Min"]) / float(const["LI"] - 1)
    dx2 = (const["x2Max"] - const["x2Min"]) / float(const["LJ"] - 1)

    # ------------------------------------------------- #
    # --- [2] Grid Generation                       --- #
    # ------------------------------------------------- #
    # -- [2-1] structured grid  -- #
    import nkUtilities.equiSpaceGrid as esg
    x1MinMaxNum = [
        const["x1Min"] + 0.5 * dx1, const["x1Max"] - 0.5 * dx1, const["LI"] - 1
    ]
    x2MinMaxNum = [
        const["x2Min"] + 0.5 * dx2, const["x2Max"] - 0.5 * dx2, const["LJ"] - 1
    ]
    x3MinMaxNum = [0.0, 0.0, 1]
    grid        = esg.equiSpaceGrid( x1MinMaxNum=x1MinMaxNum, x2MinMaxNum=x2MinMaxNum, \
                                     x3MinMaxNum=x3MinMaxNum, returnType = "point" )
    nData = grid.shape[0]
    # -- [2-2] radius & angle   -- #
    radii = np.sqrt(grid[:, x_]**2 + grid[:, y_]**2)
    phi = np.arctan2(grid[:, y_], grid[:, x_]) / np.pi * 180.0
    phi[np.where(phi < 0.0)] = phi[np.where(phi < 0.0)] + 360.0
    # -- [2-3] normalized value -- #
    rhat = (radii - const["regen_r1"]) / (const["regen_r2"] -
                                          const["regen_r1"])
    phat = (phi - const["regen_p1"]) / (const["regen_p2"] - const["regen_p1"])
    # -- [2-4] judge in/out     -- #
    idx = np.where((rhat > 0.0) & (rhat < 1.0) & (phat > 0.0) & (phat < 1.0))
    flags = np.zeros((nData))
    flags[idx] = 1.0

    # ------------------------------------------------- #
    # --- [3] interpolate regen.nodes               --- #
    # ------------------------------------------------- #

    #  -- [3-1] load regen.nodes  -- #
    inpFile = "dat/regen.nodes"
    with open(inpFile, "r") as f:
        rData = np.loadtxt(f)
    nodes = np.copy(rData[:, 2:])
    points = np.copy(grid)

    #  -- [3-2] barycentric__interpolation  -- #
    import nkInterpolator.barycentric__interpolator as bry
    ret = bry.barycentric__interpolator(nodes=nodes, points=points)

    # ------------------------------------------------- #
    # --- [4] regen coordinates making              --- #
    # ------------------------------------------------- #
    Data = np.zeros((nData, 6))
    Data[:, x_] = grid[:, x_]
    Data[:, y_] = grid[:, y_]
    Data[:, z_] = ret[:, z_]
    Data[:, i_] = ret[:, z_]
    Data[:, s_] = 0.0
    Data[:, f_] = flags

    # ------------------------------------------------- #
    # --- [5] save in File                          --- #
    # ------------------------------------------------- #
    import nkUtilities.save__pointFile as spf
    outFile = "dat/regen_shape.dat"
    spf.save__pointFile(outFile=outFile,
                        Data=Data,
                        shape=(const["LJ"] - 1, const["LI"] - 1, 6))

    # ------------------------------------------------- #
    # --- [6] output figure for check               --- #
    # ------------------------------------------------- #
    import nkUtilities.cMapTri as cmt
    pngFile = "png/flag.png"
    cmt.cMapTri(xAxis=Data[:, x_],
                yAxis=Data[:, y_],
                cMap=Data[:, f_],
                pngFile=pngFile)
    pngFile = "png/init.png"
    cmt.cMapTri(xAxis=Data[:, x_],
                yAxis=Data[:, y_],
                cMap=Data[:, i_],
                pngFile=pngFile)
Ejemplo n.º 14
0
def make__boundary_cell():

    x_, y_, z_ = 0, 1, 2

    # ------------------------------------------------- #
    # --- [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] = np.copy(grid)

    # ------------------------------------------------- #
    # --- [2] boundary detection                    --- #
    # ------------------------------------------------- #

    nField = BField.shape[0]
    LI, LJ, LK = int(const["x1MinMaxNum"][2]), int(
        const["x2MinMaxNum"][2]), int(const["x3MinMaxNum"][2])
    dx = (const["x1MinMaxNum"][1] - const["x1MinMaxNum"][0]) / (LI - 1)
    dy = (const["x2MinMaxNum"][1] - const["x2MinMaxNum"][0]) / (LJ - 1)
    delta = np.min([dx, dy])
    radii = np.sqrt(BField[:, x_]**2 + BField[:, y_]**2)
    zpos = np.copy(BField[:, z_])
    r1, r2 = const["radius"], const["radius"] + delta
    z1, z2 = const["x3MinMaxNum"][0], const["x3MinMaxNum"][1]
    index1 = np.where((radii >= r1) & (radii < r2))
    index2 = np.where((radii < r2) & (zpos == z1))
    index3 = np.where((radii < r2) & (zpos == z2))
    boundary = np.zeros((nField, ))
    boundary[index1] = 1.0
    boundary[index2] = 1.0
    boundary[index3] = 1.0

    bdr_surface = np.copy(boundary)

    index4 = np.where((radii >= r2))
    boundary[index4] = 1.0
    bdr_flags = np.copy(boundary)

    source = np.zeros((nField, 8))
    source[:, 0:6] = BField
    source[:, 6] = bdr_surface
    source[:, 7] = bdr_flags
    source = np.reshape(source, (LK, LJ, LI, 8))

    index = np.where(bdr_surface[:] == 1.0)
    BField_boundary = (BField[index])[:, 0:3]

    # ------------------------------------------------- #
    # --- [4] save in File                          --- #
    # ------------------------------------------------- #

    #  -- [4-1] save coordinate                     --  #
    outFile = "dat/ems_pst.coord"
    import nkUtilities.save__pointFile as spf
    spf.save__pointFile(outFile=outFile, Data=BField_boundary)

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

    #  -- [4-3] display source                      --  #
    import nkVTKRoutines.convert__vtkStructuredGrid as vts
    outFile = "png/source.vts"
    names = ["bx", "by", "bz", "boundary", "flag"]
    vts.convert__vtkStructuredGrid(Data=source, outFile=outFile, names=names)
Ejemplo n.º 15
0
def ideal_fringe_field():

    # ------------------------------------------------- #
    # --- [1] parameter settings                    --- #
    # ------------------------------------------------- #
    #  -- [1-1] Load parameter file                 --  #
    import nkUtilities.load__constants as lcn
    inpFile = "dat/parameter.conf"
    params = lcn.load__constants(inpFile=inpFile)

    # ------------------------------------------------- #
    # --- [2] grid making                           --- #
    # ------------------------------------------------- #

    import nkUtilities.equiSpaceGrid as esg
    x1MinMaxNum = [params["xMin"], params["xMax"], params["LI"]]
    x2MinMaxNum = [params["yMin"], params["yMax"], params["LJ"]]
    x3MinMaxNum = [0.0, 0.0, 1]
    ret         = esg.equiSpaceGrid( x1MinMaxNum=x1MinMaxNum, x2MinMaxNum=x2MinMaxNum, \
                                     x3MinMaxNum=x3MinMaxNum, returnType = "point" )
    radii = np.sqrt(ret[:, 0]**2 + ret[:, 1]**2)
    xg = np.copy(ret[:, 0])
    yg = np.copy(ret[:, 1])
    zg = np.copy(ret[:, 2])
    bz = np.copy(ret[:, 2]) * 0.0

    # ------------------------------------------------- #
    # --- [3] ideal aoki main field                 --- #
    # ------------------------------------------------- #
    index = np.where(radii <= params["r_main"])
    radii_h = radii[index]
    bz[index] = mainAokiField(radii_h, params=params)

    # ------------------------------------------------- #
    # --- [4] buffer field                          --- #
    # ------------------------------------------------- #
    index = np.where((radii > params["r_main"]) & (radii < params["r_fringe"]))
    rh = radii[index]
    xh = xg[index]
    yh = yg[index]
    nBuff = xh.shape[0]
    theta = np.arctan2(yh, xh)
    r1, r2, r3 = params["r_main"], params["r_main"] - params[
        "r_delta"], params["r_main"] - 2.0 * params["r_delta"]
    xp1, yp1 = r1 * np.cos(theta), r1 * np.sin(theta)
    xp2, yp2 = r2 * np.cos(theta), r2 * np.sin(theta)
    xp3, yp3 = r3 * np.cos(theta), r3 * np.sin(theta)
    bp1 = mainAokiField(np.sqrt(xp1**2 + yp1**2), params=params)
    bp2 = mainAokiField(np.sqrt(xp2**2 + yp2**2), params=params)
    bp3 = mainAokiField(np.sqrt(xp3**2 + yp3**2), params=params)
    dbdr_main = (bp1 - bp3) / params["r_delta"]
    dbdr_fringe = params["fringe_grad"] * np.ones((nBuff, ))
    b_fringe_edge = np.ones((nBuff)) * params["fringe_fixed"]

    rhat = (rh - r2) / (params["r_fringe"] - r2)
    delta_main = rh - r2
    delta_fringe = rh - params["r_fringe"]

    approx_main = linear_approx(delta_main, dbdr_main, bp2)
    approx_fringe = linear_approx(delta_fringe, dbdr_fringe, b_fringe_edge)
    rate_main = rateFunc_main(rhat)
    rate_fringe = rateFunc_fringe(rhat)

    bz_buffer = rate_main * approx_main + rate_fringe * approx_fringe
    bz[index] = np.copy(bz_buffer)

    # ------------------------------------------------- #
    # --- [5] main fringe field                     --- #
    # ------------------------------------------------- #
    index = np.where(radii >= params["r_fringe"])
    radii_h = radii[index]
    bz[index] = mainFringeField(radii_h, params=params)

    # ------------------------------------------------- #
    # --- [6] output field                          --- #
    # ------------------------------------------------- #
    #  -- [6-1] save in file                        --  #
    ret = np.zeros((bz.shape[0], 4))
    ret[:, 0] = np.copy(xg)
    ret[:, 1] = np.copy(yg)
    ret[:, 2] = np.copy(zg)
    ret[:, 3] = np.copy(bz)
    shape = (params["LJ"], params["LI"], 4)
    ret_ = np.reshape(ret, shape)
    import nkUtilities.save__pointFile as spf
    outFile = "dat/extended_idealField.dat"
    spf.save__pointFile(outFile=outFile, Data=ret_, shape=shape)

    #  -- [6-2] 2d color map                        --  #
    import nkUtilities.cMapTri as cmt
    cmt.cMapTri(xAxis=ret[:, 0],
                yAxis=ret[:, 1],
                cMap=ret[:, 3],
                pngFile="png/out.png")

    import nkBasicAlgs.extract__data_onAxis as ext
    onXAxis = ext.extract__data_onAxis(Data=ret, axis="y")
    onYAxis = ext.extract__data_onAxis(Data=ret, axis="x")

    import nkUtilities.plot1D as pl1
    import nkUtilities.LoadConfig as lcf
    config = lcf.LoadConfig()
    config["plt_linewidth"] = 0.0
    config["plt_marker"] = "x"

    #  -- [6-3] 1d plot (x)                         --  #
    xAxis = onXAxis[:, 0]
    bAxis = onXAxis[:, 3]
    xAxis1 = xAxis[np.where(np.abs(xAxis) <= params["r_main"])]
    bAxis1 = bAxis[np.where(np.abs(xAxis) <= params["r_main"])]
    xAxis2 = xAxis[np.where((np.abs(xAxis) > params["r_main"])
                            & (np.abs(xAxis) < params["r_fringe"]))]
    bAxis2 = bAxis[np.where((np.abs(xAxis) > params["r_main"])
                            & (np.abs(xAxis) < params["r_fringe"]))]
    xAxis3 = xAxis[np.where(np.abs(xAxis) >= params["r_fringe"])]
    bAxis3 = bAxis[np.where(np.abs(xAxis) >= params["r_fringe"])]

    pngFile = "png/onXAxis.png"
    fig = pl1.plot1D(config=config, pngFile=pngFile)
    fig.add__plot(xAxis=xAxis1, yAxis=bAxis1, label="main")
    fig.add__plot(xAxis=xAxis2, yAxis=bAxis2, label="buffer")
    fig.add__plot(xAxis=xAxis3, yAxis=bAxis3, label="fringe")
    fig.add__legend()
    fig.set__axis()
    fig.save__figure()

    #  -- [6-4] 1d plot (y)                         --  #
    yAxis = onYAxis[:, 1]
    bAxis = onYAxis[:, 3]
    yAxis1 = yAxis[np.where(np.abs(yAxis) <= params["r_main"])]
    bAxis1 = bAxis[np.where(np.abs(yAxis) <= params["r_main"])]
    yAxis2 = yAxis[np.where((np.abs(yAxis) > params["r_main"])
                            & (np.abs(yAxis) < params["r_fringe"]))]
    bAxis2 = bAxis[np.where((np.abs(yAxis) > params["r_main"])
                            & (np.abs(yAxis) < params["r_fringe"]))]
    yAxis3 = yAxis[np.where(np.abs(yAxis) >= params["r_fringe"])]
    bAxis3 = bAxis[np.where(np.abs(yAxis) >= params["r_fringe"])]

    pngFile = "png/onYAxis.png"
    fig = pl1.plot1D(config=config, pngFile=pngFile)
    fig.add__plot(xAxis=yAxis1, yAxis=bAxis1, label="main")
    fig.add__plot(xAxis=yAxis2, yAxis=bAxis2, label="buffer")
    fig.add__plot(xAxis=yAxis3, yAxis=bAxis3, label="fringe")
    fig.add__legend()
    fig.set__axis()
    fig.save__figure()

    return ()
Ejemplo n.º 16
0
        for tag in self.tags:
            self.Data[tag].generate__imageData()


# ======================================== #
# ===  実行部                          === #
# ======================================== #
if (__name__ == "__main__"):

    manager = vtkDataManager()

    import nkUtilities.equiSpaceGrid as esg
    x1MinMaxNum = [0.0, 1.0, 11]
    x2MinMaxNum = [0.0, 1.0, 11]
    x3MinMaxNum = [0.0, 1.0, 11]
    ret1        = esg.equiSpaceGrid( x1MinMaxNum=x1MinMaxNum, x2MinMaxNum=x2MinMaxNum, \
                                     x3MinMaxNum=x3MinMaxNum, returnType = "structured" )
    manager.add__vtkDataUnit(Data=ret1, tag="ret1")

    import nkUtilities.generate__testprofile as gtp
    x1MinMaxNum = [0.0, 1.0, 11]
    x2MinMaxNum = [0.0, 1.0, 11]
    x3MinMaxNum = [0.0, 1.0, 11]
    ret2        = gtp.generate__testprofile( x1MinMaxNum=x1MinMaxNum, x2MinMaxNum=x2MinMaxNum, \
                                          x3MinMaxNum=x3MinMaxNum, returnType = "point" )
    manager.add__vtkDataUnit(
        Data=ret2,
        tag="ret2",
    )

    print()
    manager.print__vtkDataInfo()
Ejemplo n.º 17
0
def generate__testprofile( dim=None, x1MinMaxNum=None, x2MinMaxNum=None, x3MinMaxNum=None, \
                           vMin=0.0, vMax=1.0, returnType="point", profileType="cos**2" ):

    # ------------------------------------------------- #
    # --- [1] Arguments                             --- #
    # ------------------------------------------------- #
    if (x1MinMaxNum is None):
        print("[generate__testprofile] no (x1,x2,x3)MinMaxNum is specified ")
        print(
            "                        :: Default => dim = 2D, [ 0.0, 1.0, 11 ] "
        )
        dim = 2
        x1MinMaxNum = [0.0, 1.0, 21]
        x2MinMaxNum = [0.0, 1.0, 21]
    elif (x2MinMaxNum is None):
        dim = 1
    elif (x3MinMaxNum is None):
        dim = 2
    else:
        dim = 3

    if (dim == 1):
        MaxLength = max(abs(x1MinMaxNum[0]), abs(x1MinMaxNum[1]))
    if (dim == 2):
        MaxLength = max( abs(x1MinMaxNum[0]), abs(x1MinMaxNum[1]), \
                         abs(x2MinMaxNum[0]), abs(x2MinMaxNum[1])  )
    if (dim == 3):
        MaxLength = max( abs(x1MinMaxNum[0]), abs(x1MinMaxNum[1]), \
                         abs(x2MinMaxNum[0]), abs(x2MinMaxNum[1]), \
                         abs(x3MinMaxNum[0]), abs(x3MinMaxNum[1])  )

    # ------------------------------------------------- #
    # --- [2] 1D ver.                               --- #
    # ------------------------------------------------- #
    if (dim == 1):
        print("[generate__testprofile]  dim == 1D, (LI)    = ({0})".format(
            x1MinMaxNum[2]))
        x1g = esg.equiSpaceGrid(x1MinMaxNum=x1MinMaxNum, returnType="tuple")
        rhat = x1g / MaxLength * 0.5 * np.pi
        if (profileType == "cos**2"):
            profile = (vMax - vMin) * (np.cos(rhat))**2 + vMin
    if (dim == 2):
        print("[generate__testprofile]  dim == 2D, (LI,LJ) = ({0},{1})".format(
            x1MinMaxNum[2], x2MinMaxNum[2]))
        x1g, x2g = esg.equiSpaceGrid(x1MinMaxNum=x1MinMaxNum,
                                     x2MinMaxNum=x2MinMaxNum,
                                     returnType="tuple")
        rhat = np.sqrt(x1g**2 + x2g**2) / MaxLength * 0.5 * np.pi
        if (profileType == "cos**2"):
            profile = (vMax - vMin) * (np.cos(rhat))**2 + vMin
    if (dim == 3):
        print("[generate__testprofile]  dim == 3D, (LI,LJ,LK) = ({0},{1},{2})".
              format(x1MinMaxNum[2], x2MinMaxNum[2], x3MinMaxNum[2]))
        x1g, x2g, x3g = esg.equiSpaceGrid(x1MinMaxNum=x1MinMaxNum,
                                          x2MinMaxNum=x2MinMaxNum,
                                          x3MinMaxNum=x3MinMaxNum,
                                          returnType="tuple")
        rhat = np.sqrt(x1g**2 + x2g**2 + x3g**2) / MaxLength * 0.5 * np.pi
        if (profileType == "cos**2"):
            profile = (vMax - vMin) * (np.cos(rhat))**2 + vMin

    # ------------------------------------------------- #
    # --- [5] Return Results (point)                --- #
    # ------------------------------------------------- #
    if (returnType.lower() == "point"):
        if (dim == 1):
            ret = np.zeros((profile.size, 2))
            ret[:, 0] = x1g
            ret[:, 1] = profile
        if (dim == 2):
            ret = np.zeros((profile.size, 3))
            ret[:, 0] = x1g.reshape((-1, ))
            ret[:, 1] = x2g.reshape((-1, ))
            ret[:, 2] = profile.reshape((-1, ))
        if (dim == 3):
            ret = np.zeros((profile.size, 4))
            ret[:, 0] = x1g.reshape((-1, ))
            ret[:, 1] = x2g.reshape((-1, ))
            ret[:, 2] = x3g.reshape((-1, ))
            ret[:, 3] = profile.reshape((-1, ))

    # ------------------------------------------------- #
    # --- [6] Return Results (dictionary)           --- #
    # ------------------------------------------------- #
    if (returnType.lower() == "dictionary"):
        if (dim == 1):
            ret = {"x1g": x1g, "profile": profile}
        if (dim == 2):
            ret = {"x1g": x1g, "x2g": x2g, "profile": profile}
        if (dim == 3):
            ret = {"x1g": x1g, "x2g": x2g, "x3g": x3g, "profile": profile}

    # ------------------------------------------------- #
    # --- [7] Return Results (structured)           --- #
    # ------------------------------------------------- #
    if (returnType.lower() == "structured"):
        if (dim == 1): arrs = np.array([x1g, profile])
        if (dim == 2): arrs = np.array([x1g, x2g, profile])
        if (dim == 3): arrs = np.array([x1g, x2g, x3g, profile])
        ret = np.concatenate([arr[..., np.newaxis] for arr in arrs], axis=-1)

    # ------------------------------------------------- #
    # --- [8] Return Results (tuple)                --- #
    # ------------------------------------------------- #
    if (returnType.lower() == "tuple"):
        if (dim == 1): ret = (x1g, profile)
        if (dim == 2): ret = (x1g, x2g, profile)
        if (dim == 3): ret = (x1g, x2g, x3g, profile)

    return (ret)
Ejemplo n.º 18
0
    import nkUtilities.equiSpaceGrid as esg
    import nkUtilities.save__pointFile as spf
    x1MinMaxNum = [0.0, 1.0, 31]
    x2MinMaxNum = [0.0, 1.0, 21]
    x3MinMaxNum = [0.0, 1.0, 11]

    # ------------------------------------------------- #
    # --- [1] ijk -> kji                            --- #
    # ------------------------------------------------- #
    # ret         = gtp.generate__testprofile( x1MinMaxNum=x1MinMaxNum, x2MinMaxNum=x2MinMaxNum, \
    # 	                                     x3MinMaxNum=x3MinMaxNum, returnType = "point" )
    # print( ret.shape )
    # spf.save__pointFile( outFile="testprofile.dat", Data=ret, DataOrder="ijk" )

    # trn = reorder__ijk_kji( Data=ret, DataType="point", shape=(31,21,11), convert="ijk_kji" )
    # print( trn.shape )
    # spf.save__pointFile( outFile="transposed.dat", Data=trn, DataOrder="kji" )

    # ------------------------------------------------- #
    # --- [2] kji -> ijk                            --- #
    # ------------------------------------------------- #
    ret         = esg.equiSpaceGrid( x1MinMaxNum=x1MinMaxNum, x2MinMaxNum=x2MinMaxNum, \
                                     x3MinMaxNum=x3MinMaxNum, returnType = "structured", \
                                     DataOrder  ="kji" )
    print(ret.shape)
    spf.save__pointFile(outFile="testprofile.dat", Data=ret, DataOrder="kji")

    trn = reorder__ijk_kji(Data=ret, DataType="structured", convert="kji_ijk")
    print(trn.shape)
    spf.save__pointFile(outFile="transposed.dat", Data=trn, DataOrder="ijk")
Ejemplo n.º 19
0
        self.writer.Write()
        print("[save__uGrid] outFile :: {0} ".format(self.vtkFile))


# ========================================================= #
# ===   実行部                                          === #
# ========================================================= #

if (__name__ == "__main__"):

    import nkUtilities.equiSpaceGrid as esg
    x1MinMaxNum = [0.0, 1.0, 2]
    x2MinMaxNum = [0.0, 2.0, 2]
    x3MinMaxNum = [0.0, 3.0, 3]
    nodes       = esg.equiSpaceGrid( x1MinMaxNum=x1MinMaxNum, x2MinMaxNum=x2MinMaxNum, \
                                     x3MinMaxNum=x3MinMaxNum, returnType = "point", \
                                     DataOrder  ="ijk" )

    elems       = np.array( [ [ 0, 1, 3, 2, 4, 5,  7,  6 ], \
                              [ 4, 5, 7, 6, 8, 9, 11, 10 ]  ] )
    cellData = np.array([[1.0, 2.0, 3.0], [0.0, 1.0, 2.0]])
    pointData1 = np.sqrt(nodes[:, 0]**2 + nodes[:, 1]**2, nodes[:, 2]**2)
    pointData2 = np.exp(-0.5 * nodes[:, 0]**2 + nodes[:, 1]**2, nodes[:, 2]**2)
    pointData = np.concatenate((pointData1[:, None], pointData2[:, None]),
                               axis=1)

    construct__uGrid(nodes=nodes,
                     elems=elems,
                     cellData=cellData,
                     pointData=pointData,
                     vtkFile="out.vtu")
Ejemplo n.º 20
0

# ======================================== #
# ===  実行部                          === #
# ======================================== #
if (__name__ == "__main__"):

    outFile = "output.dat"
    import nkUtilities.equiSpaceGrid as esg
    LI, LJ, LK = 11, 21, 31
    x1MinMaxNum = [0.0, 3.0, LI]
    x2MinMaxNum = [0.0, 10.0, LJ]
    x3MinMaxNum = [0.0, 100.0, LK]

    returnType = "structured"

    # -- 1D test -- #
    # Data        = esg.equiSpaceGrid( x1MinMaxNum=x1MinMaxNum, returnType="structured"  )
    # Data        = np.ravel( Data )

    # -- 2D test -- #
    # Data        = esg.equiSpaceGrid( x1MinMaxNum=x1MinMaxNum, x2MinMaxNum=x2MinMaxNum, \
    #                                  returnType="structured"  )

    # -- 3D test -- #
    Data        = esg.equiSpaceGrid( x1MinMaxNum=x1MinMaxNum, x2MinMaxNum=x2MinMaxNum, \
                                     x3MinMaxNum=x3MinMaxNum, returnType=returnType, )

    print(Data.shape)
    save__pointFile(outFile=outFile, Data=Data)
Ejemplo n.º 21
0
def generate__twSample():

    #  E = E0 * exp ( iwt - ikx )   -->  exp( - ikx ) = cos(kx) - sin(kx)

    # ------------------------------------------------- #
    # --- [0] parameters                            --- #
    # ------------------------------------------------- #
    wave_number = 2
    freq = 2.856e9
    beta = 0.99
    cv = 2.9979246e+08
    EField_strength = 1.0e7

    # ------------------------------------------------- #
    # --- [1] parameter settings                    --- #
    # ------------------------------------------------- #
    x_, y_, z_ = 0, 1, 2
    vx_, vy_, vz_ = 0, 1, 2

    vphase = beta * cv
    wavelength = vphase / freq
    zMin, zMax = 0.0, wavelength * wave_number
    k_wave = 2.0 * np.pi / wavelength
    phase_shift1 = 0.0
    phase_shift2 = +90.0 / 180.0 * np.pi

    print()
    print(
        "[generate__twSample.py]  zMin & zMax are determined by periodic condtion... "
    )
    print("[generate__twSample.py]         (zMin,zMax)  :: ({0},{1})".format(
        zMin, zMax))
    print()
    print("[generate__twSample.py]  set above value in your parameter.conf")
    print("[generate__twSample.py]  press any key to continue..... >>  ")
    print()

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

    # ------------------------------------------------- #
    # --- [3] grid generation                       --- #
    # ------------------------------------------------- #
    import nkUtilities.equiSpaceGrid as esg
    x1MinMaxNum = [const["xMin"], const["xMax"], const["LI"]]
    x2MinMaxNum = [const["yMin"], const["yMax"], const["LJ"]]
    x3MinMaxNum = [zMin, zMax, const["LK"]]
    grid            = esg.equiSpaceGrid( x1MinMaxNum=x1MinMaxNum, x2MinMaxNum=x2MinMaxNum, \
                                         x3MinMaxNum=x3MinMaxNum, returnType = "structured" )
    eigen1 = np.zeros_like((grid))
    eigen2 = np.zeros_like((grid))
    eigen1[..., vz_] = EField_strength * np.cos(-k_wave * grid[..., z_] +
                                                phase_shift1)
    eigen2[..., vz_] = EField_strength * np.cos(-k_wave * grid[..., z_] +
                                                phase_shift2)

    Data1 = np.concatenate((grid, eigen1), axis=3)
    Data2 = np.concatenate((grid, eigen2), axis=3)

    # ------------------------------------------------- #
    # --- [4] save in File                          --- #
    # ------------------------------------------------- #

    import nkUtilities.save__pointFile as spf
    outFile1 = "dat/Eigen1.dat"
    outFile2 = "dat/Eigen2.dat"
    spf.save__pointFile(outFile=outFile1, Data=Data1)
    spf.save__pointFile(outFile=outFile2, Data=Data2)
Ejemplo n.º 22
0
# ========================================================= #
# ===   実行部                                          === #
# ========================================================= #

if (__name__ == "__main__"):
    import nkUtilities.genArgs as gar
    args = gar.genArgs()

    # ------------------------------------------------- #
    # --- [1] grid data making                      --- #
    # ------------------------------------------------- #

    import nkUtilities.equiSpaceGrid as esg
    x1MinMaxNum = [-1.0, 1.0, 21]
    x2MinMaxNum = [-1.0, 1.0, 21]
    grid        = esg.equiSpaceGrid( x1MinMaxNum=x1MinMaxNum, x2MinMaxNum=x2MinMaxNum, \
                                     returnType = "point" )
    radii = np.sqrt(grid[:, 0]**2 + grid[:, 1]**2)
    index = np.where(radii < 1.0)
    grid = grid[index]
    radii = radii[index]
    height = (np.cos(0.5 * np.pi * radii))**2
    gData = np.concatenate([grid, np.reshape(height, (-1, 1))], 1)

    # ------------------------------------------------- #
    # --- [2] point data making                     --- #
    # ------------------------------------------------- #

    nPoints = 1001
    points = np.zeros((nPoints, 3))
    points[:, 0] = (1.0 - (-1.0)) * np.random.rand(nPoints) + (-1.0)
    points[:, 1] = (1.0 - (-1.0)) * np.random.rand(nPoints) + (-1.0)
def make__boundary():

    # ------------------------------------------------- #
    # --- [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 )

    # ------------------------------------------------- #
    # --- [5] source with boundary info             --- #
    # ------------------------------------------------- #
    #  -- for laplacian ( R.H.S. == 0 for laplacian ) -- #
    LI, LJ, LK          = field.shape[2], field.shape[1], field.shape[0]
    source_             = np.copy( np.reshape( field, (-1,6) ) )
    radii               = np.sqrt( source_[:,x_]**2 + source_[:,y_]**2 )
    index               = np.where( radii <= const["radius"] )
    boundary            = np.ones( (source_.shape[0],) )
    boundary[index]     = 0.0
    source_[index,3:6]  = 0.0
    source_             = np.reshape( source_ , (LK,LJ,LI,6) )
    source_[ 0,:,:,3:6] = field[ 0,:,:,3:6]
    source_[-1,:,:,3:6] = field[-1,:,:,3:6]
    boundary            = np.reshape( boundary, (LK,LJ,LI,1) )
    
    srcFile      = "dat/source.dat"
    spf.save__pointFile( outFile=srcFile, Data=source_ )
    bdrFile      = "dat/boundary.dat"
    spf.save__pointFile( outFile=bdrFile, Data=boundary )
    
    # ------------------------------------------------- #
    # --- [7] convert vts File                      --- #
    # ------------------------------------------------- #
    import nkVTKRoutines.convert__vtkStructuredGrid as vts
    outFile  = "png/field.vts"
    names    = [ "bx", "by", "bz" ]
    vts.convert__vtkStructuredGrid( Data=field, outFile=outFile, names=names )

    outFile  = "png/source.vts"
    names    = [ "bx", "by", "bz" ]
    vts.convert__vtkStructuredGrid( Data=source_, outFile=outFile, names=names )

    return()