Main Lemma Repository
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.

LayeredEarthEMReader.cpp 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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@lemmasoftware.org
  14. * @copyright Copyright (c) 2013-2018 Trevor Irons
  15. */
  16. #include "LayeredEarthEMReader.h"
  17. namespace Lemma {
  18. // ==================== FRIEND METHODS =====================
  19. std::ostream &operator << (std::ostream &stream, const LayeredEarthEMReader &ob) {
  20. stream << ob.Serialize() << "\n---\n"; // End of doc ---
  21. return stream;
  22. }
  23. // ==================== LIFECYCLE =======================
  24. //--------------------------------------------------------------------------------------
  25. // Class: LayeredEarthEMReader
  26. // Method: LayeredEarthEMReader
  27. // Description: constructor (protected)
  28. //--------------------------------------------------------------------------------------
  29. LayeredEarthEMReader::LayeredEarthEMReader ( const ctor_key& key ) : LemmaObject( key ),
  30. LayEarth(nullptr) {
  31. } // ----- end of method LayeredEarthEMReader::LayeredEarthEMReader (constructor) -----
  32. //--------------------------------------------------------------------------------------
  33. // Class: LayeredEarthEMReader
  34. // Method: New()
  35. // Description: public constructor
  36. //--------------------------------------------------------------------------------------
  37. std::shared_ptr<LayeredEarthEMReader> LayeredEarthEMReader::NewSP() {
  38. return std::make_shared<LayeredEarthEMReader>( ctor_key() );
  39. }
  40. //--------------------------------------------------------------------------------------
  41. // Class: LayeredEarthEMReader
  42. // Method: ~LayeredEarthEMReader
  43. // Description: destructor (protected)
  44. //--------------------------------------------------------------------------------------
  45. LayeredEarthEMReader::~LayeredEarthEMReader () {
  46. } // ----- end of method LayeredEarthEMReader::~LayeredEarthEMReader (destructor) -----
  47. //--------------------------------------------------------------------------------------
  48. // Class: LayeredEarthEMReader
  49. // Method: GetLayeredEarth
  50. //--------------------------------------------------------------------------------------
  51. std::shared_ptr<LayeredEarthEM> LayeredEarthEMReader::GetLayeredEarth ( ) {
  52. return LayEarth;
  53. } // ----- end of method LayeredEarthEMReader::GetLayeredEarth -----
  54. //--------------------------------------------------------------------------------------
  55. // Class: LayeredEarthEMReader
  56. // Method: ReadASCIIInputFile
  57. //--------------------------------------------------------------------------------------
  58. void LayeredEarthEMReader::ReadASCIIInputFile ( const std::string& name ) {
  59. auto Parser = ASCIIParser::NewSP();
  60. LayEarth = LayeredEarthEM::NewSP();
  61. Parser->SetCommentString("//");
  62. Parser->Open(name);
  63. int nlay = Parser->ReadInts( 1 )[0]; // non-air layers
  64. LayEarth->SetNumberOfLayers(nlay+1);
  65. VectorXcr sigma = VectorXcr::Zero(nlay+1);
  66. VectorXr thick(nlay-1);
  67. for (int ilay=1; ilay<nlay; ++ilay) {
  68. std::vector<Real> rval = Parser->ReadReals(2);
  69. sigma(ilay) = 1./rval[0];
  70. thick(ilay-1) = rval[1]; //CondMod[ilay+1];
  71. }
  72. sigma(nlay) = 1./Parser->ReadReals(1)[0];
  73. LayEarth->SetLayerConductivity(sigma);
  74. if (thick.size() > 0) LayEarth->SetLayerThickness(thick);
  75. return ;
  76. } // ----- end of method LayeredEarthEMReader::ReadASCIIInputFile -----
  77. } // ----- end of Lemma name -----