Lemma is an Electromagnetics API
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

LayeredEarthEM.cpp 13KB

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