Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
linedipole.cpp
Go to the documentation of this file.
1/*
2 * This file is part of Vlasiator.
3 * Copyright 2010-2016 Finnish Meteorological Institute
4 *
5 * For details of usage, see the COPYING file and read the "Rules of the Road"
6 * at http://www.physics.helsinki.fi/vlasiator/
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22/*
23Background magnetic field class of Vlasiator.
24*/
25
26#include <stdlib.h>
27#include <math.h>
28#include "linedipole.hpp"
29#include "../common.h"
30
31
32void LineDipole::initialize(const double moment,const double center_x, const double center_y, const double center_z){
33 this->initialized = true;
34 q[0]=0.0;
35 q[1]=0.0;
36 q[2]=moment;
37 center[0]=center_x;
38 center[1]=center_y;
39 center[2]=center_z;
40}
41
42double LineDipole::operator()( double x, double y, double z, coordinate component, unsigned int derivative, coordinate dcomponent) const {
43 const double minimumR=1e-3*physicalconstants::R_E; //The dipole field is defined to be outside of Earth, and units are in meters
44 if(this->initialized==false) {
45 return 0.0;
46 }
47 double r[3];
48
49 r[0]= x-center[0];
50 r[1]= y-center[1];
51 r[2]= z-center[2];
52
53 double r2 = r[0]*r[0]+r[2]*r[2]; // r[1] not necessary in this case, removed to enable proper cylindrical ionosphere (ionosphere.geometry = 3)
54
55 if(r2<minimumR*minimumR) {
56 // r2=minimumR*minimumR;
57 return 0.0; //set zero field inside dipole
58 }
59
60 const double r6 = (r2*r2*r2);
61 // const double rdotq=q[0]*r[0] + q[1]*r[1] +q[2]*r[2];
62 const double D = -q[2];
63
64 const double DerivativeSameComponent=D*( 2*r[2]*(r[2]*r[2]-3*r[0]*r[0]))/r6;
65 const double DerivativeDiffComponent=D*( 2*r[0]*(r[0]*r[0]-3*r[2]*r[2]))/r6;
66 //const double B;
67 //const double der;
68
69 switch (derivative) {
70 case 0:
71 switch (component) {
72 case 0:
73 return D*2*r[0]*r[2]/(r2*r2);
74 case 2:
75 return D*(r[2]*r[2]-r[0]*r[0])/(r2*r2);
76 default:
77 return 0;
78 }
79 case 1:
80 //first derivatives
81 if(dcomponent == 1 || component == 1) {
82 return 0;
83 } else if(dcomponent == component) {
84 switch (component) {
85 case 0:
86 return DerivativeSameComponent;
87 case 2:
88 return -DerivativeSameComponent;
89 default:
90 return 0; // Redundant for warning
91 }
92 } else {
93 return DerivativeDiffComponent;
94 }
95 default:
96 return 0; // dummy, but prevents gcc from yelling
97 }
98}
99
100
101
102
103
104
double q[3]
void initialize(const double moment, const double center_x, const double center_y, const double center_z)
double center[3]
bool initialized
double operator()(double x, double y, double z, coordinate component, unsigned int derivative=0, coordinate dcomponent=X) const
coordinate
Definition functions.hpp:28
const Real R_E
Definition common.h:575