Main Lemma Repository
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.2KB

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