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.6KB

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