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.

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