Main Lemma Repository
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.

LayeredEarthEM.cpp 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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 06/24/2009
  9. @version $Id: layeredearthem.cpp 216 2015-03-09 02:26:49Z tirons $
  10. **/
  11. #include "LayeredEarthEM.h"
  12. namespace Lemma {
  13. std::ostream &operator << (std::ostream &stream, const LayeredEarthEM &ob) {
  14. stream << ob.Serialize() << "\n---\n"; // End of doc --- as a direct stream should encapulste thingy
  15. return stream;
  16. }
  17. // ==================== LIFECYCLE ===================================
  18. LayeredEarthEM::LayeredEarthEM( ) : LayeredEarth() {
  19. }
  20. LayeredEarthEM::~LayeredEarthEM() {
  21. }
  22. std::shared_ptr<LayeredEarthEM> LayeredEarthEM::NewSP() {
  23. std::shared_ptr<LayeredEarthEM> sp(new LayeredEarthEM( ), LemmaObjectDeleter() );
  24. return sp;
  25. }
  26. YAML::Node LayeredEarthEM::Serialize() const {
  27. YAML::Node node = LayeredEarth::Serialize();
  28. node.SetTag( GetName() );
  29. node["LayerConductivity"] = LayerConductivity;
  30. node["LayerSusceptibility"] = LayerSusceptibility;
  31. node["LayerLowFreqSusceptibility"] = LayerLowFreqSusceptibility;
  32. node["LayerHighFreqSusceptibility"] = LayerHighFreqSusceptibility;
  33. node["LayerTauSusceptibility"] = LayerTauSusceptibility;
  34. node["LayerBreathSusceptibility"] = LayerBreathSusceptibility;
  35. node["LayerPermitivity"] = LayerPermitivity;
  36. node["LayerLowFreqPermitivity"] = LayerLowFreqPermitivity;
  37. node["LayerHighFreqPermitivity"] = LayerHighFreqPermitivity;
  38. node["LayerTauPermitivity"] = LayerTauPermitivity;
  39. node["LayerBreathPermitivity"] = LayerBreathPermitivity;
  40. return node;
  41. }
  42. // ==================== OPERATIONS ===================================
  43. void LayeredEarthEM::EvaluateColeColeModel(const Real& omega) {
  44. for (int ilay=0; ilay<GetNumberOfLayers(); ++ilay) {
  45. if ( LayerTauSusceptibility(ilay) > 1e-10) {
  46. LayerSusceptibility(ilay) = LayerHighFreqSusceptibility(ilay) + (LayerLowFreqSusceptibility(ilay) -
  47. LayerHighFreqSusceptibility(ilay)) /
  48. ((Real)(1.) + std::pow(Complex(0, omega*
  49. LayerTauSusceptibility(ilay)),
  50. LayerBreathSusceptibility(ilay)));
  51. } else {
  52. LayerSusceptibility(ilay) = LayerLowFreqSusceptibility(ilay);
  53. }
  54. if ( LayerTauPermitivity(ilay) > 1e-10) {
  55. LayerPermitivity(ilay) = LayerHighFreqPermitivity(ilay) +
  56. (LayerLowFreqPermitivity(ilay) -
  57. LayerHighFreqPermitivity(ilay)) /
  58. ((Real)(1.) + std::pow(Complex(0,
  59. omega*LayerTauPermitivity(ilay)),
  60. LayerBreathPermitivity(ilay)));
  61. } else {
  62. LayerPermitivity(ilay) = LayerLowFreqPermitivity(ilay);
  63. }
  64. }
  65. }
  66. std::shared_ptr<LayeredEarthEM> LayeredEarthEM::Clone() {
  67. auto copy = LayeredEarthEM::NewSP();
  68. copy->LayerConductivity = this->LayerConductivity;
  69. copy->LayerSusceptibility = this->LayerSusceptibility;
  70. copy->LayerLowFreqSusceptibility = this->LayerLowFreqSusceptibility;
  71. copy->LayerHighFreqSusceptibility = this->LayerHighFreqSusceptibility;
  72. copy->LayerTauSusceptibility = this->LayerTauSusceptibility;
  73. copy->LayerBreathSusceptibility = this->LayerBreathSusceptibility;
  74. copy->LayerPermitivity = this->LayerPermitivity;
  75. copy->LayerLowFreqPermitivity = this->LayerLowFreqPermitivity;
  76. copy->LayerHighFreqPermitivity = this->LayerHighFreqPermitivity;
  77. copy->LayerTauPermitivity = this->LayerTauPermitivity;
  78. copy->LayerBreathPermitivity = this->LayerBreathPermitivity;
  79. copy->SetNumberOfLayers( this->GetNumberOfLayers() );
  80. copy->NumberOfInterfaces = this->NumberOfInterfaces;
  81. copy->LayerThickness = this->LayerThickness;
  82. return copy;
  83. }
  84. // ==================== ACCESS ==================================
  85. void LayeredEarthEM::SetLayerConductivity(const VectorXcr &sig) {
  86. if (sig.size() != this->GetNumberOfLayers() )
  87. throw EarthModelParametersDoNotMatchNumberOfLayers( );
  88. LayerConductivity = sig;
  89. }
  90. void LayeredEarthEM::SetLayerConductivity(const int& ilay, const Complex &sig) {
  91. if (ilay > this->GetNumberOfLayers() || ilay < 1 )
  92. throw EarthModelParametersDoNotMatchNumberOfLayers( );
  93. LayerConductivity[ilay] = sig;
  94. }
  95. /*
  96. void LayeredEarthEM::SetLayerResistivity(const VectorXcr &rhos) {
  97. if (rhos.size() != this->NumberOfLayers )
  98. throw EarthModelParametersDoNotMatchNumberOfLayers( );
  99. LayerConductivity = 1./rhos.array();
  100. }
  101. */
  102. void LayeredEarthEM::SetLayerHighFreqSusceptibility(const VectorXr &sus) {
  103. if (sus.size() != this->GetNumberOfLayers() )
  104. throw EarthModelParametersDoNotMatchNumberOfLayers( );
  105. LayerHighFreqSusceptibility = sus;
  106. }
  107. void LayeredEarthEM::SetLayerLowFreqSusceptibility(const VectorXr &sus) {
  108. if (sus.size() != this->GetNumberOfLayers() )
  109. throw EarthModelParametersDoNotMatchNumberOfLayers( );
  110. LayerLowFreqSusceptibility = sus;
  111. }
  112. void LayeredEarthEM::SetLayerBreathSusceptibility(const VectorXr &sus) {
  113. if (sus.size() != this->GetNumberOfLayers() )
  114. throw EarthModelParametersDoNotMatchNumberOfLayers( );
  115. LayerBreathSusceptibility = sus;
  116. }
  117. void LayeredEarthEM::SetLayerTauSusceptibility(const VectorXr &sus) {
  118. if (sus.size() != this->GetNumberOfLayers() )
  119. throw EarthModelParametersDoNotMatchNumberOfLayers( );
  120. LayerTauSusceptibility = sus;
  121. }
  122. void LayeredEarthEM::SetLayerHighFreqPermitivity(const VectorXr &per) {
  123. if (per.size() != this->GetNumberOfLayers() )
  124. throw EarthModelParametersDoNotMatchNumberOfLayers( );
  125. LayerHighFreqPermitivity = per;
  126. }
  127. void LayeredEarthEM::SetLayerLowFreqPermitivity(const VectorXr &per) {
  128. if (per.size() != this->GetNumberOfLayers() )
  129. throw EarthModelParametersDoNotMatchNumberOfLayers( );
  130. LayerLowFreqPermitivity = per;
  131. }
  132. void LayeredEarthEM::SetLayerBreathPermitivity(const VectorXr &per) {
  133. if (per.size() != this->GetNumberOfLayers() )
  134. throw EarthModelParametersDoNotMatchNumberOfLayers( );
  135. LayerBreathPermitivity = per;
  136. }
  137. void LayeredEarthEM::SetLayerTauPermitivity(const VectorXr &per) {
  138. if (per.size() != this->GetNumberOfLayers() )
  139. throw EarthModelParametersDoNotMatchNumberOfLayers( );
  140. LayerTauPermitivity = per;
  141. }
  142. void LayeredEarthEM::SetLayerThickness(const VectorXr &thick) {
  143. if (thick.size() != this->GetNumberOfLayers() - 2)
  144. throw EarthModelParametersDoNotMatchNumberOfLayers( );
  145. LayerThickness = thick;
  146. }
  147. void LayeredEarthEM::SetNumberOfLayers(const int&nlay) {
  148. // Check for validity
  149. if (nlay < 2) {
  150. throw EarthModelWithLessThanTwoLayers();
  151. }
  152. //else if (nlay > MAXLAYERS)
  153. // throw EarthModelWithMoreThanMaxLayers();
  154. // Otherwise
  155. this->NumberOfLayers = nlay;
  156. this->NumberOfInterfaces = nlay-1;
  157. // Resize all layers
  158. //////////////////////////////////
  159. // Thicknesses set to zero
  160. LayerThickness = VectorXr::Zero(NumberOfLayers);
  161. ///////////////////////////////////
  162. // Conducitivy set to zero
  163. LayerConductivity = VectorXcr::Zero(NumberOfLayers);
  164. ////////////////////////////////////
  165. // Susceptibility set to One (free space)
  166. LayerSusceptibility = VectorXcr::Ones(NumberOfLayers);
  167. // workaround for Valgrind on AMD which compains about assignment to 1 of VectorXr
  168. LayerLowFreqSusceptibility = LayerSusceptibility.real(); // 1
  169. LayerHighFreqSusceptibility = LayerSusceptibility.real(); // 1
  170. LayerTauSusceptibility = LayerSusceptibility.imag(); // 0
  171. LayerBreathSusceptibility = LayerSusceptibility.imag(); // 0
  172. //////////////////////////////////////
  173. // Permitivity set to 1 (free space)
  174. //this->LayerPermitivity.resize(NumberOfLayers);
  175. //this->LayerPermitivity.setOnes();
  176. LayerPermitivity = VectorXcr::Ones(NumberOfLayers);
  177. // workaround for Valgrind on AMD which compains about assignment to 1 of VectorXr
  178. LayerLowFreqPermitivity = LayerPermitivity.real(); // 1
  179. LayerHighFreqPermitivity = LayerPermitivity.real(); // 1
  180. LayerTauPermitivity = LayerPermitivity.imag(); // 0
  181. LayerBreathPermitivity = LayerPermitivity.imag(); // 0
  182. }
  183. // ==================== INQUIRY ===================================
  184. VectorXcr LayeredEarthEM::GetLayerConductivity() {
  185. return this->LayerConductivity;
  186. }
  187. Complex LayeredEarthEM::GetLayerConductivity(const int &ilay) {
  188. return this->LayerConductivity(ilay);
  189. }
  190. Complex LayeredEarthEM::GetLayerSusceptibility(const int &ilay) {
  191. return this->LayerSusceptibility(ilay);
  192. }
  193. VectorXcr LayeredEarthEM::GetLayerSusceptibility( ) {
  194. return this->LayerSusceptibility;
  195. }
  196. Complex LayeredEarthEM::GetLayerPermitivity(const int &ilay) {
  197. return this->LayerPermitivity(ilay);
  198. }
  199. VectorXcr LayeredEarthEM::GetLayerPermitivity( ) {
  200. return this->LayerPermitivity;
  201. }
  202. Real LayeredEarthEM::GetLayerLowFreqSusceptibility(const int &ilay) {
  203. return this->LayerLowFreqSusceptibility(ilay);
  204. }
  205. VectorXr LayeredEarthEM::GetLayerLowFreqSusceptibility( ) {
  206. return this->LayerLowFreqSusceptibility;
  207. }
  208. Real LayeredEarthEM::GetLayerHighFreqSusceptibility(const int &ilay) {
  209. return this->LayerHighFreqSusceptibility(ilay);
  210. }
  211. VectorXr LayeredEarthEM::GetLayerHighFreqSusceptibility( ) {
  212. return this->LayerHighFreqSusceptibility;
  213. }
  214. Real LayeredEarthEM::GetLayerTauSusceptibility(const int &ilay) {
  215. return this->LayerTauSusceptibility(ilay);
  216. }
  217. VectorXr LayeredEarthEM::GetLayerTauSusceptibility( ) {
  218. return this->LayerTauSusceptibility;
  219. }
  220. Real LayeredEarthEM::GetLayerBreathSusceptibility(const int &ilay) {
  221. return this->LayerBreathSusceptibility(ilay);
  222. }
  223. VectorXr LayeredEarthEM::GetLayerBreathSusceptibility( ) {
  224. return this->LayerBreathSusceptibility;
  225. }
  226. Real LayeredEarthEM::GetLayerLowFreqPermitivity(const int &ilay) {
  227. return this->LayerLowFreqPermitivity(ilay);
  228. }
  229. VectorXr LayeredEarthEM::GetLayerLowFreqPermitivity( ) {
  230. return this->LayerLowFreqPermitivity;
  231. }
  232. Real LayeredEarthEM::GetLayerHighFreqPermitivity(const int &ilay) {
  233. return this->LayerHighFreqPermitivity(ilay);
  234. }
  235. VectorXr LayeredEarthEM::GetLayerHighFreqPermitivity( ) {
  236. return this->LayerHighFreqPermitivity;
  237. }
  238. Real LayeredEarthEM::GetLayerTauPermitivity(const int &ilay) {
  239. return this->LayerTauPermitivity(ilay);
  240. }
  241. VectorXr LayeredEarthEM::GetLayerTauPermitivity( ) {
  242. return this->LayerTauPermitivity;
  243. }
  244. Real LayeredEarthEM::GetLayerBreathPermitivity(const int &ilay) {
  245. return this->LayerBreathPermitivity(ilay);
  246. }
  247. VectorXr LayeredEarthEM::GetLayerBreathPermitivity( ) {
  248. return this->LayerBreathPermitivity;
  249. }
  250. }
  251. /* vim: set tabstop=4 expandtab: */
  252. /* vim: set filetype=cpp: */