16 #ifndef __INTREPID2_HDIV_TRI_IN_FEM_DEF_HPP__
17 #define __INTREPID2_HDIV_TRI_IN_FEM_DEF_HPP__
27 template<EOperator OpType>
28 template<
typename OutputViewType,
29 typename InputViewType,
30 typename WorkViewType,
31 typename VinvViewType>
32 KOKKOS_INLINE_FUNCTION
34 Basis_HDIV_TRI_In_FEM::Serial<OpType>::
35 getValues( OutputViewType output,
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 vcprop = Kokkos::common_view_alloc_prop(input);
57 auto ptr = work.data();
60 case OPERATOR_VALUE: {
61 const ViewType phis(Kokkos::view_wrap(ptr, vcprop), card, npts);
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.access(k,j);
77 const ViewType phis(Kokkos::view_wrap(ptr, vcprop), card, npts, spaceDim);
78 ptr += card*npts*spaceDim*get_dimension_scalar(work);
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 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_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_HDIV_TRI_In_FEM::
106 getValues( 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 typedef typename inputPointViewType::value_type inputPointType;
123 const ordinal_type cardinality = outputValues.extent(0);
124 const ordinal_type spaceDim = 2;
126 auto vcprop = Kokkos::common_view_alloc_prop(inputPoints);
127 typedef typename Kokkos::DynRankView< inputPointType, typename inputPointViewType::memory_space> workViewType;
129 switch (operatorType) {
130 case OPERATOR_VALUE: {
131 workViewType work(Kokkos::view_alloc(
"Basis_HDIV_TRI_In_FEM::getValues::work", vcprop), cardinality, inputPoints.extent(0));
132 typedef Functor<outputValueViewType,inputPointViewType,vinvViewType, workViewType,
133 OPERATOR_VALUE,numPtsPerEval> FunctorType;
134 Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, coeffs, work) );
138 workViewType work(Kokkos::view_alloc(
"Basis_HDIV_TRI_In_FEM::getValues::work", vcprop), cardinality*(2*spaceDim+1), inputPoints.extent(0));
139 typedef Functor<outputValueViewType,inputPointViewType,vinvViewType, workViewType,
140 OPERATOR_DIV,numPtsPerEval> FunctorType;
141 Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, coeffs, work) );
145 INTREPID2_TEST_FOR_EXCEPTION(
true , std::invalid_argument,
146 ">>> ERROR (Basis_HDIV_TRI_In_FEM): Operator type not implemented" );
153 template<
typename DT,
typename OT,
typename PT>
156 const EPointType pointType ) {
159 INTREPID2_TEST_FOR_EXCEPTION( order >
Parameters::MaxOrder, std::invalid_argument,
"polynomial order exceeds the max supported by this class");
161 constexpr ordinal_type spaceDim = 2;
162 this->basisCardinality_ = CardinalityHDivTri(order);
163 this->basisDegree_ = order;
164 this->basisCellTopologyKey_ = shards::Triangle<3>::key;
165 this->basisType_ = BASIS_FEM_LAGRANGIAN;
166 this->basisCoordinates_ = COORDINATES_CARTESIAN;
167 this->functionSpace_ = FUNCTION_SPACE_HDIV;
168 pointType_ = (pointType == POINTTYPE_DEFAULT) ? POINTTYPE_EQUISPACED : pointType;
170 const ordinal_type card = this->basisCardinality_;
172 const ordinal_type cardPn = Intrepid2::getPnCardinality<spaceDim>(order);
173 const ordinal_type cardPnm1 = Intrepid2::getPnCardinality<spaceDim>(order-1);
174 const ordinal_type cardPnm2 = Intrepid2::getPnCardinality<spaceDim>(order-2);
175 const ordinal_type cardVecPn = spaceDim*cardPn;
176 const ordinal_type cardVecPnm1 = spaceDim*cardPnm1;
180 constexpr ordinal_type tagSize = 4;
182 ordinal_type tags[maxCard][tagSize];
185 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
186 dofCoords(
"Hdiv::Tri::In::dofCoords", card, spaceDim);
188 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
189 dofCoeffs(
"Hdiv::Tri::In::dofCoeffs", card, spaceDim);
191 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
192 coeffs(
"Hdiv::Tri::In::coeffs", cardVecPn, card);
198 const ordinal_type lwork = card*card;
199 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
200 V1(
"Hdiv::Tri::In::V1", cardVecPn, card);
210 for (ordinal_type i=0;i<cardPnm1;i++) {
212 V1(cardPn+i,cardPnm1+i) = 1.0;
218 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> cubPoints(
"Hdiv::Tri::In::cubPoints", myCub.
getNumPoints() , spaceDim );
219 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> cubWeights(
"Hdiv::Tri::In::cubWeights", myCub.
getNumPoints() );
223 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> phisAtCubPoints(
"Hdiv::Tri::In::phisAtCubPoints", cardPn , myCub.
getNumPoints() );
224 Impl::Basis_HGRAD_TRI_Cn_FEM_ORTH::getValues<Kokkos::HostSpace::execution_space,Parameters::MaxNumPtsPerBasisEval>(
typename Kokkos::HostSpace::execution_space{},
231 for (ordinal_type i=0;i<order;i++) {
232 for (ordinal_type j=0;j<cardPn;j++) {
233 V1(j,cardVecPnm1+i) = 0.0;
234 for (ordinal_type d=0; d< spaceDim; ++d)
236 V1(j+d*cardPn,cardVecPnm1+i) +=
237 cubWeights(k) * cubPoints(k,d)
238 * phisAtCubPoints(cardPnm2+i,k)
239 * phisAtCubPoints(j,k);
245 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
246 V2(
"Hdiv::Tri::In::V2", card ,cardVecPn);
248 const shards::CellTopology cellTopo(shards::getCellTopologyData<shards::Triangle<3>>());
249 const ordinal_type numEdges = cellTopo.getEdgeCount();
250 shards::CellTopology edgeTopo(shards::getCellTopologyData<shards::Line<2> >() );
258 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> linePts(
"Hdiv::Tri::In::linePts", numPtsPerEdge , 1 );
261 const ordinal_type offset = 1;
268 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> edgePts(
"Hdiv::Tri::In::edgePts", numPtsPerEdge , spaceDim );
269 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> phisAtEdgePoints(
"Hdiv::Tri::In::phisAtEdgePoints", cardPn , numPtsPerEdge );
270 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> edgeNormal(
"Hcurl::Tri::In::edgeNormal", spaceDim );
273 for (ordinal_type edge=0;edge<numEdges;edge++) {
284 Impl::Basis_HGRAD_TRI_Cn_FEM_ORTH::getValues<Kokkos::HostSpace::execution_space,Parameters::MaxNumPtsPerBasisEval>(
typename Kokkos::HostSpace::execution_space{},
291 for (ordinal_type j=0;j<numPtsPerEdge;j++) {
293 const ordinal_type i_card = numPtsPerEdge*edge+j;
296 for (ordinal_type k=0;k<cardPn;k++) {
298 for (ordinal_type l=0; l<spaceDim; l++)
299 V2(i_card,k+l*cardPn) = edgeNormal(l) * phisAtEdgePoints(k,j);
304 for(ordinal_type l=0; l<spaceDim; ++l) {
305 dofCoords(i_card,l) = edgePts(j,l);
306 dofCoeffs(i_card,l) = edgeNormal(l);
310 tags[i_card][1] = edge;
312 tags[i_card][3] = numPtsPerEdge;
329 if (numPtsPerCell > 0) {
330 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
331 internalPoints(
"Hdiv::Tri::In::internalPoints", numPtsPerCell , spaceDim );
338 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
339 phisAtInternalPoints(
"Hdiv::Tri::In::phisAtInternalPoints", cardPn , numPtsPerCell );
340 Impl::Basis_HGRAD_TRI_Cn_FEM_ORTH::getValues<Kokkos::HostSpace::execution_space,Parameters::MaxNumPtsPerBasisEval>(
typename Kokkos::HostSpace::execution_space{},
341 phisAtInternalPoints,
347 for (ordinal_type j=0;j<numPtsPerCell;j++) {
349 const ordinal_type i_card = numEdges*order+spaceDim*j;
351 for (ordinal_type k=0;k<cardPn;k++) {
352 for (ordinal_type l=0;l<spaceDim;l++) {
353 V2(i_card+l,l*cardPn+k) = phisAtInternalPoints(k,j);
358 for(ordinal_type d=0; d<spaceDim; ++d) {
359 for(ordinal_type l=0; l<spaceDim; ++l) {
360 dofCoords(i_card+d,l) = internalPoints(j,l);
361 dofCoeffs(i_card+d,l) = (l==d);
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(
"Hdiv::Tri::In::vmat", card, card),
376 work(
"Hdiv::Tri::In::work", lwork),
377 ipiv(
"Hdiv::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_HDIV_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_HDIV_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;
436 OrdinalTypeArray1DHost tagView(&tags[0][0], card*tagSize);
440 this->setOrdinalTagData(this->tagToOrdinal_,
443 this->basisCardinality_,
451 template<
typename DT,
typename OT,
typename PT>
454 ordinal_type& perTeamSpaceSize,
455 ordinal_type& perThreadSpaceSize,
456 const PointViewType inputPoints,
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(scalarType);
463 template<
typename DT,
typename OT,
typename PT>
464 KOKKOS_INLINE_FUNCTION
466 Basis_HDIV_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_HDIV_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 WorkViewType = Kokkos::DynRankView< scalarType, typename DT::execution_space::scratch_memory_space,Kokkos::MemoryTraits<Kokkos::Unmanaged> >;
480 ordinal_type scalarSizePerPoint = (operatorType == OPERATOR_VALUE) ? this->basisCardinality_ : 5*this->basisCardinality_;
481 ordinal_type sizePerPoint = scalarSizePerPoint*get_dimension_scalar(inputPoints);
482 WorkViewType workView(scratchStorage, sizePerPoint*team_member.team_size());
483 using range_type = Kokkos::pair<ordinal_type,ordinal_type>;
485 switch(operatorType) {
487 Kokkos::parallel_for (Kokkos::TeamThreadRange (team_member, numPoints), [=] (ordinal_type& pt) {
488 auto output = Kokkos::subview( outputValues, Kokkos::ALL(), range_type (pt,pt+1), Kokkos::ALL() );
489 const auto input = Kokkos::subview( inputPoints, range_type(pt, pt+1), Kokkos::ALL() );
490 WorkViewType work(workView.data() + sizePerPoint*team_member.team_rank(), sizePerPoint);
491 Impl::Basis_HDIV_TRI_In_FEM::Serial<OPERATOR_VALUE>::getValues( output, input, work, this->coeffs_ );
495 Kokkos::parallel_for (Kokkos::TeamThreadRange (team_member, numPoints), [=] (ordinal_type& pt) {
496 auto output = Kokkos::subview( outputValues, Kokkos::ALL(), range_type(pt,pt+1), Kokkos::ALL() );
497 const auto input = Kokkos::subview( inputPoints, range_type(pt,pt+1), Kokkos::ALL() );
498 WorkViewType work(workView.data() + sizePerPoint*team_member.team_rank(), sizePerPoint);
499 Impl::Basis_HDIV_TRI_In_FEM::Serial<OPERATOR_DIV>::getValues( output, input, work, this->coeffs_ );
503 INTREPID2_TEST_FOR_ABORT(
true,
504 ">>> ERROR (Basis_HDIV_TRI_In_FEM): getValues not implemented for this operator");
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).
virtual ordinal_type getNumPoints() const override
Returns the number of cubature points.
Header file for the Intrepid2::CubatureDirectTrisymPos class.
Implementation of the default H(div)-compatible Raviart-Thomas basis of arbitrary degree on Triangle ...
static constexpr ordinal_type MaxOrder
The maximum reconstruction order.
Basis_HDIV_TRI_In_FEM(const ordinal_type order, const EPointType pointType=POINTTYPE_EQUISPACED)
Constructor.