16#ifndef __INTREPID2_HCURL_TRI_IN_FEM_DEF_HPP__
17#define __INTREPID2_HCURL_TRI_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
37 const InputViewType input,
39 const VinvViewType coeffs ) {
41 constexpr ordinal_type spaceDim = 2;
43 cardPn = coeffs.extent(0)/spaceDim,
44 card = coeffs.extent(1),
45 npts = input.extent(0);
48 ordinal_type order = 0;
50 if (card == CardinalityHCurlTri(p)) {
56 typedef typename Kokkos::DynRankView<typename InputViewType::value_type, typename WorkViewType::memory_space> ViewType;
57 auto ptr = work.data();
60 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(k,j);
77 ptr += card*npts*spaceDim*get_dimension_scalar(input);
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 output.access(i,j) += - coeffs(k,i)*phis(k,j,1)
88 + coeffs(k+cardPn,i)*phis(k,j,0);
93 INTREPID2_TEST_FOR_ABORT(
true,
94 ">>> ERROR (Basis_HCURL_TRI_In_FEM): Operator type not implemented");
99 template<
typename DT, ordinal_type numPtsPerEval,
100 typename outputValueValueType,
class ...outputValueProperties,
101 typename inputPointValueType,
class ...inputPointProperties,
102 typename vinvValueType,
class ...vinvProperties>
104 Basis_HCURL_TRI_In_FEM::
105 getValues(
const typename DT::execution_space& space,
106 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(space, 0, loopSize);
123 const ordinal_type cardinality = outputValues.extent(0);
124 const ordinal_type spaceDim = 2;
126 switch (operatorType) {
127 case OPERATOR_VALUE: {
128 auto work =
createMatchingDynRankView(inputPoints,
"Basis_HCURL_TRI_In_FEM::getValues::work", cardinality, inputPoints.extent(0));
129 typedef Functor<outputValueViewType,inputPointViewType,vinvViewType,
decltype(work),
130 OPERATOR_VALUE,numPtsPerEval> FunctorType;
131 Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, coeffs, work) );
134 case OPERATOR_CURL: {
135 auto work =
createMatchingDynRankView(inputPoints,
"Basis_HCURL_TRI_In_FEM::getValues::work", cardinality*(2*spaceDim+1), inputPoints.extent(0));
136 typedef Functor<outputValueViewType,inputPointViewType,vinvViewType,
decltype(work),
137 OPERATOR_CURL,numPtsPerEval> FunctorType;
138 Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, coeffs, work) );
142 INTREPID2_TEST_FOR_EXCEPTION(
true , std::invalid_argument,
143 ">>> ERROR (Basis_HCURL_TRI_In_FEM): Operator type not implemented" );
150 template<
typename DT,
typename OT,
typename PT>
153 const EPointType pointType ) {
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 INTREPID2_TEST_FOR_EXCEPTION( order >
Parameters::MaxOrder, std::invalid_argument,
"polynomial order exceeds the max supported by this class");
177 constexpr ordinal_type tagSize = 4;
179 ordinal_type tags[maxCard][tagSize];
182 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
183 dofCoords(
"Hcurl::Tri::In::dofCoords", card, spaceDim);
185 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
186 coeffs(
"Hcurl::Tri::In::coeffs", cardVecPn, card);
188 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
189 dofCoeffs(
"Hcurl::Tri::In::dofCoeffs", card, spaceDim);
195 const ordinal_type lwork = card*card;
196 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
197 V1(
"Hcurl::Tri::In::V1", cardVecPn, card);
208 for (ordinal_type i=0;i<cardPnm1;i++)
209 for (ordinal_type d=0;d<spaceDim;d++)
210 V1(d*cardPn+i,d*cardPnm1+i) = 1.0;
216 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> cubPoints(
"Hcurl::Tri::In::cubPoints", myCub.
getNumPoints() , spaceDim );
217 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> cubWeights(
"Hcurl::Tri::In::cubWeights", myCub.
getNumPoints() );
218 myCub.getCubature( cubPoints , cubWeights );
221 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> phisAtCubPoints(
"Hcurl::Tri::In::phisAtCubPoints", cardPn , myCub.
getNumPoints() );
222 Impl::Basis_HGRAD_TRI_Cn_FEM_ORTH::getValues<Kokkos::HostSpace::execution_space,Parameters::MaxNumPtsPerBasisEval>(
typename Kokkos::HostSpace::execution_space{},
229 for (ordinal_type i=0;i<order;i++) {
230 for (ordinal_type j=0;j<cardPn;j++) {
232 V1(j,cardVecPnm1+i) -=
233 cubWeights(k) * cubPoints(k,1)
234 * phisAtCubPoints(cardPnm2+i,k)
235 * phisAtCubPoints(j,k);
236 V1(j+cardPn,cardVecPnm1+i) +=
237 cubWeights(k) * cubPoints(k,0)
238 * phisAtCubPoints(cardPnm2+i,k)
239 * phisAtCubPoints(j,k);
245 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
246 V2(
"Hcurl::Tri::In::V2", card ,cardVecPn);
248 const shards::CellTopology cellTopo(shards::getCellTopologyData<shards::Triangle<3>>());
249 const ordinal_type numEdges = cellTopo.getEdgeCount();
251 shards::CellTopology edgeTopo(shards::getCellTopologyData<shards::Line<2> >() );
259 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> linePts(
"Hcurl::Tri::In::linePts", numPtsPerEdge , 1 );
262 const ordinal_type offset = 1;
269 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> edgePts(
"Hcurl::Tri::In::edgePts", numPtsPerEdge , spaceDim );
270 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> phisAtEdgePoints(
"Hcurl::Tri::In::phisAtEdgePoints", cardPn , numPtsPerEdge );
271 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> edgeTan(
"Hcurl::Tri::In::edgeTan", spaceDim );
274 for (ordinal_type edge=0;edge<numEdges;edge++) {
285 Impl::Basis_HGRAD_TRI_Cn_FEM_ORTH::getValues<Kokkos::HostSpace::execution_space,Parameters::MaxNumPtsPerBasisEval>(
typename Kokkos::HostSpace::execution_space{},
292 for (ordinal_type j=0;j<numPtsPerEdge;j++) {
294 const ordinal_type i_card = numPtsPerEdge*edge+j;
297 for (ordinal_type k=0;k<cardPn;k++) {
298 V2(i_card,k) = edgeTan(0) * phisAtEdgePoints(k,j);
299 V2(i_card,k+cardPn) = edgeTan(1) * phisAtEdgePoints(k,j);
304 for(ordinal_type k=0; k<spaceDim; ++k) {
305 dofCoords(i_card,k) = edgePts(j,k);
306 dofCoeffs(i_card,k) = edgeTan(k);
310 tags[i_card][1] = edge;
312 tags[i_card][3] = numPtsPerEdge;
328 if (numPtsPerCell > 0) {
329 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
330 internalPoints(
"Hcurl::Tri::In::internalPoints", numPtsPerCell , spaceDim );
337 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
338 phisAtInternalPoints(
"Hcurl::Tri::In::phisAtInternalPoints", cardPn , numPtsPerCell );
339 Impl::Basis_HGRAD_TRI_Cn_FEM_ORTH::getValues<Kokkos::HostSpace::execution_space,Parameters::MaxNumPtsPerBasisEval>(
typename Kokkos::HostSpace::execution_space{},
340 phisAtInternalPoints,
346 for (ordinal_type j=0;j<numPtsPerCell;j++) {
348 const ordinal_type i_card = numEdges*order+spaceDim*j;
350 for (ordinal_type k=0;k<cardPn;k++) {
352 V2(i_card,k) = phisAtInternalPoints(k,j);
354 V2(i_card+1,cardPn+k) = phisAtInternalPoints(k,j);
358 for(ordinal_type d=0; d<spaceDim; ++d) {
359 for(ordinal_type dim=0; dim<spaceDim; ++dim) {
360 dofCoords(i_card+d,dim) = internalPoints(j,dim);
361 dofCoeffs(i_card+d,dim) = (d==dim);
364 tags[i_card+d][0] = spaceDim;
365 tags[i_card+d][1] = 0;
366 tags[i_card+d][2] = spaceDim*j+d;
367 tags[i_card+d][3] = spaceDim*numPtsPerCell;
374 Kokkos::DynRankView<scalarType,Kokkos::LayoutLeft,Kokkos::HostSpace>
375 vmat(
"Hcurl::Tri::In::vmat", card, card),
376 work(
"Hcurl::Tri::In::work", lwork),
377 ipiv(
"Hcurl::Tri::In::ipiv", card);
380 for(ordinal_type i=0; i< card; ++i) {
381 for(ordinal_type j=0; j< card; ++j) {
383 for(ordinal_type k=0; k< cardVecPn; ++k)
384 s += V2(i,k)*V1(k,j);
389 ordinal_type info = 0;
390 Teuchos::LAPACK<ordinal_type,scalarType> lapack;
392 lapack.GETRF(card, card,
393 vmat.data(), vmat.stride(1),
394 (ordinal_type*)ipiv.data(),
397 INTREPID2_TEST_FOR_EXCEPTION( info != 0,
399 ">>> ERROR: (Intrepid2::Basis_HCURL_TRI_In_FEM) lapack.GETRF returns nonzero info." );
402 vmat.data(), vmat.stride(1),
403 (ordinal_type*)ipiv.data(),
407 INTREPID2_TEST_FOR_EXCEPTION( info != 0,
409 ">>> ERROR: (Intrepid2::Basis_HCURL_TRI_In_FEM) lapack.GETRI returns nonzero info." );
411 for (ordinal_type i=0;i<cardVecPn;++i)
412 for (ordinal_type j=0;j<card;++j){
414 for(ordinal_type k=0; k< card; ++k)
415 s += V1(i,k)*vmat(k,j);
419 this->
coeffs_ = Kokkos::create_mirror_view(
typename DT::memory_space(), coeffs);
420 Kokkos::deep_copy(this->
coeffs_ , coeffs);
422 this->
dofCoords_ = Kokkos::create_mirror_view(
typename DT::memory_space(), dofCoords);
423 Kokkos::deep_copy(this->
dofCoords_, dofCoords);
425 this->
dofCoeffs_ = Kokkos::create_mirror_view(
typename DT::memory_space(), dofCoeffs);
426 Kokkos::deep_copy(this->
dofCoeffs_, dofCoeffs);
432 const ordinal_type posScDim = 0;
433 const ordinal_type posScOrd = 1;
434 const ordinal_type posDfOrd = 2;
451 template<
typename DT,
typename OT,
typename PT>
453 Basis_HCURL_TRI_In_FEM<DT,OT,PT>::getScratchSpaceSize(
454 ordinal_type& perTeamSpaceSize,
455 ordinal_type& perThreadSpaceSize,
457 const EOperator operatorType)
const {
458 perTeamSpaceSize = 0;
459 ordinal_type scalarWorkViewExtent = (operatorType == OPERATOR_VALUE) ? this->basisCardinality_ : 5*this->basisCardinality_;
460 perThreadSpaceSize = scalarWorkViewExtent*get_dimension_scalar(inputPoints)*
sizeof(
typename BasisBase::scalarType);
463 template<
typename DT,
typename OT,
typename PT>
464 KOKKOS_INLINE_FUNCTION
466 Basis_HCURL_TRI_In_FEM<DT,OT,PT>::getValues(
467 OutputViewType outputValues,
468 const PointViewType inputPoints,
469 const EOperator operatorType,
470 const typename Kokkos::TeamPolicy<typename DT::execution_space>::member_type& team_member,
471 const typename DT::execution_space::scratch_memory_space & scratchStorage,
472 const ordinal_type subcellDim,
473 const ordinal_type subcellOrdinal)
const {
475 INTREPID2_TEST_FOR_ABORT( !((subcellDim == -1) && (subcellOrdinal == -1)),
476 ">>> ERROR: (Intrepid2::Basis_HCURL_TRI_In_FEM::getValues), The capability of selecting subsets of basis functions has not been implemented yet.");
478 const int numPoints = inputPoints.extent(0);
479 using ScalarType =
typename ScalarTraits<typename PointViewType::value_type>::scalar_type;
480 using WorkViewType = Kokkos::DynRankView< ScalarType,typename DT::execution_space::scratch_memory_space,Kokkos::MemoryTraits<Kokkos::Unmanaged> >;
481 ordinal_type scalarSizePerPoint = (operatorType == OPERATOR_VALUE) ? this->basisCardinality_ : 5*this->basisCardinality_;
482 ordinal_type sizePerPoint = scalarSizePerPoint*get_dimension_scalar(inputPoints);
483 WorkViewType workView(scratchStorage, sizePerPoint*team_member.team_size());
484 using range_type = Kokkos::pair<ordinal_type,ordinal_type>;
486 switch(operatorType) {
488 Kokkos::parallel_for (Kokkos::TeamThreadRange (team_member, numPoints), [=, &coeffs_ = this->coeffs_] (ordinal_type& pt) {
489 auto output = Kokkos::subview( outputValues, Kokkos::ALL(), range_type (pt,pt+1), Kokkos::ALL() );
490 const auto input = Kokkos::subview( inputPoints, range_type(pt, pt+1), Kokkos::ALL() );
491 WorkViewType work(workView.data() + sizePerPoint*team_member.team_rank(), sizePerPoint);
492 Impl::Basis_HCURL_TRI_In_FEM::Serial<OPERATOR_VALUE>::getValues( output, input, work, coeffs_ );
496 Kokkos::parallel_for (Kokkos::TeamThreadRange (team_member, numPoints), [=, &coeffs_ = this->coeffs_] (ordinal_type& pt) {
497 auto output = Kokkos::subview( outputValues, Kokkos::ALL(), range_type(pt,pt+1), Kokkos::ALL() );
498 const auto input = Kokkos::subview( inputPoints, range_type(pt,pt+1), Kokkos::ALL() );
499 WorkViewType work(workView.data() + sizePerPoint*team_member.team_rank(), sizePerPoint);
500 Impl::Basis_HCURL_TRI_In_FEM::Serial<OPERATOR_CURL>::getValues( output, input, work, coeffs_ );
504 INTREPID2_TEST_FOR_ABORT(
true,
505 ">>> ERROR (Basis_HCURL_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_HCURL_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_
ScalarTraits< double >::scalar_type scalarType
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.
static constexpr ordinal_type MaxOrder
The maximum reconstruction order.
See Intrepid2::Basis_HCURL_TRI_In_FEM.
See Intrepid2::Basis_HCURL_TRI_In_FEM.