Main Lemma Repository
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

LayeredEarthEMReader.cpp 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* This file is part of Lemma, a geophysical modelling and inversion API.
  2. * More information is available at http://lemmasoftware.org
  3. */
  4. /* This Source Code Form is subject to the terms of the Mozilla Public
  5. * License, v. 2.0. If a copy of the MPL was not distributed with this
  6. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  7. */
  8. /**
  9. * @file
  10. * @date 09/27/2013 01:44:46 PM
  11. * @version $Id$
  12. * @author Trevor Irons (ti)
  13. * @email Trevor.Irons@xri-geo.com
  14. * @copyright Copyright (c) 2013, XRI Geophysics, LLC
  15. * @copyright Copyright (c) 2013, Trevor Irons
  16. */
  17. #include "LayeredEarthEMReader.h"
  18. namespace Lemma {
  19. // ==================== FRIEND METHODS =====================
  20. std::ostream &operator<<(std::ostream &stream, const LayeredEarthEMReader &ob) {
  21. stream << *(LemmaObject*)(&ob);
  22. return stream;
  23. }
  24. // ==================== LIFECYCLE =======================
  25. //--------------------------------------------------------------------------------------
  26. // Class: LayeredEarthEMReader
  27. // Method: LayeredEarthEMReader
  28. // Description: constructor (protected)
  29. //--------------------------------------------------------------------------------------
  30. LayeredEarthEMReader::LayeredEarthEMReader (const std::string& name) : LemmaObject(name),
  31. LayEarth(NULL) {
  32. } // ----- end of method LayeredEarthEMReader::LayeredEarthEMReader (constructor) -----
  33. //--------------------------------------------------------------------------------------
  34. // Class: LayeredEarthEMReader
  35. // Method: New()
  36. // Description: public constructor
  37. //--------------------------------------------------------------------------------------
  38. LayeredEarthEMReader* LayeredEarthEMReader::New() {
  39. LayeredEarthEMReader* Obj = new LayeredEarthEMReader("LayeredEarthEMReader");
  40. Obj->AttachTo(Obj);
  41. return Obj;
  42. }
  43. //--------------------------------------------------------------------------------------
  44. // Class: LayeredEarthEMReader
  45. // Method: ~LayeredEarthEMReader
  46. // Description: destructor (protected)
  47. //--------------------------------------------------------------------------------------
  48. LayeredEarthEMReader::~LayeredEarthEMReader () {
  49. if (LayEarth) LayEarth->Delete();
  50. } // ----- end of method LayeredEarthEMReader::~LayeredEarthEMReader (destructor) -----
  51. //--------------------------------------------------------------------------------------
  52. // Class: LayeredEarthEMReader
  53. // Method: Delete
  54. // Description: public destructor
  55. //--------------------------------------------------------------------------------------
  56. void LayeredEarthEMReader::Delete() {
  57. this->DetachFrom(this);
  58. }
  59. //--------------------------------------------------------------------------------------
  60. // Class: LayeredEarthEMReader
  61. // Method: Release
  62. // Description: destructor (protected)
  63. //--------------------------------------------------------------------------------------
  64. void LayeredEarthEMReader::Release() {
  65. delete this;
  66. }
  67. //--------------------------------------------------------------------------------------
  68. // Class: LayeredEarthEMReader
  69. // Method: GetLayeredEarth
  70. //--------------------------------------------------------------------------------------
  71. LayeredEarthEM* LayeredEarthEMReader::GetLayeredEarth ( ) {
  72. return LayEarth;
  73. } // ----- end of method LayeredEarthEMReader::GetLayeredEarth -----
  74. //--------------------------------------------------------------------------------------
  75. // Class: LayeredEarthEMReader
  76. // Method: ReadASCIIInputFile
  77. //--------------------------------------------------------------------------------------
  78. void LayeredEarthEMReader::ReadASCIIInputFile ( const std::string& name ) {
  79. if (LayEarth) LayEarth->Delete();
  80. ASCIIParser* Parser = ASCIIParser::New();
  81. LayEarth = LayeredEarthEM::New();
  82. Parser->SetCommentString("//");
  83. Parser->Open(name);
  84. int nlay = Parser->ReadInts( 1 )[0]; // non-air layers
  85. LayEarth->SetNumberOfLayers(nlay+1);
  86. VectorXcr sigma = VectorXcr::Zero(nlay+1);
  87. VectorXr thick(nlay-1);
  88. for (int ilay=1; ilay<nlay; ++ilay) {
  89. std::vector<Real> rval = Parser->ReadReals(2);
  90. sigma(ilay) = 1./rval[0];
  91. thick(ilay-1) = rval[1]; //CondMod[ilay+1];
  92. }
  93. sigma(nlay) = 1./Parser->ReadReals(1)[0];
  94. LayEarth->SetLayerConductivity(sigma);
  95. if (thick.size() > 0) LayEarth->SetLayerThickness(thick);
  96. Parser->Delete();
  97. return ;
  98. } // ----- end of method LayeredEarthEMReader::ReadASCIIInputFile -----
  99. } // ----- end of Lemma name -----