Main Lemma Repository
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

TEMSurveyLineRecord.cpp 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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/10/2014 12:23:07 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 "TEMSurveyLineRecord.h"
  18. namespace Lemma {
  19. // ==================== FRIEND METHODS =====================
  20. #ifdef HAVE_YAMLCPP
  21. std::ostream &operator << (std::ostream &stream, const TEMSurveyLineRecord &ob) {
  22. stream << ob.Serialize() << "\n---\n"; // End of doc --- as a direct stream should encapulste thingy
  23. return stream;
  24. }
  25. #else
  26. std::ostream &operator<<(std::ostream &stream, const TEMSurveyLineRecord& ob) {
  27. stream << *(LemmaObject*)(&ob);
  28. return stream;
  29. }
  30. #endif
  31. // ==================== LIFECYCLE =======================
  32. //--------------------------------------------------------------------------------------
  33. // Class: TEMSurveyLineRecord
  34. // Method: TEMSurveyLineRecord
  35. // Description: constructor (protected)
  36. //--------------------------------------------------------------------------------------
  37. TEMSurveyLineRecord::TEMSurveyLineRecord (const std::string& name) : LemmaObject(name),
  38. numberOfPulseSequences(0)
  39. {
  40. } // ----- end of method TEMSurveyLineRecord::TEMSurveyLineRecord (constructor) -----
  41. #ifdef HAVE_YAMLCPP
  42. //--------------------------------------------------------------------------------------
  43. // Class: TEMSurveyLineRecord
  44. // Method: TEMSurveyLineRecord
  45. // Description: DeSerializing constructor (protected)
  46. //--------------------------------------------------------------------------------------
  47. TEMSurveyLineRecord::TEMSurveyLineRecord (const YAML::Node& node) : LemmaObject(node),
  48. numberOfPulseSequences(0)
  49. {
  50. } // ----- end of method TEMSurveyLineRecord::TEMSurveyLineRecord (constructor) -----
  51. #endif
  52. //--------------------------------------------------------------------------------------
  53. // Class: TEMSurveyLineRecord
  54. // Method: ~TEMSurveyLineRecord
  55. // Description: destructor (protected)
  56. //--------------------------------------------------------------------------------------
  57. TEMSurveyLineRecord::~TEMSurveyLineRecord () {
  58. for (unsigned int ip=0; ip<Transmitters.size(); ++ip) {
  59. if (Transmitters[ip] != NULL) {
  60. Transmitters[ip]->DetachFrom(this);
  61. }
  62. }
  63. for (unsigned int ir=0; ir<Receivers.size(); ++ir) {
  64. if (Receivers[ir] != NULL) {
  65. Receivers[ir]->DetachFrom(this);
  66. }
  67. }
  68. } // ----- end of method TEMSurveyLineRecord::~TEMSurveyLineRecord (destructor) -----
  69. //--------------------------------------------------------------------------------------
  70. // Class: TEMSurveyLineRecord
  71. // Method: Delete
  72. // Description: public destructor
  73. //--------------------------------------------------------------------------------------
  74. void TEMSurveyLineRecord::Delete() {
  75. this->DetachFrom(this);
  76. }
  77. //--------------------------------------------------------------------------------------
  78. // Class: TEMSurveyLineRecord
  79. // Method: Release
  80. // Description: destructor (protected)
  81. //--------------------------------------------------------------------------------------
  82. void TEMSurveyLineRecord::Release() {
  83. delete this;
  84. }
  85. //--------------------------------------------------------------------------------------
  86. // Class: TEMSurveyLineRecord
  87. // Method: SetPulseSequenceReceiverPair
  88. //--------------------------------------------------------------------------------------
  89. void TEMSurveyLineRecord::SetTransmitterReceiverPair ( const int& ii, TEMTransmitter* Tx, TEMReceiver* Rx ) {
  90. Receivers[ii] = Rx;
  91. Rx->AttachTo(this);
  92. Transmitters[ii] = Tx;
  93. Tx->AttachTo(this);
  94. return ;
  95. } // ----- end of method TEMSurveyLineRecord::SetPulseSequenceReceiverPair -----
  96. //--------------------------------------------------------------------------------------
  97. // Class: TEMSurveyLineRecord
  98. // Method: GetReceiver
  99. //--------------------------------------------------------------------------------------
  100. TEMReceiver* TEMSurveyLineRecord::GetReceiver ( const int& irec ) {
  101. if ( irec >= (int)(Receivers.size()) ) {
  102. throw std::runtime_error( "TEMSurveyLineRecord::GetReceiver(const int& irec)--array bounds error" );
  103. }
  104. return Receivers[irec] ;
  105. } // ----- end of method TEMSurveyLineRecord::GetReceiver -----
  106. #ifdef HAVE_YAMLCPP
  107. //--------------------------------------------------------------------------------------
  108. // Class: TEMSurveyLineRecord
  109. // Method: Serialize
  110. //--------------------------------------------------------------------------------------
  111. YAML::Node TEMSurveyLineRecord::Serialize ( ) const {
  112. YAML::Node node;
  113. node.SetTag( this->Name );
  114. node["numberOfPulseSequences"] = numberOfPulseSequences;
  115. // FILL IN CLASS SPECIFICS HERE
  116. for( int is=0; is<numberOfPulseSequences; ++is) {
  117. node[std::string("pulse_") + to_string(is)] = Transmitters[is]->Serialize();
  118. node[std::string("receiver_") + to_string(is)] = Receivers[is]->Serialize();
  119. }
  120. return node;
  121. } // ----- end of method TEMSurveyLineRecord::Serialize -----
  122. //--------------------------------------------------------------------------------------
  123. // Class: TEMSurveyLineRecord
  124. // Method: DeSerialize
  125. //--------------------------------------------------------------------------------------
  126. TEMSurveyLineRecord* TEMSurveyLineRecord::DeSerialize ( const YAML::Node& node ) {
  127. TEMSurveyLineRecord* Object = new TEMSurveyLineRecord(node);
  128. Object->AttachTo(Object);
  129. DESERIALIZECHECK( node, Object )
  130. return Object ;
  131. } // ----- end of method TEMSurveyLineRecord::DeSerialize -----
  132. #endif
  133. //--------------------------------------------------------------------------------------
  134. // Class: TEMSurveyLineRecord
  135. // Method: SetNumberOfPulseSequences
  136. //--------------------------------------------------------------------------------------
  137. void TEMSurveyLineRecord::SetNumberOfPulseSequences ( const int& nseq ) {
  138. for (unsigned int ip=0; ip<Transmitters.size(); ++ip) {
  139. Transmitters[ip]->DetachFrom(this);
  140. }
  141. for (unsigned int ir=0; ir<Receivers.size(); ++ir) {
  142. Receivers[ir]->DetachFrom(this);
  143. }
  144. Transmitters.clear();
  145. Receivers.clear();
  146. numberOfPulseSequences = nseq;
  147. Receivers.reserve(nseq);
  148. Transmitters.reserve(nseq);
  149. for (int ir=0; ir<nseq; ++ir) {
  150. Transmitters.push_back( NULL );
  151. Receivers.push_back( NULL );
  152. }
  153. return ;
  154. } // ----- end of method TEMSurveyLineRecord::SetNumberOfPulseSequences -----
  155. //--------------------------------------------------------------------------------------
  156. // Class: TEMSurveyLineRecord
  157. // Method: GetNumberOfPulseSequences
  158. //--------------------------------------------------------------------------------------
  159. int TEMSurveyLineRecord::GetNumberOfPulseSequences ( ) {
  160. return numberOfPulseSequences ;
  161. } // ----- end of method TEMSurveyLineRecord::GetNumberOfPulseSequences -----
  162. //--------------------------------------------------------------------------------------
  163. // Class: TEMSurveyLineRecord
  164. // Method: ForwardModel
  165. //--------------------------------------------------------------------------------------
  166. TEMSurveyLineRecordData* TEMSurveyLineRecord::ForwardModel ( LayeredEarthEM* model, bool additiveNoise ) {
  167. TEMSurveyLineRecordData* Data = TEMSurveyLineRecordData::New();
  168. // DO I want to work with InstrumentTem here? Or just roll it myself at this point?
  169. for (unsigned int ip=0; ip<Transmitters.size(); ++ip) {
  170. InstrumentTem *instrument = InstrumentTem::New();
  171. // For thread safety...
  172. TEMTransmitter* TC = Transmitters[ip]->Clone();
  173. TEMReceiver* RC = Receivers[ip]->Clone();
  174. // TODO some of this needs to be moved logic checked or use overriden functions, etc.
  175. instrument->EMEarthModel(model);
  176. instrument->SetTransmitLoop( TC );
  177. instrument->SetReferenceTime( RC->GetReferenceTime() );
  178. instrument->SetTimeGates( RC->GetWindowCentres(), RC->GetWindowWidths() );
  179. instrument->SetReceiver( RC ); // Clone??
  180. instrument->SetReceiverType(INDUCTIVE);
  181. instrument->SetPulse( TC->GetWfmAmps(), TC->GetWfmTimes() );
  182. // TODO pass this
  183. //instrument->MakeLaggedCalculation( FHTKEY51 );
  184. instrument->MakeLaggedCalculation( ANDERSON801 );
  185. Data->DataSeries.push_back( MU0*instrument->GetMeasurements().col(1) );
  186. Data->GateCentres.push_back( RC->GetWindowCentres() );
  187. if (additiveNoise) {
  188. Data->DataSeries.back() += RC->SampleNoise();
  189. }
  190. // int nlag = instrument->GetMeasurements().rows();
  191. // std::cout.precision(12);
  192. // std::cout << "// time [s] dB/dt [T/s] \n";
  193. // for (int ii=0; ii<nlag; ii++) {
  194. // std::cout<<" "<<instrument->GetMeasurements()(ii,0)<<" "<< MU0*instrument->GetMeasurements()(ii,1)<<std::endl;
  195. // }
  196. instrument->Delete();
  197. TC->Delete();
  198. RC->Delete();
  199. }
  200. return Data;
  201. } // ----- end of method TEMSurveyLineRecord::ForwardModel -----
  202. } // ----- end of Lemma name -----