Browse Source

Tweaks to integration routine, simplier now

master
Trevor Irons 7 years ago
parent
commit
579467b332
3 changed files with 39 additions and 21 deletions
  1. 7
    6
      examples/KernelV0.cpp
  2. 2
    2
      include/KernelV0.h
  3. 30
    13
      src/KernelV0.cpp

+ 7
- 6
examples/KernelV0.cpp View File

@@ -33,8 +33,8 @@ int main() {
33 33
         earth->SetMagneticFieldIncDecMag( 67, 0, 52750, NANOTESLA );
34 34
 
35 35
     // Transmitter loops
36
-    auto Tx1 = CircularLoop(31, 15, 100, 100);
37
-    auto Tx2 = CircularLoop(31, 15, 100, 120);
36
+    auto Tx1 = CircularLoop(21, 15, 100, 100);
37
+    auto Tx2 = CircularLoop(21, 15, 100, 120);
38 38
     //auto Tx1 = CircularLoop(60, 15, 0, 0); // was 60
39 39
 
40 40
     auto Kern = KernelV0::NewSP();
@@ -43,13 +43,14 @@ int main() {
43 43
         Kern->SetLayeredEarthEM( earth );
44 44
         // std::cout << *Kern << std::endl;
45 45
 
46
-        Kern->SetIntegrationSize( (Vector3r() << 200,200,2).finished() );
47
-        Kern->SetIntegrationOrigin( (Vector3r() << 0,0,15).finished() );
46
+        Kern->SetIntegrationSize( (Vector3r() << 200,200,200).finished() );
47
+        Kern->SetIntegrationOrigin( (Vector3r() << 0,0,0).finished() );
48 48
         Kern->SetTolerance( 1e-13 );
49
+        //Kern->SetTolerance( .55 ) ; // 1%
49 50
 
50 51
         Kern->SetPulseDuration(0.020);
51
-        Kern->SetPulseCurrent( VectorXr::LinSpaced( 20, .01, 200 )  ); // nbins, low, high
52
-        Kern->SetDepthLayerInterfaces( VectorXr::LinSpaced( 20, .5, 50 ) );
52
+        Kern->SetPulseCurrent( VectorXr::LinSpaced( 1, 10, 200 )  ); // nbins, low, high
53
+        Kern->SetDepthLayerInterfaces( VectorXr::LinSpaced( 2, 5, 5.5 ) );
53 54
 
54 55
     // We could, I suppose, take the earth model in here? For non-linear that
55 56
     // may be more natural to work with?

+ 2
- 2
include/KernelV0.h View File

@@ -265,8 +265,8 @@ namespace Lemma {
265 265
         // ====================  DATA MEMBERS  =========================
266 266
 
267 267
         int                                       nleaves;
268
-        int                                       minLevel=3;
269
-        int                                       maxLevel=10;
268
+        int                                       minLevel=4;
269
+        int                                       maxLevel=8;
270 270
 
271 271
         Real                                      VOLSUM;
272 272
         Real                                      tol=1e-11;

+ 30
- 13
src/KernelV0.cpp View File

@@ -138,9 +138,9 @@ namespace Lemma {
138 138
         }
139 139
 
140 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) {
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(); ++iq) {
144 144
                 std::cout << "Layer " << ilay << " q " << iq << std::endl;
145 145
                 Size(2) = Interfaces(ilay+1) - Interfaces(ilay);
146 146
                 Origin(2) = Interfaces(ilay);
@@ -162,7 +162,7 @@ namespace Lemma {
162 162
     //--------------------------------------------------------------------------------------
163 163
     Complex KernelV0::IntegrateOnOctreeGrid( const int& ilay, const int& iq, bool vtkOutput) {
164 164
 
165
-        Vector3r cpos = (Size-Origin).array() / 2.;
165
+        Vector3r cpos = Origin + Size/2.;
166 166
 
167 167
         SUM = 0;
168 168
         VOLSUM = 0;
@@ -200,12 +200,15 @@ namespace Lemma {
200 200
                 kerr->SetNumberOfComponents(1);
201 201
                 kerr->SetName("nleaf");
202 202
 
203
+            //Real LeafVol(0);
203 204
             for (auto leaf : LeafDict) {
204 205
                 kr->InsertTuple1( leaf.first, std::real(leaf.second) );
205 206
                 ki->InsertTuple1( leaf.first, std::imag(leaf.second) );
206 207
                 km->InsertTuple1( leaf.first, std::abs(leaf.second) );
207 208
                 kid->InsertTuple1( leaf.first, leaf.first );
209
+                //LeafVol += std::real(leaf.second);
208 210
             }
211
+            //std::cout << "\n\nLeafVol=" << LeafVol << std::endl;
209 212
 
210 213
             for (auto leaf : LeafDictIdx) {
211 214
                 kerr->InsertTuple1( leaf.first, leaf.second );
@@ -427,9 +430,10 @@ namespace Lemma {
427 430
         // Next level step, interested in one level below
428 431
         // bitshift requires one extra, faster than, and equivalent to std::pow(2, level+1)
429 432
         Vector3r step  = size.array() / (Real)(1 << (level+1) );
430
-        Vector3r step2 = size.array() / (Real)(1 << (level+2) );
433
+        Real vol = (step(0)*step(1)*step(2));         // volume of each child
431 434
 
432
-        Real vol = (step2(0)*step2(1)*step2(2));     // volume of each child
435
+        Vector3r step2 = size.array() / (Real)(1 << (level+2) );
436
+        Real vol2 = (step2(0)*step2(1)*step2(2));     // volume of each child
433 437
 
434 438
         Vector3r pos =  cpos - step/2.;
435 439
         Eigen::Matrix<Real, 8, 3> posadd = (Eigen::Matrix<Real, 8, 3>() <<
@@ -479,31 +483,44 @@ namespace Lemma {
479 483
 
480 484
         Complex ksum = kvals.sum();     // Kernel sum
481 485
         // Evaluate whether or not furthur splitting is needed
482
-        Real err = std::abs(ksum - parentVal);
483
-        if ( std::abs(ksum - parentVal) > tol || level < minLevel && level < maxLevel ) {
486
+        if ( std::abs(ksum-parentVal) > tol ) { // || level < minLevel && level < maxLevel ) {
487
+        //if ( std::abs(ksum.real()-parentVal.real())>tol || std::abs(ksum.imag()-parentVal.imag()) >tol ) {
488
+        //if ( std::abs(ksum) > tol && level < maxLevel ) {
484 489
             oct->SubdivideLeaf(curse);
485 490
             for (int ichild=0; ichild<8; ++ichild) {
486 491
                 curse->ToChild(ichild);
487 492
                 Vector3r cp = pos; // Eigen complains about combining these
488 493
                 cp += posadd.row(ichild);
489
-                /* Test for position via alternative means
494
+                /* Test for position via alternative means */
495
+                /*
490 496
                 Real p[3];
491 497
                 GetPosition(curse, p);
492
-                std::cout << cp[0] << "\t" << p[0] << "\t" << cp[1] << "\t" << p[1]
493
-                          << "\t" << cp[2] << "\t" << p[2] << "\t" <<  vol<< std::endl;
498
+                if ( (Vector3r(p) - cp).norm() > 1e-8 ) {
499
+                    std::cout << "ERROR @ nleaves" << nleaves << "\n" << cp[0] << "\t" << p[0] << "\t" << cp[1] << "\t" << p[1]
500
+                              << "\t" << cp[2] << "\t" << p[2] << "\t" << vol<< std::endl;
501
+                    throw std::runtime_error("doom");
502
+                }
494 503
                 */
504
+                /* End of position test */
495 505
                 bool isleaf = EvaluateKids2( size, level+1, cp, kvals(ichild), oct, curse );
506
+                /*
496 507
                 if (isleaf) {  // Include result in final integral
497
-                    LeafDict[curse->GetLeafId()] = kvals(ichild);       // VTK
498
-                    LeafDictIdx[curse->GetLeafId()] = nleaves;          // VTK
508
+                    LeafDict[curse->GetLeafId()] = ksum/(8.*vol);     //kvals(ichild) / vol;     // VTK
509
+                    LeafDictIdx[curse->GetLeafId()] = nleaves;        // VTK
499 510
                     SUM += ksum;
500 511
                     VOLSUM += 8*vol;
501 512
                     nleaves += 1;
502 513
                 }
514
+                */
503 515
                 curse->ToParent();
504 516
             }
505 517
             return false;  // not leaf
506 518
         }
519
+        LeafDict[curse->GetLeafId()] = ksum/(8.*vol);     //kvals(ichild) / vol;     // VTK
520
+        LeafDictIdx[curse->GetLeafId()] = nleaves;        // VTK
521
+        SUM += ksum;
522
+        VOLSUM += 8*vol;
523
+        nleaves += 1;
507 524
         return true;       // leaf
508 525
     }
509 526
 

Loading…
Cancel
Save