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.

kernelem1dreflbase.h 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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 05/18/2012
  9. @version $Id: kernelem1dreflbase.h 193 2014-11-10 23:51:41Z tirons $
  10. **/
  11. #ifndef KERNELEM1DREFLBASE_INC
  12. #define KERNELEM1DREFLBASE_INC
  13. #include "dipolesource.h"
  14. #include "kernelem1dbase.h"
  15. #include "layeredearthem.h"
  16. //#include "kernelem1dspec.h"
  17. namespace Lemma {
  18. //class DipoleSource;
  19. enum DIPOLE_LOCATION { INAIR, INGROUND };
  20. // forward declaration for friend
  21. template<EMMODE Mode, int Ikernel, DIPOLE_LOCATION Isource, DIPOLE_LOCATION Irecv>
  22. class KernelEm1DSpec;
  23. // ===================================================================
  24. // Class: KernelEM1DReflBase
  25. /**
  26. @class
  27. \brief Abstract class defining EM1DRefl class.
  28. \details Derived classes are template specialized for optimal performance.
  29. */
  30. // ===================================================================
  31. class KernelEM1DReflBase : public LemmaObject {
  32. template<EMMODE Mode, int Ikernel, DIPOLE_LOCATION Isource, DIPOLE_LOCATION Irecv>
  33. friend class KernelEm1DSpec;
  34. friend class KernelEM1DManager;
  35. public:
  36. // ==================== LIFECYCLE =======================
  37. // ==================== OPERATORS =======================
  38. // ==================== OPERATIONS =======================
  39. void Initialise(LayeredEarthEM* EarthIn) {
  40. nlay = EarthIn->GetNumberOfLayers();
  41. zh = VectorXcr::Zero(nlay);
  42. yh = VectorXcr::Zero(nlay);
  43. u = VectorXcr::Zero(nlay);
  44. cf = VectorXcr::Zero(nlay); // nlay -1 (lay 0 empty)
  45. rtu = VectorXcr::Zero(nlay); // nlay -1 Interfaces only
  46. rtd = VectorXcr::Zero(nlay); // nlay -1 Interfaces only
  47. kk = VectorXcr::Zero(nlay);
  48. Zyu = VectorXcr::Zero(nlay);
  49. Zyd = VectorXcr::Zero(nlay);
  50. Zyi = VectorXcr::Zero(nlay);
  51. th = VectorXcr::Zero(nlay);
  52. // Don't attach Earth, because this is performance critical.
  53. // Everying is internal, it's OK relax Frankie
  54. //if (Earth != NULL) {
  55. // Earth->DetachFrom(this);
  56. // Earth = NULL;
  57. //}
  58. //EarthIn->AttachTo(this);
  59. Earth = EarthIn;
  60. LayerThickness.resize(nlay);
  61. for (int ilay=0; ilay<nlay; ++ilay) {
  62. LayerThickness(ilay) = Earth->GetLayerThickness(ilay);
  63. }
  64. LayerDepth.resize(nlay);
  65. for (int ilay=0; ilay<nlay; ++ilay) {
  66. LayerDepth(ilay) = Earth->GetLayerDepth(ilay);
  67. }
  68. }
  69. void SetUpSource(DipoleSource *Dipole, const int &ifreq) {
  70. zh(0) = Complex(0, Dipole->GetAngularFrequency(ifreq)*MU0);
  71. yh(0) = Complex(0, Dipole->GetAngularFrequency(ifreq)*EPSILON0);
  72. kk(0) = -zh(0) * yh(0);
  73. Earth->EvaluateColeColeModel(Dipole->GetAngularFrequency(ifreq));
  74. for (int ilay=1; ilay<Earth->GetNumberOfLayers(); ++ilay) {
  75. zh(ilay) = zh(0) * Earth->GetLayerSusceptibility(ilay);
  76. yh(ilay) = Earth->GetLayerConductivity(ilay) +
  77. yh(0)*Earth->GetLayerPermitivity(ilay);
  78. kk(ilay) = -zh(ilay)*yh(ilay);
  79. }
  80. tx_z = Dipole->GetLocation(2);
  81. lays = 0;
  82. Real Depth(0);
  83. for (int ilay=1; ilay<nlay; ++ilay) {
  84. if (tx_z > Depth) {
  85. lays = ilay;
  86. }
  87. Depth += LayerThickness(ilay);
  88. }
  89. }
  90. void SetUpReceiver(const Real &rz) {
  91. rx_z = rz;
  92. Real Depth(0.);
  93. layr = 0;
  94. for (int ilay=1; ilay<Earth->GetNumberOfLayers(); ++ilay) {
  95. if (rx_z > Depth) {
  96. layr = ilay;
  97. }
  98. Depth += LayerThickness(ilay);
  99. }
  100. }
  101. // ==================== ACCESS =======================
  102. Complex GetYm() {
  103. return yh(layr);
  104. }
  105. Complex GetZm() {
  106. return zh(layr);
  107. }
  108. Complex GetZs() {
  109. return zh(lays);
  110. }
  111. Complex GetKs() {
  112. return kk(lays);
  113. }
  114. // ==================== INQUIRY =======================
  115. protected:
  116. // ==================== LIFECYCLE =======================
  117. /// Default protected constructor.
  118. KernelEM1DReflBase (const std::string& name) : LemmaObject(name)
  119. {
  120. }
  121. /// Default protected constructor.
  122. ~KernelEM1DReflBase () {
  123. if (this->NumberOfReferences > 0)
  124. throw DeleteObjectWithReferences( this );
  125. }
  126. void Release() {
  127. delete this;
  128. }
  129. // ==================== OPERATIONS =======================
  130. /** Computes reflection coefficients. Depending on the
  131. * specialisation, this will either be TM or TE mode.
  132. */
  133. virtual void ComputeReflectionCoeffs(const Real& lambda)=0;
  134. /** Precomputes expensive calculations that are reused by insances
  135. * of KernelEM1DSpec in the calculation of Related potentials.
  136. */
  137. virtual void PreComputePotentialTerms()=0;
  138. // ==================== DATA MEMBERS =========================
  139. /// Bessel order, only 0 or 1 supported
  140. int id; // Needs to be dim nRel, or separate
  141. /// Layer the source is in
  142. int lays;
  143. /// Layer the receiver is in
  144. int layr;
  145. /// Number of Layers
  146. int nlay;
  147. /// Number of Related kernels to be computed
  148. int nRelated;
  149. /// Used in related kernel precompute calls
  150. int relIud;
  151. /// Receiver z position
  152. Real rx_z;
  153. /// Transmitter z position
  154. Real tx_z;
  155. /// bessel arg squared
  156. Real rams;
  157. /** Related part of con term */
  158. Complex relCon;
  159. Complex relenukadz;
  160. Complex relexp_pbs1;
  161. Complex relexp_pbs2;
  162. Complex rel_a;
  163. /// TM or TE mode
  164. EMMODE mode;
  165. /// Pointer to layered earth
  166. LayeredEarthEM *Earth;
  167. Complex uk;
  168. Complex um;
  169. VectorXcr cf; // nlay
  170. VectorXcr u; // nlay
  171. VectorXcr yh; // nlay
  172. VectorXcr zh; // nlay
  173. VectorXcr kk; // nlay
  174. VectorXcr Zyu; //(nlay); //Zyu.setZero();
  175. VectorXcr Zyd; //(nlay); //Zyd.setZero();
  176. VectorXcr Zyi; //(nlay); //Zyi.setZero();
  177. VectorXcr th; //(nlay);
  178. VectorXr LayerThickness;
  179. VectorXr LayerDepth;
  180. /// Reflection/Transmission coeffients for upgoing waves in a
  181. /// layered earth model
  182. VectorXcr rtu;
  183. /// Reflection/Transmission coeffients for downgoing waves in
  184. /// a layered earth model
  185. VectorXcr rtd;
  186. private:
  187. }; // ----- end of class KernelEM1DReflBase -----
  188. } // ----- end of Lemma name -----
  189. #endif // ----- #ifndef KERNELEM1DREFLBASE_INC -----