Browse Source

VTK support readded for kernel calculation

master
Trevor Irons 5 years ago
parent
commit
16e0ca5869
4 changed files with 61 additions and 44 deletions
  1. 1
    1
      CMakeLists.txt
  2. 2
    2
      examples/KernelV0.cpp
  3. 5
    0
      include/KernelV0.h
  4. 53
    41
      src/KernelV0.cpp

+ 1
- 1
CMakeLists.txt View File

1
 # Configure Merlin 
1
 # Configure Merlin 
2
 set(MERLIN_VERSION_MAJOR "0")
2
 set(MERLIN_VERSION_MAJOR "0")
3
 set(MERLIN_VERSION_MINOR "0")
3
 set(MERLIN_VERSION_MINOR "0")
4
-set(MERLIN_VERSION_PATCH "3")
4
+set(MERLIN_VERSION_PATCH "4")
5
 set(MERLIN_VERSION "\"${MERLIN_VERSION_MAJOR}.${MERLIN_VERSION_MINOR}.${MERLIN_VERSION_PATCH}\"")
5
 set(MERLIN_VERSION "\"${MERLIN_VERSION_MAJOR}.${MERLIN_VERSION_MINOR}.${MERLIN_VERSION_PATCH}\"")
6
 set(MERLIN_VERSION_NOQUOTES "${MERLIN_VERSION_MAJOR}.${MERLIN_VERSION_MINOR}.${MERLIN_VERSION_PATCH}")
6
 set(MERLIN_VERSION_NOQUOTES "${MERLIN_VERSION_MAJOR}.${MERLIN_VERSION_MINOR}.${MERLIN_VERSION_PATCH}")
7
 
7
 

+ 2
- 2
examples/KernelV0.cpp View File

25
 int main(int argc, char** argv) {
25
 int main(int argc, char** argv) {
26
 
26
 
27
     if (argc < 6) {             // 1          2           3                    4                5
27
     if (argc < 6) {             // 1          2           3                    4                5
28
-        std::cout << "./KernelV0 TxCoil.yaml RxCoil.yaml  EMEarthModel.yaml    AkvoDataSet.yaml Output.yaml \n";
28
+        std::cout << "./KernelV0 TxCoil.yaml RxCoil.yaml  EMEarthModel.yaml  AkvoDataSet.yaml Output.yaml \n";
29
         exit(EXIT_SUCCESS);
29
         exit(EXIT_SUCCESS);
30
     }
30
     }
31
 
31
 
58
 
58
 
59
         Kern->SetIntegrationSize( (Vector3r() << 200,200,200).finished() );
59
         Kern->SetIntegrationSize( (Vector3r() << 200,200,200).finished() );
60
         Kern->SetIntegrationOrigin( (Vector3r() << 0,0,0).finished() );
60
         Kern->SetIntegrationOrigin( (Vector3r() << 0,0,0).finished() );
61
-        Kern->SetTolerance( 1e-9 ); // 1e-12
61
+        Kern->SetTolerance( 1e-11 ); // 1e-12
62
 
62
 
63
         auto AkvoDataNode = YAML::LoadFile(argv[4]);
63
         auto AkvoDataNode = YAML::LoadFile(argv[4]);
64
         Kern->AlignWithAkvoDataset( AkvoDataNode );
64
         Kern->AlignWithAkvoDataset( AkvoDataNode );

+ 5
- 0
include/KernelV0.h View File

29
 //#include "vtkHyperOctree.h"
29
 //#include "vtkHyperOctree.h"
30
 //#include "vtkHyperOctreeCursor.h"
30
 //#include "vtkHyperOctreeCursor.h"
31
 //#include "vtkXMLHyperOctreeWriter.h"
31
 //#include "vtkXMLHyperOctreeWriter.h"
32
+//#include "vtkXMLHyperOctreeWriter.h"
33
+#include "vtkCellData.h"
34
+#include "vtkPointData.h"
35
+#include "vtkHyperTree.h"
36
+#include "vtkHyperTree.h"
32
 #include "vtkHyperTreeGrid.h"
37
 #include "vtkHyperTreeGrid.h"
33
 #include "vtkHyperTreeCursor.h"
38
 #include "vtkHyperTreeCursor.h"
34
 #include "vtkXMLHyperTreeGridWriter.h"
39
 #include "vtkXMLHyperTreeGridWriter.h"

+ 53
- 41
src/KernelV0.cpp View File

11
  * @file
11
  * @file
12
  * @date      11/11/2016 01:47:25 PM
12
  * @date      11/11/2016 01:47:25 PM
13
  * @author    Trevor Irons (ti)
13
  * @author    Trevor Irons (ti)
14
- * @email     tirons@egi.utah.edu
14
+ * @email     Trevor.Irons@lemmasoftware.org
15
  * @copyright Copyright (c) 2016, University of Utah
15
  * @copyright Copyright (c) 2016, University of Utah
16
+ * @copyright Copyright (c) 2019, Trevor P. Irons
16
  * @copyright Copyright (c) 2016, Lemma Software, LLC
17
  * @copyright Copyright (c) 2016, Lemma Software, LLC
17
  * @copyright Copyright (c) 2008, Colorado School of Mines
18
  * @copyright Copyright (c) 2008, Colorado School of Mines
18
  */
19
  */
253
         } else {
254
         } else {
254
         #ifdef LEMMAUSEVTK
255
         #ifdef LEMMAUSEVTK
255
             vtkHyperTreeGrid* oct = vtkHyperTreeGrid::New();
256
             vtkHyperTreeGrid* oct = vtkHyperTreeGrid::New();
256
-
257
+                oct->SetGridSize( 1, 1, 1 ); // Important!
257
                 oct->SetDimension(3);
258
                 oct->SetDimension(3);
258
                 vtkNew<vtkDoubleArray> xcoords;
259
                 vtkNew<vtkDoubleArray> xcoords;
259
                     xcoords->SetNumberOfComponents(1);
260
                     xcoords->SetNumberOfComponents(1);
280
                     oct->SetZCoordinates(zcoords);
281
                     oct->SetZCoordinates(zcoords);
281
 
282
 
282
             //vtkHyperTreeGridLevelEntry* curse2 =  vtkHyperTreeGridLevelEntry::New(); // VTK 9
283
             //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?
284
+            // I belive the index in NewCursor maybe points to which cell in the Rectilinear Grid?
285
             vtkHyperTreeCursor* curse = oct->NewCursor(0, true); // true creates the cursor
285
             vtkHyperTreeCursor* curse = oct->NewCursor(0, true); // true creates the cursor
286
                 curse->ToRoot();
286
                 curse->ToRoot();
287
             EvaluateKids2( Size, 0, cpos, VectorXcr::Ones(PulseI.size()), oct, curse );
287
             EvaluateKids2( Size, 0, cpos, VectorXcr::Ones(PulseI.size()), oct, curse );
288
 
288
 
289
             for (int iq=0; iq<PulseI.size(); ++iq) {
289
             for (int iq=0; iq<PulseI.size(); ++iq) {
290
+
290
             // Fill in leaf data
291
             // Fill in leaf data
291
             vtkDoubleArray* kr = vtkDoubleArray::New();
292
             vtkDoubleArray* kr = vtkDoubleArray::New();
292
                 kr->SetNumberOfComponents(1);
293
                 kr->SetNumberOfComponents(1);
293
                 kr->SetName("Re($\\mathcal{K}_0$)");
294
                 kr->SetName("Re($\\mathcal{K}_0$)");
294
                 kr->SetNumberOfTuples( oct->GetNumberOfLeaves() );
295
                 kr->SetNumberOfTuples( oct->GetNumberOfLeaves() );
296
+
295
             vtkDoubleArray* ki = vtkDoubleArray::New();
297
             vtkDoubleArray* ki = vtkDoubleArray::New();
296
                 ki->SetNumberOfComponents(1);
298
                 ki->SetNumberOfComponents(1);
297
                 ki->SetName("Im($\\mathcal{K}_0$)");
299
                 ki->SetName("Im($\\mathcal{K}_0$)");
298
                 ki->SetNumberOfTuples( oct->GetNumberOfLeaves() );
300
                 ki->SetNumberOfTuples( oct->GetNumberOfLeaves() );
301
+
299
             vtkDoubleArray* km = vtkDoubleArray::New();
302
             vtkDoubleArray* km = vtkDoubleArray::New();
300
                 km->SetNumberOfComponents(1);
303
                 km->SetNumberOfComponents(1);
301
                 km->SetName("mod($\\mathcal{K}_0$)");
304
                 km->SetName("mod($\\mathcal{K}_0$)");
302
                 km->SetNumberOfTuples( oct->GetNumberOfLeaves() );
305
                 km->SetNumberOfTuples( oct->GetNumberOfLeaves() );
306
+
303
             vtkIntArray* kid = vtkIntArray::New();
307
             vtkIntArray* kid = vtkIntArray::New();
304
                 kid->SetNumberOfComponents(1);
308
                 kid->SetNumberOfComponents(1);
305
                 kid->SetName("ID");
309
                 kid->SetName("ID");
306
                 kid->SetNumberOfTuples( oct->GetNumberOfLeaves() );
310
                 kid->SetNumberOfTuples( oct->GetNumberOfLeaves() );
311
+
307
             vtkIntArray* kerr = vtkIntArray::New();
312
             vtkIntArray* kerr = vtkIntArray::New();
308
                 kerr->SetNumberOfComponents(1);
313
                 kerr->SetNumberOfComponents(1);
309
                 kerr->SetName("err");
314
                 kerr->SetName("err");
310
                 kerr->SetNumberOfTuples( oct->GetNumberOfLeaves() );
315
                 kerr->SetNumberOfTuples( oct->GetNumberOfLeaves() );
316
+
311
             // Ht field
317
             // Ht field
312
             vtkDoubleArray* htr = vtkDoubleArray::New();
318
             vtkDoubleArray* htr = vtkDoubleArray::New();
313
                 htr->SetNumberOfComponents(3);
319
                 htr->SetNumberOfComponents(3);
314
                 htr->SetName("Re($\\mathbf{\\mathcal{H}}_T$)");
320
                 htr->SetName("Re($\\mathbf{\\mathcal{H}}_T$)");
315
                 htr->SetNumberOfTuples( oct->GetNumberOfLeaves() );
321
                 htr->SetNumberOfTuples( oct->GetNumberOfLeaves() );
322
+
316
             vtkDoubleArray* hti = vtkDoubleArray::New();
323
             vtkDoubleArray* hti = vtkDoubleArray::New();
317
                 hti->SetNumberOfComponents(3);
324
                 hti->SetNumberOfComponents(3);
318
                 hti->SetName("Im($\\mathbf{\\mathcal{H}}_T$)");
325
                 hti->SetName("Im($\\mathbf{\\mathcal{H}}_T$)");
319
                 hti->SetNumberOfTuples( oct->GetNumberOfLeaves() );
326
                 hti->SetNumberOfTuples( oct->GetNumberOfLeaves() );
327
+
320
             // Hr field
328
             // Hr field
321
             vtkDoubleArray* hrr = vtkDoubleArray::New();
329
             vtkDoubleArray* hrr = vtkDoubleArray::New();
322
                 hrr->SetNumberOfComponents(3);
330
                 hrr->SetNumberOfComponents(3);
323
                 hrr->SetName("Re($\\mathbf{\\mathcal{H}}_R$)");
331
                 hrr->SetName("Re($\\mathbf{\\mathcal{H}}_R$)");
324
                 hrr->SetNumberOfTuples( oct->GetNumberOfLeaves() );
332
                 hrr->SetNumberOfTuples( oct->GetNumberOfLeaves() );
333
+
325
             vtkDoubleArray* hri = vtkDoubleArray::New();
334
             vtkDoubleArray* hri = vtkDoubleArray::New();
326
                 hri->SetNumberOfComponents(3);
335
                 hri->SetNumberOfComponents(3);
327
                 hri->SetName("Im($\\mathbf{\\mathcal{H}}_R$)");
336
                 hri->SetName("Im($\\mathbf{\\mathcal{H}}_R$)");
328
                 hri->SetNumberOfTuples( oct->GetNumberOfLeaves() );
337
                 hri->SetNumberOfTuples( oct->GetNumberOfLeaves() );
329
             //Real LeafVol(0);
338
             //Real LeafVol(0);
339
+
340
+            //kr->Fill(0);
341
+            int icc(0);
330
             for (auto leaf : LeafDict) {
342
             for (auto leaf : LeafDict) {
331
                 kr->InsertTuple1( leaf.first, std::real(leaf.second(iq)) );
343
                 kr->InsertTuple1( leaf.first, std::real(leaf.second(iq)) );
332
                 ki->InsertTuple1( leaf.first, std::imag(leaf.second(iq)) );
344
                 ki->InsertTuple1( leaf.first, std::imag(leaf.second(iq)) );
333
                 km->InsertTuple1( leaf.first, std::abs(leaf.second(iq)) );
345
                 km->InsertTuple1( leaf.first, std::abs(leaf.second(iq)) );
334
                 kid->InsertTuple1( leaf.first, leaf.first );
346
                 kid->InsertTuple1( leaf.first, leaf.first );
335
                 //LeafVol += std::real(leaf.second);
347
                 //LeafVol += std::real(leaf.second);
348
+                ++icc;
336
             }
349
             }
337
 
350
 
338
             for (auto leaf : LeafHt ) {
351
             for (auto leaf : LeafHt ) {
348
             for (auto leaf : LeafDictIdx) {
361
             for (auto leaf : LeafDictIdx) {
349
                 kerr->InsertTuple1( leaf.first, leaf.second );
362
                 kerr->InsertTuple1( leaf.first, leaf.second );
350
             }
363
             }
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;
364
+
365
+            // In VTK 8, vtkHyperTreeGrid does not support CellData.
366
+            // the previous class vtkHyperOctreeGrid used "LeafData",
367
+            // but for the new classes, PointData seems to function as LeafData.
368
+            // this could change in VTK 9
369
+            auto kri = oct->GetPointData()->AddArray(kr);
370
+            auto kii = oct->GetPointData()->AddArray(ki);
371
+            auto kmi = oct->GetPointData()->AddArray(km);
372
+            auto kidi = oct->GetPointData()->AddArray(kid);
373
+            auto keri = oct->GetPointData()->AddArray(kerr);
374
+            auto khtr = oct->GetPointData()->AddArray(htr);
375
+            auto khti = oct->GetPointData()->AddArray(hti);
376
+            auto khrr = oct->GetPointData()->AddArray(hrr);
377
+            auto khri = oct->GetPointData()->AddArray(hri);
378
+
379
+            //std::cout << *oct << std::endl;
363
             auto write = vtkXMLHyperTreeGridWriter::New();
380
             auto write = vtkXMLHyperTreeGridWriter::New();
364
                 std::string fname = std::string("octree-") + to_string(ilay)
381
                 std::string fname = std::string("octree-") + to_string(ilay)
365
                                   + std::string("-") + to_string(iq) + std::string(".htg");
382
                                   + std::string("-") + to_string(iq) + std::string(".htg");
366
                 write->SetFileName(fname.c_str());
383
                 write->SetFileName(fname.c_str());
367
                 write->SetInputData(oct);
384
                 write->SetInputData(oct);
368
                 write->SetDataModeToBinary();
385
                 write->SetDataModeToBinary();
369
-                //write.SetDataModeToAscii()
370
-                //write->Update();
386
+                //write->SetDataModeToAscii();
387
+                write->Update();
371
                 write->Write();
388
                 write->Write();
372
                 write->Delete();
389
                 write->Delete();
373
-/*
374
-            oct->GetLeafData()->RemoveArray( kri );
375
-            oct->GetLeafData()->RemoveArray( kii );
376
-            oct->GetLeafData()->RemoveArray( kmi );
377
-            oct->GetLeafData()->RemoveArray( kidi );
378
-            oct->GetLeafData()->RemoveArray( keri );
379
-            oct->GetLeafData()->RemoveArray( khtr );
380
-            oct->GetLeafData()->RemoveArray( khti );
381
-            oct->GetLeafData()->RemoveArray( khrr );
382
-            oct->GetLeafData()->RemoveArray( khri );
390
+
391
+            oct->GetPointData()->RemoveArray( kri );
392
+            oct->GetPointData()->RemoveArray( kii );
393
+            oct->GetPointData()->RemoveArray( kmi );
394
+            oct->GetPointData()->RemoveArray( kidi );
395
+            oct->GetPointData()->RemoveArray( keri );
396
+            oct->GetPointData()->RemoveArray( khtr );
397
+            oct->GetPointData()->RemoveArray( khti );
398
+            oct->GetPointData()->RemoveArray( khrr );
399
+            oct->GetPointData()->RemoveArray( khri );
383
 
400
 
384
             kerr->Delete();
401
             kerr->Delete();
385
             kid->Delete();
402
             kid->Delete();
390
             hti->Delete();
407
             hti->Delete();
391
             hrr->Delete();
408
             hrr->Delete();
392
             hri->Delete();
409
             hri->Delete();
393
-*/
394
             }
410
             }
411
+
395
             curse->Delete();
412
             curse->Delete();
396
             oct->Delete();
413
             oct->Delete();
397
         #else
414
         #else
656
         VectorXcr ksum = kvals.colwise().sum();     // Kernel sum
673
         VectorXcr ksum = kvals.colwise().sum();     // Kernel sum
657
         // Evaluate whether or not furthur splitting is needed
674
         // Evaluate whether or not furthur splitting is needed
658
         if ( (((ksum - parentVal).array().abs() > tol).any() && level<maxLevel) || level < minLevel ) {
675
         if ( (((ksum - parentVal).array().abs() > tol).any() && level<maxLevel) || level < minLevel ) {
659
-            // TODO Fix, 0 after curse is vtkIdType?
676
+            // 0 after curse is vtkIdType?
660
             oct->SubdivideLeaf(curse, 0);
677
             oct->SubdivideLeaf(curse, 0);
661
-            //std::cout << "Number of leaves: " << oct->GetNumberOfLeaves() << std::endl;
662
             for (int ichild=0; ichild<8; ++ichild) {
678
             for (int ichild=0; ichild<8; ++ichild) {
663
                 curse->ToChild(ichild);
679
                 curse->ToChild(ichild);
664
                 Vector3r cp = pos; // Eigen complains about combining these
680
                 Vector3r cp = pos; // Eigen complains about combining these
687
         /* Alternatively, subdivide the VTK octree here and stuff the children to make better
703
         /* Alternatively, subdivide the VTK octree here and stuff the children to make better
688
          * visuals, but also 8x the storage...
704
          * visuals, but also 8x the storage...
689
          */
705
          */
690
-        // TODO Fix, 0 after curse is vtkIdType?
706
+
707
+        // 0 after curse is vtkIdType?
691
         oct->SubdivideLeaf(curse, 0);
708
         oct->SubdivideLeaf(curse, 0);
692
         for (int ichild=0; ichild<8; ++ichild) {
709
         for (int ichild=0; ichild<8; ++ichild) {
693
             curse->ToChild(ichild);
710
             curse->ToChild(ichild);
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;
711
+            LeafDict[curse->GetVertexId()] = ksum/(8.*vol);
712
+            LeafHt[curse->GetVertexId()] = Ht.col(ichild);
713
+            LeafHr[curse->GetVertexId()] = Hr.col(ichild);
714
+            LeafDictIdx[curse->GetVertexId()] = nleaves;
703
             curse->ToParent();
715
             curse->ToParent();
704
         }
716
         }
705
 
717
 

Loading…
Cancel
Save