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.

DipoleSource.h 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. /* This file is part of Lemma, a geophysical modelling and inversion API */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. /**
  6. @file
  7. @author Trevor Irons
  8. @date 12/02/2009
  9. **/
  10. #ifndef __DIPOLESOURCE_H
  11. #define __DIPOLESOURCE_H
  12. #include "LemmaObject.h"
  13. #include "LayeredEarthEM.h"
  14. #ifdef LEMMAUSEVTK
  15. #include "vtkActor.h"
  16. #include "vtkLineSource.h"
  17. #include "vtkSphereSource.h"
  18. #include "vtkPolyDataMapper.h"
  19. #include "vtkTubeFilter.h"
  20. #include "vtkRegularPolygonSource.h"
  21. #include "vtkProperty.h"
  22. #endif
  23. namespace Lemma {
  24. // Forward declarations
  25. class KernelEM1DManager;
  26. class FieldPoints;
  27. class HankelTransform;
  28. // ==========================================================================
  29. // Class: DipoleSource
  30. /// \ingroup FDEM1D
  31. /// \brief Dipole sources form the backbone of Lemma.
  32. /// \details More complex sources are constructed from a superposition of
  33. /// dipoles.
  34. // ==========================================================================
  35. class DipoleSource : public std::enable_shared_from_this<DipoleSource>, LemmaObject {
  36. // ==================== FRIENDS ======================
  37. friend std::ostream &operator<<(std::ostream &stream, const DipoleSource &ob);
  38. friend class EMEarth1D;
  39. public:
  40. //bool operator==(DipoleSource& rhs)const;
  41. // ==================== LIFECYCLE ======================
  42. /** Default locked constructor. */
  43. explicit DipoleSource ( const ctor_key& );
  44. /** Locked deserializing constructor */
  45. DipoleSource ( const YAML::Node& node, const ctor_key& );
  46. /** Default locked constructor. */
  47. ~DipoleSource ();
  48. /**
  49. * Returns shared_ptr to new DipoleSource. Location is
  50. * initialized to (0,0,0) type and polarization are
  51. * initialized to nonworking values that will throw
  52. * exceptions if used.
  53. */
  54. static std::shared_ptr< DipoleSource > NewSP();
  55. /**
  56. * YAML Serializing method
  57. */
  58. YAML::Node Serialize() const;
  59. /**
  60. * Constructs an object from a YAML::Node.
  61. */
  62. static std::shared_ptr< DipoleSource > DeSerialize(const YAML::Node& node);
  63. /** Returns a deep copy of the dipole. Used to make thread safe methods. Does not
  64. copy attachments.
  65. */
  66. std::shared_ptr< DipoleSource > Clone();
  67. // ==================== OPERATORS ======================
  68. // ==================== ACCESS ======================
  69. /** Sets the position.
  70. * @param [in] posin
  71. */
  72. void SetLocation(const Vector3r &posin);
  73. /** Sets the location using three Real coordinate arguments.
  74. * @param[in] xp is the x coordinate of the dipole
  75. * @param[in] yp is the y coordinate of the dipole
  76. * @param[in] zp is the z coordinate of the dipole
  77. */
  78. void SetLocation(const Real &xp, const Real &yp, const Real &zp);
  79. /** Sets the dipole direction (polarisation). This method
  80. * replaced SetPolarisation(DipoleSourcePolarisation) and allows for general dipole
  81. * directionality.
  82. * @param[in] dir is the direction of the dipole. This will be normalised.
  83. */
  84. void SetPolarisation(const Vector3r &dir);
  85. /** Sets the polarisation of the dipole. Conveneince method that calls
  86. * SetPolarisation(const Vector3r &dir), constructing the normalized Vector | <x, y, z> |
  87. */
  88. void SetPolarisation(const Real& x, const Real& y, const Real& z );
  89. /// Sets the dipole polarisation
  90. /// @param[in] pol is the enumerated polarisation
  91. void SetPolarisation(const DipoleSourcePolarisation &pol);
  92. /// Sets the dipole source type
  93. /// @param[in] stype is one of the enerated values taking either
  94. /// ELECTRICDIPOLE or MAGNETICDIPOLE
  95. void SetType(const DIPOLESOURCETYPE &stype);
  96. /// Sets the dipole moment
  97. void SetMoment(const Real &moment);
  98. /// Sets the dipole phse
  99. void SetPhase(const Real &phase);
  100. /// Sets the polarity
  101. void SetPolarity(const DipoleSourcePolarity& pol);
  102. /// Sets number of frequencies
  103. void SetNumberOfFrequencies(const int &nfreq);
  104. /// Sets a specific frequency.
  105. /// @param[in] ifreq is the frequency bin number
  106. /// @param[in] freq is the frequency to set, in Hz
  107. void SetFrequency(const int &ifreq, const Real &freq);
  108. /// Sets the frequencies of the dipole.
  109. /// @param[in] freqs is a vector of the frequencies. Also sets
  110. /// number of frequencies
  111. void SetFrequencies(const VectorXr& freqs);
  112. // ==================== INQUIRY ======================
  113. /** Accessor to polarisation vector.
  114. @return returns the unit polarisation vector.
  115. */
  116. Vector3r GetPolarisation();
  117. /// Returns Vector3r position of the dipole
  118. Vector3r GetLocation();
  119. /// Returns a specific coordinate of the dipole
  120. /// @param coordinate 0=x, 1=y, 2=z
  121. Real GetLocation(const int &coordinate);
  122. /// Returns enumerated of DIPOLESOURCETYPE
  123. DIPOLESOURCETYPE GetDipoleSourceType();
  124. /// Returns the dipole type
  125. DIPOLESOURCETYPE GetType();
  126. /// Returns pointer to KernelEM1DManager
  127. std::shared_ptr<KernelEM1DManager> GetKernelManager();
  128. // Returns enumerated DipoleSourcePolarization
  129. //DipoleSourcePolarisation GetDipoleSourcePolarisation();
  130. /// Returns the dipole moment
  131. Real GetMoment();
  132. /// Returns the angular frequency of the dipole
  133. Real GetAngularFrequency(const int &ifreq);
  134. /// Returns the frequency of the dipole (Hz)
  135. Real GetFrequency(const int &ifreq);
  136. /// Returns the frequency of the dipole (Hz)
  137. VectorXr GetFrequencies( );
  138. /// Returns the phase offset of the dipole
  139. Real GetPhase();
  140. /// Returns the number of frequencies
  141. int GetNumberOfFrequencies();
  142. #ifdef LEMMAUSEVTK
  143. /// Returns an actor that can be placed into a vtk scene easily
  144. /// Note that this function throws a pointer, it is the receivers
  145. /// job to manage this memory!
  146. vtkActor* GetVtkActor();
  147. #endif
  148. /** Returns the name of the underlying class, similiar to Python's type */
  149. virtual std::string GetName() const ;
  150. protected:
  151. // ==================== OPERATIONS ======================
  152. /** Determines if kernels have been loaded already, and if so if they can be reused
  153. */
  154. void SetKernels(const int& ifreq, const FIELDCALCULATIONS& Fields,
  155. std::shared_ptr<FieldPoints> Receivers, const int& irec,
  156. std::shared_ptr<LayeredEarthEM> Earth );
  157. /** resets the kernels if they cannot be reused */
  158. virtual void ReSetKernels(const int& ifreq, const FIELDCALCULATIONS& Fields,
  159. std::shared_ptr<FieldPoints> Receivers,
  160. const int& irec, std::shared_ptr<LayeredEarthEM> Earth );
  161. /** Updates the receiver fields */
  162. virtual void UpdateFields(const int& ifreq, HankelTransform* Hankel, const Real& wavef);
  163. private:
  164. // ==================== DATA MEMBERS ======================
  165. /// Defines the type of source (magnetic or electric)
  166. DIPOLESOURCETYPE Type;
  167. // Polarization of the dipole, (x, y or z)
  168. //DipoleSourcePolarisation Polarisation;
  169. // Dipole polarity
  170. //DipoleSourcePolarity Polarity;
  171. /// Which receiver index should Kernels be configured for
  172. int irec;
  173. int lays;
  174. int layr;
  175. /// Phase offset of the dipole, referenced from 0
  176. Real Phase;
  177. /// Dipole Moment
  178. Real Moment;
  179. Real xxp;
  180. Real yyp;
  181. Real rho;
  182. Real sp;
  183. Real cp;
  184. Real scp;
  185. Real sps;
  186. Real cps;
  187. Real c2p;
  188. Real kernelFreq;
  189. FIELDCALCULATIONS FieldsToCalculate = BOTH;
  190. VectorXcr f;
  191. VectorXi ik;
  192. /// Central location of the dipole
  193. Vector3r Location;
  194. /// Unit vector defining directionality of the dipole
  195. Vector3r Phat;
  196. /// Freqencies of the source, in Hz
  197. VectorXr Freqs;
  198. /// Storage of the EM1D kernels used by this dipole
  199. std::shared_ptr<KernelEM1DManager> KernelManager;
  200. /// Receiver points, keep track if these have changed
  201. std::shared_ptr<FieldPoints> Receivers;
  202. /// Layered Earth used by Kernels
  203. std::shared_ptr<LayeredEarthEM> Earth;
  204. /** ASCII string representation of the class name */
  205. static constexpr auto CName = "DipoleSource";
  206. }; // ----- end of class DipoleSource -----
  207. /** If no dipole source has been specified, throw this error.
  208. */
  209. class NullDipoleSource : public std::runtime_error {
  210. public:
  211. /** Thrown when a DipoleSource pointer is NULL
  212. */
  213. NullDipoleSource ( );
  214. };
  215. /** Error class for assignment of a dipole source that did not connect properly.
  216. */
  217. class NonValidDipoleTypeAssignment : public std::runtime_error {
  218. public:
  219. NonValidDipoleTypeAssignment( );
  220. };
  221. /** Error class for a non-valid dipole type. Generally thrown if this was not
  222. * set properly.
  223. */
  224. class NonValidDipoleType : public std::runtime_error {
  225. public:
  226. /** Throws error. This is a deprecated function. Call the method with
  227. * the pointer address instead.
  228. */
  229. NonValidDipoleType( );
  230. /** Throws error with information on the class throwing the error.
  231. */
  232. NonValidDipoleType( LemmaObject *ptr );
  233. };
  234. /** Error class for non valid dipole polarisation
  235. */
  236. class NonValidDipolePolarisation : public std::runtime_error {
  237. public:
  238. NonValidDipolePolarisation( );
  239. };
  240. /** Error class for non valid dipole polarity
  241. */
  242. class NonValidDipolePolarity : public std::runtime_error {
  243. public:
  244. NonValidDipolePolarity( );
  245. };
  246. /** Error class for non valid dipole polarisation
  247. */
  248. class NonValidDipolePolarisationAssignment : public std::runtime_error {
  249. public:
  250. NonValidDipolePolarisationAssignment( );
  251. };
  252. /** Error class for non valid location coordinate.
  253. */
  254. class NonValidLocationCoordinate : public std::runtime_error {
  255. public:
  256. NonValidLocationCoordinate( );
  257. };
  258. }
  259. #endif // __DIPOLESOURCE_H