MagneticCircle.hpp 7.5 KB

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