Main Lemma Repository
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

EarthModel.h 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /* This file is part of Lemma, a geophysical modelling and inversion API */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. /**
  6. @file
  7. @author Trevor Irons
  8. @date 03/23/2010
  9. @version $Id: earthmodel.h 198 2014-12-27 06:14:05Z tirons $
  10. **/
  11. #ifndef EARTHMODEL_INC
  12. #define EARTHMODEL_INC
  13. #include "LemmaObject.h"
  14. namespace Lemma {
  15. // ===================================================================
  16. // Class: EarthModel
  17. /// \ingroup LemmaCore
  18. /// \brief abstract class for Earth models
  19. /// \details
  20. // ===================================================================
  21. class EarthModel : public LemmaObject {
  22. // ==================== FRIENDS ===========================
  23. friend std::ostream &operator<<(std::ostream &stream,
  24. const EarthModel &ob);
  25. public:
  26. // ==================== LIFECYCLE =======================
  27. /// Default destructor
  28. ~EarthModel ();
  29. /** YAML Serializing method
  30. */
  31. YAML::Node Serialize() const;
  32. //static LayeredEarth* DeSerialize(const YAML::Node& node);
  33. // ==================== OPERATORS =======================
  34. // ==================== OPERATIONS =======================
  35. // ==================== ACCESS =======================
  36. /** Sets the earth's magnetic field, in Tesla
  37. @param[in] bfield contains the x,y, and z components of
  38. the field. EarthModel::Inc, EarthModel::Dec, and
  39. EarthModel::BMag are computed:
  40. \f{eqnarray*}{ \mathrm{Inc} = &
  41. \cos^{-1}( \mathbf{B} \cdot \hat{\mathbf{z}} / B )
  42. \\ \mathrm{Dec} =& \cos^{-1}
  43. (\mathbf{B} \cdot \hat{\mathbf{x}} / B )
  44. \\ \mathrm{Mag} =& \Vert \mathbf{B} \Vert \f}
  45. @param[in] unit specifies the units of bfield.
  46. */
  47. void SetMagneticFieldComponents(const Vector3r &bfield,
  48. const MAGUNITS &unit);
  49. /** Sets the magnetic field using inclination, declination,
  50. and magnitude, units of Tesla
  51. @param[in] inc is the field's inclination
  52. @param[in] dec is the field's declination
  53. @param[in] Mag is the field's magnitude
  54. @param[in] unit specifies the the units used.
  55. The components are set according to
  56. \f{eqnarray*} { B_x =& B \cos(inc (\pi/180)) \cos(dec (\pi/180))
  57. \\ B_y =& B \cos(inc (\pi/180)) \sin(dec (\pi/180))
  58. \\ B_z =& B \sin(inc (\pi/180))
  59. \f}
  60. */
  61. void SetMagneticFieldIncDecMag(const Real& inc, const Real&dec,
  62. const Real& Mag, const MAGUNITS &unit);
  63. // ==================== INQUIRY =======================
  64. /** @return the magnetic field of the earth, in T
  65. */
  66. Vector3r GetMagneticField( );
  67. /** @return the magnetic field of the earth, in Gauss
  68. */
  69. Vector3r GetMagneticFieldInGauss( );
  70. /** @return the magnetic field unit vector of the earth
  71. */
  72. Vector3r GetMagneticFieldUnitVector( );
  73. /** @return the magnitude of the magnetic field (in T)
  74. * \f$ \Vert \mathbf{B}_0 \Vert \f$
  75. */
  76. Real GetMagneticFieldMagnitude();
  77. /** @return the magnitude of the magnetic field
  78. * \f$ \Vert \mathbf{B}_0 \Vert \f$ in Gauss units
  79. */
  80. Real GetMagneticFieldMagnitudeInGauss( );
  81. /** @return the name of the underlying class, similiar to Python's
  82. type
  83. */
  84. virtual inline std::string GetName() const;
  85. protected:
  86. // ==================== LIFECYCLE =======================
  87. /// Default protected constructor.
  88. EarthModel ( const ctor_key& );
  89. /** Deserialize constructor */
  90. EarthModel (const YAML::Node& node, const ctor_key&);
  91. // ==================== DATA MEMBERS =========================
  92. private:
  93. EarthModel(const EarthModel& ) = delete;
  94. /** ASCII string representation of the class name */
  95. static constexpr auto CName = "EarthModel";
  96. /// Magnetic field, in units of nT
  97. Vector3r BField;
  98. /// Magnetic field unit vector \f$ \hat{\mathbf{B}_0} \f$
  99. Vector3r BFieldUnit;
  100. /// Inclination of the magnetic field
  101. Real BInc;
  102. /// Declination of the magnetic field
  103. Real BDec;
  104. /// Declination of the magnetic field
  105. Real BMag;
  106. }; // ----- end of class EarthModel -----
  107. //////////////////////////////////////////////////////////////
  108. // Error Classes
  109. /** If the Earth class is NULL valued, throw this
  110. */
  111. class NullEarth : public std::runtime_error {
  112. /** Thrown when an Earth pointer is NULL
  113. */
  114. public: NullEarth ();
  115. };
  116. } // ----- end of Lemma name -----
  117. #endif // ----- #ifndef EARTHMODEL_INC -----