|
@@ -105,6 +105,9 @@ namespace Lemma {
|
105
|
105
|
void KernelV0::CalculateK0 (const std::vector< std::string>& Tx, const std::vector<std::string >& Rx,
|
106
|
106
|
bool vtkOutput ) {
|
107
|
107
|
|
|
108
|
+ // Set up
|
|
109
|
+ Larmor = SigmaModel->GetMagneticFieldMagnitude()*GAMMA; // in rad 2246.*2.*PI;
|
|
110
|
+
|
108
|
111
|
// All EM calculations will share same field points
|
109
|
112
|
cpoints = FieldPoints::NewSP();
|
110
|
113
|
cpoints->SetNumberOfPoints(8);
|
|
@@ -133,24 +136,30 @@ namespace Lemma {
|
133
|
136
|
EMEarths[rx]->SetTxRxMode(RX);
|
134
|
137
|
}
|
135
|
138
|
}
|
136
|
|
- IntegrateOnOctreeGrid( 1e-13, vtkOutput );
|
|
139
|
+
|
|
140
|
+ std::cout << "Calculating K0 kernel\n";
|
|
141
|
+ MatrixXcr Kern = MatrixXcr::Zero( Interfaces.size() - 1, PulseI.size() );
|
|
142
|
+ for (int ilay=0; ilay< Interfaces.size()-1; ++ilay) {
|
|
143
|
+ for (int iq=0; iq< PulseI.size()-1; ++iq) {
|
|
144
|
+ std::cout << "Layer " << ilay << " q " << iq << std::endl;
|
|
145
|
+ Size(2) = Interfaces(ilay+1) - Interfaces(ilay);
|
|
146
|
+ Origin(2) = Interfaces(ilay);
|
|
147
|
+ Ip = PulseI(iq);
|
|
148
|
+ Kern(ilay, iq) = IntegrateOnOctreeGrid( ilay, iq, vtkOutput );
|
|
149
|
+ }
|
|
150
|
+ }
|
|
151
|
+ std::cout << "\rFinished KERNEL\n";
|
|
152
|
+ std::cout << Kern << std::endl;
|
|
153
|
+ //IntegrateOnOctreeGrid( vtkOutput );
|
137
|
154
|
}
|
138
|
155
|
|
139
|
156
|
//--------------------------------------------------------------------------------------
|
140
|
157
|
// Class: KernelV0
|
141
|
158
|
// Method: IntegrateOnOctreeGrid
|
142
|
159
|
//--------------------------------------------------------------------------------------
|
143
|
|
- void KernelV0::IntegrateOnOctreeGrid( const Real& tolerance, bool vtkOutput) {
|
|
160
|
+ Complex KernelV0::IntegrateOnOctreeGrid( const int& ilay, const int& iq, bool vtkOutput) {
|
144
|
161
|
|
145
|
|
- this->tol = tolerance;
|
146
|
|
- //Vector3r Size;
|
147
|
|
- Size << 200,200,2;
|
148
|
|
- //Vector3r Origin;
|
149
|
|
- Origin << 0,0,5.0;
|
150
|
|
- Vector3r cpos; // centre position
|
151
|
|
- //cpos << 100,100,50;
|
152
|
|
- cpos = (Size-Origin).array() / 2.;
|
153
|
|
- int maxlevel;
|
|
162
|
+ Vector3r cpos = (Size-Origin).array() / 2.;
|
154
|
163
|
|
155
|
164
|
SUM = 0;
|
156
|
165
|
VOLSUM = 0;
|
|
@@ -184,30 +193,33 @@ namespace Lemma {
|
184
|
193
|
kid->SetNumberOfComponents(1);
|
185
|
194
|
kid->SetName("ID");
|
186
|
195
|
kid->SetNumberOfTuples( oct->GetNumberOfLeaves() );
|
187
|
|
- //vtkDoubleArray* kerr = vtkDoubleArray::New();
|
188
|
|
- // kerr->SetNumberOfComponents(1);
|
189
|
|
- // kerr->SetName("Error");
|
|
196
|
+ vtkIntArray* kerr = vtkIntArray::New();
|
|
197
|
+ kerr->SetNumberOfComponents(1);
|
|
198
|
+ kerr->SetName("nleaf");
|
190
|
199
|
|
191
|
200
|
for (auto leaf : LeafDict) {
|
192
|
201
|
kr->InsertTuple1( leaf.first, std::real(leaf.second) );
|
193
|
202
|
ki->InsertTuple1( leaf.first, std::imag(leaf.second) );
|
|
203
|
+ km->InsertTuple1( leaf.first, std::abs(leaf.second) );
|
194
|
204
|
kid->InsertTuple1( leaf.first, leaf.first );
|
195
|
205
|
}
|
196
|
206
|
|
197
|
|
- //for (auto leaf : LeafDictErr) {
|
198
|
|
- // kerr->InsertTuple1( leaf.first, std::imag(leaf.second) );
|
199
|
|
- //}
|
|
207
|
+ for (auto leaf : LeafDictIdx) {
|
|
208
|
+ kerr->InsertTuple1( leaf.first, leaf.second );
|
|
209
|
+ }
|
200
|
210
|
|
201
|
211
|
oct->GetLeafData()->AddArray(kr);
|
202
|
212
|
oct->GetLeafData()->AddArray(ki);
|
203
|
213
|
oct->GetLeafData()->AddArray(km);
|
204
|
214
|
oct->GetLeafData()->AddArray(kid);
|
205
|
|
- //oct->GetLeafData()->AddArray(kerr);
|
|
215
|
+ oct->GetLeafData()->AddArray(kerr);
|
206
|
216
|
|
207
|
217
|
auto write = vtkXMLHyperOctreeWriter::New();
|
208
|
218
|
//write.SetDataModeToAscii()
|
209
|
219
|
write->SetInputData(oct);
|
210
|
|
- write->SetFileName("octree.vto");
|
|
220
|
+ std::string fname = std::string("octree-") + to_string(ilay)
|
|
221
|
+ + std::string("-") + to_string(iq) + std::string(".vto");
|
|
222
|
+ write->SetFileName(fname.c_str());
|
211
|
223
|
write->Write();
|
212
|
224
|
write->Delete();
|
213
|
225
|
|
|
@@ -228,6 +240,7 @@ namespace Lemma {
|
228
|
240
|
std::cout << "nleaves\t" << nleaves << std::endl;
|
229
|
241
|
std::cout << "KSUM\t" << SUM << std::endl;
|
230
|
242
|
|
|
243
|
+ return SUM;
|
231
|
244
|
}
|
232
|
245
|
|
233
|
246
|
//--------------------------------------------------------------------------------------
|
|
@@ -258,9 +271,6 @@ namespace Lemma {
|
258
|
271
|
Vector3r Mn0 = ComputeMn0(phi, B0);
|
259
|
272
|
Real Mn0Abs = Mn0.norm();
|
260
|
273
|
|
261
|
|
- Real Taup = 0.020; // s
|
262
|
|
- Real Ip = 10; // A
|
263
|
|
-
|
264
|
274
|
// Compute the tipping angle
|
265
|
275
|
Real sintheta = std::sin(0.5*GAMMA*Ip*Taup*std::abs(EBT.alpha-EBT.beta));
|
266
|
276
|
|
|
@@ -279,7 +289,6 @@ namespace Lemma {
|
279
|
289
|
const Real& vol) {
|
280
|
290
|
|
281
|
291
|
Vector3r B0hat = {1,0,0};
|
282
|
|
- Real Larmor = 2500.*2.*PI;
|
283
|
292
|
|
284
|
293
|
// earth response of receiver adjoint field
|
285
|
294
|
Complex ejztr = std::exp(Complex(0, EBR.zeta + EBT.zeta));
|
|
@@ -384,7 +393,7 @@ namespace Lemma {
|
384
|
393
|
|
385
|
394
|
Complex ksum = kvals.sum(); // Kernel sum
|
386
|
395
|
// Evaluate whether or not furthur splitting is needed
|
387
|
|
- if ( std::abs(ksum - parentVal) > tol || level < 2 ) {
|
|
396
|
+ if ( std::abs(ksum - parentVal) > tol || level < minLevel && level < maxLevel ) {
|
388
|
397
|
for (int ichild=0; ichild<8; ++ichild) {
|
389
|
398
|
Vector3r cp = pos; // Eigen complains about combining these
|
390
|
399
|
cp += posadd.row(ichild);
|
|
@@ -467,7 +476,8 @@ namespace Lemma {
|
467
|
476
|
|
468
|
477
|
Complex ksum = kvals.sum(); // Kernel sum
|
469
|
478
|
// Evaluate whether or not furthur splitting is needed
|
470
|
|
- if ( std::abs(ksum - parentVal) > tol || level < 2 ) {
|
|
479
|
+ Real err = std::abs(ksum - parentVal);
|
|
480
|
+ if ( std::abs(ksum - parentVal) > tol || level < minLevel && level < maxLevel ) {
|
471
|
481
|
oct->SubdivideLeaf(curse);
|
472
|
482
|
for (int ichild=0; ichild<8; ++ichild) {
|
473
|
483
|
curse->ToChild(ichild);
|
|
@@ -482,6 +492,7 @@ namespace Lemma {
|
482
|
492
|
bool isleaf = EvaluateKids2( size, level+1, cp, kvals(ichild), oct, curse );
|
483
|
493
|
if (isleaf) { // Include result in final integral
|
484
|
494
|
LeafDict[curse->GetLeafId()] = kvals(ichild); // VTK
|
|
495
|
+ LeafDictIdx[curse->GetLeafId()] = nleaves; // VTK
|
485
|
496
|
SUM += ksum;
|
486
|
497
|
VOLSUM += 8*vol;
|
487
|
498
|
nleaves += 1;
|