Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
dipole.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 "dipole.hpp"
29#include "../common.h"
30
31//tilt_angle is agains the z axis in the x-z plane. In radians*/
32void Dipole::initialize(const double moment,const double center_x, const double center_y, const double center_z, const double tilt_angle=0){
33 this->initialized = true;
34 q[0]=-sin(tilt_angle)*moment;
35 q[1]=0.0;
36 q[2]=-cos(tilt_angle)*moment;
37 center[0]=center_x;
38 center[1]=center_y;
39 center[2]=center_z;
40}
41
42
43
44double Dipole::operator()( double x, double y, double z, coordinate component, unsigned int derivative, coordinate dcomponent) const {
45 const double minimumR=1e-3*physicalconstants::R_E; //The dipole field is defined to be outside of Earth, and units are in meters
46 if(this->initialized==false) {
47 return 0.0;
48 }
49 double r[3];
50
51 r[0]= x-center[0];
52 r[1]= y-center[1];
53 r[2]= z-center[2];
54
55 double r2 = r[0]*r[0]+r[1]*r[1]+r[2]*r[2];
56
57 if(r2<minimumR*minimumR) {
58 // r2=minimumR*minimumR;
59 return 0.0; //set zero field inside dipole
60 }
61
62 const double r5 = (r2*r2*sqrt(r2));
63 const double rdotq=q[0]*r[0] + q[1]*r[1] +q[2]*r[2];
64
65 const double B=( 3*r[component]*rdotq-q[component]*r2)/r5;
66
67 if(derivative == 0) {
68 //Value of B
69 return B;
70 } else if(derivative == 1) {
71 //first derivatives
72 unsigned int sameComponent;
73 if(dcomponent==component) {
74 sameComponent=1;
75 } else {
76 sameComponent=0;
77 }
78
79 return -5*B*r[dcomponent]/r2+
80 (3*q[dcomponent]*r[component] -
81 2*q[component]*r[dcomponent] +
82 3*rdotq*sameComponent)/r5;
83 }
84
85 return 0; // dummy, but prevents gcc from yelling
86}
87
88
89
90
91
92
sqrt(1.0+vA *vA/(c *c))) % Ion-acoustic wave cS
double operator()(double x, double y, double z, coordinate component, unsigned int derivative=0, coordinate dcomponent=X) const
Definition dipole.cpp:44
void initialize(const double moment, const double center_x, const double center_y, const double center_z, const double tilt_angle)
Definition dipole.cpp:32
bool initialized
Definition dipole.hpp:34
double q[3]
Definition dipole.hpp:35
double center[3]
Definition dipole.hpp:36
coordinate
Definition functions.hpp:28
const Real R_E
Definition common.h:575