Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
vectorpotentialdipole_streamlines.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_streamlines_"+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]
69else: # Same as 0
70 print("Default")
71 tilt_angle_phi = 0.
72 tilt_angle_theta = 0.
73 BGB=[0,0,0]
74
75fontsize=20
76
77#fieldmodels.dipole.set_dipole(centerx, centery, centerz, tilt_phi, tilt_theta, mult=1.0, radius_f=None, radius_z=None):
78dip = fieldmodels.dipole(0,0,0,tilt_angle_phi,tilt_angle_theta)
79mdip = fieldmodels.dipole(80*RE,0,0,tilt_angle_phi,180.-tilt_angle_theta)
80
81# Create figure
82fig = plt.figure()
83fig.set_size_inches(20,20)
84
85
86gs = mpl.gridspec.GridSpec(2, 2, wspace=0.25, hspace=0.25)
87fig.add_subplot(gs[0, 0])
88fig.add_subplot(gs[0, 1])
89fig.add_subplot(gs[1, 0])
90fig.add_subplot(gs[1, 1])
91axes = fig.get_axes()
92
93fig.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)
94
95nx = 200
96nz = 200
97xmin, xmax = (-59,41)
98zmin, zmax = (-50,50)
99
100x = np.linspace(xmin,xmax,num=nx)
101z = np.linspace(zmin,zmax,num=nz)
102BX = np.zeros([nx,nz])
103BZ = np.zeros([nx,nz])
104
105[Xmesh,Zmesh] = scipy.meshgrid(x,z)
106
107# ax = axes[0]
108# print("0")
109# for i in range(len(x)):
110# for j in range(len(z)):
111# BX[j,i] = dip.get(x[i]*RE,0,z[j]*RE,0,0,0) +BGB[0]
112# BZ[j,i] = dip.get(x[i]*RE,0,z[j]*RE,0,2,0) +BGB[2]
113# ax.streamplot(Xmesh,Zmesh,BX,BZ,linewidth=1, density=5, color='k')
114# ax.text(0.2,0.08,"Vector potential",transform=ax.transAxes, bbox=dict(facecolor='white', alpha=0.7), fontsize=fontsize)
115
116ax = axes[0]
117print("0")
118for i in range(len(x)):
119 for j in range(len(z)):
120 BX[j,i] = dip.get_old(x[i]*RE,0,z[j]*RE,0,0,0) +BGB[0]
121 BZ[j,i] = dip.get_old(x[i]*RE,0,z[j]*RE,0,2,0) +BGB[2]
122ax.streamplot(Xmesh,Zmesh,BX,BZ,linewidth=1, density=5, color='k')
123ax.text(0.2,0.08,"Regular dipole",transform=ax.transAxes, bbox=dict(facecolor='white', alpha=0.7), fontsize=fontsize)
124
125
126ax = axes[1]
127print("1")
128for i in range(len(x)):
129 for j in range(len(z)):
130 BX[j,i] = dip.getX(x[i]*RE,0,z[j]*RE,0,0,0) +BGB[0]
131 BZ[j,i] = dip.getX(x[i]*RE,0,z[j]*RE,0,2,0) +BGB[2]
132ax.streamplot(Xmesh,Zmesh,BX,BZ,linewidth=1, density=5, color='k')
133ax.text(0.2,0.08,"Vector potential (X)",transform=ax.transAxes, bbox=dict(facecolor='white', alpha=0.7), fontsize=fontsize)
134
135# ax = axes[1]
136# print("1")
137# for i in range(len(x)):
138# for j in range(len(z)):
139# BX[j,i] = dip.getX(x[i]*RE,0,z[j]*RE,0,0,0)
140# BZ[j,i] = dip.getX(x[i]*RE,0,z[j]*RE,0,2,0)
141# BX[j,i] += mdip.getX(x[i]*RE,0,z[j]*RE,0,0,0) +BGB[2]
142# BZ[j,i] += mdip.getX(x[i]*RE,0,z[j]*RE,0,2,0) +BGB[2]
143# ax.streamplot(Xmesh,Zmesh,BX,BZ,linewidth=1, density=5, color='k')
144# ax.text(0.2,0.08,"Vector potential + mirror (X)",transform=ax.transAxes, bbox=dict(facecolor='white', alpha=0.7), fontsize=fontsize)
145
146ax = axes[2]
147print("2")
148for i in range(len(x)):
149 for j in range(len(z)):
150 BX[j,i] = dip.get_old(x[i]*RE,0,z[j]*RE,0,0,0)
151 BZ[j,i] = dip.get_old(x[i]*RE,0,z[j]*RE,0,2,0)
152 BX[j,i] += mdip.get_old(x[i]*RE,0,z[j]*RE,0,0,0) +BGB[0]
153 BZ[j,i] += mdip.get_old(x[i]*RE,0,z[j]*RE,0,2,0) +BGB[2]
154ax.streamplot(Xmesh,Zmesh,BX,BZ,linewidth=1, density=5, color='k')
155ax.text(0.2,0.08,"Regular dipole + mirror",transform=ax.transAxes, bbox=dict(facecolor='white', alpha=0.7), fontsize=fontsize)
156
157if tilt_angle_phi<epsilon:
158 ax = axes[3]
159 print("3")
160 for i in range(len(x)):
161 for j in range(len(z)):
162 BX[j,i] = dip.get_ldp(x[i]*RE,0,z[j]*RE,0,0,0)
163 BZ[j,i] = dip.get_ldp(x[i]*RE,0,z[j]*RE,0,2,0)
164 BX[j,i] += mdip.get_ldp(x[i]*RE,0,z[j]*RE,0,0,0) +BGB[0]
165 BZ[j,i] += mdip.get_ldp(x[i]*RE,0,z[j]*RE,0,2,0) +BGB[2]
166 ax.streamplot(Xmesh,Zmesh,BX,BZ,linewidth=1, density=5, color='k')
167 ax.text(0.2,0.08,"Line dipole + mirror",transform=ax.transAxes, bbox=dict(facecolor='white', alpha=0.7), fontsize=fontsize)
168
169fig.savefig(outfilename)
170plt.close()