Lemma is an Electromagnetics API
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.

TEMSurveyLine.cpp 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 11:19:38 AM
  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 "TEMSurveyLine.h"
  18. namespace Lemma {
  19. // ==================== FRIEND METHODS =====================
  20. #ifdef HAVE_YAMLCPP
  21. std::ostream &operator << (std::ostream &stream, const TEMSurveyLine &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 TEMSurveyLine& ob) {
  27. stream << *(LemmaObject*)(&ob);
  28. return stream;
  29. }
  30. #endif
  31. // ==================== LIFECYCLE =======================
  32. //--------------------------------------------------------------------------------------
  33. // Class: TEMSurveyLine
  34. // Method: TEMSurveyLine
  35. // Description: constructor (protected)
  36. //--------------------------------------------------------------------------------------
  37. TEMSurveyLine::TEMSurveyLine (const std::string& name) : LemmaObject(name) {
  38. } // ----- end of method TEMSurveyLine::TEMSurveyLine (constructor) -----
  39. #ifdef HAVE_YAMLCPP
  40. //--------------------------------------------------------------------------------------
  41. // Class: TEMSurveyLine
  42. // Method: TEMSurveyLine
  43. // Description: DeSerializing constructor (protected)
  44. //--------------------------------------------------------------------------------------
  45. TEMSurveyLine::TEMSurveyLine (const YAML::Node& node) : LemmaObject(node) {
  46. } // ----- end of method TEMSurveyLine::TEMSurveyLine (constructor) -----
  47. #endif
  48. //--------------------------------------------------------------------------------------
  49. // Class: TEMSurveyLine
  50. // Method: ~TEMSurveyLine
  51. // Description: destructor (protected)
  52. //--------------------------------------------------------------------------------------
  53. TEMSurveyLine::~TEMSurveyLine () {
  54. } // ----- end of method TEMSurveyLine::~TEMSurveyLine (destructor) -----
  55. //--------------------------------------------------------------------------------------
  56. // Class: TEMSurveyLine
  57. // Method: Delete
  58. // Description: public destructor
  59. //--------------------------------------------------------------------------------------
  60. void TEMSurveyLine::Delete() {
  61. // THIS is a private member, this class must be used through a TEMSurvey
  62. this->DetachFrom(this);
  63. }
  64. //--------------------------------------------------------------------------------------
  65. // Class: TEMSurveyLine
  66. // Method: Release
  67. // Description: destructor (protected)
  68. //--------------------------------------------------------------------------------------
  69. void TEMSurveyLine::Release() {
  70. for (std::vector<TEMSurveyLineRecord*>::iterator it = Records.begin() ; it != Records.end(); ++it) {
  71. (*it)->DetachFrom(this);
  72. }
  73. delete this;
  74. }
  75. #ifdef HAVE_YAMLCPP
  76. //--------------------------------------------------------------------------------------
  77. // Class: TEMSurveyLine
  78. // Method: Serialize
  79. //--------------------------------------------------------------------------------------
  80. YAML::Node TEMSurveyLine::Serialize ( ) const {
  81. YAML::Node node;
  82. node.SetTag( this->Name );
  83. node["numberOfRecords"] = Records.size();
  84. for (unsigned int it = 0; it< Records.size(); ++it) {
  85. node[std::string("record_") + to_string(it)] = Records[it]->Serialize();
  86. }
  87. return node;
  88. } // ----- end of method TEMSurveyLine::Serialize -----
  89. //--------------------------------------------------------------------------------------
  90. // Class: TEMSurveyLine
  91. // Method: DeSerialize
  92. //--------------------------------------------------------------------------------------
  93. TEMSurveyLine* TEMSurveyLine::DeSerialize ( const YAML::Node& node ) {
  94. TEMSurveyLine* Object = new TEMSurveyLine(node);
  95. Object->AttachTo(Object);
  96. DESERIALIZECHECK( node, Object )
  97. return Object ;
  98. } // ----- end of method TEMSurveyLine::DeSerialize -----
  99. #endif
  100. TEMSurveyLineRecord* TEMSurveyLine::GetRecord( const unsigned int& irec ) {
  101. return Records[irec];
  102. }
  103. //--------------------------------------------------------------------------------------
  104. // Class: TEMSurveyLine
  105. // Method: SetNumberOfRecords
  106. //--------------------------------------------------------------------------------------
  107. void TEMSurveyLine::SetNumberOfRecords ( const int& nrec ) {
  108. // clean up any old records
  109. for (std::vector<TEMSurveyLineRecord*>::iterator it = Records.begin() ; it != Records.end(); ++it) {
  110. (*it)->DetachFrom(this);
  111. }
  112. Records.clear();
  113. // Allocate these lines
  114. Records.reserve(nrec);
  115. for (int ir=0; ir<nrec; ++ir) {
  116. Records.push_back( new TEMSurveyLineRecord("TEMSurveyLineRecord") );
  117. Records[ir]->AttachTo(this);
  118. }
  119. return ;
  120. } // ----- end of method TEMSurveyLine::SetNumberOfRecords -----
  121. //--------------------------------------------------------------------------------------
  122. // Class: TEMSurveyLine
  123. // Method: ForwardModel
  124. //--------------------------------------------------------------------------------------
  125. TEMSurveyLineData* TEMSurveyLine::ForwardModel ( LayeredEarthEM* Model, bool additiveNoise ) {
  126. TEMSurveyLineData* Data = TEMSurveyLineData::New();
  127. for (std::vector<TEMSurveyLineRecord*>::iterator it = Records.begin() ; it != Records.end(); ++it) {
  128. TEMSurveyLineRecordData* RecData = (*it)->ForwardModel(Model, additiveNoise) ;
  129. RecData->AttachTo(Data);
  130. Data->RecordData.push_back( RecData );
  131. }
  132. return Data;
  133. } // ----- end of method TEMSurveyLine::ForwardModel -----
  134. } // ----- end of Lemma name -----