GravityCircle.hpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /**
  2. * \file GravityCircle.hpp
  3. * \brief Header for GeographicLib::GravityCircle class
  4. *
  5. * Copyright (c) Charles Karney (2011-2020) <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_GRAVITYCIRCLE_HPP)
  10. #define GEOGRAPHICLIB_GRAVITYCIRCLE_HPP 1
  11. #include <vector>
  12. #include <GeographicLib/Constants.hpp>
  13. #include <GeographicLib/CircularEngine.hpp>
  14. #include <GeographicLib/GravityModel.hpp>
  15. namespace GeographicLib {
  16. /**
  17. * \brief Gravity on a circle of latitude
  18. *
  19. * Evaluate the earth's gravity field on a circle of constant height and
  20. * latitude. This uses a CircularEngine to pre-evaluate the inner sum of the
  21. * spherical harmonic sum, allowing the values of the field at several
  22. * different longitudes to be evaluated rapidly.
  23. *
  24. * Use GravityModel::Circle to create a GravityCircle object. (The
  25. * constructor for this class is private.)
  26. *
  27. * See \ref gravityparallel for an example of using GravityCircle (together
  28. * with OpenMP) to speed up the computation of geoid heights.
  29. *
  30. * Example of use:
  31. * \include example-GravityCircle.cpp
  32. *
  33. * <a href="Gravity.1.html">Gravity</a> is a command-line utility providing
  34. * access to the functionality of GravityModel and GravityCircle.
  35. **********************************************************************/
  36. class GEOGRAPHICLIB_EXPORT GravityCircle {
  37. private:
  38. typedef Math::real real;
  39. enum mask {
  40. NONE = GravityModel::NONE,
  41. GRAVITY = GravityModel::GRAVITY,
  42. DISTURBANCE = GravityModel::DISTURBANCE,
  43. DISTURBING_POTENTIAL = GravityModel::DISTURBING_POTENTIAL,
  44. GEOID_HEIGHT = GravityModel::GEOID_HEIGHT,
  45. SPHERICAL_ANOMALY = GravityModel::SPHERICAL_ANOMALY,
  46. ALL = GravityModel::ALL,
  47. };
  48. unsigned _caps;
  49. real _a, _f, _lat, _h, _Z, _Px, _invR, _cpsi, _spsi,
  50. _cphi, _sphi, _amodel, _GMmodel, _dzonal0,
  51. _corrmult, _gamma0, _gamma, _frot;
  52. CircularEngine _gravitational, _disturbing, _correction;
  53. GravityCircle(mask caps, real a, real f, real lat, real h,
  54. real Z, real P, real cphi, real sphi,
  55. real amodel, real GMmodel,
  56. real dzonal0, real corrmult,
  57. real gamma0, real gamma, real frot,
  58. const CircularEngine& gravitational,
  59. const CircularEngine& disturbing,
  60. const CircularEngine& correction);
  61. friend class GravityModel; // GravityModel calls the private constructor
  62. Math::real W(real slam, real clam,
  63. real& gX, real& gY, real& gZ) const;
  64. Math::real V(real slam, real clam,
  65. real& gX, real& gY, real& gZ) const;
  66. Math::real InternalT(real slam, real clam,
  67. real& deltaX, real& deltaY, real& deltaZ,
  68. bool gradp, bool correct) const;
  69. public:
  70. /**
  71. * A default constructor for the normal gravity. This sets up an
  72. * uninitialized object which can be later replaced by the
  73. * GravityModel::Circle.
  74. **********************************************************************/
  75. GravityCircle() : _a(-1) {}
  76. /** \name Compute the gravitational field
  77. **********************************************************************/
  78. ///@{
  79. /**
  80. * Evaluate the gravity.
  81. *
  82. * @param[in] lon the geographic longitude (degrees).
  83. * @param[out] gx the easterly component of the acceleration
  84. * (m s<sup>&minus;2</sup>).
  85. * @param[out] gy the northerly component of the acceleration
  86. * (m s<sup>&minus;2</sup>).
  87. * @param[out] gz the upward component of the acceleration
  88. * (m s<sup>&minus;2</sup>); this is usually negative.
  89. * @return \e W the sum of the gravitational and centrifugal potentials
  90. * (m<sup>2</sup> s<sup>&minus;2</sup>).
  91. *
  92. * The function includes the effects of the earth's rotation.
  93. **********************************************************************/
  94. Math::real Gravity(real lon, real& gx, real& gy, real& gz) const;
  95. /**
  96. * Evaluate the gravity disturbance vector.
  97. *
  98. * @param[in] lon the geographic longitude (degrees).
  99. * @param[out] deltax the easterly component of the disturbance vector
  100. * (m s<sup>&minus;2</sup>).
  101. * @param[out] deltay the northerly component of the disturbance vector
  102. * (m s<sup>&minus;2</sup>).
  103. * @param[out] deltaz the upward component of the disturbance vector
  104. * (m s<sup>&minus;2</sup>).
  105. * @return \e T the corresponding disturbing potential
  106. * (m<sup>2</sup> s<sup>&minus;2</sup>).
  107. **********************************************************************/
  108. Math::real Disturbance(real lon, real& deltax, real& deltay, real& deltaz)
  109. const;
  110. /**
  111. * Evaluate the geoid height.
  112. *
  113. * @param[in] lon the geographic longitude (degrees).
  114. * @return \e N the height of the geoid above the reference ellipsoid
  115. * (meters).
  116. *
  117. * Some approximations are made in computing the geoid height so that the
  118. * results of the NGA codes are reproduced accurately. Details are given
  119. * in \ref gravitygeoid.
  120. **********************************************************************/
  121. Math::real GeoidHeight(real lon) const;
  122. /**
  123. * Evaluate the components of the gravity anomaly vector using the
  124. * spherical approximation.
  125. *
  126. * @param[in] lon the geographic longitude (degrees).
  127. * @param[out] Dg01 the gravity anomaly (m s<sup>&minus;2</sup>).
  128. * @param[out] xi the northerly component of the deflection of the vertical
  129. * (degrees).
  130. * @param[out] eta the easterly component of the deflection of the vertical
  131. * (degrees).
  132. *
  133. * The spherical approximation (see Heiskanen and Moritz, Sec 2-14) is used
  134. * so that the results of the NGA codes are reproduced accurately.
  135. * approximations used here. Details are given in \ref gravitygeoid.
  136. **********************************************************************/
  137. void SphericalAnomaly(real lon, real& Dg01, real& xi, real& eta)
  138. const;
  139. /**
  140. * Evaluate the components of the acceleration due to gravity and the
  141. * centrifugal acceleration in geocentric coordinates.
  142. *
  143. * @param[in] lon the geographic longitude (degrees).
  144. * @param[out] gX the \e X component of the acceleration
  145. * (m s<sup>&minus;2</sup>).
  146. * @param[out] gY the \e Y component of the acceleration
  147. * (m s<sup>&minus;2</sup>).
  148. * @param[out] gZ the \e Z component of the acceleration
  149. * (m s<sup>&minus;2</sup>).
  150. * @return \e W = \e V + &Phi; the sum of the gravitational and
  151. * centrifugal potentials (m<sup>2</sup> s<sup>&minus;2</sup>).
  152. **********************************************************************/
  153. Math::real W(real lon, real& gX, real& gY, real& gZ) const {
  154. real slam, clam;
  155. Math::sincosd(lon, slam, clam);
  156. return W(slam, clam, gX, gY, gZ);
  157. }
  158. /**
  159. * Evaluate the components of the acceleration due to gravity in geocentric
  160. * coordinates.
  161. *
  162. * @param[in] lon the geographic longitude (degrees).
  163. * @param[out] GX the \e X component of the acceleration
  164. * (m s<sup>&minus;2</sup>).
  165. * @param[out] GY the \e Y component of the acceleration
  166. * (m s<sup>&minus;2</sup>).
  167. * @param[out] GZ the \e Z component of the acceleration
  168. * (m s<sup>&minus;2</sup>).
  169. * @return \e V = \e W - &Phi; the gravitational potential
  170. * (m<sup>2</sup> s<sup>&minus;2</sup>).
  171. **********************************************************************/
  172. Math::real V(real lon, real& GX, real& GY, real& GZ) const {
  173. real slam, clam;
  174. Math::sincosd(lon, slam, clam);
  175. return V(slam, clam, GX, GY, GZ);
  176. }
  177. /**
  178. * Evaluate the components of the gravity disturbance in geocentric
  179. * coordinates.
  180. *
  181. * @param[in] lon the geographic longitude (degrees).
  182. * @param[out] deltaX the \e X component of the gravity disturbance
  183. * (m s<sup>&minus;2</sup>).
  184. * @param[out] deltaY the \e Y component of the gravity disturbance
  185. * (m s<sup>&minus;2</sup>).
  186. * @param[out] deltaZ the \e Z component of the gravity disturbance
  187. * (m s<sup>&minus;2</sup>).
  188. * @return \e T = \e W - \e U the disturbing potential (also called the
  189. * anomalous potential) (m<sup>2</sup> s<sup>&minus;2</sup>).
  190. **********************************************************************/
  191. Math::real T(real lon, real& deltaX, real& deltaY, real& deltaZ)
  192. const {
  193. real slam, clam;
  194. Math::sincosd(lon, slam, clam);
  195. return InternalT(slam, clam, deltaX, deltaY, deltaZ, true, true);
  196. }
  197. /**
  198. * Evaluate disturbing potential in geocentric coordinates.
  199. *
  200. * @param[in] lon the geographic longitude (degrees).
  201. * @return \e T = \e W - \e U the disturbing potential (also called the
  202. * anomalous potential) (m<sup>2</sup> s<sup>&minus;2</sup>).
  203. **********************************************************************/
  204. Math::real T(real lon) const {
  205. real slam, clam, dummy;
  206. Math::sincosd(lon, slam, clam);
  207. return InternalT(slam, clam, dummy, dummy, dummy, false, true);
  208. }
  209. ///@}
  210. /** \name Inspector functions
  211. **********************************************************************/
  212. ///@{
  213. /**
  214. * @return true if the object has been initialized.
  215. **********************************************************************/
  216. bool Init() const { return _a > 0; }
  217. /**
  218. * @return \e a the equatorial radius of the ellipsoid (meters). This is
  219. * the value inherited from the GravityModel object used in the
  220. * constructor.
  221. **********************************************************************/
  222. Math::real EquatorialRadius() const
  223. { return Init() ? _a : Math::NaN(); }
  224. /**
  225. * @return \e f the flattening of the ellipsoid. This is the value
  226. * inherited from the GravityModel object used in the constructor.
  227. **********************************************************************/
  228. Math::real Flattening() const
  229. { return Init() ? _f : Math::NaN(); }
  230. /**
  231. * @return the latitude of the circle (degrees).
  232. **********************************************************************/
  233. Math::real Latitude() const
  234. { return Init() ? _lat : Math::NaN(); }
  235. /**
  236. * @return the height of the circle (meters).
  237. **********************************************************************/
  238. Math::real Height() const
  239. { return Init() ? _h : Math::NaN(); }
  240. /**
  241. * @return \e caps the computational capabilities that this object was
  242. * constructed with.
  243. **********************************************************************/
  244. unsigned Capabilities() const { return _caps; }
  245. /**
  246. * @param[in] testcaps a set of bitor'ed GravityModel::mask values.
  247. * @return true if the GravityCircle object has all these capabilities.
  248. **********************************************************************/
  249. bool Capabilities(unsigned testcaps) const {
  250. return (_caps & testcaps) == testcaps;
  251. }
  252. /**
  253. * \deprecated An old name for EquatorialRadius().
  254. **********************************************************************/
  255. GEOGRAPHICLIB_DEPRECATED("Use EquatorialRadius()")
  256. Math::real MajorRadius() const { return EquatorialRadius(); }
  257. ///@}
  258. };
  259. } // namespace GeographicLib
  260. #endif // GEOGRAPHICLIB_GRAVITYCIRCLE_HPP