50 #ifndef Intrepid2_TensorPoints_h 51 #define Intrepid2_TensorPoints_h 53 #include <Kokkos_Vector.hpp> 59 template<
class Po
intScalar,
typename DeviceType>
63 ordinal_type numTensorComponents_;
64 ordinal_type totalPointCount_;
65 ordinal_type totalDimension_;
66 Kokkos::View<ordinal_type*, DeviceType> dimToComponent_;
67 Kokkos::View<ordinal_type*, DeviceType> dimToComponentDim_;
68 Kokkos::Array<ordinal_type, Parameters::MaxTensorComponents> pointModulus_;
69 Kokkos::Array<ordinal_type, Parameters::MaxTensorComponents> pointDivisor_;
72 using reference_type =
typename ScalarView<PointScalar,DeviceType>::reference_type;
81 for (ordinal_type r=0; r<numTensorComponents_; r++)
83 totalPointCount_ *= pointTensorComponents_[r].extent_int(0);
84 totalDimension_ += pointTensorComponents_[r].extent_int(1);
86 ordinal_type pointDivisor = 1;
87 for (ordinal_type r=0; r<numTensorComponents_; r++)
89 pointModulus_[r] = pointTensorComponents_[r].extent_int(0);
90 pointDivisor_[r] = pointDivisor;
91 pointDivisor *= pointTensorComponents_[r].extent_int(0);
93 dimToComponent_ = Kokkos::View<ordinal_type*, DeviceType>(
"dimToComponent_",totalDimension_);
94 dimToComponentDim_ = Kokkos::View<ordinal_type*, DeviceType>(
"dimToComponentDim_",totalDimension_);
96 ordinal_type dimsSoFar = 0;
98 auto dimToComponentHost = Kokkos::create_mirror_view(dimToComponent_);
99 auto dimToComponentDimHost = Kokkos::create_mirror_view(dimToComponentDim_);
100 for (ordinal_type r=0; r<numTensorComponents_; r++)
102 const int componentDim = pointTensorComponents_[r].extent_int(1);
103 for (
int i=0; i<componentDim; i++)
105 dimToComponentHost[d] = r;
106 dimToComponentDimHost[d] = d - dimsSoFar;
109 dimsSoFar += componentDim;
111 Kokkos::deep_copy(dimToComponent_,dimToComponentHost);
112 Kokkos::deep_copy(dimToComponentDim_,dimToComponentDimHost);
121 template<
size_t numTensorComponents>
129 pointTensorComponents_[r] = pointTensorComponents[r];
141 TensorPoints(std::vector< ScalarView<PointScalar,DeviceType>> pointTensorComponents)
143 numTensorComponents_(pointTensorComponents.size()),
146 for (ordinal_type r=0; r<numTensorComponents_; r++)
148 pointTensorComponents_[r] = pointTensorComponents[r];
162 numTensorComponents_(1),
165 pointTensorComponents_[0] = points;
174 template<
class OtherPo
intsContainer>
177 const int numPoints = fromPoints.extent_int(0);
178 const int numDims = fromPoints.extent_int(1);
179 using ExecutionSpace =
typename DeviceType::execution_space;
180 auto policy = Kokkos::MDRangePolicy<ExecutionSpace,Kokkos::Rank<2>>({0,0},{numPoints,numDims});
181 Kokkos::parallel_for(
"copy points", policy,
182 KOKKOS_LAMBDA (
const int &i0,
const int &i1) {
183 toPoints(i0,i1) = fromPoints(i0,i1);
188 template<typename OtherDeviceType, class = typename std::enable_if< std::is_same<typename DeviceType::memory_space, typename OtherDeviceType::memory_space>::value>::type,
189 class = typename std::enable_if<!std::is_same<DeviceType,OtherDeviceType>::value>::type>
190 TensorPoints(const TensorPoints<PointScalar,OtherDeviceType> &tensorPoints)
192 numTensorComponents_(tensorPoints.numTensorComponents()),
193 isValid_(tensorPoints.isValid())
197 for (ordinal_type r=0; r<numTensorComponents_; r++)
206 template<typename OtherDeviceType, class = typename std::enable_if<!std::is_same<typename DeviceType::memory_space, typename OtherDeviceType::memory_space>::value>::type>
210 isValid_(tensorPoints.
isValid())
214 for (ordinal_type r=0; r<numTensorComponents_; r++)
216 ScalarView<PointScalar,OtherDeviceType> otherPointComponent = tensorPoints.
getTensorComponent(r);
217 const int numPoints = otherPointComponent.extent_int(0);
218 const int numDims = otherPointComponent.extent_int(1);
219 pointTensorComponents_[r] = ScalarView<PointScalar,DeviceType>(
"Intrepid2 point component", numPoints, numDims);
221 using MemorySpace =
typename DeviceType::memory_space;
222 auto pointComponentMirror = Kokkos::create_mirror_view_and_copy(MemorySpace(), otherPointComponent);
241 return pointTensorComponents_[tensorComponentOrdinal].extent_int(0);
252 template <
typename iType0,
typename iType1>
253 KOKKOS_INLINE_FUNCTION
typename std::enable_if<
254 (std::is_integral<iType0>::value && std::is_integral<iType1>::value),
255 reference_type>::type
256 operator()(
const iType0& tensorPointIndex,
const iType1& dim)
const {
257 const ordinal_type component = dimToComponent_[dim];
258 const ordinal_type d = dimToComponentDim_[dim];
259 const ordinal_type componentPointOrdinal = (tensorPointIndex / pointDivisor_[component]) % pointModulus_[component];
260 return pointTensorComponents_[component](componentPointOrdinal,d);
271 template <
typename iType0,
typename iType1,
size_t numTensorComponents>
272 KOKKOS_INLINE_FUNCTION
typename std::enable_if<
273 (std::is_integral<iType0>::value && std::is_integral<iType1>::value),
274 reference_type>::type
275 operator()(
const Kokkos::Array<iType0,numTensorComponents>& pointOrdinalComponents,
const iType1& dim)
const {
276 const ordinal_type component = dimToComponent_[dim];
277 const ordinal_type d = dimToComponentDim_[dim];
278 const ordinal_type componentPointOrdinal = pointOrdinalComponents[component];
279 return pointTensorComponents_[component](componentPointOrdinal,d);
287 template <
typename iType>
288 KOKKOS_INLINE_FUNCTION
289 typename std::enable_if<std::is_integral<iType>::value,
int>::type
291 if (r == static_cast<iType>(0))
293 return totalPointCount_;
295 else if (r == static_cast<iType>(1))
297 return totalDimension_;
310 template <
typename iType>
311 KOKKOS_INLINE_FUNCTION constexpr
312 typename std::enable_if<std::is_integral<iType>::value,
size_t>::type
315 return (r == static_cast<iType>(0)) ? totalPointCount_
317 (r ==
static_cast<iType
>(1)) ? totalDimension_ : 1;
325 ScalarView<PointScalar,DeviceType> expandedRawPoints(
"expanded raw points from TensorPoints", numPoints, spaceDim);
327 using ExecutionSpace =
typename DeviceType::execution_space;
328 Kokkos::parallel_for(
329 Kokkos::MDRangePolicy<ExecutionSpace,Kokkos::Rank<2>>({0,0},{numPoints,spaceDim}),
330 KOKKOS_LAMBDA (
const int &pointOrdinal,
const int &d) {
331 expandedRawPoints(pointOrdinal,d) = tensorPoints(pointOrdinal,d);
333 return expandedRawPoints;
341 KOKKOS_INLINE_FUNCTION
344 return pointTensorComponents_[r];
348 KOKKOS_INLINE_FUNCTION
355 KOKKOS_INLINE_FUNCTION
358 return numTensorComponents_;
362 KOKKOS_INLINE_FUNCTION
363 constexpr ordinal_type
rank()
const TensorPoints(ScalarView< PointScalar, DeviceType > points)
Constructor for point set with trivial tensor structure.
View-like interface to tensor points; point components are stored separately; the appropriate coordin...
void initialize()
Initialize members based on constructor parameters.
KOKKOS_INLINE_FUNCTION constexpr ordinal_type rank() const
Return the rank of the container, which is 2.
TensorPoints(const TensorPoints< PointScalar, OtherDeviceType > &tensorPoints)
copy-like constructor for differing memory spaces. This does a deep_copy of the underlying view...
KOKKOS_INLINE_FUNCTION std::enable_if< std::is_integral< iType >::value, int >::type extent_int(const iType &r) const
Returns the logical extent in the requested dimension.
void copyPointsContainer(ScalarView< PointScalar, DeviceType > toPoints, OtherPointsContainer fromPoints)
Copy from one points container, which may be an arbitrary functor, to a DynRankView.
ScalarView< PointScalar, DeviceType > allocateAndFillExpandedRawPointView() const
This method is for compatibility with existing methods that take raw point views. Note that in genera...
ordinal_type componentPointCount(const ordinal_type &tensorComponentOrdinal) const
Returns the number of points in the indicated component.
KOKKOS_INLINE_FUNCTION bool isValid() const
Returns true for containers that have data; false for those that don't (e.g., those that have been co...
TensorPoints(Kokkos::Array< ScalarView< PointScalar, DeviceType >, numTensorComponents > pointTensorComponents)
Constructor with fixed-length Kokkos::Array argument.
KOKKOS_INLINE_FUNCTION constexpr std::enable_if< std::is_integral< iType >::value, size_t >::type extent(const iType &r) const
Returns the logical extent in the requested dimension.
TensorPoints()
Default constructor. TensorPoints::isValid() will return false.
KOKKOS_INLINE_FUNCTION ScalarView< PointScalar, DeviceType > getTensorComponent(const ordinal_type &r) const
Returns the requested tensor component.
KOKKOS_INLINE_FUNCTION ordinal_type numTensorComponents() const
Returns the number of tensorial components.
TensorPoints(std::vector< ScalarView< PointScalar, DeviceType >> pointTensorComponents)
Constructor with variable-length std::vector argument.
static constexpr ordinal_type MaxTensorComponents
Maximum number of tensor/Cartesian products that can be taken: this allows hypercube basis in 7D to b...