16 #ifndef __INTREPID2_CELLTOOLS_DEF_REF_TO_PHYS_HPP__
17 #define __INTREPID2_CELLTOOLS_DEF_REF_TO_PHYS_HPP__
20 #if defined (__clang__) && !defined (__INTEL_COMPILER)
21 #pragma clang system_header
32 namespace FunctorCellTools {
36 template<
typename physPointViewType,
37 typename worksetCellType,
38 typename basisValType>
40 physPointViewType _physPoints;
41 const worksetCellType _worksetCells;
42 const basisValType _basisVals;
44 KOKKOS_INLINE_FUNCTION
46 worksetCellType worksetCells_,
47 basisValType basisVals_ )
48 : _physPoints(physPoints_), _worksetCells(worksetCells_), _basisVals(basisVals_) {}
50 KOKKOS_INLINE_FUNCTION
51 void operator()(
const size_type iter)
const {
53 unrollIndex( cell, pt,
54 _physPoints.extent(0),
55 _physPoints.extent(1),
57 auto phys = Kokkos::subdynrankview( _physPoints, cell, pt, Kokkos::ALL());
59 const auto valRank = rank(_basisVals);
60 const auto val = ( valRank == 2 ? Kokkos::subdynrankview( _basisVals, Kokkos::ALL(), pt) :
61 Kokkos::subdynrankview( _basisVals, cell, Kokkos::ALL(), pt));
63 const ordinal_type dim = phys.extent(0);
64 const ordinal_type cardinality = val.extent(0);
66 for (ordinal_type i=0;i<dim;++i) {
68 for (ordinal_type bf=0;bf<cardinality;++bf)
69 phys(i) += _worksetCells(cell, bf, i)*val(bf);
75 template<
typename refSubcellViewType,
76 typename paramPointsViewType,
77 typename subcellMapViewType>
79 refSubcellViewType refSubcellPoints_;
80 const paramPointsViewType paramPoints_;
81 const subcellMapViewType subcellMap_;
82 const ordinal_type subcellOrd_;
83 const ordinal_type sideDim_;
85 KOKKOS_INLINE_FUNCTION
87 const paramPointsViewType paramPoints,
88 const subcellMapViewType subcellMap,
89 ordinal_type subcellOrd)
90 : refSubcellPoints_(refSubcellPoints), paramPoints_(paramPoints), subcellMap_(subcellMap),
91 subcellOrd_(subcellOrd), sideDim_(paramPoints_.extent(1)){};
93 KOKKOS_INLINE_FUNCTION
94 void operator()(
const size_type pt,
const size_type d)
const {
96 refSubcellPoints_(pt, d) = subcellMap_(subcellOrd_, d, 0);
97 for(ordinal_type k=0; k<sideDim_; ++k)
98 refSubcellPoints_(pt, d) += subcellMap_(subcellOrd_, d, k+1)*paramPoints_(pt, k);
102 template<
typename refSubcellViewType,
103 typename paramPointsViewType,
104 typename subcellMapViewType,
105 typename ordViewType>
107 refSubcellViewType refSubcellPoints_;
108 const paramPointsViewType paramPoints_;
109 const subcellMapViewType subcellMap_;
110 const ordViewType subcellOrd_;
111 const ordinal_type sideDim_;
113 KOKKOS_INLINE_FUNCTION
115 const paramPointsViewType paramPoints,
116 const subcellMapViewType subcellMap,
117 ordViewType subcellOrd)
118 : refSubcellPoints_(refSubcellPoints), paramPoints_(paramPoints), subcellMap_(subcellMap),
119 subcellOrd_(subcellOrd), sideDim_(paramPoints_.extent(1)){};
121 KOKKOS_INLINE_FUNCTION
122 void operator()(
const size_type isc,
const size_type pt,
const size_type d)
const {
124 refSubcellPoints_(isc, pt, d) = subcellMap_(subcellOrd_(isc), d, 0);
125 for(ordinal_type k=0; k<sideDim_; ++k)
126 refSubcellPoints_(isc, pt, d) += subcellMap_(subcellOrd_(isc), d, k+1)*paramPoints_(pt, k);
131 template<
typename DeviceType>
132 template<
typename PhysPointViewType,
133 typename RefPointViewType,
134 typename WorksetType,
135 typename HGradBasisPtrType>
139 const RefPointViewType refPoints,
140 const WorksetType worksetCell,
141 const HGradBasisPtrType basis ) {
142 #ifdef HAVE_INTREPID2_DEBUG
143 CellTools_mapToPhysicalFrameArgs( physPoints, refPoints, worksetCell, basis->getBaseCellTopology() );
145 constexpr
bool are_accessible =
146 Kokkos::Impl::MemorySpaceAccess<MemSpaceType,
147 typename decltype(physPoints)::memory_space>::accessible &&
148 Kokkos::Impl::MemorySpaceAccess<MemSpaceType,
149 typename decltype(refPoints)::memory_space>::accessible;
151 static_assert(are_accessible,
"CellTools<DeviceType>::mapToPhysicalFrame(..): input/output views' memory spaces are not compatible with DeviceType");
153 const auto cellTopo = basis->getBaseCellTopology();
154 const auto numCells = worksetCell.extent(0);
157 const auto refPointRank = refPoints.rank();
158 const auto numPoints = (refPointRank == 2 ? refPoints.extent(0) : refPoints.extent(1));
159 const auto basisCardinality = basis->getCardinality();
160 auto vcprop = Kokkos::common_view_alloc_prop(physPoints);
162 using valViewType = Kokkos::DynRankView<decltype(basis->getDummyOutputValue()),DeviceType>;
166 switch (refPointRank) {
169 vals = valViewType(Kokkos::view_alloc(
"CellTools::mapToPhysicalFrame::vals", vcprop), basisCardinality, numPoints);
170 basis->getValues(vals,
178 vals = valViewType(Kokkos::view_alloc(
"CellTools::mapToPhysicalFrame::vals", vcprop), numCells, basisCardinality, numPoints);
179 for (size_type cell=0;cell<numCells;++cell)
180 basis->getValues(Kokkos::subdynrankview( vals, cell, Kokkos::ALL(), Kokkos::ALL() ),
181 Kokkos::subdynrankview( refPoints, cell, Kokkos::ALL(), Kokkos::ALL() ),
187 using FunctorType = FunctorCellTools::F_mapToPhysicalFrame<PhysPointViewType,WorksetType,valViewType>;
189 const auto loopSize = physPoints.extent(0)*physPoints.extent(1);
190 Kokkos::RangePolicy<ExecSpaceType,Kokkos::Schedule<Kokkos::Static> > policy(0, loopSize);
191 Kokkos::parallel_for( policy, FunctorType(physPoints, worksetCell, vals) );
194 template<
typename DeviceType>
195 template<
typename refSubcellViewType,
typename paramViewType>
199 const paramViewType paramPoints,
200 const ordinal_type subcellDim,
201 const ordinal_type subcellOrd,
202 const shards::CellTopology parentCell ) {
203 #ifdef HAVE_INTREPID2_DEBUG
204 ordinal_type parentCellDim = parentCell.getDimension();
205 INTREPID2_TEST_FOR_EXCEPTION( !hasReferenceCell(parentCell), std::invalid_argument,
206 ">>> ERROR (Intrepid2::CellTools::mapToReferenceSubcell): the specified cell topology does not have a reference cell.");
208 INTREPID2_TEST_FOR_EXCEPTION( subcellDim < 1 ||
209 subcellDim > parentCellDim-1, std::invalid_argument,
210 ">>> ERROR (Intrepid2::CellTools::mapToReferenceSubcell): method defined only for subcells with dimension greater than 0 and less than the cell dimension");
212 INTREPID2_TEST_FOR_EXCEPTION( subcellOrd < 0 ||
213 subcellOrd >= static_cast<ordinal_type>(parentCell.getSubcellCount(subcellDim)), std::invalid_argument,
214 ">>> ERROR (Intrepid2::CellTools::mapToReferenceSubcell): subcell ordinal out of range.");
217 INTREPID2_TEST_FOR_EXCEPTION( refSubcellPoints.rank() != 2, std::invalid_argument,
218 ">>> ERROR (Intrepid2::CellTools::mapToReferenceSubcell): refSubcellPoints must have rank 2.");
219 INTREPID2_TEST_FOR_EXCEPTION( refSubcellPoints.extent(1) != parentCell.getDimension(), std::invalid_argument,
220 ">>> ERROR (Intrepid2::CellTools::mapToReferenceSubcell): refSubcellPoints dimension (1) does not match to parent cell dimension.");
223 INTREPID2_TEST_FOR_EXCEPTION( paramPoints.rank() != 2, std::invalid_argument,
224 ">>> ERROR (Intrepid2::CellTools::mapToReferenceSubcell): paramPoints must have rank 2.");
225 INTREPID2_TEST_FOR_EXCEPTION( static_cast<ordinal_type>(paramPoints.extent(1)) != subcellDim, std::invalid_argument,
226 ">>> ERROR (Intrepid2::CellTools::mapToReferenceSubcell): paramPoints dimension (1) does not match to subcell dimension.");
229 INTREPID2_TEST_FOR_EXCEPTION( refSubcellPoints.extent(0) != paramPoints.extent(0), std::invalid_argument,
230 ">>> ERROR (Intrepid2::CellTools::mapToReferenceSubcell): refSubcellPoints dimension (0) does not match to paramPoints dimension(0).");
236 mapToReferenceSubcell(refSubcellPoints, paramPoints, subcellMap, subcellOrd);
239 template<
typename DeviceType>
240 template<
typename refSubcellViewType,
typename paramViewType>
244 const paramViewType paramPoints,
245 const typename RefSubcellParametrization<DeviceType>::ConstViewType subcellParametrization,
246 const ordinal_type subcellOrd) {
248 constexpr
bool are_accessible =
249 Kokkos::Impl::MemorySpaceAccess<MemSpaceType,
250 typename decltype(refSubcellPoints)::memory_space>::accessible &&
251 Kokkos::Impl::MemorySpaceAccess<MemSpaceType,
252 typename decltype(paramPoints)::memory_space>::accessible;
253 static_assert(are_accessible,
"CellTools<DeviceType>::mapToReferenceSubcell(..): input/output views' memory spaces are not compatible with DeviceType");
256 #ifdef HAVE_INTREPID2_DEBUG
257 const bool ranks_and_dims_compatible = (refSubcellPoints.rank() == 2) && (paramPoints.rank() == 2) && (subcellParametrization.rank() == 3) &&
258 (refSubcellPoints.extent(0) == paramPoints.extent(0)) &&
259 (refSubcellPoints.extent(1) == subcellParametrization.extent(1)) &&
260 (paramPoints.extent(1) == subcellParametrization.extent(2)-1);
262 INTREPID2_TEST_FOR_EXCEPTION(!ranks_and_dims_compatible, std::invalid_argument,
"CellTools<DeviceType>::mapToReferenceSubcell(..): input/output views' ranks and dimensions are not compatible");
265 const ordinal_type parentCellDim = subcellParametrization.extent(1);
266 const ordinal_type numPts = paramPoints.extent(0);
269 using FunctorType = FunctorCellTools::F_mapReferenceSubcell<decltype(refSubcellPoints), decltype(paramPoints), decltype(subcellParametrization)>;
271 Kokkos::MDRangePolicy<ExecSpaceType,Kokkos::Rank<2>> rangePolicy({0,0},{numPts,parentCellDim});
274 Kokkos::parallel_for( rangePolicy, FunctorType(refSubcellPoints, paramPoints, subcellParametrization, subcellOrd) );
277 template<
typename DeviceType>
278 template<
typename refSubcellViewType,
typename paramViewType,
typename ordViewType>
282 const paramViewType paramPoints,
283 const typename RefSubcellParametrization<DeviceType>::ConstViewType subcellParametrization,
284 const ordViewType subcellOrd) {
286 constexpr
bool are_accessible =
287 Kokkos::Impl::MemorySpaceAccess<MemSpaceType,
288 typename decltype(refSubcellPoints)::memory_space>::accessible &&
289 Kokkos::Impl::MemorySpaceAccess<MemSpaceType,
290 typename decltype(paramPoints)::memory_space>::accessible &&
291 Kokkos::Impl::MemorySpaceAccess<MemSpaceType,
292 typename decltype(subcellOrd)::memory_space>::accessible;
293 static_assert(are_accessible,
"CellTools<DeviceType>::mapToReferenceSubcell(..): input/output views' memory spaces are not compatible with DeviceType");
296 #ifdef HAVE_INTREPID2_DEBUG
297 const bool ranks_and_dims_compatible = (refSubcellPoints.rank() == 3) && (paramPoints.rank() == 2) && (subcellParametrization.rank() == 3) &&
298 (refSubcellPoints.extent(0) == subcellOrd.extent(0)) &&
299 (refSubcellPoints.extent(1) == paramPoints.extent(0)) &&
300 (refSubcellPoints.extent(2) == subcellParametrization.extent(1)) &&
301 (paramPoints.extent(1) == subcellParametrization.extent(2)-1);
303 INTREPID2_TEST_FOR_EXCEPTION(!ranks_and_dims_compatible, std::invalid_argument,
"CellTools<DeviceType>::mapToReferenceSubcell(..): input/output views' ranks and dimensions are not compatible");
306 const ordinal_type numSubCells = refSubcellPoints.extent(0);
307 const ordinal_type parentCellDim = subcellParametrization.extent(1);
308 const ordinal_type numPts = paramPoints.extent(0);
312 using FunctorType = FunctorCellTools::F_mapReferenceSubcellBatch<decltype(refSubcellPoints), decltype(paramPoints), decltype(subcellParametrization), decltype(subcellOrd)>;
314 Kokkos::MDRangePolicy<ExecSpaceType,Kokkos::Rank<3>> rangePolicy({0,0,0},{numSubCells,numPts,parentCellDim});
317 Kokkos::parallel_for( rangePolicy, FunctorType(refSubcellPoints, paramPoints, subcellParametrization, subcellOrd) );
static ConstViewType get(const ordinal_type subcellDim, const unsigned parentCellKey)
Returns a Kokkos view with the coefficients of the parametrization maps for the edges or faces of a r...