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.

DipoleSource.cpp 75KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357
  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 12/02/2009
  9. **/
  10. #include "DipoleSource.h"
  11. #include "KernelEM1DManager.h"
  12. //#include "GroundedElectricDipole.h"
  13. //#include "UngroundedElectricDipole.h"
  14. //#include "MagneticDipole.h"
  15. #include "FieldPoints.h"
  16. #include "HankelTransform.h"
  17. namespace Lemma {
  18. // ==================== FRIENDS ======================
  19. std::ostream &operator<<(std::ostream &stream, const DipoleSource &ob) {
  20. stream << ob.Serialize() << "\n";
  21. return stream;
  22. }
  23. /*
  24. bool DipoleSource::operator == (DipoleSource& rhs) const {
  25. if (Location != rhs.Location) return false;
  26. return true;
  27. }
  28. */
  29. // ==================== LIFECYCLE ======================
  30. DipoleSource::DipoleSource( const ctor_key& key ) : LemmaObject( key ),
  31. Type(NOSOURCETYPE),
  32. irec(-1),
  33. Phase(0),
  34. Moment(1),
  35. KernelManager(nullptr),
  36. Receivers(nullptr),
  37. Earth(nullptr)
  38. {
  39. this->Location.setZero();
  40. this->Phat.setZero();
  41. }
  42. DipoleSource::DipoleSource( const YAML::Node& node, const ctor_key& key ) : LemmaObject( node, key ),
  43. Type(NOSOURCETYPE),
  44. irec(-1),
  45. Phase(0),
  46. Moment(1),
  47. KernelManager(nullptr),
  48. Receivers(nullptr),
  49. Earth(nullptr)
  50. {
  51. Type = string2Enum<DIPOLESOURCETYPE>(node["Type"].as<std::string>());
  52. this->Location = node["Location"].as<Vector3r>();
  53. this->Phat.setZero();
  54. }
  55. DipoleSource::~DipoleSource() {
  56. }
  57. std::shared_ptr<DipoleSource> DipoleSource::NewSP() {
  58. return std::make_shared<DipoleSource> ( ctor_key() );
  59. }
  60. YAML::Node DipoleSource::Serialize() const {
  61. YAML::Node node = LemmaObject::Serialize();
  62. node.SetTag( GetName() );
  63. node["Type"] = enum2String(Type);
  64. node["Location"] = Location;
  65. node["Phat"] = Phat;
  66. node["Freqs"] = Freqs;
  67. node["Phase"] = Phase;
  68. node["Moment"] = Moment;
  69. return node;
  70. }
  71. std::shared_ptr< DipoleSource > DipoleSource::DeSerialize(const YAML::Node& node) {
  72. if (node.Tag() != "DipoleSource") {
  73. throw DeSerializeTypeMismatch( "DipoleSource", node.Tag());
  74. }
  75. return std::make_shared<DipoleSource> ( node, ctor_key() );
  76. }
  77. std::shared_ptr<DipoleSource> DipoleSource::Clone() {
  78. auto Obj = DipoleSource::NewSP();
  79. // copy
  80. Obj->Type = Type;
  81. Obj->irec = irec;
  82. Obj->lays = lays;
  83. Obj->layr = layr;
  84. Obj->Phase = Phase;
  85. Obj->Moment = Moment;
  86. Obj->xxp = xxp;
  87. Obj->yyp = yyp;
  88. Obj->rho = rho;
  89. Obj->sp = sp;
  90. Obj->cp = cp;
  91. Obj->scp = scp;
  92. Obj->sps = sps;
  93. Obj->cps = cps;
  94. Obj->c2p = c2p;
  95. Obj->FieldsToCalculate = FieldsToCalculate;
  96. Obj->f = f;
  97. Obj->ik = ik;
  98. Obj->Location = Location;
  99. Obj->Phat = Phat;
  100. Obj->Freqs = Freqs;
  101. return Obj;
  102. }
  103. //--------------------------------------------------------------------------------------
  104. // Class: DipoleSource
  105. // Method: GetName
  106. // Description: Class identifier
  107. //--------------------------------------------------------------------------------------
  108. inline std::string DipoleSource::GetName ( ) const {
  109. return CName;
  110. } // ----- end of method DipoleSource::GetName -----
  111. // ==================== ACCESS ======================
  112. void DipoleSource::SetLocation(const Vector3r &posin) {
  113. this->Location = posin;
  114. }
  115. void DipoleSource::SetLocation(const Real &xp, const Real &yp,
  116. const Real &zp) {
  117. this->Location = Vector3r(xp, yp, zp);
  118. }
  119. void DipoleSource::SetPhase(const Real &phase) {
  120. this->Phase = phase;
  121. }
  122. void DipoleSource::SetPolarity(const DipoleSourcePolarity &pol) {
  123. static bool called = false;
  124. if (!called) {
  125. std::cerr << "\n\n=================================================================\n"
  126. << "WARNING: Use of deprecated method DipoleSource::SetPolarity(pol)\n"
  127. << "Use more general SetPolarisation( Vector3r ) or SetPolarisation( x, y, z );\n"
  128. << "This method will be removed in future versions of Lemma"
  129. << "\n=================================================================\n";
  130. called = true;
  131. }
  132. // Polarity = pol;
  133. // switch (Polarity) {
  134. // case POSITIVE:
  135. // Moment = std::abs(Moment);
  136. // break;
  137. // case NEGATIVE:
  138. // Moment = -std::abs(Moment);
  139. // break;
  140. // default:
  141. // throw NonValidDipolePolarity();
  142. // };
  143. }
  144. void DipoleSource::SetType(const DIPOLESOURCETYPE & stype) {
  145. switch (stype) {
  146. case (GROUNDEDELECTRICDIPOLE):
  147. this->Type = stype;
  148. break;
  149. case (UNGROUNDEDELECTRICDIPOLE):
  150. this->Type = stype;
  151. break;
  152. case (MAGNETICDIPOLE):
  153. this->Type = stype;
  154. break;
  155. default:
  156. throw NonValidDipoleTypeAssignment();
  157. }
  158. }
  159. void DipoleSource::SetPolarisation(const Vector3r& pol) {
  160. this->Phat = pol / pol.norm();
  161. }
  162. void DipoleSource::SetPolarisation(const Real& x, const Real& y, const Real& z) {
  163. Vector3r pol = (VectorXr(3) << x, y, z).finished();
  164. this->Phat = pol / pol.norm();
  165. }
  166. Vector3r DipoleSource::GetPolarisation() {
  167. return Phat;
  168. }
  169. DIPOLESOURCETYPE DipoleSource::GetType() {
  170. return Type;
  171. }
  172. void DipoleSource::SetPolarisation(const
  173. DipoleSourcePolarisation &pol) {
  174. static bool called = false;
  175. if (!called) {
  176. std::cout << "\n\n========================================================================================\n"
  177. << "WARNING: Use of deprecated method DipoleSource::SetPolarisation(DipleSourcePolarisation)\n"
  178. << "Use more general SetPolarisation( Vector3r ) or SetPolarisation( x, y, z );\n"
  179. << "This method will be removed in future versions of Lemma"
  180. << "\n========================================================================================\n";
  181. called = true;
  182. }
  183. switch (pol) {
  184. case (XPOLARISATION):
  185. this->Phat = (VectorXr(3) << 1, 0, 0).finished();
  186. break;
  187. case (YPOLARISATION):
  188. this->Phat = (VectorXr(3) << 0, 1, 0).finished();
  189. break;
  190. case (ZPOLARISATION):
  191. this->Phat = (VectorXr(3) << 0, 0, 1).finished();
  192. break;
  193. default:
  194. throw NonValidDipolePolarisationAssignment();
  195. }
  196. }
  197. void DipoleSource::SetMoment(const Real &moment) {
  198. this->Moment = moment;
  199. }
  200. // ==================== OPERATIONS =====================
  201. void DipoleSource::SetKernels(const int& ifreq, const FIELDCALCULATIONS& Fields , std::shared_ptr<FieldPoints> ReceiversIn, const int& irecin,
  202. std::shared_ptr<LayeredEarthEM> EarthIn ) {
  203. if (Receivers != ReceiversIn) {
  204. Receivers = ReceiversIn;
  205. }
  206. if (Earth != EarthIn) {
  207. Earth = EarthIn;
  208. }
  209. if (irecin != irec) {
  210. irec = irecin;
  211. }
  212. if (FieldsToCalculate != Fields) {
  213. FieldsToCalculate = Fields;
  214. }
  215. xxp = Receivers->GetLocation(irec)[0] - Location[0];
  216. yyp = Receivers->GetLocation(irec)[1] - Location[1];
  217. rho = (Receivers->GetLocation(irec).head<2>() - Location.head<2>()).norm();
  218. sp = yyp/rho;
  219. cp = xxp/rho;
  220. scp = sp*cp;
  221. sps = sp*sp;
  222. cps = cp*cp;
  223. c2p = cps-sps;
  224. f = VectorXcr::Zero(13);
  225. ik = VectorXi::Zero(13);
  226. lays = Earth->GetLayerAtThisDepth(Location[2]);
  227. layr = Earth->GetLayerAtThisDepth(Receivers->GetLocation(irec)[2]);
  228. // TODO, avoid smart pointer here maybe?
  229. KernelManager = KernelEM1DManager::NewSP();
  230. KernelManager->SetEarth(Earth);
  231. // alternative is to use weak_ptr here, this is deep and internal, and we are safe.
  232. //KernelManager->SetDipoleSource( shared_from_this().get() , ifreq, Receivers->GetLocation(irec)[2]);
  233. KernelManager->SetDipoleSource( this, ifreq, Receivers->GetLocation(irec)[2]);
  234. //KernelManager->SetDipoleSource( this.get() , ifreq, Receivers->GetLocation(irec)[2] );
  235. kernelFreq = Freqs(ifreq); // this is never used
  236. ReSetKernels( ifreq, Fields, Receivers, irec, Earth );
  237. return;
  238. }
  239. void DipoleSource::SetupLight(const int& ifreq, const FIELDCALCULATIONS& Fields, const int& irecin) {
  240. xxp = Receivers->GetLocation(irec)[0] - Location[0];
  241. yyp = Receivers->GetLocation(irec)[1] - Location[1];
  242. rho = (Receivers->GetLocation(irec).head<2>() - Location.head<2>()).norm();
  243. sp = yyp/rho;
  244. cp = xxp/rho;
  245. scp = sp*cp;
  246. sps = sp*sp;
  247. cps = cp*cp;
  248. c2p = cps-sps;
  249. return;
  250. }
  251. // TODO we could make the dipoles template specializations avoiding this rats nest of switch statements. Probably
  252. // not the most critical piece though
  253. void DipoleSource::ReSetKernels(const int& ifreq, const FIELDCALCULATIONS& Fields ,
  254. std::shared_ptr<FieldPoints> Receivers, const int& irec,
  255. std::shared_ptr<LayeredEarthEM> Earth ) {
  256. Vector3r Pol = Phat;
  257. switch (Type) {
  258. case (GROUNDEDELECTRICDIPOLE):
  259. if (std::abs(Pol[2]) > 0) { // z dipole
  260. switch(FieldsToCalculate) {
  261. case E:
  262. if (lays == 0 && layr == 0) {
  263. ik[10] = KernelManager->AddKernel<TM, 10, INAIR, INAIR>( );
  264. ik[11] = KernelManager->AddKernel<TM, 11, INAIR, INAIR>( );
  265. } else if (lays == 0 && layr > 0) {
  266. ik[10] = KernelManager->AddKernel<TM, 10, INAIR, INGROUND>( );
  267. ik[11] = KernelManager->AddKernel<TM, 11, INAIR, INGROUND>( );
  268. } else if (lays > 0 && layr == 0) {
  269. ik[10] = KernelManager->AddKernel<TM, 10, INGROUND, INAIR>( );
  270. ik[11] = KernelManager->AddKernel<TM, 11, INGROUND, INAIR>( );
  271. } else {
  272. ik[10] = KernelManager->AddKernel<TM, 10, INGROUND, INGROUND>( );
  273. ik[11] = KernelManager->AddKernel<TM, 11, INGROUND, INGROUND>( );
  274. }
  275. break;
  276. case H:
  277. if (lays == 0 && layr == 0) {
  278. ik[12] = KernelManager->AddKernel<TM, 12, INAIR, INAIR>( );
  279. } else if (lays == 0 && layr > 0) {
  280. ik[12] = KernelManager->AddKernel<TM, 12, INAIR, INGROUND>( );
  281. } else if (lays > 0 && layr == 0) {
  282. ik[12] = KernelManager->AddKernel<TM, 12, INGROUND, INAIR>( );
  283. } else {
  284. ik[12] = KernelManager->AddKernel<TM, 12, INGROUND, INGROUND>( );
  285. }
  286. break;
  287. case BOTH:
  288. if ( lays == 0 && layr == 0) {
  289. ik[10] = KernelManager->AddKernel<TM, 10, INAIR, INAIR>( );
  290. ik[11] = KernelManager->AddKernel<TM, 11, INAIR, INAIR>( );
  291. ik[12] = KernelManager->AddKernel<TM, 12, INAIR, INAIR>( );
  292. } else if (lays == 0 && layr > 0) {
  293. ik[10] = KernelManager->AddKernel<TM, 10, INAIR, INGROUND>( );
  294. ik[11] = KernelManager->AddKernel<TM, 11, INAIR, INGROUND>( );
  295. ik[12] = KernelManager->AddKernel<TM, 12, INAIR, INGROUND>( );
  296. } else if (lays > 0 && layr == 0) {
  297. ik[10] = KernelManager->AddKernel<TM, 10, INGROUND, INAIR>( );
  298. ik[11] = KernelManager->AddKernel<TM, 11, INGROUND, INAIR>( );
  299. ik[12] = KernelManager->AddKernel<TM, 12, INGROUND, INAIR>( );
  300. } else {
  301. ik[10] = KernelManager->AddKernel<TM, 10, INGROUND, INGROUND>( );
  302. ik[11] = KernelManager->AddKernel<TM, 11, INGROUND, INGROUND>( );
  303. ik[12] = KernelManager->AddKernel<TM, 12, INGROUND, INGROUND>( );
  304. }
  305. }
  306. }
  307. if (std::abs(Pol[1]) > 0 || std::abs(Pol[0]) > 0) { // x or y grounded HED dipole
  308. switch(FieldsToCalculate) {
  309. case E:
  310. if ( lays == 0 && layr == 0) {
  311. ik[0] = KernelManager->AddKernel<TM, 0, INAIR, INAIR>( );
  312. ik[1] = KernelManager->AddKernel<TM, 1, INAIR, INAIR>( );
  313. ik[4] = KernelManager->AddKernel<TM, 4, INAIR, INAIR>( );
  314. ik[2] = KernelManager->AddKernel<TE, 2, INAIR, INAIR>( );
  315. ik[3] = KernelManager->AddKernel<TE, 3, INAIR, INAIR>( );
  316. } else if (lays == 0 && layr > 0) {
  317. ik[0] = KernelManager->AddKernel<TM, 0, INAIR, INGROUND>( );
  318. ik[1] = KernelManager->AddKernel<TM, 1, INAIR, INGROUND>( );
  319. ik[4] = KernelManager->AddKernel<TM, 4, INAIR, INGROUND>( );
  320. ik[2] = KernelManager->AddKernel<TE, 2, INAIR, INGROUND>( );
  321. ik[3] = KernelManager->AddKernel<TE, 3, INAIR, INGROUND>( );
  322. } else if (lays > 0 && layr == 0) {
  323. ik[0] = KernelManager->AddKernel<TM, 0, INGROUND, INAIR>( );
  324. ik[1] = KernelManager->AddKernel<TM, 1, INGROUND, INAIR>( );
  325. ik[4] = KernelManager->AddKernel<TM, 4, INGROUND, INAIR>( );
  326. ik[2] = KernelManager->AddKernel<TE, 2, INGROUND, INAIR>( );
  327. ik[3] = KernelManager->AddKernel<TE, 3, INGROUND, INAIR>( );
  328. } else {
  329. ik[0] = KernelManager->AddKernel<TM, 0, INGROUND, INGROUND>( );
  330. ik[1] = KernelManager->AddKernel<TM, 1, INGROUND, INGROUND>( );
  331. ik[4] = KernelManager->AddKernel<TM, 4, INGROUND, INGROUND>( );
  332. ik[2] = KernelManager->AddKernel<TE, 2, INGROUND, INGROUND>( );
  333. ik[3] = KernelManager->AddKernel<TE, 3, INGROUND, INGROUND>( );
  334. }
  335. break;
  336. case H:
  337. if (lays == 0 && layr == 0) {
  338. ik[5] = KernelManager->AddKernel<TM, 5, INAIR, INAIR>( );
  339. ik[6] = KernelManager->AddKernel<TM, 6, INAIR, INAIR>( );
  340. ik[7] = KernelManager->AddKernel<TE, 7, INAIR, INAIR>( );
  341. ik[8] = KernelManager->AddKernel<TE, 8, INAIR, INAIR>( );
  342. ik[9] = KernelManager->AddKernel<TE, 9, INAIR, INAIR>( );
  343. } else if (lays == 0 && layr > 0) {
  344. ik[5] = KernelManager->AddKernel<TM, 5, INAIR, INGROUND>( );
  345. ik[6] = KernelManager->AddKernel<TM, 6, INAIR, INGROUND>( );
  346. ik[7] = KernelManager->AddKernel<TE, 7, INAIR, INGROUND>( );
  347. ik[8] = KernelManager->AddKernel<TE, 8, INAIR, INGROUND>( );
  348. ik[9] = KernelManager->AddKernel<TE, 9, INAIR, INGROUND>( );
  349. } else if (lays > 0 && layr == 0) {
  350. ik[5] = KernelManager->AddKernel<TM, 5, INGROUND, INAIR>( );
  351. ik[6] = KernelManager->AddKernel<TM, 6, INGROUND, INAIR>( );
  352. ik[7] = KernelManager->AddKernel<TE, 7, INGROUND, INAIR>( );
  353. ik[8] = KernelManager->AddKernel<TE, 8, INGROUND, INAIR>( );
  354. ik[9] = KernelManager->AddKernel<TE, 9, INGROUND, INAIR>( );
  355. } else {
  356. ik[5] = KernelManager->AddKernel<TM, 5, INGROUND, INGROUND>( );
  357. ik[6] = KernelManager->AddKernel<TM, 6, INGROUND, INGROUND>( );
  358. ik[7] = KernelManager->AddKernel<TE, 7, INGROUND, INGROUND>( );
  359. ik[8] = KernelManager->AddKernel<TE, 8, INGROUND, INGROUND>( );
  360. ik[9] = KernelManager->AddKernel<TE, 9, INGROUND, INGROUND>( );
  361. }
  362. break;
  363. case BOTH:
  364. if (lays == 0 && layr == 0) {
  365. ik[0] = KernelManager->AddKernel<TM, 0, INAIR, INAIR>( );
  366. ik[1] = KernelManager->AddKernel<TM, 1, INAIR, INAIR>( );
  367. ik[4] = KernelManager->AddKernel<TM, 4, INAIR, INAIR>( );
  368. ik[2] = KernelManager->AddKernel<TE, 2, INAIR, INAIR>( );
  369. ik[3] = KernelManager->AddKernel<TE, 3, INAIR, INAIR>( );
  370. ik[5] = KernelManager->AddKernel<TM, 5, INAIR, INAIR>( );
  371. ik[6] = KernelManager->AddKernel<TM, 6, INAIR, INAIR>( );
  372. ik[7] = KernelManager->AddKernel<TE, 7, INAIR, INAIR>( );
  373. ik[8] = KernelManager->AddKernel<TE, 8, INAIR, INAIR>( );
  374. ik[9] = KernelManager->AddKernel<TE, 9, INAIR, INAIR>( );
  375. } else if (lays == 0 && layr > 0) {
  376. ik[0] = KernelManager->AddKernel<TM, 0, INAIR, INGROUND>( );
  377. ik[1] = KernelManager->AddKernel<TM, 1, INAIR, INGROUND>( );
  378. ik[4] = KernelManager->AddKernel<TM, 4, INAIR, INGROUND>( );
  379. ik[2] = KernelManager->AddKernel<TE, 2, INAIR, INGROUND>( );
  380. ik[3] = KernelManager->AddKernel<TE, 3, INAIR, INGROUND>( );
  381. ik[5] = KernelManager->AddKernel<TM, 5, INAIR, INGROUND>( );
  382. ik[6] = KernelManager->AddKernel<TM, 6, INAIR, INGROUND>( );
  383. ik[7] = KernelManager->AddKernel<TE, 7, INAIR, INGROUND>( );
  384. ik[8] = KernelManager->AddKernel<TE, 8, INAIR, INGROUND>( );
  385. ik[9] = KernelManager->AddKernel<TE, 9, INAIR, INGROUND>( );
  386. } else if (lays > 0 && layr == 0) {
  387. ik[0] = KernelManager->AddKernel<TM, 0, INGROUND, INAIR>( );
  388. ik[1] = KernelManager->AddKernel<TM, 1, INGROUND, INAIR>( );
  389. ik[4] = KernelManager->AddKernel<TM, 4, INGROUND, INAIR>( );
  390. ik[2] = KernelManager->AddKernel<TE, 2, INGROUND, INAIR>( );
  391. ik[3] = KernelManager->AddKernel<TE, 3, INGROUND, INAIR>( );
  392. ik[5] = KernelManager->AddKernel<TM, 5, INGROUND, INAIR>( );
  393. ik[6] = KernelManager->AddKernel<TM, 6, INGROUND, INAIR>( );
  394. ik[7] = KernelManager->AddKernel<TE, 7, INGROUND, INAIR>( );
  395. ik[8] = KernelManager->AddKernel<TE, 8, INGROUND, INAIR>( );
  396. ik[9] = KernelManager->AddKernel<TE, 9, INGROUND, INAIR>( );
  397. } else {
  398. ik[0] = KernelManager->AddKernel<TM, 0, INGROUND, INGROUND>( );
  399. ik[1] = KernelManager->AddKernel<TM, 1, INGROUND, INGROUND>( );
  400. ik[4] = KernelManager->AddKernel<TM, 4, INGROUND, INGROUND>( );
  401. ik[2] = KernelManager->AddKernel<TE, 2, INGROUND, INGROUND>( );
  402. ik[3] = KernelManager->AddKernel<TE, 3, INGROUND, INGROUND>( );
  403. ik[5] = KernelManager->AddKernel<TM, 5, INGROUND, INGROUND>( );
  404. ik[6] = KernelManager->AddKernel<TM, 6, INGROUND, INGROUND>( );
  405. ik[7] = KernelManager->AddKernel<TE, 7, INGROUND, INGROUND>( );
  406. ik[8] = KernelManager->AddKernel<TE, 8, INGROUND, INGROUND>( );
  407. ik[9] = KernelManager->AddKernel<TE, 9, INGROUND, INGROUND>( );
  408. }
  409. break;
  410. }
  411. }
  412. break;
  413. case (UNGROUNDEDELECTRICDIPOLE):
  414. if (std::abs(Pol[2]) > 0) { // z dipole
  415. switch(FieldsToCalculate) {
  416. case E:
  417. if (lays == 0 && layr == 0) {
  418. ik[11] = KernelManager->AddKernel<TM, 11, INAIR, INAIR>( );
  419. } else if (lays == 0 && layr > 0) {
  420. ik[11] = KernelManager->AddKernel<TM, 11, INAIR, INGROUND>( );
  421. } else if (lays > 0 && layr == 0) {
  422. ik[11] = KernelManager->AddKernel<TM, 11, INGROUND, INAIR>( );
  423. } else {
  424. ik[11] = KernelManager->AddKernel<TM, 11, INGROUND, INGROUND>( );
  425. }
  426. break;
  427. case H:
  428. if (lays == 0 && layr == 0) {
  429. ik[12] = KernelManager->AddKernel<TM, 12, INAIR, INAIR>( );
  430. } else if (lays == 0 && layr > 0) {
  431. ik[12] = KernelManager->AddKernel<TM, 12, INAIR, INGROUND>( );
  432. } else if (lays > 0 && layr == 0) {
  433. ik[12] = KernelManager->AddKernel<TM, 12, INGROUND, INAIR>( );
  434. } else {
  435. ik[12] = KernelManager->AddKernel<TM, 12, INGROUND, INGROUND>( );
  436. }
  437. break;
  438. case BOTH:
  439. if ( lays == 0 && layr == 0) {
  440. ik[11] = KernelManager->AddKernel<TM, 11, INAIR, INAIR>( );
  441. ik[12] = KernelManager->AddKernel<TM, 12, INAIR, INAIR>( );
  442. } else if (lays == 0 && layr > 0) {
  443. ik[11] = KernelManager->AddKernel<TM, 11, INAIR, INGROUND>( );
  444. ik[12] = KernelManager->AddKernel<TM, 12, INAIR, INGROUND>( );
  445. } else if (lays > 0 && layr == 0) {
  446. ik[11] = KernelManager->AddKernel<TM, 11, INGROUND, INAIR>( );
  447. ik[12] = KernelManager->AddKernel<TM, 12, INGROUND, INAIR>( );
  448. } else {
  449. ik[11] = KernelManager->AddKernel<TM, 11, INGROUND, INGROUND>( );
  450. ik[12] = KernelManager->AddKernel<TM, 12, INGROUND, INGROUND>( );
  451. }
  452. }
  453. }
  454. if (std::abs(Pol[1]) > 0 || std::abs(Pol[0]) > 0) { // x or y grounded HED dipole
  455. switch(FieldsToCalculate) {
  456. case E:
  457. if ( lays == 0 && layr == 0) {
  458. ik[2] = KernelManager->AddKernel<TE, 2, INAIR, INAIR>( );
  459. ik[3] = KernelManager->AddKernel<TE, 3, INAIR, INAIR>( );
  460. } else if (lays == 0 && layr > 0) {
  461. ik[2] = KernelManager->AddKernel<TE, 2, INAIR, INGROUND>( );
  462. ik[3] = KernelManager->AddKernel<TE, 3, INAIR, INGROUND>( );
  463. } else if (lays > 0 && layr == 0) {
  464. ik[2] = KernelManager->AddKernel<TE, 2, INGROUND, INAIR>( );
  465. ik[3] = KernelManager->AddKernel<TE, 3, INGROUND, INAIR>( );
  466. } else {
  467. ik[2] = KernelManager->AddKernel<TE, 2, INGROUND, INGROUND>( );
  468. ik[3] = KernelManager->AddKernel<TE, 3, INGROUND, INGROUND>( );
  469. }
  470. break;
  471. case H:
  472. if (lays == 0 && layr == 0) {
  473. ik[5] = KernelManager->AddKernel<TM, 5, INAIR, INAIR>( );
  474. ik[6] = KernelManager->AddKernel<TM, 6, INAIR, INAIR>( );
  475. ik[7] = KernelManager->AddKernel<TE, 7, INAIR, INAIR>( );
  476. ik[8] = KernelManager->AddKernel<TE, 8, INAIR, INAIR>( );
  477. ik[9] = KernelManager->AddKernel<TE, 9, INAIR, INAIR>( );
  478. } else if (lays == 0 && layr > 0) {
  479. ik[5] = KernelManager->AddKernel<TM, 5, INAIR, INGROUND>( );
  480. ik[6] = KernelManager->AddKernel<TM, 6, INAIR, INGROUND>( );
  481. ik[7] = KernelManager->AddKernel<TE, 7, INAIR, INGROUND>( );
  482. ik[8] = KernelManager->AddKernel<TE, 8, INAIR, INGROUND>( );
  483. ik[9] = KernelManager->AddKernel<TE, 9, INAIR, INGROUND>( );
  484. } else if (lays > 0 && layr == 0) {
  485. ik[5] = KernelManager->AddKernel<TM, 5, INGROUND, INAIR>( );
  486. ik[6] = KernelManager->AddKernel<TM, 6, INGROUND, INAIR>( );
  487. ik[7] = KernelManager->AddKernel<TE, 7, INGROUND, INAIR>( );
  488. ik[8] = KernelManager->AddKernel<TE, 8, INGROUND, INAIR>( );
  489. ik[9] = KernelManager->AddKernel<TE, 9, INGROUND, INAIR>( );
  490. } else {
  491. ik[5] = KernelManager->AddKernel<TM, 5, INGROUND, INGROUND>( );
  492. ik[6] = KernelManager->AddKernel<TM, 6, INGROUND, INGROUND>( );
  493. ik[7] = KernelManager->AddKernel<TE, 7, INGROUND, INGROUND>( );
  494. ik[8] = KernelManager->AddKernel<TE, 8, INGROUND, INGROUND>( );
  495. ik[9] = KernelManager->AddKernel<TE, 9, INGROUND, INGROUND>( );
  496. }
  497. break;
  498. case BOTH:
  499. if (lays == 0 && layr == 0) {
  500. ik[5] = KernelManager->AddKernel<TM, 5, INAIR, INAIR>( );
  501. ik[6] = KernelManager->AddKernel<TM, 6, INAIR, INAIR>( );
  502. ik[2] = KernelManager->AddKernel<TE, 2, INAIR, INAIR>( );
  503. ik[3] = KernelManager->AddKernel<TE, 3, INAIR, INAIR>( );
  504. ik[7] = KernelManager->AddKernel<TE, 7, INAIR, INAIR>( );
  505. ik[8] = KernelManager->AddKernel<TE, 8, INAIR, INAIR>( );
  506. ik[9] = KernelManager->AddKernel<TE, 9, INAIR, INAIR>( );
  507. } else if (lays == 0 && layr > 0) {
  508. ik[5] = KernelManager->AddKernel<TM, 5, INAIR, INGROUND>( );
  509. ik[6] = KernelManager->AddKernel<TM, 6, INAIR, INGROUND>( );
  510. ik[2] = KernelManager->AddKernel<TE, 2, INAIR, INGROUND>( );
  511. ik[3] = KernelManager->AddKernel<TE, 3, INAIR, INGROUND>( );
  512. ik[7] = KernelManager->AddKernel<TE, 7, INAIR, INGROUND>( );
  513. ik[8] = KernelManager->AddKernel<TE, 8, INAIR, INGROUND>( );
  514. ik[9] = KernelManager->AddKernel<TE, 9, INAIR, INGROUND>( );
  515. } else if (lays > 0 && layr == 0) {
  516. ik[5] = KernelManager->AddKernel<TM, 5, INGROUND, INAIR>( );
  517. ik[6] = KernelManager->AddKernel<TM, 6, INGROUND, INAIR>( );
  518. ik[2] = KernelManager->AddKernel<TE, 2, INGROUND, INAIR>( );
  519. ik[3] = KernelManager->AddKernel<TE, 3, INGROUND, INAIR>( );
  520. ik[7] = KernelManager->AddKernel<TE, 7, INGROUND, INAIR>( );
  521. ik[8] = KernelManager->AddKernel<TE, 8, INGROUND, INAIR>( );
  522. ik[9] = KernelManager->AddKernel<TE, 9, INGROUND, INAIR>( );
  523. } else {
  524. ik[5] = KernelManager->AddKernel<TM, 5, INGROUND, INGROUND>( );
  525. ik[6] = KernelManager->AddKernel<TM, 6, INGROUND, INGROUND>( );
  526. ik[2] = KernelManager->AddKernel<TE, 2, INGROUND, INGROUND>( );
  527. ik[3] = KernelManager->AddKernel<TE, 3, INGROUND, INGROUND>( );
  528. ik[7] = KernelManager->AddKernel<TE, 7, INGROUND, INGROUND>( );
  529. ik[8] = KernelManager->AddKernel<TE, 8, INGROUND, INGROUND>( );
  530. ik[9] = KernelManager->AddKernel<TE, 9, INGROUND, INGROUND>( );
  531. }
  532. break;
  533. }
  534. }
  535. break;
  536. case (MAGNETICDIPOLE):
  537. if (std::abs(Pol[2]) > 0) { // z dipole
  538. switch (FieldsToCalculate) {
  539. case E:
  540. if (lays == 0 && layr == 0) {
  541. ik[12] = KernelManager->AddKernel<TE, 12, INAIR, INAIR>( );
  542. } else if (lays == 0 && layr > 0) {
  543. ik[12] = KernelManager->AddKernel<TE, 12, INAIR, INGROUND>( );
  544. } else if (lays > 0 && layr == 0) {
  545. ik[12] = KernelManager->AddKernel<TE, 12, INGROUND, INAIR>( );
  546. } else {
  547. ik[12] = KernelManager->AddKernel<TE, 12, INGROUND, INGROUND>( );
  548. }
  549. break;
  550. case H:
  551. if (lays == 0 && layr == 0) {
  552. ik[10] = KernelManager->AddKernel<TE, 10, INAIR, INAIR>( );
  553. ik[11] = KernelManager->AddKernel<TE, 11, INAIR, INAIR>( );
  554. } else if (lays == 0 && layr > 0) {
  555. ik[10] = KernelManager->AddKernel<TE, 10, INAIR, INGROUND>( );
  556. ik[11] = KernelManager->AddKernel<TE, 11, INAIR, INGROUND>( );
  557. } else if (lays > 0 && layr == 0) {
  558. ik[10] = KernelManager->AddKernel<TE, 10, INGROUND, INAIR>( );
  559. ik[11] = KernelManager->AddKernel<TE, 11, INGROUND, INAIR>( );
  560. } else {
  561. ik[10] = KernelManager->AddKernel<TE, 10, INGROUND, INGROUND>( );
  562. ik[11] = KernelManager->AddKernel<TE, 11, INGROUND, INGROUND>( );
  563. }
  564. break;
  565. case BOTH:
  566. if (lays == 0 && layr == 0) {
  567. ik[12] = KernelManager->AddKernel<TE, 12, INAIR, INAIR>( );
  568. ik[10] = KernelManager->AddKernel<TE, 10, INAIR, INAIR>( );
  569. ik[11] = KernelManager->AddKernel<TE, 11, INAIR, INAIR>( );
  570. } else if (lays == 0 && layr > 0) {
  571. ik[12] = KernelManager->AddKernel<TE, 12, INAIR, INGROUND>( );
  572. ik[10] = KernelManager->AddKernel<TE, 10, INAIR, INGROUND>( );
  573. ik[11] = KernelManager->AddKernel<TE, 11, INAIR, INGROUND>( );
  574. } else if (lays > 0 && layr == 0) {
  575. ik[12] = KernelManager->AddKernel<TE, 12, INGROUND, INAIR>( );
  576. ik[10] = KernelManager->AddKernel<TE, 10, INGROUND, INAIR>( );
  577. ik[11] = KernelManager->AddKernel<TE, 11, INGROUND, INAIR>( );
  578. } else {
  579. ik[12] = KernelManager->AddKernel<TE, 12, INGROUND, INGROUND>( );
  580. ik[10] = KernelManager->AddKernel<TE, 10, INGROUND, INGROUND>( );
  581. ik[11] = KernelManager->AddKernel<TE, 11, INGROUND, INGROUND>( );
  582. }
  583. }
  584. }
  585. if (std::abs(Pol[1]) > 0 || std::abs(Pol[0]) > 0) { // x or y grounded HED dipole
  586. switch (FieldsToCalculate) {
  587. case E:
  588. if ( lays == 0 && layr == 0) {
  589. ik[5] = KernelManager->AddKernel<TE, 5, INAIR, INAIR>( );
  590. ik[6] = KernelManager->AddKernel<TE, 6, INAIR, INAIR>( );
  591. ik[7] = KernelManager->AddKernel<TM, 7, INAIR, INAIR>( );
  592. ik[8] = KernelManager->AddKernel<TM, 8, INAIR, INAIR>( );
  593. ik[9] = KernelManager->AddKernel<TM, 9, INAIR, INAIR>( );
  594. } else if (lays == 0 && layr > 0) {
  595. ik[5] = KernelManager->AddKernel<TE, 5, INAIR, INGROUND>( );
  596. ik[6] = KernelManager->AddKernel<TE, 6, INAIR, INGROUND>( );
  597. ik[7] = KernelManager->AddKernel<TM, 7, INAIR, INGROUND>( );
  598. ik[8] = KernelManager->AddKernel<TM, 8, INAIR, INGROUND>( );
  599. ik[9] = KernelManager->AddKernel<TM, 9, INAIR, INGROUND>( );
  600. } else if (lays > 0 && layr == 0) {
  601. ik[5] = KernelManager->AddKernel<TE, 5, INGROUND, INAIR>( );
  602. ik[6] = KernelManager->AddKernel<TE, 6, INGROUND, INAIR>( );
  603. ik[7] = KernelManager->AddKernel<TM, 7, INGROUND, INAIR>( );
  604. ik[8] = KernelManager->AddKernel<TM, 8, INGROUND, INAIR>( );
  605. ik[9] = KernelManager->AddKernel<TM, 9, INGROUND, INAIR>( );
  606. } else {
  607. ik[5] = KernelManager->AddKernel<TE, 5, INGROUND, INGROUND>( );
  608. ik[6] = KernelManager->AddKernel<TE, 6, INGROUND, INGROUND>( );
  609. ik[7] = KernelManager->AddKernel<TM, 7, INGROUND, INGROUND>( );
  610. ik[8] = KernelManager->AddKernel<TM, 8, INGROUND, INGROUND>( );
  611. ik[9] = KernelManager->AddKernel<TM, 9, INGROUND, INGROUND>( );
  612. }
  613. break;
  614. case H:
  615. if ( lays == 0 && layr == 0) {
  616. ik[0] = KernelManager->AddKernel<TE, 0, INAIR, INAIR>( );
  617. ik[1] = KernelManager->AddKernel<TE, 1, INAIR, INAIR>( );
  618. ik[4] = KernelManager->AddKernel<TE, 4, INAIR, INAIR>( );
  619. ik[2] = KernelManager->AddKernel<TM, 2, INAIR, INAIR>( );
  620. ik[3] = KernelManager->AddKernel<TM, 3, INAIR, INAIR>( );
  621. } else if (lays == 0 && layr > 0) {
  622. ik[0] = KernelManager->AddKernel<TE, 0, INAIR, INGROUND>( );
  623. ik[1] = KernelManager->AddKernel<TE, 1, INAIR, INGROUND>( );
  624. ik[4] = KernelManager->AddKernel<TE, 4, INAIR, INGROUND>( );
  625. ik[2] = KernelManager->AddKernel<TM, 2, INAIR, INGROUND>( );
  626. ik[3] = KernelManager->AddKernel<TM, 3, INAIR, INGROUND>( );
  627. } else if (lays > 0 && layr == 0) {
  628. ik[0] = KernelManager->AddKernel<TE, 0, INGROUND, INAIR>( );
  629. ik[1] = KernelManager->AddKernel<TE, 1, INGROUND, INAIR>( );
  630. ik[4] = KernelManager->AddKernel<TE, 4, INGROUND, INAIR>( );
  631. ik[2] = KernelManager->AddKernel<TM, 2, INGROUND, INAIR>( );
  632. ik[3] = KernelManager->AddKernel<TM, 3, INGROUND, INAIR>( );
  633. } else {
  634. ik[0] = KernelManager->AddKernel<TE, 0, INGROUND, INGROUND>( );
  635. ik[1] = KernelManager->AddKernel<TE, 1, INGROUND, INGROUND>( );
  636. ik[4] = KernelManager->AddKernel<TE, 4, INGROUND, INGROUND>( );
  637. ik[2] = KernelManager->AddKernel<TM, 2, INGROUND, INGROUND>( );
  638. ik[3] = KernelManager->AddKernel<TM, 3, INGROUND, INGROUND>( );
  639. }
  640. break;
  641. case BOTH:
  642. if ( lays == 0 && layr == 0) {
  643. ik[5] = KernelManager->AddKernel<TE, 5, INAIR, INAIR>( );
  644. ik[6] = KernelManager->AddKernel<TE, 6, INAIR, INAIR>( );
  645. ik[7] = KernelManager->AddKernel<TM, 7, INAIR, INAIR>( );
  646. ik[8] = KernelManager->AddKernel<TM, 8, INAIR, INAIR>( );
  647. ik[9] = KernelManager->AddKernel<TM, 9, INAIR, INAIR>( );
  648. ik[0] = KernelManager->AddKernel<TE, 0, INAIR, INAIR>( );
  649. ik[1] = KernelManager->AddKernel<TE, 1, INAIR, INAIR>( );
  650. ik[4] = KernelManager->AddKernel<TE, 4, INAIR, INAIR>( );
  651. ik[2] = KernelManager->AddKernel<TM, 2, INAIR, INAIR>( );
  652. ik[3] = KernelManager->AddKernel<TM, 3, INAIR, INAIR>( );
  653. } else if (lays == 0 && layr > 0) {
  654. ik[5] = KernelManager->AddKernel<TE, 5, INAIR, INGROUND>( );
  655. ik[6] = KernelManager->AddKernel<TE, 6, INAIR, INGROUND>( );
  656. ik[7] = KernelManager->AddKernel<TM, 7, INAIR, INGROUND>( );
  657. ik[8] = KernelManager->AddKernel<TM, 8, INAIR, INGROUND>( );
  658. ik[9] = KernelManager->AddKernel<TM, 9, INAIR, INGROUND>( );
  659. ik[0] = KernelManager->AddKernel<TE, 0, INAIR, INGROUND>( );
  660. ik[1] = KernelManager->AddKernel<TE, 1, INAIR, INGROUND>( );
  661. ik[4] = KernelManager->AddKernel<TE, 4, INAIR, INGROUND>( );
  662. ik[2] = KernelManager->AddKernel<TM, 2, INAIR, INGROUND>( );
  663. ik[3] = KernelManager->AddKernel<TM, 3, INAIR, INGROUND>( );
  664. } else {
  665. ik[5] = KernelManager->AddKernel<TE, 5, INGROUND, INGROUND>( );
  666. ik[6] = KernelManager->AddKernel<TE, 6, INGROUND, INGROUND>( );
  667. ik[7] = KernelManager->AddKernel<TM, 7, INGROUND, INGROUND>( );
  668. ik[8] = KernelManager->AddKernel<TM, 8, INGROUND, INGROUND>( );
  669. ik[9] = KernelManager->AddKernel<TM, 9, INGROUND, INGROUND>( );
  670. ik[0] = KernelManager->AddKernel<TE, 0, INGROUND, INGROUND>( );
  671. ik[1] = KernelManager->AddKernel<TE, 1, INGROUND, INGROUND>( );
  672. ik[4] = KernelManager->AddKernel<TE, 4, INGROUND, INGROUND>( );
  673. ik[2] = KernelManager->AddKernel<TM, 2, INGROUND, INGROUND>( );
  674. ik[3] = KernelManager->AddKernel<TM, 3, INGROUND, INGROUND>( );
  675. }
  676. break;
  677. }
  678. }
  679. break;
  680. default:
  681. std::cerr << "Dipole type incorrect, in dipolesource.cpp";
  682. exit(EXIT_FAILURE);
  683. }
  684. }
  685. void DipoleSource::UpdateFields( const int& ifreq, HankelTransform* Hankel, const Real& wavef) {
  686. Vector3r Pol = Phat;
  687. switch (Type) {
  688. case (GROUNDEDELECTRICDIPOLE):
  689. //Hankel->ComputeRelated(rho, KernelManager);
  690. if (std::abs(Pol[2]) > 0) { // z dipole
  691. switch(FieldsToCalculate) {
  692. case E:
  693. f(10) = Hankel->Zgauss(10, TM, 1, rho, wavef, KernelManager->GetRAWKernel(ik[10])) / KernelManager->GetRAWKernel(ik[10])->GetYm();
  694. f(11) = Hankel->Zgauss(11, TM, 0, rho, wavef, KernelManager->GetRAWKernel(ik[11])) / KernelManager->GetRAWKernel(ik[11])->GetYm();
  695. this->Receivers->AppendEfield(ifreq, irec,
  696. -Pol[2]*QPI*cp*f(10)*Moment,
  697. -Pol[2]*QPI*sp*f(10)*Moment,
  698. Pol[2]*QPI*f(11)*Moment);
  699. break;
  700. case H:
  701. f(12) = Hankel->Zgauss(12, TM, 1, rho, wavef, KernelManager->GetRAWKernel(ik[12]));
  702. this->Receivers->AppendHfield(ifreq, irec,
  703. -Pol[2]*QPI*sp*f(12)*Moment,
  704. Pol[2]*QPI*cp*f(12)*Moment,
  705. 0. );
  706. break;
  707. case BOTH:
  708. f(10) = Hankel->Zgauss(10, TM, 1, rho, wavef, KernelManager->GetRAWKernel(ik[10])) / KernelManager->GetRAWKernel(ik[10])->GetYm();
  709. f(11) = Hankel->Zgauss(11, TM, 0, rho, wavef, KernelManager->GetRAWKernel(ik[11])) / KernelManager->GetRAWKernel(ik[11])->GetYm();
  710. this->Receivers->AppendEfield(ifreq, irec,
  711. -Pol[2]*QPI*cp*f(10)*Moment,
  712. -Pol[2]*QPI*sp*f(10)*Moment,
  713. Pol[2]*QPI*f(11)*Moment );
  714. f(12) = Hankel->Zgauss(12, TM, 1, rho, wavef, KernelManager->GetRAWKernel(ik[12]));
  715. this->Receivers->AppendHfield(ifreq, irec,
  716. -Pol[2]*QPI*sp*f(12)*Moment,
  717. Pol[2]*QPI*cp*f(12)*Moment,
  718. 0. );
  719. } // Fields to calculate Z polarity Electric dipole
  720. }
  721. if (std::abs(Pol[1]) > 0 || std::abs(Pol[0]) > 0) { // x or y dipole
  722. switch(FieldsToCalculate) {
  723. case E:
  724. f(2) = Hankel->Zgauss(2, TE, 0, rho, wavef, KernelManager->GetRAWKernel(ik[2])) * KernelManager->GetRAWKernel(ik[2])->GetZs();
  725. f(3) = Hankel->Zgauss(3, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[3])) * KernelManager->GetRAWKernel(ik[3])->GetZs();
  726. f(0) = Hankel->Zgauss(0, TM, 0, rho, wavef, KernelManager->GetRAWKernel(ik[0])) / KernelManager->GetRAWKernel(ik[0])->GetYm();
  727. f(1) = Hankel->Zgauss(1, TM, 1, rho, wavef, KernelManager->GetRAWKernel(ik[1])) / KernelManager->GetRAWKernel(ik[1])->GetYm();
  728. f(4) = Hankel->Zgauss(4, TM, 1, rho, wavef, KernelManager->GetRAWKernel(ik[4])) / KernelManager->GetRAWKernel(ik[4])->GetYm();
  729. if (std::abs(Pol[1]) > 0) {
  730. this->Receivers->AppendEfield(ifreq, irec,
  731. Pol[1]*Moment*QPI*scp*((f(0)-(Real)(2.)*f(1)/rho)+(f(2)-(Real)(2.)*f(3)/rho)),
  732. Pol[1]*Moment*QPI*((sps*f(0)+c2p*f(1)/rho)-(cps*f(2)-c2p*f(3)/rho)),
  733. Pol[1]*Moment*QPI*sp*f(4));
  734. }
  735. if (std::abs(Pol[0]) > 0) {
  736. this->Receivers->AppendEfield(ifreq, irec,
  737. Pol[0]*Moment*QPI*((cps*f(0)-c2p*f(1)/rho)-(sps*f(2)+c2p*f(3)/rho)),
  738. Pol[0]*Moment*QPI*scp*((f(0)-(Real)(2.)*f(1)/rho)+(f(2)-(Real)(2.)*f(3)/rho)),
  739. Pol[0]*Moment*QPI*cp*f(4) );
  740. }
  741. break;
  742. case H:
  743. f(5) = Hankel->Zgauss(5, TM, 0, rho, wavef, KernelManager->GetRAWKernel(ik[5]));
  744. f(6) = Hankel->Zgauss(6, TM, 1, rho, wavef, KernelManager->GetRAWKernel(ik[6]));
  745. f(7) = Hankel->Zgauss(7, TE, 0, rho, wavef, KernelManager->GetRAWKernel(ik[7]))*KernelManager->GetRAWKernel(ik[7])->GetZs()/KernelManager->GetRAWKernel(ik[7])->GetZm();
  746. f(8) = Hankel->Zgauss(8, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[8]))*KernelManager->GetRAWKernel(ik[8])->GetZs()/KernelManager->GetRAWKernel(ik[8])->GetZm();
  747. f(9) = Hankel->Zgauss(9, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[9]))*KernelManager->GetRAWKernel(ik[9])->GetZs()/KernelManager->GetRAWKernel(ik[9])->GetZm();
  748. if (std::abs(Pol[1]) > 0) {
  749. this->Receivers->AppendHfield(ifreq, irec,
  750. Pol[1]*QPI*(sps*f(5)+c2p*f(6)/rho-cps*f(7)+c2p*f(8)/rho)*Moment,
  751. Pol[1]*QPI*scp*(-f(5)+(Real)(2.)*f(6)/rho-f(7)+(Real)(2.)*f(8)/rho)*Moment,
  752. -Pol[1]*QPI*cp*f(9)*Moment );
  753. }
  754. if (std::abs(Pol[0]) > 0) {
  755. this->Receivers->AppendHfield(ifreq, irec,
  756. Pol[0]*Moment*QPI*scp*(f(5)-(Real)(2.)*f(6)/rho+f(7)-(Real)(2.)*f(8)/rho),
  757. Pol[0]*Moment*QPI*(-cps*f(5)+c2p*f(6)/rho+sps*f(7)+c2p*f(8)/rho),
  758. Pol[0]*Moment*QPI*sp*f(9) );
  759. }
  760. break;
  761. case BOTH:
  762. f(0) = Hankel->Zgauss(0, TM, 0, rho, wavef, KernelManager->GetRAWKernel(ik[0])) / KernelManager->GetRAWKernel(ik[0])->GetYm();
  763. f(1) = Hankel->Zgauss(1, TM, 1, rho, wavef, KernelManager->GetRAWKernel(ik[1])) / KernelManager->GetRAWKernel(ik[1])->GetYm();
  764. f(4) = Hankel->Zgauss(4, TM, 1, rho, wavef, KernelManager->GetRAWKernel(ik[4])) / KernelManager->GetRAWKernel(ik[4])->GetYm();
  765. f(2) = Hankel->Zgauss(2, TE, 0, rho, wavef, KernelManager->GetRAWKernel(ik[2])) * KernelManager->GetRAWKernel(ik[2])->GetZs();
  766. f(3) = Hankel->Zgauss(3, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[3])) * KernelManager->GetRAWKernel(ik[3])->GetZs();
  767. f(5) = Hankel->Zgauss(5, TM, 0, rho, wavef, KernelManager->GetRAWKernel(ik[5]));
  768. f(6) = Hankel->Zgauss(6, TM, 1, rho, wavef, KernelManager->GetRAWKernel(ik[6]));
  769. f(7) = Hankel->Zgauss(7, TE, 0, rho, wavef, KernelManager->GetRAWKernel(ik[7]))*KernelManager->GetRAWKernel(ik[7])->GetZs()/KernelManager->GetRAWKernel(ik[7])->GetZm();
  770. f(8) = Hankel->Zgauss(8, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[8]))*KernelManager->GetRAWKernel(ik[8])->GetZs()/KernelManager->GetRAWKernel(ik[8])->GetZm();
  771. f(9) = Hankel->Zgauss(9, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[9]))*KernelManager->GetRAWKernel(ik[9])->GetZs()/KernelManager->GetRAWKernel(ik[9])->GetZm();
  772. if (std::abs(Pol[1]) > 0) {
  773. this->Receivers->AppendEfield(ifreq, irec,
  774. Pol[1]*QPI*scp*((f(0)-(Real)(2.)*f(1)/rho)+(f(2)-(Real)(2.)*f(3)/rho))*Moment ,
  775. Pol[1]*QPI*((sps*f(0)+c2p*f(1)/rho)-(cps*f(2)-c2p*f(3)/rho))*Moment,
  776. Pol[1]*QPI*sp*f(4)*Moment);
  777. this->Receivers->AppendHfield(ifreq, irec,
  778. Pol[1]*QPI*(sps*f(5)+c2p*f(6)/rho-cps*f(7)+c2p*f(8)/rho)*Moment,
  779. Pol[1]*QPI*scp*(-f(5)+(Real)(2.)*f(6)/rho-f(7)+(Real)(2.)*f(8)/rho)*Moment,
  780. -Pol[1]*QPI*cp*f(9)*Moment );
  781. }
  782. if (std::abs(Pol[0]) > 0) {
  783. this->Receivers->AppendEfield(ifreq, irec,
  784. Pol[0]*Moment*QPI*((cps*f(0)-c2p*f(1)/rho)-(sps*f(2)+c2p*f(3)/rho)),
  785. Pol[0]*Moment*QPI*scp*((f(0)-(Real)(2.)*f(1)/rho)+(f(2)-(Real)(2.)*f(3)/rho)),
  786. Pol[0]*Moment*QPI*cp*f(4) );
  787. this->Receivers->AppendHfield(ifreq, irec,
  788. Pol[0]*Moment*QPI*scp*(f(5)-(Real)(2.)*f(6)/rho+f(7)-(Real)(2.)*f(8)/rho),
  789. Pol[0]*Moment*QPI*(-cps*f(5)+c2p*f(6)/rho+sps*f(7)+c2p*f(8)/rho),
  790. Pol[0]*Moment*QPI*sp*f(9) );
  791. }
  792. break;
  793. }
  794. }
  795. break; // GROUNDEDELECTRICDIPOLE
  796. case UNGROUNDEDELECTRICDIPOLE:
  797. if (std::abs(Pol[2]) > 0) { // z dipole
  798. switch(FieldsToCalculate) {
  799. case E:
  800. f(10) = 0;
  801. f(11) = Hankel->Zgauss(11, TM, 0, rho, wavef, KernelManager->GetRAWKernel(ik[11])) / KernelManager->GetRAWKernel(ik[11])->GetYm();
  802. this->Receivers->AppendEfield(ifreq, irec,
  803. -Pol[2]*QPI*cp*f(10)*Moment,
  804. -Pol[2]*QPI*sp*f(10)*Moment,
  805. Pol[2]*QPI*f(11)*Moment);
  806. break;
  807. case H:
  808. f(12) = Hankel->Zgauss(12, TM, 1, rho, wavef, KernelManager->GetRAWKernel(ik[12]));
  809. this->Receivers->AppendHfield(ifreq, irec,
  810. -Pol[2]*QPI*sp*f(12)*Moment,
  811. Pol[2]*QPI*cp*f(12)*Moment,
  812. 0. );
  813. break;
  814. case BOTH:
  815. f(10) = 0;
  816. f(11) = Hankel->Zgauss(11, TM, 0, rho, wavef, KernelManager->GetRAWKernel(ik[11])) / KernelManager->GetRAWKernel(ik[11])->GetYm();
  817. this->Receivers->AppendEfield(ifreq, irec,
  818. -Pol[2]*QPI*cp*f(10)*Moment,
  819. -Pol[2]*QPI*sp*f(10)*Moment,
  820. Pol[2]*QPI*f(11)*Moment );
  821. f(12) = Hankel->Zgauss(12, TM, 1, rho, wavef, KernelManager->GetRAWKernel(ik[12]));
  822. this->Receivers->AppendHfield(ifreq, irec,
  823. -Pol[2]*QPI*sp*f(12)*Moment,
  824. Pol[2]*QPI*cp*f(12)*Moment,
  825. 0. );
  826. } // Fields to calculate Z polarity Electric dipole
  827. }
  828. if (std::abs(Pol[1]) > 0 || std::abs(Pol[0]) > 0) { // x or y dipole
  829. switch(FieldsToCalculate) {
  830. case E:
  831. f(0) = 0;
  832. f(1) = 0;
  833. f(2) = Hankel->Zgauss(2, TE, 0, rho, wavef, KernelManager->GetRAWKernel(ik[2])) * KernelManager->GetRAWKernel(ik[2])->GetZs();
  834. f(3) = Hankel->Zgauss(3, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[3])) * KernelManager->GetRAWKernel(ik[3])->GetZs();
  835. f(4) = 0;
  836. if (std::abs(Pol[1]) > 0) {
  837. this->Receivers->AppendEfield(ifreq, irec,
  838. Pol[1]*QPI*scp*((f(0)-(Real)(2.)*f(1)/rho)+(f(2)-(Real)(2.)*f(3)/rho))*Moment,
  839. Pol[1]*QPI*((sps*f(0)+c2p*f(1)/rho)-(cps*f(2)-c2p*f(3)/rho))*Moment,
  840. Pol[1]*QPI*sp*f(4)*Moment);
  841. }
  842. if (std::abs(Pol[0]) > 0) {
  843. this->Receivers->AppendEfield(ifreq, irec,
  844. Pol[0]*Moment*QPI*((cps*f(0)-c2p*f(1)/rho)-(sps*f(2)+c2p*f(3)/rho)),
  845. Pol[0]*Moment*QPI*scp*((f(0)-(Real)(2.)*f(1)/rho)+(f(2)-(Real)(2.)*f(3)/rho)),
  846. Pol[0]*Moment*QPI*cp*f(4) );
  847. }
  848. break;
  849. case H:
  850. // TI - Comparisons with Amira show slight better agreement when neglecting these grounding terms
  851. f(5) = 0; //Hankel->Zgauss(5, TM, 0, rho, wavef, KernelManager->GetRAWKernel(ik[5]));
  852. f(6) = 0; //Hankel->Zgauss(6, TM, 1, rho, wavef, KernelManager->GetRAWKernel(ik[6]));
  853. f(7) = Hankel->Zgauss(7, TE, 0, rho, wavef, KernelManager->GetRAWKernel(ik[7]))*KernelManager->GetRAWKernel(ik[7])->GetZs()/KernelManager->GetRAWKernel(ik[7])->GetZm();
  854. f(8) = Hankel->Zgauss(8, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[8]))*KernelManager->GetRAWKernel(ik[8])->GetZs()/KernelManager->GetRAWKernel(ik[8])->GetZm();
  855. f(9) = Hankel->Zgauss(9, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[9]))*KernelManager->GetRAWKernel(ik[9])->GetZs()/KernelManager->GetRAWKernel(ik[9])->GetZm();
  856. if (std::abs(Pol[1]) > 0) {
  857. this->Receivers->AppendHfield(ifreq, irec,
  858. Pol[1]*QPI*(sps*f(5)+c2p*f(6)/rho-cps*f(7)+c2p*f(8)/rho)*Moment,
  859. Pol[1]*QPI*scp*(-f(5)+(Real)(2.)*f(6)/rho-f(7)+(Real)(2.)*f(8)/rho)*Moment,
  860. -Pol[1]*QPI*cp*f(9)*Moment );
  861. }
  862. if (std::abs(Pol[0]) > 0) {
  863. this->Receivers->AppendHfield(ifreq, irec,
  864. Pol[0]*Moment*QPI*scp*(f(5)-(Real)(2.)*f(6)/rho+f(7)-(Real)(2.)*f(8)/rho),
  865. Pol[0]*Moment*QPI*(-cps*f(5)+c2p*f(6)/rho+sps*f(7)+c2p*f(8)/rho),
  866. Pol[0]*Moment*QPI*sp*f(9) );
  867. }
  868. break;
  869. case BOTH:
  870. f(0) = 0;
  871. f(1) = 0;
  872. f(4) = 0;
  873. f(2) = Hankel->Zgauss(2, TE, 0, rho, wavef, KernelManager->GetRAWKernel(ik[2])) * KernelManager->GetRAWKernel(0)->GetZs();
  874. f(3) = Hankel->Zgauss(3, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[3])) * KernelManager->GetRAWKernel(1)->GetZs();
  875. f(5) = 0;//Hankel->Zgauss(5, TM, 0, rho, wavef, KernelManager->GetRAWKernel(ik[5]));
  876. f(6) = 0;//Hankel->Zgauss(6, TM, 1, rho, wavef, KernelManager->GetRAWKernel(ik[6]));
  877. f(7) = Hankel->Zgauss(7, TE, 0, rho, wavef, KernelManager->GetRAWKernel(ik[7]))*KernelManager->GetRAWKernel(ik[7])->GetZs()/KernelManager->GetRAWKernel(ik[7])->GetZm();
  878. f(8) = Hankel->Zgauss(8, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[8]))*KernelManager->GetRAWKernel(ik[8])->GetZs()/KernelManager->GetRAWKernel(ik[8])->GetZm();
  879. f(9) = Hankel->Zgauss(9, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[9]))*KernelManager->GetRAWKernel(ik[9])->GetZs()/KernelManager->GetRAWKernel(ik[9])->GetZm();
  880. if (std::abs(Pol[1]) > 0) {
  881. this->Receivers->AppendEfield(ifreq, irec,
  882. Pol[1]*QPI*scp*((f(0)-(Real)(2.)*f(1)/rho)+(f(2)-(Real)(2.)*f(3)/rho))*Moment ,
  883. Pol[1]*QPI*((sps*f(0)+c2p*f(1)/rho)-(cps*f(2)-c2p*f(3)/rho))*Moment,
  884. Pol[1]*QPI*sp*f(4)*Moment);
  885. this->Receivers->AppendHfield(ifreq, irec,
  886. Pol[1]*QPI*(sps*f(5)+c2p*f(6)/rho-cps*f(7)+c2p*f(8)/rho)*Moment,
  887. Pol[1]*QPI*scp*(-f(5)+(Real)(2.)*f(6)/rho-f(7)+(Real)(2.)*f(8)/rho)*Moment,
  888. -Pol[1]*QPI*cp*f(9)*Moment );
  889. }
  890. if (std::abs(Pol[0]) > 0) {
  891. this->Receivers->AppendEfield(ifreq, irec,
  892. Pol[0]*Moment*QPI*((cps*f(0)-c2p*f(1)/rho)-(sps*f(2)+c2p*f(3)/rho)),
  893. Pol[0]*Moment*QPI*scp*((f(0)-(Real)(2.)*f(1)/rho)+(f(2)-(Real)(2.)*f(3)/rho)),
  894. Pol[0]*Moment*QPI*cp*f(4) );
  895. this->Receivers->AppendHfield(ifreq, irec,
  896. Pol[0]*Moment*QPI*scp*(f(5)-(Real)(2.)*f(6)/rho+f(7)-(Real)(2.)*f(8)/rho),
  897. Pol[0]*Moment*QPI*(-cps*f(5)+c2p*f(6)/rho+sps*f(7)+c2p*f(8)/rho),
  898. Pol[0]*Moment*QPI*sp*f(9) );
  899. }
  900. break;
  901. }
  902. }
  903. break; // UNGROUNDEDELECTRICDIPOLE
  904. case MAGNETICDIPOLE:
  905. //Hankel->ComputeRelated(rho, KernelManager);
  906. if (std::abs(Pol[2]) > 0) { // z dipole
  907. switch(FieldsToCalculate) {
  908. case E:
  909. f(12)=Hankel->Zgauss(12, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[12]))*KernelManager->GetRAWKernel(ik[12])->GetZs();
  910. this->Receivers->AppendEfield(ifreq, irec,
  911. Pol[2]*Moment*QPI*sp*f(12),
  912. -Pol[2]*Moment*QPI*cp*f(12),
  913. 0);
  914. break;
  915. case H:
  916. f(10)=Hankel->Zgauss(10, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[10]))*KernelManager->GetRAWKernel(ik[10])->GetZs()/KernelManager->GetRAWKernel(ik[10])->GetZm();
  917. f(11)=Hankel->Zgauss(11, TE, 0, rho, wavef, KernelManager->GetRAWKernel(ik[11]))*KernelManager->GetRAWKernel(ik[11])->GetZs()/KernelManager->GetRAWKernel(ik[11])->GetZm();
  918. this->Receivers->AppendHfield(ifreq, irec,
  919. -Pol[2]*Moment*QPI*cp*f(10),
  920. -Pol[2]*Moment*QPI*sp*f(10),
  921. Pol[2]*Moment*QPI*f(11) );
  922. break;
  923. case BOTH:
  924. f(12)=Hankel->Zgauss(12, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[12]))*KernelManager->GetRAWKernel(ik[12])->GetZs();
  925. f(10)=Hankel->Zgauss(10, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[10]))*KernelManager->GetRAWKernel(ik[10])->GetZs()/KernelManager->GetRAWKernel(ik[10])->GetZm();
  926. f(11)=Hankel->Zgauss(11, TE, 0, rho, wavef, KernelManager->GetRAWKernel(ik[11]))*KernelManager->GetRAWKernel(ik[11])->GetZs()/KernelManager->GetRAWKernel(ik[11])->GetZm();
  927. this->Receivers->AppendEfield(ifreq, irec,
  928. Pol[2]*Moment*QPI*sp*f(12),
  929. -Pol[2]*Moment*QPI*cp*f(12),
  930. 0);
  931. this->Receivers->AppendHfield(ifreq, irec,
  932. -Pol[2]*Moment*QPI*cp*f(10),
  933. -Pol[2]*Moment*QPI*sp*f(10),
  934. Pol[2]*Moment*QPI*f(11) );
  935. break;
  936. }
  937. }
  938. if (std::abs(Pol[1]) > 0 || std::abs(Pol[0]) > 0) { // x or y grounded HED dipole
  939. switch (FieldsToCalculate) {
  940. case E:
  941. f(5) = Hankel->Zgauss(5, TE, 0, rho, wavef, KernelManager->GetRAWKernel(ik[5]))*KernelManager->GetRAWKernel(ik[5])->GetZs();
  942. f(6) = Hankel->Zgauss(6, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[6]))*KernelManager->GetRAWKernel(ik[6])->GetZs();
  943. f(7) = Hankel->Zgauss(7, TM, 0, rho, wavef, KernelManager->GetRAWKernel(ik[7]))*KernelManager->GetRAWKernel(ik[7])->GetKs()/KernelManager->GetRAWKernel(ik[7])->GetYm();
  944. f(8) = Hankel->Zgauss(8, TM, 1, rho, wavef, KernelManager->GetRAWKernel(ik[8]))*KernelManager->GetRAWKernel(ik[8])->GetKs()/KernelManager->GetRAWKernel(ik[8])->GetYm();
  945. f(9) = Hankel->Zgauss(9, TM, 1, rho, wavef, KernelManager->GetRAWKernel(ik[9]))*KernelManager->GetRAWKernel(ik[9])->GetKs()/KernelManager->GetRAWKernel(ik[9])->GetYm();
  946. if (std::abs(Pol[0]) > 0) {
  947. this->Receivers->AppendEfield(ifreq, irec,
  948. Pol[0]*Moment*QPI*scp*((-f(5)+(Real)(2.)*f(6)/rho)+(f(7)-(Real)(2.)*f(8)/rho)),
  949. Pol[0]*Moment*QPI*((cps*f(5)-c2p*f(6)/rho)+(sps*f(7)+c2p*f(8)/rho)),
  950. Pol[0]*Moment*QPI*sp*f(9));
  951. }
  952. if (std::abs(Pol[1]) > 0) {
  953. this->Receivers->AppendEfield(ifreq, irec,
  954. Pol[1]*Moment*QPI*(-(sps*f(5)+c2p*f(6)/rho)-(cps*f(7)-c2p*f(8)/rho)),
  955. Pol[1]*Moment*QPI*scp*((f(5)-(Real)(2.)*f(6)/rho)-(f(7)-(Real)(2.)*f(8)/rho)),
  956. -Pol[1]*Moment*QPI*cp*f(9) );
  957. }
  958. break;
  959. case H:
  960. f(0) = Hankel->Zgauss(0, TE, 0, rho, wavef, KernelManager->GetRAWKernel(ik[0]))*KernelManager->GetRAWKernel(ik[0])->GetZs()/KernelManager->GetRAWKernel(ik[0])->GetZm();
  961. f(1) = Hankel->Zgauss(1, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[1]))*KernelManager->GetRAWKernel(ik[1])->GetZs()/KernelManager->GetRAWKernel(ik[1])->GetZm();
  962. f(4) = Hankel->Zgauss(4, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[4]))*KernelManager->GetRAWKernel(ik[4])->GetZs()/KernelManager->GetRAWKernel(ik[4])->GetZm();
  963. f(2) = Hankel->Zgauss(2, TM, 0, rho, wavef, KernelManager->GetRAWKernel(ik[2]))*KernelManager->GetRAWKernel(ik[2])->GetKs();
  964. f(3) = Hankel->Zgauss(3, TM, 1, rho, wavef, KernelManager->GetRAWKernel(ik[3]))*KernelManager->GetRAWKernel(ik[3])->GetKs();
  965. if (std::abs(Pol[0]) > 0) {
  966. this->Receivers->AppendHfield(ifreq, irec,
  967. Pol[0]*Moment*QPI*(cps*f(0)-c2p*f(1)/rho+(sps*f(2)+c2p*f(3)/rho)),
  968. Pol[0]*Moment*QPI*scp*(f(0)-(Real)(2.)*f(1)/rho-(f(2)-(Real)(2.)*f(3)/rho)),
  969. Pol[0]*Moment*QPI*cp*f(4) );
  970. }
  971. if (std::abs(Pol[1]) > 0) {
  972. this->Receivers->AppendHfield(ifreq, irec,
  973. Pol[1]*Moment*QPI*scp*(f(0)-(Real)(2.)*f(1)/rho-(f(2)-(Real)(2.)*f(3)/rho)),
  974. Pol[1]*Moment*QPI*(sps*f(0)+c2p*f(1)/rho+(cps*f(2)-c2p*f(3)/rho)),
  975. Pol[1]*Moment*QPI*sp*f(4));
  976. }
  977. break;
  978. case BOTH:
  979. f(5) = Hankel->Zgauss(5, TE, 0, rho, wavef, KernelManager->GetRAWKernel(ik[5]))*KernelManager->GetRAWKernel(ik[5])->GetZs();
  980. f(6) = Hankel->Zgauss(6, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[6]))*KernelManager->GetRAWKernel(ik[6])->GetZs();
  981. f(7) = Hankel->Zgauss(7, TM, 0, rho, wavef, KernelManager->GetRAWKernel(ik[7]))*KernelManager->GetRAWKernel(ik[7])->GetKs()/KernelManager->GetRAWKernel(ik[7])->GetYm();
  982. f(8) = Hankel->Zgauss(8, TM, 1, rho, wavef, KernelManager->GetRAWKernel(ik[8]))*KernelManager->GetRAWKernel(ik[8])->GetKs()/KernelManager->GetRAWKernel(ik[8])->GetYm();
  983. f(9) = Hankel->Zgauss(9, TM, 1, rho, wavef, KernelManager->GetRAWKernel(ik[9]))*KernelManager->GetRAWKernel(ik[9])->GetKs()/KernelManager->GetRAWKernel(ik[9])->GetYm();
  984. f(0) = Hankel->Zgauss(0, TE, 0, rho, wavef, KernelManager->GetRAWKernel(ik[0]))*KernelManager->GetRAWKernel(ik[0])->GetZs()/KernelManager->GetRAWKernel(ik[0])->GetZm();
  985. f(1) = Hankel->Zgauss(1, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[1]))*KernelManager->GetRAWKernel(ik[1])->GetZs()/KernelManager->GetRAWKernel(ik[1])->GetZm();
  986. f(4) = Hankel->Zgauss(4, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[4]))*KernelManager->GetRAWKernel(ik[4])->GetZs()/KernelManager->GetRAWKernel(ik[4])->GetZm();
  987. f(2) = Hankel->Zgauss(2, TM, 0, rho, wavef, KernelManager->GetRAWKernel(ik[2]))*KernelManager->GetRAWKernel(ik[2])->GetKs();
  988. f(3) = Hankel->Zgauss(3, TM, 1, rho, wavef, KernelManager->GetRAWKernel(ik[3]))*KernelManager->GetRAWKernel(ik[3])->GetKs();
  989. if (std::abs(Pol[0]) > 0) {
  990. this->Receivers->AppendEfield(ifreq, irec,
  991. Pol[0]*Moment*QPI*scp*((-f(5)+(Real)(2.)*f(6)/rho)+(f(7)-(Real)(2.)*f(8)/rho)),
  992. Pol[0]*Moment*QPI*((cps*f(5)-c2p*f(6)/rho)+(sps*f(7)+c2p*f(8)/rho)),
  993. Pol[0]*Moment*QPI*sp*f(9));
  994. this->Receivers->AppendHfield(ifreq, irec,
  995. Pol[0]*Moment*QPI*(cps*f(0)-c2p*f(1)/rho+(sps*f(2)+c2p*f(3)/rho)),
  996. Pol[0]*Moment*QPI*scp*(f(0)-(Real)(2.)*f(1)/rho-(f(2)-(Real)(2.)*f(3)/rho)),
  997. Pol[0]*Moment*QPI*cp*f(4) );
  998. }
  999. if (std::abs(Pol[1]) > 0) {
  1000. this->Receivers->AppendEfield(ifreq, irec,
  1001. Pol[1]*Moment*QPI*(-(sps*f(5)+c2p*f(6)/rho)-(cps*f(7)-c2p*f(8)/rho)),
  1002. Pol[1]*Moment*QPI*scp*((f(5)-(Real)(2.)*f(6)/rho)-(f(7)-(Real)(2.)*f(8)/rho)),
  1003. -Pol[1]*Moment*QPI*cp*f(9) );
  1004. this->Receivers->AppendHfield(ifreq, irec,
  1005. Pol[1]*Moment*QPI*scp*(f(0)-(Real)(2.)*f(1)/rho-(f(2)-(Real)(2.)*f(3)/rho)),
  1006. Pol[1]*Moment*QPI*(sps*f(0)+c2p*f(1)/rho+(cps*f(2)-c2p*f(3)/rho)),
  1007. Pol[1]*Moment*QPI*sp*f(4));
  1008. }
  1009. break;
  1010. }
  1011. }
  1012. break;
  1013. case NOSOURCETYPE:
  1014. throw NonValidDipoleType(this);
  1015. } // Source Type Switch
  1016. }
  1017. // ==================== INQUIRY ======================
  1018. std::shared_ptr<KernelEM1DManager> DipoleSource::GetKernelManager() {
  1019. return KernelManager;
  1020. }
  1021. Vector3r DipoleSource::GetLocation() {
  1022. return this->Location;
  1023. }
  1024. #ifdef LEMMAUSEVTK
  1025. vtkActor* DipoleSource::GetVtkActor() {
  1026. vtkActor* vActor;
  1027. vtkLineSource* vLineSource;
  1028. vtkTubeFilter* vTube;
  1029. vtkPolyDataMapper* vMapper;
  1030. vtkRegularPolygonSource* vCircleSource;
  1031. vLineSource = vtkLineSource::New();
  1032. vTube = vtkTubeFilter::New();
  1033. vMapper = vtkPolyDataMapper::New();
  1034. vCircleSource = vtkRegularPolygonSource::New();
  1035. VectorXr M0 = Location - .5*Moment*Phat;
  1036. VectorXr M1 = Location + .5*Moment*Phat;
  1037. vActor = vtkActor::New();
  1038. switch (Type) {
  1039. case GROUNDEDELECTRICDIPOLE:
  1040. vLineSource->SetPoint1( M0(0), M0(1), M0(2));
  1041. vLineSource->SetPoint2( M1(0), M1(1), M1(2));
  1042. vTube->SetInputConnection(vLineSource->GetOutputPort());
  1043. vTube->SetRadius(.1 * std::abs(Moment));
  1044. vTube->SetNumberOfSides(6);
  1045. vTube->SetCapping(1);
  1046. vMapper->SetInputConnection(vTube->GetOutputPort());
  1047. vActor->SetMapper(vMapper);
  1048. vActor->GetProperty()->SetColor(Phat[0], Phat[1], Phat[2]);
  1049. break;
  1050. case UNGROUNDEDELECTRICDIPOLE:
  1051. vLineSource->SetPoint1( M0(0), M0(1), M0(2));
  1052. vLineSource->SetPoint2( M1(0), M1(1), M1(2));
  1053. vTube->SetInputConnection(vLineSource->GetOutputPort());
  1054. vTube->SetRadius(.1 * std::abs(Moment));
  1055. vTube->SetNumberOfSides(6);
  1056. vTube->SetCapping(1);
  1057. vMapper->SetInputConnection(vTube->GetOutputPort());
  1058. vActor->SetMapper(vMapper);
  1059. //vActor->GetProperty()->SetColor(Phat[0], Phat[1], Phat[2]);
  1060. vActor->GetProperty()->SetColor(rand()/(Real)(RAND_MAX), rand()/(Real)(RAND_MAX), rand()/(Real)(RAND_MAX));
  1061. vActor->GetProperty()->SetOpacity(1.);
  1062. break;
  1063. case MAGNETICDIPOLE:
  1064. vCircleSource->SetCenter(Location(0), Location(1),
  1065. Location(2));
  1066. vCircleSource->SetNumberOfSides(360);
  1067. vCircleSource->SetNormal(Phat[0], Phat[1], Phat[2]);
  1068. vCircleSource->SetRadius(0.2); // .2 m radius
  1069. vCircleSource->SetGeneratePolygon(false);
  1070. vCircleSource->SetGeneratePolyline(true);
  1071. vCircleSource->Update();
  1072. vTube->SetInputConnection(vCircleSource->GetOutputPort());
  1073. //vTube->SetRadius( max((float)(*xCoords->GetTuple(nx)),
  1074. // (float)(*yCoords->GetTuple(ny))) / 100);
  1075. vTube->SetRadius(.1*std::abs(Moment));
  1076. vTube->SetNumberOfSides(6);
  1077. vTube->SetCapping(1);
  1078. vMapper->SetInputConnection(vTube->GetOutputPort());
  1079. vActor->SetMapper(vMapper);
  1080. vActor->GetProperty()->SetColor(.9,.2,.9);
  1081. break;
  1082. default:
  1083. throw NonValidDipoleType();
  1084. }
  1085. vLineSource->Delete();
  1086. vCircleSource->Delete();
  1087. vTube->Delete();
  1088. vMapper->Delete();
  1089. return vActor;
  1090. }
  1091. #endif
  1092. Real DipoleSource::GetLocation(const int& coordinate) {
  1093. switch (coordinate) {
  1094. case (0):
  1095. return this->Location.x();
  1096. //break; // implicit
  1097. case (1):
  1098. return this->Location.y();
  1099. //break; // implicit
  1100. case (2):
  1101. return this->Location.z();
  1102. //break; // implicit
  1103. default:
  1104. throw NonValidLocationCoordinate( );
  1105. }
  1106. }
  1107. DIPOLESOURCETYPE DipoleSource::GetDipoleSourceType() {
  1108. return this->Type;
  1109. }
  1110. //DipoleSourcePolarisation DipoleSource::GetDipoleSourcePolarisation() {
  1111. // return this->Polarisation;
  1112. //}
  1113. Real DipoleSource::GetAngularFrequency(const int& ifreq) {
  1114. return 2.*PI*this->Freqs(ifreq);
  1115. }
  1116. Real DipoleSource::GetFrequency(const int& ifreq) {
  1117. return this->Freqs(ifreq);
  1118. }
  1119. VectorXr DipoleSource::GetFrequencies( ) {
  1120. return this->Freqs;
  1121. }
  1122. Real DipoleSource::GetPhase() {
  1123. return this->Phase;
  1124. }
  1125. Real DipoleSource::GetMoment() {
  1126. return this->Moment;
  1127. }
  1128. int DipoleSource::GetNumberOfFrequencies() {
  1129. return (int)(this->Freqs.size());
  1130. }
  1131. void DipoleSource::SetNumberOfFrequencies(const int &nfreq){
  1132. Freqs.resize(nfreq);
  1133. Freqs.setZero();
  1134. }
  1135. void DipoleSource::SetFrequency(const int &ifreq, const Real &freq){
  1136. Freqs(ifreq) = freq;
  1137. }
  1138. void DipoleSource::SetFrequencies(const VectorXr &freqs){
  1139. Freqs = freqs;
  1140. }
  1141. /////////////////////////////////////////////////////////////////
  1142. /////////////////////////////////////////////////////////////////
  1143. // Error classes
  1144. NullDipoleSource::NullDipoleSource() :
  1145. runtime_error( "NULL VALUED DIPOLE SOURCE") {}
  1146. NonValidDipoleTypeAssignment::NonValidDipoleTypeAssignment( ) :
  1147. runtime_error( "NON VALID DIPOLE TYPE ASSIGNMENT") { }
  1148. NonValidDipoleType::NonValidDipoleType( LemmaObject* ptr ) :
  1149. runtime_error( "NON VALID DIPOLE TYPE") {
  1150. std::cout << "Thrown by instance of "
  1151. << ptr->GetName() << std::endl;
  1152. }
  1153. NonValidDipoleType::NonValidDipoleType( ) :
  1154. runtime_error( "NON VALID DIPOLE TYPE") { }
  1155. NonValidDipolePolarity::NonValidDipolePolarity () :
  1156. runtime_error( "NON VALID DIPOLE POLARITY") { }
  1157. NonValidDipolePolarisation::NonValidDipolePolarisation( ) :
  1158. runtime_error( "NON VALID DIPOLE TYPE") { }
  1159. NonValidDipolePolarisationAssignment::
  1160. NonValidDipolePolarisationAssignment( ) :
  1161. runtime_error( "NON VALID DIPOLE POLARISATION ASSIGNMENT") { }
  1162. NonValidLocationCoordinate::NonValidLocationCoordinate( ) :
  1163. runtime_error( "NON VALID LOCATION COORDINATE REQUESTED") { }
  1164. }