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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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 "dipolesource.h"
  14. //#include "kernelem1dreflbase.h"
  15. #include "kernelem1dbase.h"
  16. #include "KernelEM1DSpec.h"
  17. namespace Lemma {
  18. class DipoleSource;
  19. class KernelEM1DReflBase;
  20. // ===================================================================
  21. // Class: KernelEM1DManager
  22. /**
  23. @class
  24. \brief
  25. \details
  26. */
  27. // ===================================================================
  28. class KernelEM1DManager : public LemmaObject {
  29. struct ctor_key {};
  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( std::shared_ptr<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 pointer to connected dipole.
  97. */
  98. std::shared_ptr<DipoleSource> GetDipole( );
  99. inline std::vector< std::shared_ptr<KernelEm1DBase> > GetSTLVector() {
  100. return KernelVec;
  101. }
  102. // ==================== INQUIRY =======================
  103. /** Returns the name of the underlying class, similiar to Python's type */
  104. virtual inline std::string GetName() const {
  105. return CName;
  106. }
  107. protected:
  108. // ==================== LIFECYCLE =======================
  109. // ==================== DATA MEMBERS =========================
  110. /** List of KernelEm1D instances */
  111. std::vector< std::shared_ptr<KernelEm1DBase> > KernelVec;
  112. /** Reflection base used for TE mode */
  113. std::shared_ptr<KernelEM1DReflBase> TEReflBase;
  114. /** Reflection base used for TM mode */
  115. std::shared_ptr<KernelEM1DReflBase> TMReflBase;
  116. /** EmEarth Class */
  117. std::shared_ptr<LayeredEarthEM> Earth;
  118. /** EM dipole souce */
  119. std::shared_ptr<DipoleSource> Dipole;
  120. /** Frequency index for the sources */
  121. int ifreq;
  122. /** Receiver height */
  123. Real rx_z;
  124. private:
  125. static constexpr auto CName = "KernelEM1DManager";
  126. }; // ----- end of class KernelEM1DManager -----
  127. // template methods
  128. template<EMMODE Mode, int Ikernel, DIPOLE_LOCATION Isource, DIPOLE_LOCATION Irecv>
  129. int KernelEM1DManager::AddKernel( ) {
  130. auto NewKern = KernelEM1DSpec<Mode, Ikernel, Isource, Irecv>::NewSP();
  131. KernelVec.push_back( NewKern );
  132. NewKern->managerIdx = KernelVec.size()-1;
  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. return static_cast<int>(KernelVec.size()-1);
  154. }
  155. // /** Clears the vector of kernels */
  156. // void ClearVec() {
  157. // for (unsigned int ik=0; ik<this->KernelVec.size(); ++ik) {
  158. // this->KernelVec[ik]->Delete();
  159. // }
  160. // KernelVec.clear();
  161. // }
  162. } // ----- end of Lemma name -----
  163. #endif // ----- #ifndef KERNELEM1DMANAGER_INC -----