GeographicLib  1.44
MagneticCircle.hpp
Go to the documentation of this file.
1 /**
2  * \file MagneticCircle.hpp
3  * \brief Header for GeographicLib::MagneticCircle class
4  *
5  * Copyright (c) Charles Karney (2011-2015) <charles@karney.com> and licensed
6  * under the MIT/X11 License. For more information, see
7  * http://geographiclib.sourceforge.net/
8  **********************************************************************/
9 
10 #if !defined(GEOGRAPHICLIB_MAGNETICCIRCLE_HPP)
11 #define GEOGRAPHICLIB_MAGNETICCIRCLE_HPP 1
12 
13 #include <vector>
16 
17 namespace GeographicLib {
18 
19  /**
20  * \brief Geomagnetic field on a circle of latitude
21  *
22  * Evaluate the earth's magnetic field on a circle of constant height and
23  * latitude. This uses a CircularEngine to pre-evaluate the inner sum of the
24  * spherical harmonic sum, allowing the values of the field at several
25  * different longitudes to be evaluated rapidly.
26  *
27  * Use MagneticModel::Circle to create a MagneticCircle object. (The
28  * constructor for this class is private.)
29  *
30  * Example of use:
31  * \include example-MagneticCircle.cpp
32  *
33  * <a href="MagneticField.1.html">MagneticField</a> is a command-line utility
34  * providing access to the functionality of MagneticModel and MagneticCircle.
35  **********************************************************************/
36 
38  private:
39  typedef Math::real real;
40 
41  real _a, _f, _lat, _h, _t, _cphi, _sphi, _t1, _dt0;
42  bool _interpolate, _constterm;
43  CircularEngine _circ0, _circ1, _circ2;
44 
45  MagneticCircle(real a, real f, real lat, real h, real t,
46  real cphi, real sphi, real t1, real dt0,
47  bool interpolate,
48  const CircularEngine& circ0, const CircularEngine& circ1)
49  : _a(a)
50  , _f(f)
51  , _lat(Math::LatFix(lat))
52  , _h(h)
53  , _t(t)
54  , _cphi(cphi)
55  , _sphi(sphi)
56  , _t1(t1)
57  , _dt0(dt0)
58  , _interpolate(interpolate)
59  , _constterm(false)
60  , _circ0(circ0)
61  , _circ1(circ1)
62  {}
63 
64  MagneticCircle(real a, real f, real lat, real h, real t,
65  real cphi, real sphi, real t1, real dt0,
66  bool interpolate,
67  const CircularEngine& circ0, const CircularEngine& circ1,
68  const CircularEngine& circ2)
69  : _a(a)
70  , _f(f)
71  , _lat(lat)
72  , _h(h)
73  , _t(t)
74  , _cphi(cphi)
75  , _sphi(sphi)
76  , _t1(t1)
77  , _dt0(dt0)
78  , _interpolate(interpolate)
79  , _constterm(true)
80  , _circ0(circ0)
81  , _circ1(circ1)
82  , _circ2(circ2)
83  {}
84 
85  void Field(real lon, bool diffp,
86  real& Bx, real& By, real& Bz,
87  real& Bxt, real& Byt, real& Bzt) const;
88 
89  friend class MagneticModel; // MagneticModel calls the private constructor
90 
91  public:
92 
93  /**
94  * A default constructor for the normal gravity. This sets up an
95  * uninitialized object which can be later replaced by the
96  * MagneticModel::Circle.
97  **********************************************************************/
98  MagneticCircle() : _a(-1) {}
99 
100  /** \name Compute the magnetic field
101  **********************************************************************/
102  ///@{
103  /**
104  * Evaluate the components of the geomagnetic field at a particular
105  * longitude.
106  *
107  * @param[in] lon longitude of the point (degrees).
108  * @param[out] Bx the easterly component of the magnetic field (nanotesla).
109  * @param[out] By the northerly component of the magnetic field (nanotesla).
110  * @param[out] Bz the vertical (up) component of the magnetic field
111  * (nanotesla).
112  **********************************************************************/
113  void operator()(real lon, real& Bx, real& By, real& Bz) const {
114  real dummy;
115  Field(lon, false, Bx, By, Bz, dummy, dummy, dummy);
116  }
117 
118  /**
119  * Evaluate the components of the geomagnetic field and their time
120  * derivatives at a particular longitude.
121  *
122  * @param[in] lon longitude of the point (degrees).
123  * @param[out] Bx the easterly component of the magnetic field (nanotesla).
124  * @param[out] By the northerly component of the magnetic field (nanotesla).
125  * @param[out] Bz the vertical (up) component of the magnetic field
126  * (nanotesla).
127  * @param[out] Bxt the rate of change of \e Bx (nT/yr).
128  * @param[out] Byt the rate of change of \e By (nT/yr).
129  * @param[out] Bzt the rate of change of \e Bz (nT/yr).
130  **********************************************************************/
131  void operator()(real lon, real& Bx, real& By, real& Bz,
132  real& Bxt, real& Byt, real& Bzt) const {
133  Field(lon, true, Bx, By, Bz, Bxt, Byt, Bzt);
134  }
135  ///@}
136 
137  /** \name Inspector functions
138  **********************************************************************/
139  ///@{
140  /**
141  * @return true if the object has been initialized.
142  **********************************************************************/
143  bool Init() const { return _a > 0; }
144  /**
145  * @return \e a the equatorial radius of the ellipsoid (meters). This is
146  * the value inherited from the MagneticModel object used in the
147  * constructor.
148  **********************************************************************/
150  { return Init() ? _a : Math::NaN(); }
151  /**
152  * @return \e f the flattening of the ellipsoid. This is the value
153  * inherited from the MagneticModel object used in the constructor.
154  **********************************************************************/
156  { return Init() ? _f : Math::NaN(); }
157  /**
158  * @return the latitude of the circle (degrees).
159  **********************************************************************/
161  { return Init() ? _lat : Math::NaN(); }
162  /**
163  * @return the height of the circle (meters).
164  **********************************************************************/
166  { return Init() ? _h : Math::NaN(); }
167  /**
168  * @return the time (fractional years).
169  **********************************************************************/
170  Math::real Time() const
171  { return Init() ? _t : Math::NaN(); }
172 
173  ///@}
174  };
175 
176 } // namespace GeographicLib
177 
178 #endif // GEOGRAPHICLIB_MAGNETICCIRCLE_HPP
static T NaN()
Definition: Math.hpp:783
#define GEOGRAPHICLIB_EXPORT
Definition: Constants.hpp:90
GeographicLib::Math::real real
Definition: GeodSolve.cpp:32
static T LatFix(T x)
Definition: Math.hpp:482
void operator()(real lon, real &Bx, real &By, real &Bz) const
Model of the earth's magnetic field.
Geomagnetic field on a circle of latitude.
Math::real MajorRadius() const
Namespace for GeographicLib.
Definition: Accumulator.cpp:12
Header for GeographicLib::CircularEngine class.
Spherical harmonic sums for a circle.
void operator()(real lon, real &Bx, real &By, real &Bz, real &Bxt, real &Byt, real &Bzt) const
Header for GeographicLib::Constants class.
Math::real Flattening() const