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

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