Lemma is an Electromagnetics API
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 13KB

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