150 mapToReferenceFrame( Kokkos::DynRankView<refPointValueType,refPointProperties...> refPoints,
151 const Kokkos::DynRankView<physPointValueType,physPointProperties...> physPoints,
152 const Kokkos::DynRankView<worksetCellValueType,worksetCellProperties...> worksetCell,
153 const shards::CellTopology cellTopo,
154 const physPointValueType shellThickness ) {
155 constexpr bool are_accessible =
156 Kokkos::SpaceAccessibility<MemSpaceType,
157 typename decltype(refPoints)::memory_space>::accessible &&
158 Kokkos::SpaceAccessibility<MemSpaceType,
159 typename decltype(physPoints)::memory_space>::accessible &&
160 Kokkos::SpaceAccessibility<MemSpaceType,
161 typename decltype(worksetCell)::memory_space>::accessible;
163 static_assert(are_accessible,
"CellTools<DeviceType>::mapToReferenceFrame(..): input/output views' memory spaces are not compatible with DeviceType");
165#ifdef HAVE_INTREPID2_DEBUG
168 using deviceType =
typename decltype(refPoints)::device_type;
171 typedef Kokkos::DynRankView<typename ScalarTraits<refPointValueType>::scalar_type,deviceType> refPointViewSpType;
173 const auto spaceDim = cellTopo.getDimension();
175 cellCenter(
"CellTools::mapToReferenceFrame::cellCenter", spaceDim);
176 getReferenceCellCenter(cellCenter, cellTopo);
179 rst::clone(refPoints, cellCenter);
181 auto basis = createHGradBasis<refPointValueType,refPointValueType>(cellTopo);
182 return mapToReferenceFrame(refPoints, physPoints, worksetCell, basis, shellThickness);
192 mapToReferenceFrame( Kokkos::DynRankView<refPointValueType,refPointProperties...> refPoints,
193 const Kokkos::DynRankView<physPointValueType,physPointProperties...> physPoints,
194 const Kokkos::DynRankView<worksetCellValueType,worksetCellProperties...> worksetCell,
196 const physPointValueType shellThickness) {
197 constexpr bool are_accessible =
198 Kokkos::SpaceAccessibility<MemSpaceType,
199 typename decltype(refPoints)::memory_space>::accessible &&
200 Kokkos::SpaceAccessibility<MemSpaceType,
201 typename decltype(physPoints)::memory_space>::accessible &&
202 Kokkos::SpaceAccessibility<MemSpaceType,
203 typename decltype(worksetCell)::memory_space>::accessible;
205 static_assert(are_accessible,
"CellTools<DeviceType>::mapToReferenceFrameInitGuess(..): input/output views' memory spaces are not compatible with DeviceType");
207 const bool isShell = (shellThickness>0);
210 const ordinal_type refDim = basis->getDomainDimension();
211 const ordinal_type physDim = physPoints.extent_int(2);
215 const auto numCells = worksetCell.extent(0);
216 const auto numPoints = physPoints.extent(1);
219 auto refDimRange = Kokkos::pair<ordinal_type,ordinal_type>(0,refDim);
221 using result_layout =
typename DeduceLayout<
decltype(refPoints) >::result_layout;
223 auto xOld = Impl::createMatchingDynRankView(refPoints,
"CellTools::mapToReferenceFrameInitGuess::xOld", numCells, numPoints, refDim);
224 auto xTmp = Impl::createMatchingDynRankView(refPoints,
"CellTools::mapToReferenceFrameInitGuess::xTmp", numCells, numPoints, refDim);
225 auto physTmp = Impl::createMatchingDynRankView(refPoints,
"CellTools::mapToReferenceFrameInitGuess::physTmp", numCells, numPoints, physDim);
228 Kokkos::deep_copy(xOld, Kokkos::subview(refPoints, Kokkos::ALL(), Kokkos::ALL(), refDimRange));
231 using valueTypeJ = std::common_type_t<
typename decltype(refPoints)::value_type,
typename decltype(worksetCell)::value_type>;
232 using viewTypeJ = Kokkos::DynRankView<valueTypeJ, result_layout, DeviceType >;
237 metric = view_factory::template create_view<viewTypeJ>(refPoints, worksetCell,
"CellTools::mapToReferenceFrameInitGuess::metric", numCells, numPoints, refDim, refDim);
238 viewTypeJ jacobian = view_factory::template create_view<viewTypeJ>(refPoints, worksetCell,
"CellTools::mapToReferenceFrameInitGuess::jacobian", numCells, numPoints, physDim, refDim);
241 viewTypeJ jacobianInv = view_factory::template create_view<viewTypeJ>(refPoints, worksetCell,
"CellTools::mapToReferenceFrameInitGuess::jacobianInv", numCells, numPoints, refDim, refDim);
244 using errorViewType = Kokkos::DynRankView<typename ScalarTraits<refPointValueType>::scalar_type, DeviceType>;
245 using errorType =
typename errorViewType::value_type;
247 xScalarTmp (
"CellTools::mapToReferenceFrameInitGuess::xScalarTmp", numCells, numPoints, physDim),
248 errorPointwise(
"CellTools::mapToReferenceFrameInitGuess::errorPointwise", numCells, numPoints);
251 const auto tol = tolerance<errorType>();
253 errorType error(0), physInfNorm(0);
255 rst::extractScalarValues(xScalarTmp, physPoints);
256 rst::vectorNorm(errorPointwise, xScalarTmp, NORM_TWO);
257 using range_policy_type = Kokkos::MDRangePolicy<typename DeviceType::execution_space, Kokkos::Rank<2>, Kokkos::IndexType<ordinal_type> >;
258 range_policy_type policy( { 0, 0 }, { numCells, numPoints } );
260 Kokkos::parallel_reduce(
"MaxReduction", policy, FunctorType(errorPointwise), Kokkos::Max<errorType>(physInfNorm));
262 auto refPts = Kokkos::subview(refPoints,Kokkos::ALL(), Kokkos::ALL(), refDimRange);
267 bool converged(
false);
271 setJacobian(jacobian, xOld, worksetCell, basis);
274 mapToPhysicalFrame(physTmp, xOld, worksetCell, basis);
275 rst::subtract(physTmp, physPoints, physTmp);
278 rst::extractScalarValues(xScalarTmp, physTmp);
279 rst::vectorNorm(errorPointwise, xScalarTmp, NORM_TWO);
282 Kokkos::parallel_reduce(
"MaxReduction", policy, FunctorType(errorPointwise), Kokkos::Max<errorType>(error));
284 if (error < tol*physInfNorm) {
290 if(refDim < physDim) {
291 rst::matvec(xTmp, jacobian, physTmp,
true);
292 rst::AtA(metric,jacobian);
293 setJacobianInv(jacobianInv, metric);
294 rst::matvec(refPts, jacobianInv, xTmp);
297 setJacobianInv(jacobianInv, jacobian);
298 rst::matvec(refPts, jacobianInv, physTmp);
302 rst::extractScalarValues(Kokkos::subview(xScalarTmp, Kokkos::ALL(), Kokkos::ALL(), refDimRange), refPts);
304 rst::add(refPts, xOld);
309 rst::vectorNorm(errorPointwise, Kokkos::subview(xScalarTmp, Kokkos::ALL(), Kokkos::ALL(), refDimRange), NORM_TWO);
310 Kokkos::parallel_reduce(
"MaxReduction", policy, FunctorType(errorPointwise), Kokkos::Max<errorType>(error));
316 setJacobian(jacobian, refPts, worksetCell, basis);
317 mapToPhysicalFrame(physTmp, refPts, worksetCell, basis);
318 rst::subtract(physTmp, physPoints, physTmp);
324 Kokkos::deep_copy(xOld, refPts);
333 scaledResidualNormalComponent(
334 Kokkos::subview(refPoints,Kokkos::ALL(), Kokkos::ALL(), refDim),