16#ifndef __INTREPID2_HCURL_TET_IN_FEM_DEF_HPP__
17#define __INTREPID2_HCURL_TET_IN_FEM_DEF_HPP__
21#include "Teuchos_SerialDenseMatrix.hpp"
29template<EOperator OpType>
30template<
typename OutputViewType,
31typename InputViewType,
38 const InputViewType input,
40 const VinvViewType coeffs ) {
42 constexpr ordinal_type spaceDim = 3;
44 cardPn = coeffs.extent(0)/spaceDim,
45 card = coeffs.extent(1),
46 npts = input.extent(0);
49 ordinal_type order = 0;
51 if (card == CardinalityHCurlTet(p)) {
57 typedef typename Kokkos::DynRankView<typename InputViewType::value_type, typename WorkViewType::memory_space> ViewType;
58 auto ptr = work.data();
61 case OPERATOR_VALUE: {
65 Impl::Basis_HGRAD_TET_Cn_FEM_ORTH::
66 Serial<OpType>::getValues(phis, input, dummyView, order);
68 for (ordinal_type i=0;i<card;++i)
69 for (ordinal_type j=0;j<npts;++j)
70 for (ordinal_type d=0;d<spaceDim;++d) {
71 output.access(i,j,d) = 0.0;
72 for (ordinal_type k=0;k<cardPn;++k)
73 output.access(i,j,d) += coeffs(k+d*cardPn,i) * phis(k,j);
79 ptr += card*npts*spaceDim*get_dimension_scalar(input);
82 Impl::Basis_HGRAD_TET_Cn_FEM_ORTH::
83 Serial<OPERATOR_GRAD>::getValues(phis, input, workView, order);
85 for (ordinal_type i=0;i<card;++i) {
86 for (ordinal_type j=0;j<npts;++j) {
87 for (ordinal_type d=0; d< spaceDim; ++d) {
88 output.access(i,j,d) = 0.0;
89 ordinal_type d1 = (d+1) % spaceDim, d2 = (d+2) % spaceDim;
90 for (ordinal_type k=0; k<cardPn; ++k)
91 output.access(i,j,d) += coeffs(k+d2*cardPn,i)*phis(k,j,d1)
92 -coeffs(k+d1*cardPn,i)*phis(k,j,d2);
99 INTREPID2_TEST_FOR_ABORT(
true,
100 ">>> ERROR (Basis_HCURL_TET_In_FEM): Operator type not implemented");
105template<
typename DT, ordinal_type numPtsPerEval,
106typename outputValueValueType,
class ...outputValueProperties,
107typename inputPointValueType,
class ...inputPointProperties,
108typename vinvValueType,
class ...vinvProperties>
110Basis_HCURL_TET_In_FEM::
112 const typename DT::execution_space& space,
113 Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValues,
114 const Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPoints,
115 const Kokkos::DynRankView<vinvValueType, vinvProperties...> coeffs,
116 const EOperator operatorType) {
117 typedef Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValueViewType;
118 typedef Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPointViewType;
119 typedef Kokkos::DynRankView<vinvValueType, vinvProperties...> vinvViewType;
120 typedef typename ExecSpace<typename inputPointViewType::execution_space,typename DT::execution_space>::ExecSpaceType ExecSpaceType;
123 const auto loopSizeTmp1 = (inputPoints.extent(0)/numPtsPerEval);
124 const auto loopSizeTmp2 = (inputPoints.extent(0)%numPtsPerEval != 0);
125 const auto loopSize = loopSizeTmp1 + loopSizeTmp2;
126 Kokkos::RangePolicy<ExecSpaceType,Kokkos::Schedule<Kokkos::Static> > policy(space, 0, loopSize);
130 const ordinal_type cardinality = outputValues.extent(0);
131 const ordinal_type spaceDim = 3;
133 switch (operatorType) {
134 case OPERATOR_VALUE: {
135 auto work =
createMatchingDynRankView(inputPoints,
"Basis_HCURL_TET_In_FEM::getValues::work", cardinality, inputPoints.extent(0));
136 typedef Functor<outputValueViewType,inputPointViewType,vinvViewType,
decltype(work),
137 OPERATOR_VALUE,numPtsPerEval> FunctorType;
138 Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, coeffs, work) );
141 case OPERATOR_CURL: {
142 auto work =
createMatchingDynRankView(inputPoints,
"Basis_HCURL_TET_In_FEM::getValues::work", cardinality*(2*spaceDim+1), inputPoints.extent(0));
143 typedef Functor<outputValueViewType,inputPointViewType,vinvViewType,
decltype(work),
144 OPERATOR_CURL,numPtsPerEval> FunctorType;
145 Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, coeffs, work) );
149 INTREPID2_TEST_FOR_EXCEPTION(
true , std::invalid_argument,
150 ">>> ERROR (Basis_HCURL_TET_In_FEM): Operator type not implemented" );
157template<
typename DT,
typename OT,
typename PT>
160 const EPointType pointType ) {
162 constexpr ordinal_type spaceDim = 3;
175 const ordinal_type cardVecPn = spaceDim*cardPn;
176 const ordinal_type cardVecPnm1 = spaceDim*cardPnm1;
177 const ordinal_type cardPnm1H = cardPnm1-cardPnm2;
181 INTREPID2_TEST_FOR_EXCEPTION( order >
Parameters::MaxOrder, std::invalid_argument,
"polynomial order exceeds the max supported by this class");
184 constexpr ordinal_type tagSize = 4;
186 ordinal_type tags[maxCard][tagSize];
189 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
190 dofCoords(
"Hcurl::Tet::In::dofCoords", card, spaceDim);
192 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
193 coeffs(
"Hcurl::Tet::In::coeffs", cardVecPn, card);
195 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
196 dofCoeffs(
"Hcurl::Tet::In::dofCoeffs", card, spaceDim);
202 Kokkos::DynRankView<scalarType,Kokkos::LayoutLeft,Kokkos::HostSpace>
203 V1(
"Hcurl::Tet::In::V1", cardVecPn, cardVecPnm1 + spaceDim*cardPnm1H);
207 for (ordinal_type i=0;i<cardPnm1;i++)
208 for (ordinal_type d=0;d<spaceDim;d++)
209 V1(i+d*cardPn,i+d*cardPnm1) = 1.0;
215 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> cubPoints(
"Hcurl::Tet::In::cubPoints", myCub.
getNumPoints() , spaceDim );
216 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> cubWeights(
"Hcurl::Tet::In::cubWeights", myCub.
getNumPoints() );
217 myCub.getCubature( cubPoints , cubWeights );
220 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> phisAtCubPoints(
"Hcurl::Tet::In::phisAtCubPoints", cardPn , myCub.
getNumPoints() );
221 Impl::Basis_HGRAD_TET_Cn_FEM_ORTH::getValues<Kokkos::HostSpace::execution_space,Parameters::MaxNumPtsPerBasisEval>(
typename Kokkos::HostSpace::execution_space{},
228 for (ordinal_type i=0;i<cardPn;i++) {
229 for (ordinal_type j=0;j<cardPnm1H;j++) {
230 for (ordinal_type d=0; d< spaceDim; ++d) {
231 scalarType integral(0);
233 integral += cubWeights(k) * cubPoints(k,d)
234 * phisAtCubPoints(cardPnm2+j,k)
235 * phisAtCubPoints(i,k);
236 ordinal_type d1 = (d+1) % spaceDim, d2 = (d+2) % spaceDim;
237 V1(i+d2*cardPn,cardVecPnm1+d1*cardPnm1H + j) = -integral;
238 V1(i+d1*cardPn,cardVecPnm1+d2*cardPnm1H + j) = integral;
248 Kokkos::DynRankView<scalarType,Kokkos::LayoutLeft,Kokkos::HostSpace>
249 S(
"Hcurl::Tet::In::S", cardVecPn,1),
250 U(
"Hcurl::Tet::In::U", cardVecPn, cardVecPn),
251 Vt(
"Hcurl::Tet::In::Vt", cardVecPn, cardVecPn),
252 work(
"Hcurl::Tet::In::work", 5*cardVecPn,1),
253 rWork(
"Hcurl::Tet::In::rW", 1,1);
257 ordinal_type info = 0;
258 Teuchos::LAPACK<ordinal_type,scalarType> lapack;
278#ifdef HAVE_INTREPID2_DEBUG
279 ordinal_type num_nonzero_sv = 0;
280 for (
int i=0;i<cardVecPn;i++)
281 num_nonzero_sv += (S(i,0) > 10*tolerence());
283 INTREPID2_TEST_FOR_EXCEPTION( num_nonzero_sv != card, std::invalid_argument,
284 ">>> ERROR: (Intrepid2::Basis_HCURL_TET_In_FEM( order, pointType), Matrix V1 should have rank equal to the cardinality of HCURL space");
288 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
289 V2(
"Hcurl::Tet::In::V2", card ,cardVecPn);
291 shards::CellTopology cellTopo(shards::getCellTopologyData<shards::Tetrahedron<4> >());
292 const ordinal_type numEdges = cellTopo.getEdgeCount();
293 const ordinal_type numFaces = cellTopo.getFaceCount();
298 shards::CellTopology edgeTopo(shards::getCellTopologyData<shards::Line<2> >() );
299 shards::CellTopology faceTopo(shards::getCellTopologyData<shards::Triangle<3> >() );
313 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> linePts(
"Hcurl::Tet::In::linePts", numPtsPerEdge , 1 );
314 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> triPts(
"Hcurl::Tet::In::triPts", numPtsPerFace , 2 );
317 const ordinal_type offset = 1;
332 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> edgePts(
"Hcurl::Tet::In::edgePts", numPtsPerEdge , spaceDim );
333 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> facePts(
"Hcurl::Tet::In::facePts", numPtsPerFace , spaceDim );
334 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> phisAtEdgePoints(
"Hcurl::Tet::In::phisAtEdgePoints", cardPn , numPtsPerEdge );
335 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> phisAtFacePoints(
"Hcurl::Tet::In::phisAtFacePoints", cardPn , numPtsPerFace);
337 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> edgeTan(
"Hcurl::Tet::In::edgeTan", spaceDim );
340 for (ordinal_type i=0;i<numEdges;i++) {
351 Impl::Basis_HGRAD_TET_Cn_FEM_ORTH::getValues<Kokkos::HostSpace::execution_space,Parameters::MaxNumPtsPerBasisEval>(
typename Kokkos::HostSpace::execution_space{},
358 for (ordinal_type j=0;j<numPtsPerEdge;j++) {
360 const ordinal_type i_card = numPtsPerEdge*i+j;
363 for (ordinal_type k=0;k<cardPn;k++)
364 for (ordinal_type d=0;d<spaceDim;d++)
365 V2(i_card,k+d*cardPn) = edgeTan(d) * phisAtEdgePoints(k,j);
368 for(ordinal_type k=0; k<spaceDim; ++k) {
369 dofCoords(i_card,k) = edgePts(j,k);
370 dofCoeffs(i_card,k) = edgeTan(k);
376 tags[i_card][3] = numPtsPerEdge;
381 if(numPtsPerFace >0) {
382 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> faceTan1(
"Hcurl::Tet::In::edgeTan", spaceDim );
383 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> faceTan2(
"Hcurl::Tet::In::edgeTan", spaceDim );
385 for (ordinal_type i=0;i<numFaces;i++) {
397 Impl::Basis_HGRAD_TET_Cn_FEM_ORTH::getValues<Kokkos::HostSpace::execution_space,Parameters::MaxNumPtsPerBasisEval>(
typename Kokkos::HostSpace::execution_space{},
404 for (ordinal_type j=0;j<numPtsPerFace;j++) {
406 const ordinal_type i_card = numEdges*numPtsPerEdge+2*numPtsPerFace*i+2*j;
407 const ordinal_type i_card_p1 = i_card+1;
410 for (ordinal_type k=0;k<cardPn;k++)
411 for (ordinal_type d=0;d<spaceDim;d++) {
412 V2(i_card,k+d*cardPn) = faceTan1(d) * phisAtFacePoints(k,j);
413 V2(i_card_p1,k+d*cardPn) = faceTan2(d) * phisAtFacePoints(k,j);
417 for(ordinal_type k=0; k<spaceDim; ++k) {
418 dofCoords(i_card,k) = facePts(j,k);
419 dofCoords(i_card_p1,k) = facePts(j,k);
420 dofCoeffs(i_card,k) = faceTan1(k);
421 dofCoeffs(i_card_p1,k) = faceTan2(k);
426 tags[i_card][2] = 2*j;
427 tags[i_card][3] = 2*numPtsPerFace;
429 tags[i_card_p1][0] = 2;
430 tags[i_card_p1][1] = i;
431 tags[i_card_p1][2] = 2*j+1;
432 tags[i_card_p1][3] = 2*numPtsPerFace;
440 if (numPtsPerCell > 0) {
441 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
442 cellPoints(
"Hcurl::Tet::In::cellPoints", numPtsPerCell , spaceDim );
449 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
450 phisAtCellPoints(
"Hcurl::Tet::In::phisAtCellPoints", cardPn , numPtsPerCell );
451 Impl::Basis_HGRAD_TET_Cn_FEM_ORTH::getValues<Kokkos::HostSpace::execution_space,Parameters::MaxNumPtsPerBasisEval>(
typename Kokkos::HostSpace::execution_space{},
458 for (ordinal_type j=0;j<numPtsPerCell;j++) {
460 const ordinal_type i_card = numEdges*numPtsPerEdge+2*numFaces*numPtsPerFace+spaceDim*j;
462 for (ordinal_type k=0;k<cardPn;k++)
463 for (ordinal_type d=0;d<spaceDim;d++)
464 V2(i_card+d,d*cardPn+k) = phisAtCellPoints(k,j);
468 for(ordinal_type d=0; d<spaceDim; ++d) {
469 for(ordinal_type dim=0; dim<spaceDim; ++dim) {
470 dofCoords(i_card+d,dim) = cellPoints(j,dim);
471 dofCoeffs(i_card+d,dim) = (d==dim);
474 tags[i_card+d][0] = spaceDim;
475 tags[i_card+d][1] = 0;
476 tags[i_card+d][2] = spaceDim*j+d;
477 tags[i_card+d][3] = spaceDim*numPtsPerCell;
484 const ordinal_type lwork = card*card;
485 Kokkos::DynRankView<scalarType,Kokkos::LayoutLeft,Kokkos::HostSpace>
486 vmat(
"Hcurl::Tet::In::vmat", card, card),
487 work1(
"Hcurl::Tet::In::work", lwork),
488 ipiv(
"Hcurl::Tet::In::ipiv", card);
491 for(ordinal_type i=0; i< card; ++i) {
492 for(ordinal_type j=0; j< card; ++j) {
494 for(ordinal_type k=0; k< cardVecPn; ++k)
502 lapack.GETRF(card, card,
503 vmat.data(), vmat.stride(1),
504 (ordinal_type*)ipiv.data(),
507 INTREPID2_TEST_FOR_EXCEPTION( info != 0,
509 ">>> ERROR: (Intrepid2::Basis_HCURL_TET_In_FEM) lapack.GETRF returns nonzero info." );
512 vmat.data(), vmat.stride(1),
513 (ordinal_type*)ipiv.data(),
517 INTREPID2_TEST_FOR_EXCEPTION( info != 0,
519 ">>> ERROR: (Intrepid2::Basis_HCURL_TET_In_FEM) lapack.GETRI returns nonzero info." );
521 for (ordinal_type i=0;i<cardVecPn;++i) {
522 for (ordinal_type j=0;j<card;++j){
524 for(ordinal_type k=0; k< card; ++k)
525 s += U(i,k)*vmat(k,j);
530 this->
coeffs_ = Kokkos::create_mirror_view(
typename DT::memory_space(), coeffs);
531 Kokkos::deep_copy(this->
coeffs_ , coeffs);
533 this->
dofCoords_ = Kokkos::create_mirror_view(
typename DT::memory_space(), dofCoords);
534 Kokkos::deep_copy(this->
dofCoords_, dofCoords);
536 this->
dofCoeffs_ = Kokkos::create_mirror_view(
typename DT::memory_space(), dofCoeffs);
537 Kokkos::deep_copy(this->
dofCoeffs_, dofCoeffs);
543 const ordinal_type posScDim = 0;
544 const ordinal_type posScOrd = 1;
545 const ordinal_type posDfOrd = 2;
562template<
typename DT,
typename OT,
typename PT>
564Basis_HCURL_TET_In_FEM<DT,OT,PT>::getScratchSpaceSize(
565 ordinal_type& perTeamSpaceSize,
566 ordinal_type& perThreadSpaceSize,
568 const EOperator operatorType)
const {
569 perTeamSpaceSize = 0;
570 ordinal_type scalarWorkViewExtent = (operatorType == OPERATOR_VALUE) ? this->basisCardinality_ : 7*this->basisCardinality_;
571 perThreadSpaceSize = scalarWorkViewExtent*get_dimension_scalar(inputPoints)*
sizeof(
typename BasisBase::scalarType);
574template<
typename DT,
typename OT,
typename PT>
575KOKKOS_INLINE_FUNCTION
577Basis_HCURL_TET_In_FEM<DT,OT,PT>::getValues(
578 OutputViewType outputValues,
579 const PointViewType inputPoints,
580 const EOperator operatorType,
581 const typename Kokkos::TeamPolicy<typename DT::execution_space>::member_type& team_member,
582 const typename DT::execution_space::scratch_memory_space & scratchStorage,
583 const ordinal_type subcellDim,
584 const ordinal_type subcellOrdinal)
const {
586 INTREPID2_TEST_FOR_ABORT( !((subcellDim == -1) && (subcellOrdinal == -1)),
587 ">>> ERROR: (Intrepid2::Basis_HCURL_TET_In_FEM::getValues), The capability of selecting subsets of basis functions has not been implemented yet.");
589 const int numPoints = inputPoints.extent(0);
590 using ScalarType =
typename ScalarTraits<typename PointViewType::value_type>::scalar_type;
591 using WorkViewType = Kokkos::DynRankView< ScalarType,typename DT::execution_space::scratch_memory_space,Kokkos::MemoryTraits<Kokkos::Unmanaged> >;
592 ordinal_type scalarSizePerPoint = (operatorType == OPERATOR_VALUE) ? this->basisCardinality_ : 7*this->basisCardinality_;
593 ordinal_type sizePerPoint = scalarSizePerPoint*get_dimension_scalar(inputPoints);
594 WorkViewType workView(scratchStorage, sizePerPoint*team_member.team_size());
595 using range_type = Kokkos::pair<ordinal_type,ordinal_type>;
597 switch(operatorType) {
599 Kokkos::parallel_for (Kokkos::TeamThreadRange (team_member, numPoints), [=, &coeffs_ = this->coeffs_] (ordinal_type& pt) {
600 auto output = Kokkos::subview( outputValues, Kokkos::ALL(), range_type (pt,pt+1), Kokkos::ALL() );
601 const auto input = Kokkos::subview( inputPoints, range_type(pt, pt+1), Kokkos::ALL() );
602 WorkViewType work(workView.data() + sizePerPoint*team_member.team_rank(), sizePerPoint);
603 Impl::Basis_HCURL_TET_In_FEM::Serial<OPERATOR_VALUE>::getValues( output, input, work, coeffs_ );
607 Kokkos::parallel_for (Kokkos::TeamThreadRange (team_member, numPoints), [=, &coeffs_ = this->coeffs_] (ordinal_type& pt) {
608 auto output = Kokkos::subview( outputValues, Kokkos::ALL(), range_type(pt,pt+1), Kokkos::ALL() );
609 const auto input = Kokkos::subview( inputPoints, range_type(pt,pt+1), Kokkos::ALL() );
610 WorkViewType work(workView.data() + sizePerPoint*team_member.team_rank(), sizePerPoint);
611 Impl::Basis_HCURL_TET_In_FEM::Serial<OPERATOR_CURL>::getValues( output, input, work, coeffs_ );
615 INTREPID2_TEST_FOR_ABORT(
true,
616 ">>> ERROR (Basis_HCURL_TET_In_FEM): getValues not implemented for this operator");
KOKKOS_INLINE_FUNCTION ordinal_type getPnCardinality(ordinal_type n)
Returns cardinality of Polynomials of order n (P^n).
Header file for the Intrepid2::CubatureDirectTetDefault class.
Header file for the Intrepid2::Basis_HGRAD_TET_Cn_FEM_ORTH class.
KOKKOS_INLINE_FUNCTION std::enable_if< std::is_pointer_v< CtorProp > &&!std::is_convertible_v< CtorProp, constchar * >, OutViewType >::type createMatchingUnmanagedView(const InViewType &view, const CtorProp &data, const Dims... dims)
Creates an unmanaged view that matches the value_type of the provided view The type of the output vie...
DeduceDynRankView< InViewType >::type createMatchingDynRankView(const InViewType &view, const CtorProp &prop, const Dims... dims)
Creates and returns a view that matches the value_type of the provided view The output view type is d...
Basis_HCURL_TET_In_FEM(const ordinal_type order, const EPointType pointType=POINTTYPE_EQUISPACED)
Constructor.
EPointType pointType_
type of lattice used for creating the DoF coordinates
Kokkos::DynRankView< scalarType, DeviceType > coeffs_
expansion coefficients of the nodal basis in terms of the orthgonal one
ECoordinates basisCoordinates_
ordinal_type basisDegree_
void setOrdinalTagData(OrdinalTypeView3D &tagToOrdinal, OrdinalTypeView2D &ordinalToTag, const OrdinalTypeView1D tags, const ordinal_type basisCard, const ordinal_type tagSize, const ordinal_type posScDim, const ordinal_type posScOrd, const ordinal_type posDfOrd)
OrdinalTypeArray2DHost ordinalToTag_
Kokkos::DynRankView< scalarType, DeviceType > dofCoords_
Kokkos::DynRankView< scalarType, DeviceType > dofCoeffs_
ordinal_type basisCardinality_
OrdinalTypeArray3DHost tagToOrdinal_
Kokkos::View< ordinal_type *, typename ExecutionSpace::array_layout, Kokkos::HostSpace > OrdinalTypeArray1DHost
unsigned basisCellTopologyKey_
EFunctionSpace functionSpace_
virtual ordinal_type getNumPoints() const override
Returns the number of cubature points.
Defines direct integration rules on a tetrahedron.
static constexpr ordinal_type MaxOrder
The maximum reconstruction order.
See Intrepid2::Basis_HCURL_TET_In_FEM.
See Intrepid2::Basis_HCURL_TET_In_FEM.