def prepare__peelerBackGround(): # ------------------------------------------------- # # --- [1] Load Data --- # # ------------------------------------------------- # inpFile_wo = "out/ems_shm_wo.field" inpFile_wp = "out/ems_shm_wp.field" outFile = "out/ems_peeler.field" with open(inpFile_wo, "r") as f: Data_wo = np.loadtxt(f) with open(inpFile_wp, "r") as f: Data_wp = np.loadtxt(f) # ------------------------------------------------- # # --- [2] coordinate consitency --- # # ------------------------------------------------- # eps = 1.e-5 dist = np.mean( np.sqrt((Data_wo[:, 0] - Data_wp[:, 0])**2 + (Data_wo[:, 1] - Data_wp[:, 1])**2)) if (dist > eps): print( "[prepare__peelerBackGround] abnormal dist detected :: {0} :: [ERROR] " .format(dist)) sys.exit() # ------------------------------------------------- # # --- [3] obtain peeler field components --- # # ------------------------------------------------- # Data = np.zeros((Data_wp.shape[0], 6)) Data[:, 0] = Data_wp[:, 0] Data[:, 1] = Data_wp[:, 1] Data[:, 2] = Data_wp[:, 2] Data[:, 3] = Data_wp[:, 3] - Data_wo[:, 3] Data[:, 4] = Data_wp[:, 4] - Data_wo[:, 4] Data[:, 5] = Data_wp[:, 5] - Data_wo[:, 5] # ------------------------------------------------- # # --- [4] save in File --- # # ------------------------------------------------- # import nkUtilities.save__pointFile as spf spf.save__pointFile(outFile=outFile, Data=Data) # ------------------------------------------------- # # --- [5] draw cMap --- # # ------------------------------------------------- # import nkUtilities.cMapTri as cmt pngFile = "png/ems_peeler.png" cmt.cMapTri(xAxis=Data[:, 0], yAxis=Data[:, 1], cMap=Data[:, 5], pngFile=pngFile)
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()
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)
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()
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)
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()
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 )
def display(): # ------------------------------------------------- # # --- [1] Arguments --- # # ------------------------------------------------- # config = lcf.load__config() datFile = "dat/bfield_biot.dat" pngFile = datFile.replace("dat", "png") # ------------------------------------------------- # # --- [2] Fetch Data --- # # ------------------------------------------------- # import nkUtilities.load__pointFile as lpf Data = lpf.load__pointFile(inpFile=datFile, returnType="point") xAxis = Data[:, 0] yAxis = Data[:, 1] zAxis = Data[:, 5] # ------------------------------------------------- # # --- [3] config Settings --- # # ------------------------------------------------- # cfs.configSettings(configType="cMap_def", config=config) config["FigSize"] = (5, 5) config["cmp_position"] = [0.16, 0.12, 0.97, 0.88] config["xTitle"] = "X (m)" config["yTitle"] = "Y (m)" config["cmp_xAutoRange"] = True config["cmp_yAutoRange"] = True config["cmp_xRange"] = [-5.0, +5.0] config["cmp_yRange"] = [-5.0, +5.0] # ------------------------------------------------- # # --- [4] plot Figure --- # # ------------------------------------------------- # cmt.cMapTri(xAxis=xAxis, yAxis=yAxis, cMap=zAxis, pngFile=pngFile, config=config)
def display__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()
# ================================================================ # # === 実行部 === # # ================================================================ # if (__name__ == "__main__"): # ---- テスト用 プロファイル ---- # # -- 座標系 xg, yg -- # x_, y_, z_ = 0, 1, 2 import nkUtilities.equiSpaceGrid as esg x1MinMaxNum = [-1.0, 1.0, 21] x2MinMaxNum = [-1.0, 1.0, 21] x3MinMaxNum = [0.0, 1.0, 1] ret = esg.equiSpaceGrid( x1MinMaxNum=x1MinMaxNum, x2MinMaxNum=x2MinMaxNum, \ x3MinMaxNum=x3MinMaxNum, returnType = "structured" ) ret[:, :, :, z_] = np.sqrt(ret[:, :, :, x_]**2 + ret[:, :, :, y_]**2) dx1 = ret[0, 0, 1, x_] - ret[0, 0, 0, x_] dx2 = ret[0, 1, 0, y_] - ret[0, 0, 0, y_] Data = np.reshape(ret[:, :, :, z_], (ret.shape[1], ret.shape[2])) grad = calc__grad2d(Data=Data, dx1=dx1, dx2=dx2) xAxis = np.ravel(ret[0, :, :, x_]) yAxis = np.ravel(ret[0, :, :, y_]) grad_x, grad_y = np.copy(np.ravel(grad[:, :, 0])), np.copy( np.ravel(grad[:, :, 1])) Data = np.ravel(Data) print(xAxis.shape, yAxis.shape, grad_x.shape, grad_y.shape, Data.shape) import nkUtilities.cMapTri as cmt cmt.cMapTri(xAxis=xAxis, yAxis=yAxis, cMap=Data, pngFile='source.png') cmt.cMapTri(xAxis=xAxis, yAxis=yAxis, cMap=grad_x, pngFile='grad_x.png') cmt.cMapTri(xAxis=xAxis, yAxis=yAxis, cMap=grad_y, pngFile='grad_y.png')
Data = nps.vtk_to_numpy(probe.GetOutput().GetPointData().GetArray(key)) ret = np.concatenate([coord, Data], axis=-1) return (ret) # ========================================================= # # === 実行部 === # # ========================================================= # if (__name__ == "__main__"): inpFile = "vtu/cShape_magnet_t0001.vtu" key = "magnetic field strength e" import nkUtilities.equiSpaceGrid as esg x1MinMaxNum = [-1.0, +1.0, 301] x2MinMaxNum = [0.0, +0.0, 1] x3MinMaxNum = [-1.0, +1.0, 301] coord = esg.equiSpaceGrid( x1MinMaxNum=x1MinMaxNum, x2MinMaxNum=x2MinMaxNum, \ x3MinMaxNum=x3MinMaxNum, returnType = "point" ) ret = extract__vtuData(inpFile=inpFile, key=key, coord=coord) pngFile = "out.png" import nkUtilities.cMapTri as cmt cmt.cMapTri(xAxis=ret[:, 0], yAxis=ret[:, 2], cMap=ret[:, 5], pngFile=pngFile) print(ret)
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) radii = np.sqrt(points[:, 0]**2 + points[:, 1]**2) index = np.where(radii < 1.0) points = points[index] # ------------------------------------------------- # # --- [3] interpolator --- # # ------------------------------------------------- # ret = barycentric__interpolator(nodes=gData, points=points) import nkUtilities.cMapTri as cmt cmt.cMapTri(xAxis=gData[:, 0], yAxis=gData[:, 1], cMap=gData[:, 2], pngFile="png/out1.png") cmt.cMapTri(xAxis=ret[:, 0], yAxis=ret[:, 1], cMap=ret[:, 2], pngFile="png/out2.png")
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 ()
dx_, dy_, LI_, LJ_, ) return (lap_) # ================================================================ # # === テスト用 呼び出し === # # ================================================================ # if (__name__ == '__main__'): 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" ) xAxis = ret[0, :, :, 0] yAxis = ret[0, :, :, 1] phi = xAxis**2 + yAxis**2 ret = calc__laplacian(phi=phi) with open("out.dat", "w") as f: np.savetxt(f, ret) import nkUtilities.cMapTri as cmt pngFile = "out.png" xa, ya, za = np.ravel(xAxis), np.ravel(yAxis), np.ravel(ret) cmt.cMapTri(xAxis=xa, yAxis=ya, cMap=za, pngFile=pngFile)
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)
if (__name__ == '__main__'): x_, y_, z_ = 0, 1, 2 import nkUtilities.equiSpaceGrid as esg x1MinMaxNum = [-1.0, 1.0, 101] x2MinMaxNum = [-1.0, 1.0, 101] x3MinMaxNum = [0.0, 1.0, 1] ret = esg.equiSpaceGrid( x1MinMaxNum=x1MinMaxNum, x2MinMaxNum=x2MinMaxNum, \ x3MinMaxNum=x3MinMaxNum, returnType = "structured" ) LI, LJ = ret.shape[2], ret.shape[1] xAxis = np.copy(np.reshape(ret[0, :, :, x_], (LJ, LI))) yAxis = np.copy(np.reshape(ret[0, :, :, y_], (LJ, LI))) Data = np.zeros((LJ, LI, 3)) vx_, vy_, vz_ = 0, 1, 2 Data[:, :, vx_] = xAxis Data[:, :, vy_] = yAxis Data[:, :, vz_] = xAxis * yAxis curl = calc__curl2d(Data=Data, x1Axis=xAxis, x2Axis=yAxis) xAxis = np.ravel(xAxis) yAxis = np.ravel(yAxis) curlx = np.ravel(curl[:, :, vx_]) curly = np.ravel(curl[:, :, vy_]) curlz = np.ravel(curl[:, :, vz_]) import nkUtilities.cMapTri as cmt cmt.cMapTri(xAxis=xAxis, yAxis=yAxis, cMap=curlx, pngFile='curlx.png') cmt.cMapTri(xAxis=xAxis, yAxis=yAxis, cMap=curly, pngFile='curly.png') cmt.cMapTri(xAxis=xAxis, yAxis=yAxis, cMap=curlz, pngFile='curlz.png')
gamma = np.sqrt(kc**2 - omega**2 / cv**2) # ------------------------------------------------- # # --- [3] TE mode wave --- # # ------------------------------------------------- # import scipy.special as special import nkBasicAlgs.robustInv as inv rinv = inv.robustInv(radii) Ez_Amp = Emn * special.jv(mmode, kcr) * np.cos(mphi) Hz_Amp = 0.0 * kcr Er_Amp = -gamma / kc * Emn * special.jv(mmode + 1, kcr) * np.cos(mphi) Ep_Amp = gamma * mmode / kc**2 * Emn * special.jv(mmode, kcr) * np.sin(mphi) * rinv Hr_Amp = epsilon * omega * mmode / kc**2 * Emn * special.jv( mmode, kcr) * np.sin(mphi) * rinv Hp_Amp = -epsilon * omega / kc * Emn * special.jv(mmode + 1, kcr) * np.cos(mphi) # ------------------------------------------------- # # --- [4] colormap of the Amplitude --- # # ------------------------------------------------- # import nkUtilities.cMapTri as cmt cmt.cMapTri(xAxis=xg, yAxis=yg, cMap=Er_Amp, pngFile="Er_Amp.png") cmt.cMapTri(xAxis=xg, yAxis=yg, cMap=Ep_Amp, pngFile="Ep_Amp.png") cmt.cMapTri(xAxis=xg, yAxis=yg, cMap=Ez_Amp, pngFile="Ez_Amp.png") cmt.cMapTri(xAxis=xg, yAxis=yg, cMap=Hr_Amp, pngFile="Hr_Amp.png") cmt.cMapTri(xAxis=xg, yAxis=yg, cMap=Hp_Amp, pngFile="Hp_Amp.png") cmt.cMapTri(xAxis=xg, yAxis=yg, cMap=Hz_Amp, pngFile="Hz_Amp.png")
def display__axisymmField(inpFile=None): x_, y_, z_ = 0, 1, 2 vx_, vy_, vz_ = 3, 4, 5 # ------------------------------------------------- # # --- [1] Load Config & Eigenmode --- # # ------------------------------------------------- # import nkUtilities.load__constants as lcn cnsFile = "dat/parameter.conf" pngFile = "png/{0}field_{1}_{2}.png" config = lcf.load__config() const = lcn.load__constants(inpFile=cnsFile) eflist = const["EFieldListFile"] bflist = const["BFieldListFile"] with open(eflist, "r") as f: efiles = f.readlines() with open(bflist, "r") as f: bfiles = f.readlines() # ------------------------------------------------- # # --- [2] config Settings --- # # ------------------------------------------------- # cfs.configSettings(configType="cMap_def", config=config) config["FigSize"] = (8, 4) config["cmp_position"] = [0.16, 0.12, 0.97, 0.88] config["xTitle"] = "Z (m)" config["yTitle"] = "R (m)" config["cmp_xAutoRange"] = True config["cmp_yAutoRange"] = True config["cmp_xRange"] = [-5.0, +5.0] config["cmp_yRange"] = [-5.0, +5.0] config["vec_AutoScale"] = True config["vec_AutoRange"] = True config["vec_AutoScaleRef"] = 200.0 config["vec_nvec_x"] = 24 config["vec_nvec_y"] = 6 config["vec_interpolation"] = "nearest" # ------------------------------------------------- # # --- [4] plot Figure ( efield ) --- # # ------------------------------------------------- # for ik, efile in enumerate(efiles): import nkUtilities.load__pointFile as lpf efield = lpf.load__pointFile(inpFile=efile.strip(), returnType="point") xAxis = np.copy(efield[:, z_]) yAxis = np.copy(efield[:, x_]) absE = np.sqrt(efield[:, vx_]**2 + efield[:, vz_]**2) cmt.cMapTri( xAxis=xAxis, yAxis=yAxis, cMap=efield[:,vz_], \ pngFile=pngFile.format( "e", ik, "Ez" ), config=config ) cmt.cMapTri( xAxis=xAxis, yAxis=yAxis, cMap=efield[:,vx_], \ pngFile=pngFile.format( "e", ik, "Er" ), config=config ) fig = cmt.cMapTri(pngFile=pngFile.format( "e", ik, "Ev", ), config=config) fig.add__cMap(xAxis=xAxis, yAxis=yAxis, cMap=absE) fig.add__vector ( xAxis=xAxis, yAxis=yAxis, uvec=efield[:,vz_], vvec=efield[:,vx_], \ color="blue" ) fig.save__figure() # ------------------------------------------------- # # --- [5] plot Figure ( bfield ) --- # # ------------------------------------------------- # for ik, bfile in enumerate(bfiles): import nkUtilities.load__pointFile as lpf bfield = lpf.load__pointFile(inpFile=bfile.strip(), returnType="point") xAxis = np.copy(bfield[:, z_]) yAxis = np.copy(bfield[:, x_]) cmt.cMapTri( xAxis=xAxis, yAxis=yAxis, cMap=bfield[:,vy_], \ pngFile=pngFile.format( "b", ik, "Hp" ), config=config )
def check__carbonIdeal(datFile=None, pngFile=None, config=None): # ------------------------------------------------- # # --- [1] Arguments --- # # ------------------------------------------------- # if (config is None): config = lcf.LoadConfig() if (datFile1 is None): datFile1 = "dat/bfield_from_aoki.dat" if (pngFile1 is None): pngFile1 = "png/bfield_from_aoki.png" if (datFile2 is None): datFile2 = "dat/bfield_ideal_acoord.dat" if (pngFile2 is None): pngFile2 = "png/bfield_ideal_acoord.png" # ------------------------------------------------- # # --- [2] Fetch Data --- # # ------------------------------------------------- # with open(datFile1, "r") as f: Data1 = np.loadtxt(f) xAxis1 = Data1[:, 0] yAxis1 = Data1[:, 1] zAxis1 = Data1[:, 2] with open(datFile2, "r") as f: Data2 = np.loadtxt(f) xAxis2 = Data2[:, 0] yAxis2 = Data2[:, 1] zAxis2 = Data2[:, 2] pngFile3 = "png/bfield_error.png" xAxis3 = np.copy(xAxis2) yAxis3 = np.copy(yAxis2) zAxis3 = np.copy(zAxis2) - np.copy(zAxis1) # ------------------------------------------------- # # --- [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" config["yTitle"] = "Y" 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) cmt.cMapTri(xAxis=xAxis3, yAxis=yAxis3, cMap=zAxis3, pngFile=pngFile3, config=config)
# --- [4] save result --- # # ------------------------------------------------- # import nkUtilities.save__pointFile as spf spf.save__pointFile(outFile=outFile, Data=ret) # ========================================================= # # === 実行部 === # # ========================================================= # if (__name__ == "__main__"): sample = np.zeros((101, 3)) sample[:, 0] = np.linspace(0.0, 1.0, 101) sample[:, 2] = np.cos(sample[:, 0] * np.pi * 0.5)**2 import nkUtilities.save__pointFile as spf sampleFile = "dat/pole_cs.dat" gridFile = "dat/gridData.dat" spf.save__pointFile(outFile=sampleFile, Data=sample) expand__pole_cs(inpFile=sampleFile, outFile=gridFile) with open(gridFile, "r") as f: Data = np.loadtxt(f) import nkUtilities.cMapTri as cmt print(Data) cmt.cMapTri(xAxis=Data[:, 0], yAxis=Data[:, 1], cMap=Data[:, 2])
ret = li1.LinearInterp1D(xa=ra, fa=fa, xp=rp) grid[:, 2] = fa[-1] grid[index, 2] = ret # ------------------------------------------------- # # --- [4] return --- # # ------------------------------------------------- # return (grid) # ========================================================= # # === 実行部 === # # ========================================================= # if (__name__ == "__main__"): inpFile = "profile.dat" x1MinMaxNum = [0.0, 0.8, 101] x2MinMaxNum = [-0.8, 0.8, 101] ra = np.linspace(0.0, 1.0, 101) fa = np.cos(ra * np.pi * 0.5)**2 ret = expand__axisymmetric( ra=ra, fa=fa, radius=0.8, \ x1MinMaxNum=x1MinMaxNum, x2MinMaxNum=x2MinMaxNum ) import nkUtilities.cMapTri as cmt cmt.cMapTri(xAxis=ret[:, 0], yAxis=ret[:, 1], cMap=ret[:, 2], pngFile="out.png")
x2 = np.array([r2 * np.cos(p1), r2 * np.sin(p1)]) x3 = np.array([r2 * np.cos(p2), r2 * np.sin(p2)]) x4 = np.array([r1 * np.cos(p2), r1 * np.sin(p2)]) l12_x = (x2[0] - x1[0]) * t + x1[0] l12_y = (x2[1] - x1[1]) * t + x1[1] l23_x = r1 * np.cos(p) l23_y = r1 * np.sin(p) l34_x = (x4[0] - x3[0]) * t + x3[0] l34_y = (x4[1] - x3[1]) * t + x3[1] l41_x = r2 * np.cos(p) l41_y = r2 * np.sin(p) # ------------------------------------------------- # # --- [2] plot lines --- # # ------------------------------------------------- # fig.add__plot(xAxis=l12_x, yAxis=l12_y) fig.add__plot(xAxis=l23_x, yAxis=l23_y) fig.add__plot(xAxis=l34_x, yAxis=l34_y) fig.add__plot(xAxis=l41_x, yAxis=l41_y) return (fig) # ======================================== # # === 実行部 === # # ======================================== # if (__name__ == "__main__"): fig = cmt.cMapTri() add__shimRegion_cMap(fig=fig) fig.save__figure()
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()
sys.exit() # ------------------------------------------------- # # --- [4] return --- # # ------------------------------------------------- # return (ret) # ========================================================= # # === 実行部 === # # ========================================================= # if (__name__ == "__main__"): inpFile = "dat/out.bin" shape = (1, 31, 41, 4) Data = load__fortranBinary(inpFile=inpFile, shape=shape) Data = Data.reshape((-1, 4)) import nkUtilities.load__config as lcf import nkUtilities.cMapTri as cmt config = lcf.load__config() pngFile = "png/out.png" config["xTitle"] = "X (m)" config["yTitle"] = "Y (m)" config["cmp_xAutoRange"] = True config["cmp_yAutoRange"] = True cmt.cMapTri( xAxis=Data[:,0], yAxis=Data[:,1], cMap=Data[:,3], \ pngFile=pngFile, config=config )
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 ) )
xAxis = np.linspace(0.0, 1.0, 101) yAxis1 = np.sin(xAxis * 2.0 * np.pi) yAxis2 = np.cos(xAxis * 2.0 * np.pi) fig = pl1.plot1D(config=config, pngFile=pngFile) fig.add__plot(xAxis=xAxis, yAxis=yAxis1, label="sin(x)") fig.add__plot(xAxis=xAxis, yAxis=yAxis2, label="cos(x)") fig.add__legend() fig.set__axis() fig.save__figure() # ------------------------------------------------- # # --- [2] cmap config settings sample --- # # ------------------------------------------------- # import nkUtilities.load__config as lcf import nkUtilities.cMapTri as cmt config = lcf.load__config() config = configSettings(configType="cMap_def", config=config) pngFile = "test/configSettings_sample_cMap.png" import nkUtilities.equiSpaceGrid as esg x1MinMaxNum = [-1.0, 1.0, 21] x2MinMaxNum = [-1.0, 1.0, 21] x3MinMaxNum = [0.0, 0.0, 1] coord = esg.equiSpaceGrid( x1MinMaxNum=x1MinMaxNum, x2MinMaxNum=x2MinMaxNum, \ x3MinMaxNum=x3MinMaxNum, returnType = "point" ) coord[:, z_] = np.sqrt(coord[:, x_]**2 + coord[:, y_]**2) cmt.cMapTri( xAxis=coord[:,x_], yAxis=coord[:,y_], cMap=coord[:,z_], \ pngFile=pngFile, config=config )