39 mapToReferenceFrame( Kokkos::DynRankView<refPointValueType,refPointProperties...> refPoints,
40 const Kokkos::DynRankView<physPointValueType,physPointProperties...> physPoints,
41 const Kokkos::DynRankView<worksetCellValueType,worksetCellProperties...> worksetCell,
42 const shards::CellTopology cellTopo ) {
43 constexpr bool are_accessible =
44 Kokkos::Impl::MemorySpaceAccess<MemSpaceType,
45 typename decltype(refPoints)::memory_space>::accessible &&
46 Kokkos::Impl::MemorySpaceAccess<MemSpaceType,
47 typename decltype(physPoints)::memory_space>::accessible &&
48 Kokkos::Impl::MemorySpaceAccess<MemSpaceType,
49 typename decltype(worksetCell)::memory_space>::accessible;
51 static_assert(are_accessible,
"CellTools<DeviceType>::mapToReferenceFrame(..): input/output views' memory spaces are not compatible with DeviceType");
53#ifdef HAVE_INTREPID2_DEBUG
56 using deviceType =
typename decltype(refPoints)::device_type;
59 typedef Kokkos::DynRankView<typename ScalarTraits<refPointValueType>::scalar_type,deviceType> refPointViewSpType;
61 const auto spaceDim = cellTopo.getDimension();
63 cellCenter(
"CellTools::mapToReferenceFrame::cellCenter", spaceDim);
64 getReferenceCellCenter(cellCenter, cellTopo);
67 const auto numCells = worksetCell.extent(0);
68 const auto numPoints = physPoints.extent(1);
71 auto initGuess = Impl::createMatchingDynRankView(refPoints,
"CellTools::mapToReferenceFrame::initGuess", numCells, numPoints, spaceDim );
72 rst::clone(initGuess, cellCenter);
74 mapToReferenceFrameInitGuess(refPoints, initGuess, physPoints, worksetCell, cellTopo);
87 const Kokkos::DynRankView<initGuessValueType,initGuessProperties...> initGuess,
88 const Kokkos::DynRankView<physPointValueType,physPointProperties...> physPoints,
89 const Kokkos::DynRankView<worksetCellValueType,worksetCellProperties...> worksetCell,
90 const HGradBasisPtrType basis ) {
91#ifdef HAVE_INTREPID2_DEBUG
92 CellTools_mapToReferenceFrameInitGuessArgs(refPoints, initGuess, physPoints, worksetCell,
93 basis->getBaseCellTopology());
97 constexpr bool are_accessible =
98 Kokkos::Impl::MemorySpaceAccess<MemSpaceType,
99 typename decltype(refPoints)::memory_space>::accessible &&
100 Kokkos::Impl::MemorySpaceAccess<MemSpaceType,
101 typename decltype(initGuess)::memory_space>::accessible &&
102 Kokkos::Impl::MemorySpaceAccess<MemSpaceType,
103 typename decltype(physPoints)::memory_space>::accessible &&
104 Kokkos::Impl::MemorySpaceAccess<MemSpaceType,
105 typename decltype(worksetCell)::memory_space>::accessible;
107 static_assert(are_accessible,
"CellTools<DeviceType>::mapToReferenceFrameInitGuess(..): input/output views' memory spaces are not compatible with DeviceType");
110 const auto cellTopo = basis->getBaseCellTopology();
111 const auto spaceDim = cellTopo.getDimension();
115 const auto numCells = worksetCell.extent(0);
116 const auto numPoints = physPoints.extent(1);
119 const auto tol = tolerence();
121 using result_layout =
typename DeduceLayout<
decltype(refPoints) >::result_layout;
123 auto xOld = Impl::createMatchingDynRankView(refPoints,
"CellTools::mapToReferenceFrameInitGuess::xOld", numCells, numPoints, spaceDim);
124 auto xTmp = Impl::createMatchingDynRankView(refPoints,
"CellTools::mapToReferenceFrameInitGuess::xTmp", numCells, numPoints, spaceDim);
127 Kokkos::deep_copy(xOld, initGuess);
130 using valueTypeJ = std::common_type_t<
typename decltype(refPoints)::value_type,
typename decltype(worksetCell)::value_type>;
131 using viewTypeJ = Kokkos::DynRankView<valueTypeJ, result_layout, DeviceType >;
133 viewTypeJ jacobian = view_factory::template create_view<viewTypeJ>(refPoints, worksetCell,
"CellTools::mapToReferenceFrameInitGuess::jacobian", numCells, numPoints, spaceDim, spaceDim);
134 viewTypeJ jacobianInv = view_factory::template create_view<viewTypeJ>(refPoints, worksetCell,
"CellTools::mapToReferenceFrameInitGuess::jacobianInv", numCells, numPoints, spaceDim, spaceDim);
136 using errorViewType = Kokkos::DynRankView<typename ScalarTraits<refPointValueType>::scalar_type, DeviceType>;
138 xScalarTmp (
"CellTools::mapToReferenceFrameInitGuess::xScalarTmp", numCells, numPoints, spaceDim),
139 errorPointwise(
"CellTools::mapToReferenceFrameInitGuess::errorPointwise", numCells, numPoints),
140 errorCellwise (
"CellTools::mapToReferenceFrameInitGuess::errorCellwise", numCells);
147 setJacobian(jacobian, xOld, worksetCell, basis);
148 setJacobianInv(jacobianInv, jacobian);
151 mapToPhysicalFrame(xTmp, xOld, worksetCell, basis);
152 rst::subtract(xTmp, physPoints, xTmp);
153 rst::matvec(refPoints, jacobianInv, xTmp);
154 rst::add(refPoints, xOld);
157 rst::subtract(xTmp, xOld, refPoints);
160 rst::extractScalarValues(xScalarTmp, xTmp);
161 rst::vectorNorm(errorPointwise, xScalarTmp, NORM_TWO);
164 rst::vectorNorm(errorCellwise, errorPointwise, NORM_ONE);
166 auto errorCellwise_h = Kokkos::create_mirror_view(errorCellwise);
167 Kokkos::deep_copy(errorCellwise_h, errorCellwise);
168 const auto errorTotal = rst::Serial::vectorNorm(errorCellwise_h, NORM_ONE);
171 if (errorTotal < tol)
175 Kokkos::deep_copy(xOld, refPoints);