49 #ifndef __INTREPID2_HDIV_TRI_IN_FEM_DEF_HPP__ 50 #define __INTREPID2_HDIV_TRI_IN_FEM_DEF_HPP__ 60 template<EOperator opType>
61 template<
typename OutputViewType,
62 typename inputViewType,
63 typename workViewType,
64 typename vinvViewType>
65 KOKKOS_INLINE_FUNCTION
67 Basis_HDIV_TRI_In_FEM::Serial<opType>::
68 getValues( OutputViewType output,
69 const inputViewType input,
71 const vinvViewType coeffs ) {
73 constexpr ordinal_type spaceDim = 2;
75 cardPn = coeffs.extent(0)/spaceDim,
76 card = coeffs.extent(1),
77 npts = input.extent(0);
80 ordinal_type order = 0;
82 if (card == CardinalityHDivTri(p)) {
88 typedef typename Kokkos::DynRankView<typename workViewType::value_type, typename workViewType::memory_space> viewType;
89 auto vcprop = Kokkos::common_view_alloc_prop(work);
90 auto ptr = work.data();
93 case OPERATOR_VALUE: {
94 const viewType phis(Kokkos::view_wrap(ptr, vcprop), card, npts);
95 workViewType dummyView;
97 Impl::Basis_HGRAD_TRI_Cn_FEM_ORTH::
98 Serial<opType>::getValues(phis, input, dummyView, order);
100 for (ordinal_type i=0;i<card;++i)
101 for (ordinal_type j=0;j<npts;++j)
102 for (ordinal_type d=0;d<spaceDim;++d) {
103 output.access(i,j,d) = 0.0;
104 for (ordinal_type k=0;k<cardPn;++k)
105 output.access(i,j,d) += coeffs(k+d*cardPn,i) * phis.access(k,j);
110 const viewType phis(Kokkos::view_wrap(ptr, vcprop), card, npts, spaceDim);
111 ptr += card*npts*spaceDim*get_dimension_scalar(work);
112 const viewType workView(Kokkos::view_wrap(ptr, vcprop), card, npts, spaceDim+1);
114 Impl::Basis_HGRAD_TRI_Cn_FEM_ORTH::
115 Serial<OPERATOR_GRAD>::getValues(phis, input, workView, order);
117 for (ordinal_type i=0;i<card;++i)
118 for (ordinal_type j=0;j<npts;++j) {
119 output.access(i,j) = 0.0;
120 for (ordinal_type k=0; k<cardPn; ++k)
121 for (ordinal_type d=0; d<spaceDim; ++d)
122 output.access(i,j) += coeffs(k+d*cardPn,i)*phis.access(k,j,d);
127 INTREPID2_TEST_FOR_ABORT(
true,
128 ">>> ERROR (Basis_HDIV_TRI_In_FEM): Operator type not implemented");
133 template<
typename DT, ordinal_type numPtsPerEval,
134 typename outputValueValueType,
class ...outputValueProperties,
135 typename inputPointValueType,
class ...inputPointProperties,
136 typename vinvValueType,
class ...vinvProperties>
138 Basis_HDIV_TRI_In_FEM::
139 getValues( Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValues,
140 const Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPoints,
141 const Kokkos::DynRankView<vinvValueType, vinvProperties...> coeffs,
142 const EOperator operatorType) {
143 typedef Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValueViewType;
144 typedef Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPointViewType;
145 typedef Kokkos::DynRankView<vinvValueType, vinvProperties...> vinvViewType;
146 typedef typename ExecSpace<typename inputPointViewType::execution_space,typename DT::execution_space>::ExecSpaceType ExecSpaceType;
149 const auto loopSizeTmp1 = (inputPoints.extent(0)/numPtsPerEval);
150 const auto loopSizeTmp2 = (inputPoints.extent(0)%numPtsPerEval != 0);
151 const auto loopSize = loopSizeTmp1 + loopSizeTmp2;
152 Kokkos::RangePolicy<ExecSpaceType,Kokkos::Schedule<Kokkos::Static> > policy(0, loopSize);
154 typedef typename inputPointViewType::value_type inputPointType;
156 const ordinal_type cardinality = outputValues.extent(0);
157 const ordinal_type spaceDim = 2;
159 auto vcprop = Kokkos::common_view_alloc_prop(inputPoints);
160 typedef typename Kokkos::DynRankView< inputPointType, typename inputPointViewType::memory_space> workViewType;
162 switch (operatorType) {
163 case OPERATOR_VALUE: {
164 workViewType work(Kokkos::view_alloc(
"Basis_HDIV_TRI_In_FEM::getValues::work", vcprop), cardinality, inputPoints.extent(0));
165 typedef Functor<outputValueViewType,inputPointViewType,vinvViewType, workViewType,
166 OPERATOR_VALUE,numPtsPerEval> FunctorType;
167 Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, coeffs, work) );
171 workViewType work(Kokkos::view_alloc(
"Basis_HDIV_TRI_In_FEM::getValues::work", vcprop), cardinality*(2*spaceDim+1), inputPoints.extent(0));
172 typedef Functor<outputValueViewType,inputPointViewType,vinvViewType, workViewType,
173 OPERATOR_DIV,numPtsPerEval> FunctorType;
174 Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, coeffs, work) );
178 INTREPID2_TEST_FOR_EXCEPTION(
true , std::invalid_argument,
179 ">>> ERROR (Basis_HDIV_TRI_In_FEM): Operator type not implemented" );
186 template<
typename DT,
typename OT,
typename PT>
190 INTREPID2_TEST_FOR_EXCEPTION(order >
Parameters::MaxOrder, std::invalid_argument,
"Unsupported polynomial order");
192 constexpr ordinal_type spaceDim = 2;
193 this->basisCardinality_ = CardinalityHDivTri(order);
194 this->basisDegree_ = order;
195 this->basisCellTopology_ = shards::CellTopology(shards::getCellTopologyData<shards::Triangle<3> >() );
196 this->basisType_ = BASIS_FEM_LAGRANGIAN;
197 this->basisCoordinates_ = COORDINATES_CARTESIAN;
198 this->functionSpace_ = FUNCTION_SPACE_HDIV;
199 pointType_ = pointType;
201 const ordinal_type card = this->basisCardinality_;
203 const ordinal_type cardPn = Intrepid2::getPnCardinality<spaceDim>(order);
204 const ordinal_type cardPnm1 = Intrepid2::getPnCardinality<spaceDim>(order-1);
205 const ordinal_type cardPnm2 = Intrepid2::getPnCardinality<spaceDim>(order-2);
206 const ordinal_type cardVecPn = spaceDim*cardPn;
207 const ordinal_type cardVecPnm1 = spaceDim*cardPnm1;
211 constexpr ordinal_type tagSize = 4;
213 ordinal_type tags[maxCard][tagSize];
216 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
217 dofCoords(
"Hdiv::Tri::In::dofCoords", card, spaceDim);
219 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
220 dofCoeffs(
"Hdiv::Tri::In::dofCoeffs", card, spaceDim);
222 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
223 coeffs(
"Hdiv::Tri::In::coeffs", cardVecPn, card);
229 const ordinal_type lwork = card*card;
230 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
231 V1(
"Hdiv::Tri::In::V1", cardVecPn, card);
241 for (ordinal_type i=0;i<cardPnm1;i++) {
243 V1(cardPn+i,cardPnm1+i) = 1.0;
249 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> cubPoints(
"Hdiv::Tri::In::cubPoints", myCub.
getNumPoints() , spaceDim );
250 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> cubWeights(
"Hdiv::Tri::In::cubWeights", myCub.
getNumPoints() );
254 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> phisAtCubPoints(
"Hdiv::Tri::In::phisAtCubPoints", cardPn , myCub.
getNumPoints() );
255 Impl::Basis_HGRAD_TRI_Cn_FEM_ORTH::getValues<Kokkos::HostSpace::execution_space,Parameters::MaxNumPtsPerBasisEval>(phisAtCubPoints, cubPoints, order, OPERATOR_VALUE);
258 for (ordinal_type i=0;i<order;i++) {
259 for (ordinal_type j=0;j<cardPn;j++) {
260 V1(j,cardVecPnm1+i) = 0.0;
261 for (ordinal_type d=0; d< spaceDim; ++d)
263 V1(j+d*cardPn,cardVecPnm1+i) +=
264 cubWeights(k) * cubPoints(k,d)
265 * phisAtCubPoints(cardPnm2+i,k)
266 * phisAtCubPoints(j,k);
272 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
273 V2(
"Hdiv::Tri::In::V2", card ,cardVecPn);
275 const ordinal_type numEdges = this->basisCellTopology_.getEdgeCount();
277 shards::CellTopology edgeTop(shards::getCellTopologyData<shards::Line<2> >() );
285 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> linePts(
"Hdiv::Tri::In::linePts", numPtsPerEdge , 1 );
288 const ordinal_type offset = 1;
295 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> edgePts(
"Hdiv::Tri::In::edgePts", numPtsPerEdge , spaceDim );
296 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> phisAtEdgePoints(
"Hdiv::Tri::In::phisAtEdgePoints", cardPn , numPtsPerEdge );
297 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> edgeNormal(
"Hcurl::Tri::In::edgeNormal", spaceDim );
300 for (ordinal_type edge=0;edge<numEdges;edge++) {
303 this->basisCellTopology_ );
309 this->basisCellTopology_ );
311 Impl::Basis_HGRAD_TRI_Cn_FEM_ORTH::getValues<Kokkos::HostSpace::execution_space,Parameters::MaxNumPtsPerBasisEval>(phisAtEdgePoints , edgePts, order, OPERATOR_VALUE);
314 for (ordinal_type j=0;j<numPtsPerEdge;j++) {
316 const ordinal_type i_card = numPtsPerEdge*edge+j;
319 for (ordinal_type k=0;k<cardPn;k++) {
321 for (ordinal_type l=0; l<spaceDim; l++)
322 V2(i_card,k+l*cardPn) = edgeNormal(l) * phisAtEdgePoints(k,j);
327 for(ordinal_type l=0; l<spaceDim; ++l) {
328 dofCoords(i_card,l) = edgePts(j,l);
329 dofCoeffs(i_card,l) = edgeNormal(l);
333 tags[i_card][1] = edge;
335 tags[i_card][3] = numPtsPerEdge;
352 if (numPtsPerCell > 0) {
353 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
354 internalPoints(
"Hdiv::Tri::In::internalPoints", numPtsPerCell , spaceDim );
356 this->basisCellTopology_ ,
361 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
362 phisAtInternalPoints(
"Hdiv::Tri::In::phisAtInternalPoints", cardPn , numPtsPerCell );
363 Impl::Basis_HGRAD_TRI_Cn_FEM_ORTH::getValues<Kokkos::HostSpace::execution_space,Parameters::MaxNumPtsPerBasisEval>( phisAtInternalPoints , internalPoints , order, OPERATOR_VALUE );
366 for (ordinal_type j=0;j<numPtsPerCell;j++) {
368 const ordinal_type i_card = numEdges*order+spaceDim*j;
370 for (ordinal_type k=0;k<cardPn;k++) {
371 for (ordinal_type l=0;l<spaceDim;l++) {
372 V2(i_card+l,l*cardPn+k) = phisAtInternalPoints(k,j);
377 for(ordinal_type d=0; d<spaceDim; ++d) {
378 for(ordinal_type l=0; l<spaceDim; ++l) {
379 dofCoords(i_card+d,l) = internalPoints(j,l);
380 dofCoeffs(i_card+d,l) = (l==d);
383 tags[i_card+d][0] = spaceDim;
384 tags[i_card+d][1] = 0;
385 tags[i_card+d][2] = spaceDim*j+d;
386 tags[i_card+d][3] = spaceDim*numPtsPerCell;
393 Kokkos::DynRankView<scalarType,Kokkos::LayoutLeft,Kokkos::HostSpace>
394 vmat(
"Hdiv::Tri::In::vmat", card, card),
395 work(
"Hdiv::Tri::In::work", lwork),
396 ipiv(
"Hdiv::Tri::In::ipiv", card);
399 for(ordinal_type i=0; i< card; ++i) {
400 for(ordinal_type j=0; j< card; ++j) {
402 for(ordinal_type k=0; k< cardVecPn; ++k)
403 s += V2(i,k)*V1(k,j);
408 ordinal_type info = 0;
409 Teuchos::LAPACK<ordinal_type,scalarType> lapack;
411 lapack.GETRF(card, card,
412 vmat.data(), vmat.stride_1(),
413 (ordinal_type*)ipiv.data(),
416 INTREPID2_TEST_FOR_EXCEPTION( info != 0,
418 ">>> ERROR: (Intrepid2::Basis_HDIV_TRI_In_FEM) lapack.GETRF returns nonzero info." );
421 vmat.data(), vmat.stride_1(),
422 (ordinal_type*)ipiv.data(),
426 INTREPID2_TEST_FOR_EXCEPTION( info != 0,
428 ">>> ERROR: (Intrepid2::Basis_HDIV_TRI_In_FEM) lapack.GETRI returns nonzero info." );
430 for (ordinal_type i=0;i<cardVecPn;++i)
431 for (ordinal_type j=0;j<card;++j){
433 for(ordinal_type k=0; k< card; ++k)
434 s += V1(i,k)*vmat(k,j);
438 this->coeffs_ = Kokkos::create_mirror_view(
typename DT::memory_space(), coeffs);
439 Kokkos::deep_copy(this->coeffs_ , coeffs);
441 this->dofCoords_ = Kokkos::create_mirror_view(
typename DT::memory_space(), dofCoords);
442 Kokkos::deep_copy(this->dofCoords_, dofCoords);
444 this->dofCoeffs_ = Kokkos::create_mirror_view(
typename DT::memory_space(), dofCoeffs);
445 Kokkos::deep_copy(this->dofCoeffs_, dofCoeffs);
451 const ordinal_type posScDim = 0;
452 const ordinal_type posScOrd = 1;
453 const ordinal_type posDfOrd = 2;
455 OrdinalTypeArray1DHost tagView(&tags[0][0], card*tagSize);
459 this->setOrdinalTagData(this->tagToOrdinal_,
462 this->basisCardinality_,
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).
Header file for the Intrepid2::CubatureDirectTriDefault class.
Defines direct integration rules on a triangle.
virtual ordinal_type getNumPoints() const override
Returns the number of cubature points.
EPointType
Enumeration of types of point distributions in Intrepid.
static constexpr ordinal_type MaxOrder
The maximum reconstruction order.
Basis_HDIV_TRI_In_FEM(const ordinal_type order, const EPointType pointType=POINTTYPE_EQUISPACED)
Constructor.