Surface NMR forward modelling
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

KernelV0.h 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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 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. #include "vtkDoubleArray.h"
  29. #endif
  30. namespace Lemma {
  31. // Holds the elliptic field construction of Bperp
  32. // commented out variables are for error checking
  33. struct EllipticB {
  34. Real alpha;
  35. Real beta;
  36. Real zeta;
  37. // Real err;
  38. Complex eizt;
  39. // Complex BperpdotB;
  40. Vector3r bhat;
  41. Vector3r bhatp;
  42. // Vector3cr Bperp;
  43. };
  44. template <typename T> int sgn(T val) {
  45. return (val > T(0)) - (val < T(0));
  46. }
  47. /**
  48. * \ingroup Merlin
  49. * \brief
  50. * \details
  51. */
  52. class KernelV0 : public LemmaObject {
  53. friend std::ostream &operator<<(std::ostream &stream, const KernelV0 &ob);
  54. protected:
  55. /*
  56. * This key is used to lock the constructor. It is protected so that inhereted
  57. * classes also have the key to contruct their base class.
  58. */
  59. struct ctor_key {};
  60. public:
  61. // ==================== LIFECYCLE =======================
  62. /**
  63. * Default constructor.
  64. * @note This method is locked, and cannot be called directly.
  65. * The reason that the method is public is to enable the use
  66. * of make_shared whilst enforcing the use of shared_ptr,
  67. * in c++-17, this curiosity may be resolved.
  68. * @see KernelV0::NewSP
  69. */
  70. explicit KernelV0 ( const ctor_key& );
  71. /**
  72. * DeSerializing constructor.
  73. * @note This method is locked, and cannot be called directly.
  74. * The reason that the method is public is to enable the use
  75. * of make_shared whilst enforcing the use of shared_ptr,
  76. * in c++-17, this curiosity may be resolved.
  77. * @see KernelV0::DeSerialize
  78. */
  79. KernelV0 ( const YAML::Node& node, const ctor_key& );
  80. /**
  81. * Default destructor.
  82. * @note This method should never be called due to the mandated
  83. * use of smart pointers. It is necessary to keep the method
  84. * public in order to allow for the use of the more efficient
  85. * make_shared constructor.
  86. */
  87. virtual ~KernelV0 ();
  88. /**
  89. * Uses YAML to serialize this object.
  90. * @return a YAML::Node
  91. * @see KernelV0::DeSerialize
  92. */
  93. virtual YAML::Node Serialize() const;
  94. /*
  95. * Factory method for generating concrete class.
  96. * @return a std::shared_ptr of type KernelV0
  97. */
  98. static std::shared_ptr< KernelV0 > NewSP();
  99. /**
  100. * Constructs an KernelV0 object from a YAML::Node.
  101. * @see KernelV0::Serialize
  102. */
  103. static std::shared_ptr<KernelV0> DeSerialize(const YAML::Node& node);
  104. // ==================== OPERATORS =======================
  105. // ==================== OPERATIONS =======================
  106. /**
  107. * @return std::shared_ptr<LayeredEarthEM>
  108. */
  109. inline std::shared_ptr<LayeredEarthEM> GetSigmaModel ( ) {
  110. return SigmaModel;
  111. } // ----- end of method KernelV0::get_SigmaModel -----
  112. /**
  113. * @return the kernel matrix
  114. */
  115. inline MatrixXcr GetKernel ( ) {
  116. return Kern;
  117. }
  118. /**
  119. * @param[in] value the 1D-EM model used for calculations
  120. */
  121. inline void SetLayeredEarthEM ( std::shared_ptr< LayeredEarthEM > value ) {
  122. SigmaModel = value;
  123. return ;
  124. } // ----- end of method KernelV0::set_SigmaModel -----
  125. /**
  126. *
  127. */
  128. inline void SetIntegrationSize ( const Vector3r& size ) {
  129. Size = size;
  130. return ;
  131. } // ----- end of method KernelV0::SetIntegrationSize -----
  132. /**
  133. *
  134. */
  135. inline void SetIntegrationOrigin ( const Vector3r& origin ) {
  136. Origin = origin;
  137. return ;
  138. } // ----- end of method KernelV0::SetIntegrationOrigin -----
  139. /**
  140. *
  141. */
  142. inline void SetPulseCurrent ( const VectorXr& Amps ) {
  143. PulseI = Amps;
  144. return ;
  145. } // ----- end of method KernelV0::SetIntegrationOrigin -----
  146. /**
  147. * Aligns the kernel settings with an Akvo Processed dataset.
  148. */
  149. void AlignWithAkvoDataset( const YAML::Node& node ) ;
  150. /**
  151. * Assign transmiter coils
  152. */
  153. inline void PushCoil( const std::string& label, std::shared_ptr<PolygonalWireAntenna> ant ) {
  154. TxRx[label] = ant;
  155. }
  156. /**
  157. * Calculates a single imaging kernel, however, phased arrays are supported
  158. * so that more than one transmitter and/or receiver can be specified.
  159. * @param[in] tx is the list of transmitters to use for a kernel, use the same labels as
  160. * used in PushCoil.
  161. * @param[in] rx is the list of receivers to use for a kernel, use the same labels as
  162. * used in PushCoil. @see PushCoil
  163. * @param[in] vtkOutput generates a VTK hyperoctree file as well, useful for visualization.
  164. * requires compilation of Lemma with VTK. The VTK files can become very large.
  165. */
  166. void CalculateK0 (const std::vector< std::string >& tx, const std::vector< std::string >& rx,
  167. bool vtkOutput=false );
  168. /**
  169. * Sets the temperature, which has implications in calculation of \f$ M_N^{(0)}\f$. Units in
  170. * Kelvin.
  171. */
  172. inline void SetTemperature(const Real& tempK) {
  173. Temperature = tempK;
  174. }
  175. /**
  176. * Sets the tolerance to use for making the adaptive mesh
  177. *
  178. */
  179. inline void SetTolerance(const Real& ttol) {
  180. tol = ttol;
  181. }
  182. inline void SetPulseDuration(const Real& taup) {
  183. Taup = taup;
  184. }
  185. inline Real GetPulseDuration( ) {
  186. return Taup;
  187. }
  188. inline void SetDepthLayerInterfaces( const VectorXr& iface ){
  189. Interfaces = iface;
  190. }
  191. // ==================== INQUIRY =======================
  192. /**
  193. * Returns the name of the underlying class, similiar to Python's type
  194. * @return string of class name
  195. */
  196. virtual inline std::string GetName() const {
  197. return CName;
  198. }
  199. protected:
  200. // ==================== LIFECYCLE =======================
  201. /** Copy is disabled */
  202. KernelV0( const KernelV0& ) = delete;
  203. private:
  204. /**
  205. * Returns the kernel value for an input prism
  206. */
  207. VectorXcr f( const Vector3r& r, const Real& volume , const Vector3cr& Ht, const Vector3cr& Hr);
  208. // Complex ComputeV0Cell(const EllipticB& EBT, const EllipticB& EBR,
  209. // const Real& sintheta, const Real& phase, const Real& Mn0Abs,
  210. // const Real& vol);
  211. EllipticB EllipticFieldRep (const Vector3cr& B, const Vector3r& B0hat);
  212. Vector3r ComputeMn0(const Real& Porosity, const Vector3r& B0);
  213. void IntegrateOnOctreeGrid( bool vtkOutput=false );
  214. /**
  215. * Recursive call to integrate a function on an adaptive Octree Grid.
  216. * For efficiency's sake the octree grid is not stored, as only the
  217. * integral (sum) is of interest. The logic for grid refinement is based
  218. * on an Octree representation of the domain. If an Octree representation
  219. * of the kernel is desired, call alternative version @see EvaluateKids2
  220. * @param[in] size gives the domain size, in metres
  221. * @param[in] level gives the current level of the octree grid, call with 0 initially
  222. * @param[in] cpos is the centre position of the parent cuboid
  223. */
  224. void EvaluateKids( const Vector3r& size, const int& level, const Vector3r& cpos,
  225. const VectorXcr& parentVal );
  226. #ifdef LEMMAUSEVTK
  227. /**
  228. * Same functionality as @see EvaluateKids, but includes generation of a VTK
  229. * HyperOctree, which is useful for visualization.
  230. */
  231. void EvaluateKids2( const Vector3r& size, const int& level, const Vector3r& cpos,
  232. const VectorXcr& parentVal, vtkHyperOctree* octree, vtkHyperOctreeCursor* curse );
  233. void GetPosition( vtkHyperOctreeCursor* Cursor, Real* p );
  234. #endif
  235. // ==================== DATA MEMBERS =========================
  236. int ilay;
  237. int nleaves;
  238. int minLevel=0;
  239. int maxLevel=12;
  240. Real VOLSUM;
  241. Real tol=1e-11;
  242. Real Temperature=283.;
  243. Real Taup = .020; // Sec
  244. Real Larmor;
  245. Vector3r Size;
  246. Vector3r Origin;
  247. VectorXr PulseI;
  248. VectorXr Interfaces;
  249. MatrixXcr Kern;
  250. std::shared_ptr< LayeredEarthEM > SigmaModel = nullptr;
  251. std::shared_ptr< FieldPoints > cpoints;
  252. std::map< std::string , std::shared_ptr< PolygonalWireAntenna > > TxRx;
  253. std::map< std::string , std::shared_ptr< EMEarth1D > > EMEarths;
  254. #ifdef LEMMAUSEVTK
  255. std::map< int, VectorXcr > LeafDict; // kernel sum for each q
  256. std::map< int, VectorXcr > LeafHt; // Transmitter field
  257. std::map< int, VectorXcr > LeafHr; // Receiver field
  258. std::map< int, int > LeafDictIdx; // index
  259. std::map< int, Real > LeafDictErr; // error value
  260. #endif
  261. // Physical constants and conversion factors
  262. static constexpr Real GAMMA = 2.67518e8; // MKS units
  263. static constexpr Real INVSQRT2 = 0.70710678118654746; // 1/sqrt(2)
  264. static constexpr Real HBAR = 1.05457148e-34; // m2 kg / s
  265. static constexpr Real NH2O = 6.692e28; // [m^3]
  266. static constexpr Real KB = 1.3805e-23; // m^2 kg s-2 K-1
  267. static constexpr Real CHI_N = 3.29e-3; // MKS units
  268. /** ASCII string representation of the class name */
  269. static constexpr auto CName = "KernelV0";
  270. }; // ----- end of class KernelV0 -----
  271. } // ----- end of namespace Lemma ----
  272. /* vim: set tabstop=4 expandtab */
  273. /* vim: set filetype=cpp */
  274. #endif // ----- #ifndef KERNELV0_INC -----