16 #ifndef __INTREPID2_HDIV_TET_IN_FEM_DEF_HPP__
17 #define __INTREPID2_HDIV_TET_IN_FEM_DEF_HPP__
28 template<EOperator OpType>
29 template<
typename OutputViewType,
30 typename InputViewType,
31 typename WorkViewType,
32 typename VinvViewType>
33 KOKKOS_INLINE_FUNCTION
35 Basis_HDIV_TET_In_FEM::Serial<OpType>::
36 getValues( OutputViewType output,
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 vcprop = Kokkos::common_view_alloc_prop(input);
58 auto ptr = work.data();
61 case OPERATOR_VALUE: {
62 const ViewType phis(Kokkos::view_wrap(ptr, vcprop), card, npts);
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.access(k,j);
78 const ViewType phis(Kokkos::view_wrap(ptr, vcprop), card, npts, spaceDim);
79 ptr += card*npts*spaceDim*get_dimension_scalar(input);
80 const ViewType workView(Kokkos::view_wrap(ptr, vcprop), card, npts, spaceDim+1);
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 output.access(i,j) = 0.0;
88 for (ordinal_type k=0; k<cardPn; ++k)
89 for (ordinal_type d=0; d<spaceDim; ++d)
90 output.access(i,j) += coeffs(k+d*cardPn,i)*phis.access(k,j,d);
95 INTREPID2_TEST_FOR_ABORT(
true,
96 ">>> ERROR (Basis_HDIV_TET_In_FEM): Operator type not implemented");
101 template<
typename DT, ordinal_type numPtsPerEval,
102 typename outputValueValueType,
class ...outputValueProperties,
103 typename inputPointValueType,
class ...inputPointProperties,
104 typename vinvValueType,
class ...vinvProperties>
106 Basis_HDIV_TET_In_FEM::
107 getValues( Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValues,
108 const Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPoints,
109 const Kokkos::DynRankView<vinvValueType, vinvProperties...> coeffs,
110 const EOperator operatorType) {
111 typedef Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValueViewType;
112 typedef Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPointViewType;
113 typedef Kokkos::DynRankView<vinvValueType, vinvProperties...> vinvViewType;
114 typedef typename ExecSpace<typename inputPointViewType::execution_space,typename DT::execution_space>::ExecSpaceType ExecSpaceType;
117 const auto loopSizeTmp1 = (inputPoints.extent(0)/numPtsPerEval);
118 const auto loopSizeTmp2 = (inputPoints.extent(0)%numPtsPerEval != 0);
119 const auto loopSize = loopSizeTmp1 + loopSizeTmp2;
120 Kokkos::RangePolicy<ExecSpaceType,Kokkos::Schedule<Kokkos::Static> > policy(0, loopSize);
122 typedef typename inputPointViewType::value_type inputPointType;
124 const ordinal_type cardinality = outputValues.extent(0);
125 const ordinal_type spaceDim = 3;
127 auto vcprop = Kokkos::common_view_alloc_prop(inputPoints);
128 typedef typename Kokkos::DynRankView< inputPointType, typename inputPointViewType::memory_space> workViewType;
130 switch (operatorType) {
131 case OPERATOR_VALUE: {
132 workViewType work(Kokkos::view_alloc(
"Basis_HDIV_TET_In_FEM::getValues::work", vcprop), cardinality, inputPoints.extent(0));
133 typedef Functor<outputValueViewType,inputPointViewType,vinvViewType, workViewType,
134 OPERATOR_VALUE,numPtsPerEval> FunctorType;
135 Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, coeffs, work) );
139 workViewType work(Kokkos::view_alloc(
"Basis_HDIV_TET_In_FEM::getValues::work", vcprop), cardinality*(2*spaceDim+1), inputPoints.extent(0));
140 typedef Functor<outputValueViewType,inputPointViewType,vinvViewType, workViewType,
141 OPERATOR_DIV,numPtsPerEval> FunctorType;
142 Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, coeffs, work) );
146 INTREPID2_TEST_FOR_EXCEPTION(
true , std::invalid_argument,
147 ">>> ERROR (Basis_HDIV_TET_In_FEM): Operator type not implemented" );
154 template<
typename DT,
typename OT,
typename PT>
157 const EPointType pointType ) {
159 constexpr ordinal_type spaceDim = 3;
160 this->basisCardinality_ = CardinalityHDivTet(order);
161 this->basisDegree_ = order;
162 this->basisCellTopologyKey_ = shards::Tetrahedron<4>::key;
163 this->basisType_ = BASIS_FEM_LAGRANGIAN;
164 this->basisCoordinates_ = COORDINATES_CARTESIAN;
165 this->functionSpace_ = FUNCTION_SPACE_HDIV;
166 pointType_ = pointType;
168 const ordinal_type card = this->basisCardinality_;
170 const ordinal_type cardPn = Intrepid2::getPnCardinality<spaceDim>(order);
171 const ordinal_type cardPnm1 = Intrepid2::getPnCardinality<spaceDim>(order-1);
172 const ordinal_type cardPnm2 = Intrepid2::getPnCardinality<spaceDim>(order-2);
173 const ordinal_type cardVecPn = spaceDim*cardPn;
174 const ordinal_type cardVecPnm1 = spaceDim*cardPnm1;
175 const ordinal_type dim_PkH = cardPnm1 - cardPnm2;
179 INTREPID2_TEST_FOR_EXCEPTION( order >
Parameters::MaxOrder, std::invalid_argument,
"polynomial order exceeds the max supported by this class");
182 constexpr ordinal_type tagSize = 4;
184 ordinal_type tags[maxCard][tagSize];
187 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
188 dofCoords(
"Hdiv::Tet::In::dofCoords", card, spaceDim);
190 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
191 dofCoeffs(
"Hdiv::Tet::In::dofCoeffs", card, spaceDim);
193 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
194 coeffs(
"Hdiv::Tet::In::coeffs", cardVecPn, card);
200 const ordinal_type lwork = card*card;
201 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
202 V1(
"Hdiv::Tet::In::V1", cardVecPn, card);
213 for (ordinal_type i=0;i<cardPnm1;i++) {
214 for (ordinal_type k=0; k<3;k++) {
215 V1(k*cardPn+i,k*cardPnm1+i) = 1.0;
222 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> cubPoints(
"Hdiv::Tet::In::cubPoints", myCub.
getNumPoints() , spaceDim );
223 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> cubWeights(
"Hdiv::Tet::In::cubWeights", myCub.
getNumPoints() );
227 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> phisAtCubPoints(
"Hdiv::Tet::In::phisAtCubPoints", cardPn , myCub.
getNumPoints() );
228 Impl::Basis_HGRAD_TET_Cn_FEM_ORTH::getValues<Kokkos::HostSpace::execution_space,Parameters::MaxNumPtsPerBasisEval>(
typename Kokkos::HostSpace::execution_space{},
235 for (ordinal_type i=0;i<dim_PkH;i++) {
236 for (ordinal_type j=0;j<cardPn;j++) {
237 V1(j,cardVecPnm1+i) = 0.0;
238 for (ordinal_type d=0; d< spaceDim; ++d)
240 V1(j+d*cardPn,cardVecPnm1+i) +=
241 cubWeights(k) * cubPoints(k,d)
242 * phisAtCubPoints(cardPnm2+i,k)
243 * phisAtCubPoints(j,k);
249 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
250 V2(
"Hdiv::Tet::In::V2", card ,cardVecPn);
252 const shards::CellTopology cellTopo(shards::getCellTopologyData<shards::Tetrahedron<4>>());
253 const ordinal_type numFaces = cellTopo.getFaceCount();
255 shards::CellTopology faceTopo(shards::getCellTopologyData<shards::Triangle<3> >() );
262 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> triPts(
"Hdiv::Tet::In::triPts", numPtsPerFace , 2 );
265 const ordinal_type offset = 1;
273 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> facePts(
"Hdiv::Tet::In::facePts", numPtsPerFace , spaceDim );
274 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> phisAtFacePoints(
"Hdiv::Tet::In::phisAtFacePoints", cardPn , numPtsPerFace );
275 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> faceNormal(
"Hcurl::Tet::In::faceNormal", spaceDim );
278 for (ordinal_type face=0;face<numFaces;face++) {
292 Impl::Basis_HGRAD_TET_Cn_FEM_ORTH::getValues<Kokkos::HostSpace::execution_space,Parameters::MaxNumPtsPerBasisEval>(
typename Kokkos::HostSpace::execution_space{},
299 for (ordinal_type j=0;j<numPtsPerFace;j++) {
301 const ordinal_type i_card = numPtsPerFace*face+j;
304 for (ordinal_type k=0;k<cardPn;k++) {
306 for (ordinal_type l=0; l<spaceDim; l++)
307 V2(i_card,k+l*cardPn) = faceNormal(l) * phisAtFacePoints(k,j);
311 for(ordinal_type l=0; l<spaceDim; ++l) {
312 dofCoords(i_card,l) = facePts(j,l);
313 dofCoeffs(i_card,l) = faceNormal(l);
317 tags[i_card][1] = face;
319 tags[i_card][3] = numPtsPerFace;
332 if (numPtsPerCell > 0) {
333 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
334 internalPoints(
"Hdiv::Tet::In::internalPoints", numPtsPerCell , spaceDim );
341 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
342 phisAtInternalPoints(
"Hdiv::Tet::In::phisAtInternalPoints", cardPn , numPtsPerCell );
343 Impl::Basis_HGRAD_TET_Cn_FEM_ORTH::getValues<Kokkos::HostSpace::execution_space,Parameters::MaxNumPtsPerBasisEval>(
typename Kokkos::HostSpace::execution_space{},
344 phisAtInternalPoints,
350 for (ordinal_type j=0;j<numPtsPerCell;j++) {
352 const ordinal_type i_card = numFaces*numPtsPerFace+spaceDim*j;
354 for (ordinal_type k=0;k<cardPn;k++) {
355 for (ordinal_type l=0;l<spaceDim;l++) {
356 V2(i_card+l,l*cardPn+k) = phisAtInternalPoints(k,j);
361 for(ordinal_type d=0; d<spaceDim; ++d) {
362 for(ordinal_type l=0; l<spaceDim; ++l) {
363 dofCoords(i_card+d,l) = internalPoints(j,l);
364 dofCoeffs(i_card+d,l) = (l==d);
367 tags[i_card+d][0] = spaceDim;
368 tags[i_card+d][1] = 0;
369 tags[i_card+d][2] = spaceDim*j+d;
370 tags[i_card+d][3] = spaceDim*numPtsPerCell;
377 Kokkos::DynRankView<scalarType,Kokkos::LayoutLeft,Kokkos::HostSpace>
378 vmat(
"Hdiv::Tet::In::vmat", card, card),
379 work(
"Hdiv::Tet::In::work", lwork),
380 ipiv(
"Hdiv::Tet::In::ipiv", card);
383 for(ordinal_type i=0; i< card; ++i) {
384 for(ordinal_type j=0; j< card; ++j) {
386 for(ordinal_type k=0; k< cardVecPn; ++k)
387 s += V2(i,k)*V1(k,j);
392 ordinal_type info = 0;
393 Teuchos::LAPACK<ordinal_type,scalarType> lapack;
395 lapack.GETRF(card, card,
396 vmat.data(), vmat.stride_1(),
397 (ordinal_type*)ipiv.data(),
400 INTREPID2_TEST_FOR_EXCEPTION( info != 0,
402 ">>> ERROR: (Intrepid2::Basis_HDIV_TET_In_FEM) lapack.GETRF returns nonzero info." );
405 vmat.data(), vmat.stride_1(),
406 (ordinal_type*)ipiv.data(),
410 INTREPID2_TEST_FOR_EXCEPTION( info != 0,
412 ">>> ERROR: (Intrepid2::Basis_HDIV_TET_In_FEM) lapack.GETRI returns nonzero info." );
414 for (ordinal_type i=0;i<cardVecPn;++i)
415 for (ordinal_type j=0;j<card;++j){
417 for(ordinal_type k=0; k< card; ++k)
418 s += V1(i,k)*vmat(k,j);
422 this->coeffs_ = Kokkos::create_mirror_view(
typename DT::memory_space(), coeffs);
423 Kokkos::deep_copy(this->coeffs_ , coeffs);
425 this->dofCoords_ = Kokkos::create_mirror_view(
typename DT::memory_space(), dofCoords);
426 Kokkos::deep_copy(this->dofCoords_, dofCoords);
428 this->dofCoeffs_ = Kokkos::create_mirror_view(
typename DT::memory_space(), dofCoeffs);
429 Kokkos::deep_copy(this->dofCoeffs_, dofCoeffs);
435 const ordinal_type posScDim = 0;
436 const ordinal_type posScOrd = 1;
437 const ordinal_type posDfOrd = 2;
439 OrdinalTypeArray1DHost tagView(&tags[0][0], card*tagSize);
443 this->setOrdinalTagData(this->tagToOrdinal_,
446 this->basisCardinality_,
454 template<
typename DT,
typename OT,
typename PT>
457 ordinal_type& perTeamSpaceSize,
458 ordinal_type& perThreadSpaceSize,
459 const PointViewType inputPoints,
460 const EOperator operatorType)
const {
461 perTeamSpaceSize = 0;
462 ordinal_type scalarWorkViewExtent = (operatorType == OPERATOR_VALUE) ? this->basisCardinality_ : 7*this->basisCardinality_;
463 perThreadSpaceSize = scalarWorkViewExtent*get_dimension_scalar(inputPoints)*
sizeof(
typename BasisBase::scalarType);
466 template<
typename DT,
typename OT,
typename PT>
467 KOKKOS_INLINE_FUNCTION
469 Basis_HDIV_TET_In_FEM<DT,OT,PT>::getValues(
470 OutputViewType outputValues,
471 const PointViewType inputPoints,
472 const EOperator operatorType,
473 const typename Kokkos::TeamPolicy<typename DT::execution_space>::member_type& team_member,
474 const typename DT::execution_space::scratch_memory_space & scratchStorage,
475 const ordinal_type subcellDim,
476 const ordinal_type subcellOrdinal)
const {
478 INTREPID2_TEST_FOR_ABORT( !((subcellDim == -1) && (subcellOrdinal == -1)),
479 ">>> ERROR: (Intrepid2::Basis_HDIV_TET_In_FEM::getValues), The capability of selecting subsets of basis functions has not been implemented yet.");
481 const int numPoints = inputPoints.extent(0);
482 using ScalarType =
typename ScalarTraits<typename PointViewType::value_type>::scalar_type;
483 using WorkViewType = Kokkos::DynRankView< ScalarType,typename DT::execution_space::scratch_memory_space,Kokkos::MemoryTraits<Kokkos::Unmanaged> >;
484 ordinal_type scalarSizePerPoint = (operatorType == OPERATOR_VALUE) ? this->basisCardinality_ : 7*this->basisCardinality_;
485 ordinal_type sizePerPoint = scalarSizePerPoint*get_dimension_scalar(inputPoints);
486 WorkViewType workView(scratchStorage, sizePerPoint*team_member.team_size());
487 using range_type = Kokkos::pair<ordinal_type,ordinal_type>;
489 switch(operatorType) {
491 Kokkos::parallel_for (Kokkos::TeamThreadRange (team_member, numPoints), [=] (ordinal_type& pt) {
492 auto output = Kokkos::subview( outputValues, Kokkos::ALL(), range_type (pt,pt+1), Kokkos::ALL() );
493 const auto input = Kokkos::subview( inputPoints, range_type(pt, pt+1), Kokkos::ALL() );
494 WorkViewType work(workView.data() + sizePerPoint*team_member.team_rank(), sizePerPoint);
495 Impl::Basis_HDIV_TET_In_FEM::Serial<OPERATOR_VALUE>::getValues( output, input, work, this->coeffs_ );
499 Kokkos::parallel_for (Kokkos::TeamThreadRange (team_member, numPoints), [=] (ordinal_type& pt) {
500 auto output = Kokkos::subview( outputValues, Kokkos::ALL(), range_type(pt,pt+1), Kokkos::ALL() );
501 const auto input = Kokkos::subview( inputPoints, range_type(pt,pt+1), Kokkos::ALL() );
502 WorkViewType work(workView.data() + sizePerPoint*team_member.team_rank(), sizePerPoint);
503 Impl::Basis_HDIV_TET_In_FEM::Serial<OPERATOR_DIV>::getValues( output, input, work, this->coeffs_ );
507 INTREPID2_TEST_FOR_ABORT(
true,
508 ">>> ERROR (Basis_HDIV_TET_In_FEM): getValues not implemented for this operator");
virtual void getCubature(PointViewType cubPoints, weightViewType cubWeights) const override
Returns cubature points and weights (return arrays must be pre-sized/pre-allocated).
virtual ordinal_type getNumPoints() const override
Returns the number of cubature points.
Implementation of the default H(div)-compatible Raviart-Thomas basis of arbitrary degree on Tetrahedr...
Header file for the Intrepid2::CubatureDirectTetDefault class.
Defines direct integration rules on a tetrahedron.
Basis_HDIV_TET_In_FEM(const ordinal_type order, const EPointType pointType=POINTTYPE_EQUISPACED)
Constructor.
Header file for the Intrepid2::Basis_HGRAD_TET_Cn_FEM_ORTH class.
static constexpr ordinal_type MaxOrder
The maximum reconstruction order.