Lemma is an Electromagnetics API
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 06/26/2012
  9. @version 0.0
  10. **/
  11. #ifndef KERNELEM1DMANAGER_INC
  12. #define KERNELEM1DMANAGER_INC
  13. #include "KernelEM1DBase.h"
  14. #include "KernelEM1DSpec.h"
  15. namespace Lemma {
  16. class DipoleSource;
  17. class KernelEM1DReflBase;
  18. // ===================================================================
  19. // Class: KernelEM1DManager
  20. /**
  21. \ingroup FDEM1D
  22. \brief Keeps track of Kernels for EM1D
  23. \details This class keeps track of the various types of kernel terms
  24. which can be shared between permutations of sources. Care is
  25. taken to avoid duplicate calculations
  26. */
  27. // ===================================================================
  28. class KernelEM1DManager : public LemmaObject {
  29. /** Recursively streams information about this class */
  30. friend std::ostream &operator<<(std::ostream &stream, const KernelEM1DManager &ob);
  31. public:
  32. // ==================== LIFECYCLE =======================
  33. /** Default protected constructor. */
  34. KernelEM1DManager ( const ctor_key& );
  35. /** Default protected constructor. */
  36. ~KernelEM1DManager ();
  37. /** Returns a pointer to a new object of type KernelEM1DManager.
  38. * It allocates all necessary memory.
  39. */
  40. static std::shared_ptr<KernelEM1DManager> NewSP();
  41. // ==================== OPERATORS =======================
  42. // ==================== OPERATIONS =======================
  43. template<EMMODE Mode, int Ikernel, DIPOLE_LOCATION Isource, DIPOLE_LOCATION Irecv>
  44. int AddKernel( );
  45. /*
  46. {
  47. KernelEM1DSpec<Mode, Ikernel, Isource, Irecv>* NewKern =
  48. KernelEM1DSpec<Mode, Ikernel, Isource, Irecv>::New();
  49. KernelVec.push_back( NewKern );
  50. NewKern->managerIdx = KernelVec.size()-1;
  51. switch (Mode) {
  52. case TE:
  53. if (TEReflBase == NULL) {
  54. TEReflBase = KernelEM1DReflSpec<TE, Isource, Irecv>::New();
  55. TEReflBase->Initialise(Earth);
  56. TEReflBase->SetUpSource(Dipole, ifreq);
  57. TEReflBase->SetUpReceiver( rx_z );
  58. }
  59. NewKern->SetReflBase(TEReflBase);
  60. break;
  61. case TM:
  62. if (TMReflBase == NULL) {
  63. TMReflBase = KernelEM1DReflSpec<TM, Isource, Irecv>::New();
  64. TMReflBase->Initialise(Earth);
  65. TMReflBase->SetUpSource(Dipole, ifreq);
  66. TMReflBase->SetUpReceiver( rx_z );
  67. }
  68. NewKern->SetReflBase(TMReflBase);
  69. break;
  70. }
  71. return static_cast<int>(KernelVec.size()-1);
  72. }
  73. */
  74. void ResetSource(const int& ifreq);
  75. /** For use in related Kernel calculations. This function calles
  76. * ComputeReflectionCoeffs on TEReflBase and TMReflBase, if they
  77. * exist. After this has been called, KernelEM1DBase::RelBesselArg() may be safely
  78. * called. This method stores solutions of the same idx. rho0 is the intial lambda argument
  79. */
  80. void ComputeReflectionCoeffs(const Real& lambda, const int& idx, const Real& rho0);
  81. /** Clears the vector of kernels */
  82. void ClearVec() {
  83. KernelVec.clear();
  84. }
  85. // ==================== ACCESS =======================
  86. /** Sets the LayeredEarthEM class that will be used by the kernels.
  87. */
  88. void SetEarth( std::shared_ptr<LayeredEarthEM> Earth);
  89. /** Sets the source of the kernels */
  90. void SetDipoleSource( DipoleSource* Dipole, const int& ifreq, const Real& rx_zin);
  91. /** Returns pointer to specified kernel indice. Indices are assigned in the same
  92. order as they are created by AddKernel.
  93. */
  94. std::shared_ptr<KernelEM1DBase> GetKernel(const unsigned int& ik);
  95. /** Returns RAW pointer to specified kernel indice. Indices are assigned in the same
  96. order as they are created by AddKernel.
  97. */
  98. KernelEM1DBase* GetRAWKernel(const unsigned int& ik);
  99. /** Returns pointer to connected dipole.
  100. */
  101. DipoleSource* GetDipole( );
  102. inline std::vector< std::shared_ptr<KernelEM1DBase> > GetSTLVector() {
  103. return KernelVec;
  104. }
  105. // ==================== INQUIRY =======================
  106. /** Returns the name of the underlying class, similiar to Python's type */
  107. virtual inline std::string GetName() const ;
  108. protected:
  109. // ==================== LIFECYCLE =======================
  110. // ==================== DATA MEMBERS =========================
  111. /** List of KernelEm1D instances */
  112. std::vector< std::shared_ptr<KernelEM1DBase> > KernelVec;
  113. /** Reflection base used for TE mode */
  114. std::shared_ptr<KernelEM1DReflBase> TEReflBase = nullptr;
  115. /** Reflection base used for TM mode */
  116. std::shared_ptr<KernelEM1DReflBase> TMReflBase = nullptr;
  117. /** EmEarth Class */
  118. std::shared_ptr<LayeredEarthEM> Earth;
  119. /** EM dipole souce */
  120. DipoleSource* Dipole;
  121. /** Frequency index for the sources */
  122. int ifreq;
  123. /** Receiver height */
  124. Real rx_z;
  125. private:
  126. static constexpr auto CName = "KernelEM1DManager";
  127. }; // ----- end of class KernelEM1DManager -----
  128. // template methods
  129. template<EMMODE Mode, int Ikernel, DIPOLE_LOCATION Isource, DIPOLE_LOCATION Irecv>
  130. int KernelEM1DManager::AddKernel( ) {
  131. auto NewKern = KernelEM1DSpec<Mode, Ikernel, Isource, Irecv>::NewSP();
  132. NewKern->managerIdx = KernelVec.size();
  133. switch (Mode) {
  134. case TE:
  135. if (TEReflBase == nullptr) {
  136. TEReflBase = KernelEM1DReflSpec<TE, Isource, Irecv>::NewSP();
  137. TEReflBase->Initialise(Earth);
  138. TEReflBase->SetUpSource(Dipole, ifreq);
  139. TEReflBase->SetUpReceiver( rx_z );
  140. }
  141. NewKern->SetReflBase(TEReflBase);
  142. break;
  143. case TM:
  144. if (TMReflBase == nullptr) {
  145. TMReflBase = KernelEM1DReflSpec<TM, Isource, Irecv>::NewSP();
  146. TMReflBase->Initialise(Earth);
  147. TMReflBase->SetUpSource(Dipole, ifreq);
  148. TMReflBase->SetUpReceiver( rx_z );
  149. }
  150. NewKern->SetReflBase(TMReflBase);
  151. break;
  152. }
  153. KernelVec.push_back( std::move(NewKern) );
  154. return static_cast<int>(KernelVec.size()-1);
  155. }
  156. // /** Clears the vector of kernels */
  157. // void ClearVec() {
  158. // for (unsigned int ik=0; ik<this->KernelVec.size(); ++ik) {
  159. // this->KernelVec[ik]->Delete();
  160. // }
  161. // KernelVec.clear();
  162. // }
  163. } // ----- end of Lemma name -----
  164. #endif // ----- #ifndef KERNELEM1DMANAGER_INC -----