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,7 +1,7 @@
1 1
 # Configure Merlin 
2 2
 set(MERLIN_VERSION_MAJOR "0")
3 3
 set(MERLIN_VERSION_MINOR "0")
4
-set(MERLIN_VERSION_PATCH "3")
4
+set(MERLIN_VERSION_PATCH "4")
5 5
 set(MERLIN_VERSION "\"${MERLIN_VERSION_MAJOR}.${MERLIN_VERSION_MINOR}.${MERLIN_VERSION_PATCH}\"")
6 6
 set(MERLIN_VERSION_NOQUOTES "${MERLIN_VERSION_MAJOR}.${MERLIN_VERSION_MINOR}.${MERLIN_VERSION_PATCH}")
7 7
 

+ 2
- 2
examples/KernelV0.cpp View File

@@ -25,7 +25,7 @@ std::shared_ptr<PolygonalWireAntenna> CircularLoop ( int nd, Real radius, Real O
25 25
 int main(int argc, char** argv) {
26 26
 
27 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 29
         exit(EXIT_SUCCESS);
30 30
     }
31 31
 
@@ -58,7 +58,7 @@ int main(int argc, char** argv) {
58 58
 
59 59
         Kern->SetIntegrationSize( (Vector3r() << 200,200,200).finished() );
60 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 63
         auto AkvoDataNode = YAML::LoadFile(argv[4]);
64 64
         Kern->AlignWithAkvoDataset( AkvoDataNode );

+ 5
- 0
include/KernelV0.h View File

@@ -29,6 +29,11 @@
29 29
 //#include "vtkHyperOctree.h"
30 30
 //#include "vtkHyperOctreeCursor.h"
31 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 37
 #include "vtkHyperTreeGrid.h"
33 38
 #include "vtkHyperTreeCursor.h"
34 39
 #include "vtkXMLHyperTreeGridWriter.h"

+ 53
- 41
src/KernelV0.cpp View File

@@ -11,8 +11,9 @@
11 11
  * @file
12 12
  * @date      11/11/2016 01:47:25 PM
13 13
  * @author    Trevor Irons (ti)
14
- * @email     tirons@egi.utah.edu
14
+ * @email     Trevor.Irons@lemmasoftware.org
15 15
  * @copyright Copyright (c) 2016, University of Utah
16
+ * @copyright Copyright (c) 2019, Trevor P. Irons
16 17
  * @copyright Copyright (c) 2016, Lemma Software, LLC
17 18
  * @copyright Copyright (c) 2008, Colorado School of Mines
18 19
  */
@@ -253,7 +254,7 @@ namespace Lemma {
253 254
         } else {
254 255
         #ifdef LEMMAUSEVTK
255 256
             vtkHyperTreeGrid* oct = vtkHyperTreeGrid::New();
256
-
257
+                oct->SetGridSize( 1, 1, 1 ); // Important!
257 258
                 oct->SetDimension(3);
258 259
                 vtkNew<vtkDoubleArray> xcoords;
259 260
                     xcoords->SetNumberOfComponents(1);
@@ -280,59 +281,71 @@ namespace Lemma {
280 281
                     oct->SetZCoordinates(zcoords);
281 282
 
282 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 285
             vtkHyperTreeCursor* curse = oct->NewCursor(0, true); // true creates the cursor
286 286
                 curse->ToRoot();
287 287
             EvaluateKids2( Size, 0, cpos, VectorXcr::Ones(PulseI.size()), oct, curse );
288 288
 
289 289
             for (int iq=0; iq<PulseI.size(); ++iq) {
290
+
290 291
             // Fill in leaf data
291 292
             vtkDoubleArray* kr = vtkDoubleArray::New();
292 293
                 kr->SetNumberOfComponents(1);
293 294
                 kr->SetName("Re($\\mathcal{K}_0$)");
294 295
                 kr->SetNumberOfTuples( oct->GetNumberOfLeaves() );
296
+
295 297
             vtkDoubleArray* ki = vtkDoubleArray::New();
296 298
                 ki->SetNumberOfComponents(1);
297 299
                 ki->SetName("Im($\\mathcal{K}_0$)");
298 300
                 ki->SetNumberOfTuples( oct->GetNumberOfLeaves() );
301
+
299 302
             vtkDoubleArray* km = vtkDoubleArray::New();
300 303
                 km->SetNumberOfComponents(1);
301 304
                 km->SetName("mod($\\mathcal{K}_0$)");
302 305
                 km->SetNumberOfTuples( oct->GetNumberOfLeaves() );
306
+
303 307
             vtkIntArray* kid = vtkIntArray::New();
304 308
                 kid->SetNumberOfComponents(1);
305 309
                 kid->SetName("ID");
306 310
                 kid->SetNumberOfTuples( oct->GetNumberOfLeaves() );
311
+
307 312
             vtkIntArray* kerr = vtkIntArray::New();
308 313
                 kerr->SetNumberOfComponents(1);
309 314
                 kerr->SetName("err");
310 315
                 kerr->SetNumberOfTuples( oct->GetNumberOfLeaves() );
316
+
311 317
             // Ht field
312 318
             vtkDoubleArray* htr = vtkDoubleArray::New();
313 319
                 htr->SetNumberOfComponents(3);
314 320
                 htr->SetName("Re($\\mathbf{\\mathcal{H}}_T$)");
315 321
                 htr->SetNumberOfTuples( oct->GetNumberOfLeaves() );
322
+
316 323
             vtkDoubleArray* hti = vtkDoubleArray::New();
317 324
                 hti->SetNumberOfComponents(3);
318 325
                 hti->SetName("Im($\\mathbf{\\mathcal{H}}_T$)");
319 326
                 hti->SetNumberOfTuples( oct->GetNumberOfLeaves() );
327
+
320 328
             // Hr field
321 329
             vtkDoubleArray* hrr = vtkDoubleArray::New();
322 330
                 hrr->SetNumberOfComponents(3);
323 331
                 hrr->SetName("Re($\\mathbf{\\mathcal{H}}_R$)");
324 332
                 hrr->SetNumberOfTuples( oct->GetNumberOfLeaves() );
333
+
325 334
             vtkDoubleArray* hri = vtkDoubleArray::New();
326 335
                 hri->SetNumberOfComponents(3);
327 336
                 hri->SetName("Im($\\mathbf{\\mathcal{H}}_R$)");
328 337
                 hri->SetNumberOfTuples( oct->GetNumberOfLeaves() );
329 338
             //Real LeafVol(0);
339
+
340
+            //kr->Fill(0);
341
+            int icc(0);
330 342
             for (auto leaf : LeafDict) {
331 343
                 kr->InsertTuple1( leaf.first, std::real(leaf.second(iq)) );
332 344
                 ki->InsertTuple1( leaf.first, std::imag(leaf.second(iq)) );
333 345
                 km->InsertTuple1( leaf.first, std::abs(leaf.second(iq)) );
334 346
                 kid->InsertTuple1( leaf.first, leaf.first );
335 347
                 //LeafVol += std::real(leaf.second);
348
+                ++icc;
336 349
             }
337 350
 
338 351
             for (auto leaf : LeafHt ) {
@@ -348,38 +361,42 @@ namespace Lemma {
348 361
             for (auto leaf : LeafDictIdx) {
349 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 380
             auto write = vtkXMLHyperTreeGridWriter::New();
364 381
                 std::string fname = std::string("octree-") + to_string(ilay)
365 382
                                   + std::string("-") + to_string(iq) + std::string(".htg");
366 383
                 write->SetFileName(fname.c_str());
367 384
                 write->SetInputData(oct);
368 385
                 write->SetDataModeToBinary();
369
-                //write.SetDataModeToAscii()
370
-                //write->Update();
386
+                //write->SetDataModeToAscii();
387
+                write->Update();
371 388
                 write->Write();
372 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 401
             kerr->Delete();
385 402
             kid->Delete();
@@ -390,8 +407,8 @@ namespace Lemma {
390 407
             hti->Delete();
391 408
             hrr->Delete();
392 409
             hri->Delete();
393
-*/
394 410
             }
411
+
395 412
             curse->Delete();
396 413
             oct->Delete();
397 414
         #else
@@ -656,9 +673,8 @@ namespace Lemma {
656 673
         VectorXcr ksum = kvals.colwise().sum();     // Kernel sum
657 674
         // Evaluate whether or not furthur splitting is needed
658 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 677
             oct->SubdivideLeaf(curse, 0);
661
-            //std::cout << "Number of leaves: " << oct->GetNumberOfLeaves() << std::endl;
662 678
             for (int ichild=0; ichild<8; ++ichild) {
663 679
                 curse->ToChild(ichild);
664 680
                 Vector3r cp = pos; // Eigen complains about combining these
@@ -687,19 +703,15 @@ namespace Lemma {
687 703
         /* Alternatively, subdivide the VTK octree here and stuff the children to make better
688 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 708
         oct->SubdivideLeaf(curse, 0);
692 709
         for (int ichild=0; ichild<8; ++ichild) {
693 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 715
             curse->ToParent();
704 716
         }
705 717
 

Loading…
Cancel
Save