Lemma is an Electromagnetics API
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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