Surface NMR forward modelling
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.

Coupling.h 8.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /* This file is part of Lemma, a geophysical modelling and inversion API.
  2. * More information is available at http://lemmasoftware.org
  3. */
  4. /* This Source Code Form is subject to the terms of the Mozilla Public
  5. * License, v. 2.0. If a copy of the MPL was not distributed with this
  6. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  7. */
  8. /**
  9. * @file
  10. * @date 11/11/2016 01:47:34 PM
  11. * @author Trevor Irons (ti)
  12. * @email tirons@egi.utah.edu
  13. * @copyright Copyright (c) 2016, University of Utah
  14. * @copyright Copyright (c) 2016, Lemma Software, LLC
  15. * @copyright Copyright (c) 2008, Colorado School of Mines
  16. */
  17. #ifndef COUPLING_INC
  18. #define COUPLING_INC
  19. #pragma once
  20. #include "LemmaObject.h"
  21. #include "LayeredEarthEM.h"
  22. #include "PolygonalWireAntenna.h"
  23. #include "EMEarth1D.h"
  24. #ifdef LEMMAUSEVTK
  25. #include "vtkHyperOctree.h"
  26. #include "vtkHyperOctreeCursor.h"
  27. #include "vtkXMLHyperOctreeWriter.h"
  28. #include "vtkDoubleArray.h"
  29. #endif
  30. namespace Lemma {
  31. /**
  32. * \ingroup Merlin
  33. * \brief
  34. * \details
  35. */
  36. class Coupling : public LemmaObject {
  37. friend std::ostream &operator<<(std::ostream &stream, const Coupling &ob);
  38. public:
  39. // ==================== LIFECYCLE =======================
  40. /**
  41. * Default constructor.
  42. * @note This method is locked, and cannot be called directly.
  43. * The reason that the method is public is to enable the use
  44. * of make_shared whilst enforcing the use of shared_ptr,
  45. * in c++-17, this curiosity may be resolved.
  46. * @see Coupling::NewSP
  47. */
  48. explicit Coupling ( const ctor_key& );
  49. /**
  50. * DeSerializing constructor.
  51. * @note This method is locked, and cannot be called directly.
  52. * The reason that the method is public is to enable the use
  53. * of make_shared whilst enforcing the use of shared_ptr,
  54. * in c++-17, this curiosity may be resolved.
  55. * @see Coupling::DeSerialize
  56. */
  57. Coupling ( const YAML::Node& node, const ctor_key& );
  58. /**
  59. * Default destructor.
  60. * @note This method should never be called due to the mandated
  61. * use of smart pointers. It is necessary to keep the method
  62. * public in order to allow for the use of the more efficient
  63. * make_shared constructor.
  64. */
  65. virtual ~Coupling ();
  66. /**
  67. * Uses YAML to serialize this object.
  68. * @return a YAML::Node
  69. * @see Coupling::DeSerialize
  70. */
  71. virtual YAML::Node Serialize() const;
  72. /*
  73. * Factory method for generating concrete class.
  74. * @return a std::shared_ptr of type Coupling
  75. */
  76. static std::shared_ptr< Coupling > NewSP();
  77. /**
  78. * Constructs an Coupling object from a YAML::Node.
  79. * @see Coupling::Serialize
  80. */
  81. static std::shared_ptr<Coupling> DeSerialize(const YAML::Node& node);
  82. // ==================== OPERATORS =======================
  83. // ==================== OPERATIONS =======================
  84. /**
  85. * @return std::shared_ptr<LayeredEarthEM>
  86. */
  87. inline std::shared_ptr<LayeredEarthEM> GetSigmaModel ( ) {
  88. return SigmaModel;
  89. } // ----- end of method Coupling::get_SigmaModel -----
  90. /**
  91. * @param[in] value the 1D-EM model used for calculations
  92. */
  93. inline void SetLayeredEarthEM ( std::shared_ptr< LayeredEarthEM > value ) {
  94. SigmaModel = value;
  95. return ;
  96. } // ----- end of method Coupling::set_SigmaModel -----
  97. /**
  98. *
  99. */
  100. inline void SetIntegrationSize ( const Vector3r& size ) {
  101. Size = size;
  102. return ;
  103. } // ----- end of method Coupling::SetIntegrationSize -----
  104. /**
  105. *
  106. */
  107. inline void SetIntegrationOrigin ( const Vector3r& origin ) {
  108. Origin = origin;
  109. return ;
  110. } // ----- end of method Coupling::SetIntegrationOrigin -----
  111. /**
  112. * Assign transmiter coils
  113. */
  114. inline void PushCoil( const std::string& label, std::shared_ptr<PolygonalWireAntenna> ant ) {
  115. TxRx[label] = ant;
  116. }
  117. /**
  118. * Calculates a single imaging kernel, however, phased arrays are supported
  119. * so that more than one transmitter and/or receiver can be specified.
  120. * @param[in] tx is the list of transmitters to use for a kernel, use the same labels as
  121. * used in PushCoil.
  122. * @param[in] rx is the list of receivers to use for a kernel, use the same labels as
  123. * used in PushCoil. @see PushCoil
  124. * @param[in] vtkOutput generates a VTK hyperoctree file as well, useful for visualization.
  125. * requires compilation of Lemma with VTK.
  126. */
  127. Complex Calculate (const std::vector< std::string >& tx, const std::vector< std::string >& rx,
  128. bool vtkOutput=false );
  129. /**
  130. * Sets the tolerance to use for making the adaptive mesh
  131. *
  132. */
  133. inline void SetTolerance(const Real& ttol) {
  134. tol = ttol;
  135. }
  136. inline void SetPulseDuration(const Real& taup) {
  137. Taup = taup;
  138. }
  139. // ==================== INQUIRY =======================
  140. /**
  141. * Returns the name of the underlying class, similiar to Python's type
  142. * @return string of class name
  143. */
  144. virtual inline std::string GetName() const {
  145. return CName;
  146. }
  147. protected:
  148. // ==================== LIFECYCLE =======================
  149. /** Copy is disabled */
  150. Coupling( const Coupling& ) = delete;
  151. private:
  152. /**
  153. * Returns the kernel value for an input prism
  154. */
  155. Complex f( const Vector3r& r, const Real& volume , const Vector3cr& Ht, const Vector3cr& Hr);
  156. void IntegrateOnOctreeGrid( bool vtkOutput=false );
  157. /**
  158. * Recursive call to integrate a function on an adaptive Octree Grid.
  159. * For efficiency's sake the octree grid is not stored, as only the
  160. * integral (sum) is of interest. The logic for grid refinement is based
  161. * on an Octree representation of the domain. If an Octree representation
  162. * of the kernel is desired, call alternative version @see EvaluateKids2
  163. * @param[in] size gives the domain size, in metres
  164. * @param[in] level gives the current level of the octree grid, call with 0 initially
  165. * @param[in] cpos is the centre position of the parent cuboid
  166. */
  167. void EvaluateKids( const Vector3r& size, const int& level, const Vector3r& cpos,
  168. const Complex& parentVal );
  169. #ifdef LEMMAUSEVTK
  170. /**
  171. * Same functionality as @see EvaluateKids, but includes generation of a VTK
  172. * HyperOctree, which is useful for visualization.
  173. */
  174. void EvaluateKids2( const Vector3r& size, const int& level, const Vector3r& cpos,
  175. const Complex& parentVal, vtkHyperOctree* octree, vtkHyperOctreeCursor* curse );
  176. void GetPosition( vtkHyperOctreeCursor* Cursor, Real* p );
  177. #endif
  178. // ==================== DATA MEMBERS =========================
  179. int ilay;
  180. int nleaves;
  181. int minLevel=4;
  182. int maxLevel=8;
  183. Real VOLSUM;
  184. Real tol=1e-11;
  185. Real Taup = .020; // Sec
  186. Complex SUM;
  187. Vector3r Size;
  188. Vector3r Origin;
  189. std::shared_ptr< LayeredEarthEM > SigmaModel = nullptr;
  190. std::shared_ptr< FieldPoints > cpoints;
  191. std::map< std::string , std::shared_ptr< PolygonalWireAntenna > > TxRx;
  192. std::map< std::string , std::shared_ptr< EMEarth1D > > EMEarths;
  193. #ifdef LEMMAUSEVTK
  194. std::map< int, Complex > LeafDict;
  195. std::map< int, int > LeafDictIdx;
  196. std::map< int, Real > LeafDictErr;
  197. #endif
  198. /** ASCII string representation of the class name */
  199. static constexpr auto CName = "Coupling";
  200. }; // ----- end of class Coupling -----
  201. } // ----- end of namespace Lemma ----
  202. /* vim: set tabstop=4 expandtab */
  203. /* vim: set filetype=cpp */
  204. #endif // ----- #ifndef COUPLING_INC -----