Mathematicaで電磁気の考察事始めVol.Ⅶ
Mathematicaで電磁気の考察事始めVol.ⅦMathematicaで電磁気の考察事始めVol.Ⅵからの続き。10.a.1.ElectricCurrentPDE_ExsamplesElectricCurrentPDEComponentIn[]:(*電気伝導率がσ=6*10^7のくびれた長方形のプレート内の電気スカラーポテンシャルについて解く*)Vfun=NDSolveValue[{ElectricCurrentPDEComponent[{V[x,y],{x,y}},<|"ElectricalConductivity"->6*^7|>]==0,ElectricPotentialCondition[y==-2,{V[x,y],{x,y}},<|"ElectricPotential"->0|>],ElectricPotentialCondition[y==2,{V[x,y],{x,y}},<|"ElectricPotential"->1|>]},V,{x,y}\[Element]RegionUnion[Rectangle[{-1,-2},{1,-0.3}],Rectangle[{-1,0.3},{1,2}],Rectangle[{-0.3,-0.3},{0.3,0.3}]]];(*電流密度ベクトルを計算する。*)Jfield=-6*^7*Grad[Vfun[x,y],{x,y}];(*電流密度ベクトルを可視化する。*)VectorPlot[Jfield,{x,y}\[Element]RegionUnion[Rectangle[{-1,-2},{1,-0.3}],Rectangle[{-1,0.3},{1,2}],Rectangle[{-0.3,-0.3},{0.3,0.3}]],AspectRatio->Automatic]Out[]:2D定常解析In[]:(*導電率が6*10^7の3バー電気スイッチの電気スカラーポテンシャルについて解く*)Vfun=NDSolveValue[{ElectricCurrentPDEComponent[{V[x,y],{x,y}},<|"ElectricalConductivity"->6*^7|>]==0,ElectricPotentialCondition[y==-7.5,{V[x,y],{x,y}},<|"ElectricPotential"->0|>],ElectricPotentialCondition[y==7.5,{V[x,y],{x,y}},<|"ElectricPotential"->5|>]},V,{x,y}\[Element]RegionUnion[Rectangle[{0,2.5},{10,7.5}],Rectangle[{9,-2.5},{10+9,2.5}],Rectangle[{0,-7.5},{10,-2.5}]]];(*電流密度ベクトルを計算する*)Jfield=-6*^7*Grad[Vfun[x,y],{x,y}];(*電流密度ベクトルを可視化する*)VectorPlot[Jfield,{x,y}\[Element]RegionUnion[Rectangle[{0,2.5},{10,7.5}],Rectangle[{9,-2.5},{10+9,2.5}],Rectangle[{0,-7.5},{10,-2.5}]],AspectRatio->Automatic]Out[]:3D定常解析In[]:(*1[A]の直流電流(DC)で励起される銅線を上方境界における境界電流密度条件と下方境界におけるゼロ電位条件でモデル化する.定常電流PDEモデルの変数varsとparsを設定する*)vars={V[x,y,z],{x,y,z}};pars=<|"Material"->Entity["Element","Copper"]|>;(*方程式を設定する*)op=ElectricCurrentPDEComponent[vars,pars];(*下方境界における地電位を指定する*)Subscript[Γ,ground]=ElectricPotentialCondition[z==0,vars,pars,<|"ElectricPotential"->0|>];(*上方境界における流入電流の流れを指定する*)Subscript[Γ,source]=ElectricCurrentDensityValue[z==0.01,vars,pars,<|"Current"->1|>];(*円柱を定義する*)Ω=Cylinder[{{0,0,0},{0,0,0.01}},0.0005];(*PDEを解く*)Vfun=NDSolveValue[{op==Subscript[Γ,source],Subscript[Γ,ground]},V,{x,y,z}\[Element]Ω](*電位を可視化する*)Show[Graphics3D[{Opacity[0.2],Ω},Boxed->False],SliceDensityPlot3D[Vfun[x,y,z],{x,y,z}\[Element]Ω,Sequence[ColorFunction->"Rainbow",BoxRatios->Automatic,PlotLegends->BarLegend[Automatic,50,LegendLabel->"[V]"],Boxed->False,Axes->None]]]Out[]:In[]:(*電位差0.2[V]のタングステンワイヤをモデル化する.定常電流偏微分方程式のモデル変数varsとparsを設定する*)vars={V[x,y,z],{x,y,z}};pars=<|"Material"->Entity["Element","Tungsten"]|>;(*定常電流偏微分方程式を設定する*)op = ElectricCurrentPDEComponent[vars, pars];(*タングステンワイヤの半径は2.5* (10^-3)[m]で,ワイヤの幾何学形状はS字型である.幾何学パラメータを指定する*)L = 0.05;r = 0.0025;R = 0.0075;(*シミュレーション領域*)Ω =;(*左端境界ではSubscript[V, 0]=0.2[V]の電位境界条件が適用され,右端境界ではゼロ電位条件が適用される.離散化領域の数値誤差を考慮して,許容値0.01rが両端に適用される.ワイヤの両端に電位境界条件を設定する*)Subscript[Γ,potential] = {ElectricPotentialCondition[Abs[x] <= 0.01 r && y^2 + z^2 <= r^2, vars,pars, <|"ElectricPotential" -> 0.2|>],ElectricPotentialCondition[Abs[y + r] <= 0.01 r && (x - (L + 2 R + r))^2 + z^2 <= r^2, vars,pars]};(*偏微分方程式を解く*)Vfun = NDSolveValue[{op == 0, Subscript[Γ, potential]},V, {x, y, z} \[Element] Ω](*電流密度ベクトルを計算する*)Jfield = -QuantityMagnitude[pars["Material"]["ElectricalConductivity"]] * Grad[Vfun[x, y, z], {x, y, z}];(*電流密度の大きさを可視化する*)SliceDensityPlot3D[Sqrt[Total[Jfield^2]],{{"XStackedPlanes",10},{"YStackedPlanes",12},{"ZStackedPlanes",3}},{x,y,z}\[Element]Ω,Sequence[ColorFunctionScaling->False,ColorFunction->ColorData[{"Rainbow",MinMax[ReplaceAll[Sqrt[Total[Jfield^2]],Pattern[head,InterpolatingFunction][Pattern[a,BlankSequence[]]][Pattern[d,BlankSequence[]]]:>head[a]["ValuesOnGrid"]]]}],BoxRatios->Automatic,Boxed->False,Axes->None,PlotLegends->BarLegend[Automatic,50,LegendLabel->"[A/\!\(\*SuperscriptBox[\(m\), \(2\)]\)]"]]]Out[]:In[]:(*左境界に対して垂直な電流密度で励起され,右境界でゼロ電位境界条件を持つ銅スパイラルインダクタをモデル化する.スパイラルインダクタの形状を定義する*)Ω=RegionUnion[Cuboid[{0,0,0},{2,1,1}],Cuboid[{1,1,0},{2,8,1}],Cuboid[{2,7,0},{8,8,1}],Cuboid[{7,7,0},{8,0,1}],Cuboid[{7,0,0},{3,1,1}],Cuboid[{3,1,0},{4,6,1}],Cuboid[{4,6,0},{6,5,1}],Cuboid[{6,5,0},{5,2,1}],Cuboid[{5,2,1},{6,3,1.2}],Cuboid[{5,2,1.2},{10,3,2.2}]](*定常電流偏微分モデル変数varsとparsを設定する*)vars={V[x,y,z],{x,y,z}};pars=<|"Material"->Entity["Element","Copper"]|>;(*左境界に内向きの電流フローを指定する*)Subscript[Γ,source]=ElectricCurrentDensityValue[x==0,vars,pars,<|"NormalCurrentDensity"->10|>];(*地位を指定する*)Subscript[Γ,ground]=ElectricPotentialCondition[x==10,vars,pars];(*偏微分方程式を解く*)Vfun=NDSolveValue[{ElectricCurrentPDEComponent[vars,pars]==Subscript[Γ,source],Subscript[Γ,ground]},V,{x,y,z}\[Element]Ω]Vfun=NDSolveValue[{op==0,Subscript[Γ,potential]},V,{x,y,z}\[Element]Ω](*ElectricCurrentPDEComponentV2*)(*左境界に対して垂直な電流密度で励起され,右境界でゼロ電位境界条件を持つ銅スパイラルインダクタをモデル化する.スパイラルインダクタの形状を定義する*)Ω=RegionUnion[Cuboid[{0,0,0},{2,1,1}],Cuboid[{1,1,0},{2,8,1}],Cuboid[{2,7,0},{8,8,1}],Cuboid[{7,7,0},{8,0,1}],Cuboid[{7,0,0},{3,1,1}],Cuboid[{3,1,0},{4,6,1}],Cuboid[{4,6,0},{6,5,1}],Cuboid[{6,5,0},{5,2,1}],Cuboid[{5,2,1},{6,3,1.2}],Cuboid[{5,2,1.2},{10,3,2.2}]](*定常電流偏微分モデル変数varsとparsを設定する*)vars={V[x,y,z],{x,y,z}};pars=<|"Material"->Entity["Element","Copper"]|>;(*左境界に内向きの電流フローを指定する*)Subscript[Γ,source]=ElectricCurrentDensityValue[x==0,vars,pars,<|"NormalCurrentDensity"->10|>];Subscript[Γ,source]=ElectricCurrentDensityValue[x==0,vars,pars,<|"NormalCurrentDensity"->10|>];(*地位を指定する*)Subscript[Γ,ground]=ElectricPotentialCondition[x==10,vars,pars];(*偏微分方程式を解く*)Vfun=NDSolveValue[{ElectricCurrentPDEComponent[vars,pars]==Subscript[Γ,source],Subscript[Γ,ground]},V,{x,y,z}\[Element]Ω](*電流密度ベクトルを計算する*)Jfield=-QuantityMagnitude[pars["Material"]["ElectricalConductivity"]]*Grad[Vfun[x,y,z],{x,y,z}];(*電流密度の大きさを可視化する*)SliceDensityPlot3D[Sqrt[Total[Jfield^2]],{{"XstackedPlanes",10},{"YstackedPlanes",10},{"ZstackedPlanes",5}},{x,y,z}\[Element]Ω,Sequence[BoxRatios->Automatic,Boxed->False,Axes->None]]Out[]:周波数解析In[]:(*60[Hz]の交流電流(AC)で励起される円筒形コンデンサの誘電材料を,コンデンサの電極を表す上方境界の電流密度条件と下方境界の電位ゼロ状態でモデル化する.周波電流PDEモデル変数varsを設定する*)vars={V[x,y,z],ω,{x,y,z}};(*周波数と周期を定義する*)f0=60;T0=1/f0;(*領域Ωを設定する*)r0=0.01;h=0.001;Ω=Cylinder[{{0,0,0},{0,0,h}},r0];(*導電率σと比誘電率Subscript[ϵ, r]を指定する*)pars=<|"ElectricalConductivity"->1*^-8,"RelativePermittivity"->2|>;(*下方境界における地電位を指定する*)Subscript[Γ,ground]=ElectricPotentialCondition[z==0,vars,pars];(*上方境界における流入電流を指定する*)Subscript[Γ,current]=ElectricCurrentDensityValue[z==h,vars,pars,<|"Current"->1*^-7|>];(*方程式を設定する*)op=ElectricCurrentPDEComponent[vars,pars];(*調和PDEを60[Hz]について解く*)Vfun=NDSolveValue[{(op/. {ω->2 Pi f0})==Subscript[Γ,current],Subscript[Γ,ground]},V,{x,y,z}\[Element]Ω](*上方境界の電圧を時間領域に変換する*)Vlist=Table[{t,Re[Vfun[0,0,h]*Exp[I ω t]/. {ω->2 Pi f0}]},{t,0,3*T0,T0/100}];(*コンデンサの上部プレートの電圧を可視化する*)ListLinePlot[Vlist]Out[]:10.a.2.ElectricFluxDensity_ExsamplesElectricFluxDensityValueIn[]:(*電束密度境界がある平行電場をモデル化する.静電気モデル変数varsを設定する*)vars={V[x,y],{x,y}};(*領域Ωを設定する*)Ω=Rectangle[{-1,-1},{1,1}];(*Subscript[静電気モデルパラメータ比誘電率ϵ, r]を指定する*)pars=<|"RelativePermittivity"->1|>;(*境界ボックスの右側の地電位を設定する*)Subscript[Γ,ground]=ElectricPotentialCondition[x==1,vars,pars];(*境界ボックスの左側で内側電束密度境界条件を設定する*)Subscript[Γ,Flux]=ElectricFluxDensityValue[x==-1,vars,pars,<|"ElectricFluxDensity"->{8.85*^-7,0}|>](*方程式を指定する*)eqn=ElectrostaticPDEComponent[vars,pars]==Subscript[Γ,Flux];(*偏微分方程式を解く*)Vfun=NDSolveValue[{eqn,Subscript[Γ,ground]},V,{x,y}\[Element]Ω];(*電場強度Eを計算する*)Efield=-Grad[Vfun[x,y],{x,y}];(*解を可視化する*)VectorPlot[Efield,{x,y}\[Element]Ω,Sequence[VectorPoints->Fine,VectorRange->Automatic,VectorScaling->Automatic,RegionFillingStyle->None,RegionBoundaryStyle->None]]Out[]:In[]:(*コンデンサの電圧差を指定する代りにコンデンサのプレートの1つの面電荷密度を指定することもできる.静電モデル変数varsを設定する*)vars={V[x,y],{x,y}};(*領域Ωを設定する*)Ω=Rectangle[{-0.05,-0.02},{0.05,0.02}];(*Subscript[静電モデルのパラメータの比誘電率ϵ, r]を指定する*)pars=<|"RelativePermittivity"->3|>;(*上界に正の面電荷を設定する*)Subscript[Γ,p]=ElectricFluxDensityValue[y==0.02,vars,pars,<|"SurfaceChargeDensity"->1*^-9|>](*下界に地電位を設定する*)Subscript[Γ,ground]=ElectricPotentialCondition[y==-0.02,vars,pars];(*方程式を指定する:*)eqn=ElectrostaticPDEComponent[vars,pars]==Subscript[Γ,p];(*偏微分方程式を解く*)Vfun=NDSolveValue[{eqn,Subscript[Γ,ground]},V,{x,y}\[Element]Ω];(*解を可視化する*)DensityPlot[Vfun[x,y],{x,y}\[Element]Ω,Sequence[PlotRange->MinMax[Vfun["ValuesOnGrid"]],ColorFunction->ColorData[{"Rainbow",MinMax[Vfun["ValuesOnGrid"]]}],ColorFunctionScaling->False,PlotLegends->BarLegend[Automatic,50,LegendMarkerSize->150,LegendLabel->"[V]"],FrameLabel->{"x","y"},PlotLabel->"Electric Potential",AspectRatio->Automatic,PlotPoints->90]]Out[]:10.a.3.ElectricPotential_ExsamplesElectricPotentialConditionIn[]:(*電位面境界条件を設定する*)ElectricPotentialCondition[x>=0,{V[x,y],{x,y}},<|"ElectricPotential"->Subscript[V,s][x,y]|>](*デフォルトの電位面境界条件を設定する*)ElectricPotentialCondition[x>=0,{V[x,y],{x,y}},<||>](*モデル変数vars,パラメータpars,Subscript[左境界の電位V, 0](10[V]),右境界の地電位で,電位分布を計算する:モデルの変数と静電パラメータを指定する*)vars={V[x],{x}};pars=<|"RelativePermittivity"->2|>;(*偏微分方程式を設定して解く*)Vfun=NDSolveValue[{ElectrostaticPDEComponent[vars,pars]==0,{ElectricPotentialCondition[x==0,vars,pars,<|"ElectricPotential"->10|>],ElectricPotentialCondition[x==1/5,vars,pars,<|"ElectricPotential"->0|>]}},V,x\[Element]Line[{{0},{1/5}}]];(*解を可視化する*)Plot[Vfun[x],{x,0,1/5},AxesLabel->{"x","V"}]Out[]:1DIn[]:(*距離d=8[cm]で隔てられた 軸に垂直の2枚の平行プレート間の電位分布を計算する.Subscript[左側のパネルは定電位V, 0]=1[V]に保たれているのに対し,右側のパネルは接地していてV=0である.プレート間の領域は比誘電率Subscript[ϵ, r]=1Subscript[と均一な電子電荷密度ρ , v]=(10 ^-8)[C/m^3]で特徴付られる.モデルで使用する方程式は以下で与えられる*)del.(-epsilon_0epsilon_r del V(x))^(︷^(electrostatic model))=rho_v(*静電気モデル変数varsを設定する*)vars={V[x],{x}};(*領域Ωを設定する*)Ω=Line[{{0},{0.08}}];(*静電気モデルパラメータを指定する*)pars=<|"RelativePermittivity"->1,"VolumeChargeDensity"->-10*^-8|>;(*電位条件を指定する*)Subscript[Γ,v]={ElectricPotentialCondition[x==0,vars,pars,<|"ElectricPotential"->1|>],ElectricPotentialCondition[x==0.08,vars,pars]}(*方程式を設定する*)eqn=ElectrostaticPDEComponent[vars,pars]==0(*偏微分方程式を解く*)Vfun=NDSolveValue[{eqn,Subscript[Γ,v]},V,x\[Element]Ω](*解を可視化する*)Plot[Vfun[x],x\[Element]Ω]Out[]:続編:Mathematicaで電磁気の考察事始めVol.Ⅷ