Lemma is an Electromagnetics API
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

LayeredEarthEMReader.cpp 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 << *(LemmaObject*)(&ob);
  21. return stream;
  22. }
  23. // ==================== LIFECYCLE =======================
  24. //--------------------------------------------------------------------------------------
  25. // Class: LayeredEarthEMReader
  26. // Method: LayeredEarthEMReader
  27. // Description: constructor (protected)
  28. //--------------------------------------------------------------------------------------
  29. LayeredEarthEMReader::LayeredEarthEMReader (const std::string& name) : LemmaObject(name),
  30. LayEarth(NULL) {
  31. } // ----- end of method LayeredEarthEMReader::LayeredEarthEMReader (constructor) -----
  32. //--------------------------------------------------------------------------------------
  33. // Class: LayeredEarthEMReader
  34. // Method: New()
  35. // Description: public constructor
  36. //--------------------------------------------------------------------------------------
  37. LayeredEarthEMReader* LayeredEarthEMReader::New() {
  38. LayeredEarthEMReader* Obj = new LayeredEarthEMReader("LayeredEarthEMReader");
  39. Obj->AttachTo(Obj);
  40. return Obj;
  41. }
  42. //--------------------------------------------------------------------------------------
  43. // Class: LayeredEarthEMReader
  44. // Method: ~LayeredEarthEMReader
  45. // Description: destructor (protected)
  46. //--------------------------------------------------------------------------------------
  47. LayeredEarthEMReader::~LayeredEarthEMReader () {
  48. if (LayEarth) LayEarth->Delete();
  49. } // ----- end of method LayeredEarthEMReader::~LayeredEarthEMReader (destructor) -----
  50. //--------------------------------------------------------------------------------------
  51. // Class: LayeredEarthEMReader
  52. // Method: Delete
  53. // Description: public destructor
  54. //--------------------------------------------------------------------------------------
  55. void LayeredEarthEMReader::Delete() {
  56. this->DetachFrom(this);
  57. }
  58. //--------------------------------------------------------------------------------------
  59. // Class: LayeredEarthEMReader
  60. // Method: Release
  61. // Description: destructor (protected)
  62. //--------------------------------------------------------------------------------------
  63. void LayeredEarthEMReader::Release() {
  64. delete this;
  65. }
  66. //--------------------------------------------------------------------------------------
  67. // Class: LayeredEarthEMReader
  68. // Method: GetLayeredEarth
  69. //--------------------------------------------------------------------------------------
  70. LayeredEarthEM* LayeredEarthEMReader::GetLayeredEarth ( ) {
  71. return LayEarth;
  72. } // ----- end of method LayeredEarthEMReader::GetLayeredEarth -----
  73. //--------------------------------------------------------------------------------------
  74. // Class: LayeredEarthEMReader
  75. // Method: ReadASCIIInputFile
  76. //--------------------------------------------------------------------------------------
  77. void LayeredEarthEMReader::ReadASCIIInputFile ( const std::string& name ) {
  78. if (LayEarth) LayEarth->Delete();
  79. ASCIIParser* Parser = ASCIIParser::New();
  80. LayEarth = LayeredEarthEM::New();
  81. Parser->SetCommentString("//");
  82. Parser->Open(name);
  83. int nlay = Parser->ReadInts( 1 )[0]; // non-air layers
  84. LayEarth->SetNumberOfLayers(nlay+1);
  85. VectorXcr sigma = VectorXcr::Zero(nlay+1);
  86. VectorXr thick(nlay-1);
  87. for (int ilay=1; ilay<nlay; ++ilay) {
  88. std::vector<Real> rval = Parser->ReadReals(2);
  89. sigma(ilay) = 1./rval[0];
  90. thick(ilay-1) = rval[1]; //CondMod[ilay+1];
  91. }
  92. sigma(nlay) = 1./Parser->ReadReals(1)[0];
  93. LayEarth->SetLayerConductivity(sigma);
  94. if (thick.size() > 0) LayEarth->SetLayerThickness(thick);
  95. Parser->Delete();
  96. return ;
  97. } // ----- end of method LayeredEarthEMReader::ReadASCIIInputFile -----
  98. } // ----- end of Lemma name -----