GeographicLib  1.49
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  * https://geographiclib.sourceforge.io/
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
110  * (nanotesla).
111  * @param[out] Bz the vertical (up) component of the magnetic field
112  * (nanotesla).
113  **********************************************************************/
114  void operator()(real lon, real& Bx, real& By, real& Bz) const {
115  real dummy;
116  Field(lon, false, Bx, By, Bz, dummy, dummy, dummy);
117  }
118 
119  /**
120  * Evaluate the components of the geomagnetic field and their time
121  * derivatives at a particular longitude.
122  *
123  * @param[in] lon longitude of the point (degrees).
124  * @param[out] Bx the easterly component of the magnetic field (nanotesla).
125  * @param[out] By the northerly component of the magnetic field
126  * (nanotesla).
127  * @param[out] Bz the vertical (up) component of the magnetic field
128  * (nanotesla).
129  * @param[out] Bxt the rate of change of \e Bx (nT/yr).
130  * @param[out] Byt the rate of change of \e By (nT/yr).
131  * @param[out] Bzt the rate of change of \e Bz (nT/yr).
132  **********************************************************************/
133  void operator()(real lon, real& Bx, real& By, real& Bz,
134  real& Bxt, real& Byt, real& Bzt) const {
135  Field(lon, true, Bx, By, Bz, Bxt, Byt, Bzt);
136  }
137  ///@}
138 
139  /** \name Inspector functions
140  **********************************************************************/
141  ///@{
142  /**
143  * @return true if the object has been initialized.
144  **********************************************************************/
145  bool Init() const { return _a > 0; }
146  /**
147  * @return \e a the equatorial radius of the ellipsoid (meters). This is
148  * the value inherited from the MagneticModel object used in the
149  * constructor.
150  **********************************************************************/
152  { return Init() ? _a : Math::NaN(); }
153  /**
154  * @return \e f the flattening of the ellipsoid. This is the value
155  * inherited from the MagneticModel object used in the constructor.
156  **********************************************************************/
158  { return Init() ? _f : Math::NaN(); }
159  /**
160  * @return the latitude of the circle (degrees).
161  **********************************************************************/
163  { return Init() ? _lat : Math::NaN(); }
164  /**
165  * @return the height of the circle (meters).
166  **********************************************************************/
168  { return Init() ? _h : Math::NaN(); }
169  /**
170  * @return the time (fractional years).
171  **********************************************************************/
172  Math::real Time() const
173  { return Init() ? _t : Math::NaN(); }
174 
175  ///@}
176  };
177 
178 } // namespace GeographicLib
179 
180 #endif // GEOGRAPHICLIB_MAGNETICCIRCLE_HPP
static T NaN()
Definition: Math.hpp:830
#define GEOGRAPHICLIB_EXPORT
Definition: Constants.hpp:91
GeographicLib::Math::real real
Definition: GeodSolve.cpp:31
static T LatFix(T x)
Definition: Math.hpp:467
Model of the earth's magnetic field.
Geomagnetic field on a circle of latitude.
void operator()(real lon, real &Bx, real &By, real &Bz, real &Bxt, real &Byt, real &Bzt) const
Namespace for GeographicLib.
Definition: Accumulator.cpp:12
Header for GeographicLib::CircularEngine class.
void operator()(real lon, real &Bx, real &By, real &Bz) const
Spherical harmonic sums for a circle.
Header for GeographicLib::Constants class.