Browse Source

Added examples to CMake build and commented out FastDelegte calls. Still need to replace those calls with move semantics.

enhancement_3
Trevor Irons 8 years ago
parent
commit
4c5c148902
36 changed files with 4780 additions and 15 deletions
  1. 2
    0
      LemmaCore/CMakeLists.txt
  2. 36
    0
      LemmaCore/examples/CMakeLists.txt
  3. 116
    0
      LemmaCore/examples/DCIPElectrode.cpp
  4. 44
    0
      LemmaCore/examples/datatem.cpp
  5. 69
    0
      LemmaCore/examples/digitalfiltercostrans.cpp
  6. 345
    0
      LemmaCore/examples/dipolefreqsweep.cpp
  7. 504
    0
      LemmaCore/examples/dipolesource.cpp
  8. 231
    0
      LemmaCore/examples/edipole.cpp
  9. 141
    0
      LemmaCore/examples/emdipearth1d.cpp
  10. 199
    0
      LemmaCore/examples/femforward.cpp
  11. 53
    0
      LemmaCore/examples/filter.cpp
  12. 342
    0
      LemmaCore/examples/utORS.cpp
  13. 34
    0
      LemmaCore/examples/utQWEKey.cpp
  14. 86
    0
      LemmaCore/examples/utSerialize.cpp
  15. 31
    0
      LemmaCore/examples/utSkyTEM.cpp
  16. 197
    0
      LemmaCore/examples/utTEMSurvey.cpp
  17. 168
    0
      LemmaCore/examples/utXMLParse.cpp
  18. 67
    0
      LemmaCore/examples/utYAMLconfig.cpp
  19. 84
    0
      LemmaCore/examples/utgaussquad.cpp
  20. 258
    0
      LemmaCore/examples/utgmrprint.cpp
  21. 93
    0
      LemmaCore/examples/uthankel2.cpp
  22. 257
    0
      LemmaCore/examples/uthantenna.cpp
  23. 218
    0
      LemmaCore/examples/utlogbarriercg.cpp
  24. 67
    0
      LemmaCore/examples/utpolygonalantenna.cpp
  25. 68
    0
      LemmaCore/examples/utreadfemubc.cpp
  26. 54
    0
      LemmaCore/examples/utsandbox.cpp
  27. 199
    0
      LemmaCore/examples/uttemforward.cpp
  28. 131
    0
      LemmaCore/examples/utteminv1d.cpp
  29. 84
    0
      LemmaCore/examples/uttemreader.cpp
  30. 207
    0
      LemmaCore/examples/uttemsandbox.cpp
  31. 319
    0
      LemmaCore/examples/wireantenna.cpp
  32. 61
    0
      LemmaCore/include/Lemma
  33. 0
    3
      LemmaCore/include/logbarriercg.h
  34. 0
    3
      LemmaCore/include/logbarriercg_newton.h
  35. 13
    7
      LemmaCore/include/octreegrid.h
  36. 2
    2
      LemmaCore/src/octreegrid.cpp

+ 2
- 0
LemmaCore/CMakeLists.txt View File

@@ -16,3 +16,5 @@ if (VTK_SUPPORT)
16 16
 	target_link_libraries(lemmacore ${VTK_LIBRARIES})
17 17
 endif()
18 18
 target_link_libraries(lemmacore "yaml-cpp")
19
+
20
+add_subdirectory(examples)

+ 36
- 0
LemmaCore/examples/CMakeLists.txt View File

@@ -0,0 +1,36 @@
1
+FILE(GLOB  examples  "*.cpp")
2
+
3
+add_executable( datatem datatem.cpp )
4
+target_link_libraries(datatem "lemmacore")
5
+
6
+add_executable( wireantenna wireantenna.cpp )
7
+target_link_libraries(wireantenna "lemmacore")
8
+
9
+add_executable( DCIPElectrode  DCIPElectrode.cpp )
10
+target_link_libraries(DCIPElectrode "lemmacore")
11
+
12
+add_executable( digitalfiltercostrans  digitalfiltercostrans.cpp )
13
+target_link_libraries(digitalfiltercostrans "lemmacore")
14
+
15
+add_executable( dipolefreqsweep  dipolefreqsweep.cpp )
16
+target_link_libraries(dipolefreqsweep "lemmacore")
17
+
18
+add_executable( dipolesource  dipolesource.cpp )
19
+target_link_libraries(dipolesource "lemmacore")
20
+
21
+add_executable( edipole  edipole.cpp )
22
+target_link_libraries(edipole "lemmacore")
23
+
24
+add_executable( emdipearth1d  emdipearth1d.cpp )
25
+target_link_libraries(emdipearth1d "lemmacore")
26
+
27
+add_executable( femforward  femforward.cpp )
28
+target_link_libraries(femforward "lemmacore")
29
+
30
+add_executable( filter  filter.cpp )
31
+target_link_libraries(filter "lemmacore")
32
+
33
+
34
+
35
+
36
+

+ 116
- 0
LemmaCore/examples/DCIPElectrode.cpp View File

@@ -0,0 +1,116 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API.
2
+ * More information is available at http://lemmasoftware.org
3
+ */
4
+
5
+/* This Source Code Form is subject to the terms of the Mozilla Public
6
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
7
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
+ */
9
+
10
+/**
11
+ * @file
12
+ * @date      11/10/2014 12:31:01 PM
13
+ * @version   $Id$
14
+ * @author    Trevor Irons (ti)
15
+ * @email     Trevor.Irons@xri-geo.com
16
+ * @copyright Copyright (c) 2014, XRI Geophysics, LLC
17
+ * @copyright Copyright (c) 2014, Trevor Irons
18
+ */
19
+
20
+#include "DCIPElectrode.h"
21
+#include "DCSurvey.h"
22
+
23
+using namespace Lemma;
24
+
25
+int main() {
26
+
27
+
28
+    //DCIPElectrode* Electrode1 = DCIPElectrode::New();
29
+    DCIPElectrode* Electrode2 = DCIPElectrode::New();
30
+    DCIPElectrode* Electrode3 = DCIPElectrode::New();
31
+    DCIPElectrode* Electrode4 = DCIPElectrode::New();
32
+    DCIPElectrode* Electrode5 = DCIPElectrode::New();
33
+    DCIPElectrode* Electrode6 = DCIPElectrode::New();
34
+    DCIPElectrode* Electrode7 = DCIPElectrode::New();
35
+    DCIPElectrode* Electrode8 = DCIPElectrode::New();
36
+    DCIPElectrode* Electrode9 = DCIPElectrode::New();
37
+
38
+        //Electrode1->SetLocation( Vector3r( 23.23, 18.1, -45 )  );
39
+        Electrode2->SetLocation( Vector3r( 13.23, 18.1, -25 ) );
40
+        Electrode3->SetLocation( Vector3r( 13.23, 18.1, -25 ) );
41
+        Electrode4->SetLocation( Vector3r( 13.23, 18.1, -25 ) );
42
+        Electrode4->SetLocation( Vector3r( 13.23, 18.1, -25 ) );
43
+        Electrode5->SetLocation( Vector3r( 13.23, 18.1, -25 ) );
44
+        Electrode6->SetLocation( Vector3r( 13.23, 18.1, -25 ) );
45
+        Electrode7->SetLocation( Vector3r( 13.23, 18.1, -25 ) );
46
+        Electrode8->SetLocation( Vector3r( 13.23, 18.1, -25 ) );
47
+        Electrode9->SetLocation( Vector3r( 13.23, 18.1, -25 ) );
48
+
49
+//:        std::cout << *Electrode1 << std::endl;
50
+//     std::ofstream ofstr("DCIPElectrode.yaml");
51
+//         ofstr << *Electrode1;
52
+//         ofstr.close();
53
+
54
+    /*
55
+    //std::ifstream ifstr("DCIPElectrode.yaml");
56
+    std::ifstream ifstr("test.yaml");
57
+    YAML::Node node = YAML::Load(ifstr);
58
+    DCIPElectrode* Ex = DCIPElectrode::DeSerialize(node);
59
+    std::cout << *Ex << std::endl;
60
+    */
61
+    //exit(1);
62
+
63
+    //std::cout << *Electrode << std::endl;
64
+    //std::cout << *Electrode2 << std::endl;
65
+
66
+    // Set up a Survey
67
+    DCSurvey* Survey = DCSurvey::New();
68
+        // Instead we should just put location in, and then survey acts as factory?
69
+        DCIPElectrode* Electrode1 = Survey->PoundElectrode( Vector3r( 13.23, 18.1, -25 ), "L0-E0" );
70
+        Survey->PoundElectrode( Electrode2 , "L0-E1" );
71
+        Survey->PoundElectrode( Electrode3 , "L0-E2" );
72
+        Survey->PoundElectrode( Electrode4 , "L0-E3" );
73
+        Survey->PoundElectrode( Electrode5 , "L0-E4" );
74
+        Survey->PoundElectrode( Electrode6 , "L0-E5" );
75
+        Survey->PoundElectrode( Electrode7 , "L0-E6" );
76
+        Survey->PoundElectrode( Electrode8 , "L0-E7" );
77
+        Survey->PoundElectrode( Electrode9 , "L0-E8" );
78
+
79
+        int J0 = Survey->AddInjection( Electrode1, Electrode2, 1.0 );
80
+            Survey->AddMeasurement(J0, Electrode3, Electrode4 );
81
+            Survey->AddMeasurement(J0, Electrode5, Electrode6 );
82
+            Survey->AddMeasurement(J0, Electrode6, Electrode7 );
83
+            Survey->AddMeasurement(J0, "L0-E7", "L0-E8" );
84
+
85
+        int J1 = Survey->AddInjection( Electrode2, Electrode3, 1.0 );
86
+            Survey->AddMeasurement(J1, Electrode3, Electrode4 );
87
+            Survey->AddMeasurement(J1, Electrode5, Electrode6 );
88
+            Survey->AddMeasurement(J1, Electrode6, Electrode7 );
89
+
90
+        int J2 = Survey->AddInjection( Electrode3, Electrode4, 1.0 );
91
+            Survey->AddMeasurement(J2, Electrode3, Electrode4 );
92
+            Survey->AddMeasurement(J2, Electrode5, Electrode6 );
93
+            Survey->AddMeasurement(J2, Electrode6, Electrode7 );
94
+
95
+        //Survey->AddMeasurement(L1, L2)
96
+        std::cout << *Survey << std::endl;
97
+
98
+        std::ofstream outstr("DC.yaml");
99
+            outstr << *Survey << std::endl;
100
+            outstr.close();
101
+
102
+        Survey->Delete();
103
+
104
+        //TODO recheck DeSerialize make sure we are filling in all the Tag vectors
105
+
106
+        std::ifstream ifstr2("DC.yaml");
107
+        YAML::Node node2 = YAML::Load(ifstr2);
108
+        DCSurvey* Survey2 = DCSurvey::DeSerialize(node2);
109
+
110
+        std::cout << "==============================================================\n";
111
+        std::cout << *Survey2 << std::endl;
112
+
113
+    return(EXIT_SUCCESS);
114
+
115
+}
116
+

+ 44
- 0
LemmaCore/examples/datatem.cpp View File

@@ -0,0 +1,44 @@
1
+// ===========================================================================
2
+//
3
+//       Filename:
4
+//
5
+//    Description:
6
+//
7
+//        Version:  0.0
8
+//        Created:  03/02/2010 02:10:53 PM
9
+//       Revision:  none
10
+//       Compiler:  Tested with g++, icpc, and MSVC 2000
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
+
34
+#include "Lemma"
35
+using namespace Lemma;
36
+
37
+int main() {
38
+
39
+	DataTEM * tdata = DataTEM::New();
40
+	std::cout << *tdata << std::endl;
41
+	tdata->Zero();
42
+	tdata->Delete();
43
+
44
+}

+ 69
- 0
LemmaCore/examples/digitalfiltercostrans.cpp View File

@@ -0,0 +1,69 @@
1
+// ===========================================================================
2
+//
3
+//       Filename:  utdigitalfiltercostrans.cpp
4
+//
5
+//        Created:  02/08/2011 11:52:39 AM
6
+//       Compiler:  Tested with g++, icpc, and MSVC 2010
7
+//
8
+//         Author:  Trevor Irons (ti)
9
+//
10
+//   Organisation:  Colorado School of Mines (CSM)
11
+//                  United States Geological Survey (USGS)
12
+//
13
+//          Email:  tirons@mines.edu, tirons@usgs.gov
14
+//
15
+//  This program is free software: you can redistribute it and/or modify
16
+//  it under the terms of the GNU General Public License as published by
17
+//  the Free Software Foundation, either version 3 of the License, or
18
+//  (at your option) any later version.
19
+//
20
+//  This program is distributed in the hope that it will be useful,
21
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
+//  GNU General Public License for more details.
24
+//
25
+//  You should have received a copy of the GNU General Public License
26
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
27
+//
28
+// ===========================================================================
29
+
30
+/**
31
+  @file
32
+  @author   Trevor Irons
33
+  @date     02/08/2011
34
+  @version   0.0
35
+ **/
36
+
37
+#include "digitalfiltercostrans.h"
38
+#include "costransintegrationkernel.h"
39
+#include "integrationkernel.h"
40
+
41
+//class TestDriverKernel : public IntegrationKernel<Real> {
42
+//
43
+//};
44
+
45
+using namespace Lemma;
46
+
47
+int main() {
48
+
49
+	//Real A = 2.;
50
+	//Real B = 12.5;
51
+
52
+    Real A = 1.;
53
+    Real B = 2.;
54
+    DigitalFilterCosTrans* Cos = DigitalFilterCosTrans::New();
55
+    std::cout << *Cos << std::endl;
56
+    CosTransIntegrationKernel* Kernel = CosTransIntegrationKernel::New();
57
+    Cos->AttachKernel(Kernel);
58
+
59
+    Cos->Compute(B, 1, 1e-16);
60
+    std::cout << "numeric  " << Cos->GetAnswer() << std::endl;
61
+    Real SQPI = std::sqrt(PI);
62
+    Real analytic =  SQPI*std::exp(-B*B/(4.*A*A))/(2.*A);
63
+    std::cout << "analytic " << analytic <<std::endl;
64
+    std::cout << "absolute error " <<  Cos->GetAnswer()(0,0) - analytic <<std::endl;
65
+    std::cout << "relative error " << (Cos->GetAnswer()(0,0) - analytic) / analytic <<std::endl;
66
+
67
+    Cos->Delete();
68
+    Kernel->Delete();
69
+}

+ 345
- 0
LemmaCore/examples/dipolefreqsweep.cpp View File

@@ -0,0 +1,345 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API.
2
+ * More information is available at http://lemmasoftware.org
3
+ */
4
+
5
+/* This Source Code Form is subject to the terms of the Mozilla Public
6
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
7
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
+ */
9
+
10
+/**
11
+ * @file
12
+ * @date      01/29/2014 09:53:49 PM
13
+ * @version   $Id$
14
+ * @author    Trevor Irons (ti)
15
+ * @email     Trevor.Irons@xri-geo.com
16
+ * @copyright Copyright (c) 2014, XRI Geophysics, LLC
17
+ * @copyright Copyright (c) 2014, Trevor Irons
18
+ */
19
+
20
+#include <iostream>
21
+#include <fstream>
22
+#include "dipolesource.h"
23
+#include "layeredearthem.h"
24
+#include "receiverpoints.h"
25
+#include "emearth1d.h"
26
+
27
+#ifdef LEMMAUSEOMP
28
+#include "omp.h"
29
+#endif
30
+
31
+// For testing purposes disable VTK and run scale.sh
32
+//#undef LEMMAUSEVTK
33
+//#undef KIHALEE_EM1D
34
+
35
+#ifdef LEMMAUSEVTK
36
+#include "vtkRenderer.h"
37
+#include "vtkRenderWindow.h"
38
+#include "vtkRenderWindowInteractor.h"
39
+#include "vtkDoubleArray.h"
40
+#include "vtkXYPlotActor.h"
41
+#include "vtkXYPlotWidget.h"
42
+#include "vtkProperty2D.h"
43
+#endif
44
+
45
+#include "timer.h"
46
+
47
+using namespace Lemma;
48
+
49
+int main() {
50
+
51
+    // Do calculation
52
+    jsw_timer timer;
53
+
54
+    DipoleSource *dipole = DipoleSource::New();
55
+    dipole->SetType(MAGNETICDIPOLE);
56
+        dipole->SetPolarisation(0., 0.0,  1.0);
57
+        //dipole->SetPolarisation(XPOLARISATION);
58
+        //dipole->SetPolarisation(YPOLARISATION);
59
+        //dipole->SetPolarisation(ZPOLARISATION);
60
+
61
+        //dipole->SetMoment(1);
62
+        //dipole->SetLocation(1,1,-.0100328);
63
+        dipole->SetLocation(0., 0., -0.001);
64
+        //dipole->SetLocation(-2.5,1.25,0);
65
+        int iif=10000;
66
+        dipole->SetNumberOfFrequencies(iif);
67
+        Real w0 = 10;
68
+        for (int iw=0; iw<iif; ++iw) {
69
+            dipole->SetFrequency(iw, w0);
70
+            w0 += 1523.;
71
+        }
72
+
73
+    VectorXcr sigma(8);
74
+    sigma << 0., 3e-4, 5e-4, 1e-2, .5, 5e-6, .03, .04;
75
+    VectorXr  thick(6);
76
+        thick << 10 , 10 , 10 , 10 , 10 , 10;
77
+
78
+    LayeredEarthEM *earth = LayeredEarthEM::New();
79
+        earth->SetNumberOfLayers(8);
80
+        earth->SetLayerConductivity(sigma);
81
+        earth->SetLayerThickness(thick);
82
+
83
+    ReceiverPoints *receivers = ReceiverPoints::New();
84
+        Vector3r loc;
85
+        receivers->SetNumberOfReceivers(1);
86
+        loc << 150, 175, -.01;
87
+        receivers->SetLocation(0, loc);
88
+
89
+    // EmEarth
90
+    EMEarth1D  *EmEarth = EMEarth1D::New();
91
+        EmEarth->AttachDipoleSource(dipole);
92
+        EmEarth->AttachLayeredEarthEM(earth);
93
+        EmEarth->AttachReceiverPoints(receivers);
94
+        //EmEarth->SetFieldsToCalculate(BOTH);
95
+        EmEarth->SetFieldsToCalculate(H);
96
+
97
+        //EmEarth->SetHankelTransformMethod(GAUSSIANQUADRATURE);
98
+        //EmEarth->SetHankelTransformMethod(DIGITALFILTERING);
99
+        //EmEarth->SetHankelTransformMethod(FHTKEY201);
100
+        EmEarth->SetHankelTransformMethod(QWEKEY);
101
+
102
+    timer.begin();
103
+    EmEarth->MakeCalc3();
104
+    //std::cout << "H\n" << receivers->GetHfield(0)
105
+    //          << "End of H" << std::endl;
106
+    Real  lemmaTime = timer.end();
107
+    //std::cout << receivers->GetHfield() << std::endl;
108
+    std::cout << lemmaTime << "\t";
109
+
110
+    #ifdef LEMMAUSEVTK
111
+    vtkDataObject *_dataObjectxr = receivers->GetVtkDataObjectFreq(HFIELDREAL, 0,
112
+                    0, iif, XCOMPONENT, dipole->GetFrequencies());
113
+
114
+    vtkDataObject *_dataObjectxi = receivers->GetVtkDataObjectFreq(HFIELDIMAG, 0,
115
+                    0, iif, XCOMPONENT, dipole->GetFrequencies());
116
+
117
+    vtkDataObject *_dataObjectyr= receivers->GetVtkDataObjectFreq(HFIELDREAL, 0,
118
+                    0, iif, YCOMPONENT, dipole->GetFrequencies());
119
+
120
+    vtkDataObject *_dataObjectyi = receivers->GetVtkDataObjectFreq(HFIELDIMAG, 0,
121
+                    0, iif, YCOMPONENT, dipole->GetFrequencies());
122
+
123
+    vtkDataObject *_dataObjectzr = receivers->GetVtkDataObjectFreq(HFIELDREAL, 0,
124
+                    0, iif, ZCOMPONENT, dipole->GetFrequencies());
125
+
126
+    vtkDataObject *_dataObjectzi = receivers->GetVtkDataObjectFreq(HFIELDIMAG, 0,
127
+                    0, iif, ZCOMPONENT, dipole->GetFrequencies());
128
+    #endif
129
+
130
+
131
+//     //dipole->SetPolarisation(XPOLARISATION);
132
+//     //std::cout << "Fortran Calc" << std::endl;
133
+//     #ifdef KIHALEE_EM1D
134
+//     timer.begin();
135
+//     EmEarth->MakeCalc();
136
+//     Real fortranTime = timer.end();
137
+//     std::cout << fortranTime << "\t";
138
+//     std::cout << fortranTime/lemmaTime << std::endl;
139
+//     #endif
140
+
141
+//     #ifdef LEMMAUSEVTK
142
+//     vtkDataObject *_fdataObjectxr = receivers->GetVtkDataObjectFreq(HFIELDREAL, 0,
143
+//                     0, receivers->GetNumberOfReceivers(), XCOMPONENT, dipole->GetFrequencies());
144
+//
145
+//     vtkDataObject *_fdataObjectxi = receivers->GetVtkDataObjectFreq(HFIELDIMAG, 0,
146
+//                     0, receivers->GetNumberOfReceivers(), XCOMPONENT, dipole->GetFrequencies());
147
+//
148
+//     vtkDataObject *_fdataObjectyr = receivers->GetVtkDataObjectFreq(HFIELDREAL, 0,
149
+//                     0, receivers->GetNumberOfReceivers(), YCOMPONENT, dipole->GetFrequencies());
150
+//
151
+//     vtkDataObject *_fdataObjectyi = receivers->GetVtkDataObjectFreq(HFIELDIMAG, 0,
152
+//                     0, receivers->GetNumberOfReceivers(), YCOMPONENT, dipole->GetFrequencies());
153
+//
154
+//     vtkDataObject *_fdataObjectzr = receivers->GetVtkDataObjectFreq(HFIELDREAL, 0,
155
+//                     0, receivers->GetNumberOfReceivers(), ZCOMPONENT, dipole->GetFrequencies());
156
+//
157
+//     vtkDataObject *_fdataObjectzi = receivers->GetVtkDataObjectFreq(HFIELDIMAG, 0,
158
+//                     0, receivers->GetNumberOfReceivers(), ZCOMPONENT, dipole->GetFrequencies());
159
+//     #endif
160
+
161
+
162
+    #ifdef LEMMAUSEVTK
163
+    vtkRenderer *_ren = vtkRenderer::New();
164
+    vtkRenderWindow *_renwin = vtkRenderWindow::New();
165
+    _renwin->AddRenderer(_ren);
166
+
167
+    ///////////////////////////////////////////////
168
+    // X Component Plot
169
+    vtkXYPlotActor *_xplot = vtkXYPlotActor::New();
170
+    //vtkXYPlotWidget *_wplot = vtkXYPlotWidget::New();
171
+        // Add the datasets
172
+        _xplot->AddDataObjectInput( _dataObjectxr);
173
+        _xplot->AddDataObjectInput( _dataObjectxi);
174
+        //_xplot->AddDataObjectInput(_fdataObjectxr);
175
+        //_xplot->AddDataObjectInput(_fdataObjectxi);
176
+        _xplot->SetTitle("X field");
177
+        _xplot->SetXTitle("Depth");
178
+        _xplot->SetYTitle("E Field");
179
+        _xplot->SetXValuesToValue();
180
+        //_plot->SetXValuesToIndex();
181
+
182
+        // set which parts of the data object are to be used for which axis
183
+        _xplot->SetDataObjectXComponent(0,1);
184
+        _xplot->SetDataObjectYComponent(0,0);
185
+        _xplot->SetDataObjectXComponent(1,1);
186
+        _xplot->SetDataObjectYComponent(1,0);
187
+        _xplot->SetDataObjectXComponent(2,1);
188
+        _xplot->SetDataObjectYComponent(2,0);
189
+        _xplot->SetDataObjectXComponent(3,1);
190
+        _xplot->SetDataObjectYComponent(3,0);
191
+        _xplot->SetNumberOfXLabels(3);
192
+        _xplot->SetPlotColor(0,1,1,1);
193
+        _xplot->SetPlotColor(1,1,1,1);
194
+        _xplot->SetPlotColor(2,1,0,0);
195
+        _xplot->SetPlotColor(3,1,0,0);
196
+        _xplot->GetProperty()->SetLineWidth(2);
197
+        _xplot->GetProperty()->SetPointSize(4);
198
+
199
+        //  _plot->SetPlotPoints(0,0);
200
+        //  _plot->SetPlotPoints(1,0);
201
+        //  _plot->SetPlotPoints(2,0);
202
+        //  _plot->SetPlotPoints(3,0);
203
+
204
+        //  _plot->SetPlotLines(0,0);
205
+        //  _plot->SetPlotLines(1,0);
206
+        //  _plot->SetPlotLines(2,0);
207
+        //  _plot->SetPlotLines(3,0);
208
+
209
+        _xplot->PlotCurvePointsOff();
210
+        _xplot->PlotCurveLinesOff();
211
+        _xplot->GetPositionCoordinate()->SetValue(0.0, 0.67, 0);
212
+        _xplot->GetPosition2Coordinate()->SetValue(1.0, 0.33, 0);
213
+        //_plot->SetReverseYAxis(1); // Just flips axis, not data!
214
+
215
+    ///////////////////////////////////////////////
216
+    // Y Component Plot
217
+    vtkXYPlotActor *_yplot = vtkXYPlotActor::New();
218
+    //vtkXYPlotWidget *_wplot = vtkXYPlotWidget::New();
219
+        // Add the datasets
220
+        _yplot->AddDataObjectInput( _dataObjectyr);
221
+        _yplot->AddDataObjectInput( _dataObjectyi);
222
+        //_yplot->AddDataObjectInput(_fdataObjectyr);
223
+        //_yplot->AddDataObjectInput(_fdataObjectyi);
224
+        _yplot->SetTitle("Y field");
225
+        _yplot->SetXTitle("Depth");
226
+        _yplot->SetYTitle("E Field");
227
+        _yplot->SetXValuesToValue();
228
+        //_yplot->SetXValuesToIndex();
229
+
230
+        // set which parts of the data object are to be used for which axis
231
+        _yplot->SetDataObjectXComponent(0,1);
232
+        _yplot->SetDataObjectYComponent(0,0);
233
+        _yplot->SetDataObjectXComponent(1,1);
234
+        _yplot->SetDataObjectYComponent(1,0);
235
+        _yplot->SetDataObjectXComponent(2,1);
236
+        _yplot->SetDataObjectYComponent(2,0);
237
+        _yplot->SetDataObjectXComponent(3,1);
238
+        _yplot->SetDataObjectYComponent(3,0);
239
+        _yplot->SetNumberOfXLabels(3);
240
+        _yplot->SetPlotColor(0,1,1,1);
241
+        _yplot->SetPlotColor(1,1,1,1);
242
+        _yplot->SetPlotColor(2,1,0,0);
243
+        _yplot->SetPlotColor(3,1,0,0);
244
+        _yplot->GetProperty()->SetLineWidth(2);
245
+        _yplot->GetProperty()->SetPointSize(4);
246
+        _yplot->GetPositionCoordinate()->SetValue(0.00, 0.33, 0);
247
+        _yplot->GetPosition2Coordinate()->SetValue(1.0, 0.33, 0);
248
+
249
+        //  _plot->SetPlotPoints(0,0);
250
+        //  _plot->SetPlotPoints(1,0);
251
+        //  _plot->SetPlotPoints(2,0);
252
+        //  _plot->SetPlotPoints(3,0);
253
+
254
+        //  _plot->SetPlotLines(0,0);
255
+        //  _plot->SetPlotLines(1,0);
256
+        //  _plot->SetPlotLines(2,0);
257
+        //  _plot->SetPlotLines(3,0);
258
+
259
+        _yplot->PlotCurvePointsOff();
260
+        _yplot->PlotCurveLinesOff();
261
+        //_plot->SetReverseYAxis(1)
262
+
263
+    ///////////////////////////////////////////////
264
+    // Z Component Plot
265
+    vtkXYPlotActor *_zplot = vtkXYPlotActor::New();
266
+    //vtkXYPlotWidget *_wplot = vtkXYPlotWidget::New();
267
+        // Add the datasets
268
+        _zplot->AddDataObjectInput( _dataObjectzr);
269
+        _zplot->AddDataObjectInput( _dataObjectzi);
270
+        //_zplot->AddDataObjectInput(_fdataObjectzr);
271
+        //_zplot->AddDataObjectInput(_fdataObjectzi);
272
+        _zplot->SetTitle("Z field");
273
+        _zplot->SetXTitle("Depth");
274
+        _zplot->SetYTitle("E Field");
275
+        _zplot->SetXValuesToValue();
276
+        //_plot->SetXValuesToIndex();
277
+
278
+        // set which parts of the data object are to be used for which axis
279
+        _zplot->SetDataObjectXComponent(0,1);
280
+        _zplot->SetDataObjectYComponent(0,0);
281
+        _zplot->SetDataObjectXComponent(1,1);
282
+        _zplot->SetDataObjectYComponent(1,0);
283
+        _zplot->SetDataObjectXComponent(2,1);
284
+        _zplot->SetDataObjectYComponent(2,0);
285
+        _zplot->SetDataObjectXComponent(3,1);
286
+        _zplot->SetDataObjectYComponent(3,0);
287
+        _zplot->SetNumberOfXLabels(3);
288
+        _zplot->SetPlotColor(0,1,1,1);
289
+        _zplot->SetPlotColor(1,1,1,1);
290
+        _zplot->SetPlotColor(2,1,0,0);
291
+        _zplot->SetPlotColor(3,1,0,0);
292
+        _zplot->GetProperty()->SetLineWidth(2);
293
+        _zplot->GetProperty()->SetPointSize(4);
294
+        _zplot->GetPositionCoordinate()->SetValue(0.0, 0.0, 0);
295
+        _zplot->GetPosition2Coordinate()->SetValue(1.0, 0.33, 0);
296
+        //  _plot->SetPlotPoints(0,0);
297
+        //  _plot->SetPlotPoints(1,0);
298
+        //  _plot->SetPlotPoints(2,0);
299
+        //  _plot->SetPlotPoints(3,0);
300
+
301
+        //  _plot->SetPlotLines(0,0);
302
+        //  _plot->SetPlotLines(1,0);
303
+        //  _plot->SetPlotLines(2,0);
304
+        //  _plot->SetPlotLines(3,0);
305
+
306
+        _zplot->PlotCurvePointsOff();
307
+        _zplot->PlotCurveLinesOff();
308
+        //_plot->SetReverseYAxis(1)
309
+
310
+    _ren->AddActor2D(_xplot);
311
+    _ren->AddActor2D(_yplot);
312
+    _ren->AddActor2D(_zplot);
313
+
314
+    vtkRenderWindowInteractor *_iren = vtkRenderWindowInteractor::New();
315
+    _iren->SetRenderWindow(_renwin);
316
+    _iren->Initialize();
317
+    _renwin->Render();
318
+
319
+    //_wplot->SetXYPlotActor(_plot);
320
+    //_wplot->SetInteractor(_iren);
321
+    //_wplot->EnabledOn();
322
+
323
+    _iren->Start();
324
+
325
+    // TODO clean up you dirty whore
326
+//  _iren->Delete();
327
+//  _plot->Delete();
328
+//  _dataObject->Delete();
329
+//  _fieldData->Delete();
330
+//  _renwin->Delete();
331
+//  _ren->Delete();
332
+//  _xdatareal->Delete();
333
+//  _ydata->Delete();
334
+//  _depth->Delete();
335
+    #endif
336
+
337
+    EmEarth->Delete();
338
+    receivers->Delete();
339
+    earth->Delete();
340
+    dipole->Delete();
341
+
342
+    return 0;
343
+
344
+
345
+}

+ 504
- 0
LemmaCore/examples/dipolesource.cpp View File

@@ -0,0 +1,504 @@
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
+
34
+#include <iostream>
35
+#include <fstream>
36
+#include "dipolesource.h"
37
+#include "layeredearthem.h"
38
+#include "receiverpoints.h"
39
+#include "emearth1d.h"
40
+
41
+#ifdef LEMMAUSEOMP
42
+#include "omp.h"
43
+#endif
44
+
45
+// For testing purposes disable VTK and run scale.sh
46
+#undef LEMMAUSEVTK
47
+#undef KIHALEE_EM1D
48
+
49
+#ifdef LEMMAUSEVTK
50
+#include "vtkRenderer.h"
51
+#include "vtkRenderWindow.h"
52
+#include "vtkRenderWindowInteractor.h"
53
+#include "vtkDoubleArray.h"
54
+#include "vtkXYPlotActor.h"
55
+#include "vtkXYPlotWidget.h"
56
+#include "vtkProperty2D.h"
57
+#endif
58
+
59
+#include "timer.h"
60
+
61
+using namespace Lemma;
62
+
63
+int main() {
64
+
65
+    //////////////////
66
+    // TODO List of Dipole settings that aren't working
67
+
68
+    // Do calculation
69
+    jsw_timer timer;
70
+    timer.begin();
71
+
72
+    // Test with a single dipole
73
+    DipoleSource *dipole = DipoleSource::New();
74
+        //dipole->SetMoment(2);
75
+        ///////////////////////////////////
76
+        // E field Tests
77
+        // Sems to be working!
78
+        //dipole->SetType(GROUNDEDELECTRICDIPOLE);
79
+        //dipole->SetPolarisation(XPOLARISATION);
80
+        //dipole->SetPolarisation(YPOLARISATION);
81
+        //dipole->SetPolarisation(ZPOLARISATION);
82
+        //dipole->SetAzimuth(0);  // X - Northing
83
+        //dipole->SetAzimuth(90); // Y - Easting
84
+
85
+        dipole->SetType(GROUNDEDELECTRICDIPOLE);
86
+            //dipole->SetPolarisation(1., 0.0,  1.0);
87
+        //    dipole->SetPolarisation(XPOLARISATION);
88
+        dipole->SetPolarisation(YPOLARISATION);
89
+        //dipole->SetPolarisation(ZPOLARISATION);
90
+
91
+        /////////////
92
+        //dipole->SetType(MAGNETICDIPOLE);
93
+            //dipole->SetPolarisation(0., 0.0,  1.0);
94
+            //dipole->SetPolarisation(XPOLARISATION);
95
+        //dipole->SetPolarisation(YPOLARISATION);
96
+        //dipole->SetPolarisation(ZPOLARISATION);
97
+
98
+        //dipole->SetMoment(1);
99
+        //dipole->SetLocation(1,1,-.0100328);
100
+        dipole->SetLocation(0., 0., -0.001);
101
+        //dipole->SetLocation(-2.5,1.25,0);
102
+        dipole->SetNumberOfFrequencies(1);
103
+        dipole->SetFrequency(0, 2e7);
104
+        //dipole->SetFrequency(1,2000);
105
+        //dipole->SetPhase(0);
106
+
107
+        //////////////////////////////////
108
+        // H field Tests
109
+
110
+//     // Define model, this is a difficult case
111
+//     VectorXcr sigma(23);
112
+//         sigma << 0., 0.0625, 0.0166666666666667, 0.04, 0.0181818181818182,
113
+//                 0.05, 0.0222222222222222, 0.2, 0.025, 0.05, 0.025,
114
+//             0.05, 0.00833333333333333, 0.025, 0.05, 0.0222222222222222,
115
+//             0.0277777777777778, 0.0333333333333333, 0.0208333333333333,
116
+//             0.0181818181818182, 0.025, 0.04;
117
+//
118
+//     VectorXr  thick(21);
119
+//         //thick << 10, 10, 10, 10, 10, 10;
120
+//         thick << 11, 5, 5, 4, 3.5, 4.5, 4.5,
121
+//                  5.5, 3, 36, 15, 3, 6, 3, 8,
122
+//                  9, 10, 7, 8, 11, 68;
123
+
124
+    //VectorXcr sigma(8);
125
+    //    sigma << 0., Complex(.01,0.01), 0.001, .005, .0034, .0023, .0024, .0001;
126
+
127
+    VectorXcr sigma(8);
128
+        sigma << 0., 3e-4, 5e-4, 1e-2, .5, 5e-6, .03, .04;
129
+    //VectorXcr sigma(2);
130
+    //    sigma << 0., .0;
131
+    //VectorXr susl(3);
132
+    //    susl << 1., 1., 1.5;//, 5e-6, 5e-6, 5e-6;
133
+    //VectorXr sush(3);
134
+    //    sush << 1., 1.01;//, 5e-6, 5e-6, 5e-6;
135
+    //VectorXr sustau(2);
136
+    //    sustau << 1., 1.0;//, 5e-6, 5e-6, 5e-6;
137
+    //VectorXr susb(2);
138
+    //    susb << 0., .0;//, 5e-6, 5e-6, 5e-6;
139
+    VectorXr  thick(6);
140
+        thick << 10 , 10 , 10 , 10 , 10 , 10;
141
+
142
+    LayeredEarthEM *earth = LayeredEarthEM::New();
143
+        earth->SetNumberOfLayers(8);
144
+        //earth->SetNumberOfLayers(23);
145
+        earth->SetLayerConductivity(sigma);
146
+        //earth->SetLayerLowFreqSusceptibility(susl);
147
+        //earth->SetLayerHighFreqSusceptibility(sush);
148
+        //earth->SetLayerTauSusceptibility(sustau);
149
+        //earth->SetLayerBreathSusceptibility(susb);
150
+        //earth->SetLayerHighFreqSusceptibility(susl);
151
+        //earth->SetLayerHighFreqSusceptibility(susl);
152
+        earth->SetLayerThickness(thick);
153
+
154
+    // just a test
155
+    timer.end();
156
+
157
+    // Receivers
158
+    ReceiverPoints *receivers = ReceiverPoints::New();
159
+        Vector3r loc;
160
+        Real ox     =  50.;
161
+        Real oy     =  70. ;
162
+        Real depth  =  -40.13423;
163
+        Real depth2 =  depth;
164
+        Real dz     =  .25;
165
+        int  nz     =  3000;
166
+        Real dx     = .0;
167
+        receivers->SetNumberOfReceivers(nz);
168
+        int ir = 0;
169
+        for (int iz=0; iz<nz; ++iz) {
170
+            loc << ox, oy, depth;
171
+            receivers->SetLocation(ir, loc);
172
+            depth += dz;
173
+            ox += dx;
174
+            ++ ir;
175
+        }
176
+
177
+    // EmEarth
178
+    EMEarth1D  *EmEarth = EMEarth1D::New();
179
+        EmEarth->AttachDipoleSource(dipole);
180
+        EmEarth->AttachLayeredEarthEM(earth);
181
+        EmEarth->AttachReceiverPoints(receivers);
182
+        //EmEarth->SetFieldsToCalculate(BOTH);
183
+        EmEarth->SetFieldsToCalculate(H);
184
+
185
+        //EmEarth->SetHankelTransformMethod(GAUSSIANQUADRATURE);
186
+        //EmEarth->SetHankelTransformMethod(DIGITALFILTERING);
187
+        //EmEarth->SetHankelTransformMethod(FHTKEY201);
188
+        //EmEarth->SetHankelTransformMethod(QWEKEY);
189
+        EmEarth->SetHankelTransformMethod(FHTKEY51);
190
+
191
+    timer.begin();
192
+    EmEarth->MakeCalc3();
193
+    //std::cout << "H\n" << receivers->GetHfield(0)
194
+    //          << "End of H" << std::endl;
195
+    Real  lemmaTime = timer.end();
196
+    std::cout << lemmaTime << "\t";
197
+
198
+    //std::cout << "Make Calc3\n";
199
+    //receivers->ClearFields();
200
+
201
+    //EmEarth->MakeCalc3();
202
+    //std::cout << "Make Calc3 finished\n";
203
+
204
+    #ifdef LEMMAUSEVTK
205
+    int iif=0;
206
+    vtkDataObject *_dataObjectxr = receivers->GetVtkDataObject(HFIELDREAL, iif,
207
+                    0, receivers->GetNumberOfReceivers(), XCOMPONENT, ZCOORD);
208
+
209
+    vtkDataObject *_dataObjectxi = receivers->GetVtkDataObject(HFIELDIMAG, iif,
210
+                    0, receivers->GetNumberOfReceivers(), XCOMPONENT, ZCOORD);
211
+
212
+    vtkDataObject *_dataObjectyr= receivers->GetVtkDataObject(HFIELDREAL, iif,
213
+                    0, receivers->GetNumberOfReceivers(), YCOMPONENT, ZCOORD);
214
+
215
+    vtkDataObject *_dataObjectyi = receivers->GetVtkDataObject(HFIELDIMAG, iif,
216
+                    0, receivers->GetNumberOfReceivers(), YCOMPONENT, ZCOORD);
217
+
218
+    vtkDataObject *_dataObjectzr = receivers->GetVtkDataObject(HFIELDREAL, iif,
219
+                    0, receivers->GetNumberOfReceivers(), ZCOMPONENT, ZCOORD);
220
+
221
+    vtkDataObject *_dataObjectzi = receivers->GetVtkDataObject(HFIELDIMAG, iif,
222
+                    0, receivers->GetNumberOfReceivers(), ZCOMPONENT, ZCOORD);
223
+    #endif
224
+
225
+    /*
226
+    // Write out to file
227
+    depth = depth2;
228
+    std::fstream real("reale_lay.dat", std::ios::out);
229
+    std::fstream imag("image_lay.dat", std::ios::out);
230
+    std::fstream hreal("real_lay.dat", std::ios::out);
231
+    std::fstream himag("imag_lay.dat", std::ios::out);
232
+    for (int iz=0; iz<nz; ++iz) {
233
+        Vector3cr temp = receivers->GetEfield(0,iz);
234
+
235
+        //std::cout << temp << endl;
236
+        real << ox << "\t" << oy << "\t" << depth << "\t"
237
+                << temp(0).real() << "\t" << temp(1).real()
238
+                << "\t" << temp(2).real() << std::endl;
239
+
240
+        imag << ox << "\t" << oy << "\t" << depth << "\t"
241
+                << std::imag(temp(0)) << "\t" << std::imag(temp(1))
242
+                << "\t" << std::imag(temp(2)) << std::endl;
243
+
244
+        temp = receivers->GetHfield(0, iz);
245
+
246
+        hreal << ox << "\t" << oy << "\t" << depth << "\t"
247
+                << std::real(temp(0)) << "\t" << std::real(temp(1))
248
+                << "\t" << std::real(temp(2)) << std::endl;
249
+        himag << ox << "\t" << oy << "\t" << depth << "\t"
250
+                << std::imag(temp(0)) << "\t" << std::imag(temp(1))
251
+                << "\t" << std::imag(temp(2)) << std::endl;
252
+        depth += dz;
253
+    }
254
+    real.close();
255
+    imag.close();
256
+    */
257
+
258
+    // TODO check all field components for both E and H,
259
+    // diplay in some sort of reasonable manner.
260
+    // Then, and only then, optimise.
261
+
262
+    receivers->ClearFields();
263
+
264
+    //dipole->SetPolarisation(XPOLARISATION);
265
+    //std::cout << "Fortran Calc" << std::endl;
266
+    #ifdef KIHALEE_EM1D
267
+    timer.begin();
268
+    EmEarth->MakeCalc();
269
+    Real fortranTime = timer.end();
270
+    std::cout << fortranTime << "\t";
271
+    std::cout << fortranTime/lemmaTime << std::endl;
272
+    #endif
273
+
274
+    #ifdef LEMMAUSEVTK
275
+    vtkDataObject *_fdataObjectxr = receivers->GetVtkDataObject(HFIELDREAL, 0,
276
+                    0, receivers->GetNumberOfReceivers(), XCOMPONENT, ZCOORD);
277
+
278
+    vtkDataObject *_fdataObjectxi = receivers->GetVtkDataObject(HFIELDIMAG, 0,
279
+                    0, receivers->GetNumberOfReceivers(), XCOMPONENT, ZCOORD);
280
+
281
+    vtkDataObject *_fdataObjectyr = receivers->GetVtkDataObject(HFIELDREAL, 0,
282
+                    0, receivers->GetNumberOfReceivers(), YCOMPONENT, ZCOORD);
283
+
284
+    vtkDataObject *_fdataObjectyi = receivers->GetVtkDataObject(HFIELDIMAG, 0,
285
+                    0, receivers->GetNumberOfReceivers(), YCOMPONENT, ZCOORD);
286
+
287
+    vtkDataObject *_fdataObjectzr = receivers->GetVtkDataObject(HFIELDREAL, 0,
288
+                    0, receivers->GetNumberOfReceivers(), ZCOMPONENT, ZCOORD);
289
+
290
+    vtkDataObject *_fdataObjectzi = receivers->GetVtkDataObject(HFIELDIMAG, 0,
291
+                    0, receivers->GetNumberOfReceivers(), ZCOMPONENT, ZCOORD);
292
+    #endif
293
+
294
+    // Simple 2D plot in vtk to compare algorithms
295
+    #ifdef LEMMAUSEVTK
296
+    vtkRenderer *_ren = vtkRenderer::New();
297
+    vtkRenderWindow *_renwin = vtkRenderWindow::New();
298
+        _renwin->AddRenderer(_ren);
299
+
300
+    ///////////////////////////////////////////////
301
+    // X Component Plot
302
+    vtkXYPlotActor *_xplot = vtkXYPlotActor::New();
303
+    //vtkXYPlotWidget *_wplot = vtkXYPlotWidget::New();
304
+        // Add the datasets
305
+        _xplot->AddDataObjectInput( _dataObjectxr);
306
+        _xplot->AddDataObjectInput( _dataObjectxi);
307
+        _xplot->AddDataObjectInput(_fdataObjectxr);
308
+        _xplot->AddDataObjectInput(_fdataObjectxi);
309
+        _xplot->SetTitle("H_x");
310
+        _xplot->SetXTitle("");
311
+        _xplot->SetYTitle("");
312
+        _xplot->SetXValuesToValue();
313
+        //_plot->SetXValuesToIndex();
314
+
315
+        // set which parts of the data object are to be used for which axis
316
+        _xplot->SetDataObjectXComponent(0,1);
317
+        _xplot->SetDataObjectYComponent(0,0);
318
+        _xplot->SetDataObjectXComponent(1,1);
319
+        _xplot->SetDataObjectYComponent(1,0);
320
+        _xplot->SetDataObjectXComponent(2,1);
321
+        _xplot->SetDataObjectYComponent(2,0);
322
+        _xplot->SetDataObjectXComponent(3,1);
323
+        _xplot->SetDataObjectYComponent(3,0);
324
+        _xplot->SetNumberOfXLabels(3);
325
+
326
+        _xplot->SetPlotColor(0,1,1,1);
327
+        _xplot->SetPlotColor(1,0,0,1);
328
+
329
+        _xplot->SetPlotColor(2,1,0,0);
330
+        _xplot->SetPlotColor(3,0,1,0);
331
+
332
+        _xplot->SetPlotLabel(0, "Lemma real" );
333
+        _xplot->SetPlotLabel(1, "Lemma imag" );
334
+        _xplot->SetPlotLabel(2, "KiHa real" );
335
+        _xplot->SetPlotLabel(3, "KiHa imag" );
336
+
337
+        _xplot->GetProperty()->SetLineWidth(1);
338
+        _xplot->GetProperty()->SetPointSize(22);
339
+
340
+        _xplot->LegendOn();
341
+        //  _plot->SetPlotPoints(0,0);
342
+        //  _plot->SetPlotPoints(1,0);
343
+        //  _plot->SetPlotPoints(2,0);
344
+        //  _plot->SetPlotPoints(3,0);
345
+
346
+        //  _plot->SetPlotLines(0,0);
347
+        //  _plot->SetPlotLines(1,0);
348
+        //  _plot->SetPlotLines(2,0);
349
+        //  _plot->SetPlotLines(3,0);
350
+
351
+        _xplot->PlotCurvePointsOff();
352
+        _xplot->PlotCurveLinesOff();
353
+        _xplot->GetPositionCoordinate()->SetValue(0.0, 0.67, 0);
354
+        _xplot->GetPosition2Coordinate()->SetValue(1.0, 0.33, 0);
355
+        //_plot->SetReverseYAxis(1); // Just flips axis, not data!
356
+
357
+    ///////////////////////////////////////////////
358
+    // Y Component Plot
359
+    vtkXYPlotActor *_yplot = vtkXYPlotActor::New();
360
+    //vtkXYPlotWidget *_wplot = vtkXYPlotWidget::New();
361
+        // Add the datasets
362
+        _yplot->AddDataObjectInput( _dataObjectyr);
363
+        _yplot->AddDataObjectInput( _dataObjectyi);
364
+        _yplot->AddDataObjectInput(_fdataObjectyr);
365
+        _yplot->AddDataObjectInput(_fdataObjectyi);
366
+        _yplot->SetTitle("H_y");
367
+        _yplot->SetXTitle("");
368
+        _yplot->SetYTitle("");
369
+        _yplot->SetXValuesToValue();
370
+        //_yplot->SetXValuesToIndex();
371
+
372
+        // set which parts of the data object are to be used for which axis
373
+        _yplot->SetDataObjectXComponent(0,1);
374
+        _yplot->SetDataObjectYComponent(0,0);
375
+        _yplot->SetDataObjectXComponent(1,1);
376
+        _yplot->SetDataObjectYComponent(1,0);
377
+        _yplot->SetDataObjectXComponent(2,1);
378
+        _yplot->SetDataObjectYComponent(2,0);
379
+        _yplot->SetDataObjectXComponent(3,1);
380
+        _yplot->SetDataObjectYComponent(3,0);
381
+        _yplot->SetNumberOfXLabels(3);
382
+
383
+        _yplot->SetPlotColor(0,1,1,1);
384
+        _yplot->SetPlotColor(1,0,0,1);
385
+
386
+        _yplot->SetPlotColor(2,1,0,0);
387
+        _yplot->SetPlotColor(3,0,1,0);
388
+
389
+        _yplot->SetPlotLabel(0, "Lemma real" );
390
+        _yplot->SetPlotLabel(1, "Lemma imag" );
391
+        _yplot->SetPlotLabel(2, "KiHa real" );
392
+        _yplot->SetPlotLabel(3, "KiHa imag" );
393
+        _yplot->LegendOn();
394
+
395
+        _yplot->GetProperty()->SetLineWidth(1);
396
+        _yplot->GetProperty()->SetPointSize(12);
397
+        _yplot->GetPositionCoordinate()->SetValue(0.00, 0.33, 0);
398
+        _yplot->GetPosition2Coordinate()->SetValue(1.0, 0.33, 0);
399
+
400
+        //  _plot->SetPlotPoints(0,0);
401
+        //  _plot->SetPlotPoints(1,0);
402
+        //  _plot->SetPlotPoints(2,0);
403
+        //  _plot->SetPlotPoints(3,0);
404
+
405
+        //  _plot->SetPlotLines(0,0);
406
+        //  _plot->SetPlotLines(1,0);
407
+        //  _plot->SetPlotLines(2,0);
408
+        //  _plot->SetPlotLines(3,0);
409
+
410
+        _yplot->PlotCurvePointsOff();
411
+        _yplot->PlotCurveLinesOff();
412
+        //_plot->SetReverseYAxis(1)
413
+
414
+    ///////////////////////////////////////////////
415
+    // Z Component Plot
416
+    vtkXYPlotActor *_zplot = vtkXYPlotActor::New();
417
+    //vtkXYPlotWidget *_wplot = vtkXYPlotWidget::New();
418
+        // Add the datasets
419
+        _zplot->AddDataObjectInput( _dataObjectzr);
420
+        _zplot->AddDataObjectInput( _dataObjectzi);
421
+        _zplot->AddDataObjectInput(_fdataObjectzr);
422
+        _zplot->AddDataObjectInput(_fdataObjectzi);
423
+        _zplot->SetTitle("H_z");
424
+        _zplot->SetXTitle("Depth");
425
+        _zplot->SetYTitle("");
426
+        _zplot->SetXValuesToValue();
427
+        //_plot->SetXValuesToIndex();
428
+
429
+        // set which parts of the data object are to be used for which axis
430
+        _zplot->SetDataObjectXComponent(0,1);
431
+        _zplot->SetDataObjectYComponent(0,0);
432
+        _zplot->SetDataObjectXComponent(1,1);
433
+        _zplot->SetDataObjectYComponent(1,0);
434
+        _zplot->SetDataObjectXComponent(2,1);
435
+        _zplot->SetDataObjectYComponent(2,0);
436
+        _zplot->SetDataObjectXComponent(3,1);
437
+        _zplot->SetDataObjectYComponent(3,0);
438
+        _zplot->SetNumberOfXLabels(3);
439
+
440
+        _zplot->SetPlotColor(0,1,1,1);
441
+        _zplot->SetPlotColor(1,0,0,1);
442
+
443
+        _zplot->SetPlotColor(2,1,0,0);
444
+        _zplot->SetPlotColor(3,0,1,0);
445
+
446
+        _zplot->LegendOn();
447
+
448
+        _zplot->SetPlotLabel(0, "Lemma real" );
449
+        _zplot->SetPlotLabel(1, "Lemma imag" );
450
+        _zplot->SetPlotLabel(2, "KiHa real" );
451
+        _zplot->SetPlotLabel(3, "KiHa imag" );
452
+
453
+        _zplot->GetProperty()->SetLineWidth(1);
454
+        _zplot->GetProperty()->SetPointSize(14);
455
+        _zplot->GetPositionCoordinate()->SetValue(0.0, 0.0, 0);
456
+        _zplot->GetPosition2Coordinate()->SetValue(1.0, 0.33, 0);
457
+        //  _plot->SetPlotPoints(0,0);
458
+        //  _plot->SetPlotPoints(1,0);
459
+        //  _plot->SetPlotPoints(2,0);
460
+        //  _plot->SetPlotPoints(3,0);
461
+
462
+        //  _plot->SetPlotLines(0,0);
463
+        //  _plot->SetPlotLines(1,0);
464
+        //  _plot->SetPlotLines(2,0);
465
+        //  _plot->SetPlotLines(3,0);
466
+
467
+        _zplot->PlotCurvePointsOn();
468
+        _zplot->PlotCurveLinesOff();
469
+        //_plot->SetReverseYAxis(1)
470
+
471
+    _ren->AddActor2D(_xplot);
472
+    _ren->AddActor2D(_yplot);
473
+    _ren->AddActor2D(_zplot);
474
+
475
+    vtkRenderWindowInteractor *_iren = vtkRenderWindowInteractor::New();
476
+    _iren->SetRenderWindow(_renwin);
477
+    _iren->Initialize();
478
+    _renwin->Render();
479
+
480
+    //_wplot->SetXYPlotActor(_plot);
481
+    //_wplot->SetInteractor(_iren);
482
+    //_wplot->EnabledOn();
483
+
484
+    _iren->Start();
485
+
486
+    // TODO clean up you dirty whore
487
+//  _iren->Delete();
488
+//  _plot->Delete();
489
+//  _dataObject->Delete();
490
+//  _fieldData->Delete();
491
+//  _renwin->Delete();
492
+//  _ren->Delete();
493
+//  _xdatareal->Delete();
494
+//  _ydata->Delete();
495
+//  _depth->Delete();
496
+    #endif
497
+
498
+    EmEarth->Delete();
499
+    receivers->Delete();
500
+    earth->Delete();
501
+    dipole->Delete();
502
+
503
+    return 0;
504
+}

+ 231
- 0
LemmaCore/examples/edipole.cpp View File

@@ -0,0 +1,231 @@
1
+// ===========================================================================
2
+//
3
+//       Filename:  utsnmrinversion1d.cpp
4
+//
5
+//        Created:  10/07/2010 08:57:04 AM
6
+//       Compiler:  Tested with g++, icpc, and MSVC 2010
7
+//
8
+//         Author:  Trevor Irons (ti)
9
+//
10
+//   Organisation:  Colorado School of Mines (CSM)
11
+//                  United States Geological Survey (USGS)
12
+//
13
+//          Email:  tirons@mines.edu, tirons@usgs.gov
14
+//
15
+//  This program is free software: you can redistribute it and/or modify
16
+//  it under the terms of the GNU General Public License as published by
17
+//  the Free Software Foundation, either version 3 of the License, or
18
+//  (at your option) any later version.
19
+//
20
+//  This program is distributed in the hope that it will be useful,
21
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
+//  GNU General Public License for more details.
24
+//
25
+//  You should have received a copy of the GNU General Public License
26
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
27
+//
28
+// ===========================================================================
29
+
30
+/**
31
+  @file
32
+  @author   Trevor Irons
33
+  @date     10/07/2010
34
+  @version   0.0
35
+ **/
36
+
37
+#include "receiverpoints.h"
38
+#include "emearth1d.h"
39
+#include "dipolesource.h"
40
+
41
+using namespace Lemma;
42
+
43
+std::vector<Real>  readinpfile(const std::string& fname);
44
+
45
+int main(int argc, char** argv) {
46
+
47
+    std::cout <<
48
+    "\n"
49
+    << "ediple.exe Copyright (C) 2011 Broken Spoke Development, LLC\n\n"
50
+    << "This program is free software: you can redistribute it and/or modify\n"
51
+    << "it under the terms of the GNU General Public License as published by\n"
52
+    << "the Free Software Foundation, either version 3 of the License, or\n"
53
+    << "(at your option) any later version.\n\n"
54
+
55
+    << "This program is distributed in the hope that it will be useful,\n"
56
+    << "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
57
+    << "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
58
+    << "GNU General Public License for more details.\n\n"
59
+
60
+    << "You should have received a copy of the GNU General Public License\n"
61
+    << "along with this program.  If not, see <http://www.gnu.org/licenses/>.\n\n";
62
+
63
+    if (argc < 4) {
64
+        std::cout << "usage: edipole.exe  dipole.inp cond.inp points.inp \n";
65
+        exit(0);
66
+    }
67
+
68
+    std::vector<Real> Trans   = readinpfile(std::string(argv[1]));
69
+    std::vector<Real> CondMod = readinpfile(std::string(argv[2]));
70
+    std::vector<Real> Points  = readinpfile(std::string(argv[3]));
71
+
72
+    //////////////////////////////////////
73
+    // Define dipole source
74
+    DipoleSource* dipole = DipoleSource::New();
75
+        switch ( (int)(Trans[0]) ) {
76
+            case 0:
77
+                dipole->SetType(MAGNETICDIPOLE);
78
+                break;
79
+            case 1:
80
+                dipole->SetType(GROUNDEDELECTRICDIPOLE);
81
+                break;
82
+            default:
83
+                std::cerr << "Undefined dipole type, must be:\n"
84
+                     << "\t0 -> Magnetic\n"
85
+                     << "\t1 -> Grounded Electric\n";
86
+                exit(EXIT_FAILURE);
87
+        }
88
+
89
+        switch ( (int)(Trans[1]) ) {
90
+            case 0:
91
+                dipole->SetPolarisation(XPOLARISATION);
92
+                break;
93
+            case 1:
94
+                dipole->SetPolarisation(YPOLARISATION);
95
+                break;
96
+            case 2:
97
+                dipole->SetPolarisation(ZPOLARISATION);
98
+                break;
99
+            default:
100
+                std::cerr << "Undefined orientation, must be:\n"
101
+                          << "\t0 -> x\n"
102
+                          << "\t1 -> y\n"
103
+                          << "\t2 -> z\n";
104
+                exit(EXIT_FAILURE);
105
+        }
106
+        dipole->SetNumberOfFrequencies(1);
107
+        dipole->SetFrequency(0, Trans[2]);
108
+        dipole->SetLocation(Trans[3], Trans[4], Trans[5]);
109
+        dipole->SetMoment(Trans[6]);
110
+
111
+	// Receivers
112
+ 	ReceiverPoints *receivers = ReceiverPoints::New();
113
+        int nx = (int)Points[0];
114
+        int ny = (int)Points[1];
115
+        int nz = (int)Points[2];
116
+        Real ox = Points[3];
117
+        Real oy = Points[4];
118
+        Real oz = Points[5];
119
+     	Vector3r loc;
120
+        VectorXr dx(nx-1); // TODO map the dx, dy, dz vectors
121
+        VectorXr dy(ny-1);
122
+        VectorXr dz(nz-1);
123
+        int ip = 6;
124
+        int ir = 0;
125
+        for ( ; ip <6+nx-1; ++ip) {
126
+            dx[ir] = Points[ip];
127
+            ++ir;
128
+        }
129
+        ir = 0;
130
+        for ( ; ip <6+ny-1+nx-1; ++ip) {
131
+            dy[ir] = Points[ip];
132
+            ++ir;
133
+        }
134
+        ir = 0;
135
+        for ( ; ip <6+nz-1+ny-1+nx-1; ++ip) {
136
+            dz[ir] = Points[ip];
137
+            ++ir;
138
+        }
139
+ 		receivers->SetNumberOfReceivers(nx*ny*nz);
140
+ 		ir = 0;
141
+        Real pz  = oz;
142
+ 		for (int iz=0; iz<nz; ++iz) {
143
+ 		    Real py    =  oy;
144
+ 		    for (int iy=0; iy<ny; ++iy) {
145
+ 		        Real px    =  ox;
146
+ 		        for (int ix=0; ix<nx; ++ix) {
147
+ 			        loc << px, py, pz;
148
+ 			        receivers->SetLocation(ir, loc);
149
+ 			        if (ix < nx-1) px += dx[ix];
150
+ 			        ++ ir;
151
+     	        }
152
+                if (iy<ny-1) py += dy[iy];
153
+            }
154
+            if (iz<nz-1) pz += dz[iz];
155
+        }
156
+
157
+    ////////////////////////////////////
158
+    // Define model
159
+    LayeredEarthEM *earth = LayeredEarthEM::New();
160
+    VectorXcr sigma;
161
+    VectorXr  thick;
162
+ 	earth->SetNumberOfLayers(CondMod[0]+1);
163
+ 	sigma.resize(CondMod[0]+1); sigma(0) = 0; // airlayer
164
+    thick.resize(CondMod[0]-1);
165
+    int ilay=1;
166
+    for ( ; ilay/2<CondMod[0]-1; ilay+=2) {
167
+        sigma(ilay/2+1) =  1./CondMod[ilay];
168
+        thick(ilay/2) =  CondMod[ilay+1];
169
+    }
170
+    sigma(ilay/2+1) = 1./ CondMod[ilay];
171
+	earth->SetLayerConductivity(sigma);
172
+    if (thick.size() > 0) earth->SetLayerThickness(thick);
173
+
174
+	EMEarth1D  *EmEarth = EMEarth1D::New();
175
+		EmEarth->AttachDipoleSource(dipole);
176
+		EmEarth->AttachLayeredEarthEM(earth);
177
+		EmEarth->AttachReceiverPoints(receivers);
178
+		EmEarth->SetFieldsToCalculate(E);
179
+        EmEarth->MakeCalc3();
180
+
181
+    ////////////////////////////////////
182
+    // Report
183
+ 	std::fstream hreal("efield.dat", std::ios::out);
184
+    hreal << *dipole << std::endl;
185
+    hreal << *earth << std::endl;
186
+    hreal << "Right hand coordinate system, z is positive down\n\n";
187
+    hreal << "x[m]\ty[m]\tz[m]\tRe(Ex) [V/m]\t Im(Ex) [V/m]\tRe(Ey) [V/m]\tIm(Ey) [V/m]\tRe(Ez) [V/m] Im(Ez) [V/m]\n";
188
+    hreal << "\\\\ ====================================================================================================\n";
189
+    hreal.precision(8);
190
+    int i=0;
191
+	for (int iz=0; iz<nz; ++iz) {
192
+	for (int iy=0; iy<ny; ++iy) {
193
+	for (int ix=0; ix<nx; ++ix) {
194
+        hreal << receivers->GetLocation(i).transpose() << "\t";
195
+ 		hreal << std::real(receivers->GetEfield(0, i).transpose()[0]) << "\t";
196
+ 		hreal << std::imag(receivers->GetEfield(0, i).transpose()[0]) << "\t";
197
+ 		hreal << std::real(receivers->GetEfield(0, i).transpose()[1]) << "\t";
198
+ 		hreal << std::imag(receivers->GetEfield(0, i).transpose()[1]) << "\t";
199
+ 		hreal << std::real(receivers->GetEfield(0, i).transpose()[2]) << "\t";
200
+ 		hreal << std::imag(receivers->GetEfield(0, i).transpose()[2]) << "\n";
201
+        ++i;
202
+    }
203
+    }
204
+    }
205
+    hreal.close();
206
+
207
+    // Clean up
208
+    EmEarth->Delete();
209
+    earth->Delete();
210
+    receivers->Delete();
211
+    dipole->Delete();
212
+}
213
+
214
+std::vector<Real>  readinpfile(const std::string& fname) {
215
+    std::string buf;
216
+    char dump[255];
217
+    std::vector<Real> vals;
218
+    std::fstream input(fname.c_str(), std::ios::in);
219
+    if (input.fail()) {
220
+        std::cerr << "Input file " << fname << " failed to open\n";
221
+        exit(EXIT_FAILURE);
222
+    }
223
+    while (input >> buf) {
224
+        if (buf.substr(0,2) == "//") {
225
+            input.getline(dump, 255);
226
+        } else {
227
+            vals.push_back( atof(buf.c_str() ));
228
+        }
229
+    }
230
+    return vals;
231
+}

+ 141
- 0
LemmaCore/examples/emdipearth1d.cpp View File

@@ -0,0 +1,141 @@
1
+// ===========================================================================
2
+//
3
+//       Filename:  utemdipearth1d.cpp
4
+//
5
+//    Description:
6
+//
7
+//        Version:  0.0
8
+//        Created:  01/06/2010 04:27:56 PM
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 "emearth1d.h"
34
+#include "dipolesource.h"
35
+#include "layeredearthem.h"
36
+#include "receiverpoints.h"
37
+
38
+using namespace Lemma;
39
+
40
+int main() {
41
+
42
+	// Test with a single dipole
43
+	DipoleSource *dipole = DipoleSource::New();
44
+		dipole->SetType(GROUNDEDELECTRICDIPOLE);
45
+		dipole->SetPolarisation(XPOLARISATION);
46
+		dipole->SetNumberOfFrequencies(1);
47
+		dipole->SetMoment(1);
48
+		dipole->SetFrequency(0, 4400.1000);
49
+		//dipole->SetPhase(0);
50
+		//dipole->SetLocation( (VectorXr(3) << 49, 49, -1e-4).finished() );
51
+		dipole->SetLocation( 49, 49, -1e-4  );
52
+
53
+
54
+	// Define model
55
+	VectorXcr sigma(2);
56
+		sigma << 0., 1e-3;//, .1;//, .01, .001;
57
+	VectorXr  thick(1);
58
+		thick << 10;//, 10, 10;
59
+
60
+	LayeredEarthEM *earth = LayeredEarthEM::New();
61
+        earth->SetNumberOfLayers(2);
62
+		earth->SetLayerConductivity(sigma);
63
+		//earth->SetLayerThickness(thick);
64
+
65
+	// Receivers
66
+	ReceiverPoints *receivers = ReceiverPoints::New();
67
+		Vector3r loc;
68
+		//Real ox = -5.1456;
69
+		//Real oy =  2.2350;
70
+		Real ox =    50.;
71
+		Real oy =    20.;
72
+		Real depth = 18.10;
73
+		Real dz = 2.6;
74
+		int  nz = 1;
75
+
76
+		receivers->SetNumberOfReceivers(nz);
77
+		int ir = 0;
78
+		for (int iz=0; iz<nz; ++iz) {
79
+			loc << ox, oy, depth;
80
+			receivers->SetLocation(ir, loc);
81
+			depth += dz;
82
+			++ ir;
83
+		}
84
+	//receivers->SetLocation(1, ox, oy, depth);
85
+
86
+	EMEarth1D *EmEarth = EMEarth1D::New();
87
+        //EmEarth->SetHankelTransformMethod(DIGITALFILTERING);
88
+        EmEarth->SetFieldsToCalculate(BOTH); // Fortran needs this
89
+		EmEarth->AttachDipoleSource(dipole);
90
+		EmEarth->AttachLayeredEarthEM(earth);
91
+		EmEarth->AttachReceiverPoints(receivers);
92
+
93
+        //dipole->SetType(ELECTRICDIPOLE);
94
+//         receivers->SetNumberOfReceivers(1);
95
+//         //for
96
+// 	    receivers->SetLocation(0, ox, oy, depth);
97
+
98
+
99
+	std::cout << "C++\n";
100
+	EmEarth->MakeCalc3();
101
+	std::cout << receivers->GetEfield(0,0) << std::endl;
102
+	//std::cout << receivers->GetEfield(0) << std::endl;
103
+	//std::cout << receivers->GetHfield(1) << std::endl;
104
+	//std::cout << receivers->GetEfield(1) << std::endl;
105
+	receivers->ClearFields();
106
+
107
+    // swap tx rx posigion
108
+    receivers->SetLocation(0, dipole->GetLocation());
109
+    dipole->SetLocation(loc);
110
+	EmEarth->MakeCalc3();
111
+	std::cout << receivers->GetEfield(0,0) << std::endl;
112
+
113
+	receivers->ClearFields();
114
+ #ifdef KIHALEE_EM1D
115
+// 	//std::cout << "\nFORTRAN\n";
116
+ 	EmEarth->MakeCalc();
117
+// 	std::cout << receivers->GetHfield(0,0) << std::endl;
118
+ 	std::cout << receivers->GetEfield(0,0) << std::endl;
119
+ #endif
120
+
121
+    dipole->Delete();
122
+    EmEarth->Delete();
123
+    receivers->Delete();
124
+    earth->Delete();
125
+
126
+// 	try {
127
+//
128
+// 	}
129
+//
130
+// 	// Catch exceptions
131
+// 	catch (NullEarth) {
132
+// 			std::cout << "Earth model not set dummy\n";
133
+// 	}
134
+//
135
+// 	catch (NullReceivers) {
136
+// 			std::cout << "Receivers not set dummy\n";
137
+// 	}
138
+
139
+	//EmEarth->TestBess();
140
+
141
+}

+ 199
- 0
LemmaCore/examples/femforward.cpp View File

@@ -0,0 +1,199 @@
1
+// ===========================================================================
2
+// 
3
+//       Filename:  utfemforward.cpp
4
+// 
5
+//    Description:  
6
+// 
7
+//        Version:  0.0
8
+//        Created:  01/15/2013 12:11:34 PM
9
+//       Revision:  none
10
+//       Compiler:  Tested with g++ 
11
+// 
12
+//         Author:  M. Andy Kass (MAK)
13
+//
14
+//   Organisation:  Broken Spoke Development, LLC
15
+//                  
16
+//
17
+//          Email:  mkass@numericalgeo.com
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
+
34
+#include <time.h>
35
+#include "Lemma"
36
+#include "banner.h"
37
+
38
+using namespace Lemma;
39
+
40
+#ifdef LEMMAUSEVTK
41
+#include "matplot.h"
42
+using namespace matplot;
43
+#endif
44
+
45
+int main() {
46
+
47
+	clock_t launch = clock();
48
+
49
+	// Banner display
50
+	std::string name;
51
+	std::string version;
52
+	std::string usage;
53
+	name = "FEM Forward Modeller - 1D ";
54
+	version = "1.0alpha";
55
+	usage = "utfemforward [inputfile]";
56
+	banner(name,version,usage);
57
+
58
+	time_t curr = time(0);
59
+	std::cout << std::endl << "  Start time: " << ctime(&curr) << std::endl;
60
+
61
+	// Define some objects
62
+	DipoleSource* Trans = DipoleSource::New();
63
+	ReceiverPoints* Receivers = ReceiverPoints::New();
64
+	LayeredEarthEM* Earth = LayeredEarthEM::New();
65
+
66
+
67
+
68
+	// SINGLE SOUNDING
69
+
70
+	// Create new data object to receive forward model
71
+	DataFEM* modelledData = DataFEM::New();
72
+
73
+	// Create instrument object
74
+	InstrumentFem* theinstrument = InstrumentFem::New();	
75
+
76
+	// Set up EMEarthModel
77
+	Earth->SetNumberOfLayers(5);
78
+	Earth->SetLayerConductivity((VectorXcr(5) << 0.,1.e-4,1.e-2,
79
+		1.e-4,1.e-6).finished());
80
+	Earth->SetLayerThickness((VectorXr(3) << 20.,5.,50.).finished());
81
+	
82
+	// Set up transmitter
83
+	Real momtemp;
84
+	momtemp = 1;
85
+	Real freq;
86
+	freq = 391;
87
+	Trans->SetType(MAGNETICDIPOLE);
88
+	Trans->SetLocation(0,0,-1.e-3);
89
+	Trans->SetPolarisation(ZPOLARISATION);
90
+	// as a test
91
+	Trans->SetNumberOfFrequencies(1);
92
+	Trans->SetFrequency(0,freq);
93
+	Trans->SetMoment(momtemp);
94
+
95
+	// Set up receivers
96
+	Vector3r loc1;
97
+	Vector3r loc2;
98
+	Receivers->SetNumberOfReceivers(1);
99
+	loc1 << 9,0,-1.e-3;
100
+	Receivers->SetLocation(0,loc1);
101
+
102
+
103
+	// Attach to instrument
104
+	theinstrument->SetReceiverPoints(Receivers);
105
+	theinstrument->SetDipoleSource(Trans);
106
+	theinstrument->EMEarthModel(Earth);
107
+	theinstrument->SetOutputData(modelledData);
108
+
109
+	// Calculate
110
+	theinstrument->MakeCalculation();
111
+
112
+	// See what comes back...
113
+	std::cout << Receivers->GetHfield(0,0)(2) << std::endl;
114
+	
115
+	// Need to convert H field to ppm
116
+
117
+
118
+	theinstrument->Delete();
119
+	modelledData->Delete();
120
+
121
+	// MULTIPLE SOUNDING MODEL USING READ-IN DATA
122
+
123
+
124
+	InstrumentFem* theinstrument2 = InstrumentFem::New();
125
+	DataFEM* modelledData2 = DataFEM::New();
126
+
127
+	// Using the UBC data reader to read in the survey params
128
+	// this will be used for the multiple sounding testing
129
+	std::string datfile;
130
+	datfile = "126.obs";
131
+
132
+	DataReaderFemUBC* Reader = DataReaderFemUBC::New();
133
+	DataFEM* inpdata = DataFEM::New();
134
+	Reader->SetDataFEM(inpdata);
135
+	try {
136
+		Reader->ReadData(datfile,1);
137
+	} catch(std::exception& e) {
138
+		exit(EXIT_FAILURE);
139
+	}
140
+	std::cout << *inpdata << std::endl;
141
+	theinstrument2->SetOutputData(modelledData2);
142
+	theinstrument2->AlignWithData(inpdata);
143
+	// Now, how do I want to pass it an earth model for each sounding?
144
+	//
145
+	inpdata->Delete();
146
+
147
+
148
+
149
+
150
+	// Need to loop over transmitters
151
+	// The relative positions of the transmitter and receiver is fixed
152
+	// For testing, do some kind of random realisation of Earth model?
153
+//	int nObs;
154
+//	int nFreqs;
155
+//	nObs = inpdata->GetnObs();
156
+//	nFreqs = inpdata->GetnFreq();
157
+
158
+//	Trans->SetType(MAGNETICDIPOLE);
159
+//	Trans->SetLocation(0,0,-1e-3);
160
+
161
+//	Vector3r loc;
162
+//	Receivers->SetNumberOfReceivers(1);
163
+//	loc << 0,0,-1e-3;
164
+//	Receivers->SetLocation(0,loc);
165
+
166
+//	Earth->SetNumberOfLayers(5); //Including the two halfspaces
167
+//	Earth->SetLayerConductivity((VectorXcr(5) << 0.,1.e-4,1.e-2,
168
+//		1.e-4,1.e-6).finished());
169
+//	Earth->SetLayerThickness((VectorXr(3) << 20.,5.,50.).finished());
170
+
171
+//	for (int ii=0;ii<nObs;ii++) {
172
+//		for (int jj=0;jj<nFreqs;jj++) {
173
+//			Trans->SetMoment(inpdata->GetTxMom().coeff(jj));
174
+//			
175
+//		}
176
+//	}
177
+	
178
+	//This is a bunch of testing stuff
179
+	//theinstrument->AlignWithData(inpdata);
180
+	//theinstrument->MakeCalculation();
181
+	//inpdata->Delete();
182
+	//theinstrument->MakeCalculation();
183
+
184
+
185
+	theinstrument2->Delete();
186
+	Reader->Delete();
187
+	Earth->Delete();
188
+	Receivers->Delete();
189
+	Trans->Delete();
190
+
191
+	// Timey-wimey stuff
192
+	Real time;
193
+	clock_t done = clock();
194
+	time = (done-launch)/CLOCKS_PER_SEC;
195
+	std::cout << "  Execution time: " << time << " [CPU] seconds."
196
+		<< std::endl;
197
+
198
+	return EXIT_SUCCESS;
199
+}

+ 53
- 0
LemmaCore/examples/filter.cpp View File

@@ -0,0 +1,53 @@
1
+// ===========================================================================
2
+//
3
+//       Filename:  utfilter.cpp
4
+//
5
+//        Created:  07/20/2010 10:12:07 AM
6
+//       Compiler:  Tested with g++, icpc, and MSVC 2010
7
+//
8
+//         Author:  Trevor Irons (ti)
9
+//
10
+//   Organisation:  Colorado School of Mines (CSM)
11
+//                  United States Geological Survey (USGS)
12
+//
13
+//          Email:  tirons@mines.edu, tirons@usgs.gov
14
+//
15
+//  This program is free software: you can redistribute it and/or modify
16
+//  it under the terms of the GNU General Public License as published by
17
+//  the Free Software Foundation, either version 3 of the License, or
18
+//  (at your option) any later version.
19
+//
20
+//  This program is distributed in the hope that it will be useful,
21
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
+//  GNU General Public License for more details.
24
+//
25
+//  You should have received a copy of the GNU General Public License
26
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
27
+//
28
+// ===========================================================================
29
+
30
+/**
31
+  @author   Trevor Irons
32
+  @date     07/20/2010
33
+  @version   0.0
34
+ **/
35
+
36
+#include "windowfilter.h"
37
+using namespace Lemma;
38
+
39
+int main() {
40
+
41
+    WindowFilter* Hamming = WindowFilter::New();
42
+
43
+        Hamming->SetWindowType( HANNING );
44
+        Hamming->SetSamplingInterval(1e-4);
45
+        Hamming->SetBandwidth(300);
46
+        Hamming->SetNumberOfSamples(1./1e-4);
47
+
48
+    std::cout << Hamming->GetFilterCoefficients() //.transpose()
49
+              << std::endl;
50
+
51
+    Hamming->Delete();
52
+
53
+}

+ 342
- 0
LemmaCore/examples/utORS.cpp View File

@@ -0,0 +1,342 @@
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
+
34
+#include <iostream>
35
+#include <fstream>
36
+
37
+#include "dipolesource.h"
38
+#include "layeredearth.h"
39
+#include "receiverpoints.h"
40
+#include "emearth1d.h"
41
+#include "WireAntenna.h"
42
+#include "PolygonalWireAntenna.h"
43
+
44
+#if  LEMMAUSEVTK
45
+#include "vtkRenderer.h"
46
+#include "vtkRenderWindow.h"
47
+#include "vtkRenderWindowInteractor.h"
48
+#include "vtkRenderLargeImage.h"
49
+#include "vtkPNGWriter.h"
50
+#include "vtkRectilinearGrid.h"
51
+#include "vtkXMLRectilinearGridWriter.h"
52
+#include "vtkDoubleArray.h"
53
+#include "vtkFieldData.h"
54
+#include "vtkCellData.h"
55
+#endif     // -----  not LEMMA_USE_VTK  -----
56
+
57
+// For testing purposes disable VTK and run scale.sh
58
+//#undef LEMMAUSEVTK
59
+
60
+#include "timer.h"
61
+
62
+using namespace Lemma;
63
+
64
+double randDouble(double low, double high) {
65
+	//srand(time(0));
66
+	double temp;
67
+	/* swap low & high around if the user makes no sense */
68
+	if (low > high)	{
69
+	temp = low;
70
+	low = high;
71
+	high = temp;
72
+	}
73
+	/* calculate the random number & return it */
74
+	temp = (rand() / (static_cast<double>(RAND_MAX) + 1.0))
75
+	* (high - low) + low;
76
+	return temp;
77
+}
78
+
79
+
80
+int main() {
81
+
82
+	// Keep track of time
83
+	jsw_timer timer;
84
+
85
+
86
+	srand(time(0));
87
+
88
+	PolygonalWireAntenna *pa = PolygonalWireAntenna::New();
89
+	pa->SetNumberOfFrequencies(1);
90
+	pa->SetFrequency(0, 540000);
91
+    Real Depth  =   370;  // nominal depth
92
+    Real Width  = 0.14;  // transmitter height
93
+    Real Height = 0.70;//  .14;  //.014;  // transmitter width
94
+
95
+
96
+	pa->SetNumberOfPoints(5);
97
+    /*
98
+    pa->SetPoint(0, Vector3r(       0,       0, Depth));
99
+	pa->SetPoint(1, Vector3r(       0,       0, Depth+Height));
100
+	pa->SetPoint(2, Vector3r(       0,   Width, Depth+Height));
101
+	pa->SetPoint(3, Vector3r(       0,   Width, Depth));
102
+	pa->SetPoint(4, Vector3r(       0,       0, Depth));
103
+    */
104
+
105
+    pa->SetPoint(0, Vector3r(   -Width/2., -Height/2., Depth));
106
+	pa->SetPoint(1, Vector3r(    Width/2., -Height/2., Depth));
107
+	pa->SetPoint(2, Vector3r(    Width/2.,  Height/2., Depth));
108
+	pa->SetPoint(3, Vector3r(   -Width/2.,  Height/2., Depth));
109
+	pa->SetPoint(4, Vector3r(   -Width/2., -Height/2., Depth));
110
+
111
+	pa->SetCurrent(1.);
112
+    pa->SetNumberOfTurns(6);
113
+	//Vector3r rp = Vector3r::Random(3);
114
+	//rp << 150., 10, 0.;
115
+	//rp << -27.1456, 15.2350, -1e-3;
116
+	//rp << randDouble(-35,35), randDouble(-35,35), randDouble(-35,35);
117
+	//rp << 3.22806, -13.1548, 14.9695;
118
+	//rp.setRandom(3);
119
+	//std::cout <<  "rp " << rp.transpose() << std::endl;
120
+	//pa->ApproximateWithElectricDipoles(rp);
121
+
122
+
123
+	// Define model
124
+    Real Sigma = 1.0/20. ; // .05;
125
+	VectorXcr sigma(2);
126
+		sigma << Complex(0.,0), Complex(Sigma,0);
127
+	VectorXr  thick(1);
128
+		thick << 10;
129
+	LayeredEarthEM *earth = LayeredEarthEM::New();
130
+		earth->SetNumberOfLayers(2);
131
+		earth->SetLayerConductivity(sigma);
132
+		//earth->SetLayerThickness(thick);
133
+
134
+	// Receivers
135
+	ReceiverPoints *receivers = ReceiverPoints::New();
136
+		Vector3r loc;
137
+		Real ox    =    -5.*Width - .003373;
138
+		Real oy    =    -3.*Height - .003373;
139
+		Real oz    =    Depth - Height/2. - .003373;
140
+		int nx     =   120; // 60;
141
+		int ny     =   180; //  50;
142
+		int nz     =   100; // 40;
143
+		Real hx    =    11.*Width/nx;
144
+		Real hy    =     7.*Height/ny;
145
+		Real hz    =     1.*Height/nz;
146
+
147
+        receivers->SetNumberOfReceivers(nx*ny*nz);
148
+		int ir = 0;
149
+		for (int iz=0; iz<nz; ++iz) {
150
+		for (int iy=0; iy<ny; ++iy) {
151
+		for (int ix=0; ix<nx; ++ix) {
152
+			loc << ox+ix*hx, oy+iy*hy, oz+iz*hz;
153
+			receivers->SetLocation(ir, loc);
154
+			++ ir;
155
+		}
156
+        }
157
+        }
158
+
159
+	// EmEarth
160
+	EMEarth1D  *EmEarth = EMEarth1D::New();
161
+		//EmEarth->AttachWireAntenna(wire);
162
+		EmEarth->AttachWireAntenna(pa);
163
+		EmEarth->AttachLayeredEarthEM(earth);
164
+		EmEarth->AttachReceiverPoints(receivers);
165
+		EmEarth->SetFieldsToCalculate(E);
166
+        //EmEarth->SetHankelTransformMethod(GAUSSIANQUADRATURE);
167
+        EmEarth->SetHankelTransformMethod(ANDERSON801);
168
+
169
+	// Do calculation
170
+	timer.begin();
171
+	EmEarth->CalculateWireAntennaFields();
172
+	Real paTime = timer.end();
173
+	std::cout << "Polygonal wire antennae time: " << paTime << "\n";
174
+
175
+	//EmEarth->AttachWireAntenna(wire);
176
+	//timer.begin();
177
+	//EmEarth->CalculateWireAntennaFields();
178
+	//Real waTime = timer.end();
179
+	//std::cout << "Fixed wire antennae time: " << waTime << "\n";
180
+/*
181
+	depth = depth2;
182
+	std::fstream real("reale_lay.dat", std::ios::out);
183
+	std::fstream imag("image_lay.dat", std::ios::out);
184
+	for (int iz=0; iz<nz; ++iz) {
185
+		Vector3cr temp = receivers->GetEfield(0,iz);
186
+		real << ox << "\t" << oy << "\t" << depth << "\t"
187
+				<< temp(0).real() << "\t" << temp(1).real()
188
+				<< "\t" << temp(2).real() << std::endl;
189
+		imag << ox << "\t" << oy << "\t" << depth << "\t"
190
+				<< std::imag(temp(0)) << "\t" << std::imag(temp(1))
191
+				<< "\t" << std::imag(temp(2)) << std::endl;
192
+		depth += dx;
193
+	}
194
+	real.close();
195
+	imag.close();
196
+*/
197
+
198
+	//wire->Delete();
199
+#if  LEMMAUSEVTK
200
+
201
+    // Set Coordinates
202
+    vtkDoubleArray *xCoords = vtkDoubleArray::New();
203
+    xCoords->InsertNextValue(ox-hx/2.);
204
+    double xm1 = ox-hx/2.;
205
+    for (int ix=0; ix<nx; ix++) {
206
+        xCoords->InsertNextValue(xm1 + hx);
207
+        xm1 += hx;
208
+    }
209
+
210
+    vtkDoubleArray *yCoords = vtkDoubleArray::New();
211
+    yCoords->InsertNextValue(oy-hy/2.);
212
+    double ym1 = oy-hy/2.;
213
+    for (int iy=0; iy<ny; iy++) {
214
+        yCoords->InsertNextValue(ym1 + hy);
215
+        ym1 += hy;
216
+    }
217
+
218
+    vtkDoubleArray *zCoords = vtkDoubleArray::New();
219
+    zCoords->InsertNextValue(oz-hz/2.);
220
+    double zm1 = oz-hz/2.;
221
+    for (int iz=0; iz<nz; iz++) {
222
+        zCoords->InsertNextValue(zm1 + hz);
223
+        zm1 += hz;
224
+    }
225
+
226
+    vtkDoubleArray *EReal = vtkDoubleArray::New();
227
+    vtkDoubleArray *EImag = vtkDoubleArray::New();
228
+    vtkDoubleArray *Watts = vtkDoubleArray::New();
229
+    EReal->SetNumberOfComponents(3);
230
+    EImag->SetNumberOfComponents(3);
231
+    Watts->SetNumberOfComponents(1);
232
+
233
+    ir = 0;
234
+    Real WattsTotal(0);
235
+    Real WattsInterior(0);
236
+    for (int iz=0; iz<nz; ++iz) {
237
+    for (int iy=0; iy<ny; ++iy) {
238
+    for (int ix=0; ix<nx; ++ix) {
239
+        //sigmaArray->InsertTuple1(i,  sigma[ix][iy][iz] );
240
+		Vector3cr E = receivers->GetEfield(0, ir);
241
+        EReal-> InsertTuple3(ir, real(E(0)), real(E(1)), real(E(2)));
242
+        EImag-> InsertTuple3(ir, imag(E(0)), imag(E(1)), imag(E(2)));
243
+        //std::cout << std::abs(ox+ix*hx) << "\t"  <<  Width/2. << endl; // && std::abs(oy+iy*hy) > Height/2. ) { // && std::abs(oz+iz*hz - Depth) > Width/2. ) {
244
+        //if ( std::abs( ox+ix*hx ) < Width/2. && std::abs(oy+iy*hy) < Height/2. && std::abs(oz+iz*hz - Depth) < Width/2. ) {
245
+        if ( std::sqrt( std::pow(ox+ix*hx,2)  + std::pow(oz+iz*hz - Depth, 2) ) < .085 && std::abs(oy+iy*hy) < Height/2. ) {
246
+            Watts-> InsertTuple1(ir,  1e-20 );
247
+            WattsInterior += .5*  (( pow((std::abs(E(0)) + std::abs(E(1)) + std::abs(E(2))), 2)*Sigma)*hx*hy*hz );
248
+        } else {
249
+            Watts-> InsertTuple1(ir, .5* (pow( (std::abs(E(0)) + std::abs(E(1)) + std::abs(E(2))), 2)*Sigma)*hx*hy*hz );
250
+            //Watts-> InsertTuple1(ir,  1e-20 );
251
+            WattsTotal += .5*  (( pow((std::abs(E(0)) + std::abs(E(1)) + std::abs(E(2))), 2)*Sigma)*hx*hy*hz );
252
+        }
253
+		++ ir;
254
+    }
255
+    }
256
+    }
257
+    std::cout << "Total Power: " << Sigma << "\t" << WattsTotal << "\t" << WattsInterior << endl;
258
+
259
+    EReal->SetName("E_real");
260
+    EImag->SetName("E_imag");
261
+    Watts->SetName("Power");
262
+
263
+    vtkRectilinearGrid *rgrid = vtkRectilinearGrid::New();
264
+        rgrid->SetDimensions(nx+1,ny+1,nz+1);
265
+        rgrid->SetXCoordinates(xCoords);
266
+        rgrid->SetYCoordinates(yCoords);
267
+        rgrid->SetZCoordinates(zCoords);
268
+
269
+        rgrid->GetCellData()->AddArray(EReal);
270
+        rgrid->GetCellData()->AddArray(EImag);
271
+        rgrid->GetCellData()->AddArray(Watts);
272
+        //rgrid->Update();
273
+
274
+    vtkXMLRectilinearGridWriter *gridWrite = vtkXMLRectilinearGridWriter::New();
275
+        gridWrite->SetInputData(rgrid);
276
+        gridWrite->SetFileName("ors.vtr");
277
+        gridWrite->Write();
278
+        //gridWrite->Update();
279
+
280
+#endif
281
+	EmEarth->Delete();
282
+	receivers->Delete();
283
+	earth->Delete();
284
+
285
+#if  LEMMAUSEVTKX
286
+	// Create the usual rendering stuff.
287
+	vtkRenderer           *renderer = vtkRenderer::New();
288
+	vtkRenderWindow         *renWin = vtkRenderWindow::New();
289
+	vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
290
+
291
+	std::cout << "wire antennae approximating " << std::endl;
292
+	loc << 0, .5*Width, Depth+.5*Height;
293
+	pa->ApproximateWithElectricDipoles(loc);
294
+    std::cout <<  "Wire approximated with " << pa->GetNumberOfDipoles() << std::endl;
295
+
296
+    vtkActor **pdipActors = new vtkActor*[pa->GetNumberOfDipoles()];
297
+	for (int id=0; id<pa->GetNumberOfDipoles(); ++id) {
298
+		pdipActors[id] = pa->GetVtkActor(id);
299
+		renderer->AddActor(pdipActors[id]);
300
+	}
301
+
302
+    /*
303
+    vtkActor **dipActors = new vtkActor*[wire->GetNumberOfDipoles()];
304
+	for (int id=0; id<wire->GetNumberOfDipoles(); ++id) {
305
+		dipActors[id] = wire->GetVtkActor(id);
306
+		renderer->AddActor(dipActors[id]);
307
+	}
308
+    */
309
+
310
+	renderer->SetBackground(1,1,1);
311
+
312
+	// Render the window
313
+	renWin->AddRenderer(renderer);
314
+	renWin->SetWindowName("Wire antennae");
315
+
316
+	iren->SetRenderWindow(renWin);
317
+	iren->Initialize();
318
+	iren->Start();
319
+	iren->Render();
320
+
321
+    #if 0
322
+	cout << "Enter File name?: ";
323
+	std::string pngName;
324
+	std::cin >> pngName;
325
+	vtkPNGWriter *pngwrite = vtkPNGWriter::New();
326
+	vtkRenderLargeImage *renlarge = vtkRenderLargeImage::New();
327
+	renlarge->SetInput(renderer);
328
+	renlarge->SetMagnification(2);
329
+	pngwrite->SetInputConnection(renlarge->GetOutputPort());
330
+	pngName.append(".png");
331
+	pngwrite->SetFileName(pngName.c_str());
332
+	pngwrite->Write();
333
+    #endif
334
+
335
+#endif     // -----  not LEMMA_USE_VTK  -----
336
+
337
+
338
+	//std::cout << *pa << std::endl;
339
+	//pa->Delete();
340
+
341
+	return 0;
342
+}

+ 34
- 0
LemmaCore/examples/utQWEKey.cpp View File

@@ -0,0 +1,34 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API.
2
+ * More information is available at http://lemmasoftware.org
3
+ */
4
+
5
+/* This Source Code Form is subject to the terms of the Mozilla Public
6
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
7
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
+ */
9
+
10
+/**
11
+ * @file
12
+ * @date      02/12/2014 01:01:29 PM
13
+ * @version   $Id$
14
+ * @author    Trevor Irons (ti)
15
+ * @email     Trevor.Irons@xri-geo.com
16
+ * @copyright Copyright (c) 2014, XRI Geophysics, LLC
17
+ * @copyright Copyright (c) 2014, Trevor Irons
18
+ */
19
+
20
+#include "QWEKey.h"
21
+using namespace Lemma;
22
+
23
+int main() {
24
+
25
+    // TODO chech
26
+
27
+    QWEKey* QWE = QWEKey::New();
28
+    QWE->TestPrivate( 5 );
29
+    QWE->Delete();
30
+
31
+    return 0;
32
+}
33
+
34
+

+ 86
- 0
LemmaCore/examples/utSerialize.cpp View File

@@ -0,0 +1,86 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API.
2
+ * More information is available at http://lemmasoftware.org
3
+ */
4
+
5
+/* This Source Code Form is subject to the terms of the Mozilla Public
6
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
7
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
+ */
9
+
10
+/**
11
+ * @file
12
+ * @date      09/29/2014 01:31:26 PM
13
+ * @version   $Id$
14
+ * @author    Trevor Irons (ti)
15
+ * @email     Trevor.Irons@xri-geo.com
16
+ * @copyright Copyright (c) 2014, XRI Geophysics, LLC
17
+ * @copyright Copyright (c) 2014, Trevor Irons
18
+ */
19
+
20
+#include "Lemma"
21
+
22
+using namespace Lemma;
23
+
24
+#ifdef  HAVE_YAMLCPP
25
+#include "yaml-cpp/yaml.h"
26
+
27
+int main() {
28
+
29
+    std::ofstream ofstr("output.yaml");
30
+    //ofstr << "%YAML 1.2\n" << "---\n";
31
+    //ofstr << "LEMMA_CLASSES:\n";
32
+
33
+    // This works for individual classes or even groups of unrelated classes. But
34
+    // How should references work? One option would be to hack YAML and allow for references
35
+    // across 'Docs'. This is maybe undesireable, as then it's not valid YAML anymore.
36
+    // OR we could have some other kind of IDENTIFIER that could be used and Connections could be
37
+    // made AFTER the whole file is processed?
38
+
39
+    // Alternative is each class is written to it's own file. And then implicit on the Serialize function, the file tags are written
40
+    // into the YAML instead of the pointer. Alternatively, tags could do this too.
41
+
42
+    // Or file could be saved as pointer.yaml
43
+
44
+    // *
45
+    // * Or a file contains all the subclasses it point to. So that it's self-enclosed. This is nice as it's quite
46
+    // * flexible. The only downwside is possible repeat of classes. Basically if the API is careful though, only 1
47
+    // * instance will need to be serialized.
48
+    // *
49
+
50
+
51
+    TEMTransmitter* Seq = TEMTransmitter::New();
52
+        Seq->SetRepFrequency( 20, KHZ );
53
+        VectorXr Times (18);
54
+        VectorXr Amps (18);
55
+        Times << 0.0, 0.03051, 0.10267, 0.19408, 0.19889, 0.21332, 0.74249, 1.3775, 1.83452, 2.52245, \
56
+                3.191132, 3.9031135, 4.0, 4.00484486, 4.123904, 4.200182, 4.20732, 4.212946;
57
+        Amps << 0.0, 14.71872, 62.34372, 114.84372, 117.84372, 118.96872, 118.96872, 118.96872, 118.96872,\
58
+                118.59372, 119.34372, 120.0, 120.0, 117.94176, 47.60364, 0.8905848, 0.1203888, 0.0;
59
+        Seq->SetWaveform(Times, Amps, MILLISEC);
60
+    // OK dump to disk
61
+    ofstr << *Seq ;
62
+    ofstr.close();
63
+    Seq->Delete();
64
+
65
+
66
+    // OK now load
67
+    std::ifstream ifstr("output.yaml");
68
+    std::vector<YAML::Node> nodes = YAML::LoadAll(ifstr);
69
+
70
+    TEMTransmitter* Seq2 = TEMTransmitter::DeSerialize( nodes[0] );
71
+    std::cout << "Loaded\n" << *Seq2;
72
+    Seq2->Delete();
73
+    ifstr.close();
74
+
75
+    //YAML::Node nodes = YAML::LoadFile("output.yaml");
76
+    //std::cout << nodes[0] << std::endl;
77
+    //std::cout << nodes[1] << std::endl;
78
+
79
+    exit(EXIT_SUCCESS);
80
+}
81
+
82
+#else
83
+int main() {
84
+
85
+}
86
+#endif

+ 31
- 0
LemmaCore/examples/utSkyTEM.cpp View File

@@ -0,0 +1,31 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API.
2
+ * More information is available at http://lemmasoftware.org
3
+ */
4
+
5
+/* This Source Code Form is subject to the terms of the Mozilla Public
6
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
7
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
+ */
9
+
10
+/**
11
+ * @file
12
+ * @date      02/27/2015 11:02:43 AM
13
+ * @version   $Id$
14
+ * @author    Trevor Irons (ti)
15
+ * @email     Trevor.Irons@xri-geo.com
16
+ * @copyright Copyright (c) 2015, XRI Geophysics, LLC
17
+ * @copyright Copyright (c) 2015, Trevor Irons
18
+ */
19
+
20
+// SkyTEM forward modelling programme
21
+
22
+#include "TEMSurvey.h"
23
+
24
+int main() {
25
+
26
+    std::cout << "SkyTEM modelling\n";
27
+
28
+
29
+
30
+}
31
+

+ 197
- 0
LemmaCore/examples/utTEMSurvey.cpp View File

@@ -0,0 +1,197 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API.
2
+ * More information is available at http://lemmasoftware.org
3
+ */
4
+
5
+/* This Source Code Form is subject to the terms of the Mozilla Public
6
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
7
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
+ */
9
+
10
+/**
11
+ * @file
12
+ * @date      10/06/2014 10:37:30 AM
13
+ * @version   $Id$
14
+ * @author    Trevor Irons (ti)
15
+ * @email     Trevor.Irons@xri-geo.com
16
+ * @copyright Copyright (c) 2014, XRI Geophysics, LLC
17
+ * @copyright Copyright (c) 2014, Trevor Irons
18
+ */
19
+
20
+#include "Lemma"
21
+using namespace Lemma;
22
+
23
+int main() {
24
+
25
+    // Each pulse sequence functions as an autonomous transmitter. A record may contain multiple transmitters (moments).
26
+    // There is some small overhead for wire loop locations, but generality is retained doing this, as well as monitoring of
27
+    // slight changes in geometry for both pulses.
28
+    TEMTransmitter* TxHM = TEMTransmitter::New();
29
+        TxHM->SetRepFrequency( 20, KHZ );
30
+        VectorXr Times (18);
31
+        VectorXr Amps (18);
32
+        Times << 0.0, 0.03051, 0.10267, 0.19408, 0.19889, 0.21332, 0.74249, 1.3775, 1.83452, 2.52245, \
33
+                3.191132, 3.9031135, 4.0, 4.00484486, 4.123904, 4.200182, 4.20732, 4.212946;
34
+        Amps << 0.0, 14.71872, 62.34372, 114.84372, 117.84372, 118.96872, 118.96872, 118.96872, 118.96872,\
35
+                118.59372, 119.34372, 120.0, 120.0, 117.94176, 47.60364, 0.8905848, 0.1203888, 0.0;
36
+        TxHM->SetWaveform( Times, Amps, MILLISEC );
37
+        // Define wire loop
38
+        TxHM->SetNumberOfPoints(8);
39
+        TxHM->SetPoint(0, Vector3r( -16.10,    2.13,  -34));
40
+        TxHM->SetPoint(1, Vector3r(  -7.51,   10.72,  -34));
41
+        TxHM->SetPoint(2, Vector3r(   7.51,   10.72,  -34));
42
+        TxHM->SetPoint(3, Vector3r(  14.92,    3.31,  -34));
43
+        TxHM->SetPoint(4, Vector3r(  14.92,   -3.31,  -34));
44
+        TxHM->SetPoint(5, Vector3r(   7.51,  -10.72,  -34));
45
+        TxHM->SetPoint(6, Vector3r(  -7.51,  -10.72,  -34));
46
+        TxHM->SetPoint(7, Vector3r( -16.10,   -2.13,  -34));
47
+        TxHM->SetNumberOfTurns(8);
48
+
49
+    // Each Transmitter needs its own `Receiver(s)', the only difference may be the time gates, but that's OK.
50
+    //     It's a minor amount of overhead for greatly improved genearality. As sometimes different gates are
51
+    //     masked.
52
+    TEMInductiveReceiver* RxHM = TEMInductiveReceiver::New();
53
+        RxHM->SetComponent( ZCOMPONENT );      // What about Overloaded to take (X), (X,Y), or (X,Y,Z) or what about tilt?
54
+        RxHM->SetMoment( 1 );                  // Normalized
55
+        RxHM->SetReferenceTime( 4., MILLISEC );
56
+        RxHM->SetRxLocation( (Vector3r() << -16.80, 0, -36.00).finished() );
57
+
58
+        // Gate Centres  ms
59
+        VectorXr centres (37);
60
+        centres << 7.15000000e-04,   2.21500000e-03,   4.21500000e-03,   6.21500000e-03,
61
+                   8.21500000e-03,   1.02150000e-02,   1.22150000e-02,   1.47150000e-02,
62
+                   1.82150000e-02,   2.27150000e-02,   2.82150000e-02,   3.52150000e-02,
63
+                   4.42150000e-02,   5.57150000e-02,   7.02150000e-02,   8.82150000e-02,
64
+                   1.10715000e-01,   1.38715000e-01,   1.74215000e-01,   2.19715000e-01,
65
+                   2.76715000e-01,   3.48715000e-01,   4.39715000e-01,   5.53715000e-01,
66
+                   6.97715000e-01,   8.79215000e-01,   1.10771500e+00,   1.39621500e+00,
67
+                   1.76021500e+00,   2.21871500e+00,   2.79671500e+00,   3.52571500e+00,
68
+                   4.44471500e+00,   5.60321500e+00,   7.06321500e+00,   8.90421500e+00,
69
+                   1.10667200e+01;
70
+        //centres.array() += 4.;
71
+
72
+        // Gate Widths  ms
73
+        VectorXr widths (37);
74
+        widths <<   4.30000000e-04,   1.43000000e-03,   3.43000000e-03,   5.43000000e-03,
75
+                    7.43000000e-03,   9.43000000e-03,   1.14300000e-02,   1.34300000e-02,
76
+                    1.64300000e-02,   2.04300000e-02,   2.54300000e-02,   3.14300000e-02,
77
+                    3.94300000e-02,   4.94300000e-02,   6.24300000e-02,   7.84300000e-02,
78
+                    9.84300000e-02,   1.23430000e-01,   1.54430000e-01,   1.94430000e-01,
79
+                    2.45430000e-01,   3.08430000e-01,   3.89430000e-01,   4.90430000e-01,
80
+                    6.17430000e-01,   7.78430000e-01,   9.80430000e-01,   1.23543000e+00,
81
+                    1.55743000e+00,   1.96343000e+00,   2.47443000e+00,   3.11943000e+00,
82
+                    3.93243000e+00,   4.95743000e+00,   6.24943000e+00,   7.87743000e+00,
83
+                    9.93143000e+00;
84
+
85
+        RxHM->SetWindows(centres, widths, MILLISEC);
86
+
87
+    TEMTransmitter* TxLM = TEMTransmitter::New();
88
+        TxLM->SetRepFrequency( 20, KHZ );
89
+        VectorXr TimesLM (18);
90
+        VectorXr AmpsLM (18);
91
+
92
+        TimesLM << -8.00000E-004, -7.86965E-004, -7.66493E-004, -7.23688E-004,
93
+                   -6.39938E-004, -5.16174E-004, -3.93340E-004, -2.63993E-004,
94
+                   -1.43952E-004, -7.15990E-006, -2.50712E-006,  0.00000E+000,
95
+                    2.19597E-007,  1.47193E-006,  3.34398E-006,  4.68669E-006,
96
+                    5.96484E-006,  7.04934E-006;
97
+        TimesLM.array() = TimesLM.array() + 8e-4;  // Valgrind Hack += yields error. Correct for SkyTEM convention
98
+
99
+
100
+        AmpsLM <<  0.00000E+000,  3.67188E-002,  6.17188E-002,  1.17969E-001,
101
+                   2.14844E-001,  3.28906E-001,	 4.75781E-001,  6.30469E-001,
102
+                   7.82031E-001,  9.92969E-001,	 1.00000E+000,  1.00000E+000,
103
+                   9.63459E-001,  6.01030E-001,  2.29652E-001,  8.64702E-002,
104
+                   2.53196E-002,  0.00000E+000;
105
+        AmpsLM.array() = AmpsLM.array() * 8.;   // Also correct for SkyTEM convention in .geo file
106
+
107
+        TxLM->SetWaveform( TimesLM, AmpsLM, SEC );
108
+        // Define wire loop
109
+        TxLM->SetNumberOfPoints(8);
110
+        TxLM->SetPoint(0, Vector3r( -16.10,    2.13,  -34));
111
+        TxLM->SetPoint(1, Vector3r(  -7.51,   10.72,  -34));
112
+        TxLM->SetPoint(2, Vector3r(   7.51,   10.72,  -34));
113
+        TxLM->SetPoint(3, Vector3r(  14.92,    3.31,  -34));
114
+        TxLM->SetPoint(4, Vector3r(  14.92,   -3.31,  -34));
115
+        TxLM->SetPoint(5, Vector3r(   7.51,  -10.72,  -34));
116
+        TxLM->SetPoint(6, Vector3r(  -7.51,  -10.72,  -34));
117
+        TxLM->SetPoint(7, Vector3r( -16.10,   -2.13,  -34));
118
+        TxLM->SetNumberOfTurns(8);
119
+
120
+
121
+    TEMInductiveReceiver* RxLM = TEMInductiveReceiver::New();
122
+        RxLM->SetComponent( ZCOMPONENT );      // What about Overloaded to take (X), (X,Y), or (X,Y,Z) or what about tilt?
123
+        RxLM->SetMoment( 1 );                  // Normalized
124
+        RxLM->SetReferenceTime( 8e-4, SEC );
125
+        RxLM->SetRxLocation( (Vector3r() << -16.80, 0, -36.00).finished() );
126
+
127
+        // Gate Centres  ms
128
+        VectorXr centresLM (26);
129
+            centresLM << 7.150000E-07, 2.215000E-06, 4.215000E-06, 6.215000E-06, 8.215000E-06,
130
+                         1.021500E-05, 1.221500E-05, 1.471500E-05, 1.821500E-05, 2.271500E-05,
131
+                         2.821500E-05, 3.521500E-05, 4.421500E-05, 5.571500E-05, 7.021500E-05,
132
+                         8.821500E-05, 1.107150E-04, 1.387150E-04, 1.742150E-04, 2.197150E-04,
133
+                         2.767150E-04, 3.487150E-04, 4.397150E-04, 5.537150E-04, 6.977150E-04,
134
+                         8.792150E-04;
135
+
136
+        VectorXr widthsLM (26);
137
+            widthsLM << 5.700000E-07, 1.570000E-06, 1.570000E-06, 1.570000E-06, 1.570000E-06,
138
+                        1.570000E-06, 1.570000E-06, 2.570000E-06, 3.570000E-06, 4.570000E-06,
139
+                        5.570000E-06, 7.570000E-06, 9.570000E-06, 1.257000E-05, 1.557000E-05,
140
+                        1.957000E-05, 2.457000E-05, 3.057000E-05, 3.957000E-05, 5.057000E-05,
141
+                        6.257000E-05, 8.057000E-05, 1.005700E-04, 1.265700E-04, 1.605700E-04,
142
+                        2.015700E-04;
143
+
144
+        RxLM->SetWindows(centresLM, widthsLM, SEC);
145
+
146
+
147
+
148
+    // Specifies survey, this is the Glue Class, the top of the structure, etc.
149
+    TEMSurvey* Survey = TEMSurvey::New();
150
+        Survey->SetNumberOfLines(1);  // Flight lines or
151
+                                      // Internally each line is a class? But that's sort of hidden to the
152
+                                      // end user. Having each line seperate is nice for constrained inversion, where
153
+                                      // each line is a nice thing to deal with.
154
+        Survey->GetLine(0)->SetNumberOfRecords(1);    // Each Record then contains everything needed for modelling response curve(s)
155
+        Survey->GetLine(0)->GetRecord(0)->SetNumberOfPulseSequences( 1 );
156
+        Survey->GetLine(0)->GetRecord(0)->SetTransmitterReceiverPair( 0, TxHM, RxHM );
157
+        //Survey->GetLine(0)->GetRecord(0)->SetTransmitterReceiverPair( 1, TxHM, RxHM );
158
+
159
+
160
+    LayeredEarthEM* Earth = LayeredEarthEM::New();
161
+        Earth->SetNumberOfLayers(31);
162
+        Earth->SetLayerThickness( (VectorXr(29) <<  5.00E+00,  5.40E+00,
163
+             5.80E+00, 6.30E+00, 6.80E+00, 7.30E+00, 7.80E+00, 8.50E+00,
164
+             9.10E+00, 9.80E+00, 1.06E+01, 1.14E+01, 1.23E+01, 1.33E+01,
165
+             1.43E+01, 1.54E+01, 1.66E+01, 1.79E+01, 1.93E+01, 2.08E+01,
166
+             2.25E+01, 2.42E+01, 2.61E+01, 2.81E+01, 3.03E+01, 3.27E+01,
167
+             3.52E+01, 3.80E+01, 4.10E+01).finished() );
168
+
169
+        VectorXcr rho = ( (VectorXcr(31) << 0, 1.54E+01, 4.21E+01,
170
+            9.25E+01, 1.26E+02, 1.17E+02, 7.57E+01, 3.21E+01, 1.40E+01, 1.96E+01,
171
+            2.67E+01, 2.56E+01, 2.00E+01, 1.86E+01, 2.31E+01, 2.97E+01, 3.50E+01,
172
+            3.79E+01, 3.75E+01, 3.32E+01, 2.52E+01, 1.57E+01, 8.38E+00, 5.38E+00,
173
+            5.49E+00, 6.34E+00, 7.07E+00, 7.81E+00, 8.67E+00, 9.59E+00, 1.05E+01
174
+        ).finished() ); // 200 Ohm-m half space
175
+
176
+        Earth->SetLayerConductivity( 1./rho.array() );
177
+        // ALL SET UP
178
+        std::cout << *Survey << std::endl;
179
+
180
+        // OK do your thinc
181
+        //DataTEM* data =
182
+        Survey->ForwardModel( Earth );
183
+
184
+
185
+    // Clean up
186
+
187
+
188
+
189
+//     //Survey->Delete();
190
+//     Earth->Delete();
191
+//
192
+//     TxHM->Delete();
193
+//     RxHM->Delete();
194
+//     TxLM->Delete();
195
+//     RxLM->Delete();
196
+
197
+}

+ 168
- 0
LemmaCore/examples/utXMLParse.cpp View File

@@ -0,0 +1,168 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API.
2
+ * More information is available at http://lemmasoftware.org
3
+ */
4
+
5
+/* This Source Code Form is subject to the terms of the Mozilla Public
6
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
7
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
+ */
9
+
10
+/**
11
+ * @file
12
+ * @date      04/03/2014 01:08:28 PM
13
+ * @version   $Id$
14
+ * @author    Trevor Irons (ti)
15
+ * @email     Trevor.Irons@xri-geo.com
16
+ * @copyright Copyright (c) 2014, XRI Geophysics, LLC
17
+ * @copyright Copyright (c) 2014, Trevor Irons
18
+ */
19
+
20
+#include "Lemma"
21
+#ifdef TINYXMLSUPPORT
22
+#include "tinyxml2.h"
23
+
24
+#include <ctime>
25
+using namespace tinyxml2;
26
+using namespace Lemma;
27
+
28
+void ParseTEM( XMLElement* element );
29
+
30
+template <typename T>
31
+std::vector<T> ReadLine( const int& nr, const std::string& line ) ;
32
+
33
+int main(int argc, char **argv) {
34
+
35
+    if ( argc > 1 ) {
36
+		XMLDocument* doc = new XMLDocument();
37
+		clock_t startTime = clock();
38
+		doc->LoadFile( argv[1] );
39
+		clock_t loadTime = clock();
40
+		int errorID = doc->ErrorID();
41
+
42
+        // Get some info
43
+        //static const char* xml = "<element/>";
44
+        //doc->Parse( xml );
45
+        //XMLNode* titleElement = doc->FirstChild(); //Element()->FirstChildElement( "PLAY" )->FirstChildElement( "TITLE" );
46
+        XMLElement* titleElement = doc->FirstChildElement( ); //->FirstChildElement( "TITLE" );
47
+        //const char* title = titleElement->Value(); //GetText();
48
+        const char* title = titleElement->Value(); //GetText();
49
+
50
+        printf( "Test file '%s' loaded. ErrorID=%d\n", argv[1], errorID );
51
+        printf( "Name of FirstChildElement: %s\n", title );
52
+
53
+        if (strcmp ( titleElement->Value(), "NGXFile" ) != 0) {
54
+            std::cout <<"NGX file was not detected!" << std::endl;
55
+            exit(EXIT_FAILURE);
56
+        } else {
57
+            //std::cout <<
58
+            //titleElement->FirstAttribute() ;//"type");// << std::endl;;
59
+            if (strcmp(  titleElement->FindAttribute("type")->Value(),"tem") == 0) {
60
+                // Parse TEM file
61
+                ParseTEM( titleElement );
62
+            } else {
63
+                std::cout << "No parser for NGX filetype " << titleElement->FindAttribute("type")->Value() << std::endl;
64
+                std::cout << "YOU should write one!\n";
65
+                exit(EXIT_FAILURE);
66
+            }
67
+
68
+        }
69
+
70
+		delete doc; doc = 0;
71
+
72
+        clock_t deleteTime = clock();
73
+		if ( !errorID ) {
74
+			printf( "========================================================\n");
75
+			printf( "Load time=%u\n",   (unsigned)(loadTime - startTime) );
76
+			printf( "Delete time=%u\n", (unsigned)(deleteTime - loadTime) );
77
+			printf( "Total time=%u\n",  (unsigned)(deleteTime - startTime) );
78
+		}
79
+
80
+
81
+		exit(0);
82
+	} else {
83
+        std::cout << "Enter NGX.x file to parse\n";
84
+    }
85
+}
86
+
87
+void ParseTEM( XMLElement* element ) {
88
+
89
+    std::cout << "This is a NGX.t file" << std::endl;
90
+
91
+
92
+    if (strcmp( element->FindAttribute("version")->Value(),"0.1") == 0) {
93
+        std::cout << "Version 0.1 detected" << std::endl;
94
+    } else {
95
+        std::cout << "Unsupported NGX.t version" << std::endl;
96
+    }
97
+
98
+    // system description
99
+    std::cout << "System description" << std::endl;
100
+    std::cout << element->FirstChildElement("system")->FirstChildElement("name")->GetText() << std::endl;
101
+    XMLElement* system = element->FirstChildElement("system");
102
+        int ntx = atoi(system->FirstChildElement("transmitters")->FindAttribute("num")->Value());
103
+        std::cout << "numTx = " << ntx << std::endl;
104
+        // OK Parse Transmitter(s)
105
+        XMLElement* tx = system->FirstChildElement("transmitters")->FirstChildElement("transmitter");
106
+        //    std::cout << "Tx id = " << tx->FindAttribute("id")->Value() << std::endl;
107
+        //std::cout << tx->FirstChildElement("loop.coordinates")->FindAttribute("npoint")->Value();//->FirstChildElement("northingPoints")->Value() << std::endl;
108
+        //std::cout << tx->FirstChildElement("loop.coordinates")->FirstChildElement("northing.points")->GetText();//->FirstChildElement("northingPoints")->Value() << std::endl;
109
+        for (int it=0; it<ntx; ++it) {
110
+            std::cout << "\nTransmitter " << it << std::endl;
111
+            if (it > 0) tx = tx->NextSiblingElement();
112
+            int npoints = atoi(tx->FirstChildElement("loop.coordinates")->FindAttribute("npoint")->Value());
113
+
114
+            std::cout << "points= " << npoints; // tx->FirstChildElement("loop.coordinates")->FindAttribute("npoint")->Value();//->FirstChildElement("northingPoints")->Value() << std::endl;
115
+            std::vector<Real> LP = ReadLine<Real>( npoints, std::string(tx->FirstChildElement("loop.coordinates")->FirstChildElement("northing.points")->GetText()) );
116
+            for (int ii=0; ii<npoints; ++ii) std::cout << "\t"<< LP[ii] ;
117
+            //std::cout << tx->FirstChildElement("loop.coordinates")->FirstChildElement("northing.points")->GetText();//->FirstChildElement("northingPoints")->Value() << std::endl;
118
+            //std::cout << tx->FirstChildElement("loop.coordinates")->FirstChildElement("easting.points")->GetText();//->FirstChildElement("northingPoints")->Value() << std::endl;
119
+        }
120
+    std::cout << "\nEND system description\n";
121
+
122
+}
123
+
124
+
125
+template <typename T>
126
+std::vector<T> ReadLine( const int& nr, const std::string& line ) {
127
+
128
+    std::vector<T>   lineData;
129
+    std::stringstream  lineStream(line);
130
+
131
+    T value;
132
+    while(lineStream >> value) {
133
+        lineData.push_back(value);
134
+    }
135
+    return lineData;
136
+}
137
+#else
138
+
139
+int main() {
140
+    std::cout << "you have to compile lemma with external tinyxml library to use this" << std::endl;
141
+}
142
+
143
+#endif
144
+
145
+    //--------------------------------------------------------------------------------------
146
+    //       Class:  ASCIIParser
147
+    //      Method:  ReadInts
148
+    //--------------------------------------------------------------------------------------
149
+//     std::vector<int> ReadInts ( const int& nr ) {
150
+//         std::string buf;
151
+//         char *dump = new char[BufferSize];
152
+//         std::vector<int> vals(0);
153
+//         while (input >> buf) {
154
+//             if (buf.substr(0, CommentString.size()) == CommentString) {
155
+//                 input.getline(dump, BufferSize);
156
+//             } else {
157
+//                 vals.push_back( atoi(buf.c_str() ));
158
+//             }
159
+//             if (static_cast<int>(vals.size()) == nr) {
160
+//                 delete [] dump;
161
+//                 return vals;
162
+//             }
163
+//
164
+//         }
165
+//         delete [] dump;
166
+//         return vals;
167
+//     }		// -----  end of method ASCIIParser::ReadInts  -----
168
+

+ 67
- 0
LemmaCore/examples/utYAMLconfig.cpp View File

@@ -0,0 +1,67 @@
1
+#ifdef HAVE_YAMLCPP
2
+
3
+#include "yaml-cpp/yaml.h"
4
+#include "yaml-cpp/eventhandler.h"
5
+#include <fstream>
6
+#include <iostream>
7
+#include <vector>
8
+
9
+struct Params {
10
+	bool hasFile;
11
+	std::string fileName;
12
+};
13
+
14
+Params ParseArgs(int argc, char **argv) {
15
+	Params p;
16
+
17
+	std::vector<std::string> args(argv + 1, argv + argc);
18
+
19
+	return p;
20
+}
21
+
22
+class NullEventHandler: public YAML::EventHandler
23
+{
24
+public:
25
+	virtual void OnDocumentStart(const YAML::Mark&) {}
26
+	virtual void OnDocumentEnd() {}
27
+
28
+	virtual void OnNull(const YAML::Mark&, YAML::anchor_t) {}
29
+	virtual void OnAlias(const YAML::Mark&, YAML::anchor_t) {}
30
+	virtual void OnScalar(const YAML::Mark&, const std::string&, YAML::anchor_t, const std::string&) {}
31
+
32
+	virtual void OnSequenceStart(const YAML::Mark&, const std::string&, YAML::anchor_t) {}
33
+	virtual void OnSequenceEnd() {}
34
+
35
+	virtual void OnMapStart(const YAML::Mark&, const std::string&, YAML::anchor_t) {}
36
+	virtual void OnMapEnd() {}
37
+};
38
+
39
+void parse(std::istream& input)
40
+{
41
+	try {
42
+		YAML::Node doc = YAML::Load(input);
43
+		std::cout << doc << "\n";
44
+	} catch(const YAML::Exception& e) {
45
+		std::cerr << e.what() << "\n";
46
+	}
47
+}
48
+
49
+int main(int argc, char **argv)
50
+{
51
+	Params p = ParseArgs(argc, argv);
52
+
53
+	if(argc > 1) {
54
+		std::ifstream fin;
55
+		fin.open(argv[1]);
56
+		parse(fin);
57
+	} else {
58
+		parse(std::cin);
59
+	}
60
+
61
+	return 0;
62
+}
63
+#else
64
+int main() {
65
+}
66
+#endif
67
+

+ 84
- 0
LemmaCore/examples/utgaussquad.cpp View File

@@ -0,0 +1,84 @@
1
+// ===========================================================================
2
+// 
3
+//       Filename:  utqaussquad.cpp
4
+// 
5
+//    Description:  Test for gaussian quadrature algorithm
6
+// 
7
+//        Version:  0.0
8
+//        Created:  10/05/2010 08:54:26 AM
9
+//       Revision:  none
10
+//       Compiler:  Tested with g++
11
+// 
12
+//         Author:  M. Andy Kass (MAK)
13
+//
14
+//   Organisation:  Colorado School of Mines (CSM)
15
+//                  Broken Spoke Development, LLC
16
+//
17
+//          Email:  mkass@numericalgeo.com
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
+
34
+#include "Lemma"
35
+using namespace Lemma;
36
+using namespace std;
37
+
38
+#ifdef LEMMAUSEVTK
39
+#include "matplot.h"
40
+using namespace matplot;
41
+#endif
42
+
43
+int main() {
44
+
45
+	int N = 600;
46
+	int upb = 5;
47
+	int lowb = -1;
48
+	VectorXr func(N);
49
+	VectorXr wx(N);
50
+	Real integrationres,actres;
51
+
52
+	gaussianquadrature *lgqw = gaussianquadrature::New();
53
+	lgqw->SetFreqs(N,upb,lowb);
54
+	lgqw->CalcAW();
55
+
56
+	wx=lgqw->GetAbscissae();
57
+	func=cos(wx.array());
58
+//	for (int ii=0;ii<N;++ii) {
59
+//		cout << wx(ii) << "  " << func(ii) << endl;
60
+//	}
61
+
62
+	lgqw->SetFunc(func);
63
+	lgqw->Integrate();
64
+	integrationres=lgqw->GetResult();
65
+
66
+	actres = -sin((Real)upb)+sin((Real)lowb);
67
+	
68
+	cout << "Gaussian Quadrature Result: " << integrationres << endl;
69
+	cout << "Actual Result: " << actres << endl;
70
+	
71
+		
72
+	//Plot things
73
+	#ifdef LEMMAUSEVTK
74
+	double colour1[3] = {0.0,0.0,1.0};
75
+
76
+	Plot2D_VTK p1("X", "Y", 800,600);
77
+	p1.plot(wx,func,colour1,".-");
78
+	p1.show();
79
+
80
+	#endif
81
+
82
+	return EXIT_SUCCESS;
83
+}
84
+

+ 258
- 0
LemmaCore/examples/utgmrprint.cpp View File

@@ -0,0 +1,258 @@
1
+// ===========================================================================
2
+//   This file is distributed with Lemma,
3
+//
4
+//       Filename:  utsnmrinversion1d.cpp
5
+//
6
+//        Created:  10/07/2010 08:57:04 AM
7
+//       Compiler:  Tested with g++, icpc, and MSVC 2010
8
+//
9
+//         Author:  Trevor Irons (ti)
10
+//
11
+//   Organisation:  Colorado School of Mines (CSM)
12
+//                  United States Geological Survey (USGS)
13
+//
14
+//          Email:  tirons@mines.edu, tirons@usgs.gov
15
+//
16
+//  This program is free software: you can redistribute it and/or modify
17
+//  it under the terms of the GNU General Public License as published by
18
+//  the Free Software Foundation, either version 3 of the License, or
19
+//  (at your option) any later version.
20
+//
21
+//  This program is distributed in the hope that it will be useful,
22
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
23
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
+//  GNU General Public License for more details.
25
+//
26
+//  You should have received a copy of the GNU General Public License
27
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
28
+//
29
+// ===========================================================================
30
+
31
+/**
32
+  @file
33
+  @author   Trevor Irons
34
+  @date     10/07/2010
35
+  @version   0.0
36
+ **/
37
+
38
+#ifdef LEMMAUSEVTK
39
+#include "vtkRenderer.h"
40
+#include "vtkRenderWindow.h"
41
+#include "vtkRenderWindowInteractor.h"
42
+#include "vtkPNGWriter.h"
43
+#include "vtkRenderLargeImage.h"
44
+#endif
45
+
46
+#include "receiverpoints.h"
47
+#include "emearth1d.h"
48
+#include "PolygonalWireAntenna.h"
49
+
50
+using namespace Lemma;
51
+
52
+std::vector<Real>  readinpfile(const std::string& fname);
53
+
54
+int main(int argc, char** argv) {
55
+
56
+    std::cout <<
57
+    "\n"
58
+    << "hantenna - a programme for computing the h field from polygonal wire\n"
59
+    << "loop sources \n\n"
60
+    << "The following copyrights apply to this application:\n"
61
+    << "Copyright (C) 2009, 2010, 2011, 2012 Colorado School of Mines\n"
62
+    << "Copyright (C) 2009, 2010, 2011, 2012 Trevor Irons\n"
63
+    << "Copyright (C) 2011 Broken Spoke Development, LLC\n\n"
64
+    << "hantenna was built using Lemma (Lemma is an Electromagnetics Modelling API)\n"
65
+    << "More information may be found at https://lemmasoftware.org\n\n"
66
+    << "This program is free software: you can redistribute it and/or modify\n"
67
+    << "it under the terms of the GNU General Public License as published by\n"
68
+    << "the Free Software Foundation, either version 3 of the License, or\n"
69
+    << "(at your option) any later version.\n\n"
70
+
71
+    << "This program is distributed in the hope that it will be useful,\n"
72
+    << "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
73
+    << "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
74
+    << "GNU General Public License for more details.\n\n"
75
+
76
+    << "You should have received a copy of the GNU General Public License\n"
77
+    << "along with this program.  If not, see <http://www.gnu.org/licenses/>.\n\n";
78
+
79
+    if (argc < 4) {
80
+        std::cout << "usage: hantenna.exe  trans.inp cond.inp points.inp \n";
81
+        exit(0);
82
+    }
83
+
84
+    std::vector<Real> Trans   = readinpfile(std::string(argv[1]));
85
+    std::vector<Real> CondMod = readinpfile(std::string(argv[2]));
86
+    std::vector<Real> Points  = readinpfile(std::string(argv[3]));
87
+
88
+    //////////////////////////////////////
89
+    // Define transmitter
90
+    PolygonalWireAntenna* trans = PolygonalWireAntenna::New();
91
+        trans->SetNumberOfPoints((int)(Trans[0]));
92
+        int ip=1;
93
+        for ( ; ip<=(int)(Trans[0])*2; ip+=2) {
94
+            trans->SetPoint(ip/2, Vector3r (Trans[ip], Trans[ip+1], -1e-3));
95
+        }
96
+ 	    trans->SetNumberOfFrequencies(1);
97
+ 	    trans->SetFrequency(0, Trans[ip]);
98
+        trans->SetCurrent(Trans[ip+1]);
99
+
100
+	// Receivers
101
+ 	ReceiverPoints *receivers = ReceiverPoints::New();
102
+        int nx = (int)Points[0];
103
+        int ny = (int)Points[1];
104
+        int nz = (int)Points[2];
105
+        Real ox = Points[3];
106
+        Real oy = Points[4];
107
+        Real oz = Points[5];
108
+     	Vector3r loc;
109
+        VectorXr dx(nx-1); // TODO map the dx, dy, dz vectors
110
+        VectorXr dy(ny-1);
111
+        VectorXr dz(nz-1);
112
+        ip = 6;
113
+        int ir = 0;
114
+        for ( ; ip <6+nx-1; ++ip) {
115
+            dx[ir] = Points[ip];
116
+            ++ir;
117
+        }
118
+        ir = 0;
119
+        for ( ; ip <6+ny-1+nx-1; ++ip) {
120
+            dy[ir] = Points[ip];
121
+            ++ir;
122
+        }
123
+        ir = 0;
124
+        for ( ; ip <6+nz-1+ny-1+nx-1; ++ip) {
125
+            dz[ir] = Points[ip];
126
+            ++ir;
127
+        }
128
+ 		receivers->SetNumberOfReceivers(nx*ny*nz);
129
+ 		ir = 0;
130
+        Real pz  = oz;
131
+ 		for (int iz=0; iz<nz; ++iz) {
132
+ 		    Real py    =  oy;
133
+ 		    for (int iy=0; iy<ny; ++iy) {
134
+ 		        Real px    =  ox;
135
+ 		        for (int ix=0; ix<nx; ++ix) {
136
+ 			        loc << px, py, pz;
137
+ 			        receivers->SetLocation(ir, loc);
138
+ 			        if (ix < nx-1) px += dx[ix];
139
+ 			        ++ ir;
140
+     	        }
141
+                if (iy<ny-1) py += dy[iy];
142
+            }
143
+            if (iz<nz-1) pz += dz[iz];
144
+        }
145
+
146
+    ////////////////////////////////////
147
+    // Define model
148
+    LayeredEarthEM *earth = LayeredEarthEM::New();
149
+    VectorXcr sigma;
150
+    VectorXr  thick;
151
+ 	earth->SetNumberOfLayers(CondMod[0]+1);
152
+ 	sigma.resize(CondMod[0]+1); sigma(0) = 0; // airlayer
153
+    thick.resize(CondMod[0]-1);
154
+    int ilay=1;
155
+    for ( ; ilay/2<CondMod[0]-1; ilay+=2) {
156
+        sigma(ilay/2+1) =  1./CondMod[ilay];
157
+        thick(ilay/2) =  CondMod[ilay+1];
158
+    }
159
+    sigma(ilay/2+1) = 1./ CondMod[ilay];
160
+	earth->SetLayerConductivity(sigma);
161
+    if (thick.size() > 0) earth->SetLayerThickness(thick);
162
+
163
+	EMEarth1D  *EmEarth = EMEarth1D::New();
164
+		EmEarth->AttachWireAntenna(trans);
165
+		EmEarth->AttachLayeredEarthEM(earth);
166
+		EmEarth->AttachReceiverPoints(receivers);
167
+		EmEarth->SetFieldsToCalculate(H);
168
+        EmEarth->CalculateWireAntennaFields();
169
+
170
+    #ifdef LEMMAUSEVTK
171
+	vtkRenderer           *renderer = vtkRenderer::New();
172
+	vtkRenderWindow         *renWin = vtkRenderWindow::New();
173
+	vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
174
+    trans->ApproximateWithElectricDipoles( (VectorXr (3) << 0,0,0).finished() );
175
+	vtkActor **dipActors = new vtkActor*[trans->GetNumberOfDipoles()];
176
+	for (int id=0; id<trans->GetNumberOfDipoles(); ++id) {
177
+		dipActors[id] = trans->GetVtkActor(id);
178
+		renderer->AddActor(dipActors[id]);
179
+	}
180
+    vtkActor *hfield  = receivers->GetVtkGlyphActor (HFIELDREAL, 3, 1e2, 0);
181
+ 	vtkActor *hfieldi = receivers->GetVtkGlyphActor (HFIELDIMAG, 3, 1e2, 0);
182
+    hfieldi->GetProperty()->SetColor(1,0,1);
183
+ 	hfield->GetProperty()->SetColor(0,1,0);
184
+ 	renderer->AddActor(hfield);
185
+ 	renderer->AddActor(hfieldi);
186
+	renderer->SetBackground(0,0,0);
187
+	// Render the window
188
+	renWin->AddRenderer(renderer);
189
+	iren->SetRenderWindow(renWin);
190
+	iren->Initialize();
191
+	iren->Start();
192
+	iren->Render();
193
+	cout << "Enter File name?: ";
194
+	std::string pngName;
195
+	std::cin >> pngName;
196
+	vtkPNGWriter *pngwrite = vtkPNGWriter::New();
197
+	vtkRenderLargeImage *renlarge = vtkRenderLargeImage::New();
198
+	renlarge->SetInput(renderer);
199
+	renlarge->SetMagnification(2);
200
+	pngwrite->SetInputConnection(renlarge->GetOutputPort());
201
+	pngName.append(".png");
202
+	pngwrite->SetFileName(pngName.c_str());
203
+	pngwrite->Write();
204
+	iren->Delete();
205
+	renWin->Delete();
206
+	renderer->Delete();
207
+    #endif
208
+
209
+    ////////////////////////////////////
210
+    // Report
211
+ 	std::fstream hreal("hfield.dat", std::ios::out);
212
+    hreal << *trans << std::endl;
213
+    hreal << *earth << std::endl;
214
+    hreal << "Right hand coordinate system, z is positive down\n";
215
+    hreal << "x[m]\ty[m]\tz[m]\tHx[A/m]\tHy[A/m]\tHz[A/m]\n";
216
+    hreal.precision(8);
217
+    int i=0;
218
+	for (int iz=0; iz<nz; ++iz) {
219
+	for (int iy=0; iy<ny; ++iy) {
220
+	for (int ix=0; ix<nx; ++ix) {
221
+        hreal << receivers->GetLocation(i).transpose() << "\t";
222
+ 		hreal << std::real(receivers->GetHfield(0, i).transpose()[0]) << "\t";
223
+ 		hreal << std::imag(receivers->GetHfield(0, i).transpose()[0]) << "\t";
224
+ 		hreal << std::real(receivers->GetHfield(0, i).transpose()[1]) << "\t";
225
+ 		hreal << std::imag(receivers->GetHfield(0, i).transpose()[1]) << "\t";
226
+ 		hreal << std::real(receivers->GetHfield(0, i).transpose()[2]) << "\t";
227
+ 		hreal << std::imag(receivers->GetHfield(0, i).transpose()[2]) << "\n";
228
+        ++i;
229
+    }
230
+    }
231
+    }
232
+    hreal.close();
233
+
234
+    // Clean up
235
+    EmEarth->Delete();
236
+    earth->Delete();
237
+    receivers->Delete();
238
+    trans->Delete();
239
+}
240
+
241
+std::vector<Real>  readinpfile(const std::string& fname) {
242
+    std::string buf;
243
+    char dump[255];
244
+    std::vector<Real> vals;
245
+    std::fstream input(fname.c_str(), std::ios::in);
246
+    if (input.fail()) {
247
+        std::cerr << "Input file " << fname << " failed to open\n";
248
+        exit(EXIT_FAILURE);
249
+    }
250
+    while (input >> buf) {
251
+        if (buf.substr(0,2) == "//") {
252
+            input.getline(dump, 255);
253
+        } else {
254
+            vals.push_back( atof(buf.c_str() ));
255
+        }
256
+    }
257
+    return vals;
258
+}

+ 93
- 0
LemmaCore/examples/uthankel2.cpp View File

@@ -0,0 +1,93 @@
1
+// ===========================================================================
2
+//
3
+//       Filename:  uthankel2.cpp
4
+//
5
+//    Description:
6
+//
7
+//        Version:  0.0
8
+//        Created:  05/14/2010 10:26:59 AM
9
+//       Revision:  none
10
+//       Compiler:  Tested with g++, icpc, and MSVC 2000
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
+
34
+#include "hankeltransformhankel2.h"
35
+#include "hankeltransformgaussianquadrature.h"
36
+#include "kernelem1d.h"
37
+#include "layeredearthem.h"
38
+
39
+using namespace Lemma;
40
+
41
+int main() {
42
+
43
+	// Define model
44
+	LayeredEarthEM *Earth = LayeredEarthEM::New();
45
+		VectorXcr sigma(3);
46
+		sigma << 0., .1, 0.01;
47
+		VectorXr  thick(1);
48
+		thick << 10;
49
+		Earth->SetNumberOfLayers(3);
50
+		Earth->SetLayerConductivity(sigma);
51
+		Earth->SetLayerThickness(thick);
52
+
53
+	// Source
54
+	// Test with a single dipole
55
+	DipoleSource *dipole = DipoleSource::New();
56
+		dipole->SetMoment(2);
57
+		dipole->SetType(MAGNETICDIPOLE);
58
+		dipole->SetPolarisation(ZPOLARISATION);
59
+		dipole->SetLocation(0,0,0);
60
+		dipole->SetNumberOfFrequencies(1);
61
+		dipole->SetFrequency(0,1000);
62
+		dipole->SetPhase(0);
63
+
64
+	KernelEm1D *Kernel = KernelEm1D::New();
65
+		Kernel->Initialise(Earth);
66
+		Kernel->SetUpSource(dipole, 0);
67
+		Kernel->SetUpReceiver(-0.4);
68
+    //std::vector< KernelEm1DBase* > KernelVec;
69
+    //    KernelVec.push_back( )
70
+
71
+	std::cout.precision(10);
72
+
73
+	Hankel2 *dig = Hankel2::New();
74
+//         dig->ComputeRelated(.23 , Kernel);
75
+//  		std::cout << "  dig->Zgauss "
76
+//  				  << dig->Zgauss(0, TE, 0, 100.,
77
+//  								  1000.*std::sqrt(MU0*EPSILON0), Kernel)
78
+//  			      << std::endl;
79
+
80
+// 	HankelTransformGaussianQuadrature *gauss =
81
+// 			HankelTransformGaussianQuadrature::New();
82
+// 		std::cout << "gauss->Zgauss "
83
+// 				  << gauss->Zgauss(0, TE, 0, 100.,
84
+// 								  1000.*std::sqrt(MU0*EPSILON0), Kernel)
85
+// 			      << std::endl;
86
+
87
+	Earth->Delete();
88
+	dig->Delete();
89
+	//gauss->Delete();
90
+    dipole->Delete();
91
+	Kernel->Delete();
92
+	return EXIT_SUCCESS;
93
+}

+ 257
- 0
LemmaCore/examples/uthantenna.cpp View File

@@ -0,0 +1,257 @@
1
+// ===========================================================================
2
+//
3
+//       Filename:  hantenna.cpp
4
+//
5
+//        Created:  10/07/2010 08:57:04 AM
6
+//       Modified:  14 Aug 2012
7
+//       Compiler:  Tested with g++, icpc, and MSVC 2010
8
+//
9
+//         Author:  Trevor Irons (ti)
10
+//
11
+//       Copyright (C) 2011    Broken Spoke Development, LLC
12
+//       Copyright (C) 2012    Trevor Irons
13
+//
14
+//   Organisation:  Colorado School of Mines (CSM)
15
+//
16
+//          Email:  tirons@mines.edu
17
+//
18
+//  This program is free software: you can redistribute it and/or modify
19
+//  it under the terms of the GNU General Public License as published by
20
+//  the Free Software Foundation, either version 3 of the License, or
21
+//  (at your option) any later version.
22
+//
23
+//  This program is distributed in the hope that it will be useful,
24
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
25
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
+//  GNU General Public License for more details.
27
+//
28
+//  You should have received a copy of the GNU General Public License
29
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
30
+//
31
+// ===========================================================================
32
+
33
+/**
34
+  @file
35
+  @author   Trevor Irons
36
+  @date     10/07/2010
37
+  @version  $Revision: 208 $
38
+  $Id$
39
+ **/
40
+
41
+#include "receiverpoints.h"
42
+#include "emearth1d.h"
43
+#include "PolygonalWireAntenna.h"
44
+#ifdef LEMMAUSEOMP
45
+#include "omp.h"
46
+#endif
47
+
48
+#include "timer.h"
49
+
50
+using namespace Lemma;
51
+
52
+std::vector<Real>  readinpfile(const std::string& fname);
53
+
54
+std::vector<std::string>  readinpfile2(const std::string& fname);
55
+
56
+int main(int argc, char** argv) {
57
+
58
+    std::cout <<
59
+    "\n"
60
+    << "hantenna- $Date: 2015-01-26 10:11:24 -0700 (Mon, 26 Jan 2015) $ $Revision: 208 $\n\n"
61
+    << "hantenna is a programme for computing the h field from polygonal wire\n"
62
+    << "loop sources \n\n"
63
+    << "hantenna was built using Lemma (Lemma is an Electromagnetics Modelling API)\n"
64
+    << "Lemma is Free and Open Source Software (FOSS) and is released under\n"
65
+    << "the MPL, it is covered by the following copyrights:\n"
66
+    << "Copyright (C) 2009, 2010, 2011, 2012      Colorado School of Mines\n"
67
+    << "Copyright (C) 2009, 2010, 2011, 2012      Trevor P. Irons\n"
68
+    << "Copyright (C) 2011, 2012                  M. Andy Kass\n\n"
69
+    << "More information may be found at: https://lemmasoftware.org\n"
70
+    << "                                  info@lemmasoftware.org\n\n"
71
+    << "=====================================================================\n"
72
+    << "This programme is part of Lemma, a geophysical modelling and inversion API \n"
73
+    << "This Source Code Form is subject to the terms of the Mozilla Public\n"
74
+    << "License, v. 2.0. If a copy of the MPL was not distributed with this\n"
75
+    << "file, You can obtain one at http://mozilla.org/MPL/2.0/. \n"
76
+    << "=====================================================================\n\n\n";
77
+
78
+    if (argc < 5) {
79
+        std::cout << "usage: hantenna.exe  trans.inp cond.inp points.inp config.inp \n";
80
+        exit(0);
81
+    }
82
+
83
+    #ifdef LEMMAUSEOMP
84
+    std::cout << "OpenMP is using " << omp_get_max_threads() << " threads" << std::endl;
85
+    #endif
86
+
87
+    std::vector<Real> Trans   = readinpfile(std::string(argv[1]));
88
+    std::vector<Real> CondMod = readinpfile(std::string(argv[2]));
89
+    std::vector<Real> Points  = readinpfile(std::string(argv[3]));
90
+    std::vector<std::string> config  = readinpfile2(std::string(argv[4]));
91
+
92
+    //////////////////////////////////////
93
+    // Define transmitter
94
+    PolygonalWireAntenna* trans = PolygonalWireAntenna::New();
95
+        trans->SetNumberOfPoints((int)(Trans[0]));
96
+        int ip=1;
97
+        for ( ; ip<=(int)(Trans[0])*2; ip+=2) {
98
+            trans->SetPoint(ip/2, Vector3r (Trans[ip], Trans[ip+1], -1e-3));
99
+        }
100
+ 	    trans->SetNumberOfFrequencies(1);
101
+ 	    trans->SetFrequency(0, Trans[ip]);
102
+        trans->SetCurrent(Trans[ip+1]);
103
+        trans->SetMinDipoleRatio(atof(config[1].c_str()));
104
+        trans->SetMinDipoleMoment(atof(config[2].c_str()));
105
+        trans->SetMaxDipoleMoment(atof(config[3].c_str()));
106
+
107
+	// Receivers
108
+ 	ReceiverPoints *receivers = ReceiverPoints::New();
109
+        int nx = (int)Points[0];
110
+        int ny = (int)Points[1];
111
+        int nz = (int)Points[2];
112
+        Real ox = Points[3];
113
+        Real oy = Points[4];
114
+        Real oz = Points[5];
115
+     	Vector3r loc;
116
+        VectorXr dx(nx-1);
117
+        VectorXr dy(ny-1);
118
+        VectorXr dz(nz-1);
119
+        ip = 6;
120
+        int ir = 0;
121
+        for ( ; ip <6+nx-1; ++ip) {
122
+            dx[ir] = Points[ip];
123
+            ++ir;
124
+        }
125
+        ir = 0;
126
+        for ( ; ip <6+ny-1+nx-1; ++ip) {
127
+            dy[ir] = Points[ip];
128
+            ++ir;
129
+        }
130
+        ir = 0;
131
+        for ( ; ip <6+nz-1+ny-1+nx-1; ++ip) {
132
+            dz[ir] = Points[ip];
133
+            ++ir;
134
+        }
135
+ 		receivers->SetNumberOfReceivers(nx*ny*nz);
136
+ 		ir = 0;
137
+        Real pz  = oz;
138
+ 		for (int iz=0; iz<nz; ++iz) {
139
+ 		    Real py    =  oy;
140
+ 		    for (int iy=0; iy<ny; ++iy) {
141
+ 		        Real px    =  ox;
142
+ 		        for (int ix=0; ix<nx; ++ix) {
143
+ 			        loc << px, py, pz;
144
+ 			        receivers->SetLocation(ir, loc);
145
+ 			        if (ix < nx-1) px += dx[ix];
146
+ 			        ++ ir;
147
+     	        }
148
+                if (iy<ny-1) py += dy[iy];
149
+            }
150
+            if (iz<nz-1) pz += dz[iz];
151
+        }
152
+
153
+    ////////////////////////////////////
154
+    // Define model
155
+    LayeredEarthEM *earth = LayeredEarthEM::New();
156
+    VectorXcr sigma;
157
+    VectorXr  thick;
158
+ 	earth->SetNumberOfLayers(CondMod[0]+1);
159
+ 	sigma.resize(CondMod[0]+1); sigma(0) = 0; // airlayer
160
+    thick.resize(CondMod[0]-1);
161
+    int ilay=1;
162
+    for ( ; ilay/2<CondMod[0]-1; ilay+=2) {
163
+        sigma(ilay/2+1) =  1./CondMod[ilay];
164
+        thick(ilay/2) =  CondMod[ilay+1];
165
+    }
166
+    sigma(ilay/2+1) = 1./ CondMod[ilay];
167
+	earth->SetLayerConductivity(sigma);
168
+    if (thick.size() > 0) earth->SetLayerThickness(thick);
169
+
170
+	EMEarth1D  *EmEarth = EMEarth1D::New();
171
+		EmEarth->AttachWireAntenna(trans);
172
+		EmEarth->AttachLayeredEarthEM(earth);
173
+		EmEarth->AttachReceiverPoints(receivers);
174
+		EmEarth->SetFieldsToCalculate(H);
175
+        EmEarth->SetHankelTransformMethod(string2Enum<HANKELTRANSFORMTYPE>(config[0]));
176
+        EmEarth->SetHankelTransformMethod(FHTKEY201);
177
+
178
+	// Keep track of time
179
+	jsw_timer timer;
180
+  	timer.begin();
181
+    clock_t launch = clock();
182
+    EmEarth->CalculateWireAntennaFields(true);    // true=status bar
183
+	Real paTime = timer.end();
184
+
185
+    std::cout << "\n\n===========================================\ncalc. real time: " << paTime/60. << "\t[m]\n";
186
+
187
+    std::cout << "calc. user time: " <<  (clock()-launch)/CLOCKS_PER_SEC/60.   << "\t[CPU m]"
188
+		 << std::endl;
189
+
190
+    ////////////////////////////////////
191
+    // Report
192
+ 	std::fstream hrep("hfield.yaml", std::ios::out);
193
+    std::fstream hreal("hfield.dat", std::ios::out);
194
+
195
+    hrep << *EmEarth << std::endl;
196
+    hrep.close();
197
+    //hreal << *trans << std::endl;
198
+    //hreal << *earth << std::endl;
199
+
200
+    hreal << "// Right hand coordinate system, z is positive down\n";
201
+    hreal << "// x[m]\ty[m]\tz[m]\tHx[A/m]\tHy[A/m]\tHz[A/m]\n";
202
+    hreal.precision(8);
203
+    int i=0;
204
+	for (int iz=0; iz<nz; ++iz) {
205
+	for (int iy=0; iy<ny; ++iy) {
206
+	for (int ix=0; ix<nx; ++ix) {
207
+        hreal << receivers->GetLocation(i).transpose() << "\t";
208
+ 		hreal << receivers->GetHfield(0, i).transpose() << "\n";
209
+        ++i;
210
+    }
211
+    }
212
+    }
213
+    hreal.close();
214
+    // Clean up
215
+    EmEarth->Delete();
216
+    earth->Delete();
217
+    receivers->Delete();
218
+    trans->Delete();
219
+}
220
+
221
+std::vector<Real>  readinpfile(const std::string& fname) {
222
+    std::string buf;
223
+    char dump[255];
224
+    std::vector<Real> vals;
225
+    std::fstream input(fname.c_str(), std::ios::in);
226
+    if (input.fail()) {
227
+        std::cerr << "Input file " << fname << " failed to open\n";
228
+        exit(EXIT_FAILURE);
229
+    }
230
+    while (input >> buf) {
231
+        if (buf.substr(0,2) == "//") {
232
+            input.getline(dump, 255);
233
+        } else {
234
+            vals.push_back( atof(buf.c_str() ));
235
+        }
236
+    }
237
+    return vals;
238
+}
239
+
240
+std::vector<std::string>  readinpfile2(const std::string& fname) {
241
+    std::string buf;
242
+    char dump[255];
243
+    std::vector<std::string> vals;
244
+    std::fstream input(fname.c_str(), std::ios::in);
245
+    if (input.fail()) {
246
+        std::cerr << "Input file " << fname << " failed to open\n";
247
+        exit(EXIT_FAILURE);
248
+    }
249
+    while (input >> buf) {
250
+        if (buf.substr(0,2) == "//") {
251
+            input.getline(dump, 255);
252
+        } else {
253
+            vals.push_back( std::string(buf.c_str() ));
254
+        }
255
+    }
256
+    return vals;
257
+}

+ 218
- 0
LemmaCore/examples/utlogbarriercg.cpp View File

@@ -0,0 +1,218 @@
1
+// ===========================================================================
2
+//
3
+//       Filename:  utlogbarriercg.cpp
4
+//
5
+//        Created:  12/29/2010 09:40:23 AM
6
+//       Compiler:  Tested with g++, icpc, and MSVC 2010
7
+//
8
+//         Author:  Trevor Irons (ti)
9
+//
10
+//   Organisation:  Colorado School of Mines (CSM)
11
+//                  United States Geological Survey (USGS)
12
+//
13
+//          Email:  tirons@mines.edu, tirons@usgs.gov
14
+//
15
+//  This program is free software: you can redistribute it and/or modify
16
+//  it under the terms of the GNU General Public License as published by
17
+//  the Free Software Foundation, either version 3 of the License, or
18
+//  (at your option) any later version.
19
+//
20
+//  This program is distributed in the hope that it will be useful,
21
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
+//  GNU General Public License for more details.
24
+//
25
+//  You should have received a copy of the GNU General Public License
26
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
27
+//
28
+// ===========================================================================
29
+
30
+/**
31
+  @file
32
+  @author   Trevor Irons
33
+  @date     12/29/2010
34
+  @version   0.0
35
+ **/
36
+
37
+#include "LemmaObject.h"
38
+//#include "logbarriercg.h"
39
+//#include "datasnmr.h"
40
+#include <ctime>
41
+
42
+#ifdef HAVEBOOSTRANDOM
43
+#include <boost/random.hpp>
44
+#include <boost/random/normal_distribution.hpp>
45
+#endif
46
+
47
+using namespace std;
48
+using namespace Lemma;
49
+
50
+MatrixXr BuildG(const Real& T2, const Real& Larmor, const Real& T,
51
+        const Real& dt, const VectorXr& nT2Bins, const Real& scale);
52
+
53
+MatrixXr BuildGw(const Real& T2, const Real& Larmor, const Real& T,
54
+        const Real& dt, const VectorXr& nT2Bins, const Real& scale,
55
+        const VectorXr& freqs);
56
+
57
+/// test driver program for log-barrier optimization algorithm
58
+int main() {
59
+    return 0;
60
+}
61
+
62
+#ifdef AA
63
+    // Parameters
64
+    Real T2(.200);
65
+    Real Larmor(2000); // Hz
66
+    Real wL = 2.*PI * Larmor;
67
+    Real T(.6);
68
+    Real dt(1e-4);
69
+    int  nT2(20);
70
+    Real T2Low(.020);
71
+    Real T2Hi(.220);
72
+
73
+    // T2 bins
74
+    VectorXr T2Bins = VectorXr::LinSpaced(nT2, T2Low, T2Hi);
75
+
76
+    // Build true model
77
+    VectorXr m = VectorXr::Zero(T2Bins.size());
78
+    //m[4]  = .15;
79
+    //m[5]  = .15;
80
+    //m[6]  = .15;
81
+    m[7]  = .15;
82
+    m[8]  = .15;
83
+    m[11] = .15;
84
+    m[12] = .15;
85
+    m[13] = .15;
86
+    m[14] = .15;
87
+
88
+    // Build G
89
+    srand ( std::time(NULL) );
90
+    Real scale = 1e-4*std::abs(VectorXr::Random(1)[0]);
91
+    MatrixXr G = BuildG(T2, wL, T, dt, T2Bins, scale);
92
+
93
+    #ifdef HAVEBOOSTRANDOM
94
+    Real mean = 0;
95
+    Real variance = scale*.05*(.5+.15);
96
+    boost::mt19937 randgen(static_cast<unsigned int> (std::time(0)));
97
+    boost::normal_distribution<Real> noise(mean, variance);
98
+    boost::variate_generator<boost::mt19937, boost::normal_distribution<Real> > nD(randgen, noise);
99
+    VectorXr noisy = G*m;
100
+//     for (int i=0; i < noisy.size(); ++i) {
101
+//        noisy(i) += nD();
102
+//     }
103
+    #else
104
+    VectorXr d = G * m;
105
+    VectorXr noisy = d.array();// + .05*( .5 + .15 ) *Eigen::ArrayXd::Random(d.size());
106
+    #endif
107
+
108
+    // Clean Data, and 10% random noise data
109
+    VectorXr RefMod = VectorXr::Zero(m.size());
110
+
111
+    // todo let alpha's be set.
112
+    Real alpha_s  =  .0;
113
+    Real alpha_t2 = 1.0;
114
+    Eigen::SparseMatrix<Real> Wd (G.rows(), G.rows());
115
+    Eigen::SparseMatrix<Real> Wm (G.cols(), G.cols());
116
+
117
+    /////////////////
118
+    // Model objective function
119
+    int ii = 0;
120
+    for (int iT2=0; iT2<nT2; ++iT2) {
121
+        Wm.coeffRef(ii, ii) += alpha_s - alpha_t2;
122
+        if (iT2 < nT2-1) {
123
+            Wm.coeffRef(ii, ii+1) += alpha_t2;
124
+        }
125
+        ++ii;
126
+    }
127
+    Wm.finalize();
128
+    std::fstream  WmOut( "wmMatrix.dat" , std::ios::out);
129
+    WmOut << Wm << std::endl;
130
+    WmOut.close();
131
+
132
+    // Data objective function
133
+    /// @todo add measure of suspected std dev to this.
134
+    for (int id=0; id<G.rows(); ++id) {
135
+        Wd.coeffRef(id, id) = 1.; // 1/sigma(i);
136
+    }
137
+    Wd.finalize();
138
+
139
+    // invert time-domain sinusoid exponent
140
+    //LogBarrierCG(G, RefMod, noisy, (Real)0., (Real)1e5, nT2, Wd, Wm, scale*1e1);
141
+    return EXIT_SUCCESS;
142
+
143
+//     #if 0
144
+//     // invert FD
145
+//     Eigen::FFT<Real> fft;
146
+//     fft.SetFlag(fft.HalfSpectrum);
147
+//     VectorXcr dw;
148
+//     fft.fwd(dw, noisy);
149
+//
150
+//     // Compute freqs Hz
151
+//     VectorXr freqs = DataSNMR::GetNMRSampledFrequencies(T/dt, dt);
152
+//     Real df = freqs[1];
153
+//     Real window = 300; // Hz
154
+//     int iL = (int)(Larmor/df);
155
+//     MatrixXr Gw = BuildGw(T2, wL, T, dt, T2Bins, scale, freqs.segment(iL-window/2, window));
156
+//
157
+//     VectorXr dwu = VectorXr::Zero(2.*window);
158
+//     dwu.head(window) = dw.segment(iL-window/2, window).real();
159
+//     dwu.tail(window) = dw.segment(iL-window/2, window).imag();
160
+//
161
+//     Eigen::DynamicSparseMatrix<Real> Wdw (Gw.rows(), Gw.rows());
162
+//     for (int id=0; id<Gw.rows(); ++id) {
163
+//         Wdw.coeffRef(id, id) = 1.; // 1/sigma(i);
164
+//     }
165
+//     Wdw.finalize();
166
+//     std::cout << "psize " << (Gw*RefMod).size() << std::endl;
167
+//     VectorXr dw2 = Gw*m;
168
+//     //std::cout << dw2 << std::endl;
169
+//     std::cout << "Gw " << Gw.rows() << "\t" << Gw.cols() << std::endl;
170
+//     std::cout << "dwu " << dwu.size() << std::endl;
171
+//     //RefMod.array() += .1;
172
+//     VectorXr mod = LogBarrierCG(Gw, RefMod, dwu, 0., 3., nT2, Wdw, Wm,scale*1e5);
173
+//     //VectorXr mod = LogBarrierCG(Gw, dwu, 0., 1e5);
174
+//
175
+//     std::fstream Gws("gw.out", std::ios::out);
176
+//     Gws << Gw << std::endl;
177
+//     Gws.close();
178
+//     #endif
179
+}
180
+
181
+#endif
182
+
183
+MatrixXr BuildG(const Real& T2, const Real& wL, const Real& T,
184
+            const Real& dt, const VectorXr& T2Bins, const Real& scale) {
185
+    std::cout << "scale " << scale << std::endl;
186
+    int nt = T/dt;
187
+    int nT2 = T2Bins.size();
188
+    MatrixXr G = MatrixXr::Zero(nt,nT2);
189
+    for (int iT2=0; iT2<nT2; ++iT2) {
190
+        Real t=0;
191
+        for (int it=0; it<nt; ++it) {
192
+            G(it, iT2) = scale * exp(-t/T2Bins(iT2)) * sin(wL * t);
193
+            t += dt;
194
+        }
195
+    }
196
+    return G;
197
+}
198
+
199
+
200
+MatrixXr BuildGw(const Real& T2, const Real& wL, const Real& T,
201
+            const Real& dt, const VectorXr& T2Bins, const Real& scale,
202
+            const VectorXr &freqs) {
203
+    VectorXr omegas = freqs.array() * 2.*PI;
204
+    std::cout << "scale " << scale << std::endl;
205
+    int nT2 = T2Bins.size();
206
+    MatrixXr Gw = MatrixXr::Zero(2*freqs.size(), nT2);
207
+    int nW = freqs.size();
208
+    Real sc = 1./dt;
209
+    for (int iT2=0; iT2<nT2; ++iT2) {
210
+        for (int iw=0; iw<freqs.size(); ++iw) {
211
+            Real a = 1./T2Bins(iT2);
212
+            Complex T = wL / ( wL*wL + (a+Complex(0, omegas[iw]))*(a+Complex(0,omegas[iw])) ) ;
213
+            Gw(iw, iT2)     = sc * scale * std::real(T);
214
+            Gw(iw+nW, iT2) = sc * scale * std::imag(T);
215
+        }
216
+    }
217
+    return Gw;
218
+}

+ 67
- 0
LemmaCore/examples/utpolygonalantenna.cpp View File

@@ -0,0 +1,67 @@
1
+// ===========================================================================
2
+//
3
+//       Filename:  utpolygonalantennae.cpp
4
+//
5
+//    Description:  Unit test of PolygonalAntenna
6
+//
7
+//        Version:  0.0
8
+//        Created:  05/26/2010 04:30:56 PM
9
+//       Revision:  none
10
+//       Compiler:  Tested with g++, icpc, and MSVC 2000
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
+
34
+#include "Lemma"
35
+
36
+using namespace Lemma;
37
+
38
+int main() {
39
+
40
+    PolygonalWireAntenna *pa = PolygonalWireAntenna::New();
41
+        pa->SetNumberOfPoints(5);
42
+        pa->SetPoint(0, Vector3r(  0,  0, -1e-3));
43
+        pa->SetPoint(1, Vector3r( 10,  0, -1e-3));
44
+        pa->SetPoint(2, Vector3r( 10, 10, -1e-3));
45
+        pa->SetPoint(3, Vector3r(  0, 10, -1e-3));
46
+        pa->SetPoint(4, Vector3r(  0,  0, -1e-3));
47
+        pa->SetNumberOfFrequencies(1);
48
+        pa->SetFrequency(0,1000.);
49
+        pa->SetCurrent(10.);
50
+        pa->SetNumberOfTurns(1);
51
+
52
+    Vector3r pos;
53
+    pos << 23,23,23;
54
+    pa->ApproximateWithElectricDipoles(pos);
55
+    std::cout << "pos "<< pos.transpose() << "  ndipoles="
56
+              << pa->GetNumberOfDipoles() << std::endl;
57
+    pos << 2,2,2;
58
+    pa->ApproximateWithElectricDipoles(pos);
59
+    std::cout << "pos "<< pos.transpose() << "  ndipoles="
60
+              << pa->GetNumberOfDipoles() << std::endl;
61
+    pos << 1,1,1;
62
+    pa->ApproximateWithElectricDipoles(pos);
63
+    std::cout << "pos "<< pos.transpose() << "  ndipoles="
64
+              << pa->GetNumberOfDipoles() << std::endl;
65
+
66
+    pa->Delete();
67
+}

+ 68
- 0
LemmaCore/examples/utreadfemubc.cpp View File

@@ -0,0 +1,68 @@
1
+// ===========================================================================
2
+// 
3
+//       Filename:  utreadfemubc.cpp
4
+// 
5
+//    Description:  
6
+// 
7
+//        Version:  0.0
8
+//        Created:  01/03/2013 02:47:24 PM
9
+//       Revision:  none
10
+//       Compiler:  Tested with g++ 
11
+// 
12
+//         Author:  M. Andy Kass (MAK)
13
+//
14
+//   Organisation:  Broken Spoke Development, LLC
15
+//                  
16
+//
17
+//          Email:  mkass@numericalgeo.com
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
+
34
+#include "Lemma"
35
+
36
+using namespace Lemma;
37
+
38
+#ifdef LEMMAUSEVTK
39
+#include "matplot.h"
40
+using namespace matplot;
41
+#endif
42
+
43
+int main() {
44
+
45
+	std::string datfile;
46
+
47
+	datfile = "126.obs";
48
+	
49
+	DataReaderFemUBC* Reader = DataReaderFemUBC::New();
50
+	DataFEM* thedata = DataFEM::New();
51
+
52
+	Reader->SetDataFEM(thedata);
53
+
54
+	try {
55
+	Reader->ReadData(datfile,1);
56
+	} catch(std::exception& e) {
57
+		exit(EXIT_FAILURE);
58
+	}
59
+
60
+	std::cout << *Reader << std::endl;
61
+	std::cout << *thedata << std::endl;
62
+
63
+
64
+	thedata->Delete();
65
+	Reader->Delete();
66
+
67
+	return EXIT_SUCCESS;
68
+}

+ 54
- 0
LemmaCore/examples/utsandbox.cpp View File

@@ -0,0 +1,54 @@
1
+// ===========================================================================
2
+//
3
+//       Filename:  utsandbox.cpp
4
+//
5
+//        Created:  07/29/2010 10:34:23 AM
6
+//       Compiler:  Tested with g++, icpc, and MSVC 2010
7
+//
8
+//         Author:  Trevor Irons (ti)
9
+//
10
+//   Organisation:  Colorado School of Mines (CSM)
11
+//                  United States Geological Survey (USGS)
12
+//
13
+//          Email:  tirons@mines.edu, tirons@usgs.gov
14
+//
15
+//  This program is free software: you can redistribute it and/or modify
16
+//  it under the terms of the GNU General Public License as published by
17
+//  the Free Software Foundation, either version 3 of the License, or
18
+//  (at your option) any later version.
19
+//
20
+//  This program is distributed in the hope that it will be useful,
21
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
+//  GNU General Public License for more details.
24
+//
25
+//  You should have received a copy of the GNU General Public License
26
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
27
+//
28
+// ===========================================================================
29
+
30
+/**
31
+  @file test sandbox helm1rameters
32
+  @author   Trevor Irons
33
+  @date     07/29/2010
34
+  @version   0.0
35
+ **/
36
+
37
+#include "Lemma"
38
+
39
+using namespace Lemma;
40
+
41
+int main() {
42
+
43
+    PolygonalWireAntenna *helm1 = PolygonalWireAntenna::New();
44
+	helm1->SetNumberOfFrequencies(1);
45
+	helm1->SetFrequency(0, 1000);
46
+	helm1->SetNumberOfPoints(5);
47
+	helm1->SetPoint(0, Vector3r(   0,   0, 0));
48
+	helm1->SetPoint(1, Vector3r(   0,   0, 0));
49
+	helm1->SetPoint(2, Vector3r(   0,   0, 0));
50
+	helm1->SetPoint(3, Vector3r(   0,   0, 0));
51
+	helm1->SetPoint(4, Vector3r(   0,   0, 0));
52
+	helm1->SetCurrent(1.);
53
+    helm1->Delete();
54
+}

+ 199
- 0
LemmaCore/examples/uttemforward.cpp View File

@@ -0,0 +1,199 @@
1
+// ===========================================================================
2
+//
3
+//       Filename:  uttemforward.cpp
4
+//
5
+//    Description:  TEM Forward Modeller
6
+//
7
+//        Version:  0.0
8
+//        Created:  02/10/2011 03:32:18 PM
9
+//       Revision:  none
10
+//       Compiler:  Tested with g++, icpc, and MSVC 2000
11
+//
12
+//         Author:  M. Andy Kass (MAK)
13
+//
14
+//		Copyright:  2011 Trevor Irons and M. Andy Kass
15
+//
16
+//   Organisation:  Colorado School of Mines (CSM)
17
+//                  Broken Spoke Development, LLC
18
+//
19
+//          Email:  mkass@numericalgeo.com
20
+//
21
+//  This program is free software: you can redistribute it and/or modify
22
+//  it under the terms of the GNU General Public License as published by
23
+//  the Free Software Foundation, either version 3 of the License, or
24
+//  (at your option) any later version.
25
+//
26
+//  This program is distributed in the hope that it will be useful,
27
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
28
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29
+//  GNU General Public License for more details.
30
+//
31
+//  You should have received a copy of the GNU General Public License
32
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
33
+//
34
+// ===========================================================================
35
+
36
+#include <time.h>
37
+#include "Lemma"
38
+#include "banner.h"
39
+
40
+using namespace Lemma;
41
+
42
+#ifdef LEMMAUSEVTK
43
+#include "matplot.h"
44
+using namespace matplot;
45
+#endif
46
+
47
+int main(int argv, char** argc) {
48
+
49
+	// Just for timing
50
+	clock_t launch =clock();
51
+
52
+	// Banner display
53
+	std::string name;
54
+	std::string version;
55
+	std::string usage;
56
+	name = "TEM Forward Modeller - 1D";
57
+	version = "1.0beta";
58
+	usage = "temforward1d [inputfile]";
59
+	banner(name,version,usage);
60
+    if ( argv < 2 ) {
61
+        std::cout << "No input file specified, should be of format\n";
62
+        std::cout <<
63
+"origparabk.obsy        ! Observations-style file.\n\
64
+origpara.con           ! Starting model.\n\
65
+100                    ! Number of Hankel kernel evaluations.\n\
66
+100 1. 1.0E+10         ! Number of Fourier kernel evaluations, & min & max freq.\n\
67
+N                      ! Is noise to be added?\n\
68
+5.  1.0E-08  30        ! Noise to be added: percentage, threshold, seed.\n\
69
+" << std::endl;
70
+
71
+        exit(0);
72
+    }
73
+
74
+	time_t curr=time(0);
75
+	std::cout << std::endl;
76
+	std::cout << "  Start time: " << ctime(&curr) << std::endl;
77
+
78
+	// Define objects
79
+	PolygonalWireAntenna* Trans = PolygonalWireAntenna::New();
80
+//     PolygonalWireAntenna* pa = PolygonalWireAntenna::New();
81
+//         pa->SetNumberOfPoints(5);
82
+// 	    pa->SetPoint(0, Vector3r(   0,   0, -30.001));
83
+// 	    pa->SetPoint(1, Vector3r(   0,  20, -35.001));
84
+// 	    pa->SetPoint(2, Vector3r(  20 , 20, -35.001));
85
+// 	    pa->SetPoint(3, Vector3r(  20,   0, -30.001));
86
+// 	    pa->SetPoint(4, Vector3r(   0,   0, -30.001));
87
+// 	    pa->SetCurrent(100.);
88
+//         pa->SetNumberOfTurns(1);
89
+
90
+
91
+	//DipoleSource* Trans = DipoleSource::New();
92
+	ReceiverPoints *Receivers = ReceiverPoints::New();
93
+	LayeredEarthEM *Earth = LayeredEarthEM::New();
94
+	VectorXr maintimes;
95
+
96
+    /////////////////////////////////////
97
+	// Using model reader
98
+	ModelReaderTem1DUBC* Reader = ModelReaderTem1DUBC::New();
99
+	    Reader->SetEMEarth1D(Earth);
100
+	    Reader->SetTransmitter(Trans);
101
+	    Reader->SetReceiver(Receivers);
102
+	    Reader->ReadParameters( argc[1] );
103
+	    maintimes = Reader->GetTimes();
104
+
105
+	// Attach it to instrumentTEM
106
+	InstrumentTem *instrument = InstrumentTem::New();
107
+	    instrument->EMEarthModel(Earth);
108
+	    instrument->SetTransmitLoop(Trans);
109
+	    //instrument->SetTransmitLoop(pa);
110
+	    //instrument->SetDipoleSource(Trans);
111
+	    instrument->SetReceiver(Receivers);
112
+
113
+
114
+
115
+        // TODO need to input these
116
+        VectorXr widths = VectorXr::Ones(maintimes.size()); // * 1e-5;
117
+        /*
118
+        widths.segment(0,5).array()  *= 5e-6;
119
+        widths.segment(5,5).array()  *= 1e-5;
120
+        widths.segment(10,5).array() *= 5e-5;
121
+        widths.segment(15,5).array() *= 2e-4;
122
+        widths.segment(20,5).array() *= 4e-4;
123
+        //widths.segment(25,5).array() *= 4e-4;
124
+        */
125
+        /*
126
+        widths << .48,4.,8.,8.,8.,8.,8.,12.,12.,12.,16.,16.,16.,20.,24.,24.,28.,32.,32.,36.,40.,44.,52.,
127
+  				56.,64.,68.,76.,88.,96.,104.,120.,132.,144.,160.,180.,200.,220.,248.,272.,304.,336.,376.,
128
+  				416.,464.,516.,572.,636.,708.,784.,872.,968.,1076.,1196.,1328.,1476.,1640.,1824.,2024.,
129
+  				2248.,2500. ;
130
+        */
131
+        widths *= 1e-6;
132
+        std::cout << widths.transpose() << std::endl;
133
+
134
+        instrument->SetReferenceTime(.025);
135
+        //instrument->SetReferenceTime(.025);
136
+	    instrument->SetTimeGates(maintimes, widths);
137
+
138
+        //instrument->SetReceiverType(MAGNETOMETER);
139
+        instrument->SetReceiverType(INDUCTIVE);
140
+        // Set the pulse
141
+        VectorXr Amp(4); Amp << 0,1,1,0;
142
+        VectorXr Times(4); Times << 0., .0005, .02497, .025;
143
+
144
+        //VectorXr Amp(4); Amp << 0,1,1,0;
145
+        //VectorXr Times(4); Times << -0.025, -0.0245, -0.00003, 0.0;
146
+        //instrument->SetPulse(Amp, Times);
147
+
148
+        //VectorXr Amp(3); Amp << 0,1,0;
149
+        //VectorXr Times(3); Times << 0, .015, .030;
150
+        //instrument->SetPulse(Amp, Times);
151
+
152
+        //VectorXr Amp(3); Amp << 0,1,0;
153
+        //VectorXr Times(3); Times << 0, .01, .020;
154
+        instrument->SetPulse(Amp, Times);
155
+
156
+    std::cout << *Earth << "\n" << *Trans << "\n" << *Receivers << std::endl;
157
+
158
+	// Perform the forward model
159
+	//instrument->MakeDirectCalculation( FHTKEY201  );
160
+	//instrument->MakeLaggedCalculation( ANDERSON801 );
161
+	//instrument->MakeLaggedCalculation( QWEKEY );
162
+	//instrument->MakeLaggedCalculation( CHAVE );
163
+	instrument->MakeLaggedCalculation( FHTKEY201 );
164
+	//instrument->MakeLaggedCalculation( FHTKEY101 );
165
+
166
+    int nlag = instrument->GetMeasurements().rows();
167
+	// Output results to screen
168
+	for (int ii=0; ii<nlag; ii++) {
169
+		std::cout<<"  "<<instrument->GetMeasurements()(ii,0)<<"  "<<instrument->GetMeasurements()(ii,1)<<std::endl;
170
+	}
171
+
172
+	// Output results to file
173
+	std::ofstream outfile1;
174
+	outfile1.open("solution.out");
175
+    //outfile1 << "//timegate [ms]\t dB/dt [nT/s]" << std::endl;
176
+    outfile1 << "//timegate [s]\t dB/dt [T/s]" << std::endl;
177
+	for (int ii=0; ii<nlag; ii++) {
178
+		//outfile1 << 1e3*instrument->GetMeasurements()(ii,0)<< "\t" << (MU0*1e9)*instrument->GetMeasurements()(ii,1)<<std::endl;
179
+		outfile1 << instrument->GetMeasurements()(ii,0)<< "\t" << MU0*instrument->GetMeasurements()(ii,1) << std::endl;
180
+		//outfile1 << instrument->GetMeasurements()(ii,0)<< "\t" << instrument->GetMeasurements()(ii,1)<<std::endl;
181
+	}
182
+	outfile1.close();
183
+
184
+
185
+	// Timing stuff
186
+	std::cout << "  Time for execution: " <<  (clock()-launch)/CLOCKS_PER_SEC   << " [CPU] seconds."
187
+		 << std::endl;
188
+
189
+
190
+	instrument->Delete();
191
+	Trans->Delete();
192
+	Earth->Delete();
193
+	Receivers->Delete();
194
+	Reader->Delete();
195
+
196
+	return EXIT_SUCCESS;
197
+}
198
+
199
+

+ 131
- 0
LemmaCore/examples/utteminv1d.cpp View File

@@ -0,0 +1,131 @@
1
+// ===========================================================================
2
+//
3
+//       Filename:  utteminv1d.cpp
4
+//
5
+//    Description:  Invert for the difference in water table
6
+//
7
+//        Version:  0.0
8
+//        Created:  03/23/2011 02:07:19 PM
9
+//       Revision:  none
10
+//       Compiler:  Tested with g++, icpc, and MSVC 2000
11
+//
12
+//         Author:  M. Andy Kass (MAK)
13
+//
14
+//   Organisation:  Colorado School of Mines (CSM)
15
+//                  Broken Spoke Development, LLC
16
+//
17
+//          Email:  mkass@numericalgeo.com
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
+
34
+#include "Lemma"
35
+#include "banner.h"
36
+
37
+using namespace Lemma;
38
+
39
+int main () {
40
+
41
+	VectorXr maintimes;
42
+	int ntimes;
43
+
44
+	//Banner
45
+	std::string name;
46
+	std::string version;
47
+	std::string usage;
48
+	name = "TEM Inversion - 1D";
49
+	version = "1.0beta";
50
+	usage = "teminv1d [inputfile]";
51
+	banner(name,version,usage);
52
+
53
+	PolygonalWireAntenna* Trans = PolygonalWireAntenna::New();
54
+	ReceiverPoints* Receivers = ReceiverPoints::New();
55
+	LayeredEarthEM* StartingMod = LayeredEarthEM::New();
56
+	//LayeredEarthEM* RecoveredMod = LayeredEarthEM::New();
57
+	InverseSolverTEM1D* Inverse = InverseSolverTEM1D::New();
58
+
59
+
60
+	Trans->SetNumberOfPoints(5);
61
+    Trans->SetPoint(0, Vector3r(   0,   0, -1e-3));
62
+    Trans->SetPoint(1, Vector3r( 100,   0, -1e-3));
63
+    Trans->SetPoint(2, Vector3r( 100, 100, -1e-3));
64
+    Trans->SetPoint(3, Vector3r(   0, 100, -1e-3));
65
+    Trans->SetPoint(4, Vector3r(   0,   0, -1e-3));
66
+	Trans->SetCurrent(1);
67
+	Trans->SetNumberOfTurns(1);
68
+    Trans->SetMinDipoleRatio(1/2.);
69
+
70
+	Vector3r loc;
71
+	Real ox = 50.;
72
+	Real oy = 50.;
73
+	Real depth = -1.e-3;
74
+	Receivers->SetNumberOfReceivers(1);
75
+	loc << ox,oy,depth;
76
+	Receivers->SetLocation(0,loc);
77
+
78
+	StartingMod->SetNumberOfLayers(22);
79
+	StartingMod->SetLayerConductivity( (VectorXcr(22) << 0.,1.e-3,
80
+		1.e-3,1.e-3,1.e-3,1.e-3,1.e-3,1.e-3,1.e-3,1.e-3,1.e-3,1.e-3,1.e-3,
81
+		1.e-3,1.e-3,1.e-3,1.e-3,1.e-3,1.e-3,1.e-3,1.e-3,1.e-3).finished() );
82
+	StartingMod->SetLayerThickness((VectorXr(20)<<4,4,4,4,4,4,4,4,4,4,4,4,4,
83
+		4,4,4,4,4,4,4).finished());
84
+	//EM-47 gate times
85
+	ntimes = 30;
86
+	maintimes.resize(ntimes);
87
+	maintimes << 36.,45.25,57.,72.25,92.,117.,148.,186.5,234.,290.,
88
+		352.5,427.5,525.,647.5,802.5,1002.5,1257.5,1582.5,1997.5,2525.,
89
+		3197.5,4055.,5147.5,6542.5,8322.5,10592.,13490.,17187.,21902.,
90
+		27915.;
91
+	maintimes = maintimes.array() /1000000;
92
+
93
+	Inverse->AttachStartMod(StartingMod);
94
+	Inverse->AttachWireAntenna(Trans);
95
+	Inverse->AttachReceiver(Receivers);
96
+	Inverse->SetTimes(maintimes);
97
+	LayeredEarthEM* RecoveredMod = StartingMod->Clone();
98
+	Inverse->AttachRecMod(RecoveredMod);
99
+
100
+	//Read input data - temp for SEG!
101
+	/// TODO write a TEM data reader class.  and a functional TEM data class
102
+	std::fstream infile("rotateddat.dat",std::ios::in);
103
+	if (infile.fail()) {
104
+		std::cout << "Shit!" << std::endl;
105
+	}
106
+	MatrixXr rotinpdata;
107
+	rotinpdata.resize(30,1);
108
+	for (int ii=0;ii<30;ii++) {
109
+		infile >> rotinpdata(ii);
110
+	}
111
+	infile.close();
112
+
113
+
114
+	Inverse->AttachMeasuredData(rotinpdata);
115
+	//Inverse->SetFreeParams( (VectorXi(2)<<0,1).finished(),
116
+	//	(VectorXi(3)<<1,2,3).finished());
117
+
118
+	std::cout << *Inverse << std::endl;
119
+
120
+	Inverse->Calculate();
121
+	//Inverse->ShowSoln();
122
+	//Inverse->WriteSoln("temp.dat");
123
+
124
+	Inverse->Delete();
125
+	RecoveredMod->Delete();
126
+	StartingMod->Delete();
127
+	Receivers->Delete();
128
+	Trans->Delete();
129
+
130
+	return EXIT_SUCCESS;
131
+}

+ 84
- 0
LemmaCore/examples/uttemreader.cpp View File

@@ -0,0 +1,84 @@
1
+// ===========================================================================
2
+// 
3
+//       Filename:  uttemreader.cpp
4
+// 
5
+//    Description:  
6
+// 
7
+//        Version:  0.0
8
+//        Created:  02/19/2011 12:30:59 PM
9
+//       Revision:  none
10
+//       Compiler:  Tested with g++, icpc, and MSVC 2000 
11
+// 
12
+//         Author:  M. Andy Kass (MAK)
13
+//
14
+//   Organisation:  Colorado School of Mines (CSM)
15
+//                  Broken Spoke Brewery, LLC
16
+//
17
+//          Email:  mkass@numericalgeo.com
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
+
34
+#include "Lemma"
35
+
36
+using namespace Lemma;
37
+
38
+
39
+int main() {
40
+
41
+	/*
42
+	ModelReaderTem1DUBC* Reader = ModelReaderTem1DUBC::New();
43
+	PolygonalWireAntenna* Trans = PolygonalWireAntenna::New();
44
+	ReceiverPoints *Receivers = ReceiverPoints::New();
45
+	LayeredEarthEM *Earth = LayeredEarthEM::New();
46
+	Reader->SetEMEarth1D(Earth);
47
+	Reader->SetTransmitter(Trans);
48
+	Reader->SetReceiver(Receivers);
49
+	Reader->ReadParameters("em1dtmfwd.in");
50
+
51
+	Reader->Delete();
52
+	Earth->Delete();
53
+	Receivers->Delete();
54
+	Trans->Delete();
55
+	*/
56
+
57
+	int rnObs;
58
+	int rnGates;
59
+	std::string inputfile;
60
+	MatrixXr somedata;
61
+	Vector3Xr somepositions;
62
+
63
+	DataTEM* TheData = DataTEM::New();
64
+	DataReaderTem* Reader = DataReaderTem::New();
65
+
66
+	inputfile = "temreadertest.txt";
67
+
68
+	Reader->SetDataTEM(TheData);
69
+	Reader->ReadData(inputfile);
70
+
71
+	rnObs = TheData->GetnObs();
72
+	rnGates = TheData->GetnGates();
73
+	somedata = TheData->GetData();
74
+	somepositions = TheData->GetPositions();
75
+
76
+	std::cout << rnObs << " " << rnGates << std::endl;
77
+	std::cout << somedata << std::endl;
78
+	std::cout << somepositions << std::endl;
79
+
80
+	Reader->Delete();
81
+	TheData->Delete();
82
+
83
+	return EXIT_SUCCESS;
84
+}

+ 207
- 0
LemmaCore/examples/uttemsandbox.cpp View File

@@ -0,0 +1,207 @@
1
+// ===========================================================================
2
+//
3
+//       Filename:  uttemsandbox.cpp
4
+//
5
+//        Created:  09/29/2010 07:38:26 AM
6
+//       Compiler:  Tested with g++, icpc, and MSVC 2010
7
+//
8
+//         Author:  Trevor Irons (ti), M. Andy Kass
9
+//
10
+//
11
+//   Organisation:  Colorado School of Mines (CSM)
12
+//                  United States Geological Survey (USGS)
13
+//					Broken Spoke Development, LLC
14
+//
15
+//          Email:  tirons@mines.edu, tirons@usgs.gov
16
+//					mkass@numericalgeo.com
17
+//
18
+//  This program is free software: you can redistribute it and/or modify
19
+//  it under the terms of the GNU General Public License as published by
20
+//  the Free Software Foundation, either version 3 of the License, or
21
+//  (at your option) any later version.
22
+//
23
+//  This program is distributed in the hope that it will be useful,
24
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
25
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
+//  GNU General Public License for more details.
27
+//
28
+//  You should have received a copy of the GNU General Public License
29
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
30
+//
31
+// ===========================================================================
32
+
33
+/**
34
+  @file
35
+  @author   Trevor Irons
36
+  @date     09/29/2010
37
+  @version   0.0
38
+ **/
39
+
40
+#include "Lemma"
41
+using namespace Lemma;
42
+
43
+#ifdef LEMMAUSEVTK
44
+#include "matplot.h"
45
+using namespace matplot;
46
+#endif
47
+
48
+int main() {
49
+
50
+
51
+    int nfreq  =    6000;  // Number of frequencies
52
+
53
+	// Specify receiver times
54
+	int ntimes	=	30;
55
+	VectorXr times(ntimes);
56
+	times <<
57
+	36.0, 45.25, 57.0, 72.25, 92.0,
58
+	117.0, 148.0, 186.5, 234.0, 290.0,
59
+	352.5, 427.5, 525.0, 647.5, 802.5,
60
+	1002.5, 1257.5, 1582.5, 1997.5, 2525.0,
61
+	3197.5, 4055.0, 5147.5, 6542.5, 8322.5,
62
+	10592.0, 13490.0, 17187.0, 21902.0, 27915.0;
63
+
64
+	times = times.array()*1.0e-6;
65
+
66
+	//CALCULATE ABSCISSA
67
+	//define bounds
68
+
69
+	gaussianquadrature *lgqw = gaussianquadrature::New();
70
+
71
+	Real lowb;
72
+	Real upb;
73
+	lowb = 1.0;
74
+	upb = 6000000.0;
75
+	lgqw->SetFreqs(nfreq,upb,lowb);
76
+	lgqw->CalcAW();
77
+
78
+	VectorXr xu(nfreq);
79
+	xu=lgqw->GetAbscissae();
80
+	DipoleSource* Trans=DipoleSource::New();
81
+	Trans->SetType(MAGNETICDIPOLE);
82
+	Trans->SetPolarisation(ZPOLARISATION);
83
+	Trans->SetLocation(0.0,0.0,-1e-4);
84
+
85
+
86
+    // Specify Transmitter
87
+    //PolygonalWireAntenna* Trans  = PolygonalWireAntenna::New();
88
+    //Trans->SetNumberOfPoints(5);
89
+    //Trans->SetPoint(0, Vector3r(   0,   0, -1e-3));
90
+    //Trans->SetPoint(1, Vector3r( 100,   0, -1e-3));
91
+    //Trans->SetPoint(2, Vector3r( 100, 100, -1e-3));
92
+    //Trans->SetPoint(3, Vector3r(   0, 100, -1e-3));
93
+    //Trans->SetPoint(4, Vector3r(   0,   0, -1e-3));
94
+    Trans->SetNumberOfFrequencies(nfreq);
95
+    VectorXr  f(nfreq);
96
+    for (int ifreq=0; ifreq<nfreq; ++ifreq) {
97
+    //    Trans->SetFrequency(ifreq, 1e-3 + dfreq*(Real)(ifreq));
98
+		Trans->SetFrequency(ifreq,xu(ifreq));
99
+        f(ifreq) = xu(ifreq);
100
+    }
101
+	//cout << Trans->GetFrequencies();
102
+    //Trans->SetCurrent(1);
103
+    //Trans->SetNumberOfTurns(1);
104
+
105
+    // Earth properties, top layer is air layer 0 conductivity is fine
106
+    LayeredEarthEM *Earth = LayeredEarthEM::New();
107
+        Earth->SetNumberOfLayers(4);
108
+        Earth->SetLayerConductivity( (VectorXcr(4) << 0.,1.e-6,1.e-2,1.e-6 ).finished() );
109
+        Earth->SetLayerThickness( (VectorXr(2) << 50, 20).finished() );
110
+
111
+    // Receivers, just 1 in the centre for now
112
+   	ReceiverPoints *Receivers = ReceiverPoints::New();
113
+		Vector3r loc;
114
+		Real ox     =    50.;
115
+		Real oy     =    50.;
116
+		Real depth  =  -1e-2;
117
+		Receivers->SetNumberOfReceivers(1);
118
+		loc << ox, oy, depth;
119
+		Receivers->SetLocation(0, loc);
120
+
121
+	// EmEarth
122
+	EMEarth1D  *EmEarth = EMEarth1D::New();
123
+		//EmEarth->AttachWireAntenna(Trans);
124
+		EmEarth->AttachDipoleSource(Trans);
125
+		EmEarth->AttachLayeredEarthEM(Earth);
126
+		EmEarth->AttachReceiverPoints(Receivers);
127
+		EmEarth->SetFieldsToCalculate(H);
128
+        // slower but may be more accurate, depending on frequencies
129
+        EmEarth->SetHankelTransformMethod(CHAVE);
130
+        //EmEarth->SetHankelTransformMethod(DIGITALFILTERING);
131
+
132
+    // Do calculation
133
+   	//EmEarth->CalculateWireAntennaFields();
134
+	//EmEarth->MakeCalc();
135
+	EmEarth->MakeCalc3();
136
+
137
+    // Grab Z component
138
+    // A little painful, I'll try to clean up the API
139
+    VectorXcr Hw(nfreq);
140
+    VectorXr  e(nfreq);
141
+    Hw(0) = 0.; // DC component
142
+    for (int ifreq=0; ifreq<nfreq; ++ifreq) {
143
+        Hw(ifreq) = (Receivers->GetHfield(ifreq, 0))(2);
144
+        e(ifreq) = ifreq;
145
+    }
146
+
147
+    VectorXr Ht(ntimes);                   // Time domain H field
148
+
149
+	//Sine transform
150
+	VectorXr func(nfreq);
151
+	for (int ii=0;ii<ntimes;++ii) {
152
+		func = (Hw.imag().array()*((f.array()*times(ii)).sin()));
153
+		lgqw->SetFunc(func);
154
+		lgqw->Integrate();
155
+		Ht(ii)=lgqw->GetResult();
156
+	}
157
+	Ht = Ht.array()*(-2.0/PI);
158
+
159
+	std::ofstream myfile1;
160
+	myfile1.open("solution.txt");
161
+	for (int ii=0;ii<ntimes;++ii) {
162
+		myfile1 << times(ii) << "   " << Ht(ii) << std::endl;
163
+	}
164
+	myfile1.close();
165
+
166
+	std::ofstream myfile2;
167
+	myfile2.open("freq_domain.txt");
168
+	for (int ii=0;ii<nfreq;++ii) {
169
+		myfile2 << f(ii) << "  " << Hw(ii).real() << "  " << Hw(ii).imag()
170
+			<< std::endl;
171
+	}
172
+	myfile2.close();
173
+
174
+    //std::cout << Ht << std::endl;
175
+    //std::cout << Hw.real() << std::endl;
176
+
177
+    // Quick and dirty plot
178
+    #ifdef  LEMMAUSEVTK
179
+    double colour1[3] = {0.0,0.0,1.0};
180
+    double colour2[3] = {1.0,0.0,0.0};
181
+
182
+    Plot2D_VTK p1("Hz", "Re(Hw)", 800, 600);
183
+    p1.plot(f, Hw.real().eval(), colour1, ".-");
184
+    p1.show();
185
+
186
+    Plot2D_VTK p2("Hz", "Im(Hw)", 800, 600);
187
+    p2.plot(f, Hw.imag().eval(), colour2, ".-");
188
+    p2.show();
189
+
190
+    Plot2D_VTK p3("Time (seconds)", "Ht", 800, 600);
191
+    p3.plot(times, Ht, colour2, ".-");
192
+    p3.show();
193
+
194
+	//Plot2D_VTK p4("index", "frequency",800,600);
195
+	//p4.plot(e,f,colour1,".-");
196
+	//p4.show();
197
+
198
+    #endif
199
+
200
+    // Clean up
201
+    Trans->Delete();
202
+    Earth->Delete();
203
+    Receivers->Delete();
204
+    EmEarth->Delete();
205
+
206
+    return EXIT_SUCCESS;
207
+}

+ 319
- 0
LemmaCore/examples/wireantenna.cpp View File

@@ -0,0 +1,319 @@
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
+
34
+#include <iostream>
35
+#include <fstream>
36
+
37
+#include "dipolesource.h"
38
+#include "layeredearth.h"
39
+#include "receiverpoints.h"
40
+#include "emearth1d.h"
41
+#include "WireAntenna.h"
42
+#include "PolygonalWireAntenna.h"
43
+
44
+#if  LEMMAUSEVTK
45
+#include "vtkRenderer.h"
46
+#include "vtkRenderWindow.h"
47
+#include "vtkRenderWindowInteractor.h"
48
+#include "vtkRenderLargeImage.h"
49
+#include "vtkPNGWriter.h"
50
+#endif     // -----  not LEMMA_USE_VTK  -----
51
+
52
+// For testing purposes disable VTK and run scale.sh
53
+//#undef LEMMAUSEVTK
54
+
55
+#include "timer.h"
56
+
57
+using namespace Lemma;
58
+
59
+double randDouble(double low, double high) {
60
+	//srand(time(0));
61
+	double temp;
62
+	/* swap low & high around if the user makes no sense */
63
+	if (low > high)	{
64
+	temp = low;
65
+	low = high;
66
+	high = temp;
67
+	}
68
+	/* calculate the random number & return it */
69
+	temp = (rand() / (static_cast<double>(RAND_MAX) + 1.0))
70
+	* (high - low) + low;
71
+	return temp;
72
+}
73
+
74
+
75
+int main() {
76
+
77
+	// Keep track of time
78
+	jsw_timer timer;
79
+
80
+
81
+	srand(time(0));
82
+
83
+	PolygonalWireAntenna *pa = PolygonalWireAntenna::New();
84
+	pa->SetNumberOfFrequencies(1);
85
+	pa->SetFrequency(0, 1000);
86
+	pa->SetNumberOfPoints(5);
87
+	pa->SetPoint(0, Vector3r(   0,   0, -.001));
88
+	pa->SetPoint(1, Vector3r( 100,   0, -.001));
89
+	pa->SetPoint(2, Vector3r( 100, 100, -.001));
90
+	pa->SetPoint(3, Vector3r(   0, 100, -.001));
91
+	pa->SetPoint(4, Vector3r(   0,   0, -.001));
92
+	pa->SetCurrent(1.);
93
+    pa->SetNumberOfTurns(1);
94
+	//Vector3r rp = Vector3r::Random(3);
95
+	//rp << 150., 10, 0.;
96
+	//rp << -27.1456, 15.2350, -1e-3;
97
+	//rp << randDouble(-35,35), randDouble(-35,35), randDouble(-35,35);
98
+	//rp << 3.22806, -13.1548, 14.9695;
99
+	//rp.setRandom(3);
100
+	//std::cout <<  "rp " << rp.transpose() << std::endl;
101
+	//pa->ApproximateWithElectricDipoles(rp);
102
+
103
+	WireAntenna *wire = WireAntenna::New();
104
+		wire->SetNumberOfPoints(5);
105
+		wire->SetPoint(0, Vector3r(   0,   0, -1e-3));
106
+		wire->SetPoint(1, Vector3r( 10,   0, -1e-3));
107
+		wire->SetPoint(2, Vector3r( 10, 10, -1e-3));
108
+		wire->SetPoint(3, Vector3r(   0, 10, -1e-3));
109
+		wire->SetPoint(4, Vector3r(   0,   0, -1e-3));
110
+		// TODO change wire antennae to use my class
111
+		//wire->SetNumberOfFrequencies(1);
112
+		wire->SetCurrent(1.);
113
+		wire->SetNumberOfFrequencies(1);
114
+		wire->SetFrequency(0, 1000);
115
+        wire->SetNumberOfTurns(1);
116
+		//wire->ApproximateWithElectricDipoles(5);
117
+
118
+	// Define model
119
+	VectorXcr sigma(2);
120
+		sigma << Complex(0.,0), Complex(.1,0);
121
+	VectorXr  thick(1);
122
+		thick << 10;
123
+	LayeredEarthEM *earth = LayeredEarthEM::New();
124
+		earth->SetNumberOfLayers(2);
125
+		earth->SetLayerConductivity(sigma);
126
+		//earth->SetLayerThickness(thick);
127
+
128
+	// Receivers
129
+	ReceiverPoints *receivers = ReceiverPoints::New();
130
+		Vector3r loc;
131
+		Real ox    =    50.561 ;
132
+		Real oy    =   105.235 ;
133
+		Real depth =    -3.75e1;
134
+		Real depth2 =   depth;
135
+		Real dx    =    1.;
136
+		int nz     =    1;
137
+		receivers->SetNumberOfReceivers(nz);
138
+		int ir = 0;
139
+		for (int iz=0; iz<nz; ++iz) {
140
+			loc << ox, oy, depth;
141
+			receivers->SetLocation(ir, loc);
142
+			depth += dx;
143
+			++ ir;
144
+		}
145
+
146
+	// EmEarth
147
+	EMEarth1D  *EmEarth = EMEarth1D::New();
148
+		//EmEarth->AttachWireAntenna(wire);
149
+		EmEarth->AttachWireAntenna(pa);
150
+		EmEarth->AttachLayeredEarthEM(earth);
151
+		EmEarth->AttachReceiverPoints(receivers);
152
+		EmEarth->SetFieldsToCalculate(H);
153
+        //EmEarth->SetHankelTransformMethod(GAUSSIANQUADRATURE);
154
+
155
+	// Do calculation
156
+	timer.begin();
157
+	EmEarth->CalculateWireAntennaFields();
158
+	Real paTime = timer.end();
159
+	std::cout << "Polygonal wire antennae time: " << paTime << "\n";
160
+
161
+	//EmEarth->AttachWireAntenna(wire);
162
+	//timer.begin();
163
+	//EmEarth->CalculateWireAntennaFields();
164
+	//Real waTime = timer.end();
165
+	//std::cout << "Fixed wire antennae time: " << waTime << "\n";
166
+
167
+	depth = depth2;
168
+	std::fstream real("reale_lay.dat", std::ios::out);
169
+	std::fstream imag("image_lay.dat", std::ios::out);
170
+	std::fstream hreal("real_lay.dat", std::ios::out);
171
+	std::fstream himag("imag_lay.dat", std::ios::out);
172
+	for (int iz=0; iz<nz; ++iz) {
173
+		Vector3cr temp = receivers->GetEfield(0,iz);
174
+		real << ox << "\t" << oy << "\t" << depth << "\t"
175
+				<< temp(0).real() << "\t" << temp(1).real()
176
+				<< "\t" << temp(2).real() << std::endl;
177
+		imag << ox << "\t" << oy << "\t" << depth << "\t"
178
+				<< std::imag(temp(0)) << "\t" << std::imag(temp(1))
179
+				<< "\t" << std::imag(temp(2)) << std::endl;
180
+		temp = receivers->GetHfield(0, iz);
181
+		hreal << ox << "\t" << oy << "\t" << depth << "\t"
182
+				<< std::real(temp(0)) << "\t" << std::real(temp(1))
183
+				<< "\t" << std::real(temp(2)) << std::endl;
184
+		himag << ox << "\t" << oy << "\t" << depth << "\t"
185
+				<< std::imag(temp(0)) << "\t" << std::imag(temp(1))
186
+				<< "\t" << std::imag(temp(2)) << std::endl;
187
+		depth += dx;
188
+	}
189
+	real.close();
190
+	imag.close();
191
+	hreal.close();
192
+	himag.close();
193
+	EmEarth->Delete();
194
+	receivers->Delete();
195
+	earth->Delete();
196
+	//wire->Delete();
197
+
198
+#if  LEMMAUSEVTK
199
+	// Create the usual rendering stuff.
200
+	vtkRenderer           *renderer = vtkRenderer::New();
201
+	vtkRenderWindow         *renWin = vtkRenderWindow::New();
202
+	vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
203
+
204
+	// Line of tx
205
+	vtkLineSource       *vline = vtkLineSource::New();
206
+	vtkTubeFilter       *vTube = vtkTubeFilter::New();
207
+ 	vtkPolyDataMapper   *vMapper = vtkPolyDataMapper::New();
208
+	vtkActor             *vActor = vtkActor::New();
209
+	vline->SetPoint1(0,0,0);
210
+	vline->SetPoint2(10,0,0);
211
+
212
+	vTube->SetInputConnection(vline->GetOutputPort());
213
+	vTube->SetRadius(.2);
214
+	vTube->SetNumberOfSides(6);
215
+	vMapper->SetInputConnection(vTube->GetOutputPort());
216
+	vActor->SetMapper(vMapper);
217
+	vActor->GetProperty()->SetColor(0.0, .0, 1.0);
218
+	vActor->GetProperty()->SetOpacity(.15);
219
+	renderer->AddActor(vActor);
220
+
221
+	vtkLineSource       *vline2 = vtkLineSource::New();
222
+	vtkTubeFilter       *vTube2 = vtkTubeFilter::New();
223
+ 	vtkPolyDataMapper   *vMapper2 = vtkPolyDataMapper::New();
224
+	vtkActor             *vActor2 = vtkActor::New();
225
+	vline2->SetPoint1(10,0,0);
226
+	vline2->SetPoint2(10,10,0);
227
+
228
+	vTube2->SetInputConnection(vline2->GetOutputPort());
229
+	vTube2->SetRadius(.2);
230
+	vTube2->SetNumberOfSides(6);
231
+	vMapper2->SetInputConnection(vTube2->GetOutputPort());
232
+	vActor2->SetMapper(vMapper2);
233
+	vActor2->GetProperty()->SetColor(0.0, .0, 1.0);
234
+	vActor2->GetProperty()->SetOpacity(.15);
235
+	renderer->AddActor(vActor2);
236
+
237
+	vtkLineSource       *vline3 = vtkLineSource::New();
238
+	vtkTubeFilter       *vTube3 = vtkTubeFilter::New();
239
+ 	vtkPolyDataMapper   *vMapper3 = vtkPolyDataMapper::New();
240
+	vtkActor             *vActor3 = vtkActor::New();
241
+	vline3->SetPoint1(10,10,0);
242
+	vline3->SetPoint2(0,10,0);
243
+
244
+	vTube3->SetInputConnection(vline3->GetOutputPort());
245
+	vTube3->SetRadius(.2);
246
+	vTube3->SetNumberOfSides(6);
247
+	vMapper3->SetInputConnection(vTube3->GetOutputPort());
248
+	vActor3->SetMapper(vMapper3);
249
+	vActor3->GetProperty()->SetColor(0.0, .0, 1.0);
250
+	vActor3->GetProperty()->SetOpacity(.15);
251
+	renderer->AddActor(vActor3);
252
+
253
+	vtkLineSource       *vline4 = vtkLineSource::New();
254
+	vtkTubeFilter       *vTube4 = vtkTubeFilter::New();
255
+ 	vtkPolyDataMapper   *vMapper4 = vtkPolyDataMapper::New();
256
+	vtkActor             *vActor4 = vtkActor::New();
257
+	vline4->SetPoint1(0,10,0);
258
+	vline4->SetPoint2(0,0,0);
259
+
260
+	vTube4->SetInputConnection(vline4->GetOutputPort());
261
+	vTube4->SetRadius(.2);
262
+	vTube4->SetNumberOfSides(6);
263
+	vMapper4->SetInputConnection(vTube4->GetOutputPort());
264
+	vActor4->SetMapper(vMapper4);
265
+	vActor4->GetProperty()->SetColor(0.0, .0, 1.0);
266
+	vActor4->GetProperty()->SetOpacity(.15);
267
+	renderer->AddActor(vActor4);
268
+
269
+    loc << 50, 50, -1e-3;
270
+	pa->ApproximateWithElectricDipoles(loc);
271
+
272
+    vtkActor **pdipActors = new vtkActor*[pa->GetNumberOfDipoles()];
273
+    std::cout <<  "Wire approximated with " << pa->GetNumberOfDipoles() << std::endl;
274
+	for (int id=0; id<pa->GetNumberOfDipoles(); ++id) {
275
+		pdipActors[id] = pa->GetVtkActor(id);
276
+		renderer->AddActor(pdipActors[id]);
277
+	}
278
+
279
+    /*
280
+    vtkActor **dipActors = new vtkActor*[wire->GetNumberOfDipoles()];
281
+	for (int id=0; id<wire->GetNumberOfDipoles(); ++id) {
282
+		dipActors[id] = wire->GetVtkActor(id);
283
+		renderer->AddActor(dipActors[id]);
284
+	}
285
+    */
286
+
287
+	renderer->SetBackground(1,1,1);
288
+
289
+	// Render the window
290
+	renWin->AddRenderer(renderer);
291
+	renWin->SetWindowName("Wire antennae");
292
+
293
+	iren->SetRenderWindow(renWin);
294
+	iren->Initialize();
295
+	iren->Start();
296
+	iren->Render();
297
+
298
+    #if 0
299
+	cout << "Enter File name?: ";
300
+	std::string pngName;
301
+	std::cin >> pngName;
302
+	vtkPNGWriter *pngwrite = vtkPNGWriter::New();
303
+	vtkRenderLargeImage *renlarge = vtkRenderLargeImage::New();
304
+	renlarge->SetInput(renderer);
305
+	renlarge->SetMagnification(2);
306
+	pngwrite->SetInputConnection(renlarge->GetOutputPort());
307
+	pngName.append(".png");
308
+	pngwrite->SetFileName(pngName.c_str());
309
+	pngwrite->Write();
310
+    #endif
311
+
312
+#endif     // -----  not LEMMA_USE_VTK  -----
313
+
314
+
315
+	//std::cout << *pa << std::endl;
316
+	//pa->Delete();
317
+
318
+	return 0;
319
+}

+ 61
- 0
LemmaCore/include/Lemma View File

@@ -0,0 +1,61 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API */
2
+
3
+/* Copyright (C) 2009-2013 Trevor Irons <trevorirons@gmail.com> */
4
+
5
+/* This Source Code Form is subject to the terms of the Mozilla Public
6
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
7
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8
+
9
+/**
10
+  @file
11
+  @author   Trevor Irons
12
+  @version  $Id$
13
+ **/
14
+
15
+// Convenience include all of Lemma
16
+
17
+#ifndef  LEMMAINCLUDE_INC
18
+#define  LEMMAINCLUDE_INC
19
+
20
+// Basic EM Classes
21
+//#include "dipolesource.h"
22
+#include "emearth1d.h"
23
+#include "emearth3d.h"
24
+#include "kernel.h"
25
+#include "receiverpoints.h"
26
+#include "receivercubes.h"
27
+#include "hankeltransformgaussianquadrature.h"
28
+#include "layeredearthem.h"
29
+#include "WireAntenna.h"
30
+#include "PolygonalWireAntenna.h"
31
+#include "gaussianquadrature.h"
32
+#include "digitalfiltercostrans.h"
33
+#include "octreegrid.h"
34
+
35
+// TEM
36
+#include "TEMSurvey.h"
37
+#include "TEMInductiveReceiver.h"
38
+#include "TEMTransmitter.h"
39
+
40
+//#include "rectilineargrid.h"
41
+
42
+// Specialized EM Classes
43
+#include "instrumenttem.h"
44
+#include "instrumentfem.h"
45
+
46
+// TEM Classes
47
+#include "datatem.h"
48
+#include "modelreadertem1dubc.h"
49
+#include "datareadertem.h"
50
+
51
+// FEM Classes
52
+#include "datareaderfemubc.h"
53
+#include "datafem.h"
54
+
55
+// Inverse
56
+#include "quasinewtonbfgs.h"
57
+#include "inversesolvertem1d.h"
58
+#endif   // ----- #ifndef LEMMAINCLUDE_INC  -----
59
+
60
+/* vim: set tabstop=4 expandtab: */
61
+/* vim: set filetype=cpp: */

+ 0
- 3
LemmaCore/include/logbarriercg.h View File

@@ -23,9 +23,6 @@
23 23
 #include "bicgstab.h"
24 24
 #include "lemma.h"
25 25
 
26
-#ifdef LEMMAUSEVTK
27
-#include "matplot.h"
28
-#endif
29 26
 
30 27
 namespace Lemma {
31 28
 

+ 0
- 3
LemmaCore/include/logbarriercg_newton.h View File

@@ -23,9 +23,6 @@
23 23
 #include "bicgstab.h"
24 24
 #include "lemma.h"
25 25
 
26
-#ifdef LEMMAUSEVTK
27
-#include "matplot.h"
28
-#endif
29 26
 
30 27
 namespace Lemma {
31 28
 

+ 13
- 7
LemmaCore/include/octreegrid.h View File

@@ -38,8 +38,8 @@
38 38
 //#include "layeredearthnmr.h"
39 39
 #include "inversesolver.h"
40 40
 
41
-#include "FastDelegate.h"
42
-#include "FastDelegateBind.h"
41
+//#include "FastDelegate.h"
42
+//#include "FastDelegateBind.h"
43 43
 
44 44
 namespace Lemma {
45 45
 
@@ -202,7 +202,12 @@ namespace Lemma {
202 202
             template <class Derived>
203 203
             void SampleScalarFromLayeredEarth(LayeredEarth* earth,
204 204
                     Real (Derived::*fcnptr)(const int& id), const std::string &name) {
205
-
205
+                std::cerr << "In octreegrid.h SampleScalrFromLayeredEarth FastDelegate method was "
206
+                         << "removed, need to fix with move semantics or function pointer." << std::endl;
207
+                exit(3);
208
+                //TODO fix SampleScalar below, as call to SampleScalarFromLayeredEarthFD is
209
+                //     removed there.
210
+/*
206 211
                 SampleScalarFromLayeredEarthFD.bind(static_cast<Derived*>(earth), fcnptr);
207 212
                 GetLayerInt.bind(earth, &LayeredEarth::GetLayerAtThisDepth);
208 213
                 // TODO, don't use KernelArray, instead create new Array, and set it
@@ -212,6 +217,7 @@ namespace Lemma {
212 217
                 SampleScalar();
213 218
                 this->Octree->GetLeafData()->SetScalars( KernelArray );
214 219
                 this->Octree->GetLeafData()->AddArray( KernelArray );
220
+*/
215 221
             }
216 222
 
217 223
             /** Sends cursor to root
@@ -247,14 +253,14 @@ namespace Lemma {
247 253
              */
248 254
             void GetPosition( Real* p );
249 255
 
250
-            /** Used to fill leaf data with a scalar value from a layered earth
256
+            /* Used to fill leaf data with a scalar value from a layered earth
251 257
              *  model
252 258
              */
253
-            fastdelegate::FastDelegate1< const int&, Real > SampleScalarFromLayeredEarthFD;
259
+            //fastdelegate::FastDelegate1< const int&, Real > SampleScalarFromLayeredEarthFD;
254 260
 
255
-            /** Used to get the Layer of delagated model.
261
+            /* Used to get the Layer of delagated model.
256 262
              */
257
-            fastdelegate::FastDelegate1< const Real&, int >  GetLayerInt;
263
+            //fastdelegate::FastDelegate1< const Real&, int >  GetLayerInt;
258 264
 
259 265
             /** Recursively determines the mesh to use
260 266
              */

+ 2
- 2
LemmaCore/src/octreegrid.cpp View File

@@ -617,8 +617,8 @@ namespace Lemma {
617 617
 
618 618
         //  split if needed
619 619
         if (Cursor->CurrentIsLeaf())  {
620
-            KernelArray->InsertValue(Cursor->GetLeafId(),
621
-                SampleScalarFromLayeredEarthFD(GetLayerInt(cpos(2))));
620
+            //KernelArray->InsertValue(Cursor->GetLeafId(),
621
+            //    SampleScalarFromLayeredEarthFD(GetLayerInt(cpos(2))));
622 622
         } else {
623 623
             // Evaluate function at cell centre
624 624
             for (int child=0; child < Cursor->GetNumberOfChildren(); ++ child) {

Loading…
Cancel
Save