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 12KB

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