Lemma is an Electromagnetics API
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

TEMSurvey.cpp 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 10/08/2014 01:52:04 PM
  11. * @version $Id$
  12. * @author Trevor Irons (ti)
  13. * @email Trevor.Irons@xri-geo.com
  14. * @copyright Copyright (c) 2014, XRI Geophysics, LLC
  15. * @copyright Copyright (c) 2014, Trevor Irons
  16. */
  17. #include "TEMSurvey.h"
  18. namespace Lemma {
  19. // ==================== FRIEND METHODS =====================
  20. #ifdef HAVE_YAMLCPP
  21. std::ostream &operator << (std::ostream &stream, const TEMSurvey &ob) {
  22. stream << ob.Serialize() << "\n---\n"; // End of doc --- a direct stream should encapulste object
  23. return stream;
  24. }
  25. #else
  26. std::ostream &operator<<(std::ostream &stream, const TEMSurvey &ob) {
  27. stream << *(LemmaObject*)(&ob);
  28. return stream;
  29. }
  30. #endif
  31. // ==================== LIFECYCLE =======================
  32. //--------------------------------------------------------------------------------------
  33. // Class: TEMSurvey
  34. // Method: TEMSurvey
  35. // Description: constructor (protected)
  36. //--------------------------------------------------------------------------------------
  37. TEMSurvey::TEMSurvey (const std::string& name) : LemmaObject(name) {
  38. } // ----- end of method TEMSurvey::TEMSurvey (constructor) -----
  39. //--------------------------------------------------------------------------------------
  40. // Class: TEMSurvey
  41. // Method: TEMSurvey
  42. // Description: DeSerializing constructor (protected)
  43. //--------------------------------------------------------------------------------------
  44. #ifdef HAVE_YAMLCPP
  45. TEMSurvey::TEMSurvey (const YAML::Node& node) : LemmaObject(node) {
  46. Lines.resize( node["numberOfLines"].as<int>( ) );
  47. } // ----- end of method TEMSurvey::TEMSurvey (constructor) -----
  48. #endif
  49. //--------------------------------------------------------------------------------------
  50. // Class: TEMSurvey
  51. // Method: New()
  52. // Description: public constructor
  53. //--------------------------------------------------------------------------------------
  54. TEMSurvey* TEMSurvey::New() {
  55. TEMSurvey* Obj = new TEMSurvey("TEMSurvey");
  56. Obj->AttachTo(Obj);
  57. return Obj;
  58. }
  59. //--------------------------------------------------------------------------------------
  60. // Class: TEMSurvey
  61. // Method: ~TEMSurvey
  62. // Description: destructor (protected)
  63. //--------------------------------------------------------------------------------------
  64. TEMSurvey::~TEMSurvey () {
  65. } // ----- end of method TEMSurvey::~TEMSurvey (destructor) -----
  66. //--------------------------------------------------------------------------------------
  67. // Class: TEMSurvey
  68. // Method: Delete
  69. // Description: public destructor
  70. //--------------------------------------------------------------------------------------
  71. void TEMSurvey::Delete() {
  72. this->DetachFrom(this);
  73. }
  74. //--------------------------------------------------------------------------------------
  75. // Class: TEMSurvey
  76. // Method: Release
  77. // Description: destructor (protected)
  78. //--------------------------------------------------------------------------------------
  79. void TEMSurvey::Release() {
  80. for (std::vector<TEMSurveyLine*>::iterator it = Lines.begin() ; it != Lines.end(); ++it) {
  81. (*it)->DetachFrom(this);
  82. }
  83. delete this;
  84. }
  85. #ifdef HAVE_YAMLCPP
  86. //--------------------------------------------------------------------------------------
  87. // Class: TEMSurvey
  88. // Method: Serialize
  89. //--------------------------------------------------------------------------------------
  90. YAML::Node TEMSurvey::Serialize ( ) const {
  91. YAML::Node node;
  92. node.SetTag( this->Name );
  93. node["numberOfLines"] = Lines.size();
  94. for (unsigned int it = 0; it< Lines.size(); ++it) {
  95. node[std::string("line_") + to_string(it)] = Lines[it]->Serialize();
  96. }
  97. return node;
  98. } // ----- end of method TEMSurvey::Serialize -----
  99. //--------------------------------------------------------------------------------------
  100. // Class: TEMSurvey
  101. // Method: DeSerialize
  102. //--------------------------------------------------------------------------------------
  103. TEMSurvey* TEMSurvey::DeSerialize ( const YAML::Node& node ) {
  104. TEMSurvey* Object = new TEMSurvey(node);
  105. Object->AttachTo(Object);
  106. DESERIALIZECHECK( node, Object )
  107. return Object ;
  108. } // ----- end of method TEMSurvey::DeSerialize -----
  109. #endif
  110. // ==================== OPERATORS =======================
  111. TEMSurveyLine* TEMSurvey::operator( ) ( const int& idx ) const {
  112. return this->Lines[ idx ];
  113. }
  114. TEMSurveyLineRecord* TEMSurvey::operator( ) ( const int& iline, const int& irec ) const {
  115. return Lines[ iline ]->GetRecord( irec );
  116. }
  117. //--------------------------------------------------------------------------------------
  118. // Class: TEMSurvey
  119. // Method: SetNumberOfLines
  120. //--------------------------------------------------------------------------------------
  121. void TEMSurvey::SetNumberOfLines ( const int& nlines ) {
  122. // clean up any old lines
  123. for (std::vector<TEMSurveyLine*>::iterator it = Lines.begin() ; it != Lines.end(); ++it) {
  124. (*it)->DetachFrom(this);
  125. }
  126. Lines.clear();
  127. // Allocate these lines
  128. Lines.reserve(nlines);
  129. for (int il=0; il<nlines; ++il) {
  130. Lines.push_back( new TEMSurveyLine("TEMSurveyLine") );
  131. Lines[il]->AttachTo(this);
  132. }
  133. return ;
  134. } // ----- end of method TEMSurvey::SetNumberOfLines -----
  135. //--------------------------------------------------------------------------------------
  136. // Class: TEMSurvey
  137. // Method: GetLine
  138. //--------------------------------------------------------------------------------------
  139. TEMSurveyLine* TEMSurvey::GetLine ( const unsigned int& iline ) {
  140. return Lines[iline];
  141. } // ----- end of method TEMSurvey::GetLine -----
  142. //--------------------------------------------------------------------------------------
  143. // Class: TEMSurvey
  144. // Method: ForwardModel
  145. //--------------------------------------------------------------------------------------
  146. TEMSurveyData* TEMSurvey::ForwardModel ( LayeredEarthEM* model, bool additiveNoise ) {
  147. TEMSurveyData* ForwardData = TEMSurveyData::New();
  148. //ForwardData->SetNumberOfLines(Lines.size());
  149. for (std::vector<TEMSurveyLine*>::iterator it = Lines.begin() ; it != Lines.end(); ++it) {
  150. TEMSurveyLineData* LineData = ((*it)->ForwardModel( model, additiveNoise ) );
  151. LineData->AttachTo(ForwardData);
  152. ForwardData->LineData.push_back( LineData );
  153. }
  154. //for (int it=0; it<Lines.size(); ++it) {
  155. // Lines[it]->ForwardModel( model );
  156. //}
  157. return ForwardData;
  158. } // ----- end of method TEMSurvey::ForwardModel -----
  159. } // ----- end of Lemma name -----