29import matplotlib.pyplot
as plt
30import matplotlib
as mpl
32import fluxfunction
as ff
35''' Testing routine for different dipole formulations
37 Plots flux function contours of magnetic field in the meridional x-z-plane for four different models.
38 Also evaluates in-plane divergence, as the flux function doesn't work properly for the 3D dipole models.
43 testset = int(sys.argv[1])
47plt.switch_backend(
'Agg')
49outfilename =
"./vecpotdip_verify_fluxfunctions_"+str(testset)+
".png"
66flux_levels = np.reshape([np.linspace(-5.e-6,-1e-14,1000),np.linspace(1.e-14,5e-6,1000)],2000)
85 tilt_angle_theta = 45.
101fig.set_size_inches(20,20)
103gs = mpl.gridspec.GridSpec(2, 2, wspace=0.25, hspace=0.25)
104fig.add_subplot(gs[0, 0])
105fig.add_subplot(gs[0, 1])
106fig.add_subplot(gs[1, 0])
107fig.add_subplot(gs[1, 1])
110fig.suptitle(
r"Flux function contours of meridional plane magnetic field with dipole tilt $\Phi="+str(int(tilt_angle_phi))+
"$, $\Theta="+str(int(tilt_angle_theta))+
"$ with IMF=("+str(BGB[0])+
","+str(BGB[1])+
","+str(BGB[2])+
")", fontsize=fontsize)
118x = np.linspace(xmin,xmax,num=nx)
119z = np.linspace(zmin,zmax,num=nz)
120BX = np.zeros([nx,1,nz])
121BZ = np.zeros([nx,1,nz])
123divB = np.zeros([nx,1,nz])
125[Xmesh,Zmesh] = scipy.meshgrid(x,z)
127dxdydz=[x[1]-x[0],0,z[1]-z[0]]
132for i
in range(len(x)):
133 for j
in range(len(z)):
134 BX[i,0,j] = dip.get_old(x[i]*RE,0,z[j]*RE,0,0,0) +BGB[0]
135 BZ[i,0,j] = dip.get_old(x[i]*RE,0,z[j]*RE,0,2,0) +BGB[2]
136 divB[i,0,j] = dip.get_old(x[i]*RE,0,z[j]*RE,1,0,0)
137 divB[i,0,j] += dip.get_old(x[i]*RE,0,z[j]*RE,1,2,2)
138print(np.sum(divB),np.amin(divB),np.amax(divB))
139ax.pcolormesh(Xmesh,Zmesh,divB[:,0,:])
140flux_function =
ffc(BX,
None,BZ,dxdydz)
141fluxcont = ax.contour(Xmesh,Zmesh,flux_function[:,0,:].T,flux_levels,colors=
'k',linestyles=
'solid',linewidths=0.5)
142ax.text(0.2,0.08,
"Regular dipole",transform=ax.transAxes, bbox=dict(facecolor=
'white', alpha=0.7), fontsize=fontsize)
146for i
in range(len(x)):
147 for j
in range(len(z)):
148 BX[i,0,j] = dip.getX(x[i]*RE,0,z[j]*RE,0,0,0) +BGB[0]
149 BZ[i,0,j] = dip.getX(x[i]*RE,0,z[j]*RE,0,2,0) +BGB[2]
150 divB[i,0,j] = dip.getX(x[i]*RE,0,z[j]*RE,1,0,0)
151 divB[i,0,j] += dip.getX(x[i]*RE,0,z[j]*RE,1,2,2)
152print(np.sum(divB),np.amin(divB),np.amax(divB))
153ax.pcolormesh(Xmesh,Zmesh,divB[:,0,:])
154flux_function =
ffc(BX,
None,BZ,dxdydz)
155fluxcont = ax.contour(Xmesh,Zmesh,flux_function[:,0,:].T,flux_levels,colors=
'k',linestyles=
'solid',linewidths=0.5)
156ax.text(0.2,0.08,
"Vector potential (X)",transform=ax.transAxes, bbox=dict(facecolor=
'white', alpha=0.7), fontsize=fontsize)
174for i
in range(len(x)):
175 for j
in range(len(z)):
176 BX[i,0,j] = dip.get_old(x[i]*RE,0,z[j]*RE,0,0,0)
177 BZ[i,0,j] = dip.get_old(x[i]*RE,0,z[j]*RE,0,2,0)
178 BX[i,0,j] += mdip.get_old(x[i]*RE,0,z[j]*RE,0,0,0) +BGB[0]
179 BZ[i,0,j] += mdip.get_old(x[i]*RE,0,z[j]*RE,0,2,0) +BGB[2]
181 divB[i,0,j] = dip.get_old(x[i]*RE,0,z[j]*RE,1,0,0)
182 divB[i,0,j] += dip.get_old(x[i]*RE,0,z[j]*RE,1,2,2)
183 divB[i,0,j] += mdip.get_old(x[i]*RE,0,z[j]*RE,1,0,0)
184 divB[i,0,j] += mdip.get_old(x[i]*RE,0,z[j]*RE,1,2,2)
185print(np.sum(divB),np.amin(divB),np.amax(divB))
186ax.pcolormesh(Xmesh,Zmesh,divB[:,0,:])
187flux_function =
ffc(BX,
None,BZ,dxdydz)
188fluxcont = ax.contour(Xmesh,Zmesh,flux_function[:,0,:].T,flux_levels,colors=
'k',linestyles=
'solid',linewidths=0.5)
189ax.text(0.2,0.08,
"Regular dipole + mirror",transform=ax.transAxes, bbox=dict(facecolor=
'white', alpha=0.7), fontsize=fontsize)
191if tilt_angle_phi<epsilon:
194 for i
in range(len(x)):
195 for j
in range(len(z)):
196 BX[i,0,j] = dip.get_ldp(x[i]*RE,0,z[j]*RE,0,0,0)
197 BZ[i,0,j] = dip.get_ldp(x[i]*RE,0,z[j]*RE,0,2,0)
198 BX[i,0,j] += mdip.get_ldp(x[i]*RE,0,z[j]*RE,0,0,0) +BGB[0]
199 BZ[i,0,j] += mdip.get_ldp(x[i]*RE,0,z[j]*RE,0,2,0) +BGB[2]
201 divB[i,0,j] = dip.get_ldp(x[i]*RE,0,z[j]*RE,1,0,0)
202 divB[i,0,j] += dip.get_ldp(x[i]*RE,0,z[j]*RE,1,2,2)
203 divB[i,0,j] += mdip.get_ldp(x[i]*RE,0,z[j]*RE,1,0,0)
204 divB[i,0,j] += mdip.get_ldp(x[i]*RE,0,z[j]*RE,1,2,2)
205 print(np.sum(divB),np.amin(divB),np.amax(divB))
206 ax.pcolormesh(Xmesh,Zmesh,divB[:,0,:])
207 flux_function =
ffc(BX,
None,BZ,dxdydz)
208 fluxcont = ax.contour(Xmesh,Zmesh,flux_function[:,0,:].T,flux_levels,colors=
'k',linestyles=
'solid',linewidths=0.5)
209 ax.text(0.2,0.08,
"Line dipole + mirror",transform=ax.transAxes, bbox=dict(facecolor=
'white', alpha=0.7), fontsize=fontsize)
211fig.savefig(outfilename)