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
35 Basis_HCURL_TRI_In_FEM::Serial<OpType>::
36 getValues( OutputViewType output,
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 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), dummyView;
64 Impl::Basis_HGRAD_TRI_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(k,j);
77 const ViewType phis(Kokkos::view_wrap(ptr, vcprop), card, npts, spaceDim);
78 ptr += card*npts*spaceDim*get_dimension_scalar(input);
79 const ViewType workView(Kokkos::view_wrap(ptr, vcprop), card, npts, spaceDim+1);
81 Impl::Basis_HGRAD_TRI_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 output.access(i,j) += - coeffs(k,i)*phis(k,j,1)
89 + coeffs(k+cardPn,i)*phis(k,j,0);
94 INTREPID2_TEST_FOR_ABORT(
true,
95 ">>> ERROR (Basis_HCURL_TRI_In_FEM): Operator type not implemented");
100 template<
typename DT, ordinal_type numPtsPerEval,
101 typename outputValueValueType,
class ...outputValueProperties,
102 typename inputPointValueType,
class ...inputPointProperties,
103 typename vinvValueType,
class ...vinvProperties>
105 Basis_HCURL_TRI_In_FEM::
106 getValues(
const typename DT::execution_space& space,
107 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(space, 0, loopSize);
122 typedef typename inputPointViewType::value_type inputPointType;
124 const ordinal_type cardinality = outputValues.extent(0);
125 const ordinal_type spaceDim = 2;
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(space,
"Basis_HCURL_TRI_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) );
138 case OPERATOR_CURL: {
139 workViewType work(Kokkos::view_alloc(space,
"Basis_HCURL_TRI_In_FEM::getValues::work", vcprop), cardinality*(2*spaceDim+1), inputPoints.extent(0));
140 typedef Functor<outputValueViewType,inputPointViewType,vinvViewType, workViewType,
141 OPERATOR_CURL,numPtsPerEval> FunctorType;
142 Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, coeffs, work) );
146 INTREPID2_TEST_FOR_EXCEPTION(
true , std::invalid_argument,
147 ">>> ERROR (Basis_HCURL_TRI_In_FEM): Operator type not implemented" );
154 template<
typename DT,
typename OT,
typename PT>
157 const EPointType pointType ) {
159 constexpr ordinal_type spaceDim = 2;
160 this->basisCardinality_ = CardinalityHCurlTri(order);
161 this->basisDegree_ = order;
162 this->basisCellTopologyKey_ = shards::Triangle<3>::key;
163 this->basisType_ = BASIS_FEM_LAGRANGIAN;
164 this->basisCoordinates_ = COORDINATES_CARTESIAN;
165 this->functionSpace_ = FUNCTION_SPACE_HCURL;
166 pointType_ = (pointType == POINTTYPE_DEFAULT) ? POINTTYPE_EQUISPACED : 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;
178 INTREPID2_TEST_FOR_EXCEPTION( order >
Parameters::MaxOrder, std::invalid_argument,
"polynomial order exceeds the max supported by this class");
181 constexpr ordinal_type tagSize = 4;
183 ordinal_type tags[maxCard][tagSize];
186 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
187 dofCoords(
"Hcurl::Tri::In::dofCoords", card, spaceDim);
189 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
190 coeffs(
"Hcurl::Tri::In::coeffs", cardVecPn, card);
192 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
193 dofCoeffs(
"Hcurl::Tri::In::dofCoeffs", card, spaceDim);
199 const ordinal_type lwork = card*card;
200 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
201 V1(
"Hcurl::Tri::In::V1", cardVecPn, card);
212 for (ordinal_type i=0;i<cardPnm1;i++)
213 for (ordinal_type d=0;d<spaceDim;d++)
214 V1(d*cardPn+i,d*cardPnm1+i) = 1.0;
220 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> cubPoints(
"Hcurl::Tri::In::cubPoints", myCub.
getNumPoints() , spaceDim );
221 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> cubWeights(
"Hcurl::Tri::In::cubWeights", myCub.
getNumPoints() );
225 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> phisAtCubPoints(
"Hcurl::Tri::In::phisAtCubPoints", cardPn , myCub.
getNumPoints() );
226 Impl::Basis_HGRAD_TRI_Cn_FEM_ORTH::getValues<Kokkos::HostSpace::execution_space,Parameters::MaxNumPtsPerBasisEval>(
typename Kokkos::HostSpace::execution_space{},
233 for (ordinal_type i=0;i<order;i++) {
234 for (ordinal_type j=0;j<cardPn;j++) {
236 V1(j,cardVecPnm1+i) -=
237 cubWeights(k) * cubPoints(k,1)
238 * phisAtCubPoints(cardPnm2+i,k)
239 * phisAtCubPoints(j,k);
240 V1(j+cardPn,cardVecPnm1+i) +=
241 cubWeights(k) * cubPoints(k,0)
242 * phisAtCubPoints(cardPnm2+i,k)
243 * phisAtCubPoints(j,k);
249 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
250 V2(
"Hcurl::Tri::In::V2", card ,cardVecPn);
252 const shards::CellTopology cellTopo(shards::getCellTopologyData<shards::Triangle<3>>());
253 const ordinal_type numEdges = cellTopo.getEdgeCount();
255 shards::CellTopology edgeTopo(shards::getCellTopologyData<shards::Line<2> >() );
263 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> linePts(
"Hcurl::Tri::In::linePts", numPtsPerEdge , 1 );
266 const ordinal_type offset = 1;
273 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> edgePts(
"Hcurl::Tri::In::edgePts", numPtsPerEdge , spaceDim );
274 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> phisAtEdgePoints(
"Hcurl::Tri::In::phisAtEdgePoints", cardPn , numPtsPerEdge );
275 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> edgeTan(
"Hcurl::Tri::In::edgeTan", spaceDim );
278 for (ordinal_type edge=0;edge<numEdges;edge++) {
289 Impl::Basis_HGRAD_TRI_Cn_FEM_ORTH::getValues<Kokkos::HostSpace::execution_space,Parameters::MaxNumPtsPerBasisEval>(
typename Kokkos::HostSpace::execution_space{},
296 for (ordinal_type j=0;j<numPtsPerEdge;j++) {
298 const ordinal_type i_card = numPtsPerEdge*edge+j;
301 for (ordinal_type k=0;k<cardPn;k++) {
302 V2(i_card,k) = edgeTan(0) * phisAtEdgePoints(k,j);
303 V2(i_card,k+cardPn) = edgeTan(1) * phisAtEdgePoints(k,j);
308 for(ordinal_type k=0; k<spaceDim; ++k) {
309 dofCoords(i_card,k) = edgePts(j,k);
310 dofCoeffs(i_card,k) = edgeTan(k);
314 tags[i_card][1] = edge;
316 tags[i_card][3] = numPtsPerEdge;
332 if (numPtsPerCell > 0) {
333 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
334 internalPoints(
"Hcurl::Tri::In::internalPoints", numPtsPerCell , spaceDim );
341 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
342 phisAtInternalPoints(
"Hcurl::Tri::In::phisAtInternalPoints", cardPn , numPtsPerCell );
343 Impl::Basis_HGRAD_TRI_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 = numEdges*order+spaceDim*j;
354 for (ordinal_type k=0;k<cardPn;k++) {
356 V2(i_card,k) = phisAtInternalPoints(k,j);
358 V2(i_card+1,cardPn+k) = phisAtInternalPoints(k,j);
362 for(ordinal_type d=0; d<spaceDim; ++d) {
363 for(ordinal_type dim=0; dim<spaceDim; ++dim) {
364 dofCoords(i_card+d,dim) = internalPoints(j,dim);
365 dofCoeffs(i_card+d,dim) = (d==dim);
368 tags[i_card+d][0] = spaceDim;
369 tags[i_card+d][1] = 0;
370 tags[i_card+d][2] = spaceDim*j+d;
371 tags[i_card+d][3] = spaceDim*numPtsPerCell;
378 Kokkos::DynRankView<scalarType,Kokkos::LayoutLeft,Kokkos::HostSpace>
379 vmat(
"Hcurl::Tri::In::vmat", card, card),
380 work(
"Hcurl::Tri::In::work", lwork),
381 ipiv(
"Hcurl::Tri::In::ipiv", card);
384 for(ordinal_type i=0; i< card; ++i) {
385 for(ordinal_type j=0; j< card; ++j) {
387 for(ordinal_type k=0; k< cardVecPn; ++k)
388 s += V2(i,k)*V1(k,j);
393 ordinal_type info = 0;
394 Teuchos::LAPACK<ordinal_type,scalarType> lapack;
396 lapack.GETRF(card, card,
397 vmat.data(), vmat.stride_1(),
398 (ordinal_type*)ipiv.data(),
401 INTREPID2_TEST_FOR_EXCEPTION( info != 0,
403 ">>> ERROR: (Intrepid2::Basis_HCURL_TRI_In_FEM) lapack.GETRF returns nonzero info." );
406 vmat.data(), vmat.stride_1(),
407 (ordinal_type*)ipiv.data(),
411 INTREPID2_TEST_FOR_EXCEPTION( info != 0,
413 ">>> ERROR: (Intrepid2::Basis_HCURL_TRI_In_FEM) lapack.GETRI returns nonzero info." );
415 for (ordinal_type i=0;i<cardVecPn;++i)
416 for (ordinal_type j=0;j<card;++j){
418 for(ordinal_type k=0; k< card; ++k)
419 s += V1(i,k)*vmat(k,j);
423 this->coeffs_ = Kokkos::create_mirror_view(
typename DT::memory_space(), coeffs);
424 Kokkos::deep_copy(this->coeffs_ , coeffs);
426 this->dofCoords_ = Kokkos::create_mirror_view(
typename DT::memory_space(), dofCoords);
427 Kokkos::deep_copy(this->dofCoords_, dofCoords);
429 this->dofCoeffs_ = Kokkos::create_mirror_view(
typename DT::memory_space(), dofCoeffs);
430 Kokkos::deep_copy(this->dofCoeffs_, dofCoeffs);
436 const ordinal_type posScDim = 0;
437 const ordinal_type posScOrd = 1;
438 const ordinal_type posDfOrd = 2;
444 this->setOrdinalTagData(this->tagToOrdinal_,
447 this->basisCardinality_,
455 template<
typename DT,
typename OT,
typename PT>
458 ordinal_type& perTeamSpaceSize,
459 ordinal_type& perThreadSpaceSize,
461 const EOperator operatorType)
const {
462 perTeamSpaceSize = 0;
463 ordinal_type scalarWorkViewExtent = (operatorType == OPERATOR_VALUE) ? this->basisCardinality_ : 5*this->basisCardinality_;
464 perThreadSpaceSize = scalarWorkViewExtent*get_dimension_scalar(inputPoints)*
sizeof(
typename BasisBase::scalarType);
467 template<
typename DT,
typename OT,
typename PT>
468 KOKKOS_INLINE_FUNCTION
471 OutputViewType outputValues,
472 const PointViewType inputPoints,
473 const EOperator operatorType,
474 const typename Kokkos::TeamPolicy<typename DT::execution_space>::member_type& team_member,
475 const typename DT::execution_space::scratch_memory_space & scratchStorage,
476 const ordinal_type subcellDim,
477 const ordinal_type subcellOrdinal)
const {
479 INTREPID2_TEST_FOR_ABORT( !((subcellDim == -1) && (subcellOrdinal == -1)),
480 ">>> ERROR: (Intrepid2::Basis_HCURL_TRI_In_FEM::getValues), The capability of selecting subsets of basis functions has not been implemented yet.");
482 const int numPoints = inputPoints.extent(0);
483 using ScalarType =
typename ScalarTraits<typename PointViewType::value_type>::scalar_type;
484 using WorkViewType = Kokkos::DynRankView< ScalarType,typename DT::execution_space::scratch_memory_space,Kokkos::MemoryTraits<Kokkos::Unmanaged> >;
485 ordinal_type scalarSizePerPoint = (operatorType == OPERATOR_VALUE) ? this->basisCardinality_ : 5*this->basisCardinality_;
486 ordinal_type sizePerPoint = scalarSizePerPoint*get_dimension_scalar(inputPoints);
487 WorkViewType workView(scratchStorage, sizePerPoint*team_member.team_size());
488 using range_type = Kokkos::pair<ordinal_type,ordinal_type>;
490 switch(operatorType) {
492 Kokkos::parallel_for (Kokkos::TeamThreadRange (team_member, numPoints), [=] (ordinal_type& pt) {
493 auto output = Kokkos::subview( outputValues, Kokkos::ALL(), range_type (pt,pt+1), Kokkos::ALL() );
494 const auto input = Kokkos::subview( inputPoints, range_type(pt, pt+1), Kokkos::ALL() );
495 WorkViewType work(workView.data() + sizePerPoint*team_member.team_rank(), sizePerPoint);
500 Kokkos::parallel_for (Kokkos::TeamThreadRange (team_member, numPoints), [=] (ordinal_type& pt) {
501 auto output = Kokkos::subview( outputValues, Kokkos::ALL(), range_type(pt,pt+1), Kokkos::ALL() );
502 const auto input = Kokkos::subview( inputPoints, range_type(pt,pt+1), Kokkos::ALL() );
503 WorkViewType work(workView.data() + sizePerPoint*team_member.team_rank(), sizePerPoint);
504 Impl::Basis_HCURL_TRI_In_FEM::Serial<OPERATOR_CURL>::getValues( output, input, work, this->coeffs_ );
508 INTREPID2_TEST_FOR_ABORT(
true,
509 ">>> ERROR (Basis_HCURL_TRI_In_FEM): getValues not implemented for this operator");
ScalarTraits< pointValueType >::scalar_type scalarType
Scalar type for point values.
virtual void getValues(const ExecutionSpace &space, OutputViewType outputValues, const PointViewType inputPoints, const EOperator operatorType=OPERATOR_VALUE) const override
Evaluation of a FEM basis on a reference cell.
Header file for the Intrepid2::Basis_HGRAD_TRI_Cn_FEM_ORTH class.
virtual void getCubature(PointViewType cubPoints, weightViewType cubWeights) const override
Returns cubature points and weights (return arrays must be pre-sized/pre-allocated).
Kokkos::View< ordinal_type *, typename ExecutionSpace::array_layout, Kokkos::HostSpace > OrdinalTypeArray1DHost
View type for 1d host array.
Basis_HCURL_TRI_In_FEM(const ordinal_type order, const EPointType pointType=POINTTYPE_EQUISPACED)
Constructor.
virtual ordinal_type getNumPoints() const override
Returns the number of cubature points.
virtual void getScratchSpaceSize(ordinal_type &perTeamSpaceSize, ordinal_type &perThreadSpaceSize, const PointViewType inputPointsconst, const EOperator operatorType=OPERATOR_VALUE) const override
Return the size of the scratch space, in bytes, needed for using the team-level implementation of get...
Header file for the Intrepid2::CubatureDirectTrisymPos class.
See Intrepid2::Basis_HCURL_TRI_In_FEM.
Kokkos::DynRankView< PointValueType, Kokkos::LayoutStride, DeviceType > PointViewType
View type for input points.
ScalarTraits< pointValueType >::scalar_type scalarType
Scalar type for point values.
static constexpr ordinal_type MaxOrder
The maximum reconstruction order.