19 #ifndef viskores_internal_ConnectivityStructuredInternals_h
20 #define viskores_internal_ConnectivityStructuredInternals_h
35 template <viskores::IdComponent>
36 class ConnectivityStructuredInternals;
40 class ConnectivityStructuredInternals<1>
46 void SetPointDimensions(
viskores::Id dimensions) { this->PointDimensions = dimensions; }
51 this->GlobalPointDimensions = dimensions;
55 void SetGlobalPointIndexStart(
viskores::Id start) { this->GlobalPointIndexStart = start; }
58 viskores::Id GetPointDimensions()
const {
return this->PointDimensions; }
61 viskores::Id GetGlobalPointDimensions()
const {
return this->GlobalPointDimensions; }
64 viskores::Id GetCellDimensions()
const {
return this->PointDimensions - 1; }
67 viskores::Id GetGlobalCellDimensions()
const {
return this->GlobalPointDimensions - 1; }
72 return this->GetNumberOfCells();
78 return this->GetNumberOfPoints();
82 SchedulingRangeType GetGlobalPointIndexStart()
const {
return this->GlobalPointIndexStart; }
88 viskores::Id GetNumberOfPoints()
const {
return this->PointDimensions; }
90 viskores::Id GetNumberOfCells()
const {
return this->PointDimensions - 1; }
105 pointIds[1] = pointIds[0] + 1;
114 if ((pointIndex > 0) && (pointIndex < this->PointDimensions - 1))
134 cellIds.
Append(index - 1);
136 if (index < this->PointDimensions - 1)
151 return logicalPointIndex;
160 return logicalCellIndex;
164 void PrintSummary(std::ostream& out)
const
166 out <<
" UniformConnectivity<1> ";
167 out <<
"PointDimensions[" << this->PointDimensions <<
"] ";
168 out <<
"GlobalPointDimensions[" << this->GlobalPointDimensions <<
"] ";
169 out <<
"GlobalPointIndexStart[" << this->GlobalPointIndexStart <<
"] ";
181 class ConnectivityStructuredInternals<2>
187 void SetPointDimensions(
viskores::Id2 dims) { this->PointDimensions = dims; }
190 void SetGlobalPointDimensions(
viskores::Id2 dims) { this->GlobalPointDimensions = dims; }
193 void SetGlobalPointIndexStart(
viskores::Id2 start) { this->GlobalPointIndexStart = start; }
196 const viskores::Id2& GetPointDimensions()
const {
return this->PointDimensions; }
199 const viskores::Id2& GetGlobalPointDimensions()
const {
return this->GlobalPointDimensions; }
220 return this->GetCellDimensions();
225 return this->GetPointDimensions();
229 const viskores::Id2& GetGlobalPointIndexStart()
const {
return this->GlobalPointIndexStart; }
248 const SchedulingRangeType& logicalCellIndex)
const
251 pointIds[0] = this->LogicalToFlatPointIndex(logicalCellIndex);
252 pointIds[1] = pointIds[0] + 1;
253 pointIds[2] = pointIds[1] + this->PointDimensions[0];
254 pointIds[3] = pointIds[2] - 1;
261 return this->GetPointsOfCell(this->FlatToLogicalCellIndex(cellIndex));
265 const SchedulingRangeType& ij)
const
271 if ((ij[dim] > 0) && (ij[dim] < this->PointDimensions[dim] - 1))
283 return this->GetNumberOfCellsOnPoint(this->FlatToLogicalPointIndex(pointIndex));
288 const SchedulingRangeType& ij)
const
292 if ((ij[0] > 0) && (ij[1] > 0))
296 if ((ij[0] < this->PointDimensions[0] - 1) && (ij[1] > 0))
300 if ((ij[0] > 0) && (ij[1] < this->PointDimensions[1] - 1))
304 if ((ij[0] < this->PointDimensions[0] - 1) && (ij[1] < this->PointDimensions[1] - 1))
306 cellIds.
Append(this->LogicalToFlatCellIndex(ij));
316 return this->GetCellsOfPoint(this->FlatToLogicalPointIndex(pointIndex));
323 logicalPointIndex[0] = flatPointIndex % this->PointDimensions[0];
324 logicalPointIndex[1] = flatPointIndex / this->PointDimensions[0];
325 return logicalPointIndex;
331 return logicalPointIndex[0] + this->PointDimensions[0] * logicalPointIndex[1];
339 logicalCellIndex[0] = flatCellIndex % cellDimensions[0];
340 logicalCellIndex[1] = flatCellIndex / cellDimensions[0];
341 return logicalCellIndex;
348 return logicalCellIndex[0] + cellDimensions[0] * logicalCellIndex[1];
352 void PrintSummary(std::ostream& out)
const
354 out <<
" UniformConnectivity<2> ";
355 out <<
"PointDimensions[" << this->PointDimensions[0] <<
" " << this->PointDimensions[1]
357 out <<
"GlobalPointDimensions[" << this->GlobalPointDimensions[0] <<
" "
358 << this->GlobalPointDimensions[1] <<
"] ";
359 out <<
"GlobalPointIndexStart[" << this->GlobalPointIndexStart[0] <<
" "
360 << this->GlobalPointIndexStart[1] <<
"] ";
372 class ConnectivityStructuredInternals<3>
380 this->PointDimensions = dims;
382 this->CellDim01 = (dims[0] - 1) * (dims[1] - 1);
388 this->GlobalPointDimensions = dims;
393 void SetGlobalPointIndexStart(
viskores::Id3 start) { this->GlobalPointIndexStart = start; }
396 const viskores::Id3& GetPointDimensions()
const {
return this->PointDimensions; }
399 const viskores::Id3& GetGlobalPointDimensions()
const {
return this->GlobalPointDimensions; }
402 const viskores::Id3& GetCellDimensions()
const {
return this->CellDimensions; }
405 const viskores::Id3& GetGlobalCellDimensions()
const {
return this->GlobalCellDimensions; }
414 return this->GetCellDimensions();
419 return this->GetPointDimensions();
423 const viskores::Id3& GetGlobalPointIndexStart()
const {
return this->GlobalPointIndexStart; }
442 const SchedulingRangeType& ijk)
const
445 pointIds[0] = (ijk[2] * this->PointDimensions[1] + ijk[1]) * this->PointDimensions[0] + ijk[0];
446 pointIds[1] = pointIds[0] + 1;
447 pointIds[2] = pointIds[1] + this->PointDimensions[0];
448 pointIds[3] = pointIds[2] - 1;
449 pointIds[4] = pointIds[0] + this->PointDimensions[0] * this->PointDimensions[1];
450 pointIds[5] = pointIds[4] + 1;
451 pointIds[6] = pointIds[5] + this->PointDimensions[0];
452 pointIds[7] = pointIds[6] - 1;
460 return this->GetPointsOfCell(this->FlatToLogicalCellIndex(cellIndex));
464 const SchedulingRangeType& ijk)
const
470 if ((ijk[dim] > 0) && (ijk[dim] < this->PointDimensions[dim] - 1))
482 return this->GetNumberOfCellsOnPoint(this->FlatToLogicalPointIndex(pointIndex));
487 const SchedulingRangeType& ijk)
const
491 if ((ijk[0] > 0) && (ijk[1] > 0) && (ijk[2] > 0))
495 if ((ijk[0] < this->PointDimensions[0] - 1) && (ijk[1] > 0) && (ijk[2] > 0))
499 if ((ijk[0] > 0) && (ijk[1] < this->PointDimensions[1] - 1) && (ijk[2] > 0))
503 if ((ijk[0] < this->PointDimensions[0] - 1) && (ijk[1] < this->PointDimensions[1] - 1) &&
509 if ((ijk[0] > 0) && (ijk[1] > 0) && (ijk[2] < this->PointDimensions[2] - 1))
513 if ((ijk[0] < this->PointDimensions[0] - 1) && (ijk[1] > 0) &&
514 (ijk[2] < this->PointDimensions[2] - 1))
518 if ((ijk[0] > 0) && (ijk[1] < this->PointDimensions[1] - 1) &&
519 (ijk[2] < this->PointDimensions[2] - 1))
523 if ((ijk[0] < this->PointDimensions[0] - 1) && (ijk[1] < this->PointDimensions[1] - 1) &&
524 (ijk[2] < this->PointDimensions[2] - 1))
526 cellIds.
Append(this->LogicalToFlatCellIndex(ijk));
536 return this->GetCellsOfPoint(this->FlatToLogicalPointIndex(pointIndex));
540 void PrintSummary(std::ostream& out)
const
542 out <<
" UniformConnectivity<3> ";
543 out <<
"PointDimensions[" << this->PointDimensions[0] <<
" " << this->PointDimensions[1] <<
" "
544 << this->PointDimensions[2] <<
"] ";
545 out <<
"GlobalPointDimensions[" << this->GlobalPointDimensions[0] <<
" "
546 << this->GlobalPointDimensions[1] <<
" " << this->GlobalPointDimensions[2] <<
"] ";
547 out <<
"GlobalPointIndexStart[" << this->GlobalPointIndexStart[0] <<
" "
548 << this->GlobalPointIndexStart[1] <<
" " << this->GlobalPointIndexStart[2] <<
"] ";
555 const viskores::Id pointDims01 = this->PointDimensions[0] * this->PointDimensions[1];
556 const viskores::Id indexij = flatPointIndex % pointDims01;
559 indexij / this->PointDimensions[0],
560 flatPointIndex / pointDims01);
566 return logicalPointIndex[0] +
567 this->PointDimensions[0] *
568 (logicalPointIndex[1] + this->PointDimensions[1] * logicalPointIndex[2]);
574 const viskores::Id indexij = flatCellIndex % this->CellDim01;
576 indexij / this->CellDimensions[0],
577 flatCellIndex / this->CellDim01);
583 return logicalCellIndex[0] +
584 this->CellDimensions[0] *
585 (logicalCellIndex[1] + this->CellDimensions[1] * logicalCellIndex[2]);
600 template <
typename VisitTopology,
typename Inc
identTopology, viskores::IdComponent Dimension>
601 struct ConnectivityStructuredIndexHelper
608 "Missing Specialization for Topologies");
611 template <viskores::IdComponent Dimension>
612 struct ConnectivityStructuredIndexHelper<
viskores::TopologyElementTagCell,
616 using ConnectivityType = viskores::internal::ConnectivityStructuredInternals<Dimension>;
617 using LogicalIndexType =
typename ConnectivityType::SchedulingRangeType;
619 using CellShapeTag =
typename ConnectivityType::CellShapeTag;
625 return connectivity.GetNumberOfCells();
628 template <
typename IndexType>
633 return ConnectivityType::NUM_POINTS_IN_CELL;
636 template <
typename IndexType>
637 VISKORES_EXEC_CONT static IndicesType GetIndices(
const ConnectivityType& connectivity,
638 const IndexType& cellIndex)
640 return connectivity.GetPointsOfCell(cellIndex);
644 static LogicalIndexType FlatToLogicalIncidentIndex(
const ConnectivityType& connectivity,
647 return connectivity.FlatToLogicalPointIndex(flatFromIndex);
651 static viskores::Id LogicalToFlatIncidentIndex(
const ConnectivityType& connectivity,
652 const LogicalIndexType& logicalFromIndex)
654 return connectivity.LogicalToFlatPointIndex(logicalFromIndex);
658 static LogicalIndexType FlatToLogicalVisitIndex(
const ConnectivityType& connectivity,
661 return connectivity.FlatToLogicalCellIndex(flatToIndex);
665 static viskores::Id LogicalToFlatVisitIndex(
const ConnectivityType& connectivity,
666 const LogicalIndexType& logicalToIndex)
668 return connectivity.LogicalToFlatCellIndex(logicalToIndex);
672 template <viskores::IdComponent Dimension>
673 struct ConnectivityStructuredIndexHelper<
viskores::TopologyElementTagPoint,
677 using ConnectivityType = viskores::internal::ConnectivityStructuredInternals<Dimension>;
678 using LogicalIndexType =
typename ConnectivityType::SchedulingRangeType;
686 return connectivity.GetNumberOfPoints();
689 template <
typename IndexType>
691 const ConnectivityType& connectivity,
692 const IndexType& pointIndex)
694 return connectivity.GetNumberOfCellsOnPoint(pointIndex);
697 template <
typename IndexType>
698 VISKORES_EXEC_CONT static IndicesType GetIndices(
const ConnectivityType& connectivity,
699 const IndexType& pointIndex)
701 return connectivity.GetCellsOfPoint(pointIndex);
705 static LogicalIndexType FlatToLogicalIncidentIndex(
const ConnectivityType& connectivity,
708 return connectivity.FlatToLogicalCellIndex(flatFromIndex);
712 static viskores::Id LogicalToFlatIncidentIndex(
const ConnectivityType& connectivity,
713 const LogicalIndexType& logicalFromIndex)
715 return connectivity.LogicalToFlatCellIndex(logicalFromIndex);
719 static LogicalIndexType FlatToLogicalVisitIndex(
const ConnectivityType& connectivity,
722 return connectivity.FlatToLogicalPointIndex(flatToIndex);
726 static viskores::Id LogicalToFlatVisitIndex(
const ConnectivityType& connectivity,
727 const LogicalIndexType& logicalToIndex)
729 return connectivity.LogicalToFlatPointIndex(logicalToIndex);
735 #endif //viskores_internal_ConnectivityStructuredInternals_h