Procházet zdrojové kódy

Cleaning up kernel calculatio

master
Trevor Irons před 7 roky
rodič
revize
53d70afdf5
3 změnil soubory, kde provedl 24 přidání a 33 odebrání
  1. 9
    1
      examples/KernelV0.cpp
  2. 2
    2
      include/KernelV0.h
  3. 13
    30
      src/KernelV0.cpp

+ 9
- 1
examples/KernelV0.cpp Zobrazit soubor

49
         //Kern->SetTolerance( .55 ) ; // 1%
49
         //Kern->SetTolerance( .55 ) ; // 1%
50
 
50
 
51
         Kern->SetPulseDuration(0.020);
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
         Kern->SetPulseCurrent( VectorXr::LinSpaced( 1, 10, 200 )  ); // nbins, low, high
60
         Kern->SetPulseCurrent( VectorXr::LinSpaced( 1, 10, 200 )  ); // nbins, low, high
53
         Kern->SetDepthLayerInterfaces( VectorXr::LinSpaced( 2, 5, 5.5 ) );
61
         Kern->SetDepthLayerInterfaces( VectorXr::LinSpaced( 2, 5, 5.5 ) );
54
 
62
 
56
     // may be more natural to work with?
64
     // may be more natural to work with?
57
     std::vector<std::string> tx = {std::string("Coil 1")};
65
     std::vector<std::string> tx = {std::string("Coil 1")};
58
     std::vector<std::string> rx = {std::string("Coil 1")};
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 Zobrazit soubor

248
          *  @param[in] level gives the current level of the octree grid, call with 0 initially
248
          *  @param[in] level gives the current level of the octree grid, call with 0 initially
249
          *  @param[in] cpos is the centre position of the parent cuboid
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
                             const Complex& parentVal );
252
                             const Complex& parentVal );
253
 
253
 
254
         #ifdef LEMMAUSEVTK
254
         #ifdef LEMMAUSEVTK
256
          *  Same functionality as @see EvaluateKids, but includes generation of a VTK
256
          *  Same functionality as @see EvaluateKids, but includes generation of a VTK
257
          *  HyperOctree, which is useful for visualization.
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
                             const Complex& parentVal, vtkHyperOctree* octree, vtkHyperOctreeCursor* curse );
260
                             const Complex& parentVal, vtkHyperOctree* octree, vtkHyperOctreeCursor* curse );
261
 
261
 
262
         void GetPosition( vtkHyperOctreeCursor* Cursor, Real* p );
262
         void GetPosition( vtkHyperOctreeCursor* Cursor, Real* p );

+ 13
- 30
src/KernelV0.cpp Zobrazit soubor

337
     //       Class:  KernelV0
337
     //       Class:  KernelV0
338
     //      Method:  EvaluateKids
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
         const Complex& parentVal ) {
341
         const Complex& parentVal ) {
342
 
342
 
343
         std::cout << "\r" << (int)(1e2*VOLSUM/(Size[0]*Size[1]*Size[2])) << "\t" << nleaves;
343
         std::cout << "\r" << (int)(1e2*VOLSUM/(Size[0]*Size[1]*Size[2])) << "\t" << nleaves;
346
         // Next level step, interested in one level below
346
         // Next level step, interested in one level below
347
         // bitshift requires one extra, faster than, and equivalent to std::pow(2, level+1)
347
         // bitshift requires one extra, faster than, and equivalent to std::pow(2, level+1)
348
         Vector3r step  = size.array() / (Real)(1 << (level+1) );
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
         Vector3r pos =  cpos - step/2.;
351
         Vector3r pos =  cpos - step/2.;
354
         Eigen::Matrix<Real, 8, 3> posadd = (Eigen::Matrix<Real, 8, 3>() <<
352
         Eigen::Matrix<Real, 8, 3> posadd = (Eigen::Matrix<Real, 8, 3>() <<
403
             for (int ichild=0; ichild<8; ++ichild) {
401
             for (int ichild=0; ichild<8; ++ichild) {
404
                 Vector3r cp = pos; // Eigen complains about combining these
402
                 Vector3r cp = pos; // Eigen complains about combining these
405
                 cp += posadd.row(ichild);
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
         // Save here instead?
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
     #ifdef LEMMAUSEVTK
415
     #ifdef LEMMAUSEVTK
421
     //       Class:  KernelV0
417
     //       Class:  KernelV0
422
     //      Method:  EvaluateKids2 -- same as Evaluate Kids, but include VTK octree generation
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
         const Complex& parentVal, vtkHyperOctree* oct, vtkHyperOctreeCursor* curse) {
421
         const Complex& parentVal, vtkHyperOctree* oct, vtkHyperOctreeCursor* curse) {
426
 
422
 
427
         std::cout << "\r" << (int)(1e2*VOLSUM/(Size[0]*Size[1]*Size[2])) << "\t" << nleaves;
423
         std::cout << "\r" << (int)(1e2*VOLSUM/(Size[0]*Size[1]*Size[2])) << "\t" << nleaves;
432
         Vector3r step  = size.array() / (Real)(1 << (level+1) );
428
         Vector3r step  = size.array() / (Real)(1 << (level+1) );
433
         Real vol = (step(0)*step(1)*step(2));         // volume of each child
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
         Vector3r pos =  cpos - step/2.;
431
         Vector3r pos =  cpos - step/2.;
439
         Eigen::Matrix<Real, 8, 3> posadd = (Eigen::Matrix<Real, 8, 3>() <<
432
         Eigen::Matrix<Real, 8, 3> posadd = (Eigen::Matrix<Real, 8, 3>() <<
440
                         0,       0,       0,
433
                         0,       0,       0,
483
 
476
 
484
         Complex ksum = kvals.sum();     // Kernel sum
477
         Complex ksum = kvals.sum();     // Kernel sum
485
         // Evaluate whether or not furthur splitting is needed
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
         //if ( std::abs(ksum.real()-parentVal.real())>tol || std::abs(ksum.imag()-parentVal.imag()) >tol ) {
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
             oct->SubdivideLeaf(curse);
481
             oct->SubdivideLeaf(curse);
490
             for (int ichild=0; ichild<8; ++ichild) {
482
             for (int ichild=0; ichild<8; ++ichild) {
491
                 curse->ToChild(ichild);
483
                 curse->ToChild(ichild);
502
                 }
494
                 }
503
                 */
495
                 */
504
                 /* End of position test */
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
                 curse->ToParent();
498
                 curse->ToParent();
516
             }
499
             }
517
-            return false;  // not leaf
500
+            return;  // not a leaf
518
         }
501
         }
519
         LeafDict[curse->GetLeafId()] = ksum/(8.*vol);     //kvals(ichild) / vol;     // VTK
502
         LeafDict[curse->GetLeafId()] = ksum/(8.*vol);     //kvals(ichild) / vol;     // VTK
520
         LeafDictIdx[curse->GetLeafId()] = nleaves;        // VTK
503
         LeafDictIdx[curse->GetLeafId()] = nleaves;        // VTK
521
         SUM += ksum;
504
         SUM += ksum;
522
         VOLSUM += 8*vol;
505
         VOLSUM += 8*vol;
523
         nleaves += 1;
506
         nleaves += 1;
524
-        return true;       // leaf
507
+        return;     // is a leaf
525
     }
508
     }
526
 
509
 
527
     //--------------------------------------------------------------------------------------
510
     //--------------------------------------------------------------------------------------

Načítá se…
Zrušit
Uložit