26 #ifndef __INTREPID2_ORIENTATIONTOOLS_DEF_COEFF_MATRIX_HDIV_HPP__
27 #define __INTREPID2_ORIENTATIONTOOLS_DEF_COEFF_MATRIX_HDIV_HPP__
30 #if defined (__clang__) && !defined (__INTEL_COMPILER)
31 #pragma clang system_header
40 #ifdef HAVE_INTREPID2_DEBUG
41 template<
typename subcellBasisType,
42 typename cellBasisType>
45 check_getCoeffMatrix_HDIV(
const subcellBasisType& subcellBasis,
46 const cellBasisType& cellBasis,
47 const ordinal_type subcellId,
48 const ordinal_type subcellOrt) {
49 const shards::CellTopology cellTopo = cellBasis.getBaseCellTopology();
50 const shards::CellTopology subcellTopo = subcellBasis.getBaseCellTopology();
52 const ordinal_type cellDim = cellTopo.getDimension();
53 const ordinal_type subcellDim = subcellTopo.getDimension();
55 INTREPID2_TEST_FOR_EXCEPTION( subcellDim >= cellDim,
57 ">>> ERROR (Intrepid::OrientationTools::getCoeffMatrix_HDIV): " \
58 "cellDim must be greater than subcellDim.");
60 const auto subcellBaseKey = subcellTopo.getBaseKey();
61 const auto cellBaseKey = cellTopo.getBaseKey();
63 INTREPID2_TEST_FOR_EXCEPTION( subcellBaseKey != shards::Line<>::key &&
64 subcellBaseKey != shards::Quadrilateral<>::key &&
65 subcellBaseKey != shards::Triangle<>::key,
67 ">>> ERROR (Intrepid::OrientationTools::getCoeffMatrix_HDIV): " \
68 "subcellBasis must have line, quad, or triangle topology.");
70 INTREPID2_TEST_FOR_EXCEPTION( cellBaseKey != shards::Quadrilateral<>::key &&
71 cellBaseKey != shards::Triangle<>::key &&
72 cellBaseKey != shards::Hexahedron<>::key &&
73 cellBaseKey != shards::Wedge<>::key &&
74 cellBaseKey != shards::Tetrahedron<>::key &&
75 cellBaseKey != shards::Pyramid<>::key,
77 ">>> ERROR (Intrepid::OrientationTools::getCoeffMatrix_HDIV): " \
78 "cellBasis must have quad, triangle, hexhedron or tetrahedron topology.");
84 const bool isHDIV = cellBasis.getFunctionSpace() == FUNCTION_SPACE_HDIV;
85 INTREPID2_TEST_FOR_EXCEPTION( !isHDIV,
87 ">>> ERROR (Intrepid::OrientationTools::getCoeffMatrix_HDIV): "
88 "cellBasis is not HDIV.");
90 const bool subcellBasisIsHGRAD = subcellBasis.getFunctionSpace() == FUNCTION_SPACE_HGRAD;
91 const bool subcellBasisIsHVOL = subcellBasis.getFunctionSpace() == FUNCTION_SPACE_HVOL;
92 const bool cellIsTri = cellBaseKey == shards::Triangle<>::key;
93 const bool cellIsTet = cellBaseKey == shards::Tetrahedron<>::key;
94 const bool cellIsHex = cellBaseKey == shards::Hexahedron<>::key;
95 const bool cellIsQuad = cellBaseKey == shards::Quadrilateral<>::key;
100 if (cellIsHex || cellIsQuad) {
101 INTREPID2_TEST_FOR_EXCEPTION( !(subcellBasisIsHGRAD||subcellBasisIsHVOL),
103 ">>> ERROR (Intrepid::OrientationTools::getCoeffMatrix_DIV): "
104 "subcellBasis function space (1d) is not consistent to cellBasis, which should be open line hgrad, order -1.");
105 }
else if (cellIsTet || cellIsTri) {
106 INTREPID2_TEST_FOR_EXCEPTION( !subcellBasisIsHVOL,
108 ">>> ERROR (Intrepid::OrientationTools::getCoeffMatrix_DIV): "
109 "subcellBasis function space (1d) is not consistent to cellBasis, which should be HVOL line, order -1.");
114 if (subcellBaseKey == shards::Quadrilateral<>::key) {
116 INTREPID2_TEST_FOR_EXCEPTION( !(subcellBasisIsHGRAD||subcellBasisIsHVOL),
118 ">>> ERROR (Intrepid::OrientationTools::getCoeffMatrix_HDIV): "
119 "subcellBasis function space is not compatible, which should be open line hgrad, order -1.");
120 }
else if (subcellBaseKey == shards::Triangle<>::key) {
122 INTREPID2_TEST_FOR_EXCEPTION( !subcellBasisIsHVOL,
124 ">>> ERROR (Intrepid::OrientationTools::getCoeffMatrix_HDIV): "
125 "subcellBasis function space is not compatible, which should HVOL, order-1.");
136 template<
typename OutputViewType,
137 typename subcellBasisHostType,
138 typename cellBasisHostType>
143 const subcellBasisHostType& subcellBasis,
144 const cellBasisHostType& cellBasis,
145 const ordinal_type subcellId,
146 const ordinal_type subcellOrt,
147 const bool inverse) {
149 #ifdef HAVE_INTREPID2_DEBUG
150 Debug::check_getCoeffMatrix_HDIV(subcellBasis,cellBasis,subcellId,subcellOrt);
153 using value_type =
typename OutputViewType::non_const_value_type;
154 using host_device_type = Kokkos::HostSpace::device_type;
159 const shards::CellTopology cellTopo = cellBasis.getBaseCellTopology();
160 const shards::CellTopology subcellTopo = subcellBasis.getBaseCellTopology();
161 const ordinal_type cellDim = cellTopo.getDimension();
162 const ordinal_type subcellDim = subcellTopo.getDimension();
163 const auto subcellBaseKey = subcellTopo.getBaseKey();
164 const ordinal_type numCellBasis = cellBasis.getCardinality();
165 const ordinal_type numSubcellBasis = subcellBasis.getCardinality();
166 const ordinal_type ndofSubcell = cellBasis.getDofCount(subcellDim,subcellId);
173 auto latticeDegree = (subcellBaseKey == shards::Triangle<>::key) ?
174 cellBasis.getDegree()+2 : cellBasis.getDegree()+1;
177 Kokkos::DynRankView<value_type,host_device_type> refPtsSubcell(
"refPtsSubcell", ndofSubcell, subcellDim);
179 INTREPID2_TEST_FOR_EXCEPTION( latticeSize != ndofSubcell,
181 ">>> ERROR (Intrepid::OrientationTools::getCoeffMatrix_HDIV): " \
182 "Lattice size should be equal to the onber of subcell internal DoFs");
189 Kokkos::DynRankView<value_type,host_device_type> refPtsCell(
"refPtsCell", ndofSubcell, cellDim);
194 Kokkos::DynRankView<value_type,host_device_type> tangentsAndNormal(
"trJacobianF", cellDim, cellDim );
196 auto sideNormal = Kokkos::subview(tangentsAndNormal, cellDim-1, Kokkos::ALL());
204 Kokkos::DynRankView<value_type,host_device_type> cellBasisValues(
"cellBasisValues", numCellBasis, ndofSubcell, cellDim);
205 cellBasis.getValues(cellBasisValues, refPtsCell, OPERATOR_VALUE);
208 Kokkos::DynRankView<value_type,host_device_type> subCellValues(
"subCellValues", numSubcellBasis, ndofSubcell);
209 subcellBasis.getValues(subCellValues, refPtsSubcell, OPERATOR_VALUE);
218 Kokkos::DynRankView<value_type,Kokkos::LayoutLeft,host_device_type>
219 PsiMat(
"PsiMat", ndofSubcell, ndofSubcell),
220 PhiMat(
"PhiMat", ndofSubcell, ndofSubcell),
224 auto cellTagToOrdinal = cellBasis.getAllDofOrdinal();
225 auto subcellTagToOrdinal = subcellBasis.getAllDofOrdinal();
227 for (ordinal_type i=0;i<ndofSubcell;++i) {
228 const ordinal_type ic = cellTagToOrdinal(subcellDim, subcellId, i);
229 const ordinal_type isc = subcellTagToOrdinal(subcellDim, 0, i);
230 for (ordinal_type j=0;j<ndofSubcell;++j) {
231 PhiMat(j,i) = get_scalar_value(subCellValues(isc,j));
232 for (ordinal_type k=0;k<cellDim;++k)
233 PsiMat(j,i) += get_scalar_value(cellBasisValues(ic,j,k))*sideNormal(k);
237 RefMat = inverse ? PhiMat : PsiMat;
238 OrtMat = inverse ? PsiMat : PhiMat;
242 Teuchos::LAPACK<ordinal_type,value_type> lapack;
243 ordinal_type info = 0;
244 Kokkos::DynRankView<ordinal_type,host_device_type> pivVec(
"pivVec", ndofSubcell);
246 lapack.GESV(ndofSubcell, ndofSubcell,
255 std::stringstream ss;
256 ss <<
">>> ERROR (Intrepid::OrientationTools::getCoeffMatrix_HDIV): "
257 <<
"LAPACK return with error code: "
259 INTREPID2_TEST_FOR_EXCEPTION(
true, std::runtime_error, ss.str().c_str() );
265 const double eps = tolerence();
266 for (ordinal_type i=0;i<ndofSubcell;++i) {
267 auto intmatii = std::round(OrtMat(i,i));
268 OrtMat(i,i) = (std::abs(OrtMat(i,i) - intmatii) < eps) ? intmatii : OrtMat(i,i);
269 for (ordinal_type j=i+1;j<ndofSubcell;++j) {
270 auto matij = OrtMat(i,j);
272 auto intmatji = std::round(OrtMat(j,i));
273 OrtMat(i,j) = (std::abs(OrtMat(j,i) - intmatji) < eps) ? intmatji : OrtMat(j,i);
275 auto intmatij = std::round(matij);
276 OrtMat(j,i) = (std::abs(matij - intmatij) < eps) ? intmatij : matij;
298 const Kokkos::pair<ordinal_type,ordinal_type> range(0, ndofSubcell);
299 auto suboutput = Kokkos::subview(output, range, range);
300 auto tmp = Kokkos::create_mirror_view_and_copy(
typename OutputViewType::device_type::memory_space(), OrtMat);
301 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...