Lemma is an Electromagnetics API
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

EarthModel.cpp 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. //--------------------------------------------------------------------------------------
  40. // Class: EarthModel
  41. // Method: GetName
  42. // Description: Class identifier
  43. //--------------------------------------------------------------------------------------
  44. inline std::string EarthModel::GetName ( ) const {
  45. return CName;
  46. } // ----- end of method EarthModel::get_GetName -----
  47. void EarthModel::SetMagneticFieldComponents(const Vector3r &bfield,
  48. const MAGUNITS &unit) {
  49. this->BField = bfield;
  50. switch (unit) {
  51. case TESLA:
  52. break;
  53. case NANOTESLA:
  54. BField *= 1e-9;
  55. break;
  56. case GAUSS:
  57. BField *= 1e-4;
  58. break;
  59. default:
  60. throw "MAGUNITS UNDEFINED\n";
  61. }
  62. BMag = bfield.norm( );
  63. BInc = std::acos (bfield.dot(Vector3r(0,0,1)) / BMag) ;
  64. BDec = std::acos (bfield.dot(Vector3r(1,0,0)) / BMag) ;
  65. BFieldUnit = BField.array() / BMag;
  66. }
  67. void EarthModel::SetMagneticFieldIncDecMag(const Real &inc,
  68. const Real &dec, const Real &mag, const MAGUNITS &unit) {
  69. BMag = mag;
  70. BInc = inc;
  71. BDec = dec;
  72. switch (unit) {
  73. case TESLA:
  74. break;
  75. case NANOTESLA:
  76. BMag *= 1e-9;
  77. break;
  78. case GAUSS:
  79. BMag *= 1e-4;
  80. break;
  81. default:
  82. throw "MAGUNITS UNDEFINED\n";
  83. }
  84. BField(0) = BMag * cos(BInc*(PI/180.)) * cos(BDec*(PI/180.));
  85. BField(1) = BMag * cos(BInc*(PI/180.)) * sin(BDec*(PI/180.));
  86. BField(2) = BMag * sin(BInc*(PI/180.)) ;
  87. BFieldUnit = BField.array() / BMag;
  88. }
  89. // ==================== INQUIRY =======================
  90. Vector3r EarthModel::GetMagneticField( ) {
  91. return this->BField;
  92. }
  93. Vector3r EarthModel::GetMagneticFieldInGauss( ) {
  94. return this->BField*1e4;
  95. }
  96. Vector3r EarthModel::GetMagneticFieldUnitVector() {
  97. return this->BFieldUnit;
  98. }
  99. Real EarthModel::GetMagneticFieldMagnitude() {
  100. return this->BMag;
  101. }
  102. Real EarthModel::GetMagneticFieldMagnitudeInGauss() {
  103. return this->BMag*1e4;
  104. }
  105. ////////////////////////////////////////////////////////
  106. // Error Classes
  107. NullEarth::NullEarth() :
  108. runtime_error( "NULL VALUED LAYERED EARTH MODEL") {}
  109. } // ----- end of Lemma name -----