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 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 --- as a direct stream should encapulste thingy
  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. {
  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. void LayeredEarth::SetLayerThickness(const VectorXr &thick) {
  41. if (thick.size() != this->NumberOfLayers - 2)
  42. throw EarthModelParametersDoNotMatchNumberOfLayers( );
  43. LayerThickness = thick;
  44. }
  45. // ==================== INQUIRY ===================================
  46. int LayeredEarth::GetNumberOfLayers () {
  47. return this->NumberOfLayers;
  48. }
  49. int LayeredEarth::GetNumberOfNonAirLayers () {
  50. return this->NumberOfLayers - 1;
  51. }
  52. Real LayeredEarth::GetLayerThickness(const int &ilay) {
  53. // Take into account infinite top and bottom layers
  54. // estimate infinity by 1000 m
  55. if (ilay < 0 || ilay > NumberOfLayers - 1) {
  56. throw RequestForNonValidEarthModelParameter( );
  57. } else if (ilay == 0) {
  58. return 1000.;
  59. } else if (ilay == NumberOfLayers - 1) {
  60. return 1000.;
  61. } else {
  62. return this->LayerThickness(ilay-1);
  63. }
  64. }
  65. Real LayeredEarth::GetLayerDepth(const int &ilay) {
  66. Real depth = 0;
  67. if (ilay == 0) {
  68. return depth;
  69. } else {
  70. for (int i=1; i<=ilay; ++i) {
  71. depth += GetLayerThickness(i);
  72. }
  73. }
  74. return depth;
  75. }
  76. int LayeredEarth::GetLayerAtThisDepth(const Real& depth) {
  77. if (depth <= 0 || NumberOfLayers < 2) {
  78. return 0;
  79. }
  80. Real laydep = 0;
  81. for (int ilay=0; ilay<NumberOfLayers-2; ++ilay) {
  82. laydep += LayerThickness[ilay];
  83. if (laydep >= depth) { return ilay+1; }
  84. }
  85. return NumberOfLayers-1;
  86. }
  87. EarthModelWithLessThanTwoLayers::EarthModelWithLessThanTwoLayers() :
  88. runtime_error( "EARTH MODEL WITH LESS THAN TWO LAYERS") { }
  89. EarthModelWithMoreThanMaxLayers::EarthModelWithMoreThanMaxLayers() :
  90. runtime_error( "EARTH MODEL WITH MORE THAN MAX LAYERS") { }
  91. EarthModelParametersDoNotMatchNumberOfLayers::
  92. EarthModelParametersDoNotMatchNumberOfLayers( ) :
  93. runtime_error( "EARTH MODEL PARAMETERS DO NOT MATCH NUMBER OF LAYERS")
  94. {}
  95. RequestForNonValidEarthModelParameter::
  96. RequestForNonValidEarthModelParameter() :
  97. runtime_error( "REQUEST FOR NON VALID EARTH MODEL PARAMETER") {}
  98. }