Lemma is an Electromagnetics API
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

LayeredEarth.cpp 3.8KB

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