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