VTK-m  2.2
FetchTagArrayTopologyMapIn.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10 #ifndef vtk_m_exec_arg_FetchTagArrayTopologyMapIn_h
11 #define vtk_m_exec_arg_FetchTagArrayTopologyMapIn_h
12 
14 #include <vtkm/exec/arg/Fetch.h>
16 
18 
20 
24 
26 
27 namespace vtkm
28 {
29 namespace exec
30 {
31 namespace arg
32 {
33 
41 {
42 };
43 
45 namespace detail
46 {
47 
48 // This internal class defines how a TopologyMapIn fetch loads from field data
49 // based on the connectivity class and the object holding the field data. The
50 // default implementation gets a Vec of indices and an array portal for the
51 // field and delivers a VecFromPortalPermute. Specializations could have more
52 // efficient implementations. For example, if the connectivity is structured
53 // and the field is regular point coordinates, it is much faster to compute the
54 // field directly.
55 
56 template <typename ConnectivityType, typename FieldExecObjectType, typename ThreadIndicesType>
57 struct FetchArrayTopologyMapInImplementation
58 {
59  // stored in a Vec-like object.
60  using IndexVecType = typename ThreadIndicesType::IndicesIncidentType;
61 
62  // The FieldExecObjectType is expected to behave like an ArrayPortal.
63  using PortalType = FieldExecObjectType;
64 
66 
68  VTKM_EXEC
69  static ValueType Load(const ThreadIndicesType& indices, const FieldExecObjectType& field)
70  {
71  // It is important that we give the VecFromPortalPermute (ValueType) a
72  // pointer that will stay around during the time the Vec is valid. Thus, we
73  // should make sure that indices is a reference that goes up the stack at
74  // least as far as the returned VecFromPortalPermute is used.
75  return ValueType(indices.GetIndicesIncidentPointer(), field);
76  }
77 
79  VTKM_EXEC
80  static ValueType Load(const ThreadIndicesType& indices, const FieldExecObjectType* const field)
81  {
82  // It is important that we give the VecFromPortalPermute (ValueType) a
83  // pointer that will stay around during the time the Vec is valid. Thus, we
84  // should make sure that indices is a reference that goes up the stack at
85  // least as far as the returned VecFromPortalPermute is used.
86  return ValueType(indices.GetIndicesIncidentPointer(), field);
87  }
88 };
89 
90 static inline VTKM_EXEC vtkm::VecAxisAlignedPointCoordinates<1> make_VecAxisAlignedPointCoordinates(
91  const vtkm::Vec3f& origin,
92  const vtkm::Vec3f& spacing,
93  const vtkm::Vec<vtkm::Id, 1>& logicalId)
94 {
95  vtkm::Vec3f offsetOrigin(
96  origin[0] + spacing[0] * static_cast<vtkm::FloatDefault>(logicalId[0]), origin[1], origin[2]);
97  return vtkm::VecAxisAlignedPointCoordinates<1>(offsetOrigin, spacing);
98 }
99 
100 static inline VTKM_EXEC vtkm::VecAxisAlignedPointCoordinates<1> make_VecAxisAlignedPointCoordinates(
101  const vtkm::Vec3f& origin,
102  const vtkm::Vec3f& spacing,
103  vtkm::Id logicalId)
104 {
105  return make_VecAxisAlignedPointCoordinates(origin, spacing, vtkm::Vec<vtkm::Id, 1>(logicalId));
106 }
107 
108 static inline VTKM_EXEC vtkm::VecAxisAlignedPointCoordinates<2> make_VecAxisAlignedPointCoordinates(
109  const vtkm::Vec3f& origin,
110  const vtkm::Vec3f& spacing,
111  const vtkm::Id2& logicalId)
112 {
113  vtkm::Vec3f offsetOrigin(origin[0] + spacing[0] * static_cast<vtkm::FloatDefault>(logicalId[0]),
114  origin[1] + spacing[1] * static_cast<vtkm::FloatDefault>(logicalId[1]),
115  origin[2]);
116  return vtkm::VecAxisAlignedPointCoordinates<2>(offsetOrigin, spacing);
117 }
118 
119 static inline VTKM_EXEC vtkm::VecAxisAlignedPointCoordinates<3> make_VecAxisAlignedPointCoordinates(
120  const vtkm::Vec3f& origin,
121  const vtkm::Vec3f& spacing,
122  const vtkm::Id3& logicalId)
123 {
124  vtkm::Vec3f offsetOrigin(origin[0] + spacing[0] * static_cast<vtkm::FloatDefault>(logicalId[0]),
125  origin[1] + spacing[1] * static_cast<vtkm::FloatDefault>(logicalId[1]),
126  origin[2] + spacing[2] * static_cast<vtkm::FloatDefault>(logicalId[2]));
127  return vtkm::VecAxisAlignedPointCoordinates<3>(offsetOrigin, spacing);
128 }
129 
130 template <vtkm::IdComponent NumDimensions, typename ThreadIndicesType>
131 struct FetchArrayTopologyMapInImplementation<
132  vtkm::exec::ConnectivityStructured<vtkm::TopologyElementTagCell,
133  vtkm::TopologyElementTagPoint,
134  NumDimensions>,
135  vtkm::internal::ArrayPortalUniformPointCoordinates,
136  ThreadIndicesType>
137 
138 {
141  NumDimensions>;
142 
144 
146  VTKM_EXEC
147  static ValueType Load(const ThreadIndicesType& indices,
148  const vtkm::internal::ArrayPortalUniformPointCoordinates& field)
149  {
150  // This works because the logical cell index is the same as the logical
151  // point index of the first point on the cell.
152  return vtkm::exec::arg::detail::make_VecAxisAlignedPointCoordinates(
153  field.GetOrigin(), field.GetSpacing(), indices.GetIndexLogical());
154  }
155 };
156 
157 template <typename PermutationPortal, vtkm::IdComponent NumDimensions, typename ThreadIndicesType>
158 struct FetchArrayTopologyMapInImplementation<
159  vtkm::exec::ConnectivityPermutedVisitCellsWithPoints<
160  PermutationPortal,
161  vtkm::exec::ConnectivityStructured<vtkm::TopologyElementTagCell,
162  vtkm::TopologyElementTagPoint,
163  NumDimensions>>,
164  vtkm::internal::ArrayPortalUniformPointCoordinates,
165  ThreadIndicesType>
166 
167 {
169  PermutationPortal,
172  NumDimensions>>;
173 
175 
177  VTKM_EXEC
178  static ValueType Load(const ThreadIndicesType& indices,
179  const vtkm::internal::ArrayPortalUniformPointCoordinates& field)
180  {
181  // This works because the logical cell index is the same as the logical
182  // point index of the first point on the cell.
183 
184  // we have a flat index but we need 3d uniform coordinates, so we
185  // need to take an flat index and convert to logical index
186  return vtkm::exec::arg::detail::make_VecAxisAlignedPointCoordinates(
187  field.GetOrigin(), field.GetSpacing(), indices.GetIndexLogical());
188  }
189 };
190 
191 } // namespace detail
193 
194 template <typename ExecObjectType>
197  ExecObjectType>
198 {
199 
200  //using ConnectivityType = typename ThreadIndicesType::Connectivity;
202  template <typename ThreadIndicesType>
203  VTKM_EXEC auto Load(const ThreadIndicesType& indices, const ExecObjectType& field) const
204  -> decltype(
205  detail::FetchArrayTopologyMapInImplementation<typename ThreadIndicesType::Connectivity,
206  ExecObjectType,
207  ThreadIndicesType>::Load(indices, field))
208  {
209  using Implementation =
210  detail::FetchArrayTopologyMapInImplementation<typename ThreadIndicesType::Connectivity,
211  ExecObjectType,
212  ThreadIndicesType>;
213  return Implementation::Load(indices, field);
214  }
215 
216  //Optimized fetch for point arrays when iterating the cells ConnectivityExtrude
218  template <typename ScatterAndMaskMode>
221  ScatterAndMaskMode>& indices,
222  const ExecObjectType& portal) -> vtkm::Vec<typename ExecObjectType::ValueType, 6>
223  {
224  // std::cout << "opimized fetch for point values" << std::endl;
225  const auto& xgcidx = indices.GetIndicesIncident();
226  const vtkm::Id offset1 = (xgcidx.Planes[0] * xgcidx.NumberOfPointsPerPlane);
227  const vtkm::Id offset2 = (xgcidx.Planes[1] * xgcidx.NumberOfPointsPerPlane);
228 
230 
231  return ValueType(portal.Get(offset1 + xgcidx.PointIds[0][0]),
232  portal.Get(offset1 + xgcidx.PointIds[0][1]),
233  portal.Get(offset1 + xgcidx.PointIds[0][2]),
234  portal.Get(offset2 + xgcidx.PointIds[1][0]),
235  portal.Get(offset2 + xgcidx.PointIds[1][1]),
236  portal.Get(offset2 + xgcidx.PointIds[1][2]));
237  }
238 
239 
240  template <typename ThreadIndicesType, typename T>
241  VTKM_EXEC void Store(const ThreadIndicesType&, const ExecObjectType&, const T&) const
242  {
243  // Store is a no-op for this fetch.
244  }
245 };
246 }
247 }
248 } // namespace vtkm::exec::arg
249 
250 #endif //vtk_m_exec_arg_FetchTagArrayTopologyMapIn_h
vtkm::TopologyElementTagPoint
A tag used to identify the point elements in a topology.
Definition: TopologyElementTag.h:34
ConnectivityStructured.h
vtkm::VecAxisAlignedPointCoordinates
An implicit vector for point coordinates in axis aligned cells.
Definition: VecAxisAlignedPointCoordinates.h:78
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
ArrayPortalUniformPointCoordinates.h
vtkm::exec::arg::FetchTagArrayTopologyMapIn
Fetch tag for getting array values determined by topology connections.
Definition: FetchTagArrayTopologyMapIn.h:40
ThreadIndicesTopologyMap.h
vtkm::exec::arg::Fetch< vtkm::exec::arg::FetchTagArrayTopologyMapIn, vtkm::exec::arg::AspectTagDefault, ExecObjectType >::Load
auto Load(const vtkm::exec::arg::ThreadIndicesTopologyMap< vtkm::exec::ConnectivityExtrude, ScatterAndMaskMode > &indices, const ExecObjectType &portal) -> vtkm::Vec< typename ExecObjectType::ValueType, 6 >
Definition: FetchTagArrayTopologyMapIn.h:219
vtkm::exec::arg::Fetch::ValueType
typename ExecObjectType::ValueType ValueType
The type of value to load and store.
Definition: Fetch.h:58
vtkm::exec::arg::Fetch
Class for loading and storing values in thread instance.
Definition: Fetch.h:49
VecFromPortalPermute.h
ConnectivityExtrude.h
vtkm::exec::arg::Fetch< vtkm::exec::arg::FetchTagArrayTopologyMapIn, vtkm::exec::arg::AspectTagDefault, ExecObjectType >::Load
auto Load(const ThreadIndicesType &indices, const ExecObjectType &field) const -> decltype(detail::FetchArrayTopologyMapInImplementation< typename ThreadIndicesType::Connectivity, ExecObjectType, ThreadIndicesType >::Load(indices, field))
Definition: FetchTagArrayTopologyMapIn.h:203
Fetch.h
AspectTagDefault.h
vtkm::Id
vtkm::Int64 Id
Base type to use to index arrays.
Definition: Types.h:227
vtkm::exec::ConnectivityExtrude
Definition: ConnectivityExtrude.h:26
vtkm::exec::ConnectivityStructured
A class holding information about topology connections.
Definition: ConnectivityStructured.h:30
vtkm::Vec< vtkm::FloatDefault, 3 >
vtkm::FloatDefault
vtkm::Float32 FloatDefault
The floating point type to use when no other precision is specified.
Definition: Types.h:236
vtkm::exec::arg::Fetch::Load
ValueType Load(const ThreadIndicesType &indices, const ExecObjectType &execObject) const
Load data for a work instance.
vtkm::exec::arg::Fetch< vtkm::exec::arg::FetchTagArrayTopologyMapIn, vtkm::exec::arg::AspectTagDefault, ExecObjectType >::Store
void Store(const ThreadIndicesType &, const ExecObjectType &, const T &) const
Definition: FetchTagArrayTopologyMapIn.h:241
vtkm::exec::arg::AspectTagDefault
Aspect tag to use for default load/store of data.
Definition: AspectTagDefault.h:22
vtkm::TopologyElementTagCell
A tag used to identify the cell elements in a topology.
Definition: TopologyElementTag.h:24
VecAxisAlignedPointCoordinates.h
VTKM_SUPPRESS_EXEC_WARNINGS
#define VTKM_SUPPRESS_EXEC_WARNINGS
Definition: ExportMacros.h:53
vtkm::exec::arg::ThreadIndicesTopologyMap
Container for thread indices in a topology map.
Definition: ThreadIndicesTopologyMap.h:95
vtkm::exec::ConnectivityPermutedVisitCellsWithPoints
Definition: ConnectivityPermuted.h:25
TopologyElementTag.h
vtkm::VecFromPortalPermute
A short vector from an ArrayPortal and a vector of indices.
Definition: VecFromPortalPermute.h:28