Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
vectorpotentialdipole_streamlines2.py
Go to the documentation of this file.
1#!/usr/bin/env python import matplotlib.pyplot as plt
2
3# /*
4# * This file is part of Vlasiator.
5# * Copyright 2010-2016 Finnish Meteorological Institute
6# * Copyright 2017-2019 University of Helsinki
7# *
8# * For details of usage, see the COPYING file and read the "Rules of the Road"
9# * at http://www.physics.helsinki.fi/vlasiator/
10# *
11# * This program is free software; you can redistribute it and/or modify
12# * it under the terms of the GNU General Public License as published by
13# * the Free Software Foundation; either version 2 of the License, or
14# * (at your option) any later version.
15# *
16# * This program is distributed in the hope that it will be useful,
17# * but WITHOUT ANY WARRANTY; without even the implied warranty of
18# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19# * GNU General Public License for more details.
20# *
21# * You should have received a copy of the GNU General Public License along
22# * with this program; if not, write to the Free Software Foundation, Inc.,
23# * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24# */
25import numpy as np
26import math
27import sys,os
28import pytools as pt
29import matplotlib.pyplot as plt
30import matplotlib as mpl
31import scipy
32import fieldmodels
33
34''' Testing routine for different dipole formulations
35
36 Plots streamlines of magnetic field in the meridional x-z-plane for four different models
37
38'''
39
40if len(sys.argv)!=1:
41 testset = int(sys.argv[1])
42else:
43 testset = 0
44
45
46plt.switch_backend('Agg')
47print(mpl.__version__)
48outfilename = "./vecpotdip_verify_streamlines2_"+str(testset)+".png"
49
50RE=6371000.
51epsilon=1.e-15
52
53if testset==0:
54 tilt_angle_phi = 0.
55 tilt_angle_theta = 0.
56 BGB=[0,0,0]
57elif testset==1:
58 tilt_angle_phi = 10.
59 tilt_angle_theta = 0.
60 BGB=[0,0,0]
61elif testset==2:
62 tilt_angle_phi = 0.
63 tilt_angle_theta = 0.
64 BGB=[0,0,-5.e-9]
65elif testset==3:
66 tilt_angle_phi = 10.
67 tilt_angle_theta = 45.
68 BGB=[0,0,0]
69elif testset==3:
70 tilt_angle_phi = 0.
71 tilt_angle_theta = 0.
72 BGB=[2.236e-9,0,-2.236e-9]
73elif testset==4:
74 tilt_angle_phi = 10.
75 tilt_angle_theta = 40.
76 BGB=[2.236e-9,0,-2.236e-9]
77else: # Same as 0
78 print("Default")
79 tilt_angle_phi = 0.
80 tilt_angle_theta = 0.
81 BGB=[0,0,0]
82
83fontsize=20
84
85#fieldmodels.dipole.set_dipole(centerx, centery, centerz, tilt_phi, tilt_theta, mult=1.0, radius_f=None, radius_z=None):
86dip = fieldmodels.dipole(0,0,0,tilt_angle_phi,tilt_angle_theta)
87mdip = fieldmodels.dipole(80*RE,0,0,tilt_angle_phi,180.-tilt_angle_theta)
88
89# IMF scaling to inflow boundary
90imfpot = fieldmodels.IMFpotential(radius_z=10, radius_f=40, IMF=BGB)
91
92# Create figure
93fig = plt.figure()
94fig.set_size_inches(20,20)
95
96
97gs = mpl.gridspec.GridSpec(2, 2, wspace=0.25, hspace=0.25)
98fig.add_subplot(gs[0, 0])
99fig.add_subplot(gs[0, 1])
100fig.add_subplot(gs[1, 0])
101fig.add_subplot(gs[1, 1])
102axes = fig.get_axes()
103
104fig.suptitle(r"Streamlines 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)
105
106nx = 200
107nz = 200
108xmin, xmax = (-59,41)
109zmin, zmax = (-50,50)
110
111x = np.linspace(xmin,xmax,num=nx)
112z = np.linspace(zmin,zmax,num=nz)
113BX = np.zeros([nx,nz])
114BZ = np.zeros([nx,nz])
115
116[Xmesh,Zmesh] = scipy.meshgrid(x,z)
117
118# ax = axes[0]
119# print("0")
120# for i in range(len(x)):
121# for j in range(len(z)):
122# BX[j,i] = dip.get(x[i]*RE,0,z[j]*RE,0,0,0) +BGB[0]
123# BZ[j,i] = dip.get(x[i]*RE,0,z[j]*RE,0,2,0) +BGB[2]
124# ax.streamplot(Xmesh,Zmesh,BX,BZ,linewidth=1, density=5, color='k')
125# ax.text(0.2,0.08,"Vector potential",transform=ax.transAxes, bbox=dict(facecolor='white', alpha=0.7), fontsize=fontsize)
126
127ax = axes[0]
128print("0")
129for i in range(len(x)):
130 for j in range(len(z)):
131 BX[j,i] = dip.get_old(x[i]*RE,0,z[j]*RE,0,0,0) +BGB[0]
132 BZ[j,i] = dip.get_old(x[i]*RE,0,z[j]*RE,0,2,0) +BGB[2]
133ax.streamplot(Xmesh,Zmesh,BX,BZ,linewidth=1, density=5, color='k')
134ax.text(0.2,0.08,"Regular dipole",transform=ax.transAxes, bbox=dict(facecolor='white', alpha=0.7), fontsize=fontsize)
135
136
137ax = axes[1]
138print("1")
139for i in range(len(x)):
140 for j in range(len(z)):
141 BX[j,i] = dip.getX(x[i]*RE,0,z[j]*RE,0,0,0) +BGB[0]
142 BZ[j,i] = dip.getX(x[i]*RE,0,z[j]*RE,0,2,0) +BGB[2]
143ax.streamplot(Xmesh,Zmesh,BX,BZ,linewidth=1, density=5, color='k')
144ax.text(0.2,0.08,"Vector potential (X)",transform=ax.transAxes, bbox=dict(facecolor='white', alpha=0.7), fontsize=fontsize)
145
146# ax = axes[1]
147# print("1")
148# for i in range(len(x)):
149# for j in range(len(z)):
150# BX[j,i] = dip.getX(x[i]*RE,0,z[j]*RE,0,0,0)
151# BZ[j,i] = dip.getX(x[i]*RE,0,z[j]*RE,0,2,0)
152# BX[j,i] += mdip.getX(x[i]*RE,0,z[j]*RE,0,0,0) +BGB[2]
153# BZ[j,i] += mdip.getX(x[i]*RE,0,z[j]*RE,0,2,0) +BGB[2]
154# ax.streamplot(Xmesh,Zmesh,BX,BZ,linewidth=1, density=5, color='k')
155# ax.text(0.2,0.08,"Vector potential + mirror (X)",transform=ax.transAxes, bbox=dict(facecolor='white', alpha=0.7), fontsize=fontsize)
156
157ax = axes[2]
158print("2")
159for i in range(len(x)):
160 for j in range(len(z)):
161 BX[j,i] = dip.get_old(x[i]*RE,0,z[j]*RE,0,0,0)
162 BZ[j,i] = dip.get_old(x[i]*RE,0,z[j]*RE,0,2,0)
163 BX[j,i] += mdip.get_old(x[i]*RE,0,z[j]*RE,0,0,0) +BGB[0]
164 BZ[j,i] += mdip.get_old(x[i]*RE,0,z[j]*RE,0,2,0) +BGB[2]
165ax.streamplot(Xmesh,Zmesh,BX,BZ,linewidth=1, density=5, color='k')
166ax.text(0.2,0.08,"Regular dipole + mirror",transform=ax.transAxes, bbox=dict(facecolor='white', alpha=0.7), fontsize=fontsize)
167
168# if tilt_angle_phi<epsilon:
169# ax = axes[3]
170# print("3")
171# for i in range(len(x)):
172# for j in range(len(z)):
173# BX[j,i] = dip.get_ldp(x[i]*RE,0,z[j]*RE,0,0,0)
174# BZ[j,i] = dip.get_ldp(x[i]*RE,0,z[j]*RE,0,2,0)
175# BX[j,i] += mdip.get_ldp(x[i]*RE,0,z[j]*RE,0,0,0) +BGB[0]
176# BZ[j,i] += mdip.get_ldp(x[i]*RE,0,z[j]*RE,0,2,0) +BGB[2]
177# ax.streamplot(Xmesh,Zmesh,BX,BZ,linewidth=1, density=5, color='k')
178# ax.text(0.2,0.08,"Line dipole + mirror",transform=ax.transAxes, bbox=dict(facecolor='white', alpha=0.7), fontsize=fontsize)
179
180ax = axes[3]
181print("3")
182for i in range(len(x)):
183 for j in range(len(z)):
184 BX[j,i] = dip.getX(x[i]*RE,0,z[j]*RE,0,0,0)
185 BZ[j,i] = dip.getX(x[i]*RE,0,z[j]*RE,0,2,0)
186
187 BX[j,i] += imfpot.get(x[i]*RE,0,z[j]*RE,0,0,0)
188 BZ[j,i] += imfpot.get(x[i]*RE,0,z[j]*RE,0,2,0)
189ax.streamplot(Xmesh,Zmesh,BX,BZ,linewidth=1, density=5, color='k')
190ax.text(0.2,0.08,"Vector potential (X) + IMF potential",transform=ax.transAxes, bbox=dict(facecolor='white', alpha=0.7), fontsize=fontsize)
191
192fig.savefig(outfilename)
193plt.close()