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.

LayeredEarthMR.cpp 8.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 08/28/2017 03:32:34 PM
  11. * @version $Id$
  12. * @author Trevor Irons (ti)
  13. * @email tirons@egi.utah.edu
  14. * @copyright Copyright (c) 2017, University of Utah
  15. * @copyright Copyright (c) 2017, Lemma Software, LLC
  16. */
  17. #include "LayeredEarthMR.h"
  18. namespace Lemma {
  19. // ==================== FRIEND METHODS =====================
  20. std::ostream &operator << (std::ostream &stream, const LayeredEarthMR &ob) {
  21. stream << ob.Serialize() << "\n"; // End of doc ---
  22. return stream;
  23. }
  24. // ==================== LIFECYCLE =======================
  25. //--------------------------------------------------------------------------------------
  26. // Class: LayeredEarthMR
  27. // Method: LayeredEarthMR
  28. // Description: constructor (locked)
  29. //--------------------------------------------------------------------------------------
  30. LayeredEarthMR::LayeredEarthMR (const ctor_key& key) : LayeredEarth( key ) {
  31. } // ----- end of method LayeredEarthMR::LayeredEarthMR (constructor) -----
  32. //--------------------------------------------------------------------------------------
  33. // Class: LayeredEarthMR
  34. // Method: LayeredEarthMR
  35. // Description: DeSerializing constructor (locked)
  36. //--------------------------------------------------------------------------------------
  37. LayeredEarthMR::LayeredEarthMR (const YAML::Node& node, const ctor_key& key) : LayeredEarth(node, key) {
  38. Interfaces = node["Interfaces"].as<VectorXr>();
  39. T2StarBins = node["T2StarBins"].as<VectorXr>();
  40. T2StarBinEdges = node["T2StarBinEdges"].as<VectorXr>();
  41. ModelMat = node["ModelMat"].as<MatrixXr>();
  42. } // ----- end of method LayeredEarthMR::LayeredEarthMR (constructor) -----
  43. //--------------------------------------------------------------------------------------
  44. // Class: LayeredEarthMR
  45. // Method: NewSP()
  46. // Description: public constructor returing a shared_ptr
  47. //--------------------------------------------------------------------------------------
  48. std::shared_ptr< LayeredEarthMR > LayeredEarthMR::NewSP() {
  49. return std::make_shared< LayeredEarthMR >( ctor_key() );
  50. }
  51. //--------------------------------------------------------------------------------------
  52. // Class: LayeredEarthMR
  53. // Method: ~LayeredEarthMR
  54. // Description: destructor (protected)
  55. //--------------------------------------------------------------------------------------
  56. LayeredEarthMR::~LayeredEarthMR () {
  57. } // ----- end of method LayeredEarthMR::~LayeredEarthMR (destructor) -----
  58. //--------------------------------------------------------------------------------------
  59. // Class: LayeredEarthMR
  60. // Method: Serialize
  61. //--------------------------------------------------------------------------------------
  62. YAML::Node LayeredEarthMR::Serialize ( ) const {
  63. YAML::Node node = LayeredEarth::Serialize();
  64. node.SetTag( GetName() );
  65. // FILL IN CLASS SPECIFICS HERE
  66. node["Merlin_VERSION"] = MERLIN_VERSION;
  67. node["Interfaces"] = Interfaces;
  68. node["T2StarBins"] = T2StarBins;
  69. node["T2StarBinEdges"] = T2StarBinEdges;
  70. node["ModelMat"] = ModelMat;
  71. return node;
  72. } // ----- end of method LayeredEarthMR::Serialize -----
  73. //--------------------------------------------------------------------------------------
  74. // Class: LayeredEarthMR
  75. // Method: DeSerialize
  76. //--------------------------------------------------------------------------------------
  77. std::shared_ptr<LayeredEarthMR> LayeredEarthMR::DeSerialize ( const YAML::Node& node ) {
  78. if (node.Tag() != "LayeredEarthMR" ) {
  79. throw DeSerializeTypeMismatch( "LayeredEarthMR", node.Tag());
  80. }
  81. return std::make_shared< LayeredEarthMR > ( node, ctor_key() );
  82. } // ----- end of method LayeredEarthMR::DeSerialize -----
  83. //--------------------------------------------------------------------------------------
  84. // Class: LayeredEarthMR
  85. // Method: SetNumberOfLayers
  86. //--------------------------------------------------------------------------------------
  87. void LayeredEarthMR::SetNumberOfLayers ( const int& nlay ) {
  88. NumberOfLayers = nlay;
  89. NumberOfInterfaces = nlay+1;
  90. return ;
  91. } // ----- end of method LayeredEarthMR::SetNumberOfLayers -----
  92. //--------------------------------------------------------------------------------------
  93. // Class: LayeredEarthMR
  94. // Method: AlignWithKernel
  95. //--------------------------------------------------------------------------------------
  96. void LayeredEarthMR::AlignWithKernel ( std::shared_ptr<KernelV0> Kern ) {
  97. int nlay = Kern->GetInterfaces().size()-1;
  98. SetNumberOfLayers( nlay );
  99. Interfaces = Kern->GetInterfaces();
  100. LayerThickness = Kern->GetInterfaces().tail(nlay) - Kern->GetInterfaces().head(nlay) ;
  101. SetMagneticFieldComponents( Kern->GetSigmaModel()->GetMagneticField(), TESLA);
  102. return ;
  103. } // ----- end of method LayeredEarthMR::AlignWithKernel -----
  104. //--------------------------------------------------------------------------------------
  105. // Class: LayeredEarthMR
  106. // Method: SetNumberOfT2StarBins
  107. //--------------------------------------------------------------------------------------
  108. void LayeredEarthMR::SetT2StarBins ( const Real& first, const Real& last, const int& nT2 ) {
  109. T2StarBinEdges = VectorXr::Zero(nT2+1);
  110. Real m = 1./(nT2);
  111. Real quotient = std::pow(last/first, m);
  112. T2StarBinEdges[0] = first;
  113. for (int i=1; i<nT2+1; ++i) {
  114. T2StarBinEdges[i] = T2StarBinEdges[i-1]*quotient;
  115. }
  116. T2StarBins = (T2StarBinEdges.head(nT2) + T2StarBinEdges.tail(nT2)) / 2;
  117. InitModelMat();
  118. return;
  119. } // ----- end of method LayeredEarthMR::SetNumberOfT2StarBins -----
  120. //--------------------------------------------------------------------------------------
  121. // Class: LayeredEarthMR
  122. // Method: InitModelMat
  123. //--------------------------------------------------------------------------------------
  124. void LayeredEarthMR::InitModelMat ( ) {
  125. ModelMat = MatrixXr::Zero( NumberOfLayers, T2StarBins.size() );
  126. return ;
  127. } // ----- end of method LayeredEarthMR::InitModelMat -----
  128. //--------------------------------------------------------------------------------------
  129. // Class: LayeredEarthMR
  130. // Method: GetT2StarBins
  131. //--------------------------------------------------------------------------------------
  132. VectorXr LayeredEarthMR::GetT2StarBins ( ) {
  133. return T2StarBins ;
  134. } // ----- end of method LayeredEarthMR::GetT2StarBins -----
  135. //--------------------------------------------------------------------------------------
  136. // Class: LayeredEarthMR
  137. // Method: GetModelMatrix
  138. //--------------------------------------------------------------------------------------
  139. MatrixXr LayeredEarthMR::GetModelMatrix ( ) {
  140. return ModelMat ;
  141. } // ----- end of method LayeredEarthMR::GetModelMatrix -----
  142. //--------------------------------------------------------------------------------------
  143. // Class: LayeredEarthMR
  144. // Method: GetModelVector
  145. //--------------------------------------------------------------------------------------
  146. VectorXr LayeredEarthMR::GetModelVector ( ) {
  147. //VectorXr B(Eigen::Map<VectorXr>(ModelMat.data(), ModelMat.cols()*ModelMat.rows()));
  148. MatrixXr MT = ModelMat.transpose();
  149. VectorXr B(Eigen::Map<VectorXr>(MT.data(), MT.cols()*MT.rows()));
  150. //VectorXr B(Eigen::Map<VectorXr>(ModelMat.transpose().data(), ModelMat.cols()*ModelMat.rows()));
  151. return B;
  152. } // ----- end of method LayeredEarthMR::GetModelVector -----
  153. } // ---- end of namespace Lemma ----
  154. /* vim: set tabstop=4 expandtab: */
  155. /* vim: set filetype=cpp: */