16#ifndef __INTREPID2_HDIV_TRI_IN_FEM_DEF_HPP__
17#define __INTREPID2_HDIV_TRI_IN_FEM_DEF_HPP__
27template<EOperator OpType>
28template<
typename OutputViewType,
29typename InputViewType,
36 const InputViewType input,
38 const VinvViewType coeffs ) {
40 constexpr ordinal_type spaceDim = 2;
42 cardPn = coeffs.extent(0)/spaceDim,
43 card = coeffs.extent(1),
44 npts = input.extent(0);
47 ordinal_type order = 0;
49 if (card == CardinalityHDivTri(p)) {
55 typedef typename Kokkos::DynRankView<typename InputViewType::value_type, typename WorkViewType::memory_space> ViewType;
56 auto ptr = work.data();
59 case OPERATOR_VALUE: {
63 Impl::Basis_HGRAD_TRI_Cn_FEM_ORTH::
64 Serial<OpType>::getValues(phis, input, dummyView, order);
66 for (ordinal_type i=0;i<card;++i)
67 for (ordinal_type j=0;j<npts;++j)
68 for (ordinal_type d=0;d<spaceDim;++d) {
69 output.access(i,j,d) = 0.0;
70 for (ordinal_type k=0;k<cardPn;++k)
71 output.access(i,j,d) += coeffs(k+d*cardPn,i) * phis.access(k,j);
77 ptr += card*npts*spaceDim*get_dimension_scalar(work);
80 Impl::Basis_HGRAD_TRI_Cn_FEM_ORTH::
81 Serial<OPERATOR_GRAD>::getValues(phis, input, workView, order);
83 for (ordinal_type i=0;i<card;++i)
84 for (ordinal_type j=0;j<npts;++j) {
85 output.access(i,j) = 0.0;
86 for (ordinal_type k=0; k<cardPn; ++k)
87 for (ordinal_type d=0; d<spaceDim; ++d)
88 output.access(i,j) += coeffs(k+d*cardPn,i)*phis.access(k,j,d);
93 INTREPID2_TEST_FOR_ABORT(
true,
94 ">>> ERROR (Basis_HDIV_TRI_In_FEM): Operator type not implemented");
99template<
typename DT, ordinal_type numPtsPerEval,
100typename outputValueValueType,
class ...outputValueProperties,
101typename inputPointValueType,
class ...inputPointProperties,
102typename vinvValueType,
class ...vinvProperties>
104Basis_HDIV_TRI_In_FEM::
105getValues( Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValues,
106 const Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPoints,
107 const Kokkos::DynRankView<vinvValueType, vinvProperties...> coeffs,
108 const EOperator operatorType) {
109 typedef Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValueViewType;
110 typedef Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPointViewType;
111 typedef Kokkos::DynRankView<vinvValueType, vinvProperties...> vinvViewType;
112 typedef typename ExecSpace<typename inputPointViewType::execution_space,typename DT::execution_space>::ExecSpaceType ExecSpaceType;
115 const auto loopSizeTmp1 = (inputPoints.extent(0)/numPtsPerEval);
116 const auto loopSizeTmp2 = (inputPoints.extent(0)%numPtsPerEval != 0);
117 const auto loopSize = loopSizeTmp1 + loopSizeTmp2;
118 Kokkos::RangePolicy<ExecSpaceType,Kokkos::Schedule<Kokkos::Static> > policy(0, loopSize);
120 const ordinal_type cardinality = outputValues.extent(0);
121 const ordinal_type spaceDim = 2;
123 switch (operatorType) {
124 case OPERATOR_VALUE: {
125 auto work =
createMatchingDynRankView(inputPoints,
"Basis_HDIV_TRI_In_FEM::getValues::work", cardinality, inputPoints.extent(0));
126 typedef Functor<outputValueViewType,inputPointViewType,vinvViewType,
decltype(work),
127 OPERATOR_VALUE,numPtsPerEval> FunctorType;
128 Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, coeffs, work) );
132 auto work =
createMatchingDynRankView(inputPoints,
"Basis_HDIV_TRI_In_FEM::getValues::work", cardinality*(2*spaceDim+1), inputPoints.extent(0));
133 typedef Functor<outputValueViewType,inputPointViewType,vinvViewType,
decltype(work),
134 OPERATOR_DIV,numPtsPerEval> FunctorType;
135 Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, coeffs, work) );
139 INTREPID2_TEST_FOR_EXCEPTION(
true , std::invalid_argument,
140 ">>> ERROR (Basis_HDIV_TRI_In_FEM): Operator type not implemented" );
147template<
typename DT,
typename OT,
typename PT>
150 const EPointType pointType ) {
153 INTREPID2_TEST_FOR_EXCEPTION( order >
Parameters::MaxOrder, std::invalid_argument,
"polynomial order exceeds the max supported by this class");
155 constexpr ordinal_type spaceDim = 2;
162 pointType_ = (pointType == POINTTYPE_DEFAULT) ? POINTTYPE_EQUISPACED : pointType;
169 const ordinal_type cardVecPn = spaceDim*cardPn;
170 const ordinal_type cardVecPnm1 = spaceDim*cardPnm1;
174 constexpr ordinal_type tagSize = 4;
176 ordinal_type tags[maxCard][tagSize];
179 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
180 dofCoords(
"Hdiv::Tri::In::dofCoords", card, spaceDim);
182 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
183 dofCoeffs(
"Hdiv::Tri::In::dofCoeffs", card, spaceDim);
185 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
186 coeffs(
"Hdiv::Tri::In::coeffs", cardVecPn, card);
192 const ordinal_type lwork = card*card;
193 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
194 V1(
"Hdiv::Tri::In::V1", cardVecPn, card);
204 for (ordinal_type i=0;i<cardPnm1;i++) {
206 V1(cardPn+i,cardPnm1+i) = 1.0;
212 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> cubPoints(
"Hdiv::Tri::In::cubPoints", myCub.
getNumPoints() , spaceDim );
213 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> cubWeights(
"Hdiv::Tri::In::cubWeights", myCub.
getNumPoints() );
214 myCub.getCubature( cubPoints , cubWeights );
217 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> phisAtCubPoints(
"Hdiv::Tri::In::phisAtCubPoints", cardPn , myCub.
getNumPoints() );
218 Impl::Basis_HGRAD_TRI_Cn_FEM_ORTH::getValues<Kokkos::HostSpace::execution_space,Parameters::MaxNumPtsPerBasisEval>(
typename Kokkos::HostSpace::execution_space{},
225 for (ordinal_type i=0;i<order;i++) {
226 for (ordinal_type j=0;j<cardPn;j++) {
227 V1(j,cardVecPnm1+i) = 0.0;
228 for (ordinal_type d=0; d< spaceDim; ++d)
230 V1(j+d*cardPn,cardVecPnm1+i) +=
231 cubWeights(k) * cubPoints(k,d)
232 * phisAtCubPoints(cardPnm2+i,k)
233 * phisAtCubPoints(j,k);
239 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
240 V2(
"Hdiv::Tri::In::V2", card ,cardVecPn);
242 const shards::CellTopology cellTopo(shards::getCellTopologyData<shards::Triangle<3>>());
243 const ordinal_type numEdges = cellTopo.getEdgeCount();
244 shards::CellTopology edgeTopo(shards::getCellTopologyData<shards::Line<2> >() );
252 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> linePts(
"Hdiv::Tri::In::linePts", numPtsPerEdge , 1 );
255 const ordinal_type offset = 1;
262 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> edgePts(
"Hdiv::Tri::In::edgePts", numPtsPerEdge , spaceDim );
263 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> phisAtEdgePoints(
"Hdiv::Tri::In::phisAtEdgePoints", cardPn , numPtsPerEdge );
264 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> edgeNormal(
"Hcurl::Tri::In::edgeNormal", spaceDim );
267 for (ordinal_type edge=0;edge<numEdges;edge++) {
278 Impl::Basis_HGRAD_TRI_Cn_FEM_ORTH::getValues<Kokkos::HostSpace::execution_space,Parameters::MaxNumPtsPerBasisEval>(
typename Kokkos::HostSpace::execution_space{},
285 for (ordinal_type j=0;j<numPtsPerEdge;j++) {
287 const ordinal_type i_card = numPtsPerEdge*edge+j;
290 for (ordinal_type k=0;k<cardPn;k++) {
292 for (ordinal_type l=0; l<spaceDim; l++)
293 V2(i_card,k+l*cardPn) = edgeNormal(l) * phisAtEdgePoints(k,j);
298 for(ordinal_type l=0; l<spaceDim; ++l) {
299 dofCoords(i_card,l) = edgePts(j,l);
300 dofCoeffs(i_card,l) = edgeNormal(l);
304 tags[i_card][1] = edge;
306 tags[i_card][3] = numPtsPerEdge;
323 if (numPtsPerCell > 0) {
324 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
325 internalPoints(
"Hdiv::Tri::In::internalPoints", numPtsPerCell , spaceDim );
332 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
333 phisAtInternalPoints(
"Hdiv::Tri::In::phisAtInternalPoints", cardPn , numPtsPerCell );
334 Impl::Basis_HGRAD_TRI_Cn_FEM_ORTH::getValues<Kokkos::HostSpace::execution_space,Parameters::MaxNumPtsPerBasisEval>(
typename Kokkos::HostSpace::execution_space{},
335 phisAtInternalPoints,
341 for (ordinal_type j=0;j<numPtsPerCell;j++) {
343 const ordinal_type i_card = numEdges*order+spaceDim*j;
345 for (ordinal_type k=0;k<cardPn;k++) {
346 for (ordinal_type l=0;l<spaceDim;l++) {
347 V2(i_card+l,l*cardPn+k) = phisAtInternalPoints(k,j);
352 for(ordinal_type d=0; d<spaceDim; ++d) {
353 for(ordinal_type l=0; l<spaceDim; ++l) {
354 dofCoords(i_card+d,l) = internalPoints(j,l);
355 dofCoeffs(i_card+d,l) = (l==d);
358 tags[i_card+d][0] = spaceDim;
359 tags[i_card+d][1] = 0;
360 tags[i_card+d][2] = spaceDim*j+d;
361 tags[i_card+d][3] = spaceDim*numPtsPerCell;
368 Kokkos::DynRankView<scalarType,Kokkos::LayoutLeft,Kokkos::HostSpace>
369 vmat(
"Hdiv::Tri::In::vmat", card, card),
370 work(
"Hdiv::Tri::In::work", lwork),
371 ipiv(
"Hdiv::Tri::In::ipiv", card);
374 for(ordinal_type i=0; i< card; ++i) {
375 for(ordinal_type j=0; j< card; ++j) {
377 for(ordinal_type k=0; k< cardVecPn; ++k)
378 s += V2(i,k)*V1(k,j);
383 ordinal_type info = 0;
384 Teuchos::LAPACK<ordinal_type,scalarType> lapack;
386 lapack.GETRF(card, card,
387 vmat.data(), vmat.stride(1),
388 (ordinal_type*)ipiv.data(),
391 INTREPID2_TEST_FOR_EXCEPTION( info != 0,
393 ">>> ERROR: (Intrepid2::Basis_HDIV_TRI_In_FEM) lapack.GETRF returns nonzero info." );
396 vmat.data(), vmat.stride(1),
397 (ordinal_type*)ipiv.data(),
401 INTREPID2_TEST_FOR_EXCEPTION( info != 0,
403 ">>> ERROR: (Intrepid2::Basis_HDIV_TRI_In_FEM) lapack.GETRI returns nonzero info." );
405 for (ordinal_type i=0;i<cardVecPn;++i)
406 for (ordinal_type j=0;j<card;++j){
408 for(ordinal_type k=0; k< card; ++k)
409 s += V1(i,k)*vmat(k,j);
413 this->
coeffs_ = Kokkos::create_mirror_view(
typename DT::memory_space(), coeffs);
414 Kokkos::deep_copy(this->
coeffs_ , coeffs);
416 this->
dofCoords_ = Kokkos::create_mirror_view(
typename DT::memory_space(), dofCoords);
417 Kokkos::deep_copy(this->
dofCoords_, dofCoords);
419 this->
dofCoeffs_ = Kokkos::create_mirror_view(
typename DT::memory_space(), dofCoeffs);
420 Kokkos::deep_copy(this->
dofCoeffs_, dofCoeffs);
426 const ordinal_type posScDim = 0;
427 const ordinal_type posScOrd = 1;
428 const ordinal_type posDfOrd = 2;
430 OrdinalTypeArray1DHost tagView(&tags[0][0], card*tagSize);
445 template<
typename DT,
typename OT,
typename PT>
447 Basis_HDIV_TRI_In_FEM<DT,OT,PT>::getScratchSpaceSize(
448 ordinal_type& perTeamSpaceSize,
449 ordinal_type& perThreadSpaceSize,
451 const EOperator operatorType)
const {
452 perTeamSpaceSize = 0;
453 ordinal_type scalarWorkViewExtent = (operatorType == OPERATOR_VALUE) ? this->basisCardinality_ : 5*this->basisCardinality_;
454 perThreadSpaceSize = scalarWorkViewExtent*get_dimension_scalar(inputPoints)*
sizeof(
scalarType);
457 template<
typename DT,
typename OT,
typename PT>
458 KOKKOS_INLINE_FUNCTION
460 Basis_HDIV_TRI_In_FEM<DT,OT,PT>::getValues(
461 OutputViewType outputValues,
462 const PointViewType inputPoints,
463 const EOperator operatorType,
464 const typename Kokkos::TeamPolicy<typename DT::execution_space>::member_type& team_member,
465 const typename DT::execution_space::scratch_memory_space & scratchStorage,
466 const ordinal_type subcellDim,
467 const ordinal_type subcellOrdinal)
const {
469 INTREPID2_TEST_FOR_ABORT( !((subcellDim == -1) && (subcellOrdinal == -1)),
470 ">>> ERROR: (Intrepid2::Basis_HDIV_TRI_In_FEM::getValues), The capability of selecting subsets of basis functions has not been implemented yet.");
472 const int numPoints = inputPoints.extent(0);
473 using WorkViewType = Kokkos::DynRankView< scalarType, typename DT::execution_space::scratch_memory_space,Kokkos::MemoryTraits<Kokkos::Unmanaged> >;
474 ordinal_type scalarSizePerPoint = (operatorType == OPERATOR_VALUE) ? this->basisCardinality_ : 5*this->basisCardinality_;
475 ordinal_type sizePerPoint = scalarSizePerPoint*get_dimension_scalar(inputPoints);
476 WorkViewType workView(scratchStorage, sizePerPoint*team_member.team_size());
477 using range_type = Kokkos::pair<ordinal_type,ordinal_type>;
479 switch(operatorType) {
481 Kokkos::parallel_for (Kokkos::TeamThreadRange (team_member, numPoints), [=, &coeffs_ = this->coeffs_] (ordinal_type& pt) {
482 auto output = Kokkos::subview( outputValues, Kokkos::ALL(), range_type (pt,pt+1), Kokkos::ALL() );
483 const auto input = Kokkos::subview( inputPoints, range_type(pt, pt+1), Kokkos::ALL() );
484 WorkViewType work(workView.data() + sizePerPoint*team_member.team_rank(), sizePerPoint);
485 Impl::Basis_HDIV_TRI_In_FEM::Serial<OPERATOR_VALUE>::getValues( output, input, work, coeffs_ );
489 Kokkos::parallel_for (Kokkos::TeamThreadRange (team_member, numPoints), [=, &coeffs_ = this->coeffs_] (ordinal_type& pt) {
490 auto output = Kokkos::subview( outputValues, Kokkos::ALL(), range_type(pt,pt+1), Kokkos::ALL() );
491 const auto input = Kokkos::subview( inputPoints, range_type(pt,pt+1), Kokkos::ALL() );
492 WorkViewType work(workView.data() + sizePerPoint*team_member.team_rank(), sizePerPoint);
493 Impl::Basis_HDIV_TRI_In_FEM::Serial<OPERATOR_DIV>::getValues( output, input, work, coeffs_ );
497 INTREPID2_TEST_FOR_ABORT(
true,
498 ">>> ERROR (Basis_HDIV_TRI_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::CubatureDirectTrisymPos class.
Header file for the Intrepid2::Basis_HGRAD_TRI_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...
Kokkos::DynRankView< scalarType, DeviceType > coeffs_
expansion coefficients of the nodal basis in terms of the orthgonal one
Basis_HDIV_TRI_In_FEM(const ordinal_type order, const EPointType pointType=POINTTYPE_EQUISPACED)
Constructor.
EPointType pointType_
type of lattice used for creating the DoF coordinates
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.
static constexpr ordinal_type MaxOrder
The maximum reconstruction order.
See Intrepid2::Basis_HDIV_TRI_In_FEM.
See Intrepid2::Basis_HDIV_TRI_In_FEM.