16#ifndef __INTREPID2_HDIV_TET_IN_FEM_DEF_HPP__
17#define __INTREPID2_HDIV_TET_IN_FEM_DEF_HPP__
28template<EOperator OpType>
29template<
typename OutputViewType,
30typename InputViewType,
37 const InputViewType input,
39 const VinvViewType coeffs ) {
41 constexpr ordinal_type spaceDim = 3;
43 cardPn = coeffs.extent(0)/spaceDim,
44 card = coeffs.extent(1),
45 npts = input.extent(0);
48 ordinal_type order = 0;
50 if (card == CardinalityHDivTet(p)) {
56 typedef typename Kokkos::DynRankView<typename InputViewType::value_type, typename WorkViewType::memory_space> ViewType;
57 auto ptr = work.data();
60 case OPERATOR_VALUE: {
64 Impl::Basis_HGRAD_TET_Cn_FEM_ORTH::
65 Serial<OpType>::getValues(phis, input, dummyView, order);
67 for (ordinal_type i=0;i<card;++i)
68 for (ordinal_type j=0;j<npts;++j)
69 for (ordinal_type d=0;d<spaceDim;++d) {
70 output.access(i,j,d) = 0.0;
71 for (ordinal_type k=0;k<cardPn;++k)
72 output.access(i,j,d) += coeffs(k+d*cardPn,i) * phis.access(k,j);
78 ptr += card*npts*spaceDim*get_dimension_scalar(input);
81 Impl::Basis_HGRAD_TET_Cn_FEM_ORTH::
82 Serial<OPERATOR_GRAD>::getValues(phis, input, workView, order);
84 for (ordinal_type i=0;i<card;++i)
85 for (ordinal_type j=0;j<npts;++j) {
86 output.access(i,j) = 0.0;
87 for (ordinal_type k=0; k<cardPn; ++k)
88 for (ordinal_type d=0; d<spaceDim; ++d)
89 output.access(i,j) += coeffs(k+d*cardPn,i)*phis.access(k,j,d);
94 INTREPID2_TEST_FOR_ABORT(
true,
95 ">>> ERROR (Basis_HDIV_TET_In_FEM): Operator type not implemented");
100template<
typename DT, ordinal_type numPtsPerEval,
101typename outputValueValueType,
class ...outputValueProperties,
102typename inputPointValueType,
class ...inputPointProperties,
103typename vinvValueType,
class ...vinvProperties>
105Basis_HDIV_TET_In_FEM::
106getValues( Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValues,
107 const Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPoints,
108 const Kokkos::DynRankView<vinvValueType, vinvProperties...> coeffs,
109 const EOperator operatorType) {
110 typedef Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValueViewType;
111 typedef Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPointViewType;
112 typedef Kokkos::DynRankView<vinvValueType, vinvProperties...> vinvViewType;
113 typedef typename ExecSpace<typename inputPointViewType::execution_space,typename DT::execution_space>::ExecSpaceType ExecSpaceType;
116 const auto loopSizeTmp1 = (inputPoints.extent(0)/numPtsPerEval);
117 const auto loopSizeTmp2 = (inputPoints.extent(0)%numPtsPerEval != 0);
118 const auto loopSize = loopSizeTmp1 + loopSizeTmp2;
119 Kokkos::RangePolicy<ExecSpaceType,Kokkos::Schedule<Kokkos::Static> > policy(0, loopSize);
121 const ordinal_type cardinality = outputValues.extent(0);
122 const ordinal_type spaceDim = 3;
124 switch (operatorType) {
125 case OPERATOR_VALUE: {
126 auto work =
createMatchingDynRankView(inputPoints,
"Basis_HDIV_TET_In_FEM::getValues::work", cardinality, inputPoints.extent(0));
127 typedef Functor<outputValueViewType,inputPointViewType,vinvViewType,
decltype(work),
128 OPERATOR_VALUE,numPtsPerEval> FunctorType;
129 Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, coeffs, work) );
133 auto work =
createMatchingDynRankView(inputPoints,
"Basis_HDIV_TET_In_FEM::getValues::work", cardinality*(2*spaceDim+1), inputPoints.extent(0));
134 typedef Functor<outputValueViewType,inputPointViewType,vinvViewType,
decltype(work),
135 OPERATOR_DIV,numPtsPerEval> FunctorType;
136 Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, coeffs, work) );
140 INTREPID2_TEST_FOR_EXCEPTION(
true , std::invalid_argument,
141 ">>> ERROR (Basis_HDIV_TET_In_FEM): Operator type not implemented" );
148template<
typename DT,
typename OT,
typename PT>
151 const EPointType pointType ) {
153 constexpr ordinal_type spaceDim = 3;
167 const ordinal_type cardVecPn = spaceDim*cardPn;
168 const ordinal_type cardVecPnm1 = spaceDim*cardPnm1;
169 const ordinal_type dim_PkH = cardPnm1 - cardPnm2;
173 INTREPID2_TEST_FOR_EXCEPTION( order >
Parameters::MaxOrder, std::invalid_argument,
"polynomial order exceeds the max supported by this class");
176 constexpr ordinal_type tagSize = 4;
178 ordinal_type tags[maxCard][tagSize];
181 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
182 dofCoords(
"Hdiv::Tet::In::dofCoords", card, spaceDim);
184 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
185 dofCoeffs(
"Hdiv::Tet::In::dofCoeffs", card, spaceDim);
187 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
188 coeffs(
"Hdiv::Tet::In::coeffs", cardVecPn, card);
194 const ordinal_type lwork = card*card;
195 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
196 V1(
"Hdiv::Tet::In::V1", cardVecPn, card);
207 for (ordinal_type i=0;i<cardPnm1;i++) {
208 for (ordinal_type k=0; k<3;k++) {
209 V1(k*cardPn+i,k*cardPnm1+i) = 1.0;
216 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> cubPoints(
"Hdiv::Tet::In::cubPoints", myCub.
getNumPoints() , spaceDim );
217 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> cubWeights(
"Hdiv::Tet::In::cubWeights", myCub.
getNumPoints() );
218 myCub.getCubature( cubPoints , cubWeights );
221 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> phisAtCubPoints(
"Hdiv::Tet::In::phisAtCubPoints", cardPn , myCub.
getNumPoints() );
222 Impl::Basis_HGRAD_TET_Cn_FEM_ORTH::getValues<Kokkos::HostSpace::execution_space,Parameters::MaxNumPtsPerBasisEval>(
typename Kokkos::HostSpace::execution_space{},
229 for (ordinal_type i=0;i<dim_PkH;i++) {
230 for (ordinal_type j=0;j<cardPn;j++) {
231 V1(j,cardVecPnm1+i) = 0.0;
232 for (ordinal_type d=0; d< spaceDim; ++d)
234 V1(j+d*cardPn,cardVecPnm1+i) +=
235 cubWeights(k) * cubPoints(k,d)
236 * phisAtCubPoints(cardPnm2+i,k)
237 * phisAtCubPoints(j,k);
243 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
244 V2(
"Hdiv::Tet::In::V2", card ,cardVecPn);
246 const shards::CellTopology cellTopo(shards::getCellTopologyData<shards::Tetrahedron<4>>());
247 const ordinal_type numFaces = cellTopo.getFaceCount();
249 shards::CellTopology faceTopo(shards::getCellTopologyData<shards::Triangle<3> >() );
256 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> triPts(
"Hdiv::Tet::In::triPts", numPtsPerFace , 2 );
259 const ordinal_type offset = 1;
267 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> facePts(
"Hdiv::Tet::In::facePts", numPtsPerFace , spaceDim );
268 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> phisAtFacePoints(
"Hdiv::Tet::In::phisAtFacePoints", cardPn , numPtsPerFace );
269 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> faceNormal(
"Hcurl::Tet::In::faceNormal", spaceDim );
272 for (ordinal_type face=0;face<numFaces;face++) {
286 Impl::Basis_HGRAD_TET_Cn_FEM_ORTH::getValues<Kokkos::HostSpace::execution_space,Parameters::MaxNumPtsPerBasisEval>(
typename Kokkos::HostSpace::execution_space{},
293 for (ordinal_type j=0;j<numPtsPerFace;j++) {
295 const ordinal_type i_card = numPtsPerFace*face+j;
298 for (ordinal_type k=0;k<cardPn;k++) {
300 for (ordinal_type l=0; l<spaceDim; l++)
301 V2(i_card,k+l*cardPn) = faceNormal(l) * phisAtFacePoints(k,j);
305 for(ordinal_type l=0; l<spaceDim; ++l) {
306 dofCoords(i_card,l) = facePts(j,l);
307 dofCoeffs(i_card,l) = faceNormal(l);
311 tags[i_card][1] = face;
313 tags[i_card][3] = numPtsPerFace;
326 if (numPtsPerCell > 0) {
327 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
328 internalPoints(
"Hdiv::Tet::In::internalPoints", numPtsPerCell , spaceDim );
335 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
336 phisAtInternalPoints(
"Hdiv::Tet::In::phisAtInternalPoints", cardPn , numPtsPerCell );
337 Impl::Basis_HGRAD_TET_Cn_FEM_ORTH::getValues<Kokkos::HostSpace::execution_space,Parameters::MaxNumPtsPerBasisEval>(
typename Kokkos::HostSpace::execution_space{},
338 phisAtInternalPoints,
344 for (ordinal_type j=0;j<numPtsPerCell;j++) {
346 const ordinal_type i_card = numFaces*numPtsPerFace+spaceDim*j;
348 for (ordinal_type k=0;k<cardPn;k++) {
349 for (ordinal_type l=0;l<spaceDim;l++) {
350 V2(i_card+l,l*cardPn+k) = phisAtInternalPoints(k,j);
355 for(ordinal_type d=0; d<spaceDim; ++d) {
356 for(ordinal_type l=0; l<spaceDim; ++l) {
357 dofCoords(i_card+d,l) = internalPoints(j,l);
358 dofCoeffs(i_card+d,l) = (l==d);
361 tags[i_card+d][0] = spaceDim;
362 tags[i_card+d][1] = 0;
363 tags[i_card+d][2] = spaceDim*j+d;
364 tags[i_card+d][3] = spaceDim*numPtsPerCell;
371 Kokkos::DynRankView<scalarType,Kokkos::LayoutLeft,Kokkos::HostSpace>
372 vmat(
"Hdiv::Tet::In::vmat", card, card),
373 work(
"Hdiv::Tet::In::work", lwork),
374 ipiv(
"Hdiv::Tet::In::ipiv", card);
377 for(ordinal_type i=0; i< card; ++i) {
378 for(ordinal_type j=0; j< card; ++j) {
380 for(ordinal_type k=0; k< cardVecPn; ++k)
381 s += V2(i,k)*V1(k,j);
386 ordinal_type info = 0;
387 Teuchos::LAPACK<ordinal_type,scalarType> lapack;
389 lapack.GETRF(card, card,
390 vmat.data(), vmat.stride(1),
391 (ordinal_type*)ipiv.data(),
394 INTREPID2_TEST_FOR_EXCEPTION( info != 0,
396 ">>> ERROR: (Intrepid2::Basis_HDIV_TET_In_FEM) lapack.GETRF returns nonzero info." );
399 vmat.data(), vmat.stride(1),
400 (ordinal_type*)ipiv.data(),
404 INTREPID2_TEST_FOR_EXCEPTION( info != 0,
406 ">>> ERROR: (Intrepid2::Basis_HDIV_TET_In_FEM) lapack.GETRI returns nonzero info." );
408 for (ordinal_type i=0;i<cardVecPn;++i)
409 for (ordinal_type j=0;j<card;++j){
411 for(ordinal_type k=0; k< card; ++k)
412 s += V1(i,k)*vmat(k,j);
416 this->
coeffs_ = Kokkos::create_mirror_view(
typename DT::memory_space(), coeffs);
417 Kokkos::deep_copy(this->
coeffs_ , coeffs);
419 this->
dofCoords_ = Kokkos::create_mirror_view(
typename DT::memory_space(), dofCoords);
420 Kokkos::deep_copy(this->
dofCoords_, dofCoords);
422 this->
dofCoeffs_ = Kokkos::create_mirror_view(
typename DT::memory_space(), dofCoeffs);
423 Kokkos::deep_copy(this->
dofCoeffs_, dofCoeffs);
429 const ordinal_type posScDim = 0;
430 const ordinal_type posScOrd = 1;
431 const ordinal_type posDfOrd = 2;
433 OrdinalTypeArray1DHost tagView(&tags[0][0], card*tagSize);
448template<
typename DT,
typename OT,
typename PT>
450Basis_HDIV_TET_In_FEM<DT,OT,PT>::getScratchSpaceSize(
451 ordinal_type& perTeamSpaceSize,
452 ordinal_type& perThreadSpaceSize,
454 const EOperator operatorType)
const {
455 perTeamSpaceSize = 0;
456 ordinal_type scalarWorkViewExtent = (operatorType == OPERATOR_VALUE) ? this->basisCardinality_ : 7*this->basisCardinality_;
457 perThreadSpaceSize = scalarWorkViewExtent*get_dimension_scalar(inputPoints)*
sizeof(
typename BasisBase::scalarType);
460template<
typename DT,
typename OT,
typename PT>
461KOKKOS_INLINE_FUNCTION
463Basis_HDIV_TET_In_FEM<DT,OT,PT>::getValues(
464 OutputViewType outputValues,
465 const PointViewType inputPoints,
466 const EOperator operatorType,
467 const typename Kokkos::TeamPolicy<typename DT::execution_space>::member_type& team_member,
468 const typename DT::execution_space::scratch_memory_space & scratchStorage,
469 const ordinal_type subcellDim,
470 const ordinal_type subcellOrdinal)
const {
472 INTREPID2_TEST_FOR_ABORT( !((subcellDim == -1) && (subcellOrdinal == -1)),
473 ">>> ERROR: (Intrepid2::Basis_HDIV_TET_In_FEM::getValues), The capability of selecting subsets of basis functions has not been implemented yet.");
475 const int numPoints = inputPoints.extent(0);
476 using ScalarType =
typename ScalarTraits<typename PointViewType::value_type>::scalar_type;
477 using WorkViewType = Kokkos::DynRankView< ScalarType,typename DT::execution_space::scratch_memory_space,Kokkos::MemoryTraits<Kokkos::Unmanaged> >;
478 ordinal_type scalarSizePerPoint = (operatorType == OPERATOR_VALUE) ? this->basisCardinality_ : 7*this->basisCardinality_;
479 ordinal_type sizePerPoint = scalarSizePerPoint*get_dimension_scalar(inputPoints);
480 WorkViewType workView(scratchStorage, sizePerPoint*team_member.team_size());
481 using range_type = Kokkos::pair<ordinal_type,ordinal_type>;
483 switch(operatorType) {
485 Kokkos::parallel_for (Kokkos::TeamThreadRange (team_member, numPoints), [=, &coeffs_ = this->coeffs_] (ordinal_type& pt) {
486 auto output = Kokkos::subview( outputValues, Kokkos::ALL(), range_type (pt,pt+1), Kokkos::ALL() );
487 const auto input = Kokkos::subview( inputPoints, range_type(pt, pt+1), Kokkos::ALL() );
488 WorkViewType work(workView.data() + sizePerPoint*team_member.team_rank(), sizePerPoint);
489 Impl::Basis_HDIV_TET_In_FEM::Serial<OPERATOR_VALUE>::getValues( output, input, work, coeffs_ );
493 Kokkos::parallel_for (Kokkos::TeamThreadRange (team_member, numPoints), [=, &coeffs_ = this->coeffs_] (ordinal_type& pt) {
494 auto output = Kokkos::subview( outputValues, Kokkos::ALL(), range_type(pt,pt+1), Kokkos::ALL() );
495 const auto input = Kokkos::subview( inputPoints, range_type(pt,pt+1), Kokkos::ALL() );
496 WorkViewType work(workView.data() + sizePerPoint*team_member.team_rank(), sizePerPoint);
497 Impl::Basis_HDIV_TET_In_FEM::Serial<OPERATOR_DIV>::getValues( output, input, work, coeffs_ );
501 INTREPID2_TEST_FOR_ABORT(
true,
502 ">>> ERROR (Basis_HDIV_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_HDIV_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_
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_HDIV_TET_In_FEM.
See Intrepid2::Basis_HDIV_TET_In_FEM.