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.

KernelV0.h 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. * @version $Id$
  12. * @author Trevor Irons (ti)
  13. * @email tirons@egi.utah.edu
  14. * @copyright Copyright (c) 2016, University of Utah
  15. * @copyright Copyright (c) 2016, Lemma Software, LLC
  16. */
  17. #ifndef KERNELV0_INC
  18. #define KERNELV0_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. #endif
  29. namespace Lemma {
  30. /**
  31. * \ingroup Merlin
  32. * \brief
  33. * \details
  34. */
  35. class KernelV0 : public LemmaObject {
  36. friend std::ostream &operator<<(std::ostream &stream, const KernelV0 &ob);
  37. protected:
  38. /*
  39. * This key is used to lock the constructor. It is protected so that inhereted
  40. * classes also have the key to contruct their base class.
  41. */
  42. struct ctor_key {};
  43. public:
  44. // ==================== LIFECYCLE =======================
  45. /**
  46. * Default constructor.
  47. * @note This method is locked, and cannot be called directly.
  48. * The reason that the method is public is to enable the use
  49. * of make_shared whilst enforcing the use of shared_ptr,
  50. * in c++-17, this curiosity may be resolved.
  51. * @see KernelV0::NewSP
  52. */
  53. explicit KernelV0 ( const ctor_key& );
  54. /**
  55. * DeSerializing constructor.
  56. * @note This method is locked, and cannot be called directly.
  57. * The reason that the method is public is to enable the use
  58. * of make_shared whilst enforcing the use of shared_ptr,
  59. * in c++-17, this curiosity may be resolved.
  60. * @see KernelV0::DeSerialize
  61. */
  62. KernelV0 ( const YAML::Node& node, const ctor_key& );
  63. /**
  64. * Default destructor.
  65. * @note This method should never be called due to the mandated
  66. * use of smart pointers. It is necessary to keep the method
  67. * public in order to allow for the use of the more efficient
  68. * make_shared constructor.
  69. */
  70. virtual ~KernelV0 ();
  71. /**
  72. * Uses YAML to serialize this object.
  73. * @return a YAML::Node
  74. * @see KernelV0::DeSerialize
  75. */
  76. virtual YAML::Node Serialize() const;
  77. /*
  78. * Factory method for generating concrete class.
  79. * @return a std::shared_ptr of type KernelV0
  80. */
  81. static std::shared_ptr< KernelV0 > NewSP();
  82. /**
  83. * Constructs an KernelV0 object from a YAML::Node.
  84. * @see KernelV0::Serialize
  85. */
  86. static std::shared_ptr<KernelV0> DeSerialize(const YAML::Node& node);
  87. // ==================== OPERATORS =======================
  88. // ==================== OPERATIONS =======================
  89. /**
  90. * @return std::shared_ptr<LayeredEarthEM>
  91. */
  92. inline std::shared_ptr<LayeredEarthEM> GetSigmaModel ( ) {
  93. return SigmaModel;
  94. } // ----- end of method KernelV0::get_SigmaModel -----
  95. /**
  96. * @param[in] value the 1D-EM model used for calculations
  97. */
  98. inline void SetLayeredEarthEM ( std::shared_ptr< LayeredEarthEM > value ) {
  99. SigmaModel = value;
  100. return ;
  101. } // ----- end of method KernelV0::set_SigmaModel -----
  102. /**
  103. * Assign transmiter coils
  104. */
  105. inline void PushCoil( const std::string& label, std::shared_ptr<PolygonalWireAntenna> ant ) {
  106. TxRx[label] = ant;
  107. }
  108. /**
  109. * Calculates a single imaging kernel, however, phased arrays are supported
  110. * so that more than one transmitter and/or receiver can be specified.
  111. * @param[in] tx is the list of transmitters to use for a kernel, use the same labels as
  112. * used in PushCoil.
  113. * @param[in] rx is the list of receivers to use for a kernel, use the same labels as
  114. * used in PushCoil. @see PushCoil
  115. * @param[in] vtkOutput generates a VTK hyperoctree file as well, useful for visualization.
  116. * requires compilation of Lemma with VTK.
  117. */
  118. void CalculateK0 (const std::vector< std::string >& tx, const std::vector< std::string >& rx,
  119. bool vtkOutput=false );
  120. // ==================== INQUIRY =======================
  121. /**
  122. * Returns the name of the underlying class, similiar to Python's type
  123. * @return string of class name
  124. */
  125. virtual inline std::string GetName() const {
  126. return CName;
  127. }
  128. protected:
  129. // ==================== LIFECYCLE =======================
  130. /** Copy is disabled */
  131. KernelV0( const KernelV0& ) = delete;
  132. private:
  133. /**
  134. * Returns the kernel value for an input prism
  135. */
  136. Complex f( const Vector3r& r, const Real& volume , const Vector3cr& Bt);
  137. void IntegrateOnOctreeGrid( const Real& tolerance , bool vtkOutput=false );
  138. /**
  139. * Recursive call to integrate a function on an adaptive Octree Grid.
  140. * For efficiency's sake the octree grid is not stored, as only the
  141. * integral (sum) is of interest. The logic for grid refinement is based
  142. * on an Octree representation of the domain. If an Octree representation
  143. * of the kernel is desired, call alternative version @see EvaluateKids2
  144. * @param[in] size gives the domain size, in metres
  145. * @param[in] level gives the current level of the octree grid, call with 0 initially
  146. * @param[in] cpos is the centre position of the parent cuboid
  147. */
  148. bool EvaluateKids( const Vector3r& size, const int& level, const Vector3r& cpos,
  149. const Complex& parentVal );
  150. #ifdef LEMMAUSEVTK
  151. /**
  152. * Same functionality as @see EvaluateKids, but includes generation of a VTK
  153. * HyperOctree, which is useful for visualization.
  154. */
  155. bool EvaluateKids2( const Vector3r& size, const int& level, const Vector3r& cpos,
  156. const Complex& parentVal, vtkHyperOctree* octree, vtkHyperOctreeCursor* curse );
  157. #endif
  158. // ==================== DATA MEMBERS =========================
  159. Complex SUM;
  160. Real tol=1e-3;
  161. int nleaves;
  162. std::shared_ptr< LayeredEarthEM > SigmaModel = nullptr;
  163. std::map< std::string , std::shared_ptr< PolygonalWireAntenna > > TxRx;
  164. std::vector< std::shared_ptr<EMEarth1D> > EMEarths;
  165. #ifdef LEMMAUSEVTK
  166. std::map< int, Complex > LeafDict;
  167. #endif
  168. /** ASCII string representation of the class name */
  169. static constexpr auto CName = "KernelV0";
  170. }; // ----- end of class KernelV0 -----
  171. } // ----- end of namespace Lemma ----
  172. /* vim: set tabstop=4 expandtab */
  173. /* vim: set filetype=cpp */
  174. #endif // ----- #ifndef KERNELV0_INC -----