Bladeren bron

Cleaning up kernel calculatio

master
Trevor Irons 8 jaren geleden
bovenliggende
commit
53d70afdf5
3 gewijzigde bestanden met toevoegingen van 24 en 33 verwijderingen
  1. 9
    1
      examples/KernelV0.cpp
  2. 2
    2
      include/KernelV0.h
  3. 13
    30
      src/KernelV0.cpp

+ 9
- 1
examples/KernelV0.cpp Bestand weergeven

@@ -49,6 +49,14 @@ int main() {
49 49
         //Kern->SetTolerance( .55 ) ; // 1%
50 50
 
51 51
         Kern->SetPulseDuration(0.020);
52
+        VectorXr I(36);
53
+        I << 397.4208916184016, 352.364477036168, 313.0112765842783, 278.37896394065376, 247.81424224324982,
54
+             220.77925043190442, 196.76493264105017, 175.31662279234038, 156.0044839325404, 138.73983004230124,
55
+             123.42064612625474, 109.82713394836259, 97.76534468972267, 87.06061858367781, 77.56000002944572, 69.1280780096311,
56
+             61.64250263640252, 54.99473044877554, 49.091182970515476, 43.84634004556388, 39.184136917167976, 35.03619319797924,
57
+             31.347205894128976, 28.06346770557137, 25.139117042424758, 22.53420773366429, 20.214205433283347,
58
+             18.144318026099942, 16.299965972298878, 14.652633628829891, 13.184271405688083, 11.870540177313893,
59
+             10.697057141915716, 9.64778948429609, 8.709338689612677, 7.871268012862094;
52 60
         Kern->SetPulseCurrent( VectorXr::LinSpaced( 1, 10, 200 )  ); // nbins, low, high
53 61
         Kern->SetDepthLayerInterfaces( VectorXr::LinSpaced( 2, 5, 5.5 ) );
54 62
 
@@ -56,7 +64,7 @@ int main() {
56 64
     // may be more natural to work with?
57 65
     std::vector<std::string> tx = {std::string("Coil 1")};
58 66
     std::vector<std::string> rx = {std::string("Coil 1")};
59
-    Kern->CalculateK0( tx, rx, true );
67
+    Kern->CalculateK0( tx, rx, false );
60 68
 
61 69
 }
62 70
 

+ 2
- 2
include/KernelV0.h Bestand weergeven

@@ -248,7 +248,7 @@ namespace Lemma {
248 248
          *  @param[in] level gives the current level of the octree grid, call with 0 initially
249 249
          *  @param[in] cpos is the centre position of the parent cuboid
250 250
          */
251
-        bool EvaluateKids(  const Vector3r& size, const int& level, const Vector3r& cpos,
251
+        void EvaluateKids(  const Vector3r& size, const int& level, const Vector3r& cpos,
252 252
                             const Complex& parentVal );
253 253
 
254 254
         #ifdef LEMMAUSEVTK
@@ -256,7 +256,7 @@ namespace Lemma {
256 256
          *  Same functionality as @see EvaluateKids, but includes generation of a VTK
257 257
          *  HyperOctree, which is useful for visualization.
258 258
          */
259
-        bool EvaluateKids2(  const Vector3r& size, const int& level, const Vector3r& cpos,
259
+        void EvaluateKids2(  const Vector3r& size, const int& level, const Vector3r& cpos,
260 260
                             const Complex& parentVal, vtkHyperOctree* octree, vtkHyperOctreeCursor* curse );
261 261
 
262 262
         void GetPosition( vtkHyperOctreeCursor* Cursor, Real* p );

+ 13
- 30
src/KernelV0.cpp Bestand weergeven

@@ -337,7 +337,7 @@ namespace Lemma {
337 337
     //       Class:  KernelV0
338 338
     //      Method:  EvaluateKids
339 339
     //--------------------------------------------------------------------------------------
340
-    bool KernelV0::EvaluateKids( const Vector3r& size, const int& level, const Vector3r& cpos,
340
+    void KernelV0::EvaluateKids( const Vector3r& size, const int& level, const Vector3r& cpos,
341 341
         const Complex& parentVal ) {
342 342
 
343 343
         std::cout << "\r" << (int)(1e2*VOLSUM/(Size[0]*Size[1]*Size[2])) << "\t" << nleaves;
@@ -346,9 +346,7 @@ namespace Lemma {
346 346
         // Next level step, interested in one level below
347 347
         // bitshift requires one extra, faster than, and equivalent to std::pow(2, level+1)
348 348
         Vector3r step  = size.array() / (Real)(1 << (level+1) );
349
-        Vector3r step2 = size.array() / (Real)(1 << (level+2) );
350
-
351
-        Real vol = (step2(0)*step2(1)*step2(2));     // volume of each child
349
+        Real vol = (step(0)*step(1)*step(2));     // volume of each child
352 350
 
353 351
         Vector3r pos =  cpos - step/2.;
354 352
         Eigen::Matrix<Real, 8, 3> posadd = (Eigen::Matrix<Real, 8, 3>() <<
@@ -403,17 +401,15 @@ namespace Lemma {
403 401
             for (int ichild=0; ichild<8; ++ichild) {
404 402
                 Vector3r cp = pos; // Eigen complains about combining these
405 403
                 cp += posadd.row(ichild);
406
-                bool isleaf = EvaluateKids( size, level+1, cp, kvals(ichild) );
407
-                if (isleaf) {      // Include result in final integral
408
-                    SUM += ksum;
409
-                    VOLSUM += 8.*vol;
410
-                    nleaves += 1;
411
-                }
404
+                EvaluateKids( size, level+1, cp, kvals(ichild) );
412 405
             }
413
-            return false;  // not leaf
406
+            return; // not leaf
414 407
         }
415 408
         // Save here instead?
416
-        return true;       // leaf
409
+        SUM += ksum;
410
+        VOLSUM += 8.*vol;
411
+        nleaves += 1;
412
+        return;     // is leaf
417 413
     }
418 414
 
419 415
     #ifdef LEMMAUSEVTK
@@ -421,7 +417,7 @@ namespace Lemma {
421 417
     //       Class:  KernelV0
422 418
     //      Method:  EvaluateKids2 -- same as Evaluate Kids, but include VTK octree generation
423 419
     //--------------------------------------------------------------------------------------
424
-    bool KernelV0::EvaluateKids2( const Vector3r& size, const int& level, const Vector3r& cpos,
420
+    void KernelV0::EvaluateKids2( const Vector3r& size, const int& level, const Vector3r& cpos,
425 421
         const Complex& parentVal, vtkHyperOctree* oct, vtkHyperOctreeCursor* curse) {
426 422
 
427 423
         std::cout << "\r" << (int)(1e2*VOLSUM/(Size[0]*Size[1]*Size[2])) << "\t" << nleaves;
@@ -432,9 +428,6 @@ namespace Lemma {
432 428
         Vector3r step  = size.array() / (Real)(1 << (level+1) );
433 429
         Real vol = (step(0)*step(1)*step(2));         // volume of each child
434 430
 
435
-        Vector3r step2 = size.array() / (Real)(1 << (level+2) );
436
-        Real vol2 = (step2(0)*step2(1)*step2(2));     // volume of each child
437
-
438 431
         Vector3r pos =  cpos - step/2.;
439 432
         Eigen::Matrix<Real, 8, 3> posadd = (Eigen::Matrix<Real, 8, 3>() <<
440 433
                         0,       0,       0,
@@ -483,9 +476,8 @@ namespace Lemma {
483 476
 
484 477
         Complex ksum = kvals.sum();     // Kernel sum
485 478
         // Evaluate whether or not furthur splitting is needed
486
-        if ( std::abs(ksum-parentVal) > tol ) { // || level < minLevel && level < maxLevel ) {
479
+        if ( std::abs(ksum - parentVal) > tol || level < minLevel && level < maxLevel ) {
487 480
         //if ( std::abs(ksum.real()-parentVal.real())>tol || std::abs(ksum.imag()-parentVal.imag()) >tol ) {
488
-        //if ( std::abs(ksum) > tol && level < maxLevel ) {
489 481
             oct->SubdivideLeaf(curse);
490 482
             for (int ichild=0; ichild<8; ++ichild) {
491 483
                 curse->ToChild(ichild);
@@ -502,26 +494,17 @@ namespace Lemma {
502 494
                 }
503 495
                 */
504 496
                 /* End of position test */
505
-                bool isleaf = EvaluateKids2( size, level+1, cp, kvals(ichild), oct, curse );
506
-                /*
507
-                if (isleaf) {  // Include result in final integral
508
-                    LeafDict[curse->GetLeafId()] = ksum/(8.*vol);     //kvals(ichild) / vol;     // VTK
509
-                    LeafDictIdx[curse->GetLeafId()] = nleaves;        // VTK
510
-                    SUM += ksum;
511
-                    VOLSUM += 8*vol;
512
-                    nleaves += 1;
513
-                }
514
-                */
497
+                EvaluateKids2( size, level+1, cp, kvals(ichild), oct, curse );
515 498
                 curse->ToParent();
516 499
             }
517
-            return false;  // not leaf
500
+            return;  // not a leaf
518 501
         }
519 502
         LeafDict[curse->GetLeafId()] = ksum/(8.*vol);     //kvals(ichild) / vol;     // VTK
520 503
         LeafDictIdx[curse->GetLeafId()] = nleaves;        // VTK
521 504
         SUM += ksum;
522 505
         VOLSUM += 8*vol;
523 506
         nleaves += 1;
524
-        return true;       // leaf
507
+        return;     // is a leaf
525 508
     }
526 509
 
527 510
     //--------------------------------------------------------------------------------------

Laden…
Annuleren
Opslaan