Browse Source

Tweaks to integration routine, simplier now

master
Trevor Irons 8 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
         earth->SetMagneticFieldIncDecMag( 67, 0, 52750, NANOTESLA );
33
         earth->SetMagneticFieldIncDecMag( 67, 0, 52750, NANOTESLA );
34
 
34
 
35
     // Transmitter loops
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
     //auto Tx1 = CircularLoop(60, 15, 0, 0); // was 60
38
     //auto Tx1 = CircularLoop(60, 15, 0, 0); // was 60
39
 
39
 
40
     auto Kern = KernelV0::NewSP();
40
     auto Kern = KernelV0::NewSP();
43
         Kern->SetLayeredEarthEM( earth );
43
         Kern->SetLayeredEarthEM( earth );
44
         // std::cout << *Kern << std::endl;
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
         Kern->SetTolerance( 1e-13 );
48
         Kern->SetTolerance( 1e-13 );
49
+        //Kern->SetTolerance( .55 ) ; // 1%
49
 
50
 
50
         Kern->SetPulseDuration(0.020);
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
     // We could, I suppose, take the earth model in here? For non-linear that
55
     // We could, I suppose, take the earth model in here? For non-linear that
55
     // may be more natural to work with?
56
     // may be more natural to work with?

+ 2
- 2
include/KernelV0.h View File

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

+ 30
- 13
src/KernelV0.cpp View File

138
         }
138
         }
139
 
139
 
140
         std::cout << "Calculating K0 kernel\n";
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
                 std::cout << "Layer " << ilay << " q " << iq << std::endl;
144
                 std::cout << "Layer " << ilay << " q " << iq << std::endl;
145
                 Size(2) = Interfaces(ilay+1) - Interfaces(ilay);
145
                 Size(2) = Interfaces(ilay+1) - Interfaces(ilay);
146
                 Origin(2) = Interfaces(ilay);
146
                 Origin(2) = Interfaces(ilay);
162
     //--------------------------------------------------------------------------------------
162
     //--------------------------------------------------------------------------------------
163
     Complex KernelV0::IntegrateOnOctreeGrid( const int& ilay, const int& iq, bool vtkOutput) {
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
         SUM = 0;
167
         SUM = 0;
168
         VOLSUM = 0;
168
         VOLSUM = 0;
200
                 kerr->SetNumberOfComponents(1);
200
                 kerr->SetNumberOfComponents(1);
201
                 kerr->SetName("nleaf");
201
                 kerr->SetName("nleaf");
202
 
202
 
203
+            //Real LeafVol(0);
203
             for (auto leaf : LeafDict) {
204
             for (auto leaf : LeafDict) {
204
                 kr->InsertTuple1( leaf.first, std::real(leaf.second) );
205
                 kr->InsertTuple1( leaf.first, std::real(leaf.second) );
205
                 ki->InsertTuple1( leaf.first, std::imag(leaf.second) );
206
                 ki->InsertTuple1( leaf.first, std::imag(leaf.second) );
206
                 km->InsertTuple1( leaf.first, std::abs(leaf.second) );
207
                 km->InsertTuple1( leaf.first, std::abs(leaf.second) );
207
                 kid->InsertTuple1( leaf.first, leaf.first );
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
             for (auto leaf : LeafDictIdx) {
213
             for (auto leaf : LeafDictIdx) {
211
                 kerr->InsertTuple1( leaf.first, leaf.second );
214
                 kerr->InsertTuple1( leaf.first, leaf.second );
427
         // Next level step, interested in one level below
430
         // Next level step, interested in one level below
428
         // bitshift requires one extra, faster than, and equivalent to std::pow(2, level+1)
431
         // bitshift requires one extra, faster than, and equivalent to std::pow(2, level+1)
429
         Vector3r step  = size.array() / (Real)(1 << (level+1) );
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
         Vector3r pos =  cpos - step/2.;
438
         Vector3r pos =  cpos - step/2.;
435
         Eigen::Matrix<Real, 8, 3> posadd = (Eigen::Matrix<Real, 8, 3>() <<
439
         Eigen::Matrix<Real, 8, 3> posadd = (Eigen::Matrix<Real, 8, 3>() <<
479
 
483
 
480
         Complex ksum = kvals.sum();     // Kernel sum
484
         Complex ksum = kvals.sum();     // Kernel sum
481
         // Evaluate whether or not furthur splitting is needed
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
             oct->SubdivideLeaf(curse);
489
             oct->SubdivideLeaf(curse);
485
             for (int ichild=0; ichild<8; ++ichild) {
490
             for (int ichild=0; ichild<8; ++ichild) {
486
                 curse->ToChild(ichild);
491
                 curse->ToChild(ichild);
487
                 Vector3r cp = pos; // Eigen complains about combining these
492
                 Vector3r cp = pos; // Eigen complains about combining these
488
                 cp += posadd.row(ichild);
493
                 cp += posadd.row(ichild);
489
-                /* Test for position via alternative means
494
+                /* Test for position via alternative means */
495
+                /*
490
                 Real p[3];
496
                 Real p[3];
491
                 GetPosition(curse, p);
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
                 bool isleaf = EvaluateKids2( size, level+1, cp, kvals(ichild), oct, curse );
505
                 bool isleaf = EvaluateKids2( size, level+1, cp, kvals(ichild), oct, curse );
506
+                /*
496
                 if (isleaf) {  // Include result in final integral
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
                     SUM += ksum;
510
                     SUM += ksum;
500
                     VOLSUM += 8*vol;
511
                     VOLSUM += 8*vol;
501
                     nleaves += 1;
512
                     nleaves += 1;
502
                 }
513
                 }
514
+                */
503
                 curse->ToParent();
515
                 curse->ToParent();
504
             }
516
             }
505
             return false;  // not leaf
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
         return true;       // leaf
524
         return true;       // leaf
508
     }
525
     }
509
 
526
 

Loading…
Cancel
Save