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.

LayeredEarth.cpp 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 06/24/2009
  9. @version $Id: layeredearth.cpp 210 2015-02-25 02:57:03Z tirons $
  10. **/
  11. #include "LayeredEarth.h"
  12. namespace Lemma {
  13. // ==================== FRIENDS ======================
  14. std::ostream &operator << (std::ostream &stream, const LayeredEarth &ob) {
  15. stream << ob.Serialize() << "\n---\n"; // End of doc
  16. return stream;
  17. }
  18. // ==================== LIFECYCLE ===================================
  19. LayeredEarth::LayeredEarth( ) : EarthModel( ),
  20. NumberOfLayers(0), NumberOfInterfaces(0) {
  21. }
  22. LayeredEarth::~LayeredEarth() {
  23. }
  24. LayeredEarth::LayeredEarth(const YAML::Node& node) : EarthModel(node) {
  25. std::cout << "LayeredEarth(YAML::Node )" << std::endl;
  26. NumberOfLayers = node["NumberOfLayers"].as<int>();
  27. NumberOfInterfaces = node["NumberOfInterfaces"].as<int>();
  28. LayerThickness = node["LayerThickness"].as<VectorXr>();
  29. }
  30. YAML::Node LayeredEarth::Serialize() const {
  31. YAML::Node node = EarthModel::Serialize();
  32. node["NumberOfLayers"] = NumberOfLayers;
  33. node["NumberOfInterfaces"] = NumberOfInterfaces;
  34. node["LayerThickness"] = LayerThickness;
  35. node.SetTag( this->GetName() );
  36. return node;
  37. }
  38. // ==================== OPERATIONS ===================================
  39. // ==================== ACCESS ===================================
  40. //--------------------------------------------------------------------------------------
  41. // Class: LayeredEarth
  42. // Method: GetName
  43. // Description: Class identifier
  44. //--------------------------------------------------------------------------------------
  45. inline std::string LayeredEarth::GetName ( ) const {
  46. return CName;
  47. } // ----- end of method LayeredEarth::get_GetName -----
  48. void LayeredEarth::SetLayerThickness(const VectorXr &thick) {
  49. if (thick.size() != this->NumberOfLayers - 2)
  50. throw EarthModelParametersDoNotMatchNumberOfLayers( );
  51. LayerThickness = thick;
  52. }
  53. // ==================== INQUIRY ===================================
  54. int LayeredEarth::GetNumberOfLayers () {
  55. return this->NumberOfLayers;
  56. }
  57. int LayeredEarth::GetNumberOfNonAirLayers () {
  58. return this->NumberOfLayers - 1;
  59. }
  60. VectorXr LayeredEarth::GetLayerThickness( ) {
  61. return LayerThickness;
  62. }
  63. Real LayeredEarth::GetLayerThickness(const int &ilay) {
  64. // Take into account infinite top and bottom layers
  65. // estimate infinity by 1000 m
  66. if (ilay < 0 || ilay > NumberOfLayers - 1) {
  67. throw RequestForNonValidEarthModelParameter( );
  68. } else if (ilay == 0) {
  69. return 1000.;
  70. } else if (ilay == NumberOfLayers - 1) {
  71. return 1000.;
  72. } else {
  73. return this->LayerThickness(ilay-1);
  74. }
  75. }
  76. Real LayeredEarth::GetLayerDepth(const int &ilay) {
  77. Real depth = 0;
  78. if (ilay == 0) {
  79. return depth;
  80. } else {
  81. for (int i=1; i<=ilay; ++i) {
  82. depth += GetLayerThickness(i);
  83. }
  84. }
  85. return depth;
  86. }
  87. int LayeredEarth::GetLayerAtThisDepth(const Real& depth) {
  88. if (depth <= 0 || NumberOfLayers < 2) {
  89. return 0;
  90. }
  91. Real laydep = 0;
  92. for (int ilay=0; ilay<NumberOfLayers-2; ++ilay) {
  93. laydep += LayerThickness[ilay];
  94. if (laydep >= depth) { return ilay+1; }
  95. }
  96. return NumberOfLayers-1;
  97. }
  98. EarthModelWithLessThanTwoLayers::EarthModelWithLessThanTwoLayers() :
  99. runtime_error( "EARTH MODEL WITH LESS THAN TWO LAYERS") { }
  100. EarthModelWithMoreThanMaxLayers::EarthModelWithMoreThanMaxLayers() :
  101. runtime_error( "EARTH MODEL WITH MORE THAN MAX LAYERS") { }
  102. EarthModelParametersDoNotMatchNumberOfLayers::
  103. EarthModelParametersDoNotMatchNumberOfLayers( ) :
  104. runtime_error( "EARTH MODEL PARAMETERS DO NOT MATCH NUMBER OF LAYERS")
  105. {}
  106. RequestForNonValidEarthModelParameter::
  107. RequestForNonValidEarthModelParameter() :
  108. runtime_error( "REQUEST FOR NON VALID EARTH MODEL PARAMETER") {}
  109. }