16 #ifndef __INTREPID2_CELLTOOLS_DEF_PHYS_TO_REF_HPP__
17 #define __INTREPID2_CELLTOOLS_DEF_PHYS_TO_REF_HPP__
20 #if defined (__clang__) && !defined (__INTEL_COMPILER)
21 #pragma clang system_header
33 template<
typename DeviceType>
34 template<
typename refPointValueType,
class ...refPointProperties,
35 typename physPointValueType,
class ...physPointProperties,
36 typename worksetCellValueType,
class ...worksetCellProperties>
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
54 CellTools_mapToReferenceFrameArgs(refPoints, physPoints, worksetCell, cellTopo);
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 using result_layout =
typename DeduceLayout< decltype(refPoints) >::result_layout;
72 auto vcprop = Kokkos::common_view_alloc_prop(refPoints);
73 using common_value_type =
typename decltype(vcprop)::value_type;
74 Kokkos::DynRankView< common_value_type, result_layout, deviceType > initGuess ( Kokkos::view_alloc(
"CellTools::mapToReferenceFrame::initGuess", vcprop), numCells, numPoints, spaceDim );
76 rst::clone(initGuess, cellCenter);
78 mapToReferenceFrameInitGuess(refPoints, initGuess, physPoints, worksetCell, cellTopo);
82 template<
typename DeviceType>
83 template<
typename refPointValueType,
class ...refPointProperties,
84 typename initGuessValueType,
class ...initGuessProperties,
85 typename physPointValueType,
class ...physPointProperties,
86 typename worksetCellValueType,
class ...worksetCellProperties,
87 typename HGradBasisPtrType>
91 const Kokkos::DynRankView<initGuessValueType,initGuessProperties...> initGuess,
92 const Kokkos::DynRankView<physPointValueType,physPointProperties...> physPoints,
93 const Kokkos::DynRankView<worksetCellValueType,worksetCellProperties...> worksetCell,
94 const HGradBasisPtrType basis ) {
95 #ifdef HAVE_INTREPID2_DEBUG
96 CellTools_mapToReferenceFrameInitGuessArgs(refPoints, initGuess, physPoints, worksetCell,
97 basis->getBaseCellTopology());
101 constexpr
bool are_accessible =
102 Kokkos::Impl::MemorySpaceAccess<MemSpaceType,
103 typename decltype(refPoints)::memory_space>::accessible &&
104 Kokkos::Impl::MemorySpaceAccess<MemSpaceType,
105 typename decltype(initGuess)::memory_space>::accessible &&
106 Kokkos::Impl::MemorySpaceAccess<MemSpaceType,
107 typename decltype(physPoints)::memory_space>::accessible &&
108 Kokkos::Impl::MemorySpaceAccess<MemSpaceType,
109 typename decltype(worksetCell)::memory_space>::accessible;
111 static_assert(are_accessible,
"CellTools<DeviceType>::mapToReferenceFrameInitGuess(..): input/output views' memory spaces are not compatible with DeviceType");
114 const auto cellTopo = basis->getBaseCellTopology();
115 const auto spaceDim = cellTopo.getDimension();
119 const auto numCells = worksetCell.extent(0);
120 const auto numPoints = physPoints.extent(1);
123 const auto tol = tolerence();
125 using result_layout =
typename DeduceLayout< decltype(refPoints) >::result_layout;
126 auto vcprop = Kokkos::common_view_alloc_prop(refPoints);
127 using viewType = Kokkos::DynRankView<typename decltype(vcprop)::value_type, result_layout, DeviceType >;
130 viewType xOld(Kokkos::view_alloc(
"CellTools::mapToReferenceFrameInitGuess::xOld", vcprop), numCells, numPoints, spaceDim);
131 viewType xTmp(Kokkos::view_alloc(
"CellTools::mapToReferenceFrameInitGuess::xTmp", vcprop), numCells, numPoints, spaceDim);
134 Kokkos::deep_copy(xOld, initGuess);
137 auto vcpropJ = Kokkos::common_view_alloc_prop(refPoints, worksetCell);
138 using viewTypeJ = Kokkos::DynRankView<typename decltype(vcpropJ)::value_type, result_layout, DeviceType >;
139 viewTypeJ jacobian(Kokkos::view_alloc(
"CellTools::mapToReferenceFrameInitGuess::jacobian", vcpropJ), numCells, numPoints, spaceDim, spaceDim);
140 viewTypeJ jacobianInv(Kokkos::view_alloc(
"CellTools::mapToReferenceFrameInitGuess::jacobianInv", vcpropJ), numCells, numPoints, spaceDim, spaceDim);
142 using errorViewType = Kokkos::DynRankView<typename ScalarTraits<refPointValueType>::scalar_type, DeviceType>;
144 xScalarTmp (
"CellTools::mapToReferenceFrameInitGuess::xScalarTmp", numCells, numPoints, spaceDim),
145 errorPointwise(
"CellTools::mapToReferenceFrameInitGuess::errorPointwise", numCells, numPoints),
146 errorCellwise (
"CellTools::mapToReferenceFrameInitGuess::errorCellwise", numCells);
153 setJacobian(jacobian, xOld, worksetCell, basis);
154 setJacobianInv(jacobianInv, jacobian);
157 mapToPhysicalFrame(xTmp, xOld, worksetCell, basis);
158 rst::subtract(xTmp, physPoints, xTmp);
159 rst::matvec(refPoints, jacobianInv, xTmp);
160 rst::add(refPoints, xOld);
163 rst::subtract(xTmp, xOld, refPoints);
166 rst::extractScalarValues(xScalarTmp, xTmp);
167 rst::vectorNorm(errorPointwise, xScalarTmp, NORM_TWO);
170 rst::vectorNorm(errorCellwise, errorPointwise, NORM_ONE);
172 auto errorCellwise_h = Kokkos::create_mirror_view(errorCellwise);
173 Kokkos::deep_copy(errorCellwise_h, errorCellwise);
174 const auto errorTotal = rst::Serial::vectorNorm(errorCellwise_h, NORM_ONE);
177 if (errorTotal < tol)
181 Kokkos::deep_copy(xOld, refPoints);
static constexpr ordinal_type MaxNewton
Maximum number of Newton iterations used internally in methods such as computing the action of the in...