18 #ifndef viskores_cont_CellSetPermutation_h
19 #define viskores_cont_CellSetPermutation_h
39 #ifndef VISKORES_DEFAULT_CELLSET_PERMUTATION_STORAGE_TAG
40 #define VISKORES_DEFAULT_CELLSET_PERMUTATION_STORAGE_TAG VISKORES_DEFAULT_STORAGE_TAG
56 class RConnTableHelpers
61 using ControlSignature = void(CellSetIn cellset, FieldOutCell numIndices);
62 using ExecutionSignature = void(PointCount, _2);
63 using InputDomain = _1;
68 numIndices = pointCount;
74 using ControlSignature = void(CellSetIn cellset, FieldOutCell connectivity);
75 using ExecutionSignature = void(PointCount, PointIndices, _2);
76 using InputDomain = _1;
78 template <
typename Po
intIndicesType,
typename OutConnectivityType>
80 const PointIndicesType& pointIndices,
81 OutConnectivityType& connectivity)
const
85 connectivity[i] = pointIndices[i];
90 template <
typename CellSetPermutationType>
92 const CellSetPermutationType& cs,
100 template <
typename NumIndicesStorageType>
106 return viskores::cont::internal::ConvertNumComponentsToOffsetsTemplate(numIndices,
110 template <
typename CellSetPermutationType,
typename OffsetsStorageType>
112 const CellSetPermutationType& cs,
118 connectivity.
Allocate(connectivityLength);
127 template <
typename ConnectivityStorageTag = VISKORES_DEFAULT_STORAGE_TAG,
128 typename OffsetsStorageTag = VISKORES_DEFAULT_STORAGE_TAG,
129 typename NumIndicesStorageTag = VISKORES_DEFAULT_STORAGE_TAG>
130 struct RConnBuilderInputData
134 using NumIndicesArrayType =
137 ConnectivityArrayType Connectivity;
138 OffsetsArrayType Offsets;
139 NumIndicesArrayType NumIndices;
143 template <
typename CellSetPermutationType>
144 class RConnBuilderInput
147 using ConnectivityArrays = viskores::cont::internal::RConnBuilderInputData<>;
149 static ConnectivityArrays
Get(
const CellSetPermutationType& cellset,
152 using Helper = RConnTableHelpers;
153 ConnectivityArrays conn;
156 conn.NumIndices = Helper::GetNumIndicesArray(cellset, device);
157 conn.Offsets = Helper::GetOffsetsArray(conn.NumIndices, connectivityLength, device);
159 Helper::GetConnectivityArray(cellset, conn.Offsets, connectivityLength, device);
166 template <
typename InShapesST,
168 typename InOffsetsST,
169 typename PermutationArrayHandleType>
170 class RConnBuilderInput<CellSetPermutation<CellSetExplicit<InShapesST, InConnST, InOffsetsST>,
171 PermutationArrayHandleType>>
174 using BaseCellSetType = CellSetExplicit<InShapesST, InConnST, InOffsetsST>;
175 using CellSetPermutationType = CellSetPermutation<BaseCellSetType, PermutationArrayHandleType>;
177 using InShapesArrayType =
typename BaseCellSetType::ShapesArrayType;
178 using InNumIndicesArrayType =
typename BaseCellSetType::NumIndicesArrayType;
182 using NumIndicesStorageTag =
184 InNumIndicesArrayType>::StorageTag;
188 using ConnectivityArrays = viskores::cont::internal::
189 RConnBuilderInputData<ConnectivityStorageTag, OffsetsStorageTag, NumIndicesStorageTag>;
191 static ConnectivityArrays
Get(
const CellSetPermutationType& cellset,
194 using Helper = RConnTableHelpers;
199 auto fullCellSet = cellset.GetFullCellSet();
202 ConnectivityArrays conn;
204 fullCellSet.GetOffsetsArray(cell, point);
209 cellset.GetValidCellIds(), fullCellSet.GetNumIndicesArray(cell, point));
213 conn.Offsets = Helper::GetOffsetsArray(conn.NumIndices, connectivityLength, device);
220 Helper::GetConnectivityArray(cellset, conn.Offsets, connectivityLength, device);
227 template <viskores::IdComponent DIMENSION,
typename PermutationArrayHandleType>
228 class RConnBuilderInput<
229 CellSetPermutation<CellSetStructured<DIMENSION>, PermutationArrayHandleType>>
232 using CellSetPermutationType =
233 CellSetPermutation<CellSetStructured<DIMENSION>, PermutationArrayHandleType>;
236 using ConnectivityArrays = viskores::cont::internal::RConnBuilderInputData<
237 VISKORES_DEFAULT_STORAGE_TAG,
241 static ConnectivityArrays
Get(
const CellSetPermutationType& cellset,
244 viskores::Id numberOfCells = cellset.GetNumberOfCells();
246 viskores::internal::ConnectivityStructuredInternals<DIMENSION>::NUM_POINTS_IN_CELL;
247 viskores::Id connectivityLength = numberOfCells * numPointsInCell;
249 ConnectivityArrays conn;
251 conn.Offsets = ArrayHandleCounting<viskores::Id>(0, numPointsInCell, numberOfCells + 1);
253 RConnTableHelpers::GetConnectivityArray(cellset, conn.Offsets, connectivityLength, device);
259 template <
typename CellSetPermutationType>
260 struct CellSetPermutationTraits;
262 template <
typename OriginalCellSet_,
typename PermutationArrayHandleType_>
263 struct CellSetPermutationTraits<CellSetPermutation<OriginalCellSet_, PermutationArrayHandleType_>>
265 using OriginalCellSet = OriginalCellSet_;
266 using PermutationArrayHandleType = PermutationArrayHandleType_;
269 template <
typename OriginalCellSet_,
270 typename OriginalPermutationArrayHandleType,
271 typename PermutationArrayHandleType_>
272 struct CellSetPermutationTraits<
273 CellSetPermutation<CellSetPermutation<OriginalCellSet_, OriginalPermutationArrayHandleType>,
274 PermutationArrayHandleType_>>
276 using PreviousCellSet = CellSetPermutation<OriginalCellSet_, OriginalPermutationArrayHandleType>;
278 PermutationArrayHandleType_,
279 typename CellSetPermutationTraits<PreviousCellSet>::PermutationArrayHandleType>;
280 using OriginalCellSet =
typename CellSetPermutationTraits<PreviousCellSet>::OriginalCellSet;
281 using Superclass = CellSetPermutation<OriginalCellSet, PermutationArrayHandleType>;
284 template <
typename VisitTopology,
285 typename IncidentTopology,
286 typename OriginalCellSetType,
287 typename PermutationArrayHandleType>
288 struct CellSetPermutationConnectivityChooser;
290 template <
typename OriginalCellSetType,
typename PermutationArrayHandleType>
291 struct CellSetPermutationConnectivityChooser<
viskores::TopologyElementTagCell,
294 PermutationArrayHandleType>
296 using ExecPortalType =
typename PermutationArrayHandleType::ReadPortalType;
297 using OrigExecObjectType =
301 using ExecConnectivityType =
305 template <
typename OriginalCellSetType,
typename PermutationArrayHandleType>
306 struct CellSetPermutationConnectivityChooser<
viskores::TopologyElementTagPoint,
309 PermutationArrayHandleType>
312 using NumIndicesPortalType =
316 using ExecConnectivityType =
334 typename OriginalCellSetType_,
335 typename PermutationArrayHandleType_ =
337 class CellSetPermutation :
public CellSet
342 (std::is_same<viskores::Id, typename PermutationArrayHandleType_::ValueType>::value),
343 "Must use ArrayHandle with value type of Id for permutation array.");
424 "Calling GetCellShape(cellid) is a performance bug. Call ShapesReadPortal() "
425 "and loop over the Get.")
442 return std::make_shared<CellSetPermutation>();
453 this->
FullCellSet.DeepCopy(&(other->GetFullCellSet()));
480 template <
typename VisitTopology,
typename Inc
identTopology>
508 using ConnectivityType =
510 return ConnectivityType(
512 this->FullCellSet.PrepareForInput(device, visitTopology, incidentTopology, token));
517 ExecConnectivityType<viskores::TopologyElementTagPoint, viskores::TopologyElementTagCell>
524 (void)incidentTopology;
528 internal::ComputeRConnTable(
532 using ConnectivityType =
535 this->VisitPointsWithCells.Offsets.PrepareForInput(device, token));
541 out <<
"CellSetPermutation of: " << std::endl;
543 out <<
"Permutation Array: " << std::endl;
556 template <
typename CellSetType,
557 typename PermutationArrayHandleType1,
558 typename PermutationArrayHandleType2>
560 PermutationArrayHandleType2>
561 :
public internal::CellSetPermutationTraits<
562 CellSetPermutation<CellSetPermutation<CellSetType, PermutationArrayHandleType1>,
566 using Superclass =
typename internal::CellSetPermutationTraits<CellSetPermutation>::Superclass;
587 void Fill(
const PermutationArrayHandleType2& validCellIds,
596 return std::make_shared<CellSetPermutation>();
600 template <
typename OriginalCellSet,
typename PermutationArrayHandleType>
603 const OriginalCellSet& cellSet)
609 cellIndexMap, cellSet);
622 template <
typename CSType,
typename AHVal
idCellIds>
623 struct SerializableTypeString<
viskores::cont::CellSetPermutation<CSType, AHValidCellIds>>
638 template <
typename CSType,
typename AHVal
idCellIds>
639 struct Serialization<
viskores::cont::CellSetPermutation<CSType, AHValidCellIds>>
645 static VISKORES_CONT void save(BinaryBuffer& bb,
const Type& cs)
647 viskoresdiy::save(bb, cs.GetFullCellSet());
648 viskoresdiy::save(bb, cs.GetValidCellIds());
655 AHValidCellIds validCellIds;
665 #endif //viskores_cont_CellSetPermutation_h