Main Lemma Repository
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

dipolesource.cpp 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. // ===========================================================================
  2. //
  3. // Filename: utdipolesource.cpp
  4. //
  5. // Description:
  6. //
  7. // Version: 0.0
  8. // Created: 12/02/2009 11:57:14 AM
  9. // Revision: none
  10. // Compiler: g++ (c++)
  11. //
  12. // Author: Trevor Irons (ti)
  13. //
  14. // Organisation: Colorado School of Mines (CSM)
  15. // United States Geological Survey (USGS)
  16. //
  17. // Email: tirons@mines.edu, tirons@usgs.gov
  18. //
  19. // This program is free software: you can redistribute it and/or modify
  20. // it under the terms of the GNU General Public License as published by
  21. // the Free Software Foundation, either version 3 of the License, or
  22. // (at your option) any later version.
  23. //
  24. // This program is distributed in the hope that it will be useful,
  25. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. // GNU General Public License for more details.
  28. //
  29. // You should have received a copy of the GNU General Public License
  30. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  31. //
  32. // ===========================================================================
  33. #include <iostream>
  34. #include <fstream>
  35. #include "dipolesource.h"
  36. #include "layeredearthem.h"
  37. #include "receiverpoints.h"
  38. #include "emearth1d.h"
  39. #ifdef LEMMAUSEOMP
  40. #include "omp.h"
  41. #endif
  42. // For testing purposes disable VTK and run scale.sh
  43. #undef LEMMAUSEVTK
  44. #undef KIHALEE_EM1D
  45. #ifdef LEMMAUSEVTK
  46. #include "vtkRenderer.h"
  47. #include "vtkRenderWindow.h"
  48. #include "vtkRenderWindowInteractor.h"
  49. #include "vtkDoubleArray.h"
  50. #include "vtkXYPlotActor.h"
  51. #include "vtkXYPlotWidget.h"
  52. #include "vtkProperty2D.h"
  53. #endif
  54. #include "timer.h"
  55. using namespace Lemma;
  56. int main() {
  57. //////////////////
  58. // TODO List of Dipole settings that aren't working
  59. // Do calculation
  60. jsw_timer timer;
  61. timer.begin();
  62. // Test with a single dipole
  63. DipoleSource *dipole = DipoleSource::New();
  64. //dipole->SetMoment(2);
  65. ///////////////////////////////////
  66. // E field Tests
  67. // Sems to be working!
  68. //dipole->SetType(GROUNDEDELECTRICDIPOLE);
  69. //dipole->SetPolarisation(XPOLARISATION);
  70. //dipole->SetPolarisation(YPOLARISATION);
  71. //dipole->SetPolarisation(ZPOLARISATION);
  72. //dipole->SetAzimuth(0); // X - Northing
  73. //dipole->SetAzimuth(90); // Y - Easting
  74. dipole->SetType(GROUNDEDELECTRICDIPOLE);
  75. //dipole->SetPolarisation(1., 0.0, 1.0);
  76. // dipole->SetPolarisation(XPOLARISATION);
  77. dipole->SetPolarisation(YPOLARISATION);
  78. //dipole->SetPolarisation(ZPOLARISATION);
  79. /////////////
  80. //dipole->SetType(MAGNETICDIPOLE);
  81. //dipole->SetPolarisation(0., 0.0, 1.0);
  82. //dipole->SetPolarisation(XPOLARISATION);
  83. //dipole->SetPolarisation(YPOLARISATION);
  84. //dipole->SetPolarisation(ZPOLARISATION);
  85. //dipole->SetMoment(1);
  86. //dipole->SetLocation(1,1,-.0100328);
  87. dipole->SetLocation(0., 0., -0.001);
  88. //dipole->SetLocation(-2.5,1.25,0);
  89. dipole->SetNumberOfFrequencies(1);
  90. dipole->SetFrequency(0, 2e7);
  91. //dipole->SetFrequency(1,2000);
  92. //dipole->SetPhase(0);
  93. //////////////////////////////////
  94. // H field Tests
  95. // // Define model, this is a difficult case
  96. // VectorXcr sigma(23);
  97. // sigma << 0., 0.0625, 0.0166666666666667, 0.04, 0.0181818181818182,
  98. // 0.05, 0.0222222222222222, 0.2, 0.025, 0.05, 0.025,
  99. // 0.05, 0.00833333333333333, 0.025, 0.05, 0.0222222222222222,
  100. // 0.0277777777777778, 0.0333333333333333, 0.0208333333333333,
  101. // 0.0181818181818182, 0.025, 0.04;
  102. //
  103. // VectorXr thick(21);
  104. // //thick << 10, 10, 10, 10, 10, 10;
  105. // thick << 11, 5, 5, 4, 3.5, 4.5, 4.5,
  106. // 5.5, 3, 36, 15, 3, 6, 3, 8,
  107. // 9, 10, 7, 8, 11, 68;
  108. //VectorXcr sigma(8);
  109. // sigma << 0., Complex(.01,0.01), 0.001, .005, .0034, .0023, .0024, .0001;
  110. VectorXcr sigma(8);
  111. sigma << 0., 3e-4, 5e-4, 1e-2, .5, 5e-6, .03, .04;
  112. //VectorXcr sigma(2);
  113. // sigma << 0., .0;
  114. //VectorXr susl(3);
  115. // susl << 1., 1., 1.5;//, 5e-6, 5e-6, 5e-6;
  116. //VectorXr sush(3);
  117. // sush << 1., 1.01;//, 5e-6, 5e-6, 5e-6;
  118. //VectorXr sustau(2);
  119. // sustau << 1., 1.0;//, 5e-6, 5e-6, 5e-6;
  120. //VectorXr susb(2);
  121. // susb << 0., .0;//, 5e-6, 5e-6, 5e-6;
  122. VectorXr thick(6);
  123. thick << 10 , 10 , 10 , 10 , 10 , 10;
  124. LayeredEarthEM *earth = LayeredEarthEM::New();
  125. earth->SetNumberOfLayers(8);
  126. //earth->SetNumberOfLayers(23);
  127. earth->SetLayerConductivity(sigma);
  128. //earth->SetLayerLowFreqSusceptibility(susl);
  129. //earth->SetLayerHighFreqSusceptibility(sush);
  130. //earth->SetLayerTauSusceptibility(sustau);
  131. //earth->SetLayerBreathSusceptibility(susb);
  132. //earth->SetLayerHighFreqSusceptibility(susl);
  133. //earth->SetLayerHighFreqSusceptibility(susl);
  134. earth->SetLayerThickness(thick);
  135. // just a test
  136. timer.end();
  137. // Receivers
  138. ReceiverPoints *receivers = ReceiverPoints::New();
  139. Vector3r loc;
  140. Real ox = 50.;
  141. Real oy = 70. ;
  142. Real depth = -40.13423;
  143. Real depth2 = depth;
  144. Real dz = .25;
  145. int nz = 3000;
  146. Real dx = .0;
  147. receivers->SetNumberOfReceivers(nz);
  148. int ir = 0;
  149. for (int iz=0; iz<nz; ++iz) {
  150. loc << ox, oy, depth;
  151. receivers->SetLocation(ir, loc);
  152. depth += dz;
  153. ox += dx;
  154. ++ ir;
  155. }
  156. // EmEarth
  157. EMEarth1D *EmEarth = EMEarth1D::New();
  158. EmEarth->AttachDipoleSource(dipole);
  159. EmEarth->AttachLayeredEarthEM(earth);
  160. EmEarth->AttachReceiverPoints(receivers);
  161. //EmEarth->SetFieldsToCalculate(BOTH);
  162. EmEarth->SetFieldsToCalculate(H);
  163. //EmEarth->SetHankelTransformMethod(GAUSSIANQUADRATURE);
  164. //EmEarth->SetHankelTransformMethod(DIGITALFILTERING);
  165. //EmEarth->SetHankelTransformMethod(FHTKEY201);
  166. //EmEarth->SetHankelTransformMethod(QWEKEY);
  167. EmEarth->SetHankelTransformMethod(FHTKEY51);
  168. timer.begin();
  169. EmEarth->MakeCalc3();
  170. //std::cout << "H\n" << receivers->GetHfield(0)
  171. // << "End of H" << std::endl;
  172. Real lemmaTime = timer.end();
  173. std::cout << lemmaTime << "\t";
  174. //std::cout << "Make Calc3\n";
  175. //receivers->ClearFields();
  176. //EmEarth->MakeCalc3();
  177. //std::cout << "Make Calc3 finished\n";
  178. #ifdef LEMMAUSEVTK
  179. int iif=0;
  180. vtkDataObject *_dataObjectxr = receivers->GetVtkDataObject(HFIELDREAL, iif,
  181. 0, receivers->GetNumberOfReceivers(), XCOMPONENT, ZCOORD);
  182. vtkDataObject *_dataObjectxi = receivers->GetVtkDataObject(HFIELDIMAG, iif,
  183. 0, receivers->GetNumberOfReceivers(), XCOMPONENT, ZCOORD);
  184. vtkDataObject *_dataObjectyr= receivers->GetVtkDataObject(HFIELDREAL, iif,
  185. 0, receivers->GetNumberOfReceivers(), YCOMPONENT, ZCOORD);
  186. vtkDataObject *_dataObjectyi = receivers->GetVtkDataObject(HFIELDIMAG, iif,
  187. 0, receivers->GetNumberOfReceivers(), YCOMPONENT, ZCOORD);
  188. vtkDataObject *_dataObjectzr = receivers->GetVtkDataObject(HFIELDREAL, iif,
  189. 0, receivers->GetNumberOfReceivers(), ZCOMPONENT, ZCOORD);
  190. vtkDataObject *_dataObjectzi = receivers->GetVtkDataObject(HFIELDIMAG, iif,
  191. 0, receivers->GetNumberOfReceivers(), ZCOMPONENT, ZCOORD);
  192. #endif
  193. /*
  194. // Write out to file
  195. depth = depth2;
  196. std::fstream real("reale_lay.dat", std::ios::out);
  197. std::fstream imag("image_lay.dat", std::ios::out);
  198. std::fstream hreal("real_lay.dat", std::ios::out);
  199. std::fstream himag("imag_lay.dat", std::ios::out);
  200. for (int iz=0; iz<nz; ++iz) {
  201. Vector3cr temp = receivers->GetEfield(0,iz);
  202. //std::cout << temp << endl;
  203. real << ox << "\t" << oy << "\t" << depth << "\t"
  204. << temp(0).real() << "\t" << temp(1).real()
  205. << "\t" << temp(2).real() << std::endl;
  206. imag << ox << "\t" << oy << "\t" << depth << "\t"
  207. << std::imag(temp(0)) << "\t" << std::imag(temp(1))
  208. << "\t" << std::imag(temp(2)) << std::endl;
  209. temp = receivers->GetHfield(0, iz);
  210. hreal << ox << "\t" << oy << "\t" << depth << "\t"
  211. << std::real(temp(0)) << "\t" << std::real(temp(1))
  212. << "\t" << std::real(temp(2)) << std::endl;
  213. himag << ox << "\t" << oy << "\t" << depth << "\t"
  214. << std::imag(temp(0)) << "\t" << std::imag(temp(1))
  215. << "\t" << std::imag(temp(2)) << std::endl;
  216. depth += dz;
  217. }
  218. real.close();
  219. imag.close();
  220. */
  221. // TODO check all field components for both E and H,
  222. // diplay in some sort of reasonable manner.
  223. // Then, and only then, optimise.
  224. receivers->ClearFields();
  225. //dipole->SetPolarisation(XPOLARISATION);
  226. //std::cout << "Fortran Calc" << std::endl;
  227. #ifdef KIHALEE_EM1D
  228. timer.begin();
  229. EmEarth->MakeCalc();
  230. Real fortranTime = timer.end();
  231. std::cout << fortranTime << "\t";
  232. std::cout << fortranTime/lemmaTime << std::endl;
  233. #endif
  234. #ifdef LEMMAUSEVTK
  235. vtkDataObject *_fdataObjectxr = receivers->GetVtkDataObject(HFIELDREAL, 0,
  236. 0, receivers->GetNumberOfReceivers(), XCOMPONENT, ZCOORD);
  237. vtkDataObject *_fdataObjectxi = receivers->GetVtkDataObject(HFIELDIMAG, 0,
  238. 0, receivers->GetNumberOfReceivers(), XCOMPONENT, ZCOORD);
  239. vtkDataObject *_fdataObjectyr = receivers->GetVtkDataObject(HFIELDREAL, 0,
  240. 0, receivers->GetNumberOfReceivers(), YCOMPONENT, ZCOORD);
  241. vtkDataObject *_fdataObjectyi = receivers->GetVtkDataObject(HFIELDIMAG, 0,
  242. 0, receivers->GetNumberOfReceivers(), YCOMPONENT, ZCOORD);
  243. vtkDataObject *_fdataObjectzr = receivers->GetVtkDataObject(HFIELDREAL, 0,
  244. 0, receivers->GetNumberOfReceivers(), ZCOMPONENT, ZCOORD);
  245. vtkDataObject *_fdataObjectzi = receivers->GetVtkDataObject(HFIELDIMAG, 0,
  246. 0, receivers->GetNumberOfReceivers(), ZCOMPONENT, ZCOORD);
  247. #endif
  248. // Simple 2D plot in vtk to compare algorithms
  249. #ifdef LEMMAUSEVTK
  250. vtkRenderer *_ren = vtkRenderer::New();
  251. vtkRenderWindow *_renwin = vtkRenderWindow::New();
  252. _renwin->AddRenderer(_ren);
  253. ///////////////////////////////////////////////
  254. // X Component Plot
  255. vtkXYPlotActor *_xplot = vtkXYPlotActor::New();
  256. //vtkXYPlotWidget *_wplot = vtkXYPlotWidget::New();
  257. // Add the datasets
  258. _xplot->AddDataObjectInput( _dataObjectxr);
  259. _xplot->AddDataObjectInput( _dataObjectxi);
  260. _xplot->AddDataObjectInput(_fdataObjectxr);
  261. _xplot->AddDataObjectInput(_fdataObjectxi);
  262. _xplot->SetTitle("H_x");
  263. _xplot->SetXTitle("");
  264. _xplot->SetYTitle("");
  265. _xplot->SetXValuesToValue();
  266. //_plot->SetXValuesToIndex();
  267. // set which parts of the data object are to be used for which axis
  268. _xplot->SetDataObjectXComponent(0,1);
  269. _xplot->SetDataObjectYComponent(0,0);
  270. _xplot->SetDataObjectXComponent(1,1);
  271. _xplot->SetDataObjectYComponent(1,0);
  272. _xplot->SetDataObjectXComponent(2,1);
  273. _xplot->SetDataObjectYComponent(2,0);
  274. _xplot->SetDataObjectXComponent(3,1);
  275. _xplot->SetDataObjectYComponent(3,0);
  276. _xplot->SetNumberOfXLabels(3);
  277. _xplot->SetPlotColor(0,1,1,1);
  278. _xplot->SetPlotColor(1,0,0,1);
  279. _xplot->SetPlotColor(2,1,0,0);
  280. _xplot->SetPlotColor(3,0,1,0);
  281. _xplot->SetPlotLabel(0, "Lemma real" );
  282. _xplot->SetPlotLabel(1, "Lemma imag" );
  283. _xplot->SetPlotLabel(2, "KiHa real" );
  284. _xplot->SetPlotLabel(3, "KiHa imag" );
  285. _xplot->GetProperty()->SetLineWidth(1);
  286. _xplot->GetProperty()->SetPointSize(22);
  287. _xplot->LegendOn();
  288. // _plot->SetPlotPoints(0,0);
  289. // _plot->SetPlotPoints(1,0);
  290. // _plot->SetPlotPoints(2,0);
  291. // _plot->SetPlotPoints(3,0);
  292. // _plot->SetPlotLines(0,0);
  293. // _plot->SetPlotLines(1,0);
  294. // _plot->SetPlotLines(2,0);
  295. // _plot->SetPlotLines(3,0);
  296. _xplot->PlotCurvePointsOff();
  297. _xplot->PlotCurveLinesOff();
  298. _xplot->GetPositionCoordinate()->SetValue(0.0, 0.67, 0);
  299. _xplot->GetPosition2Coordinate()->SetValue(1.0, 0.33, 0);
  300. //_plot->SetReverseYAxis(1); // Just flips axis, not data!
  301. ///////////////////////////////////////////////
  302. // Y Component Plot
  303. vtkXYPlotActor *_yplot = vtkXYPlotActor::New();
  304. //vtkXYPlotWidget *_wplot = vtkXYPlotWidget::New();
  305. // Add the datasets
  306. _yplot->AddDataObjectInput( _dataObjectyr);
  307. _yplot->AddDataObjectInput( _dataObjectyi);
  308. _yplot->AddDataObjectInput(_fdataObjectyr);
  309. _yplot->AddDataObjectInput(_fdataObjectyi);
  310. _yplot->SetTitle("H_y");
  311. _yplot->SetXTitle("");
  312. _yplot->SetYTitle("");
  313. _yplot->SetXValuesToValue();
  314. //_yplot->SetXValuesToIndex();
  315. // set which parts of the data object are to be used for which axis
  316. _yplot->SetDataObjectXComponent(0,1);
  317. _yplot->SetDataObjectYComponent(0,0);
  318. _yplot->SetDataObjectXComponent(1,1);
  319. _yplot->SetDataObjectYComponent(1,0);
  320. _yplot->SetDataObjectXComponent(2,1);
  321. _yplot->SetDataObjectYComponent(2,0);
  322. _yplot->SetDataObjectXComponent(3,1);
  323. _yplot->SetDataObjectYComponent(3,0);
  324. _yplot->SetNumberOfXLabels(3);
  325. _yplot->SetPlotColor(0,1,1,1);
  326. _yplot->SetPlotColor(1,0,0,1);
  327. _yplot->SetPlotColor(2,1,0,0);
  328. _yplot->SetPlotColor(3,0,1,0);
  329. _yplot->SetPlotLabel(0, "Lemma real" );
  330. _yplot->SetPlotLabel(1, "Lemma imag" );
  331. _yplot->SetPlotLabel(2, "KiHa real" );
  332. _yplot->SetPlotLabel(3, "KiHa imag" );
  333. _yplot->LegendOn();
  334. _yplot->GetProperty()->SetLineWidth(1);
  335. _yplot->GetProperty()->SetPointSize(12);
  336. _yplot->GetPositionCoordinate()->SetValue(0.00, 0.33, 0);
  337. _yplot->GetPosition2Coordinate()->SetValue(1.0, 0.33, 0);
  338. // _plot->SetPlotPoints(0,0);
  339. // _plot->SetPlotPoints(1,0);
  340. // _plot->SetPlotPoints(2,0);
  341. // _plot->SetPlotPoints(3,0);
  342. // _plot->SetPlotLines(0,0);
  343. // _plot->SetPlotLines(1,0);
  344. // _plot->SetPlotLines(2,0);
  345. // _plot->SetPlotLines(3,0);
  346. _yplot->PlotCurvePointsOff();
  347. _yplot->PlotCurveLinesOff();
  348. //_plot->SetReverseYAxis(1)
  349. ///////////////////////////////////////////////
  350. // Z Component Plot
  351. vtkXYPlotActor *_zplot = vtkXYPlotActor::New();
  352. //vtkXYPlotWidget *_wplot = vtkXYPlotWidget::New();
  353. // Add the datasets
  354. _zplot->AddDataObjectInput( _dataObjectzr);
  355. _zplot->AddDataObjectInput( _dataObjectzi);
  356. _zplot->AddDataObjectInput(_fdataObjectzr);
  357. _zplot->AddDataObjectInput(_fdataObjectzi);
  358. _zplot->SetTitle("H_z");
  359. _zplot->SetXTitle("Depth");
  360. _zplot->SetYTitle("");
  361. _zplot->SetXValuesToValue();
  362. //_plot->SetXValuesToIndex();
  363. // set which parts of the data object are to be used for which axis
  364. _zplot->SetDataObjectXComponent(0,1);
  365. _zplot->SetDataObjectYComponent(0,0);
  366. _zplot->SetDataObjectXComponent(1,1);
  367. _zplot->SetDataObjectYComponent(1,0);
  368. _zplot->SetDataObjectXComponent(2,1);
  369. _zplot->SetDataObjectYComponent(2,0);
  370. _zplot->SetDataObjectXComponent(3,1);
  371. _zplot->SetDataObjectYComponent(3,0);
  372. _zplot->SetNumberOfXLabels(3);
  373. _zplot->SetPlotColor(0,1,1,1);
  374. _zplot->SetPlotColor(1,0,0,1);
  375. _zplot->SetPlotColor(2,1,0,0);
  376. _zplot->SetPlotColor(3,0,1,0);
  377. _zplot->LegendOn();
  378. _zplot->SetPlotLabel(0, "Lemma real" );
  379. _zplot->SetPlotLabel(1, "Lemma imag" );
  380. _zplot->SetPlotLabel(2, "KiHa real" );
  381. _zplot->SetPlotLabel(3, "KiHa imag" );
  382. _zplot->GetProperty()->SetLineWidth(1);
  383. _zplot->GetProperty()->SetPointSize(14);
  384. _zplot->GetPositionCoordinate()->SetValue(0.0, 0.0, 0);
  385. _zplot->GetPosition2Coordinate()->SetValue(1.0, 0.33, 0);
  386. // _plot->SetPlotPoints(0,0);
  387. // _plot->SetPlotPoints(1,0);
  388. // _plot->SetPlotPoints(2,0);
  389. // _plot->SetPlotPoints(3,0);
  390. // _plot->SetPlotLines(0,0);
  391. // _plot->SetPlotLines(1,0);
  392. // _plot->SetPlotLines(2,0);
  393. // _plot->SetPlotLines(3,0);
  394. _zplot->PlotCurvePointsOn();
  395. _zplot->PlotCurveLinesOff();
  396. //_plot->SetReverseYAxis(1)
  397. _ren->AddActor2D(_xplot);
  398. _ren->AddActor2D(_yplot);
  399. _ren->AddActor2D(_zplot);
  400. vtkRenderWindowInteractor *_iren = vtkRenderWindowInteractor::New();
  401. _iren->SetRenderWindow(_renwin);
  402. _iren->Initialize();
  403. _renwin->Render();
  404. //_wplot->SetXYPlotActor(_plot);
  405. //_wplot->SetInteractor(_iren);
  406. //_wplot->EnabledOn();
  407. _iren->Start();
  408. // TODO clean up you dirty whore
  409. // _iren->Delete();
  410. // _plot->Delete();
  411. // _dataObject->Delete();
  412. // _fieldData->Delete();
  413. // _renwin->Delete();
  414. // _ren->Delete();
  415. // _xdatareal->Delete();
  416. // _ydata->Delete();
  417. // _depth->Delete();
  418. #endif
  419. EmEarth->Delete();
  420. receivers->Delete();
  421. earth->Delete();
  422. dipole->Delete();
  423. return 0;
  424. }