Main Lemma Repository
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

TEMReceiver.cpp 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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 03:04:56 PM
  11. * @author Trevor Irons (ti)
  12. * @email Trevor.Irons@utah.edu
  13. * @copyright Copyright (c) 2014, 2018 Trevor Irons
  14. */
  15. #include "TEMReceiver.h"
  16. namespace Lemma {
  17. // ==================== FRIEND METHODS =====================
  18. std::ostream &operator << (std::ostream &stream, const TEMReceiver &ob) {
  19. stream << ob.Serialize() << "\n";
  20. return stream;
  21. }
  22. // ==================== LIFECYCLE =======================
  23. //--------------------------------------------------------------------------------------
  24. // Class: TEMReceiver
  25. // Method: TEMReceiver
  26. // Description: constructor (locked)
  27. //--------------------------------------------------------------------------------------
  28. TEMReceiver::TEMReceiver ( const ctor_key& key ) : FieldPoints(key), moment(1), referenceTime(0) {
  29. } // ----- end of method TEMReceiver::TEMReceiver (constructor) -----
  30. //--------------------------------------------------------------------------------------
  31. // Class: TEMReceiver
  32. // Method: TEMReceiver
  33. // Description: constructor (protected)
  34. //--------------------------------------------------------------------------------------
  35. TEMReceiver::TEMReceiver (const YAML::Node& node, const ctor_key& key) : FieldPoints(node, key) {
  36. moment = node["moment"].as<Real>();
  37. referenceTime = node["referenceTime"].as<Real>();
  38. component = string2Enum<FIELDCOMPONENT>( node["component"].as<std::string>() );
  39. windowCentres = node["windowCentres"].as<VectorXr>();
  40. windowWidths = node["windowWidths"].as<VectorXr>();
  41. noiseSTD = node["noiseSTD"].as<VectorXr>();
  42. //location = node["location"].as<Vector3r>();
  43. } // ----- end of method TEMReceiver::TEMReceiver (constructor) -----
  44. //--------------------------------------------------------------------------------------
  45. // Class: TEMReceiver
  46. // Method: New()
  47. // Description: public constructor
  48. //--------------------------------------------------------------------------------------
  49. std::shared_ptr<TEMReceiver> TEMReceiver::NewSP() {
  50. return std::make_shared<TEMReceiver> ( ctor_key() );
  51. }
  52. //--------------------------------------------------------------------------------------
  53. // Class: TEMReceiver
  54. // Method: Clone
  55. //--------------------------------------------------------------------------------------
  56. /*
  57. TEMReceiver* TEMReceiver::Clone() {
  58. TEMReceiver* Copy = TEMReceiver::New();
  59. Copy->SetNumberOfReceivers( this->NumberOfReceivers );
  60. Copy->Mask = this->Mask;
  61. Copy->Locations = this->Locations;
  62. // TEM stuff
  63. Copy->moment = this->moment;
  64. Copy->referenceTime = this->referenceTime;
  65. Copy->nHat = this->nHat;
  66. Copy->component = this->component;
  67. Copy->windowCentres = this->windowCentres;
  68. Copy->windowWidths = this->windowWidths;
  69. Copy->noiseSTD = this->noiseSTD;
  70. return Copy;
  71. } // ----- end of method TEMReceiver::Clone -----
  72. */
  73. //--------------------------------------------------------------------------------------
  74. // Class: TEMReceiver
  75. // Method: ~TEMReceiver
  76. // Description: destructor (protected)
  77. //--------------------------------------------------------------------------------------
  78. TEMReceiver::~TEMReceiver () {
  79. } // ----- end of method TEMReceiver::~TEMReceiver (destructor) -----
  80. //--------------------------------------------------------------------------------------
  81. // Class: TEMReceiver
  82. // Method: SetWindows
  83. //--------------------------------------------------------------------------------------
  84. void TEMReceiver::SetWindows ( const VectorXr& centres, const VectorXr& widths, const TIMEUNITS& Units ) {
  85. Real sc(0);
  86. switch (Units) {
  87. case SEC:
  88. sc = 1;
  89. break;
  90. case MILLISEC:
  91. sc = 1e-3;
  92. break;
  93. case MICROSEC:
  94. sc = 1e-6;
  95. break;
  96. case NANOSEC:
  97. sc = 1e-9;
  98. break;
  99. case PICOSEC:
  100. sc = 1e-12;
  101. break;
  102. };
  103. windowCentres = sc*centres;
  104. windowWidths = sc*widths;
  105. noiseSTD = VectorXr::Zero(windowCentres.size());
  106. return ;
  107. } // ----- end of method TEMReceiver::SetWindows -----
  108. //--------------------------------------------------------------------------------------
  109. // Class: TEMReceiver
  110. // Method: SetNoiseSTD
  111. //--------------------------------------------------------------------------------------
  112. void TEMReceiver::SetNoiseSTD ( const VectorXr& noiseIn ) {
  113. if ( noiseIn.size() == windowCentres.size() ) {
  114. noiseSTD = noiseIn;
  115. } else {
  116. throw std::runtime_error("TEMReceiver::SetNoiseSTD not aligned");
  117. }
  118. return ;
  119. } // ----- end of method TEMReceiver::SetNoiseSTD -----
  120. //--------------------------------------------------------------------------------------
  121. // Class: TEMReceiver
  122. // Method: GetNoiseSTD
  123. //--------------------------------------------------------------------------------------
  124. VectorXr TEMReceiver::GetNoiseSTD ( ) {
  125. return noiseSTD ;
  126. } // ----- end of method TEMReceiver::GetNoiseSTD -----
  127. //--------------------------------------------------------------------------------------
  128. // Class: TEMReceiver
  129. // Method: SampleNoise
  130. //--------------------------------------------------------------------------------------
  131. VectorXr TEMReceiver::SampleNoise ( ) {
  132. /* we have C++-11 now! No Boost!
  133. boost::mt19937 rng(time(0));
  134. boost::normal_distribution<> nd(0.0, 1.0);
  135. boost::variate_generator<boost::mt19937&, boost::normal_distribution<> > var_nor(rng, nd);
  136. */
  137. std::random_device rd;
  138. std::mt19937 gen(rd());
  139. std::normal_distribution<> d(0.0, 1.00);
  140. VectorXr noise = VectorXr::Zero( windowCentres.size() );
  141. for (int ii=0; ii<windowCentres.size(); ++ii) {
  142. //noise(ii) = var_nor(); // old boost way
  143. noise(ii) = d(gen);
  144. }
  145. return noise.array() * noiseSTD.array();
  146. } // ----- end of method TEMReceiver::SampleNoise -----
  147. //--------------------------------------------------------------------------------------
  148. // Class: TEMReceiver
  149. // Method: SetReferenceTime
  150. //--------------------------------------------------------------------------------------
  151. void TEMReceiver::SetReferenceTime ( const Real& refTime, const TIMEUNITS& units ) {
  152. Real sc(0);
  153. switch (units) {
  154. case SEC:
  155. sc = 1;
  156. break;
  157. case MILLISEC:
  158. sc = 1e-3;
  159. break;
  160. case MICROSEC:
  161. sc = 1e-6;
  162. break;
  163. case NANOSEC:
  164. sc = 1e-9;
  165. break;
  166. case PICOSEC:
  167. sc = 1e-12;
  168. break;
  169. };
  170. referenceTime = sc*refTime;
  171. return ;
  172. } // ----- end of method TEMReceiver::SetReferenceTime -----
  173. //--------------------------------------------------------------------------------------
  174. // Class: TEMReceiver
  175. // Method: SetMoment
  176. //--------------------------------------------------------------------------------------
  177. void TEMReceiver::SetMoment ( const Real& mom ) {
  178. moment = mom;
  179. return ;
  180. } // ----- end of method TEMReceiver::SetMoment -----
  181. //--------------------------------------------------------------------------------------
  182. // Class: TEMReceiver
  183. // Method: SetLocation
  184. //--------------------------------------------------------------------------------------
  185. void TEMReceiver::SetRxLocation ( const Vector3r& loc ) {
  186. this->SetNumberOfPoints(1); // Valgrind doesn't like??
  187. this->SetLocation(0, loc);
  188. //location = loc;
  189. return ;
  190. } // ----- end of method TEMReceiver::SetLocation -----
  191. //--------------------------------------------------------------------------------------
  192. // Class: TEMReceiver
  193. // Method: SetComponent
  194. //--------------------------------------------------------------------------------------
  195. void TEMReceiver::SetComponent ( const FIELDCOMPONENT& comp ) {
  196. component = comp;
  197. return ;
  198. } // ----- end of method TEMReceiver::SetComponent -----
  199. //--------------------------------------------------------------------------------------
  200. // Class: TEMReceiver
  201. // Method: get_WindowWidths
  202. //--------------------------------------------------------------------------------------
  203. VectorXr TEMReceiver::GetWindowWidths ( ) {
  204. return windowWidths;
  205. } // ----- end of method TEMReceiver::get_WindowWidths -----
  206. //--------------------------------------------------------------------------------------
  207. // Class: TEMReceiver
  208. // Method: get_WindowCentres
  209. //--------------------------------------------------------------------------------------
  210. VectorXr TEMReceiver::GetWindowCentres ( ) {
  211. return windowCentres;
  212. } // ----- end of method TEMReceiver::get_WindowCentres -----
  213. //--------------------------------------------------------------------------------------
  214. // Class: TEMReceiver
  215. // Method: GetReferenceTime
  216. //--------------------------------------------------------------------------------------
  217. Real TEMReceiver::GetReferenceTime ( ) {
  218. return referenceTime;
  219. } // ----- end of method TEMReceiver::GetReferenceTime -----
  220. //--------------------------------------------------------------------------------------
  221. // Class: TEMReceiver
  222. // Method: Serialize
  223. //--------------------------------------------------------------------------------------
  224. YAML::Node TEMReceiver::Serialize ( ) const {
  225. YAML::Node node = FieldPoints::Serialize();
  226. node.SetTag( GetName() );
  227. node["moment"] = moment;
  228. node["referenceTime"] = referenceTime;
  229. node["component"] = enum2String(component);
  230. node["windowCentres"] = windowCentres;
  231. node["windowWidths"] = windowWidths;
  232. node["noiseSTD"] = noiseSTD;
  233. //node["location"] = location;
  234. return node;
  235. } // ----- end of method TEMReceiver::Serialize -----
  236. //--------------------------------------------------------------------------------------
  237. // Class: TEMReceiver
  238. // Method: DeSerialize
  239. //--------------------------------------------------------------------------------------
  240. std::shared_ptr<TEMReceiver> TEMReceiver::DeSerialize ( const YAML::Node& node ) {
  241. if (node.Tag() != "TEMReceiver") {
  242. throw DeSerializeTypeMismatch( "TEMReceiver", node.Tag());
  243. }
  244. return std::make_shared<TEMReceiver> ( node, ctor_key() );
  245. } // ----- end of method TEMReceiver::DeSerialize -----
  246. } // ----- end of Lemma name -----