123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498 |
- // ===========================================================================
- //
- // Filename: utdipolesource.cpp
- //
- // Description:
- //
- // Version: 0.0
- // Created: 12/02/2009 11:57:14 AM
- // Revision: none
- // Compiler: g++ (c++)
- //
- // Author: Trevor Irons (ti)
- //
- // Organisation: Colorado School of Mines (CSM)
- // United States Geological Survey (USGS)
- //
- // Email: tirons@mines.edu, tirons@usgs.gov
- //
- // This program is free software: you can redistribute it and/or modify
- // it under the terms of the GNU General Public License as published by
- // the Free Software Foundation, either version 3 of the License, or
- // (at your option) any later version.
- //
- // This program is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU General Public License for more details.
- //
- // You should have received a copy of the GNU General Public License
- // along with this program. If not, see <http://www.gnu.org/licenses/>.
- //
- // ===========================================================================
-
- #include <iostream>
- #include <fstream>
- #include "DipoleSource.h"
-
-
- // For testing purposes disable VTK and run scale.sh
- #undef LEMMAUSEVTK
- #undef KIHALEE_EM1D
-
- #ifdef LEMMAUSEVTK
- #include "vtkRenderer.h"
- #include "vtkRenderWindow.h"
- #include "vtkRenderWindowInteractor.h"
- #include "vtkDoubleArray.h"
- #include "vtkXYPlotActor.h"
- #include "vtkXYPlotWidget.h"
- #include "vtkProperty2D.h"
- #endif
-
- #include "timer.h"
-
- using namespace Lemma;
-
- int main() {
-
- //////////////////
- // TODO List of Dipole settings that aren't working
-
- // Do calculation
- jsw_timer timer;
- timer.begin();
-
- // Test with a single dipole
- DipoleSource *dipole = DipoleSource::New();
- //dipole->SetMoment(2);
- ///////////////////////////////////
- // E field Tests
- // Sems to be working!
- //dipole->SetType(GROUNDEDELECTRICDIPOLE);
- //dipole->SetPolarisation(XPOLARISATION);
- //dipole->SetPolarisation(YPOLARISATION);
- //dipole->SetPolarisation(ZPOLARISATION);
- //dipole->SetAzimuth(0); // X - Northing
- //dipole->SetAzimuth(90); // Y - Easting
-
- dipole->SetType(GROUNDEDELECTRICDIPOLE);
- //dipole->SetPolarisation(1., 0.0, 1.0);
- // dipole->SetPolarisation(XPOLARISATION);
- dipole->SetPolarisation(YPOLARISATION);
- //dipole->SetPolarisation(ZPOLARISATION);
-
- /////////////
- //dipole->SetType(MAGNETICDIPOLE);
- //dipole->SetPolarisation(0., 0.0, 1.0);
- //dipole->SetPolarisation(XPOLARISATION);
- //dipole->SetPolarisation(YPOLARISATION);
- //dipole->SetPolarisation(ZPOLARISATION);
-
- //dipole->SetMoment(1);
- //dipole->SetLocation(1,1,-.0100328);
- dipole->SetLocation(0., 0., -0.001);
- //dipole->SetLocation(-2.5,1.25,0);
- dipole->SetNumberOfFrequencies(1);
- dipole->SetFrequency(0, 2e7);
- //dipole->SetFrequency(1,2000);
- //dipole->SetPhase(0);
-
- //////////////////////////////////
- // H field Tests
-
- // // Define model, this is a difficult case
- // VectorXcr sigma(23);
- // sigma << 0., 0.0625, 0.0166666666666667, 0.04, 0.0181818181818182,
- // 0.05, 0.0222222222222222, 0.2, 0.025, 0.05, 0.025,
- // 0.05, 0.00833333333333333, 0.025, 0.05, 0.0222222222222222,
- // 0.0277777777777778, 0.0333333333333333, 0.0208333333333333,
- // 0.0181818181818182, 0.025, 0.04;
- //
- // VectorXr thick(21);
- // //thick << 10, 10, 10, 10, 10, 10;
- // thick << 11, 5, 5, 4, 3.5, 4.5, 4.5,
- // 5.5, 3, 36, 15, 3, 6, 3, 8,
- // 9, 10, 7, 8, 11, 68;
-
- //VectorXcr sigma(8);
- // sigma << 0., Complex(.01,0.01), 0.001, .005, .0034, .0023, .0024, .0001;
-
- VectorXcr sigma(8);
- sigma << 0., 3e-4, 5e-4, 1e-2, .5, 5e-6, .03, .04;
- //VectorXcr sigma(2);
- // sigma << 0., .0;
- //VectorXr susl(3);
- // susl << 1., 1., 1.5;//, 5e-6, 5e-6, 5e-6;
- //VectorXr sush(3);
- // sush << 1., 1.01;//, 5e-6, 5e-6, 5e-6;
- //VectorXr sustau(2);
- // sustau << 1., 1.0;//, 5e-6, 5e-6, 5e-6;
- //VectorXr susb(2);
- // susb << 0., .0;//, 5e-6, 5e-6, 5e-6;
- VectorXr thick(6);
- thick << 10 , 10 , 10 , 10 , 10 , 10;
-
- LayeredEarthEM *earth = LayeredEarthEM::New();
- earth->SetNumberOfLayers(8);
- //earth->SetNumberOfLayers(23);
- earth->SetLayerConductivity(sigma);
- //earth->SetLayerLowFreqSusceptibility(susl);
- //earth->SetLayerHighFreqSusceptibility(sush);
- //earth->SetLayerTauSusceptibility(sustau);
- //earth->SetLayerBreathSusceptibility(susb);
- //earth->SetLayerHighFreqSusceptibility(susl);
- //earth->SetLayerHighFreqSusceptibility(susl);
- earth->SetLayerThickness(thick);
-
- // just a test
- timer.end();
-
- // Receivers
- ReceiverPoints *receivers = ReceiverPoints::New();
- Vector3r loc;
- Real ox = 50.;
- Real oy = 70. ;
- Real depth = -40.13423;
- Real depth2 = depth;
- Real dz = .25;
- int nz = 3000;
- Real dx = .0;
- receivers->SetNumberOfReceivers(nz);
- int ir = 0;
- for (int iz=0; iz<nz; ++iz) {
- loc << ox, oy, depth;
- receivers->SetLocation(ir, loc);
- depth += dz;
- ox += dx;
- ++ ir;
- }
-
- // EmEarth
- EMEarth1D *EmEarth = EMEarth1D::New();
- EmEarth->AttachDipoleSource(dipole);
- EmEarth->AttachLayeredEarthEM(earth);
- EmEarth->AttachReceiverPoints(receivers);
- //EmEarth->SetFieldsToCalculate(BOTH);
- EmEarth->SetFieldsToCalculate(H);
-
- //EmEarth->SetHankelTransformMethod(GAUSSIANQUADRATURE);
- //EmEarth->SetHankelTransformMethod(DIGITALFILTERING);
- //EmEarth->SetHankelTransformMethod(FHTKEY201);
- //EmEarth->SetHankelTransformMethod(QWEKEY);
- EmEarth->SetHankelTransformMethod(FHTKEY51);
-
- timer.begin();
- EmEarth->MakeCalc3();
- //std::cout << "H\n" << receivers->GetHfield(0)
- // << "End of H" << std::endl;
- Real lemmaTime = timer.end();
- std::cout << lemmaTime << "\t";
-
- //std::cout << "Make Calc3\n";
- //receivers->ClearFields();
-
- //EmEarth->MakeCalc3();
- //std::cout << "Make Calc3 finished\n";
-
- #ifdef LEMMAUSEVTK
- int iif=0;
- vtkDataObject *_dataObjectxr = receivers->GetVtkDataObject(HFIELDREAL, iif,
- 0, receivers->GetNumberOfReceivers(), XCOMPONENT, ZCOORD);
-
- vtkDataObject *_dataObjectxi = receivers->GetVtkDataObject(HFIELDIMAG, iif,
- 0, receivers->GetNumberOfReceivers(), XCOMPONENT, ZCOORD);
-
- vtkDataObject *_dataObjectyr= receivers->GetVtkDataObject(HFIELDREAL, iif,
- 0, receivers->GetNumberOfReceivers(), YCOMPONENT, ZCOORD);
-
- vtkDataObject *_dataObjectyi = receivers->GetVtkDataObject(HFIELDIMAG, iif,
- 0, receivers->GetNumberOfReceivers(), YCOMPONENT, ZCOORD);
-
- vtkDataObject *_dataObjectzr = receivers->GetVtkDataObject(HFIELDREAL, iif,
- 0, receivers->GetNumberOfReceivers(), ZCOMPONENT, ZCOORD);
-
- vtkDataObject *_dataObjectzi = receivers->GetVtkDataObject(HFIELDIMAG, iif,
- 0, receivers->GetNumberOfReceivers(), ZCOMPONENT, ZCOORD);
- #endif
-
- /*
- // Write out to file
- depth = depth2;
- std::fstream real("reale_lay.dat", std::ios::out);
- std::fstream imag("image_lay.dat", std::ios::out);
- std::fstream hreal("real_lay.dat", std::ios::out);
- std::fstream himag("imag_lay.dat", std::ios::out);
- for (int iz=0; iz<nz; ++iz) {
- Vector3cr temp = receivers->GetEfield(0,iz);
-
- //std::cout << temp << endl;
- real << ox << "\t" << oy << "\t" << depth << "\t"
- << temp(0).real() << "\t" << temp(1).real()
- << "\t" << temp(2).real() << std::endl;
-
- imag << ox << "\t" << oy << "\t" << depth << "\t"
- << std::imag(temp(0)) << "\t" << std::imag(temp(1))
- << "\t" << std::imag(temp(2)) << std::endl;
-
- temp = receivers->GetHfield(0, iz);
-
- hreal << ox << "\t" << oy << "\t" << depth << "\t"
- << std::real(temp(0)) << "\t" << std::real(temp(1))
- << "\t" << std::real(temp(2)) << std::endl;
- himag << ox << "\t" << oy << "\t" << depth << "\t"
- << std::imag(temp(0)) << "\t" << std::imag(temp(1))
- << "\t" << std::imag(temp(2)) << std::endl;
- depth += dz;
- }
- real.close();
- imag.close();
- */
-
- // TODO check all field components for both E and H,
- // diplay in some sort of reasonable manner.
- // Then, and only then, optimise.
-
- receivers->ClearFields();
-
- //dipole->SetPolarisation(XPOLARISATION);
- //std::cout << "Fortran Calc" << std::endl;
- #ifdef KIHALEE_EM1D
- timer.begin();
- EmEarth->MakeCalc();
- Real fortranTime = timer.end();
- std::cout << fortranTime << "\t";
- std::cout << fortranTime/lemmaTime << std::endl;
- #endif
-
- #ifdef LEMMAUSEVTK
- vtkDataObject *_fdataObjectxr = receivers->GetVtkDataObject(HFIELDREAL, 0,
- 0, receivers->GetNumberOfReceivers(), XCOMPONENT, ZCOORD);
-
- vtkDataObject *_fdataObjectxi = receivers->GetVtkDataObject(HFIELDIMAG, 0,
- 0, receivers->GetNumberOfReceivers(), XCOMPONENT, ZCOORD);
-
- vtkDataObject *_fdataObjectyr = receivers->GetVtkDataObject(HFIELDREAL, 0,
- 0, receivers->GetNumberOfReceivers(), YCOMPONENT, ZCOORD);
-
- vtkDataObject *_fdataObjectyi = receivers->GetVtkDataObject(HFIELDIMAG, 0,
- 0, receivers->GetNumberOfReceivers(), YCOMPONENT, ZCOORD);
-
- vtkDataObject *_fdataObjectzr = receivers->GetVtkDataObject(HFIELDREAL, 0,
- 0, receivers->GetNumberOfReceivers(), ZCOMPONENT, ZCOORD);
-
- vtkDataObject *_fdataObjectzi = receivers->GetVtkDataObject(HFIELDIMAG, 0,
- 0, receivers->GetNumberOfReceivers(), ZCOMPONENT, ZCOORD);
- #endif
-
- // Simple 2D plot in vtk to compare algorithms
- #ifdef LEMMAUSEVTK
- vtkRenderer *_ren = vtkRenderer::New();
- vtkRenderWindow *_renwin = vtkRenderWindow::New();
- _renwin->AddRenderer(_ren);
-
- ///////////////////////////////////////////////
- // X Component Plot
- vtkXYPlotActor *_xplot = vtkXYPlotActor::New();
- //vtkXYPlotWidget *_wplot = vtkXYPlotWidget::New();
- // Add the datasets
- _xplot->AddDataObjectInput( _dataObjectxr);
- _xplot->AddDataObjectInput( _dataObjectxi);
- _xplot->AddDataObjectInput(_fdataObjectxr);
- _xplot->AddDataObjectInput(_fdataObjectxi);
- _xplot->SetTitle("H_x");
- _xplot->SetXTitle("");
- _xplot->SetYTitle("");
- _xplot->SetXValuesToValue();
- //_plot->SetXValuesToIndex();
-
- // set which parts of the data object are to be used for which axis
- _xplot->SetDataObjectXComponent(0,1);
- _xplot->SetDataObjectYComponent(0,0);
- _xplot->SetDataObjectXComponent(1,1);
- _xplot->SetDataObjectYComponent(1,0);
- _xplot->SetDataObjectXComponent(2,1);
- _xplot->SetDataObjectYComponent(2,0);
- _xplot->SetDataObjectXComponent(3,1);
- _xplot->SetDataObjectYComponent(3,0);
- _xplot->SetNumberOfXLabels(3);
-
- _xplot->SetPlotColor(0,1,1,1);
- _xplot->SetPlotColor(1,0,0,1);
-
- _xplot->SetPlotColor(2,1,0,0);
- _xplot->SetPlotColor(3,0,1,0);
-
- _xplot->SetPlotLabel(0, "Lemma real" );
- _xplot->SetPlotLabel(1, "Lemma imag" );
- _xplot->SetPlotLabel(2, "KiHa real" );
- _xplot->SetPlotLabel(3, "KiHa imag" );
-
- _xplot->GetProperty()->SetLineWidth(1);
- _xplot->GetProperty()->SetPointSize(22);
-
- _xplot->LegendOn();
- // _plot->SetPlotPoints(0,0);
- // _plot->SetPlotPoints(1,0);
- // _plot->SetPlotPoints(2,0);
- // _plot->SetPlotPoints(3,0);
-
- // _plot->SetPlotLines(0,0);
- // _plot->SetPlotLines(1,0);
- // _plot->SetPlotLines(2,0);
- // _plot->SetPlotLines(3,0);
-
- _xplot->PlotCurvePointsOff();
- _xplot->PlotCurveLinesOff();
- _xplot->GetPositionCoordinate()->SetValue(0.0, 0.67, 0);
- _xplot->GetPosition2Coordinate()->SetValue(1.0, 0.33, 0);
- //_plot->SetReverseYAxis(1); // Just flips axis, not data!
-
- ///////////////////////////////////////////////
- // Y Component Plot
- vtkXYPlotActor *_yplot = vtkXYPlotActor::New();
- //vtkXYPlotWidget *_wplot = vtkXYPlotWidget::New();
- // Add the datasets
- _yplot->AddDataObjectInput( _dataObjectyr);
- _yplot->AddDataObjectInput( _dataObjectyi);
- _yplot->AddDataObjectInput(_fdataObjectyr);
- _yplot->AddDataObjectInput(_fdataObjectyi);
- _yplot->SetTitle("H_y");
- _yplot->SetXTitle("");
- _yplot->SetYTitle("");
- _yplot->SetXValuesToValue();
- //_yplot->SetXValuesToIndex();
-
- // set which parts of the data object are to be used for which axis
- _yplot->SetDataObjectXComponent(0,1);
- _yplot->SetDataObjectYComponent(0,0);
- _yplot->SetDataObjectXComponent(1,1);
- _yplot->SetDataObjectYComponent(1,0);
- _yplot->SetDataObjectXComponent(2,1);
- _yplot->SetDataObjectYComponent(2,0);
- _yplot->SetDataObjectXComponent(3,1);
- _yplot->SetDataObjectYComponent(3,0);
- _yplot->SetNumberOfXLabels(3);
-
- _yplot->SetPlotColor(0,1,1,1);
- _yplot->SetPlotColor(1,0,0,1);
-
- _yplot->SetPlotColor(2,1,0,0);
- _yplot->SetPlotColor(3,0,1,0);
-
- _yplot->SetPlotLabel(0, "Lemma real" );
- _yplot->SetPlotLabel(1, "Lemma imag" );
- _yplot->SetPlotLabel(2, "KiHa real" );
- _yplot->SetPlotLabel(3, "KiHa imag" );
- _yplot->LegendOn();
-
- _yplot->GetProperty()->SetLineWidth(1);
- _yplot->GetProperty()->SetPointSize(12);
- _yplot->GetPositionCoordinate()->SetValue(0.00, 0.33, 0);
- _yplot->GetPosition2Coordinate()->SetValue(1.0, 0.33, 0);
-
- // _plot->SetPlotPoints(0,0);
- // _plot->SetPlotPoints(1,0);
- // _plot->SetPlotPoints(2,0);
- // _plot->SetPlotPoints(3,0);
-
- // _plot->SetPlotLines(0,0);
- // _plot->SetPlotLines(1,0);
- // _plot->SetPlotLines(2,0);
- // _plot->SetPlotLines(3,0);
-
- _yplot->PlotCurvePointsOff();
- _yplot->PlotCurveLinesOff();
- //_plot->SetReverseYAxis(1)
-
- ///////////////////////////////////////////////
- // Z Component Plot
- vtkXYPlotActor *_zplot = vtkXYPlotActor::New();
- //vtkXYPlotWidget *_wplot = vtkXYPlotWidget::New();
- // Add the datasets
- _zplot->AddDataObjectInput( _dataObjectzr);
- _zplot->AddDataObjectInput( _dataObjectzi);
- _zplot->AddDataObjectInput(_fdataObjectzr);
- _zplot->AddDataObjectInput(_fdataObjectzi);
- _zplot->SetTitle("H_z");
- _zplot->SetXTitle("Depth");
- _zplot->SetYTitle("");
- _zplot->SetXValuesToValue();
- //_plot->SetXValuesToIndex();
-
- // set which parts of the data object are to be used for which axis
- _zplot->SetDataObjectXComponent(0,1);
- _zplot->SetDataObjectYComponent(0,0);
- _zplot->SetDataObjectXComponent(1,1);
- _zplot->SetDataObjectYComponent(1,0);
- _zplot->SetDataObjectXComponent(2,1);
- _zplot->SetDataObjectYComponent(2,0);
- _zplot->SetDataObjectXComponent(3,1);
- _zplot->SetDataObjectYComponent(3,0);
- _zplot->SetNumberOfXLabels(3);
-
- _zplot->SetPlotColor(0,1,1,1);
- _zplot->SetPlotColor(1,0,0,1);
-
- _zplot->SetPlotColor(2,1,0,0);
- _zplot->SetPlotColor(3,0,1,0);
-
- _zplot->LegendOn();
-
- _zplot->SetPlotLabel(0, "Lemma real" );
- _zplot->SetPlotLabel(1, "Lemma imag" );
- _zplot->SetPlotLabel(2, "KiHa real" );
- _zplot->SetPlotLabel(3, "KiHa imag" );
-
- _zplot->GetProperty()->SetLineWidth(1);
- _zplot->GetProperty()->SetPointSize(14);
- _zplot->GetPositionCoordinate()->SetValue(0.0, 0.0, 0);
- _zplot->GetPosition2Coordinate()->SetValue(1.0, 0.33, 0);
- // _plot->SetPlotPoints(0,0);
- // _plot->SetPlotPoints(1,0);
- // _plot->SetPlotPoints(2,0);
- // _plot->SetPlotPoints(3,0);
-
- // _plot->SetPlotLines(0,0);
- // _plot->SetPlotLines(1,0);
- // _plot->SetPlotLines(2,0);
- // _plot->SetPlotLines(3,0);
-
- _zplot->PlotCurvePointsOn();
- _zplot->PlotCurveLinesOff();
- //_plot->SetReverseYAxis(1)
-
- _ren->AddActor2D(_xplot);
- _ren->AddActor2D(_yplot);
- _ren->AddActor2D(_zplot);
-
- vtkRenderWindowInteractor *_iren = vtkRenderWindowInteractor::New();
- _iren->SetRenderWindow(_renwin);
- _iren->Initialize();
- _renwin->Render();
-
- //_wplot->SetXYPlotActor(_plot);
- //_wplot->SetInteractor(_iren);
- //_wplot->EnabledOn();
-
- _iren->Start();
-
- // TODO clean up you dirty whore
- // _iren->Delete();
- // _plot->Delete();
- // _dataObject->Delete();
- // _fieldData->Delete();
- // _renwin->Delete();
- // _ren->Delete();
- // _xdatareal->Delete();
- // _ydata->Delete();
- // _depth->Delete();
- #endif
-
- EmEarth->Delete();
- receivers->Delete();
- earth->Delete();
- dipole->Delete();
-
- return 0;
- }
|