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

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