59 #ifndef __INTREPID2_ORIENTATIONTOOLS_DEF_COEFF_MATRIX_HDIV_HPP__
60 #define __INTREPID2_ORIENTATIONTOOLS_DEF_COEFF_MATRIX_HDIV_HPP__
63 #if defined (__clang__) && !defined (__INTEL_COMPILER)
64 #pragma clang system_header
73 #ifdef HAVE_INTREPID2_DEBUG
74 template<
typename subcellBasisType,
75 typename cellBasisType>
78 check_getCoeffMatrix_HDIV(
const subcellBasisType& subcellBasis,
79 const cellBasisType& cellBasis,
80 const ordinal_type subcellId,
81 const ordinal_type subcellOrt) {
82 const shards::CellTopology cellTopo = cellBasis.getBaseCellTopology();
83 const shards::CellTopology subcellTopo = subcellBasis.getBaseCellTopology();
85 const ordinal_type cellDim = cellTopo.getDimension();
86 const ordinal_type subcellDim = subcellTopo.getDimension();
88 INTREPID2_TEST_FOR_EXCEPTION( subcellDim >= cellDim,
90 ">>> ERROR (Intrepid::OrientationTools::getCoeffMatrix_HDIV): " \
91 "cellDim must be greater than subcellDim.");
93 const auto subcellBaseKey = subcellTopo.getBaseKey();
94 const auto cellBaseKey = cellTopo.getBaseKey();
96 INTREPID2_TEST_FOR_EXCEPTION( subcellBaseKey != shards::Line<>::key &&
97 subcellBaseKey != shards::Quadrilateral<>::key &&
98 subcellBaseKey != shards::Triangle<>::key,
100 ">>> ERROR (Intrepid::OrientationTools::getCoeffMatrix_HDIV): " \
101 "subcellBasis must have line, quad, or triangle topology.");
103 INTREPID2_TEST_FOR_EXCEPTION( cellBaseKey != shards::Quadrilateral<>::key &&
104 cellBaseKey != shards::Triangle<>::key &&
105 cellBaseKey != shards::Hexahedron<>::key &&
106 cellBaseKey != shards::Wedge<>::key &&
107 cellBaseKey != shards::Tetrahedron<>::key &&
108 cellBaseKey != shards::Pyramid<>::key,
110 ">>> ERROR (Intrepid::OrientationTools::getCoeffMatrix_HDIV): " \
111 "cellBasis must have quad, triangle, hexhedron or tetrahedron topology.");
117 const bool isHDIV = cellBasis.getFunctionSpace() == FUNCTION_SPACE_HDIV;
118 INTREPID2_TEST_FOR_EXCEPTION( !isHDIV,
120 ">>> ERROR (Intrepid::OrientationTools::getCoeffMatrix_HDIV): "
121 "cellBasis is not HDIV.");
123 const bool subcellBasisIsHGRAD = subcellBasis.getFunctionSpace() == FUNCTION_SPACE_HGRAD;
124 const bool subcellBasisIsHVOL = subcellBasis.getFunctionSpace() == FUNCTION_SPACE_HVOL;
125 const bool cellIsTri = cellBaseKey == shards::Triangle<>::key;
126 const bool cellIsTet = cellBaseKey == shards::Tetrahedron<>::key;
127 const bool cellIsHex = cellBaseKey == shards::Hexahedron<>::key;
128 const bool cellIsQuad = cellBaseKey == shards::Quadrilateral<>::key;
130 switch (subcellDim) {
133 if (cellIsHex || cellIsQuad) {
134 INTREPID2_TEST_FOR_EXCEPTION( !(subcellBasisIsHGRAD||subcellBasisIsHVOL),
136 ">>> ERROR (Intrepid::OrientationTools::getCoeffMatrix_DIV): "
137 "subcellBasis function space (1d) is not consistent to cellBasis, which should be open line hgrad, order -1.");
138 }
else if (cellIsTet || cellIsTri) {
139 INTREPID2_TEST_FOR_EXCEPTION( !subcellBasisIsHVOL,
141 ">>> ERROR (Intrepid::OrientationTools::getCoeffMatrix_DIV): "
142 "subcellBasis function space (1d) is not consistent to cellBasis, which should be HVOL line, order -1.");
147 if (subcellBaseKey == shards::Quadrilateral<>::key) {
149 INTREPID2_TEST_FOR_EXCEPTION( !(subcellBasisIsHGRAD||subcellBasisIsHVOL),
151 ">>> ERROR (Intrepid::OrientationTools::getCoeffMatrix_HDIV): "
152 "subcellBasis function space is not compatible, which should be open line hgrad, order -1.");
153 }
else if (subcellBaseKey == shards::Triangle<>::key) {
155 INTREPID2_TEST_FOR_EXCEPTION( !subcellBasisIsHVOL,
157 ">>> ERROR (Intrepid::OrientationTools::getCoeffMatrix_HDIV): "
158 "subcellBasis function space is not compatible, which should HVOL, order-1.");
169 template<
typename OutputViewType,
170 typename subcellBasisHostType,
171 typename cellBasisHostType>
176 const subcellBasisHostType& subcellBasis,
177 const cellBasisHostType& cellBasis,
178 const ordinal_type subcellId,
179 const ordinal_type subcellOrt,
180 const bool inverse) {
182 #ifdef HAVE_INTREPID2_DEBUG
183 Debug::check_getCoeffMatrix_HDIV(subcellBasis,cellBasis,subcellId,subcellOrt);
186 using value_type =
typename OutputViewType::non_const_value_type;
187 using host_device_type = Kokkos::HostSpace::device_type;
192 const shards::CellTopology cellTopo = cellBasis.getBaseCellTopology();
193 const shards::CellTopology subcellTopo = subcellBasis.getBaseCellTopology();
194 const ordinal_type cellDim = cellTopo.getDimension();
195 const ordinal_type subcellDim = subcellTopo.getDimension();
196 const auto subcellBaseKey = subcellTopo.getBaseKey();
197 const ordinal_type numCellBasis = cellBasis.getCardinality();
198 const ordinal_type numSubcellBasis = subcellBasis.getCardinality();
199 const ordinal_type ndofSubcell = cellBasis.getDofCount(subcellDim,subcellId);
206 auto latticeDegree = (subcellBaseKey == shards::Triangle<>::key) ?
207 cellBasis.getDegree()+2 : cellBasis.getDegree()+1;
210 Kokkos::DynRankView<value_type,host_device_type> refPtsSubcell(
"refPtsSubcell", ndofSubcell, subcellDim);
212 INTREPID2_TEST_FOR_EXCEPTION( latticeSize != ndofSubcell,
214 ">>> ERROR (Intrepid::OrientationTools::getCoeffMatrix_HDIV): " \
215 "Lattice size should be equal to the onber of subcell internal DoFs");
222 Kokkos::DynRankView<value_type,host_device_type> refPtsCell(
"refPtsCell", ndofSubcell, cellDim);
227 Kokkos::DynRankView<value_type,host_device_type> tangentsAndNormal(
"trJacobianF", cellDim, cellDim );
229 auto sideNormal = Kokkos::subview(tangentsAndNormal, cellDim-1, Kokkos::ALL());
237 Kokkos::DynRankView<value_type,host_device_type> cellBasisValues(
"cellBasisValues", numCellBasis, ndofSubcell, cellDim);
238 cellBasis.getValues(cellBasisValues, refPtsCell, OPERATOR_VALUE);
241 Kokkos::DynRankView<value_type,host_device_type> subCellValues(
"subCellValues", numSubcellBasis, ndofSubcell);
242 subcellBasis.getValues(subCellValues, refPtsSubcell, OPERATOR_VALUE);
251 Kokkos::DynRankView<value_type,Kokkos::LayoutLeft,host_device_type>
252 PsiMat(
"PsiMat", ndofSubcell, ndofSubcell),
253 PhiMat(
"PhiMat", ndofSubcell, ndofSubcell),
257 auto cellTagToOrdinal = cellBasis.getAllDofOrdinal();
258 auto subcellTagToOrdinal = subcellBasis.getAllDofOrdinal();
260 for (ordinal_type i=0;i<ndofSubcell;++i) {
261 const ordinal_type ic = cellTagToOrdinal(subcellDim, subcellId, i);
262 const ordinal_type isc = subcellTagToOrdinal(subcellDim, 0, i);
263 for (ordinal_type j=0;j<ndofSubcell;++j) {
264 PhiMat(j,i) = get_scalar_value(subCellValues(isc,j));
265 for (ordinal_type k=0;k<cellDim;++k)
266 PsiMat(j,i) += get_scalar_value(cellBasisValues(ic,j,k))*sideNormal(k);
270 RefMat = inverse ? PhiMat : PsiMat;
271 OrtMat = inverse ? PsiMat : PhiMat;
275 Teuchos::LAPACK<ordinal_type,value_type> lapack;
276 ordinal_type info = 0;
277 Kokkos::DynRankView<ordinal_type,host_device_type> pivVec(
"pivVec", ndofSubcell);
279 lapack.GESV(ndofSubcell, ndofSubcell,
288 std::stringstream ss;
289 ss <<
">>> ERROR (Intrepid::OrientationTools::getCoeffMatrix_HDIV): "
290 <<
"LAPACK return with error code: "
292 INTREPID2_TEST_FOR_EXCEPTION(
true, std::runtime_error, ss.str().c_str() );
298 const double eps = tolerence();
299 for (ordinal_type i=0;i<ndofSubcell;++i) {
300 auto intmatii = std::round(OrtMat(i,i));
301 OrtMat(i,i) = (std::abs(OrtMat(i,i) - intmatii) < eps) ? intmatii : OrtMat(i,i);
302 for (ordinal_type j=i+1;j<ndofSubcell;++j) {
303 auto matij = OrtMat(i,j);
305 auto intmatji = std::round(OrtMat(j,i));
306 OrtMat(i,j) = (std::abs(OrtMat(j,i) - intmatji) < eps) ? intmatji : OrtMat(j,i);
308 auto intmatij = std::round(matij);
309 OrtMat(j,i) = (std::abs(matij - intmatij) < eps) ? intmatij : matij;
331 const Kokkos::pair<ordinal_type,ordinal_type> range(0, ndofSubcell);
332 auto suboutput = Kokkos::subview(output, range, range);
333 auto tmp = Kokkos::create_mirror_view_and_copy(
typename OutputViewType::device_type::memory_space(), OrtMat);
334 Kokkos::deep_copy(suboutput, tmp);
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...