Browse Source

Progress towards vtkHyperTreeGrid support

master
Trevor Irons 5 years ago
parent
commit
afb6bb645a
7 changed files with 93 additions and 45 deletions
  1. 1
    1
      examples/KernelV0.cpp
  2. 7
    4
      include/Coupling.h
  3. 9
    5
      include/KernelV0.h
  4. 4
    4
      include/LoopInteractions.h
  5. 1
    0
      include/MerlinObject.h
  6. 2
    2
      src/Coupling.cpp
  7. 69
    29
      src/KernelV0.cpp

+ 1
- 1
examples/KernelV0.cpp View File

82
     //std::vector<std::string> tx = {std::string("Coil 1"), std::string("Coil 2") };
82
     //std::vector<std::string> tx = {std::string("Coil 1"), std::string("Coil 2") };
83
     std::vector<std::string> tx = {std::string("Coil 1")};  //, std::string("Coil 2") };
83
     std::vector<std::string> tx = {std::string("Coil 1")};  //, std::string("Coil 2") };
84
     std::vector<std::string> rx = {std::string("Coil 2")};
84
     std::vector<std::string> rx = {std::string("Coil 2")};
85
-    Kern->CalculateK0( tx, rx, false );
85
+    Kern->CalculateK0( tx, rx, true );
86
 
86
 
87
 /*
87
 /*
88
     std::ofstream dout = std::ofstream(std::string("k-Tx2coil-Rx1coil-offset-")+ std::string(argv[1])+ std::string(".dat"));
88
     std::ofstream dout = std::ofstream(std::string("k-Tx2coil-Rx1coil-offset-")+ std::string(argv[1])+ std::string(".dat"));

+ 7
- 4
include/Coupling.h View File

26
 #include "EMEarth1D.h"
26
 #include "EMEarth1D.h"
27
 
27
 
28
 #ifdef LEMMAUSEVTK
28
 #ifdef LEMMAUSEVTK
29
-#include "vtkHyperOctree.h"
30
-#include "vtkHyperOctreeCursor.h"
31
-#include "vtkXMLHyperOctreeWriter.h"
29
+//#include "vtkHyperOctree.h"
30
+//#include "vtkHyperOctreeCursor.h"
31
+//#include "vtkXMLHyperOctreeWriter.h"
32
+#include "vtkHyperTreeGrid.h"
33
+#include "vtkHyperTreeCursor.h"
34
+#include "vtkXMLHyperTreeGridWriter.h"
32
 #include "vtkDoubleArray.h"
35
 #include "vtkDoubleArray.h"
33
 #endif
36
 #endif
34
 
37
 
200
         void EvaluateKids(  const Vector3r& size, const int& level, const Vector3r& cpos,
203
         void EvaluateKids(  const Vector3r& size, const int& level, const Vector3r& cpos,
201
                             const Complex& parentVal );
204
                             const Complex& parentVal );
202
 
205
 
203
-        #ifdef LEMMAUSEVTK
206
+        #ifdef LEMMAUSEVTK6
204
         /**
207
         /**
205
          *  Same functionality as @see EvaluateKids, but includes generation of a VTK
208
          *  Same functionality as @see EvaluateKids, but includes generation of a VTK
206
          *  HyperOctree, which is useful for visualization.
209
          *  HyperOctree, which is useful for visualization.

+ 9
- 5
include/KernelV0.h View File

26
 #include "EMEarth1D.h"
26
 #include "EMEarth1D.h"
27
 
27
 
28
 #ifdef LEMMAUSEVTK
28
 #ifdef LEMMAUSEVTK
29
-#include "vtkHyperOctree.h"
30
-#include "vtkHyperOctreeCursor.h"
31
-#include "vtkXMLHyperOctreeWriter.h"
29
+//#include "vtkHyperOctree.h"
30
+//#include "vtkHyperOctreeCursor.h"
31
+//#include "vtkXMLHyperOctreeWriter.h"
32
+#include "vtkHyperTreeGrid.h"
33
+#include "vtkHyperTreeCursor.h"
34
+#include "vtkXMLHyperTreeGridWriter.h"
35
+//#include "vtkHyperTreeGridLevelEntry.h" VTK 9
32
 #include "vtkDoubleArray.h"
36
 #include "vtkDoubleArray.h"
33
 #endif
37
 #endif
34
 
38
 
299
          *  HyperOctree, which is useful for visualization.
303
          *  HyperOctree, which is useful for visualization.
300
          */
304
          */
301
         void EvaluateKids2(  const Vector3r& size, const int& level, const Vector3r& cpos,
305
         void EvaluateKids2(  const Vector3r& size, const int& level, const Vector3r& cpos,
302
-                            const VectorXcr& parentVal, vtkHyperOctree* octree, vtkHyperOctreeCursor* curse );
306
+                            const VectorXcr& parentVal, vtkHyperTreeGrid* octree, vtkHyperTreeCursor* curse );
303
 
307
 
304
-        void GetPosition( vtkHyperOctreeCursor* Cursor, Real* p );
308
+        void GetPosition( vtkHyperTreeCursor* Cursor, Real* p );
305
         #endif
309
         #endif
306
 
310
 
307
         // ====================  DATA MEMBERS  =========================
311
         // ====================  DATA MEMBERS  =========================

+ 4
- 4
include/LoopInteractions.h View File

26
 #include "EMEarth1D.h"
26
 #include "EMEarth1D.h"
27
 #include "FieldPoints.h"
27
 #include "FieldPoints.h"
28
 
28
 
29
-#ifdef LEMMAUSEVTK
29
+#ifdef LEMMAUSEVTK6
30
 #include "vtkHyperOctree.h"
30
 #include "vtkHyperOctree.h"
31
 #include "vtkHyperOctreeCursor.h"
31
 #include "vtkHyperOctreeCursor.h"
32
 #include "vtkXMLHyperOctreeWriter.h"
32
 #include "vtkXMLHyperOctreeWriter.h"
232
         void EvaluateKids(  const Vector3r& size, const int& level, const Vector3r& cpos,
232
         void EvaluateKids(  const Vector3r& size, const int& level, const Vector3r& cpos,
233
                             const Complex& parentVal );
233
                             const Complex& parentVal );
234
 
234
 
235
-        #ifdef LEMMAUSEVTK
235
+        #ifdef LEMMAUSEVTK6
236
         /**
236
         /**
237
          *  Same functionality as @see EvaluateKids, but includes generation of a VTK
237
          *  Same functionality as @see EvaluateKids, but includes generation of a VTK
238
          *  HyperOctree, which is useful for visualization.
238
          *  HyperOctree, which is useful for visualization.
358
         if (!vtkOutput) {
358
         if (!vtkOutput) {
359
             EvaluateKids( Size, 0, cpos, Complex(100.));
359
             EvaluateKids( Size, 0, cpos, Complex(100.));
360
         } else {
360
         } else {
361
-        #ifdef LEMMAUSEVTK
361
+        #ifdef LEMMAUSEVTK6
362
             vtkHyperOctree* oct = vtkHyperOctree::New();
362
             vtkHyperOctree* oct = vtkHyperOctree::New();
363
                 oct->SetDimension(3);
363
                 oct->SetDimension(3);
364
                 oct->SetOrigin( Origin(0), Origin(1), Origin(2) );
364
                 oct->SetOrigin( Origin(0), Origin(1), Origin(2) );
521
         return;     // is leaf
521
         return;     // is leaf
522
     }
522
     }
523
 
523
 
524
-    #ifdef LEMMAUSEVTK
524
+    #ifdef LEMMAUSEVTK6
525
     //--------------------------------------------------------------------------------------
525
     //--------------------------------------------------------------------------------------
526
     //       Class:  LoopInteractions
526
     //       Class:  LoopInteractions
527
     //      Method:  EvaluateKids2 -- same as Evaluate Kids, but include VTK octree generation
527
     //      Method:  EvaluateKids2 -- same as Evaluate Kids, but include VTK octree generation

+ 1
- 0
include/MerlinObject.h View File

119
         static constexpr auto CName = "MerlinObject";
119
         static constexpr auto CName = "MerlinObject";
120
 
120
 
121
     }; // -----  end of class  MerlinObject  -----
121
     }; // -----  end of class  MerlinObject  -----
122
+
122
 }  // -----  end of namespace Lemma ----
123
 }  // -----  end of namespace Lemma ----
123
 
124
 
124
 /* vim: set tabstop=4 expandtab: */
125
 /* vim: set tabstop=4 expandtab: */

+ 2
- 2
src/Coupling.cpp View File

165
         if (!vtkOutput) {
165
         if (!vtkOutput) {
166
             EvaluateKids( Size, 0, cpos, Complex(100.));
166
             EvaluateKids( Size, 0, cpos, Complex(100.));
167
         } else {
167
         } else {
168
-        #ifdef LEMMAUSEVTK
168
+        #ifdef LEMMAUSEVTK6
169
             vtkHyperOctree* oct = vtkHyperOctree::New();
169
             vtkHyperOctree* oct = vtkHyperOctree::New();
170
                 oct->SetDimension(3);
170
                 oct->SetDimension(3);
171
                 oct->SetOrigin( Origin(0), Origin(1), Origin(2) );
171
                 oct->SetOrigin( Origin(0), Origin(1), Origin(2) );
336
         return;     // is leaf
336
         return;     // is leaf
337
     }
337
     }
338
 
338
 
339
-    #ifdef LEMMAUSEVTK
339
+    #ifdef LEMMAUSEVTK6
340
     //--------------------------------------------------------------------------------------
340
     //--------------------------------------------------------------------------------------
341
     //       Class:  Coupling
341
     //       Class:  Coupling
342
     //      Method:  EvaluateKids2 -- same as Evaluate Kids, but include VTK octree generation
342
     //      Method:  EvaluateKids2 -- same as Evaluate Kids, but include VTK octree generation

+ 69
- 29
src/KernelV0.cpp View File

252
             EvaluateKids( Size, 0, cpos, VectorXcr::Ones(PulseI.size()) );
252
             EvaluateKids( Size, 0, cpos, VectorXcr::Ones(PulseI.size()) );
253
         } else {
253
         } else {
254
         #ifdef LEMMAUSEVTK
254
         #ifdef LEMMAUSEVTK
255
-            vtkHyperOctree* oct = vtkHyperOctree::New();
255
+            vtkHyperTreeGrid* oct = vtkHyperTreeGrid::New();
256
+
256
                 oct->SetDimension(3);
257
                 oct->SetDimension(3);
257
-                oct->SetOrigin( Origin(0), Origin(1), Origin(2) );
258
-                oct->SetSize( Size(0), Size(1), Size(2) );
259
-            vtkHyperOctreeCursor* curse = oct->NewCellCursor();
258
+                vtkNew<vtkDoubleArray> xcoords;
259
+                    xcoords->SetNumberOfComponents(1);
260
+                    xcoords->SetNumberOfTuples(2);
261
+                    xcoords->SetTuple1( 0, Origin(0) );
262
+                    xcoords->SetTuple1( 1, Origin(0) + Size(0) );
263
+                    xcoords->SetName("northing (m)");
264
+                    oct->SetXCoordinates(xcoords);
265
+
266
+                vtkNew<vtkDoubleArray> ycoords;
267
+                    ycoords->SetNumberOfComponents(1);
268
+                    ycoords->SetNumberOfTuples(2);
269
+                    ycoords->SetTuple1( 0, Origin(1) );
270
+                    ycoords->SetTuple1( 1, Origin(1) + Size(1) );
271
+                    ycoords->SetName("easting (m)");
272
+                    oct->SetYCoordinates(ycoords);
273
+
274
+                vtkNew<vtkDoubleArray> zcoords;
275
+                    zcoords->SetNumberOfComponents(1);
276
+                    zcoords->SetNumberOfTuples(2);
277
+                    zcoords->SetTuple1( 0, Origin(2) );
278
+                    zcoords->SetTuple1( 1, Origin(2) + Size(2) );
279
+                    zcoords->SetName("depth (m)");
280
+                    oct->SetZCoordinates(zcoords);
281
+
282
+            //vtkHyperTreeGridLevelEntry* curse2 =  vtkHyperTreeGridLevelEntry::New(); // VTK 9
283
+            //std::cout << *oct << std::endl;
284
+            // TODO, check the index in NewCursor maybe points to which cell in the Rectilinear Grid?
285
+            vtkHyperTreeCursor* curse = oct->NewCursor(0, true); // true creates the cursor
260
                 curse->ToRoot();
286
                 curse->ToRoot();
261
             EvaluateKids2( Size, 0, cpos, VectorXcr::Ones(PulseI.size()), oct, curse );
287
             EvaluateKids2( Size, 0, cpos, VectorXcr::Ones(PulseI.size()), oct, curse );
262
 
288
 
322
             for (auto leaf : LeafDictIdx) {
348
             for (auto leaf : LeafDictIdx) {
323
                 kerr->InsertTuple1( leaf.first, leaf.second );
349
                 kerr->InsertTuple1( leaf.first, leaf.second );
324
             }
350
             }
325
-
326
-            auto kri = oct->GetLeafData()->AddArray(kr);
327
-            auto kii = oct->GetLeafData()->AddArray(ki);
328
-            auto kmi = oct->GetLeafData()->AddArray(km);
329
-            auto kidi = oct->GetLeafData()->AddArray(kid);
330
-            auto keri = oct->GetLeafData()->AddArray(kerr);
331
-            auto khtr = oct->GetLeafData()->AddArray(htr);
332
-            auto khti = oct->GetLeafData()->AddArray(hti);
333
-            auto khrr = oct->GetLeafData()->AddArray(hrr);
334
-            auto khri = oct->GetLeafData()->AddArray(hri);
335
-
336
-            auto write = vtkXMLHyperOctreeWriter::New();
337
-                //write.SetDataModeToAscii()
338
-                write->SetInputData(oct);
351
+/* TODO fix
352
+            auto kri = oct->GetCellData()->AddArray(kr);
353
+            auto kii = oct->GetCellData()->AddArray(ki);
354
+            auto kmi = oct->GetCellData()->AddArray(km);
355
+            auto kidi = oct->GetCellData()->AddArray(kid);
356
+            auto keri = oct->GetCellData()->AddArray(kerr);
357
+            auto khtr = oct->GetCellData()->AddArray(htr);
358
+            auto khti = oct->GetCellData()->AddArray(hti);
359
+            auto khrr = oct->GetCellData()->AddArray(hrr);
360
+            auto khri = oct->GetCellData()->AddArray(hri);
361
+*/
362
+            std::cout << "Writing file...Number of leaves: " << oct->GetNumberOfLeaves() << std::endl;
363
+            auto write = vtkXMLHyperTreeGridWriter::New();
339
                 std::string fname = std::string("octree-") + to_string(ilay)
364
                 std::string fname = std::string("octree-") + to_string(ilay)
340
-                                  + std::string("-") + to_string(iq) + std::string(".vto");
365
+                                  + std::string("-") + to_string(iq) + std::string(".htg");
341
                 write->SetFileName(fname.c_str());
366
                 write->SetFileName(fname.c_str());
367
+                write->SetInputData(oct);
368
+                write->SetDataModeToBinary();
369
+                //write.SetDataModeToAscii()
370
+                //write->Update();
342
                 write->Write();
371
                 write->Write();
343
                 write->Delete();
372
                 write->Delete();
344
-
373
+/*
345
             oct->GetLeafData()->RemoveArray( kri );
374
             oct->GetLeafData()->RemoveArray( kri );
346
             oct->GetLeafData()->RemoveArray( kii );
375
             oct->GetLeafData()->RemoveArray( kii );
347
             oct->GetLeafData()->RemoveArray( kmi );
376
             oct->GetLeafData()->RemoveArray( kmi );
361
             hti->Delete();
390
             hti->Delete();
362
             hrr->Delete();
391
             hrr->Delete();
363
             hri->Delete();
392
             hri->Delete();
364
-
393
+*/
365
             }
394
             }
366
             curse->Delete();
395
             curse->Delete();
367
             oct->Delete();
396
             oct->Delete();
568
     //      Method:  EvaluateKids2 -- same as Evaluate Kids, but include VTK octree generation
597
     //      Method:  EvaluateKids2 -- same as Evaluate Kids, but include VTK octree generation
569
     //--------------------------------------------------------------------------------------
598
     //--------------------------------------------------------------------------------------
570
     void KernelV0::EvaluateKids2( const Vector3r& size, const int& level, const Vector3r& cpos,
599
     void KernelV0::EvaluateKids2( const Vector3r& size, const int& level, const Vector3r& cpos,
571
-        const VectorXcr& parentVal, vtkHyperOctree* oct, vtkHyperOctreeCursor* curse) {
600
+        const VectorXcr& parentVal, vtkHyperTreeGrid* oct, vtkHyperTreeCursor* curse) {
572
 
601
 
573
         std::cout << "\r" << (int)(1e2*VOLSUM/(Size[0]*Size[1]*Size[2])) << "\t" << nleaves;
602
         std::cout << "\r" << (int)(1e2*VOLSUM/(Size[0]*Size[1]*Size[2])) << "\t" << nleaves;
574
         //std::cout.flush();
603
         //std::cout.flush();
627
         VectorXcr ksum = kvals.colwise().sum();     // Kernel sum
656
         VectorXcr ksum = kvals.colwise().sum();     // Kernel sum
628
         // Evaluate whether or not furthur splitting is needed
657
         // Evaluate whether or not furthur splitting is needed
629
         if ( (((ksum - parentVal).array().abs() > tol).any() && level<maxLevel) || level < minLevel ) {
658
         if ( (((ksum - parentVal).array().abs() > tol).any() && level<maxLevel) || level < minLevel ) {
630
-            oct->SubdivideLeaf(curse);
659
+            // TODO Fix, 0 after curse is vtkIdType?
660
+            oct->SubdivideLeaf(curse, 0);
661
+            //std::cout << "Number of leaves: " << oct->GetNumberOfLeaves() << std::endl;
631
             for (int ichild=0; ichild<8; ++ichild) {
662
             for (int ichild=0; ichild<8; ++ichild) {
632
                 curse->ToChild(ichild);
663
                 curse->ToChild(ichild);
633
                 Vector3r cp = pos; // Eigen complains about combining these
664
                 Vector3r cp = pos; // Eigen complains about combining these
656
         /* Alternatively, subdivide the VTK octree here and stuff the children to make better
687
         /* Alternatively, subdivide the VTK octree here and stuff the children to make better
657
          * visuals, but also 8x the storage...
688
          * visuals, but also 8x the storage...
658
          */
689
          */
659
-        oct->SubdivideLeaf(curse);
690
+        // TODO Fix, 0 after curse is vtkIdType?
691
+        oct->SubdivideLeaf(curse, 0);
660
         for (int ichild=0; ichild<8; ++ichild) {
692
         for (int ichild=0; ichild<8; ++ichild) {
661
             curse->ToChild(ichild);
693
             curse->ToChild(ichild);
662
-            LeafDict[curse->GetLeafId()] = ksum/(8.*vol);
663
-            LeafHt[curse->GetLeafId()] = Ht.col(ichild);
664
-            LeafHr[curse->GetLeafId()] = Hr.col(ichild);
665
-            LeafDictIdx[curse->GetLeafId()] = nleaves;
694
+            // TODO fix, GetLeafId to GetLevel??
695
+            //LeafDict[curse->GetLeafId()] = ksum/(8.*vol);
696
+            //LeafHt[curse->GetLeafId()] = Ht.col(ichild);
697
+            //LeafHr[curse->GetLeafId()] = Hr.col(ichild);
698
+            //LeafDictIdx[curse->GetLeafId()] = nleaves;
699
+            LeafDict[curse->GetLevel()] = ksum/(8.*vol);
700
+            LeafHt[curse->GetLevel()] = Ht.col(ichild);
701
+            LeafHr[curse->GetLevel()] = Hr.col(ichild);
702
+            LeafDictIdx[curse->GetLevel()] = nleaves;
666
             curse->ToParent();
703
             curse->ToParent();
667
         }
704
         }
668
 
705
 
676
     //       Class:  KernelV0
713
     //       Class:  KernelV0
677
     //      Method:  GetPosition
714
     //      Method:  GetPosition
678
     //--------------------------------------------------------------------------------------
715
     //--------------------------------------------------------------------------------------
679
-    void KernelV0::GetPosition( vtkHyperOctreeCursor* Cursor, Real* p ) {
716
+    void KernelV0::GetPosition( vtkHyperTreeCursor* Cursor, Real* p ) {
717
+        // TODO fix
718
+        /*
680
         Real ratio=1.0/(1<<(Cursor->GetCurrentLevel()));
719
         Real ratio=1.0/(1<<(Cursor->GetCurrentLevel()));
681
         //step  = ((Size).array() / std::pow(2.,Cursor->GetCurrentLevel()));
720
         //step  = ((Size).array() / std::pow(2.,Cursor->GetCurrentLevel()));
682
         p[0]=(Cursor->GetIndex(0)+.5)*ratio*this->Size[0]+this->Origin[0] ;//+ .5*step[0];
721
         p[0]=(Cursor->GetIndex(0)+.5)*ratio*this->Size[0]+this->Origin[0] ;//+ .5*step[0];
683
         p[1]=(Cursor->GetIndex(1)+.5)*ratio*this->Size[1]+this->Origin[1] ;//+ .5*step[1];
722
         p[1]=(Cursor->GetIndex(1)+.5)*ratio*this->Size[1]+this->Origin[1] ;//+ .5*step[1];
684
         p[2]=(Cursor->GetIndex(2)+.5)*ratio*this->Size[2]+this->Origin[2] ;//+ .5*step[2];
723
         p[2]=(Cursor->GetIndex(2)+.5)*ratio*this->Size[2]+this->Origin[2] ;//+ .5*step[2];
724
+        */
685
     }
725
     }
686
 
726
 
687
     #endif
727
     #endif

Loading…
Cancel
Save