Main Lemma Repository
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.

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