16 #ifndef __INTREPID2_HGRAD_TET_CN_FEM_DEF_HPP__
17 #define __INTREPID2_HGRAD_TET_CN_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_HGRAD_TET_Cn_FEM::Serial<OpType>::
35 getValues( OutputViewType output,
36 const InputViewType input,
38 const VinvViewType vinv,
39 const ordinal_type order ) {
41 constexpr ordinal_type spaceDim = 3;
43 card = vinv.extent(0),
44 npts = input.extent(0);
46 typedef typename Kokkos::DynRankView<typename InputViewType::value_type, typename WorkViewType::memory_space> ViewType;
47 auto vcprop = Kokkos::common_view_alloc_prop(input);
48 auto ptr = work.data();
51 case OPERATOR_VALUE: {
52 const ViewType phis(Kokkos::view_wrap(ptr, vcprop), card, npts);
55 Impl::Basis_HGRAD_TET_Cn_FEM_ORTH::
56 Serial<OpType>::getValues(phis, input, dummyView, order);
58 for (ordinal_type i=0;i<card;++i)
59 for (ordinal_type j=0;j<npts;++j) {
60 output.access(i,j) = 0.0;
61 for (ordinal_type k=0;k<card;++k)
62 output.access(i,j) += vinv(k,i)*phis.access(k,j);
68 const ViewType phis(Kokkos::view_wrap(ptr, vcprop), card, npts, spaceDim);
69 ptr += card*npts*spaceDim*get_dimension_scalar(input);
70 const ViewType workView(Kokkos::view_wrap(ptr, vcprop), card, npts, spaceDim+1);
71 Impl::Basis_HGRAD_TET_Cn_FEM_ORTH::
72 Serial<OpType>::getValues(phis, input, workView, order);
74 for (ordinal_type i=0;i<card;++i)
75 for (ordinal_type j=0;j<npts;++j)
76 for (ordinal_type k=0;k<spaceDim;++k) {
77 output.access(i,j,k) = 0.0;
78 for (ordinal_type l=0;l<card;++l)
79 output.access(i,j,k) += vinv(l,i)*phis.access(l,j,k);
92 const ordinal_type dkcard = getDkCardinality<OpType,spaceDim>();
93 const ViewType phis(Kokkos::view_wrap(ptr, vcprop), card, npts, dkcard);
96 Impl::Basis_HGRAD_TET_Cn_FEM_ORTH::
97 Serial<OpType>::getValues(phis, input, dummyView, order);
99 for (ordinal_type i=0;i<card;++i)
100 for (ordinal_type j=0;j<npts;++j)
101 for (ordinal_type k=0;k<dkcard;++k) {
102 output.access(i,j,k) = 0.0;
103 for (ordinal_type l=0;l<card;++l)
104 output.access(i,j,k) += vinv(l,i)*phis.access(l,j,k);
109 INTREPID2_TEST_FOR_ABORT(
true,
110 ">>> ERROR (Basis_HGRAD_TET_Cn_FEM): Operator type not implemented");
115 template<
typename DT, ordinal_type numPtsPerEval,
116 typename outputValueValueType,
class ...outputValueProperties,
117 typename inputPointValueType,
class ...inputPointProperties,
118 typename vinvValueType,
class ...vinvProperties>
120 Basis_HGRAD_TET_Cn_FEM::
122 const typename DT::execution_space& space,
123 Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValues,
124 const Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPoints,
125 const Kokkos::DynRankView<vinvValueType, vinvProperties...> vinv,
126 const ordinal_type order,
127 const EOperator operatorType) {
128 typedef Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValueViewType;
129 typedef Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPointViewType;
130 typedef Kokkos::DynRankView<vinvValueType, vinvProperties...> vinvViewType;
131 typedef typename ExecSpace<typename inputPointViewType::execution_space,typename DT::execution_space>::ExecSpaceType ExecSpaceType;
134 const auto loopSizeTmp1 = (inputPoints.extent(0)/numPtsPerEval);
135 const auto loopSizeTmp2 = (inputPoints.extent(0)%numPtsPerEval != 0);
136 const auto loopSize = loopSizeTmp1 + loopSizeTmp2;
137 Kokkos::RangePolicy<ExecSpaceType,Kokkos::Schedule<Kokkos::Static> > policy(space, 0, loopSize);
139 typedef typename inputPointViewType::value_type inputPointType;
141 const ordinal_type cardinality = outputValues.extent(0);
142 const ordinal_type spaceDim = 3;
144 auto vcprop = Kokkos::common_view_alloc_prop(inputPoints);
145 typedef typename Kokkos::DynRankView< inputPointType, typename inputPointViewType::memory_space> workViewType;
147 switch (operatorType) {
148 case OPERATOR_VALUE: {
149 workViewType work(Kokkos::view_alloc(space,
"Basis_HGRAD_TET_Cn_FEM::getValues::work", vcprop), cardinality, inputPoints.extent(0));
150 typedef Functor<outputValueViewType,inputPointViewType,vinvViewType, workViewType,
151 OPERATOR_VALUE,numPtsPerEval> FunctorType;
152 Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, vinv, work, order) );
157 workViewType work(Kokkos::view_alloc(space,
"Basis_HGRAD_TET_Cn_FEM::getValues::work", vcprop), cardinality*(2*spaceDim+1), inputPoints.extent(0));
158 typedef Functor<outputValueViewType,inputPointViewType,vinvViewType, workViewType,
159 OPERATOR_D1,numPtsPerEval> FunctorType;
160 Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, vinv, work, order) );
164 typedef Functor<outputValueViewType,inputPointViewType,vinvViewType, workViewType,
165 OPERATOR_D2,numPtsPerEval> FunctorType;
166 workViewType work(Kokkos::view_alloc(space,
"Basis_HGRAD_TET_Cn_FEM::getValues::work", vcprop), cardinality*outputValues.extent(2), inputPoints.extent(0));
167 Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, vinv, work, order) );
171 INTREPID2_TEST_FOR_EXCEPTION(
true , std::invalid_argument,
172 ">>> ERROR (Basis_HGRAD_TET_Cn_FEM): Operator type not implemented" );
179 template<
typename DT,
typename OT,
typename PT>
182 const EPointType pointType ) {
183 constexpr ordinal_type spaceDim = 3;
185 this->basisCardinality_ = Intrepid2::getPnCardinality<spaceDim>(order);
186 this->basisDegree_ = order;
187 this->basisCellTopologyKey_ = shards::Tetrahedron<4>::key;
188 this->basisType_ = BASIS_FEM_LAGRANGIAN;
189 this->basisCoordinates_ = COORDINATES_CARTESIAN;
190 this->functionSpace_ = FUNCTION_SPACE_HGRAD;
191 pointType_ = (pointType == POINTTYPE_DEFAULT) ? POINTTYPE_EQUISPACED : pointType;
193 const ordinal_type card = this->basisCardinality_;
196 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
197 dofCoords(
"Hgrad::Tet::Cn::dofCoords", card, spaceDim);
201 INTREPID2_TEST_FOR_EXCEPTION( order >
Parameters::MaxOrder, std::invalid_argument,
"polynomial order exceeds the max supported by this class");
204 constexpr ordinal_type tagSize = 4;
205 constexpr ordinal_type maxCard = Intrepid2::getPnCardinality<spaceDim, Parameters::MaxOrder>();
206 ordinal_type tags[maxCard][tagSize];
210 shards::CellTopology cellTopo(shards::getCellTopologyData<shards::Tetrahedron<4> >() );
211 const ordinal_type numEdges = cellTopo.getEdgeCount();
212 const ordinal_type numFaces = cellTopo.getFaceCount();
214 shards::CellTopology edgeTopo(shards::getCellTopologyData<shards::Line<2> >() );
215 shards::CellTopology faceTopo(shards::getCellTopologyData<shards::Triangle<3> >() );
233 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> vertexes(
"Hcurl::Tet::In::vertexes", numVertexes , spaceDim );
234 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> linePts(
"Hcurl::Tet::In::linePts", numPtsPerEdge , 1 );
235 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> triPts(
"Hcurl::Tet::In::triPts", numPtsPerFace , 2 );
238 const ordinal_type offset = 1;
257 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> edgePts(
"Hcurl::Tet::In::edgePts", numPtsPerEdge , spaceDim );
258 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> facePts(
"Hcurl::Tet::In::facePts", numPtsPerFace , spaceDim );
260 for (ordinal_type i=0;i<numVertexes;i++) {
262 for(ordinal_type k=0; k<spaceDim; ++k)
263 dofCoords(i_card,k) = vertexes(i,k);
272 for (ordinal_type i=0;i<numEdges;i++) {
281 for (ordinal_type j=0;j<numPtsPerEdge;j++) {
283 const ordinal_type i_card = numVertexes + numPtsPerEdge*i+j;
286 for(ordinal_type k=0; k<spaceDim; ++k)
287 dofCoords(i_card,k) = edgePts(j,k);
292 tags[i_card][3] = numPtsPerEdge;
297 if(numPtsPerFace >0) {
299 for (ordinal_type i=0;i<numFaces;i++) {
306 for (ordinal_type j=0;j<numPtsPerFace;j++) {
308 const ordinal_type i_card = numVertexes+numEdges*numPtsPerEdge+numPtsPerFace*i+j;
311 for(ordinal_type k=0; k<spaceDim; ++k)
312 dofCoords(i_card,k) = facePts(j,k);
317 tags[i_card][3] = numPtsPerFace;
324 if (numPtsPerCell > 0) {
325 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
326 cellPoints(
"Hcurl::Tet::In::cellPoints", numPtsPerCell , spaceDim );
334 for (ordinal_type j=0;j<numPtsPerCell;j++) {
336 const ordinal_type i_card = numVertexes+numEdges*numPtsPerEdge+numFaces*numPtsPerFace+j;
339 for(ordinal_type dim=0; dim<spaceDim; ++dim)
340 dofCoords(i_card,dim) = cellPoints(j,dim);
342 tags[i_card][0] = spaceDim;
345 tags[i_card][3] = numPtsPerCell;
349 this->dofCoords_ = Kokkos::create_mirror_view(
typename DT::memory_space(), dofCoords);
350 Kokkos::deep_copy(this->dofCoords_, dofCoords);
354 const ordinal_type lwork = card*card;
355 Kokkos::DynRankView<scalarType,Kokkos::LayoutLeft,Kokkos::HostSpace>
356 vmat(
"Hgrad::Tet::Cn::vmat", card, card),
357 work(
"Hgrad::Tet::Cn::work", lwork),
358 ipiv(
"Hgrad::Tet::Cn::ipiv", card);
360 Impl::Basis_HGRAD_TET_Cn_FEM_ORTH::getValues<Kokkos::HostSpace::execution_space,Parameters::MaxNumPtsPerBasisEval>(
typename Kokkos::HostSpace::execution_space{},
366 ordinal_type info = 0;
367 Teuchos::LAPACK<ordinal_type,scalarType> lapack;
369 lapack.GETRF(card, card,
370 vmat.data(), vmat.stride_1(),
371 (ordinal_type*)ipiv.data(),
374 INTREPID2_TEST_FOR_EXCEPTION( info != 0,
376 ">>> ERROR: (Intrepid2::Basis_HGRAD_TET_Cn_FEM) lapack.GETRF returns nonzero info." );
379 vmat.data(), vmat.stride_1(),
380 (ordinal_type*)ipiv.data(),
384 INTREPID2_TEST_FOR_EXCEPTION( info != 0,
386 ">>> ERROR: (Intrepid2::Basis_HGRAD_TET_Cn_FEM) lapack.GETRI returns nonzero info." );
389 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
390 vinv(
"Hgrad::Line::Cn::vinv", card, card);
392 for (ordinal_type i=0;i<card;++i)
393 for (ordinal_type j=0;j<card;++j)
394 vinv(i,j) = vmat(j,i);
396 this->vinv_ = Kokkos::create_mirror_view(
typename DT::memory_space(), vinv);
397 Kokkos::deep_copy(this->vinv_ , vinv);
402 const ordinal_type posScDim = 0;
403 const ordinal_type posScOrd = 1;
404 const ordinal_type posDfOrd = 2;
410 this->setOrdinalTagData(this->tagToOrdinal_,
413 this->basisCardinality_,
421 template<
typename DT,
typename OT,
typename PT>
424 ordinal_type& perTeamSpaceSize,
425 ordinal_type& perThreadSpaceSize,
427 const EOperator operatorType)
const {
428 perTeamSpaceSize = 0;
429 perThreadSpaceSize = getWorkSizePerPoint(operatorType)*get_dimension_scalar(inputPoints)*
sizeof(
typename BasisBase::scalarType);
432 template<
typename DT,
typename OT,
typename PT>
433 KOKKOS_INLINE_FUNCTION
436 OutputViewType outputValues,
437 const PointViewType inputPoints,
438 const EOperator operatorType,
439 const typename Kokkos::TeamPolicy<typename DT::execution_space>::member_type& team_member,
440 const typename DT::execution_space::scratch_memory_space & scratchStorage,
441 const ordinal_type subcellDim,
442 const ordinal_type subcellOrdinal)
const {
444 INTREPID2_TEST_FOR_ABORT( !((subcellDim == -1) && (subcellOrdinal == -1)),
445 ">>> ERROR: (Intrepid2::Basis_HGRAD_TET_Cn_FEM::getValues), The capability of selecting subsets of basis functions has not been implemented yet.");
447 const int numPoints = inputPoints.extent(0);
448 using ScalarType =
typename ScalarTraits<typename PointViewType::value_type>::scalar_type;
449 using WorkViewType = Kokkos::DynRankView< ScalarType,typename DT::execution_space::scratch_memory_space,Kokkos::MemoryTraits<Kokkos::Unmanaged> >;
450 constexpr ordinal_type spaceDim = 3;
451 auto sizePerPoint = (operatorType==OPERATOR_VALUE) ?
452 this->vinv_.extent(0)*get_dimension_scalar(inputPoints) :
453 (2*spaceDim+1)*this->vinv_.extent(0)*get_dimension_scalar(inputPoints);
454 WorkViewType workView(scratchStorage, sizePerPoint*team_member.team_size());
455 using range_type = Kokkos::pair<ordinal_type,ordinal_type>;
456 switch(operatorType) {
458 Kokkos::parallel_for (Kokkos::TeamThreadRange (team_member, numPoints), [=] (ordinal_type& pt) {
459 auto output = Kokkos::subview( outputValues, Kokkos::ALL(), range_type (pt,pt+1), Kokkos::ALL() );
460 const auto input = Kokkos::subview( inputPoints, range_type(pt, pt+1), Kokkos::ALL() );
461 WorkViewType work(workView.data() + sizePerPoint*team_member.team_rank(), sizePerPoint);
466 Kokkos::parallel_for (Kokkos::TeamThreadRange (team_member, numPoints), [=] (ordinal_type& pt) {
467 auto output = Kokkos::subview( outputValues, Kokkos::ALL(), range_type(pt,pt+1), Kokkos::ALL() );
468 const auto input = Kokkos::subview( inputPoints, range_type(pt,pt+1), Kokkos::ALL() );
469 WorkViewType work(workView.data() + sizePerPoint*team_member.team_rank(), sizePerPoint);
470 Impl::Basis_HGRAD_TET_Cn_FEM::Serial<OPERATOR_GRAD>::getValues( output, input, work, this->vinv_, this->basisDegree_);
474 INTREPID2_TEST_FOR_ABORT(
true,
475 ">>> ERROR (Basis_HGRAD_TET_Cn_FEM): getValues not implemented for this operator");
ScalarTraits< pointValueType >::scalar_type scalarType
Scalar type for point values.
Kokkos::DynRankView< PointValueType, Kokkos::LayoutStride, DeviceType > PointViewType
View type for input points.
See Intrepid2::Basis_HGRAD_TET_Cn_FEM.
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.
Kokkos::View< ordinal_type *, typename ExecutionSpace::array_layout, Kokkos::HostSpace > OrdinalTypeArray1DHost
View type for 1d host array.
Header file for the Intrepid2::Basis_HGRAD_TET_Cn_FEM class.
virtual void getScratchSpaceSize(ordinal_type &perTeamSpaceSize, ordinal_type &perThreadSpaceSize, const PointViewType inputPoints, 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...
Basis_HGRAD_TET_Cn_FEM(const ordinal_type order, const EPointType pointType=POINTTYPE_EQUISPACED)
Constructor.
Header file for the Intrepid2::Basis_HGRAD_TET_Cn_FEM_ORTH class.
static constexpr ordinal_type MaxOrder
The maximum reconstruction order.