15 #ifndef __INTREPID2_ORIENTATIONTOOLS_DEF_MODIFY_BASIS_HPP__
16 #define __INTREPID2_ORIENTATIONTOOLS_DEF_MODIFY_BASIS_HPP__
19 #if defined (__clang__) && !defined (__INTEL_COMPILER)
20 #pragma clang system_header
28 template<
typename elemOrtValueType,
class ...elemOrtProperties,
29 typename elemNodeValueType,
class ...elemNodeProperties>
32 getOrientation( Kokkos::DynRankView<elemOrtValueType,elemOrtProperties...> elemOrts,
33 const Kokkos::DynRankView<elemNodeValueType,elemNodeProperties...> elemNodes,
34 const shards::CellTopology cellTopo,
37 auto elemOrtsHost = Kokkos::create_mirror_view(elemOrts);
38 auto elemNodesHost = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), elemNodes);
40 const ordinal_type numCells = elemNodes.extent(0);
41 for (
auto cell=0;cell<numCells;++cell) {
42 const auto nodes = Kokkos::subview(elemNodesHost, cell, Kokkos::ALL());
43 elemOrtsHost(cell) = Orientation::getOrientation(cellTopo, nodes, isSide);
46 Kokkos::deep_copy(elemOrts, elemOrtsHost);
49 template<
typename ortViewType,
50 typename OutputViewType,
51 typename inputViewType,
54 typename dataViewType>
57 OutputViewType output;
59 o2tViewType ordinalToTag;
60 t2oViewType tagToOrdinal;
62 const dataViewType matData;
63 const ordinal_type cellDim, numVerts, numEdges, numFaces, numPoints, dimBasis;
64 const bool leftMultiply;
70 OutputViewType output_,
72 o2tViewType ordinalToTag_,
73 t2oViewType tagToOrdinal_,
74 const dataViewType matData_,
75 const ordinal_type cellDim_,
76 const ordinal_type numVerts_,
77 const ordinal_type numEdges_,
78 const ordinal_type numFaces_,
79 const ordinal_type numPoints_,
80 const ordinal_type dimBasis_,
81 const bool leftMultiply_ =
true,
82 const bool transpose_ =
false)
86 ordinalToTag(ordinalToTag_),
87 tagToOrdinal(tagToOrdinal_),
93 numPoints(numPoints_),
95 leftMultiply(leftMultiply_),
99 KOKKOS_INLINE_FUNCTION
100 void operator()(
const ordinal_type cell)
const {
101 typedef typename inputViewType::non_const_value_type input_value_type;
103 auto out = Kokkos::subview(output, cell, Kokkos::ALL(), Kokkos::ALL(), Kokkos::ALL());
104 auto in = (input.rank() == output.rank()) ?
105 Kokkos::subview(input, cell, Kokkos::ALL(), Kokkos::ALL(), Kokkos::ALL())
106 : Kokkos::subview(input, Kokkos::ALL(), Kokkos::ALL(), Kokkos::ALL());
109 ordinal_type existEdgeDofs = 0;
111 ordinal_type ortEdges[12];
112 orts(cell).getEdgeOrientation(ortEdges, numEdges);
115 for (ordinal_type edgeId=0;edgeId<numEdges;++edgeId) {
116 const ordinal_type ordEdge = (1 < tagToOrdinal.extent(0) ? (
static_cast<size_type
>(edgeId) < tagToOrdinal.extent(1) ? tagToOrdinal(1, edgeId, 0) : -1) : -1);
120 const ordinal_type ndofEdge = ordinalToTag(ordEdge, 3);
121 const auto mat = Kokkos::subview(matData,
122 edgeId, ortEdges[edgeId],
123 Kokkos::ALL(), Kokkos::ALL());
125 for (ordinal_type j=0;j<numPoints;++j)
126 for (ordinal_type i=0;i<ndofEdge;++i) {
127 const ordinal_type ii = tagToOrdinal(1, edgeId, i);
129 for (ordinal_type k=0;k<dimBasis;++k) {
130 input_value_type temp = 0.0;
131 for (ordinal_type l=0;l<ndofEdge;++l) {
132 const ordinal_type ll = tagToOrdinal(1, edgeId, l);
133 auto & input_ = leftMultiply ? in(ll, j, k) : in(j, ll, k);
134 auto & mat_il = transpose ? mat(l,i) : mat(i,l);
135 temp += mat_il*input_;
137 auto & output_ = leftMultiply ? out(ii, j, k) : out(j, ii, k);
147 ordinal_type ortFaces[12];
148 orts(cell).getFaceOrientation(ortFaces, numFaces);
151 for (ordinal_type faceId=0;faceId<numFaces;++faceId) {
152 const ordinal_type ordFace = (2 < tagToOrdinal.extent(0) ? (
static_cast<size_type
>(faceId) < tagToOrdinal.extent(1) ? tagToOrdinal(2, faceId, 0) : -1) : -1);
155 const ordinal_type ndofFace = ordinalToTag(ordFace, 3);
156 const auto mat = Kokkos::subview(matData,
157 numEdges*existEdgeDofs+faceId, ortFaces[faceId],
158 Kokkos::ALL(), Kokkos::ALL());
160 for (ordinal_type j=0;j<numPoints;++j)
161 for (ordinal_type i=0;i<ndofFace;++i) {
162 const ordinal_type ii = tagToOrdinal(2, faceId, i);
164 for (ordinal_type k=0;k<dimBasis;++k) {
165 input_value_type temp = 0.0;
166 for (ordinal_type l=0;l<ndofFace;++l) {
167 const ordinal_type ll = tagToOrdinal(2, faceId, l);
168 auto & input_ = leftMultiply ? in(ll, j, k) : in(j, ll, k);
169 auto & mat_il = transpose ? mat(l,i) : mat(i,l);
170 temp += mat_il*input_;
173 auto & output_ = leftMultiply ? out(ii, j, k) : out(j, ii, k);
182 ordinal_type faceOrt(0), edgeOrt(0);
183 if(cellDim == 2) orts(cell).getFaceOrientation(&faceOrt, 1);
185 const ordinal_type ordFace = (2 < tagToOrdinal.extent(0) ? (
static_cast<size_type
>(0) < tagToOrdinal.extent(1) ? tagToOrdinal(2, 0, 0) : -1) : -1);
188 const ordinal_type ndofFace = ordinalToTag(ordFace, 3);
189 const auto mat = Kokkos::subview(matData,
190 numEdges*existEdgeDofs, faceOrt,
191 Kokkos::ALL(), Kokkos::ALL());
193 for (ordinal_type j=0;j<numPoints;++j)
194 for (ordinal_type i=0;i<ndofFace;++i) {
195 const ordinal_type ii = tagToOrdinal(2, 0, i);
197 for (ordinal_type k=0;k<dimBasis;++k) {
198 input_value_type temp = 0.0;
199 for (ordinal_type l=0;l<ndofFace;++l) {
200 const ordinal_type ll = tagToOrdinal(2, 0, l);
201 auto & input_ = leftMultiply ? in(ll, j, k) : in(j, ll, k);
202 auto & mat_il = transpose ? mat(l,i) : mat(i,l);
203 temp += mat_il*input_;
205 auto & output_ = leftMultiply ? out(ii, j, k) : out(j, ii, k);
212 if(cellDim == 1) orts(cell).getEdgeOrientation(&edgeOrt, 1);
214 const ordinal_type ordEdge = (1 < tagToOrdinal.extent(0) ? (
static_cast<size_type
>(0) < tagToOrdinal.extent(1) ? tagToOrdinal(1, 0, 0) : -1) : -1);
217 const ordinal_type ndofEdge = ordinalToTag(ordEdge, 3);
218 const auto mat = Kokkos::subview(matData,
220 Kokkos::ALL(), Kokkos::ALL());
222 for (ordinal_type j=0;j<numPoints;++j)
223 for (ordinal_type i=0;i<ndofEdge;++i) {
224 const ordinal_type ii = tagToOrdinal(1, 0, i);
226 for (ordinal_type k=0;k<dimBasis;++k) {
227 input_value_type temp = 0.0;
228 for (ordinal_type l=0;l<ndofEdge;++l) {
229 const ordinal_type ll = tagToOrdinal(1, 0, l);
230 auto & input_ = leftMultiply ? in(ll, j, k) : in(j, ll, k);
231 auto & mat_il = transpose ? mat(l,i) : mat(i,l);
232 temp += mat_il*input_;
234 auto & output_ = leftMultiply ? out(ii, j, k) : out(j, ii, k);
243 template<
typename DT>
244 template<
typename outputValueType,
class ...outputProperties,
245 typename inputValueType,
class ...inputProperties,
246 typename OrientationViewType,
251 const Kokkos::DynRankView<inputValueType, inputProperties...> input,
252 const OrientationViewType orts,
253 const BasisType* basis,
254 const bool transpose) {
255 #ifdef HAVE_INTREPID2_DEBUG
257 if (input.rank() == output.rank())
259 for (size_type i=0;i<input.rank();++i)
260 INTREPID2_TEST_FOR_EXCEPTION( input.extent(i) != output.extent(i), std::invalid_argument,
261 ">>> ERROR (OrientationTools::modifyBasisByOrientation): Input and output dimensions do not match.");
263 else if (input.rank() == output.rank() - 1)
265 for (size_type i=0;i<input.rank();++i)
266 INTREPID2_TEST_FOR_EXCEPTION( input.extent(i) != output.extent(i+1), std::invalid_argument,
267 ">>> ERROR (OrientationTools::modifyBasisByOrientation): Input dimensions must match output dimensions exactly, or else match all but the first dimension (in the case that input does not have a 'cell' dimension).");
271 INTREPID2_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
272 ">>> ERROR (OrientationTools::modifyBasisByOrientation): input and output ranks must either match, or input rank must be one less than that of output.")
275 INTREPID2_TEST_FOR_EXCEPTION( static_cast<ordinal_type>(output.extent(1)) != basis->getCardinality(), std::invalid_argument,
276 ">>> ERROR (OrientationTools::modifyBasisByOrientation): Field dimension of input/output does not match to basis cardinality.");
280 const shards::CellTopology cellTopo = basis->getBaseCellTopology();
281 const ordinal_type cellDim = cellTopo.getDimension();
284 if(input.rank() == output.rank())
285 Kokkos::deep_copy(output, input);
289 if ((cellDim < 3) || basis->requireOrientation()) {
290 auto ordinalToTag = Kokkos::create_mirror_view_and_copy(
typename DT::memory_space(), basis->getAllDofTags());
291 auto tagToOrdinal = Kokkos::create_mirror_view_and_copy(
typename DT::memory_space(), basis->getAllDofOrdinal());
294 numCells = output.extent(0),
296 numPoints = output.extent(2),
297 dimBasis = output.extent(3);
301 ordinal_type numVerts(0), numEdges(0), numFaces(0);
303 if (basis->requireOrientation()) {
304 numVerts = cellTopo.getVertexCount()*ordinal_type(basis->getDofCount(0, 0) > 0);
305 numEdges = cellTopo.getEdgeCount()*ordinal_type(basis->getDofCount(1, 0) > 0);
306 numFaces = cellTopo.getFaceCount()*ordinal_type(basis->getDofCount(2, 0) > 0);
309 bool leftMultiply =
true;
311 const Kokkos::RangePolicy<typename DT::execution_space> policy(0, numCells);
314 decltype(output),decltype(input),
315 decltype(ordinalToTag),decltype(tagToOrdinal),
316 decltype(matData)> FunctorType;
321 ordinalToTag, tagToOrdinal,
323 cellDim, numVerts, numEdges, numFaces,
324 numPoints, dimBasis, leftMultiply, transpose));
328 template<
typename DT>
329 template<
typename outputValueType,
class ...outputProperties,
330 typename inputValueType,
class ...inputProperties,
331 typename OrientationViewType,
336 const Kokkos::DynRankView<inputValueType, inputProperties...> input,
337 const OrientationViewType orts,
338 const BasisType* basis ) {
339 bool transpose =
true;
340 modifyBasisByOrientation(output, input, orts, basis, transpose);
343 template<
typename DT>
344 template<
typename outputValueType,
class ...outputProperties,
345 typename inputValueType,
class ...inputProperties,
346 typename OrientationViewType,
351 const Kokkos::DynRankView<inputValueType, inputProperties...> input,
352 const OrientationViewType orts,
353 const BasisType* basis,
354 const bool transpose ) {
355 #ifdef HAVE_INTREPID2_DEBUG
357 if (input.rank() == output.rank())
359 for (size_type i=0;i<input.rank();++i)
360 INTREPID2_TEST_FOR_EXCEPTION( input.extent(i) != output.extent(i), std::invalid_argument,
361 ">>> ERROR (OrientationTools::modifyBasisByOrientation): Input and output dimensions do not match.");
363 else if (input.rank() == output.rank() - 1)
365 for (size_type i=0;i<input.rank();++i)
366 INTREPID2_TEST_FOR_EXCEPTION( input.extent(i) != output.extent(i+1), std::invalid_argument,
367 ">>> ERROR (OrientationTools::modifyBasisByOrientation): Input dimensions must match output dimensions exactly, or else match all but the first dimension (in the case that input does not have a 'cell' dimension).");
371 INTREPID2_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
372 ">>> ERROR (OrientationTools::modifyBasisByOrientation): input and output ranks must either match, or input rank must be one less than that of output.")
375 INTREPID2_TEST_FOR_EXCEPTION( static_cast<ordinal_type>(output.extent(1)) != basis->getCardinality(), std::invalid_argument,
376 ">>> ERROR (OrientationTools::modifyBasisByOrientation): Field dimension of input/output does not match to basis cardinality.");
380 const shards::CellTopology cellTopo = basis->getBaseCellTopology();
381 const ordinal_type cellDim = cellTopo.getDimension();
384 if(input.rank() == output.rank())
385 Kokkos::deep_copy(output, input);
389 if ((cellDim < 3) || basis->requireOrientation()) {
390 auto ordinalToTag = Kokkos::create_mirror_view_and_copy(
typename DT::memory_space(), basis->getAllDofTags());
391 auto tagToOrdinal = Kokkos::create_mirror_view_and_copy(
typename DT::memory_space(), basis->getAllDofOrdinal());
394 numCells = output.extent(0),
396 numPoints = output.extent(2),
397 dimBasis = output.extent(3);
401 ordinal_type numVerts(0), numEdges(0), numFaces(0);
403 if (basis->requireOrientation()) {
404 numVerts = cellTopo.getVertexCount()*ordinal_type(basis->getDofCount(0, 0) > 0);
405 numEdges = cellTopo.getEdgeCount()*ordinal_type(basis->getDofCount(1, 0) > 0);
406 numFaces = cellTopo.getFaceCount()*ordinal_type(basis->getDofCount(2, 0) > 0);
409 bool leftMultiply =
true;
411 const Kokkos::RangePolicy<typename DT::execution_space> policy(0, numCells);
414 decltype(output),decltype(input),
415 decltype(ordinalToTag),decltype(tagToOrdinal),
416 decltype(matData)> FunctorType;
421 ordinalToTag, tagToOrdinal,
423 cellDim, numVerts, numEdges, numFaces,
424 numPoints, dimBasis, leftMultiply, transpose));
428 template<
typename DT>
429 template<
typename outputValueType,
class ...outputProperties,
430 typename inputValueType,
class ...inputProperties,
431 typename OrientationViewType,
432 typename BasisTypeLeft,
433 typename BasisTypeRight>
437 const Kokkos::DynRankView<inputValueType, inputProperties...> input,
438 const OrientationViewType orts,
439 const BasisTypeLeft* basisLeft,
440 const BasisTypeRight* basisRight)
442 const ordinal_type numCells = output.extent(0);
443 const ordinal_type numFieldsLeft = basisLeft->getCardinality();
444 const ordinal_type numFieldsRight = basisRight->getCardinality();
445 #ifdef HAVE_INTREPID2_DEBUG
447 if (input.rank() == output.rank())
449 for (size_type i=0;i<input.rank();++i)
450 INTREPID2_TEST_FOR_EXCEPTION( input.extent(i) != output.extent(i), std::invalid_argument,
451 ">>> ERROR (OrientationTools::modifyMatrixByOrientation): Input and output dimensions do not match.");
453 else if (input.rank() == output.rank() - 1)
455 for (size_type i=0;i<input.rank();++i)
456 INTREPID2_TEST_FOR_EXCEPTION( input.extent(i) != output.extent(i+1), std::invalid_argument,
457 ">>> ERROR (OrientationTools::modifyMatrixByOrientation): Input dimensions must match output dimensions exactly, or else match all but the first dimension (in the case that input does not have a 'cell' dimension).");
461 INTREPID2_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
462 ">>> ERROR (OrientationTools::modifyMatrixByOrientation): input and output ranks must either match, or input rank must be one less than that of output.")
465 INTREPID2_TEST_FOR_EXCEPTION( static_cast<ordinal_type>(output.extent(1)) != numFieldsLeft, std::invalid_argument,
466 ">>> ERROR (OrientationTools::modifyMatrixByOrientation): First field dimension of input/output does not match left basis cardinality.");
467 INTREPID2_TEST_FOR_EXCEPTION( static_cast<ordinal_type>(output.extent(2)) != numFieldsRight, std::invalid_argument,
468 ">>> ERROR (OrientationTools::modifyMatrixByOrientation): Second field dimension of input/output does not match right basis cardinality.");
469 INTREPID2_TEST_FOR_EXCEPTION( static_cast<ordinal_type>(output.extent(3)) != 1, std::invalid_argument,
470 ">>> ERROR (OrientationTools::modifyMatrixByOrientation): Third dimension of output must be 1.");
474 const shards::CellTopology cellTopo = basisLeft->getBaseCellTopology();
475 const ordinal_type cellDim = cellTopo.getDimension();
478 decltype(output) outputLeft(
"temp view - output from left application", numCells, numFieldsLeft, numFieldsRight);
481 if(input.rank() == output.rank())
482 Kokkos::deep_copy(outputLeft, input);
486 if ((cellDim < 3) || basisLeft->requireOrientation()) {
487 bool leftMultiply =
true;
488 auto ordinalToTag = Kokkos::create_mirror_view_and_copy(
typename DT::memory_space(), basisLeft->getAllDofTags());
489 auto tagToOrdinal = Kokkos::create_mirror_view_and_copy(
typename DT::memory_space(), basisLeft->getAllDofOrdinal());
492 numOtherFields = output.extent(2),
493 dimBasis = output.extent(3);
497 ordinal_type numVerts(0), numEdges(0), numFaces(0);
499 if (basisLeft->requireOrientation()) {
500 numVerts = cellTopo.getVertexCount()*ordinal_type(basisLeft->getDofCount(0, 0) > 0);
501 numEdges = cellTopo.getEdgeCount()*ordinal_type(basisLeft->getDofCount(1, 0) > 0);
502 numFaces = cellTopo.getFaceCount()*ordinal_type(basisLeft->getDofCount(2, 0) > 0);
505 const Kokkos::RangePolicy<typename DT::execution_space> policy(0, numCells);
508 decltype(outputLeft),decltype(input),
509 decltype(ordinalToTag),decltype(tagToOrdinal),
510 decltype(matData)> FunctorType;
515 ordinalToTag, tagToOrdinal,
517 cellDim, numVerts, numEdges, numFaces,
518 numOtherFields, dimBasis, leftMultiply));
523 Kokkos::deep_copy(output, outputLeft);
524 if ((cellDim < 3) || basisRight->requireOrientation()) {
525 bool leftMultiply =
false;
526 auto ordinalToTag = Kokkos::create_mirror_view_and_copy(
typename DT::memory_space(), basisRight->getAllDofTags());
527 auto tagToOrdinal = Kokkos::create_mirror_view_and_copy(
typename DT::memory_space(), basisRight->getAllDofOrdinal());
530 numOtherFields = output.extent(1),
531 dimBasis = output.extent(3);
535 ordinal_type numVerts(0), numEdges(0), numFaces(0);
537 if (basisRight->requireOrientation()) {
538 numVerts = cellTopo.getVertexCount()*ordinal_type(basisRight->getDofCount(0, 0) > 0);
539 numEdges = cellTopo.getEdgeCount()*ordinal_type(basisRight->getDofCount(1, 0) > 0);
540 numFaces = cellTopo.getFaceCount()*ordinal_type(basisRight->getDofCount(2, 0) > 0);
543 const Kokkos::RangePolicy<typename DT::execution_space> policy(0, numCells);
546 decltype(output),decltype(outputLeft),
547 decltype(ordinalToTag),decltype(tagToOrdinal),
548 decltype(matData)> FunctorType;
553 ordinalToTag, tagToOrdinal,
555 cellDim, numVerts, numEdges, numFaces,
556 numOtherFields, dimBasis, leftMultiply));
Header file for the Intrepid2::Orientation class.