|
@@ -0,0 +1,251 @@
|
|
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/01/19 22:34:11
|
|
13
|
+ * @version $Id$
|
|
14
|
+ * @author Trevor Irons (ti)
|
|
15
|
+ * @email Trevor.Irons@utah.edu
|
|
16
|
+ * @copyright Copyright (c) 2019, University of Utah
|
|
17
|
+ * @copyright Copyright (c) 2019, Lemma Software, LLC
|
|
18
|
+ */
|
|
19
|
+
|
|
20
|
+#include <cxxtest/TestSuite.h>
|
|
21
|
+#include <FDEM1D>
|
|
22
|
+#include <random>
|
|
23
|
+#include "timer.h"
|
|
24
|
+
|
|
25
|
+#define EPSILON 1e-10
|
|
26
|
+using namespace Lemma;
|
|
27
|
+
|
|
28
|
+class MyAlgorithmTest : public CxxTest::TestSuite {
|
|
29
|
+ // Put in your usual, quick unit tests here
|
|
30
|
+};
|
|
31
|
+
|
|
32
|
+class MyAlgorithmTestPerformance : public CxxTest::TestSuite {
|
|
33
|
+
|
|
34
|
+public:
|
|
35
|
+
|
|
36
|
+ std::shared_ptr< DipoleSource > dipole;
|
|
37
|
+ std::shared_ptr< LayeredEarthEM > earth;
|
|
38
|
+ std::shared_ptr< FieldPoints > receivers;
|
|
39
|
+ std::shared_ptr< EMEarth1D > EmEarth;
|
|
40
|
+
|
|
41
|
+ jsw_timer timer;
|
|
42
|
+
|
|
43
|
+ Real Delta;
|
|
44
|
+
|
|
45
|
+ void setUp() {
|
|
46
|
+ // Put in any code needed to set up your test,
|
|
47
|
+ // but that should NOT be counted in the execution time.
|
|
48
|
+ dipole = DipoleSource::NewSP();
|
|
49
|
+
|
|
50
|
+ //dipole->SetType(GROUNDEDELECTRICDIPOLE);
|
|
51
|
+ //dipole->SetPolarisation(XPOLARISATION);
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+ dipole->SetNumberOfFrequencies(1);
|
|
55
|
+ dipole->SetMoment(1);
|
|
56
|
+ dipole->SetFrequency(0, 4400.1000);
|
|
57
|
+ //dipole->SetPhase(0);
|
|
58
|
+ //dipole->SetLocation( (VectorXr(3) << 49, 49, -1e-4).finished() );
|
|
59
|
+ dipole->SetLocation( 0, 0, -1e-4 );
|
|
60
|
+
|
|
61
|
+ // Define model
|
|
62
|
+ VectorXcr sigma(2);
|
|
63
|
+ sigma << 0., 1e-3;//, .1;//, .01, .001;
|
|
64
|
+ VectorXr thick(1);
|
|
65
|
+ thick << 10;//, 10, 10;
|
|
66
|
+
|
|
67
|
+ earth = LayeredEarthEM::NewSP();
|
|
68
|
+ earth->SetNumberOfLayers(2);
|
|
69
|
+ earth->SetLayerConductivity(sigma);
|
|
70
|
+ //earth->SetLayerThickness(thick);
|
|
71
|
+
|
|
72
|
+ receivers = FieldPoints::NewSP();
|
|
73
|
+ Vector3r loc;
|
|
74
|
+
|
|
75
|
+ Real ox = 2.;
|
|
76
|
+ Real oy = 2.;
|
|
77
|
+ Real oz = 2;
|
|
78
|
+
|
|
79
|
+ Real dx = 0.62;
|
|
80
|
+ Real dy = 0.62;
|
|
81
|
+ Real dz = 0.62;
|
|
82
|
+
|
|
83
|
+ int nx = 20;
|
|
84
|
+ int ny = 20;
|
|
85
|
+ int nz = 20;
|
|
86
|
+ Delta = nx*ny*nz*1e-10;
|
|
87
|
+
|
|
88
|
+ receivers->SetNumberOfPoints(nx*ny*nz);
|
|
89
|
+ int ir = 0;
|
|
90
|
+ for (int ix=0; ix<nx; ++ix) {
|
|
91
|
+ for (int iy=0; iy<ny; ++iy) {
|
|
92
|
+ for (int iz=0; iz<nz; ++iz) {
|
|
93
|
+ loc << ox+ix*dx, oy+iy*dy, oz+iz*dz;
|
|
94
|
+ //std::cout << "Receiver location " << loc.transpose() << std::endl;
|
|
95
|
+ receivers->SetLocation(ir, loc);
|
|
96
|
+ //oz += dz;
|
|
97
|
+ ++ ir;
|
|
98
|
+ }
|
|
99
|
+ }
|
|
100
|
+ }
|
|
101
|
+
|
|
102
|
+ EmEarth = EMEarth1D::NewSP();
|
|
103
|
+ EmEarth->SetHankelTransformMethod(CHAVE);
|
|
104
|
+ EmEarth->SetFieldsToCalculate(BOTH); // Fortran needs this
|
|
105
|
+ EmEarth->AttachDipoleSource(dipole);
|
|
106
|
+ EmEarth->AttachLayeredEarthEM(earth);
|
|
107
|
+ EmEarth->AttachFieldPoints(receivers);
|
|
108
|
+
|
|
109
|
+ }
|
|
110
|
+
|
|
111
|
+ void tearDown() {
|
|
112
|
+ // Clean-up code, also NOT counted in execution time.
|
|
113
|
+ }
|
|
114
|
+
|
|
115
|
+ void test_Hz() {
|
|
116
|
+
|
|
117
|
+ dipole->SetType(MAGNETICDIPOLE);
|
|
118
|
+ dipole->SetPolarisation(ZPOLARISATION);
|
|
119
|
+
|
|
120
|
+ // Put in a unit test that will be slow.
|
|
121
|
+ std::cout << "C++\n";
|
|
122
|
+
|
|
123
|
+ timer.begin();
|
|
124
|
+ EmEarth->MakeCalc3();
|
|
125
|
+ Real lemmaTime = timer.end();
|
|
126
|
+
|
|
127
|
+ auto lc = receivers->GetEfield( 0 );
|
|
128
|
+
|
|
129
|
+ #ifdef KIHALEE_EM1D
|
|
130
|
+ receivers->ClearFields();
|
|
131
|
+ std::cout << "\nFORTRAN KiHa\n";
|
|
132
|
+ timer.begin();
|
|
133
|
+ EmEarth->MakeCalc();
|
|
134
|
+ Real kihaTime = timer.end();
|
|
135
|
+
|
|
136
|
+ auto fc = receivers->GetEfield( 0 ); //0,0);
|
|
137
|
+
|
|
138
|
+ std::cout << "Lemma time:" << lemmaTime << "\tKiHa time:" << kihaTime << std::endl;
|
|
139
|
+
|
|
140
|
+ std::cout.precision(16);
|
|
141
|
+ std::cout << "Lemma norm |" << (lc).norm() << "|" << std::endl;
|
|
142
|
+ std::cout << "KiHa norm |" << (fc).norm() << "|" << std::endl;
|
|
143
|
+ std::cout << "Difference norm |" << (lc - fc).norm() << "|" << std::endl;
|
|
144
|
+
|
|
145
|
+ TS_ASSERT_DELTA((lc-fc).norm(), 0.0, Delta);
|
|
146
|
+ #endif
|
|
147
|
+ }
|
|
148
|
+
|
|
149
|
+ void test_Hx() {
|
|
150
|
+
|
|
151
|
+ dipole->SetType(MAGNETICDIPOLE);
|
|
152
|
+ dipole->SetPolarisation(XPOLARISATION);
|
|
153
|
+
|
|
154
|
+ // Put in a unit test that will be slow.
|
|
155
|
+ std::cout << "C++\n";
|
|
156
|
+
|
|
157
|
+ timer.begin();
|
|
158
|
+ EmEarth->MakeCalc3();
|
|
159
|
+ Real lemmaTime = timer.end();
|
|
160
|
+
|
|
161
|
+ auto lc = receivers->GetEfield( 0 );
|
|
162
|
+
|
|
163
|
+ #ifdef KIHALEE_EM1D
|
|
164
|
+ receivers->ClearFields();
|
|
165
|
+ std::cout << "\nFORTRAN KiHa\n";
|
|
166
|
+ timer.begin();
|
|
167
|
+ EmEarth->MakeCalc();
|
|
168
|
+ Real kihaTime = timer.end();
|
|
169
|
+
|
|
170
|
+ auto fc = receivers->GetEfield( 0 ); //0,0);
|
|
171
|
+
|
|
172
|
+ std::cout << "Lemma time:" << lemmaTime << "\tKiHa time:" << kihaTime << std::endl;
|
|
173
|
+
|
|
174
|
+ std::cout.precision(16);
|
|
175
|
+ std::cout << "Lemma norm |" << (lc).norm() << "|" << std::endl;
|
|
176
|
+ std::cout << "KiHa norm |" << (fc).norm() << "|" << std::endl;
|
|
177
|
+ std::cout << "Difference norm |" << (lc - fc).norm() << "|" << std::endl;
|
|
178
|
+
|
|
179
|
+ TS_ASSERT_DELTA((lc-fc).norm(), 0.0, Delta);
|
|
180
|
+ #endif
|
|
181
|
+ }
|
|
182
|
+
|
|
183
|
+ void test_Hy() {
|
|
184
|
+
|
|
185
|
+ dipole->SetType(MAGNETICDIPOLE);
|
|
186
|
+ dipole->SetPolarisation(YPOLARISATION);
|
|
187
|
+
|
|
188
|
+ // Put in a unit test that will be slow.
|
|
189
|
+ std::cout << "C++\n";
|
|
190
|
+
|
|
191
|
+ timer.begin();
|
|
192
|
+ EmEarth->MakeCalc3();
|
|
193
|
+ Real lemmaTime = timer.end();
|
|
194
|
+
|
|
195
|
+ auto lc = receivers->GetEfield( 0 );
|
|
196
|
+
|
|
197
|
+ #ifdef KIHALEE_EM1D
|
|
198
|
+ receivers->ClearFields();
|
|
199
|
+ std::cout << "\nFORTRAN KiHa\n";
|
|
200
|
+ timer.begin();
|
|
201
|
+ EmEarth->MakeCalc();
|
|
202
|
+ Real kihaTime = timer.end();
|
|
203
|
+
|
|
204
|
+ auto fc = receivers->GetEfield( 0 ); //0,0);
|
|
205
|
+
|
|
206
|
+ std::cout << "Lemma time:" << lemmaTime << "\tKiHa time:" << kihaTime << std::endl;
|
|
207
|
+
|
|
208
|
+ std::cout.precision(16);
|
|
209
|
+ std::cout << "Lemma norm |" << (lc).norm() << "|" << std::endl;
|
|
210
|
+ std::cout << "KiHa norm |" << (fc).norm() << "|" << std::endl;
|
|
211
|
+ std::cout << "Difference norm |" << (lc - fc).norm() << "|" << std::endl;
|
|
212
|
+
|
|
213
|
+ TS_ASSERT_DELTA((lc-fc).norm(), 0.0, Delta);
|
|
214
|
+ #endif
|
|
215
|
+ }
|
|
216
|
+
|
|
217
|
+ void test_Ex() {
|
|
218
|
+
|
|
219
|
+ dipole->SetType(GROUNDEDELECTRICDIPOLE);
|
|
220
|
+ dipole->SetPolarisation(XPOLARISATION);
|
|
221
|
+
|
|
222
|
+ // Put in a unit test that will be slow.
|
|
223
|
+ std::cout << "C++\n";
|
|
224
|
+
|
|
225
|
+ timer.begin();
|
|
226
|
+ EmEarth->MakeCalc3();
|
|
227
|
+ Real lemmaTime = timer.end();
|
|
228
|
+
|
|
229
|
+ auto lc = receivers->GetEfield( 0 );
|
|
230
|
+
|
|
231
|
+ #ifdef KIHALEE_EM1D
|
|
232
|
+ receivers->ClearFields();
|
|
233
|
+ std::cout << "\nFORTRAN KiHa\n";
|
|
234
|
+ timer.begin();
|
|
235
|
+ EmEarth->MakeCalc();
|
|
236
|
+ Real kihaTime = timer.end();
|
|
237
|
+
|
|
238
|
+ auto fc = receivers->GetEfield( 0 ); //0,0);
|
|
239
|
+
|
|
240
|
+ std::cout << "Lemma time:" << lemmaTime << "\tKiHa time:" << kihaTime << std::endl;
|
|
241
|
+
|
|
242
|
+ std::cout.precision(16);
|
|
243
|
+ std::cout << "Lemma norm |" << (lc).norm() << "|" << std::endl;
|
|
244
|
+ std::cout << "KiHa norm |" << (fc).norm() << "|" << std::endl;
|
|
245
|
+ std::cout << "Difference norm |" << (lc - fc).norm() << "|" << std::endl;
|
|
246
|
+
|
|
247
|
+ TS_ASSERT_DELTA((lc-fc).norm(), 0.0, Delta);
|
|
248
|
+ #endif
|
|
249
|
+ }
|
|
250
|
+
|
|
251
|
+};
|