1 //============================================================================
2 //  Copyright (c) Kitware, Inc.
3 //  All rights reserved.
4 //  See LICENSE.txt for details.
5 //  This software is distributed WITHOUT ANY WARRANTY; without even
6 //  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
7 //  PURPOSE.  See the above copyright notice for more information.
8 //
9 //  Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
10 //  Copyright 2014 UT-Battelle, LLC.
11 //  Copyright 2014 Los Alamos National Security.
12 //
13 //  Under the terms of Contract DE-NA0003525 with NTESS,
14 //  the U.S. Government retains certain rights in this software.
15 //
16 //  Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
17 //  Laboratory (LANL), the U.S. Government retains certain rights in
18 //  this software.
19 //============================================================================
20 // Copyright (c) 2018, The Regents of the University of California, through
21 // Lawrence Berkeley National Laboratory (subject to receipt of any required approvals
22 // from the U.S. Dept. of Energy).  All rights reserved.
23 //
24 // Redistribution and use in source and binary forms, with or without modification,
25 // are permitted provided that the following conditions are met:
26 //
27 // (1) Redistributions of source code must retain the above copyright notice, this
28 //     list of conditions and the following disclaimer.
29 //
30 // (2) Redistributions in binary form must reproduce the above copyright notice,
31 //     this list of conditions and the following disclaimer in the documentation
32 //     and/or other materials provided with the distribution.
33 //
34 // (3) Neither the name of the University of California, Lawrence Berkeley National
35 //     Laboratory, U.S. Dept. of Energy nor the names of its contributors may be
36 //     used to endorse or promote products derived from this software without
37 //     specific prior written permission.
38 //
39 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
40 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
41 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
42 // IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
43 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
44 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
45 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
46 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
47 // OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
48 // OF THE POSSIBILITY OF SUCH DAMAGE.
49 //
50 //=============================================================================
51 //
52 //  This code is an extension of the algorithm presented in the paper:
53 //  Parallel Peak Pruning for Scalable SMP Contour Tree Computation.
54 //  Hamish Carr, Gunther Weber, Christopher Sewell, and James Ahrens.
55 //  Proceedings of the IEEE Symposium on Large Data Analysis and Visualization
56 //  (LDAV), October 2016, Baltimore, Maryland.
57 //
58 //  The PPP2 algorithm and software were jointly developed by
59 //  Hamish Carr (University of Leeds), Gunther H. Weber (LBNL), and
60 //  Oliver Ruebel (LBNL)
61 //==============================================================================
62 
63 
64 #ifndef vtkm_worklet_contourtree_augmented_contourtree_maker_inc_augment_merge_tree_init_new_join_splot_id_and_superparents_h
65 #define vtkm_worklet_contourtree_augmented_contourtree_maker_inc_augment_merge_tree_init_new_join_splot_id_and_superparents_h
66 
67 #include <vtkm/worklet/WorkletMapField.h>
68 #include <vtkm/worklet/contourtree_augmented/Types.h>
69 
70 namespace vtkm
71 {
72 namespace worklet
73 {
74 namespace contourtree_augmented
75 {
76 namespace contourtree_maker_inc
77 {
78 
79 // Worklet for computing the sort indices from the sort order
80 class AugmentMergeTrees_InitNewJoinSplitIDAndSuperparents : public vtkm::worklet::WorkletMapField
81 {
82 public:
83   typedef void ControlSignature(
84     FieldIn<IdType> contourTreeSupernodes,      // (input) supernodes from the contour tree
85     WholeArrayIn<IdType> joinTreeSuperparents,  // (input)
86     WholeArrayIn<IdType> splitTreeSuperparents, // (input)
87     WholeArrayIn<IdType> joinTreeSupernodes,    // (input)
88     WholeArrayIn<IdType> splitTreeSupernodes,   // (input)
89     WholeArrayOut<IdType> joinSuperparent,      // (output)
90     WholeArrayOut<IdType> splitSuperparent,     // (output)
91     WholeArrayOut<IdType> newJoinID,            // (output)
92     WholeArrayOut<IdType> newSplitID);          // (output)
93   typedef void ExecutionSignature(_1, InputIndex, _2, _3, _4, _5, _6, _7, _8, _9);
94   typedef _1 InputDomain;
95 
96   // Default Constructor
97   VTKM_EXEC_CONT
AugmentMergeTrees_InitNewJoinSplitIDAndSuperparents()98   AugmentMergeTrees_InitNewJoinSplitIDAndSuperparents() {}
99 
100   template <typename InFieldPortalType, typename OutFieldPortalType>
operator()101   VTKM_EXEC void operator()(const vtkm::Id& nodeID,
102                             const vtkm::Id supernode,
103                             const InFieldPortalType& joinTreeSuperparentsPortal,
104                             const InFieldPortalType& splitTreeSuperparentsPortal,
105                             const InFieldPortalType& joinTreeSupernodesPortal,
106                             const InFieldPortalType& splitTreeSupernodesPortal,
107                             const OutFieldPortalType& joinSuperparentPortal,
108                             const OutFieldPortalType& splitSuperparentPortal,
109                             const OutFieldPortalType& newJoinIDPortal,
110                             const OutFieldPortalType& newSplitIDPortal) const
111   {
112     // Transfer the join information
113     // look up the join superparent in the join tree
114     vtkm::Id joinSuperparent = joinTreeSuperparentsPortal.Get(nodeID);
115     // save the join superparent
116     joinSuperparentPortal.Set(supernode, joinSuperparent);
117     // now, if the join superparent's mesh ID is the node itself, we're at a join supernode
118     if (joinTreeSupernodesPortal.Get(joinSuperparent) == nodeID)
119       newJoinIDPortal.Set(joinSuperparent, supernode);
120 
121     // Transfer the split information
122     // look up the split superparent in the split tree
123     vtkm::Id splitSuperparent = splitTreeSuperparentsPortal.Get(nodeID);
124     // save the split superparent
125     splitSuperparentPortal.Set(supernode, splitSuperparent);
126     // now, if the split superparent's mesh ID is the node, we're at a split supernode
127     if (splitTreeSupernodesPortal.Get(splitSuperparent) == nodeID)
128       newSplitIDPortal.Set(splitSuperparent, supernode);
129 
130     // In serial this worklet implements the following operation
131     /*
132       for (vtkm::Id supernode = 0; supernode < nSupernodes; supernode++)
133         { // per supernode
134 
135           // find the regular ID for the supernode
136           vtkm::Id nodeID = contourTree.supernodes[supernode];
137 
138           // Transfer the join information
139           // look up the join superparent in the join tree
140           vtkm::Id joinSuperparent = joinTree.superparents[nodeID];
141           // save the join superparent
142           joinSuperparents[supernode] = joinSuperparent;
143           // now, if the join superparent's mesh ID is the node itself, we're at a join supernode
144           if (joinTree.supernodes[joinSuperparent] == nodeID)
145                   newJoinID[joinSuperparent] = supernode;
146 
147           // Transfer the split information
148           // look up the split superparent in the split tree
149           vtkm::Id splitSuperparent = splitTree.superparents[nodeID];
150           // save the split superparent
151           splitSuperparents[supernode] = splitSuperparent;
152           // now, if the split superparent's mesh ID is the node, we're at a split supernode
153           if (splitTree.supernodes[splitSuperparent] == nodeID)
154                   newSplitID[splitSuperparent] = supernode;
155 
156         } // per supernode
157       */
158   }
159 
160 }; // AugmentMergeTrees_InitNewJoinSplitIDAndSuperparents.h
161 
162 } // namespace contourtree_maker_inc
163 } // namespace contourtree_augmented
164 } // namespace worklet
165 } // namespace vtkm
166 
167 #endif
168