Lemma is an Electromagnetics API
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

EarthModel.cpp 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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.cpp 210 2015-02-25 02:57:03Z tirons $
  10. **/
  11. #include "EarthModel.h"
  12. namespace Lemma {
  13. std::ostream &operator << (std::ostream &stream, const EarthModel &ob) {
  14. stream << ob.Serialize() << "\n";
  15. return stream;
  16. }
  17. // ==================== LIFECYCLE =======================
  18. EarthModel::EarthModel( const ctor_key& key ) : LemmaObject( key ),
  19. BField(0,0,0), BFieldUnit(0,0,0), BInc(0), BDec(0), BMag(0) {
  20. }
  21. EarthModel::EarthModel(const YAML::Node& node, const ctor_key& key) : LemmaObject(node, key) {
  22. BInc = node["BInc"].as<double>();
  23. BDec = node["BDec"].as<double>();
  24. BMag = node["BMag"].as<double>();
  25. BField = node["BField"].as<Vector3r>();
  26. SetMagneticFieldIncDecMag(BInc, BDec, BMag, TESLA);
  27. }
  28. YAML::Node EarthModel::Serialize() const {
  29. YAML::Node node = LemmaObject::Serialize();
  30. node.SetTag( this->GetName() );
  31. node["BField"] = BField;
  32. node["BInc"] = BInc;
  33. node["BDec"] = BDec;
  34. node["BMag"] = BMag;
  35. return node;
  36. }
  37. EarthModel::~EarthModel() {
  38. }
  39. // ==================== ACCESS ===================================
  40. //--------------------------------------------------------------------------------------
  41. // Class: EarthModel
  42. // Method: GetName
  43. // Description: Class identifier
  44. //--------------------------------------------------------------------------------------
  45. inline std::string EarthModel::GetName ( ) const {
  46. return CName;
  47. } // ----- end of method EarthModel::get_GetName -----
  48. void EarthModel::SetMagneticFieldComponents(const Vector3r &bfield,
  49. const MAGUNITS &unit) {
  50. this->BField = bfield;
  51. switch (unit) {
  52. case TESLA:
  53. break;
  54. case NANOTESLA:
  55. BField *= 1e-9;
  56. break;
  57. case GAUSS:
  58. BField *= 1e-4;
  59. break;
  60. default:
  61. throw "MAGUNITS UNDEFINED\n";
  62. }
  63. BMag = bfield.norm( );
  64. BInc = std::acos (bfield.dot(Vector3r(0,0,1)) / BMag) ;
  65. BDec = std::acos (bfield.dot(Vector3r(1,0,0)) / BMag) ;
  66. BFieldUnit = BField / BField.norm();
  67. }
  68. void EarthModel::SetMagneticFieldIncDecMag(const Real &inc,
  69. const Real &dec, const Real &mag, const MAGUNITS &unit) {
  70. BMag = mag;
  71. BInc = inc;
  72. BDec = dec;
  73. switch (unit) {
  74. case TESLA:
  75. break;
  76. case NANOTESLA:
  77. BMag *= 1e-9;
  78. break;
  79. case GAUSS:
  80. BMag *= 1e-4;
  81. break;
  82. default:
  83. throw "MAGUNITS UNDEFINED\n";
  84. }
  85. BField(0) = BMag * cos(BInc*(PI/180.)) * cos(BDec*(PI/180.));
  86. BField(1) = BMag * cos(BInc*(PI/180.)) * sin(BDec*(PI/180.));
  87. BField(2) = BMag * sin(BInc*(PI/180.)) ;
  88. BFieldUnit = BField / BField.norm();
  89. }
  90. // ==================== INQUIRY =======================
  91. Vector3r EarthModel::GetMagneticField( ) {
  92. return this->BField;
  93. }
  94. Vector3r EarthModel::GetMagneticFieldInGauss( ) {
  95. return this->BField*1e4;
  96. }
  97. Vector3r EarthModel::GetMagneticFieldUnitVector() {
  98. return BField/BField.norm();
  99. }
  100. Real EarthModel::GetMagneticFieldMagnitude() {
  101. return this->BMag;
  102. }
  103. Real EarthModel::GetMagneticFieldMagnitudeInGauss() {
  104. return this->BMag*1e4;
  105. }
  106. ////////////////////////////////////////////////////////
  107. // Error Classes
  108. NullEarth::NullEarth() :
  109. runtime_error( "NULL VALUED LAYERED EARTH MODEL") {}
  110. } // ----- end of Lemma name -----