Lemma is an Electromagnetics API
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.

KernelEM1DManager.h 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. \brief
  23. \details
  24. */
  25. // ===================================================================
  26. class KernelEM1DManager : public LemmaObject {
  27. struct ctor_key {};
  28. /** Recursively streams information about this class */
  29. friend std::ostream &operator<<(std::ostream &stream, const KernelEM1DManager &ob);
  30. public:
  31. // ==================== LIFECYCLE =======================
  32. /** Default protected constructor. */
  33. KernelEM1DManager ( const ctor_key& );
  34. /** Default protected constructor. */
  35. ~KernelEM1DManager ();
  36. /** Returns a pointer to a new object of type KernelEM1DManager.
  37. * It allocates all necessary memory.
  38. */
  39. static std::shared_ptr<KernelEM1DManager> NewSP();
  40. // ==================== OPERATORS =======================
  41. // ==================== OPERATIONS =======================
  42. template<EMMODE Mode, int Ikernel, DIPOLE_LOCATION Isource, DIPOLE_LOCATION Irecv>
  43. int AddKernel( );
  44. /*
  45. {
  46. KernelEM1DSpec<Mode, Ikernel, Isource, Irecv>* NewKern =
  47. KernelEM1DSpec<Mode, Ikernel, Isource, Irecv>::New();
  48. KernelVec.push_back( NewKern );
  49. NewKern->managerIdx = KernelVec.size()-1;
  50. switch (Mode) {
  51. case TE:
  52. if (TEReflBase == NULL) {
  53. TEReflBase = KernelEM1DReflSpec<TE, Isource, Irecv>::New();
  54. TEReflBase->Initialise(Earth);
  55. TEReflBase->SetUpSource(Dipole, ifreq);
  56. TEReflBase->SetUpReceiver( rx_z );
  57. }
  58. NewKern->SetReflBase(TEReflBase);
  59. break;
  60. case TM:
  61. if (TMReflBase == NULL) {
  62. TMReflBase = KernelEM1DReflSpec<TM, Isource, Irecv>::New();
  63. TMReflBase->Initialise(Earth);
  64. TMReflBase->SetUpSource(Dipole, ifreq);
  65. TMReflBase->SetUpReceiver( rx_z );
  66. }
  67. NewKern->SetReflBase(TMReflBase);
  68. break;
  69. }
  70. return static_cast<int>(KernelVec.size()-1);
  71. }
  72. */
  73. void ResetSource(const int& ifreq);
  74. /** For use in related Kernel calculations. This function calles
  75. * ComputeReflectionCoeffs on TEReflBase and TMReflBase, if they
  76. * exist. After this has been called, KernelEM1DBase::RelBesselArg() may be safely
  77. * called. This method stores solutions of the same idx. rho0 is the intial lambda argument
  78. */
  79. void ComputeReflectionCoeffs(const Real& lambda, const int& idx, const Real& rho0);
  80. /** Clears the vector of kernels */
  81. void ClearVec() {
  82. KernelVec.clear();
  83. }
  84. // ==================== ACCESS =======================
  85. /** Sets the LayeredEarthEM class that will be used by the kernels.
  86. */
  87. void SetEarth( std::shared_ptr<LayeredEarthEM> Earth);
  88. /** Sets the source of the kernels */
  89. void SetDipoleSource( DipoleSource* Dipole, const int& ifreq, const Real& rx_zin);
  90. /** Returns pointer to specified kernel indice. Indices are assigned in the same
  91. order as they are created by AddKernel.
  92. */
  93. std::shared_ptr<KernelEM1DBase> GetKernel(const unsigned int& ik);
  94. /** Returns RAW pointer to specified kernel indice. Indices are assigned in the same
  95. order as they are created by AddKernel.
  96. */
  97. KernelEM1DBase* GetRAWKernel(const unsigned int& ik);
  98. /** Returns pointer to connected dipole.
  99. */
  100. DipoleSource* GetDipole( );
  101. inline std::vector< std::shared_ptr<KernelEM1DBase> > GetSTLVector() {
  102. return KernelVec;
  103. }
  104. // ==================== INQUIRY =======================
  105. /** Returns the name of the underlying class, similiar to Python's type */
  106. virtual inline std::string GetName() const {
  107. return CName;
  108. }
  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 -----