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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337
  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->Polarisation = pol;
  186. this->Phat = (VectorXr(3) << 1, 0, 0).finished();
  187. break;
  188. case (YPOLARISATION):
  189. //this->Polarisation = pol;
  190. this->Phat = (VectorXr(3) << 0, 1, 0).finished();
  191. break;
  192. case (ZPOLARISATION):
  193. //this->Polarisation = pol;
  194. this->Phat = (VectorXr(3) << 0, 0, 1).finished();
  195. break;
  196. default:
  197. throw NonValidDipolePolarisationAssignment();
  198. }
  199. }
  200. void DipoleSource::SetMoment(const Real &moment) {
  201. this->Moment = moment;
  202. }
  203. // ==================== OPERATIONS =====================
  204. void DipoleSource::SetKernels(const int& ifreq, const FIELDCALCULATIONS& Fields , std::shared_ptr<FieldPoints> ReceiversIn, const int& irecin,
  205. std::shared_ptr<LayeredEarthEM> EarthIn ) {
  206. if (Receivers != ReceiversIn) {
  207. Receivers = ReceiversIn;
  208. }
  209. if (Earth != EarthIn) {
  210. Earth = EarthIn;
  211. }
  212. if (irecin != irec) {
  213. irec = irecin;
  214. }
  215. if (FieldsToCalculate != Fields) {
  216. FieldsToCalculate = Fields;
  217. }
  218. xxp = Receivers->GetLocation(irec)[0] - Location[0];
  219. yyp = Receivers->GetLocation(irec)[1] - Location[1];
  220. rho = (Receivers->GetLocation(irec).head<2>() - Location.head<2>()).norm();
  221. sp = yyp/rho;
  222. cp = xxp/rho;
  223. scp = sp*cp;
  224. sps = sp*sp;
  225. cps = cp*cp;
  226. c2p = cps-sps;
  227. f = VectorXcr::Zero(13);
  228. ik = VectorXi::Zero(13);
  229. lays = Earth->GetLayerAtThisDepth(Location[2]);
  230. layr = Earth->GetLayerAtThisDepth(Receivers->GetLocation(irec)[2]);
  231. KernelManager = KernelEM1DManager::NewSP();
  232. KernelManager->SetEarth(Earth);
  233. // alternative is to use weak_ptr here, this is deep and internal, and we are safe.
  234. KernelManager->SetDipoleSource( shared_from_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. // TODO we could make the dipoles template specializations avoiding this rats nest of switch statements. Probably
  240. // not the most critical piece though
  241. void DipoleSource::ReSetKernels(const int& ifreq, const FIELDCALCULATIONS& Fields , std::shared_ptr<FieldPoints> Receivers, const int& irec,
  242. std::shared_ptr<LayeredEarthEM> Earth ) {
  243. Vector3r Pol = Phat;
  244. switch (Type) {
  245. case (GROUNDEDELECTRICDIPOLE):
  246. if (std::abs(Pol[2]) > 0) { // z dipole
  247. switch(FieldsToCalculate) {
  248. case E:
  249. if (lays == 0 && layr == 0) {
  250. ik[10] = KernelManager->AddKernel<TM, 10, INAIR, INAIR>( );
  251. ik[11] = KernelManager->AddKernel<TM, 11, INAIR, INAIR>( );
  252. } else if (lays == 0 && layr > 0) {
  253. ik[10] = KernelManager->AddKernel<TM, 10, INAIR, INGROUND>( );
  254. ik[11] = KernelManager->AddKernel<TM, 11, INAIR, INGROUND>( );
  255. } else if (lays > 0 && layr == 0) {
  256. ik[10] = KernelManager->AddKernel<TM, 10, INGROUND, INAIR>( );
  257. ik[11] = KernelManager->AddKernel<TM, 11, INGROUND, INAIR>( );
  258. } else {
  259. ik[10] = KernelManager->AddKernel<TM, 10, INGROUND, INGROUND>( );
  260. ik[11] = KernelManager->AddKernel<TM, 11, INGROUND, INGROUND>( );
  261. }
  262. break;
  263. case H:
  264. if (lays == 0 && layr == 0) {
  265. ik[12] = KernelManager->AddKernel<TM, 12, INAIR, INAIR>( );
  266. } else if (lays == 0 && layr > 0) {
  267. ik[12] = KernelManager->AddKernel<TM, 12, INAIR, INGROUND>( );
  268. } else if (lays > 0 && layr == 0) {
  269. ik[12] = KernelManager->AddKernel<TM, 12, INGROUND, INAIR>( );
  270. } else {
  271. ik[12] = KernelManager->AddKernel<TM, 12, INGROUND, INGROUND>( );
  272. }
  273. break;
  274. case BOTH:
  275. if ( lays == 0 && layr == 0) {
  276. ik[10] = KernelManager->AddKernel<TM, 10, INAIR, INAIR>( );
  277. ik[11] = KernelManager->AddKernel<TM, 11, INAIR, INAIR>( );
  278. ik[12] = KernelManager->AddKernel<TM, 12, INAIR, INAIR>( );
  279. } else if (lays == 0 && layr > 0) {
  280. ik[10] = KernelManager->AddKernel<TM, 10, INAIR, INGROUND>( );
  281. ik[11] = KernelManager->AddKernel<TM, 11, INAIR, INGROUND>( );
  282. ik[12] = KernelManager->AddKernel<TM, 12, INAIR, INGROUND>( );
  283. } else if (lays > 0 && layr == 0) {
  284. ik[10] = KernelManager->AddKernel<TM, 10, INGROUND, INAIR>( );
  285. ik[11] = KernelManager->AddKernel<TM, 11, INGROUND, INAIR>( );
  286. ik[12] = KernelManager->AddKernel<TM, 12, INGROUND, INAIR>( );
  287. } else {
  288. ik[10] = KernelManager->AddKernel<TM, 10, INGROUND, INGROUND>( );
  289. ik[11] = KernelManager->AddKernel<TM, 11, INGROUND, INGROUND>( );
  290. ik[12] = KernelManager->AddKernel<TM, 12, INGROUND, INGROUND>( );
  291. }
  292. }
  293. }
  294. if (std::abs(Pol[1]) > 0 || std::abs(Pol[0]) > 0) { // x or y grounded HED dipole
  295. switch(FieldsToCalculate) {
  296. case E:
  297. if ( lays == 0 && layr == 0) {
  298. ik[0] = KernelManager->AddKernel<TM, 0, INAIR, INAIR>( );
  299. ik[1] = KernelManager->AddKernel<TM, 1, INAIR, INAIR>( );
  300. ik[4] = KernelManager->AddKernel<TM, 4, INAIR, INAIR>( );
  301. ik[2] = KernelManager->AddKernel<TE, 2, INAIR, INAIR>( );
  302. ik[3] = KernelManager->AddKernel<TE, 3, INAIR, INAIR>( );
  303. } else if (lays == 0 && layr > 0) {
  304. ik[0] = KernelManager->AddKernel<TM, 0, INAIR, INGROUND>( );
  305. ik[1] = KernelManager->AddKernel<TM, 1, INAIR, INGROUND>( );
  306. ik[4] = KernelManager->AddKernel<TM, 4, INAIR, INGROUND>( );
  307. ik[2] = KernelManager->AddKernel<TE, 2, INAIR, INGROUND>( );
  308. ik[3] = KernelManager->AddKernel<TE, 3, INAIR, INGROUND>( );
  309. } else if (lays > 0 && layr == 0) {
  310. ik[0] = KernelManager->AddKernel<TM, 0, INGROUND, INAIR>( );
  311. ik[1] = KernelManager->AddKernel<TM, 1, INGROUND, INAIR>( );
  312. ik[4] = KernelManager->AddKernel<TM, 4, INGROUND, INAIR>( );
  313. ik[2] = KernelManager->AddKernel<TE, 2, INGROUND, INAIR>( );
  314. ik[3] = KernelManager->AddKernel<TE, 3, INGROUND, INAIR>( );
  315. } else {
  316. ik[0] = KernelManager->AddKernel<TM, 0, INGROUND, INGROUND>( );
  317. ik[1] = KernelManager->AddKernel<TM, 1, INGROUND, INGROUND>( );
  318. ik[4] = KernelManager->AddKernel<TM, 4, INGROUND, INGROUND>( );
  319. ik[2] = KernelManager->AddKernel<TE, 2, INGROUND, INGROUND>( );
  320. ik[3] = KernelManager->AddKernel<TE, 3, INGROUND, INGROUND>( );
  321. }
  322. break;
  323. case H:
  324. if (lays == 0 && layr == 0) {
  325. ik[5] = KernelManager->AddKernel<TM, 5, INAIR, INAIR>( );
  326. ik[6] = KernelManager->AddKernel<TM, 6, INAIR, INAIR>( );
  327. ik[7] = KernelManager->AddKernel<TE, 7, INAIR, INAIR>( );
  328. ik[8] = KernelManager->AddKernel<TE, 8, INAIR, INAIR>( );
  329. ik[9] = KernelManager->AddKernel<TE, 9, INAIR, INAIR>( );
  330. } else if (lays == 0 && layr > 0) {
  331. ik[5] = KernelManager->AddKernel<TM, 5, INAIR, INGROUND>( );
  332. ik[6] = KernelManager->AddKernel<TM, 6, INAIR, INGROUND>( );
  333. ik[7] = KernelManager->AddKernel<TE, 7, INAIR, INGROUND>( );
  334. ik[8] = KernelManager->AddKernel<TE, 8, INAIR, INGROUND>( );
  335. ik[9] = KernelManager->AddKernel<TE, 9, INAIR, INGROUND>( );
  336. } else if (lays > 0 && layr == 0) {
  337. ik[5] = KernelManager->AddKernel<TM, 5, INGROUND, INAIR>( );
  338. ik[6] = KernelManager->AddKernel<TM, 6, INGROUND, INAIR>( );
  339. ik[7] = KernelManager->AddKernel<TE, 7, INGROUND, INAIR>( );
  340. ik[8] = KernelManager->AddKernel<TE, 8, INGROUND, INAIR>( );
  341. ik[9] = KernelManager->AddKernel<TE, 9, INGROUND, INAIR>( );
  342. } else {
  343. ik[5] = KernelManager->AddKernel<TM, 5, INGROUND, INGROUND>( );
  344. ik[6] = KernelManager->AddKernel<TM, 6, INGROUND, INGROUND>( );
  345. ik[7] = KernelManager->AddKernel<TE, 7, INGROUND, INGROUND>( );
  346. ik[8] = KernelManager->AddKernel<TE, 8, INGROUND, INGROUND>( );
  347. ik[9] = KernelManager->AddKernel<TE, 9, INGROUND, INGROUND>( );
  348. }
  349. break;
  350. case BOTH:
  351. if (lays == 0 && layr == 0) {
  352. ik[0] = KernelManager->AddKernel<TM, 0, INAIR, INAIR>( );
  353. ik[1] = KernelManager->AddKernel<TM, 1, INAIR, INAIR>( );
  354. ik[4] = KernelManager->AddKernel<TM, 4, INAIR, INAIR>( );
  355. ik[2] = KernelManager->AddKernel<TE, 2, INAIR, INAIR>( );
  356. ik[3] = KernelManager->AddKernel<TE, 3, INAIR, INAIR>( );
  357. ik[5] = KernelManager->AddKernel<TM, 5, INAIR, INAIR>( );
  358. ik[6] = KernelManager->AddKernel<TM, 6, INAIR, INAIR>( );
  359. ik[7] = KernelManager->AddKernel<TE, 7, INAIR, INAIR>( );
  360. ik[8] = KernelManager->AddKernel<TE, 8, INAIR, INAIR>( );
  361. ik[9] = KernelManager->AddKernel<TE, 9, INAIR, INAIR>( );
  362. } else if (lays == 0 && layr > 0) {
  363. ik[0] = KernelManager->AddKernel<TM, 0, INAIR, INGROUND>( );
  364. ik[1] = KernelManager->AddKernel<TM, 1, INAIR, INGROUND>( );
  365. ik[4] = KernelManager->AddKernel<TM, 4, INAIR, INGROUND>( );
  366. ik[2] = KernelManager->AddKernel<TE, 2, INAIR, INGROUND>( );
  367. ik[3] = KernelManager->AddKernel<TE, 3, INAIR, INGROUND>( );
  368. ik[5] = KernelManager->AddKernel<TM, 5, INAIR, INGROUND>( );
  369. ik[6] = KernelManager->AddKernel<TM, 6, INAIR, INGROUND>( );
  370. ik[7] = KernelManager->AddKernel<TE, 7, INAIR, INGROUND>( );
  371. ik[8] = KernelManager->AddKernel<TE, 8, INAIR, INGROUND>( );
  372. ik[9] = KernelManager->AddKernel<TE, 9, INAIR, INGROUND>( );
  373. } else if (lays > 0 && layr == 0) {
  374. ik[0] = KernelManager->AddKernel<TM, 0, INGROUND, INAIR>( );
  375. ik[1] = KernelManager->AddKernel<TM, 1, INGROUND, INAIR>( );
  376. ik[4] = KernelManager->AddKernel<TM, 4, INGROUND, INAIR>( );
  377. ik[2] = KernelManager->AddKernel<TE, 2, INGROUND, INAIR>( );
  378. ik[3] = KernelManager->AddKernel<TE, 3, INGROUND, INAIR>( );
  379. ik[5] = KernelManager->AddKernel<TM, 5, INGROUND, INAIR>( );
  380. ik[6] = KernelManager->AddKernel<TM, 6, INGROUND, INAIR>( );
  381. ik[7] = KernelManager->AddKernel<TE, 7, INGROUND, INAIR>( );
  382. ik[8] = KernelManager->AddKernel<TE, 8, INGROUND, INAIR>( );
  383. ik[9] = KernelManager->AddKernel<TE, 9, INGROUND, INAIR>( );
  384. } else {
  385. ik[0] = KernelManager->AddKernel<TM, 0, INGROUND, INGROUND>( );
  386. ik[1] = KernelManager->AddKernel<TM, 1, INGROUND, INGROUND>( );
  387. ik[4] = KernelManager->AddKernel<TM, 4, INGROUND, INGROUND>( );
  388. ik[2] = KernelManager->AddKernel<TE, 2, INGROUND, INGROUND>( );
  389. ik[3] = KernelManager->AddKernel<TE, 3, INGROUND, INGROUND>( );
  390. ik[5] = KernelManager->AddKernel<TM, 5, INGROUND, INGROUND>( );
  391. ik[6] = KernelManager->AddKernel<TM, 6, INGROUND, INGROUND>( );
  392. ik[7] = KernelManager->AddKernel<TE, 7, INGROUND, INGROUND>( );
  393. ik[8] = KernelManager->AddKernel<TE, 8, INGROUND, INGROUND>( );
  394. ik[9] = KernelManager->AddKernel<TE, 9, INGROUND, INGROUND>( );
  395. }
  396. break;
  397. }
  398. }
  399. break;
  400. case (UNGROUNDEDELECTRICDIPOLE):
  401. if (std::abs(Pol[2]) > 0) { // z dipole
  402. switch(FieldsToCalculate) {
  403. case E:
  404. if (lays == 0 && layr == 0) {
  405. ik[11] = KernelManager->AddKernel<TM, 11, INAIR, INAIR>( );
  406. } else if (lays == 0 && layr > 0) {
  407. ik[11] = KernelManager->AddKernel<TM, 11, INAIR, INGROUND>( );
  408. } else if (lays > 0 && layr == 0) {
  409. ik[11] = KernelManager->AddKernel<TM, 11, INGROUND, INAIR>( );
  410. } else {
  411. ik[11] = KernelManager->AddKernel<TM, 11, INGROUND, INGROUND>( );
  412. }
  413. break;
  414. case H:
  415. if (lays == 0 && layr == 0) {
  416. ik[12] = KernelManager->AddKernel<TM, 12, INAIR, INAIR>( );
  417. } else if (lays == 0 && layr > 0) {
  418. ik[12] = KernelManager->AddKernel<TM, 12, INAIR, INGROUND>( );
  419. } else if (lays > 0 && layr == 0) {
  420. ik[12] = KernelManager->AddKernel<TM, 12, INGROUND, INAIR>( );
  421. } else {
  422. ik[12] = KernelManager->AddKernel<TM, 12, INGROUND, INGROUND>( );
  423. }
  424. break;
  425. case BOTH:
  426. if ( lays == 0 && layr == 0) {
  427. ik[11] = KernelManager->AddKernel<TM, 11, INAIR, INAIR>( );
  428. ik[12] = KernelManager->AddKernel<TM, 12, INAIR, INAIR>( );
  429. } else if (lays == 0 && layr > 0) {
  430. ik[11] = KernelManager->AddKernel<TM, 11, INAIR, INGROUND>( );
  431. ik[12] = KernelManager->AddKernel<TM, 12, INAIR, INGROUND>( );
  432. } else if (lays > 0 && layr == 0) {
  433. ik[11] = KernelManager->AddKernel<TM, 11, INGROUND, INAIR>( );
  434. ik[12] = KernelManager->AddKernel<TM, 12, INGROUND, INAIR>( );
  435. } else {
  436. ik[11] = KernelManager->AddKernel<TM, 11, INGROUND, INGROUND>( );
  437. ik[12] = KernelManager->AddKernel<TM, 12, INGROUND, INGROUND>( );
  438. }
  439. }
  440. }
  441. if (std::abs(Pol[1]) > 0 || std::abs(Pol[0]) > 0) { // x or y grounded HED dipole
  442. switch(FieldsToCalculate) {
  443. case E:
  444. if ( lays == 0 && layr == 0) {
  445. ik[2] = KernelManager->AddKernel<TE, 2, INAIR, INAIR>( );
  446. ik[3] = KernelManager->AddKernel<TE, 3, INAIR, INAIR>( );
  447. } else if (lays == 0 && layr > 0) {
  448. ik[2] = KernelManager->AddKernel<TE, 2, INAIR, INGROUND>( );
  449. ik[3] = KernelManager->AddKernel<TE, 3, INAIR, INGROUND>( );
  450. } else if (lays > 0 && layr == 0) {
  451. ik[2] = KernelManager->AddKernel<TE, 2, INGROUND, INAIR>( );
  452. ik[3] = KernelManager->AddKernel<TE, 3, INGROUND, INAIR>( );
  453. } else {
  454. ik[2] = KernelManager->AddKernel<TE, 2, INGROUND, INGROUND>( );
  455. ik[3] = KernelManager->AddKernel<TE, 3, INGROUND, INGROUND>( );
  456. }
  457. break;
  458. case H:
  459. if (lays == 0 && layr == 0) {
  460. ik[5] = KernelManager->AddKernel<TM, 5, INAIR, INAIR>( );
  461. ik[6] = KernelManager->AddKernel<TM, 6, INAIR, INAIR>( );
  462. ik[7] = KernelManager->AddKernel<TE, 7, INAIR, INAIR>( );
  463. ik[8] = KernelManager->AddKernel<TE, 8, INAIR, INAIR>( );
  464. ik[9] = KernelManager->AddKernel<TE, 9, INAIR, INAIR>( );
  465. } else if (lays == 0 && layr > 0) {
  466. ik[5] = KernelManager->AddKernel<TM, 5, INAIR, INGROUND>( );
  467. ik[6] = KernelManager->AddKernel<TM, 6, INAIR, INGROUND>( );
  468. ik[7] = KernelManager->AddKernel<TE, 7, INAIR, INGROUND>( );
  469. ik[8] = KernelManager->AddKernel<TE, 8, INAIR, INGROUND>( );
  470. ik[9] = KernelManager->AddKernel<TE, 9, INAIR, INGROUND>( );
  471. } else if (lays > 0 && layr == 0) {
  472. ik[5] = KernelManager->AddKernel<TM, 5, INGROUND, INAIR>( );
  473. ik[6] = KernelManager->AddKernel<TM, 6, INGROUND, INAIR>( );
  474. ik[7] = KernelManager->AddKernel<TE, 7, INGROUND, INAIR>( );
  475. ik[8] = KernelManager->AddKernel<TE, 8, INGROUND, INAIR>( );
  476. ik[9] = KernelManager->AddKernel<TE, 9, INGROUND, INAIR>( );
  477. } else {
  478. ik[5] = KernelManager->AddKernel<TM, 5, INGROUND, INGROUND>( );
  479. ik[6] = KernelManager->AddKernel<TM, 6, INGROUND, INGROUND>( );
  480. ik[7] = KernelManager->AddKernel<TE, 7, INGROUND, INGROUND>( );
  481. ik[8] = KernelManager->AddKernel<TE, 8, INGROUND, INGROUND>( );
  482. ik[9] = KernelManager->AddKernel<TE, 9, INGROUND, INGROUND>( );
  483. }
  484. break;
  485. case BOTH:
  486. if (lays == 0 && layr == 0) {
  487. ik[5] = KernelManager->AddKernel<TM, 5, INAIR, INAIR>( );
  488. ik[6] = KernelManager->AddKernel<TM, 6, INAIR, INAIR>( );
  489. ik[2] = KernelManager->AddKernel<TE, 2, INAIR, INAIR>( );
  490. ik[3] = KernelManager->AddKernel<TE, 3, INAIR, INAIR>( );
  491. ik[7] = KernelManager->AddKernel<TE, 7, INAIR, INAIR>( );
  492. ik[8] = KernelManager->AddKernel<TE, 8, INAIR, INAIR>( );
  493. ik[9] = KernelManager->AddKernel<TE, 9, INAIR, INAIR>( );
  494. } else if (lays == 0 && layr > 0) {
  495. ik[5] = KernelManager->AddKernel<TM, 5, INAIR, INGROUND>( );
  496. ik[6] = KernelManager->AddKernel<TM, 6, INAIR, INGROUND>( );
  497. ik[2] = KernelManager->AddKernel<TE, 2, INAIR, INGROUND>( );
  498. ik[3] = KernelManager->AddKernel<TE, 3, INAIR, INGROUND>( );
  499. ik[7] = KernelManager->AddKernel<TE, 7, INAIR, INGROUND>( );
  500. ik[8] = KernelManager->AddKernel<TE, 8, INAIR, INGROUND>( );
  501. ik[9] = KernelManager->AddKernel<TE, 9, INAIR, INGROUND>( );
  502. } else if (lays > 0 && layr == 0) {
  503. ik[5] = KernelManager->AddKernel<TM, 5, INGROUND, INAIR>( );
  504. ik[6] = KernelManager->AddKernel<TM, 6, INGROUND, INAIR>( );
  505. ik[2] = KernelManager->AddKernel<TE, 2, INGROUND, INAIR>( );
  506. ik[3] = KernelManager->AddKernel<TE, 3, INGROUND, INAIR>( );
  507. ik[7] = KernelManager->AddKernel<TE, 7, INGROUND, INAIR>( );
  508. ik[8] = KernelManager->AddKernel<TE, 8, INGROUND, INAIR>( );
  509. ik[9] = KernelManager->AddKernel<TE, 9, INGROUND, INAIR>( );
  510. } else {
  511. ik[5] = KernelManager->AddKernel<TM, 5, INGROUND, INGROUND>( );
  512. ik[6] = KernelManager->AddKernel<TM, 6, INGROUND, INGROUND>( );
  513. ik[2] = KernelManager->AddKernel<TE, 2, INGROUND, INGROUND>( );
  514. ik[3] = KernelManager->AddKernel<TE, 3, INGROUND, INGROUND>( );
  515. ik[7] = KernelManager->AddKernel<TE, 7, INGROUND, INGROUND>( );
  516. ik[8] = KernelManager->AddKernel<TE, 8, INGROUND, INGROUND>( );
  517. ik[9] = KernelManager->AddKernel<TE, 9, INGROUND, INGROUND>( );
  518. }
  519. break;
  520. }
  521. }
  522. break;
  523. case (MAGNETICDIPOLE):
  524. if (std::abs(Pol[2]) > 0) { // z dipole
  525. switch (FieldsToCalculate) {
  526. case E:
  527. if (lays == 0 && layr == 0) {
  528. ik[12] = KernelManager->AddKernel<TE, 12, INAIR, INAIR>( );
  529. } else if (lays == 0 && layr > 0) {
  530. ik[12] = KernelManager->AddKernel<TE, 12, INAIR, INGROUND>( );
  531. } else if (lays > 0 && layr == 0) {
  532. ik[12] = KernelManager->AddKernel<TE, 12, INGROUND, INAIR>( );
  533. } else {
  534. ik[12] = KernelManager->AddKernel<TE, 12, INGROUND, INGROUND>( );
  535. }
  536. break;
  537. case H:
  538. if (lays == 0 && layr == 0) {
  539. ik[10] = KernelManager->AddKernel<TE, 10, INAIR, INAIR>( );
  540. ik[11] = KernelManager->AddKernel<TE, 11, INAIR, INAIR>( );
  541. } else if (lays == 0 && layr > 0) {
  542. ik[10] = KernelManager->AddKernel<TE, 10, INAIR, INGROUND>( );
  543. ik[11] = KernelManager->AddKernel<TE, 11, INAIR, INGROUND>( );
  544. } else if (lays > 0 && layr == 0) {
  545. ik[10] = KernelManager->AddKernel<TE, 10, INGROUND, INAIR>( );
  546. ik[11] = KernelManager->AddKernel<TE, 11, INGROUND, INAIR>( );
  547. } else {
  548. ik[10] = KernelManager->AddKernel<TE, 10, INGROUND, INGROUND>( );
  549. ik[11] = KernelManager->AddKernel<TE, 11, INGROUND, INGROUND>( );
  550. }
  551. break;
  552. case BOTH:
  553. if (lays == 0 && layr == 0) {
  554. ik[12] = KernelManager->AddKernel<TE, 12, INAIR, INAIR>( );
  555. ik[10] = KernelManager->AddKernel<TE, 10, INAIR, INAIR>( );
  556. ik[11] = KernelManager->AddKernel<TE, 11, INAIR, INAIR>( );
  557. } else if (lays == 0 && layr > 0) {
  558. ik[12] = KernelManager->AddKernel<TE, 12, INAIR, INGROUND>( );
  559. ik[10] = KernelManager->AddKernel<TE, 10, INAIR, INGROUND>( );
  560. ik[11] = KernelManager->AddKernel<TE, 11, INAIR, INGROUND>( );
  561. } else if (lays > 0 && layr == 0) {
  562. ik[12] = KernelManager->AddKernel<TE, 12, INGROUND, INAIR>( );
  563. ik[10] = KernelManager->AddKernel<TE, 10, INGROUND, INAIR>( );
  564. ik[11] = KernelManager->AddKernel<TE, 11, INGROUND, INAIR>( );
  565. } else {
  566. ik[12] = KernelManager->AddKernel<TE, 12, INGROUND, INGROUND>( );
  567. ik[10] = KernelManager->AddKernel<TE, 10, INGROUND, INGROUND>( );
  568. ik[11] = KernelManager->AddKernel<TE, 11, INGROUND, INGROUND>( );
  569. }
  570. }
  571. }
  572. if (std::abs(Pol[1]) > 0 || std::abs(Pol[0]) > 0) { // x or y grounded HED dipole
  573. switch (FieldsToCalculate) {
  574. case E:
  575. if ( lays == 0 && layr == 0) {
  576. ik[5] = KernelManager->AddKernel<TE, 5, INAIR, INAIR>( );
  577. ik[6] = KernelManager->AddKernel<TE, 6, INAIR, INAIR>( );
  578. ik[7] = KernelManager->AddKernel<TM, 7, INAIR, INAIR>( );
  579. ik[8] = KernelManager->AddKernel<TM, 8, INAIR, INAIR>( );
  580. ik[9] = KernelManager->AddKernel<TM, 9, INAIR, INAIR>( );
  581. } else if (lays == 0 && layr > 0) {
  582. ik[5] = KernelManager->AddKernel<TE, 5, INAIR, INGROUND>( );
  583. ik[6] = KernelManager->AddKernel<TE, 6, INAIR, INGROUND>( );
  584. ik[7] = KernelManager->AddKernel<TM, 7, INAIR, INGROUND>( );
  585. ik[8] = KernelManager->AddKernel<TM, 8, INAIR, INGROUND>( );
  586. ik[9] = KernelManager->AddKernel<TM, 9, INAIR, INGROUND>( );
  587. } else if (lays > 0 && layr == 0) {
  588. ik[5] = KernelManager->AddKernel<TE, 5, INGROUND, INAIR>( );
  589. ik[6] = KernelManager->AddKernel<TE, 6, INGROUND, INAIR>( );
  590. ik[7] = KernelManager->AddKernel<TM, 7, INGROUND, INAIR>( );
  591. ik[8] = KernelManager->AddKernel<TM, 8, INGROUND, INAIR>( );
  592. ik[9] = KernelManager->AddKernel<TM, 9, INGROUND, INAIR>( );
  593. } else {
  594. ik[5] = KernelManager->AddKernel<TE, 5, INGROUND, INGROUND>( );
  595. ik[6] = KernelManager->AddKernel<TE, 6, INGROUND, INGROUND>( );
  596. ik[7] = KernelManager->AddKernel<TM, 7, INGROUND, INGROUND>( );
  597. ik[8] = KernelManager->AddKernel<TM, 8, INGROUND, INGROUND>( );
  598. ik[9] = KernelManager->AddKernel<TM, 9, INGROUND, INGROUND>( );
  599. }
  600. break;
  601. case H:
  602. if ( lays == 0 && layr == 0) {
  603. ik[0] = KernelManager->AddKernel<TE, 0, INAIR, INAIR>( );
  604. ik[1] = KernelManager->AddKernel<TE, 1, INAIR, INAIR>( );
  605. ik[4] = KernelManager->AddKernel<TE, 4, INAIR, INAIR>( );
  606. ik[2] = KernelManager->AddKernel<TM, 2, INAIR, INAIR>( );
  607. ik[3] = KernelManager->AddKernel<TM, 3, INAIR, INAIR>( );
  608. } else if (lays == 0 && layr > 0) {
  609. ik[0] = KernelManager->AddKernel<TE, 0, INAIR, INGROUND>( );
  610. ik[1] = KernelManager->AddKernel<TE, 1, INAIR, INGROUND>( );
  611. ik[4] = KernelManager->AddKernel<TE, 4, INAIR, INGROUND>( );
  612. ik[2] = KernelManager->AddKernel<TM, 2, INAIR, INGROUND>( );
  613. ik[3] = KernelManager->AddKernel<TM, 3, INAIR, INGROUND>( );
  614. } else if (lays > 0 && layr == 0) {
  615. ik[0] = KernelManager->AddKernel<TE, 0, INGROUND, INAIR>( );
  616. ik[1] = KernelManager->AddKernel<TE, 1, INGROUND, INAIR>( );
  617. ik[4] = KernelManager->AddKernel<TE, 4, INGROUND, INAIR>( );
  618. ik[2] = KernelManager->AddKernel<TM, 2, INGROUND, INAIR>( );
  619. ik[3] = KernelManager->AddKernel<TM, 3, INGROUND, INAIR>( );
  620. } else {
  621. ik[0] = KernelManager->AddKernel<TE, 0, INGROUND, INGROUND>( );
  622. ik[1] = KernelManager->AddKernel<TE, 1, INGROUND, INGROUND>( );
  623. ik[4] = KernelManager->AddKernel<TE, 4, INGROUND, INGROUND>( );
  624. ik[2] = KernelManager->AddKernel<TM, 2, INGROUND, INGROUND>( );
  625. ik[3] = KernelManager->AddKernel<TM, 3, INGROUND, INGROUND>( );
  626. }
  627. break;
  628. case BOTH:
  629. if ( lays == 0 && layr == 0) {
  630. ik[5] = KernelManager->AddKernel<TE, 5, INAIR, INAIR>( );
  631. ik[6] = KernelManager->AddKernel<TE, 6, INAIR, INAIR>( );
  632. ik[7] = KernelManager->AddKernel<TM, 7, INAIR, INAIR>( );
  633. ik[8] = KernelManager->AddKernel<TM, 8, INAIR, INAIR>( );
  634. ik[9] = KernelManager->AddKernel<TM, 9, INAIR, INAIR>( );
  635. ik[0] = KernelManager->AddKernel<TE, 0, INAIR, INAIR>( );
  636. ik[1] = KernelManager->AddKernel<TE, 1, INAIR, INAIR>( );
  637. ik[4] = KernelManager->AddKernel<TE, 4, INAIR, INAIR>( );
  638. ik[2] = KernelManager->AddKernel<TM, 2, INAIR, INAIR>( );
  639. ik[3] = KernelManager->AddKernel<TM, 3, INAIR, INAIR>( );
  640. } else if (lays == 0 && layr > 0) {
  641. ik[5] = KernelManager->AddKernel<TE, 5, INAIR, INGROUND>( );
  642. ik[6] = KernelManager->AddKernel<TE, 6, INAIR, INGROUND>( );
  643. ik[7] = KernelManager->AddKernel<TM, 7, INAIR, INGROUND>( );
  644. ik[8] = KernelManager->AddKernel<TM, 8, INAIR, INGROUND>( );
  645. ik[9] = KernelManager->AddKernel<TM, 9, INAIR, INGROUND>( );
  646. ik[0] = KernelManager->AddKernel<TE, 0, INAIR, INGROUND>( );
  647. ik[1] = KernelManager->AddKernel<TE, 1, INAIR, INGROUND>( );
  648. ik[4] = KernelManager->AddKernel<TE, 4, INAIR, INGROUND>( );
  649. ik[2] = KernelManager->AddKernel<TM, 2, INAIR, INGROUND>( );
  650. ik[3] = KernelManager->AddKernel<TM, 3, INAIR, INGROUND>( );
  651. } else {
  652. ik[5] = KernelManager->AddKernel<TE, 5, INGROUND, INGROUND>( );
  653. ik[6] = KernelManager->AddKernel<TE, 6, INGROUND, INGROUND>( );
  654. ik[7] = KernelManager->AddKernel<TM, 7, INGROUND, INGROUND>( );
  655. ik[8] = KernelManager->AddKernel<TM, 8, INGROUND, INGROUND>( );
  656. ik[9] = KernelManager->AddKernel<TM, 9, INGROUND, INGROUND>( );
  657. ik[0] = KernelManager->AddKernel<TE, 0, INGROUND, INGROUND>( );
  658. ik[1] = KernelManager->AddKernel<TE, 1, INGROUND, INGROUND>( );
  659. ik[4] = KernelManager->AddKernel<TE, 4, INGROUND, INGROUND>( );
  660. ik[2] = KernelManager->AddKernel<TM, 2, INGROUND, INGROUND>( );
  661. ik[3] = KernelManager->AddKernel<TM, 3, INGROUND, INGROUND>( );
  662. }
  663. break;
  664. }
  665. }
  666. break;
  667. default:
  668. std::cerr << "Dipole type incorrect, in dipolesource.cpp";
  669. exit(EXIT_FAILURE);
  670. }
  671. }
  672. void DipoleSource::UpdateFields( const int& ifreq, HankelTransform* Hankel, const Real& wavef) {
  673. Vector3r Pol = Phat;
  674. switch (Type) {
  675. case (GROUNDEDELECTRICDIPOLE):
  676. //Hankel->ComputeRelated(rho, KernelManager);
  677. if (std::abs(Pol[2]) > 0) { // z dipole
  678. switch(FieldsToCalculate) {
  679. case E:
  680. f(10) = Hankel->Zgauss(10, TM, 1, rho, wavef, KernelManager->GetRAWKernel(ik[10])) / KernelManager->GetRAWKernel(ik[10])->GetYm();
  681. f(11) = Hankel->Zgauss(11, TM, 0, rho, wavef, KernelManager->GetRAWKernel(ik[11])) / KernelManager->GetRAWKernel(ik[11])->GetYm();
  682. std::cout.precision(12);
  683. this->Receivers->AppendEfield(ifreq, irec,
  684. -Pol[2]*QPI*cp*f(10)*Moment,
  685. -Pol[2]*QPI*sp*f(10)*Moment,
  686. Pol[2]*QPI*f(11)*Moment);
  687. break;
  688. case H:
  689. f(12) = Hankel->Zgauss(12, TM, 1, rho, wavef, KernelManager->GetRAWKernel(ik[12]));
  690. this->Receivers->AppendHfield(ifreq, irec,
  691. -Pol[2]*QPI*sp*f(12)*Moment,
  692. Pol[2]*QPI*cp*f(12)*Moment,
  693. 0. );
  694. break;
  695. case BOTH:
  696. f(10) = Hankel->Zgauss(10, TM, 1, rho, wavef, KernelManager->GetRAWKernel(ik[10])) / KernelManager->GetRAWKernel(ik[10])->GetYm();
  697. f(11) = Hankel->Zgauss(11, TM, 0, rho, wavef, KernelManager->GetRAWKernel(ik[11])) / KernelManager->GetRAWKernel(ik[11])->GetYm();
  698. this->Receivers->AppendEfield(ifreq, irec,
  699. -Pol[2]*QPI*cp*f(10)*Moment,
  700. -Pol[2]*QPI*sp*f(10)*Moment,
  701. Pol[2]*QPI*f(11)*Moment );
  702. f(12) = Hankel->Zgauss(12, TM, 1, rho, wavef, KernelManager->GetRAWKernel(ik[12]));
  703. this->Receivers->AppendHfield(ifreq, irec,
  704. -Pol[2]*QPI*sp*f(12)*Moment,
  705. Pol[2]*QPI*cp*f(12)*Moment,
  706. 0. );
  707. } // Fields to calculate Z polarity Electric dipole
  708. }
  709. if (std::abs(Pol[1]) > 0 || std::abs(Pol[0]) > 0) { // y dipole
  710. switch(FieldsToCalculate) {
  711. case E:
  712. f(2) = Hankel->Zgauss(2, TE, 0, rho, wavef, KernelManager->GetRAWKernel(ik[2])) * KernelManager->GetRAWKernel(ik[2])->GetZs();
  713. f(3) = Hankel->Zgauss(3, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[3])) * KernelManager->GetRAWKernel(ik[3])->GetZs();
  714. f(0) = Hankel->Zgauss(0, TM, 0, rho, wavef, KernelManager->GetRAWKernel(ik[0])) / KernelManager->GetRAWKernel(ik[0])->GetYm();
  715. f(1) = Hankel->Zgauss(1, TM, 1, rho, wavef, KernelManager->GetRAWKernel(ik[1])) / KernelManager->GetRAWKernel(ik[1])->GetYm();
  716. f(4) = Hankel->Zgauss(4, TM, 1, rho, wavef, KernelManager->GetRAWKernel(ik[4])) / KernelManager->GetRAWKernel(ik[4])->GetYm();
  717. if (std::abs(Pol[1]) > 0) {
  718. this->Receivers->AppendEfield(ifreq, irec,
  719. Pol[1]*QPI*scp*((f(0)-(Real)(2.)*f(1)/rho)+(f(2)-(Real)(2.)*f(3)/rho))*Moment,
  720. Pol[1]*QPI*((sps*f(0)+c2p*f(1)/rho)-(cps*f(2)-c2p*f(3)/rho))*Moment,
  721. Pol[1]*QPI*sp*f(4)*Moment);
  722. }
  723. if (std::abs(Pol[0]) > 0) {
  724. this->Receivers->AppendEfield(ifreq, irec,
  725. Pol[0]*Moment*QPI*((cps*f(0)-c2p*f(1)/rho)-(sps*f(2)+c2p*f(3)/rho)),
  726. Pol[0]*Moment*QPI*scp*((f(0)-(Real)(2.)*f(1)/rho)+(f(2)-(Real)(2.)*f(3)/rho)),
  727. Pol[0]*Moment*QPI*cp*f(4) );
  728. }
  729. break;
  730. case H:
  731. f(5) = Hankel->Zgauss(5, TM, 0, rho, wavef, KernelManager->GetRAWKernel(ik[5]));
  732. f(6) = Hankel->Zgauss(6, TM, 1, rho, wavef, KernelManager->GetRAWKernel(ik[6]));
  733. f(7) = Hankel->Zgauss(7, TE, 0, rho, wavef, KernelManager->GetRAWKernel(ik[7]))*KernelManager->GetRAWKernel(ik[7])->GetZs()/KernelManager->GetRAWKernel(ik[7])->GetZm();
  734. f(8) = Hankel->Zgauss(8, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[8]))*KernelManager->GetRAWKernel(ik[8])->GetZs()/KernelManager->GetRAWKernel(ik[8])->GetZm();
  735. f(9) = Hankel->Zgauss(9, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[9]))*KernelManager->GetRAWKernel(ik[9])->GetZs()/KernelManager->GetRAWKernel(ik[9])->GetZm();
  736. if (std::abs(Pol[1]) > 0) {
  737. this->Receivers->AppendHfield(ifreq, irec,
  738. Pol[1]*QPI*(sps*f(5)+c2p*f(6)/rho-cps*f(7)+c2p*f(8)/rho)*Moment,
  739. Pol[1]*QPI*scp*(-f(5)+(Real)(2.)*f(6)/rho-f(7)+(Real)(2.)*f(8)/rho)*Moment,
  740. -Pol[1]*QPI*cp*f(9)*Moment );
  741. }
  742. if (std::abs(Pol[0]) > 0) {
  743. this->Receivers->AppendHfield(ifreq, irec,
  744. Pol[0]*Moment*QPI*scp*(f(5)-(Real)(2.)*f(6)/rho+f(7)-(Real)(2.)*f(8)/rho),
  745. Pol[0]*Moment*QPI*(-cps*f(5)+c2p*f(6)/rho+sps*f(7)+c2p*f(8)/rho),
  746. Pol[0]*Moment*QPI*sp*f(9) );
  747. }
  748. break;
  749. case BOTH:
  750. f(0) = Hankel->Zgauss(0, TM, 0, rho, wavef, KernelManager->GetRAWKernel(ik[0])) / KernelManager->GetRAWKernel(ik[0])->GetYm();
  751. f(1) = Hankel->Zgauss(1, TM, 1, rho, wavef, KernelManager->GetRAWKernel(ik[1])) / KernelManager->GetRAWKernel(ik[1])->GetYm();
  752. f(4) = Hankel->Zgauss(4, TM, 1, rho, wavef, KernelManager->GetRAWKernel(ik[4])) / KernelManager->GetRAWKernel(ik[4])->GetYm();
  753. f(2) = Hankel->Zgauss(2, TE, 0, rho, wavef, KernelManager->GetRAWKernel(ik[2])) * KernelManager->GetRAWKernel(ik[2])->GetZs();
  754. f(3) = Hankel->Zgauss(3, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[3])) * KernelManager->GetRAWKernel(ik[3])->GetZs();
  755. f(5) = Hankel->Zgauss(5, TM, 0, rho, wavef, KernelManager->GetRAWKernel(ik[5]));
  756. f(6) = Hankel->Zgauss(6, TM, 1, rho, wavef, KernelManager->GetRAWKernel(ik[6]));
  757. f(7) = Hankel->Zgauss(7, TE, 0, rho, wavef, KernelManager->GetRAWKernel(ik[7]))*KernelManager->GetRAWKernel(ik[7])->GetZs()/KernelManager->GetRAWKernel(ik[7])->GetZm();
  758. f(8) = Hankel->Zgauss(8, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[8]))*KernelManager->GetRAWKernel(ik[8])->GetZs()/KernelManager->GetRAWKernel(ik[8])->GetZm();
  759. f(9) = Hankel->Zgauss(9, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[9]))*KernelManager->GetRAWKernel(ik[9])->GetZs()/KernelManager->GetRAWKernel(ik[9])->GetZm();
  760. if (std::abs(Pol[1]) > 0) {
  761. this->Receivers->AppendEfield(ifreq, irec,
  762. Pol[1]*QPI*scp*((f(0)-(Real)(2.)*f(1)/rho)+(f(2)-(Real)(2.)*f(3)/rho))*Moment ,
  763. Pol[1]*QPI*((sps*f(0)+c2p*f(1)/rho)-(cps*f(2)-c2p*f(3)/rho))*Moment,
  764. Pol[1]*QPI*sp*f(4)*Moment);
  765. this->Receivers->AppendHfield(ifreq, irec,
  766. Pol[1]*QPI*(sps*f(5)+c2p*f(6)/rho-cps*f(7)+c2p*f(8)/rho)*Moment,
  767. Pol[1]*QPI*scp*(-f(5)+(Real)(2.)*f(6)/rho-f(7)+(Real)(2.)*f(8)/rho)*Moment,
  768. -Pol[1]*QPI*cp*f(9)*Moment );
  769. }
  770. if (std::abs(Pol[0]) > 0) {
  771. this->Receivers->AppendEfield(ifreq, irec,
  772. Pol[0]*Moment*QPI*((cps*f(0)-c2p*f(1)/rho)-(sps*f(2)+c2p*f(3)/rho)),
  773. Pol[0]*Moment*QPI*scp*((f(0)-(Real)(2.)*f(1)/rho)+(f(2)-(Real)(2.)*f(3)/rho)),
  774. Pol[0]*Moment*QPI*cp*f(4) );
  775. this->Receivers->AppendHfield(ifreq, irec,
  776. Pol[0]*Moment*QPI*scp*(f(5)-(Real)(2.)*f(6)/rho+f(7)-(Real)(2.)*f(8)/rho),
  777. Pol[0]*Moment*QPI*(-cps*f(5)+c2p*f(6)/rho+sps*f(7)+c2p*f(8)/rho),
  778. Pol[0]*Moment*QPI*sp*f(9) );
  779. }
  780. break;
  781. }
  782. }
  783. break; // GROUNDEDELECTRICDIPOLE
  784. case UNGROUNDEDELECTRICDIPOLE:
  785. if (std::abs(Pol[2]) > 0) { // z dipole
  786. switch(FieldsToCalculate) {
  787. case E:
  788. f(10) = 0;
  789. f(11) = Hankel->Zgauss(11, TM, 0, rho, wavef, KernelManager->GetRAWKernel(ik[11])) / KernelManager->GetRAWKernel(ik[11])->GetYm();
  790. this->Receivers->AppendEfield(ifreq, irec,
  791. -Pol[2]*QPI*cp*f(10)*Moment,
  792. -Pol[2]*QPI*sp*f(10)*Moment,
  793. Pol[2]*QPI*f(11)*Moment);
  794. break;
  795. case H:
  796. f(12) = Hankel->Zgauss(12, TM, 1, rho, wavef, KernelManager->GetRAWKernel(ik[12]));
  797. this->Receivers->AppendHfield(ifreq, irec,
  798. -Pol[2]*QPI*sp*f(12)*Moment,
  799. Pol[2]*QPI*cp*f(12)*Moment,
  800. 0. );
  801. break;
  802. case BOTH:
  803. f(10) = 0;
  804. f(11) = Hankel->Zgauss(11, TM, 0, rho, wavef, KernelManager->GetRAWKernel(ik[11])) / KernelManager->GetRAWKernel(ik[11])->GetYm();
  805. this->Receivers->AppendEfield(ifreq, irec,
  806. -Pol[2]*QPI*cp*f(10)*Moment,
  807. -Pol[2]*QPI*sp*f(10)*Moment,
  808. Pol[2]*QPI*f(11)*Moment );
  809. f(12) = Hankel->Zgauss(12, TM, 1, rho, wavef, KernelManager->GetRAWKernel(ik[12]));
  810. this->Receivers->AppendHfield(ifreq, irec,
  811. -Pol[2]*QPI*sp*f(12)*Moment,
  812. Pol[2]*QPI*cp*f(12)*Moment,
  813. 0. );
  814. } // Fields to calculate Z polarity Electric dipole
  815. }
  816. if (std::abs(Pol[1]) > 0 || std::abs(Pol[0]) > 0) { // x or y dipole
  817. switch(FieldsToCalculate) {
  818. case E:
  819. f(0) = 0;
  820. f(1) = 0;
  821. f(2) = Hankel->Zgauss(2, TE, 0, rho, wavef, KernelManager->GetRAWKernel(ik[2])) * KernelManager->GetRAWKernel(ik[2])->GetZs();
  822. f(3) = Hankel->Zgauss(3, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[3])) * KernelManager->GetRAWKernel(ik[3])->GetZs();
  823. f(4) = 0;
  824. if (std::abs(Pol[1]) > 0) {
  825. this->Receivers->AppendEfield(ifreq, irec,
  826. Pol[1]*QPI*scp*((f(0)-(Real)(2.)*f(1)/rho)+(f(2)-(Real)(2.)*f(3)/rho))*Moment,
  827. Pol[1]*QPI*((sps*f(0)+c2p*f(1)/rho)-(cps*f(2)-c2p*f(3)/rho))*Moment,
  828. Pol[1]*QPI*sp*f(4)*Moment);
  829. }
  830. if (std::abs(Pol[0]) > 0) {
  831. this->Receivers->AppendEfield(ifreq, irec,
  832. Pol[0]*Moment*QPI*((cps*f(0)-c2p*f(1)/rho)-(sps*f(2)+c2p*f(3)/rho)),
  833. Pol[0]*Moment*QPI*scp*((f(0)-(Real)(2.)*f(1)/rho)+(f(2)-(Real)(2.)*f(3)/rho)),
  834. Pol[0]*Moment*QPI*cp*f(4) );
  835. }
  836. break;
  837. case H:
  838. f(5) = Hankel->Zgauss(5, TM, 0, rho, wavef, KernelManager->GetRAWKernel(ik[5]));
  839. f(6) = Hankel->Zgauss(6, TM, 1, rho, wavef, KernelManager->GetRAWKernel(ik[6]));
  840. f(7) = Hankel->Zgauss(7, TE, 0, rho, wavef, KernelManager->GetRAWKernel(ik[7]))*KernelManager->GetRAWKernel(ik[7])->GetZs()/KernelManager->GetRAWKernel(ik[7])->GetZm();
  841. f(8) = Hankel->Zgauss(8, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[8]))*KernelManager->GetRAWKernel(ik[8])->GetZs()/KernelManager->GetRAWKernel(ik[8])->GetZm();
  842. f(9) = Hankel->Zgauss(9, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[9]))*KernelManager->GetRAWKernel(ik[9])->GetZs()/KernelManager->GetRAWKernel(ik[9])->GetZm();
  843. if (std::abs(Pol[1]) > 0) {
  844. this->Receivers->AppendHfield(ifreq, irec,
  845. Pol[1]*QPI*(sps*f(5)+c2p*f(6)/rho-cps*f(7)+c2p*f(8)/rho)*Moment,
  846. Pol[1]*QPI*scp*(-f(5)+(Real)(2.)*f(6)/rho-f(7)+(Real)(2.)*f(8)/rho)*Moment,
  847. -Pol[1]*QPI*cp*f(9)*Moment );
  848. // Analytic whole space solution could go here
  849. }
  850. if (std::abs(Pol[0]) > 0) {
  851. this->Receivers->AppendHfield(ifreq, irec,
  852. Pol[0]*Moment*QPI*scp*(f(5)-(Real)(2.)*f(6)/rho+f(7)-(Real)(2.)*f(8)/rho),
  853. Pol[0]*Moment*QPI*(-cps*f(5)+c2p*f(6)/rho+sps*f(7)+c2p*f(8)/rho),
  854. Pol[0]*Moment*QPI*sp*f(9) );
  855. // Analytic whole space solution
  856. }
  857. break;
  858. case BOTH:
  859. f(0) = 0;
  860. f(1) = 0;
  861. f(4) = 0;
  862. f(2) = Hankel->Zgauss(2, TE, 0, rho, wavef, KernelManager->GetRAWKernel(ik[2])) * KernelManager->GetRAWKernel(0)->GetZs();
  863. f(3) = Hankel->Zgauss(3, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[3])) * KernelManager->GetRAWKernel(1)->GetZs();
  864. f(5) = Hankel->Zgauss(5, TM, 0, rho, wavef, KernelManager->GetRAWKernel(ik[5]));
  865. f(6) = Hankel->Zgauss(6, TM, 1, rho, wavef, KernelManager->GetRAWKernel(ik[6]));
  866. f(7) = Hankel->Zgauss(7, TE, 0, rho, wavef, KernelManager->GetRAWKernel(ik[7]))*KernelManager->GetRAWKernel(ik[7])->GetZs()/KernelManager->GetRAWKernel(ik[7])->GetZm();
  867. f(8) = Hankel->Zgauss(8, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[8]))*KernelManager->GetRAWKernel(ik[8])->GetZs()/KernelManager->GetRAWKernel(ik[8])->GetZm();
  868. f(9) = Hankel->Zgauss(9, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[9]))*KernelManager->GetRAWKernel(ik[9])->GetZs()/KernelManager->GetRAWKernel(ik[9])->GetZm();
  869. if (std::abs(Pol[1]) > 0) {
  870. this->Receivers->AppendEfield(ifreq, irec,
  871. Pol[1]*QPI*scp*((f(0)-(Real)(2.)*f(1)/rho)+(f(2)-(Real)(2.)*f(3)/rho))*Moment ,
  872. Pol[1]*QPI*((sps*f(0)+c2p*f(1)/rho)-(cps*f(2)-c2p*f(3)/rho))*Moment,
  873. Pol[1]*QPI*sp*f(4)*Moment);
  874. this->Receivers->AppendHfield(ifreq, irec,
  875. Pol[1]*QPI*(sps*f(5)+c2p*f(6)/rho-cps*f(7)+c2p*f(8)/rho)*Moment,
  876. Pol[1]*QPI*scp*(-f(5)+(Real)(2.)*f(6)/rho-f(7)+(Real)(2.)*f(8)/rho)*Moment,
  877. -Pol[1]*QPI*cp*f(9)*Moment );
  878. }
  879. if (std::abs(Pol[0]) > 0) {
  880. this->Receivers->AppendEfield(ifreq, irec,
  881. Pol[0]*Moment*QPI*((cps*f(0)-c2p*f(1)/rho)-(sps*f(2)+c2p*f(3)/rho)),
  882. Pol[0]*Moment*QPI*scp*((f(0)-(Real)(2.)*f(1)/rho)+(f(2)-(Real)(2.)*f(3)/rho)),
  883. Pol[0]*Moment*QPI*cp*f(4) );
  884. this->Receivers->AppendHfield(ifreq, irec,
  885. Pol[0]*Moment*QPI*scp*(f(5)-(Real)(2.)*f(6)/rho+f(7)-(Real)(2.)*f(8)/rho),
  886. Pol[0]*Moment*QPI*(-cps*f(5)+c2p*f(6)/rho+sps*f(7)+c2p*f(8)/rho),
  887. Pol[0]*Moment*QPI*sp*f(9) );
  888. }
  889. break;
  890. }
  891. }
  892. break; // UNGROUNDEDELECTRICDIPOLE
  893. case MAGNETICDIPOLE:
  894. //Hankel->ComputeRelated(rho, KernelManager);
  895. if (std::abs(Pol[2]) > 0) { // z dipole
  896. switch(FieldsToCalculate) {
  897. case E:
  898. f(12)=Hankel->Zgauss(12, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[12]))*KernelManager->GetRAWKernel(ik[12])->GetZs();
  899. this->Receivers->AppendEfield(ifreq, irec,
  900. Pol[2]*Moment*QPI*sp*f(12),
  901. -Pol[2]*Moment*QPI*cp*f(12),
  902. 0);
  903. break;
  904. case H:
  905. f(10)=Hankel->Zgauss(10, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[10]))*KernelManager->GetRAWKernel(ik[10])->GetZs()/KernelManager->GetRAWKernel(ik[10])->GetZm();
  906. f(11)=Hankel->Zgauss(11, TE, 0, rho, wavef, KernelManager->GetRAWKernel(ik[11]))*KernelManager->GetRAWKernel(ik[11])->GetZs()/KernelManager->GetRAWKernel(ik[11])->GetZm();
  907. this->Receivers->AppendHfield(ifreq, irec,
  908. -Pol[2]*Moment*QPI*cp*f(10),
  909. -Pol[2]*Moment*QPI*sp*f(10),
  910. Pol[2]*Moment*QPI*f(11) );
  911. break;
  912. case BOTH:
  913. f(12)=Hankel->Zgauss(12, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[12]))*KernelManager->GetRAWKernel(ik[12])->GetZs();
  914. f(10)=Hankel->Zgauss(10, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[10]))*KernelManager->GetRAWKernel(ik[10])->GetZs()/KernelManager->GetRAWKernel(ik[10])->GetZm();
  915. f(11)=Hankel->Zgauss(11, TE, 0, rho, wavef, KernelManager->GetRAWKernel(ik[11]))*KernelManager->GetRAWKernel(ik[11])->GetZs()/KernelManager->GetRAWKernel(ik[11])->GetZm();
  916. this->Receivers->AppendEfield(ifreq, irec,
  917. Pol[2]*Moment*QPI*sp*f(12),
  918. -Pol[2]*Moment*QPI*cp*f(12),
  919. 0);
  920. this->Receivers->AppendHfield(ifreq, irec,
  921. -Pol[2]*Moment*QPI*cp*f(10),
  922. -Pol[2]*Moment*QPI*sp*f(10),
  923. Pol[2]*Moment*QPI*f(11) );
  924. break;
  925. }
  926. }
  927. if (std::abs(Pol[1]) > 0 || std::abs(Pol[0]) > 0) { // x or y grounded HED dipole
  928. switch (FieldsToCalculate) {
  929. case E:
  930. f(5) = Hankel->Zgauss(5, TE, 0, rho, wavef, KernelManager->GetRAWKernel(ik[5]))*KernelManager->GetRAWKernel(ik[5])->GetZs();
  931. f(6) = Hankel->Zgauss(6, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[6]))*KernelManager->GetRAWKernel(ik[6])->GetZs();
  932. f(7) = Hankel->Zgauss(7, TM, 0, rho, wavef, KernelManager->GetRAWKernel(ik[7]))*KernelManager->GetRAWKernel(ik[7])->GetKs()/KernelManager->GetRAWKernel(ik[7])->GetYm();
  933. f(8) = Hankel->Zgauss(8, TM, 1, rho, wavef, KernelManager->GetRAWKernel(ik[8]))*KernelManager->GetRAWKernel(ik[8])->GetKs()/KernelManager->GetRAWKernel(ik[8])->GetYm();
  934. f(9) = Hankel->Zgauss(9, TM, 1, rho, wavef, KernelManager->GetRAWKernel(ik[9]))*KernelManager->GetRAWKernel(ik[9])->GetKs()/KernelManager->GetRAWKernel(ik[9])->GetYm();
  935. if (std::abs(Pol[0]) > 0) {
  936. this->Receivers->AppendEfield(ifreq, irec,
  937. Pol[0]*Moment*QPI*scp*((-f(5)+(Real)(2.)*f(6)/rho)+(f(7)-(Real)(2.)*f(8)/rho)),
  938. Pol[0]*Moment*QPI*((cps*f(5)-c2p*f(6)/rho)+(sps*f(7)+c2p*f(8)/rho)),
  939. Pol[0]*Moment*QPI*sp*f(9));
  940. }
  941. if (std::abs(Pol[1]) > 0) {
  942. this->Receivers->AppendEfield(ifreq, irec,
  943. Pol[1]*Moment*QPI*(-(sps*f(5)+c2p*f(6)/rho)-(cps*f(7)-c2p*f(8)/rho)),
  944. Pol[1]*Moment*QPI*scp*((f(5)-(Real)(2.)*f(6)/rho)-(f(7)-(Real)(2.)*f(8)/rho)),
  945. -Pol[1]*Moment*QPI*cp*f(9) );
  946. }
  947. break;
  948. case H:
  949. f(0) = Hankel->Zgauss(0, TE, 0, rho, wavef, KernelManager->GetRAWKernel(ik[0]))*KernelManager->GetRAWKernel(ik[0])->GetZs()/KernelManager->GetRAWKernel(ik[0])->GetZm();
  950. f(1) = Hankel->Zgauss(1, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[1]))*KernelManager->GetRAWKernel(ik[1])->GetZs()/KernelManager->GetRAWKernel(ik[1])->GetZm();
  951. f(4) = Hankel->Zgauss(4, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[4]))*KernelManager->GetRAWKernel(ik[4])->GetZs()/KernelManager->GetRAWKernel(ik[4])->GetZm();
  952. f(2) = Hankel->Zgauss(2, TM, 0, rho, wavef, KernelManager->GetRAWKernel(ik[2]))*KernelManager->GetRAWKernel(ik[2])->GetKs();
  953. f(3) = Hankel->Zgauss(3, TM, 1, rho, wavef, KernelManager->GetRAWKernel(ik[3]))*KernelManager->GetRAWKernel(ik[3])->GetKs();
  954. if (std::abs(Pol[0]) > 0) {
  955. this->Receivers->AppendHfield(ifreq, irec,
  956. Pol[0]*Moment*QPI*(cps*f(0)-c2p*f(1)/rho+(sps*f(2)+c2p*f(3)/rho)),
  957. Pol[0]*Moment*QPI*scp*(f(0)-(Real)(2.)*f(1)/rho-(f(2)-(Real)(2.)*f(3)/rho)),
  958. Pol[0]*Moment*QPI*cp*f(4) );
  959. }
  960. if (std::abs(Pol[1]) > 0) {
  961. this->Receivers->AppendHfield(ifreq, irec,
  962. Pol[1]*Moment*QPI*scp*(f(0)-(Real)(2.)*f(1)/rho-(f(2)-(Real)(2.)*f(3)/rho)),
  963. Pol[1]*Moment*QPI*(sps*f(0)+c2p*f(1)/rho+(cps*f(2)-c2p*f(3)/rho)),
  964. Pol[1]*Moment*QPI*sp*f(4));
  965. }
  966. break;
  967. case BOTH:
  968. f(5) = Hankel->Zgauss(5, TE, 0, rho, wavef, KernelManager->GetRAWKernel(ik[5]))*KernelManager->GetRAWKernel(ik[5])->GetZs();
  969. f(6) = Hankel->Zgauss(6, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[6]))*KernelManager->GetRAWKernel(ik[6])->GetZs();
  970. f(7) = Hankel->Zgauss(7, TM, 0, rho, wavef, KernelManager->GetRAWKernel(ik[7]))*KernelManager->GetRAWKernel(ik[7])->GetKs()/KernelManager->GetRAWKernel(ik[7])->GetYm();
  971. f(8) = Hankel->Zgauss(8, TM, 1, rho, wavef, KernelManager->GetRAWKernel(ik[8]))*KernelManager->GetRAWKernel(ik[8])->GetKs()/KernelManager->GetRAWKernel(ik[8])->GetYm();
  972. f(9) = Hankel->Zgauss(9, TM, 1, rho, wavef, KernelManager->GetRAWKernel(ik[9]))*KernelManager->GetRAWKernel(ik[9])->GetKs()/KernelManager->GetRAWKernel(ik[9])->GetYm();
  973. f(0) = Hankel->Zgauss(0, TE, 0, rho, wavef, KernelManager->GetRAWKernel(ik[0]))*KernelManager->GetRAWKernel(ik[0])->GetZs()/KernelManager->GetRAWKernel(ik[0])->GetZm();
  974. f(1) = Hankel->Zgauss(1, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[1]))*KernelManager->GetRAWKernel(ik[1])->GetZs()/KernelManager->GetRAWKernel(ik[1])->GetZm();
  975. f(4) = Hankel->Zgauss(4, TE, 1, rho, wavef, KernelManager->GetRAWKernel(ik[4]))*KernelManager->GetRAWKernel(ik[4])->GetZs()/KernelManager->GetRAWKernel(ik[4])->GetZm();
  976. f(2) = Hankel->Zgauss(2, TM, 0, rho, wavef, KernelManager->GetRAWKernel(ik[2]))*KernelManager->GetRAWKernel(ik[2])->GetKs();
  977. f(3) = Hankel->Zgauss(3, TM, 1, rho, wavef, KernelManager->GetRAWKernel(ik[3]))*KernelManager->GetRAWKernel(ik[3])->GetKs();
  978. if (std::abs(Pol[0]) > 0) {
  979. this->Receivers->AppendEfield(ifreq, irec,
  980. Pol[0]*Moment*QPI*scp*((-f(5)+(Real)(2.)*f(6)/rho)+(f(7)-(Real)(2.)*f(8)/rho)),
  981. Pol[0]*Moment*QPI*((cps*f(5)-c2p*f(6)/rho)+(sps*f(7)+c2p*f(8)/rho)),
  982. Pol[0]*Moment*QPI*sp*f(9));
  983. this->Receivers->AppendHfield(ifreq, irec,
  984. Pol[0]*Moment*QPI*(cps*f(0)-c2p*f(1)/rho+(sps*f(2)+c2p*f(3)/rho)),
  985. Pol[0]*Moment*QPI*scp*(f(0)-(Real)(2.)*f(1)/rho-(f(2)-(Real)(2.)*f(3)/rho)),
  986. Pol[0]*Moment*QPI*cp*f(4) );
  987. }
  988. if (std::abs(Pol[1]) > 0) {
  989. this->Receivers->AppendEfield(ifreq, irec,
  990. Pol[1]*Moment*QPI*(-(sps*f(5)+c2p*f(6)/rho)-(cps*f(7)-c2p*f(8)/rho)),
  991. Pol[1]*Moment*QPI*scp*((f(5)-(Real)(2.)*f(6)/rho)-(f(7)-(Real)(2.)*f(8)/rho)),
  992. -Pol[1]*Moment*QPI*cp*f(9) );
  993. this->Receivers->AppendHfield(ifreq, irec,
  994. Pol[1]*Moment*QPI*scp*(f(0)-(Real)(2.)*f(1)/rho-(f(2)-(Real)(2.)*f(3)/rho)),
  995. Pol[1]*Moment*QPI*(sps*f(0)+c2p*f(1)/rho+(cps*f(2)-c2p*f(3)/rho)),
  996. Pol[1]*Moment*QPI*sp*f(4));
  997. }
  998. break;
  999. }
  1000. }
  1001. break;
  1002. case NOSOURCETYPE:
  1003. throw NonValidDipoleType(this);
  1004. } // Source Type Switch
  1005. }
  1006. // ==================== INQUIRY ======================
  1007. std::shared_ptr<KernelEM1DManager> DipoleSource::GetKernelManager() {
  1008. return KernelManager;
  1009. }
  1010. Vector3r DipoleSource::GetLocation() {
  1011. return this->Location;
  1012. }
  1013. #ifdef LEMMAUSEVTK
  1014. vtkActor* DipoleSource::GetVtkActor() {
  1015. vtkActor* vActor;
  1016. vtkLineSource* vLineSource;
  1017. vtkTubeFilter* vTube;
  1018. vtkPolyDataMapper* vMapper;
  1019. vtkRegularPolygonSource* vCircleSource;
  1020. vLineSource = vtkLineSource::New();
  1021. vTube = vtkTubeFilter::New();
  1022. vMapper = vtkPolyDataMapper::New();
  1023. vCircleSource = vtkRegularPolygonSource::New();
  1024. VectorXr M0 = Location - .5*Moment*Phat;
  1025. VectorXr M1 = Location + .5*Moment*Phat;
  1026. vActor = vtkActor::New();
  1027. switch (Type) {
  1028. case GROUNDEDELECTRICDIPOLE:
  1029. vLineSource->SetPoint1( M0(0), M0(1), M0(2));
  1030. vLineSource->SetPoint2( M1(0), M1(1), M1(2));
  1031. vTube->SetInputConnection(vLineSource->GetOutputPort());
  1032. vTube->SetRadius(.1 * std::abs(Moment));
  1033. vTube->SetNumberOfSides(6);
  1034. vTube->SetCapping(1);
  1035. vMapper->SetInputConnection(vTube->GetOutputPort());
  1036. vActor->SetMapper(vMapper);
  1037. vActor->GetProperty()->SetColor(Phat[0], Phat[1], Phat[2]);
  1038. break;
  1039. case UNGROUNDEDELECTRICDIPOLE:
  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. vActor->GetProperty()->SetColor(rand()/(Real)(RAND_MAX), rand()/(Real)(RAND_MAX), rand()/(Real)(RAND_MAX));
  1050. vActor->GetProperty()->SetOpacity(1.);
  1051. break;
  1052. case MAGNETICDIPOLE:
  1053. vCircleSource->SetCenter(Location(0), Location(1),
  1054. Location(2));
  1055. vCircleSource->SetNumberOfSides(360);
  1056. vCircleSource->SetNormal(Phat[0], Phat[1], Phat[2]);
  1057. vCircleSource->SetRadius(0.2); // .2 m radius
  1058. vCircleSource->SetGeneratePolygon(false);
  1059. vCircleSource->SetGeneratePolyline(true);
  1060. vCircleSource->Update();
  1061. vTube->SetInputConnection(vCircleSource->GetOutputPort());
  1062. //vTube->SetRadius( max((float)(*xCoords->GetTuple(nx)),
  1063. // (float)(*yCoords->GetTuple(ny))) / 100);
  1064. vTube->SetRadius(.1*std::abs(Moment));
  1065. vTube->SetNumberOfSides(6);
  1066. vTube->SetCapping(1);
  1067. vMapper->SetInputConnection(vTube->GetOutputPort());
  1068. vActor->SetMapper(vMapper);
  1069. vActor->GetProperty()->SetColor(.9,.2,.9);
  1070. break;
  1071. default:
  1072. throw NonValidDipoleType();
  1073. }
  1074. vLineSource->Delete();
  1075. vCircleSource->Delete();
  1076. vTube->Delete();
  1077. vMapper->Delete();
  1078. return vActor;
  1079. }
  1080. #endif
  1081. Real DipoleSource::GetLocation(const int& coordinate) {
  1082. switch (coordinate) {
  1083. case (0):
  1084. return this->Location.x();
  1085. break;
  1086. case (1):
  1087. return this->Location.y();
  1088. break;
  1089. case (2):
  1090. return this->Location.z();
  1091. break;
  1092. default:
  1093. throw NonValidLocationCoordinate( );
  1094. }
  1095. }
  1096. DIPOLESOURCETYPE DipoleSource::GetDipoleSourceType() {
  1097. return this->Type;
  1098. }
  1099. //DipoleSourcePolarisation DipoleSource::GetDipoleSourcePolarisation() {
  1100. // return this->Polarisation;
  1101. //}
  1102. Real DipoleSource::GetAngularFrequency(const int& ifreq) {
  1103. return 2.*PI*this->Freqs(ifreq);
  1104. }
  1105. Real DipoleSource::GetFrequency(const int& ifreq) {
  1106. return this->Freqs(ifreq);
  1107. }
  1108. VectorXr DipoleSource::GetFrequencies( ) {
  1109. return this->Freqs;
  1110. }
  1111. Real DipoleSource::GetPhase() {
  1112. return this->Phase;
  1113. }
  1114. Real DipoleSource::GetMoment() {
  1115. return this->Moment;
  1116. }
  1117. int DipoleSource::GetNumberOfFrequencies() {
  1118. return (int)(this->Freqs.size());
  1119. }
  1120. void DipoleSource::SetNumberOfFrequencies(const int &nfreq){
  1121. Freqs.resize(nfreq);
  1122. Freqs.setZero();
  1123. }
  1124. void DipoleSource::SetFrequency(const int &ifreq, const Real &freq){
  1125. Freqs(ifreq) = freq;
  1126. }
  1127. void DipoleSource::SetFrequencies(const VectorXr &freqs){
  1128. Freqs = freqs;
  1129. }
  1130. /////////////////////////////////////////////////////////////////
  1131. /////////////////////////////////////////////////////////////////
  1132. // Error classes
  1133. NullDipoleSource::NullDipoleSource() :
  1134. runtime_error( "NULL VALUED DIPOLE SOURCE") {}
  1135. NonValidDipoleTypeAssignment::NonValidDipoleTypeAssignment( ) :
  1136. runtime_error( "NON VALID DIPOLE TYPE ASSIGNMENT") { }
  1137. NonValidDipoleType::NonValidDipoleType( LemmaObject* ptr ) :
  1138. runtime_error( "NON VALID DIPOLE TYPE") {
  1139. std::cout << "Thrown by instance of "
  1140. << ptr->GetName() << std::endl;
  1141. }
  1142. NonValidDipoleType::NonValidDipoleType( ) :
  1143. runtime_error( "NON VALID DIPOLE TYPE") { }
  1144. NonValidDipolePolarity::NonValidDipolePolarity () :
  1145. runtime_error( "NON VALID DIPOLE POLARITY") { }
  1146. NonValidDipolePolarisation::NonValidDipolePolarisation( ) :
  1147. runtime_error( "NON VALID DIPOLE TYPE") { }
  1148. NonValidDipolePolarisationAssignment::
  1149. NonValidDipolePolarisationAssignment( ) :
  1150. runtime_error( "NON VALID DIPOLE POLARISATION ASSIGNMENT") { }
  1151. NonValidLocationCoordinate::NonValidLocationCoordinate( ) :
  1152. runtime_error( "NON VALID LOCATION COORDINATE REQUESTED") { }
  1153. }