Lemma is an Electromagnetics API
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

DipoleSource.h 13KB

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