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);
76 for (ordinal_type j=0;j<npts;++j)
77 for (ordinal_type k=0;k<spaceDim;++k)
78 for (ordinal_type i=0;i<card;++i)
80 output.access(i,j,k) = 0.0;
81 for (ordinal_type l=0;l<card;++l)
82 output.access(i,j,k) += vinv(l,i)*phis.access(l,j,k);
95 const ordinal_type dkcard = getDkCardinality<OpType,spaceDim>();
96 const ViewType phis(Kokkos::view_wrap(ptr, vcprop), card, npts, dkcard);
99 Impl::Basis_HGRAD_TET_Cn_FEM_ORTH::
100 Serial<OpType>::getValues(phis, input, dummyView, order);
102 for (ordinal_type i=0;i<card;++i)
103 for (ordinal_type j=0;j<npts;++j)
104 for (ordinal_type k=0;k<dkcard;++k) {
105 output.access(i,j,k) = 0.0;
106 for (ordinal_type l=0;l<card;++l)
107 output.access(i,j,k) += vinv(l,i)*phis.access(l,j,k);
112 INTREPID2_TEST_FOR_ABORT(
true,
113 ">>> ERROR (Basis_HGRAD_TET_Cn_FEM): Operator type not implemented");
118 template<
typename DT, ordinal_type numPtsPerEval,
119 typename outputValueValueType,
class ...outputValueProperties,
120 typename inputPointValueType,
class ...inputPointProperties,
121 typename vinvValueType,
class ...vinvProperties>
123 Basis_HGRAD_TET_Cn_FEM::
125 const typename DT::execution_space& space,
126 Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValues,
127 const Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPoints,
128 const Kokkos::DynRankView<vinvValueType, vinvProperties...> vinv,
129 const ordinal_type order,
130 const EOperator operatorType) {
131 typedef Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValueViewType;
132 typedef Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPointViewType;
133 typedef Kokkos::DynRankView<vinvValueType, vinvProperties...> vinvViewType;
134 typedef typename ExecSpace<typename inputPointViewType::execution_space,typename DT::execution_space>::ExecSpaceType ExecSpaceType;
137 const auto loopSizeTmp1 = (inputPoints.extent(0)/numPtsPerEval);
138 const auto loopSizeTmp2 = (inputPoints.extent(0)%numPtsPerEval != 0);
139 const auto loopSize = loopSizeTmp1 + loopSizeTmp2;
140 Kokkos::RangePolicy<ExecSpaceType,Kokkos::Schedule<Kokkos::Static> > policy(space, 0, loopSize);
142 typedef typename inputPointViewType::value_type inputPointType;
144 const ordinal_type cardinality = outputValues.extent(0);
145 const ordinal_type spaceDim = 3;
147 auto vcprop = Kokkos::common_view_alloc_prop(inputPoints);
148 typedef typename Kokkos::DynRankView< inputPointType, typename inputPointViewType::memory_space> workViewType;
150 switch (operatorType) {
151 case OPERATOR_VALUE: {
152 workViewType work(Kokkos::view_alloc(space,
"Basis_HGRAD_TET_Cn_FEM::getValues::work", vcprop), cardinality, inputPoints.extent(0));
153 typedef Functor<outputValueViewType,inputPointViewType,vinvViewType, workViewType,
154 OPERATOR_VALUE,numPtsPerEval> FunctorType;
155 Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, vinv, work, order) );
160 workViewType work(Kokkos::view_alloc(space,
"Basis_HGRAD_TET_Cn_FEM::getValues::work", vcprop), cardinality*(2*spaceDim+1), inputPoints.extent(0));
161 typedef Functor<outputValueViewType,inputPointViewType,vinvViewType, workViewType,
162 OPERATOR_D1,numPtsPerEval> FunctorType;
163 Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, vinv, work, order) );
167 typedef Functor<outputValueViewType,inputPointViewType,vinvViewType, workViewType,
168 OPERATOR_D2,numPtsPerEval> FunctorType;
169 workViewType work(Kokkos::view_alloc(space,
"Basis_HGRAD_TET_Cn_FEM::getValues::work", vcprop), cardinality*outputValues.extent(2), inputPoints.extent(0));
170 Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, vinv, work, order) );
174 INTREPID2_TEST_FOR_EXCEPTION(
true , std::invalid_argument,
175 ">>> ERROR (Basis_HGRAD_TET_Cn_FEM): Operator type not implemented" );
182 template<
typename DT,
typename OT,
typename PT>
185 const EPointType pointType ) {
186 constexpr ordinal_type spaceDim = 3;
188 this->basisCardinality_ = Intrepid2::getPnCardinality<spaceDim>(order);
189 this->basisDegree_ = order;
190 this->basisCellTopologyKey_ = shards::Tetrahedron<4>::key;
191 this->basisType_ = BASIS_FEM_LAGRANGIAN;
192 this->basisCoordinates_ = COORDINATES_CARTESIAN;
193 this->functionSpace_ = FUNCTION_SPACE_HGRAD;
194 pointType_ = (pointType == POINTTYPE_DEFAULT) ? POINTTYPE_EQUISPACED : pointType;
196 const ordinal_type card = this->basisCardinality_;
199 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
200 dofCoords(
"Hgrad::Tet::Cn::dofCoords", card, spaceDim);
204 INTREPID2_TEST_FOR_EXCEPTION( order >
Parameters::MaxOrder, std::invalid_argument,
"polynomial order exceeds the max supported by this class");
207 constexpr ordinal_type tagSize = 4;
208 constexpr ordinal_type maxCard = Intrepid2::getPnCardinality<spaceDim, Parameters::MaxOrder>();
209 ordinal_type tags[maxCard][tagSize];
213 shards::CellTopology cellTopo(shards::getCellTopologyData<shards::Tetrahedron<4> >() );
214 const ordinal_type numEdges = cellTopo.getEdgeCount();
215 const ordinal_type numFaces = cellTopo.getFaceCount();
217 shards::CellTopology edgeTopo(shards::getCellTopologyData<shards::Line<2> >() );
218 shards::CellTopology faceTopo(shards::getCellTopologyData<shards::Triangle<3> >() );
236 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> vertexes(
"Hcurl::Tet::In::vertexes", numVertexes , spaceDim );
237 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> linePts(
"Hcurl::Tet::In::linePts", numPtsPerEdge , 1 );
238 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> triPts(
"Hcurl::Tet::In::triPts", numPtsPerFace , 2 );
241 const ordinal_type offset = 1;
260 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> edgePts(
"Hcurl::Tet::In::edgePts", numPtsPerEdge , spaceDim );
261 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> facePts(
"Hcurl::Tet::In::facePts", numPtsPerFace , spaceDim );
263 for (ordinal_type i=0;i<numVertexes;i++) {
265 for(ordinal_type k=0; k<spaceDim; ++k)
266 dofCoords(i_card,k) = vertexes(i,k);
275 for (ordinal_type i=0;i<numEdges;i++) {
284 for (ordinal_type j=0;j<numPtsPerEdge;j++) {
286 const ordinal_type i_card = numVertexes + numPtsPerEdge*i+j;
289 for(ordinal_type k=0; k<spaceDim; ++k)
290 dofCoords(i_card,k) = edgePts(j,k);
295 tags[i_card][3] = numPtsPerEdge;
300 if(numPtsPerFace >0) {
302 for (ordinal_type i=0;i<numFaces;i++) {
309 for (ordinal_type j=0;j<numPtsPerFace;j++) {
311 const ordinal_type i_card = numVertexes+numEdges*numPtsPerEdge+numPtsPerFace*i+j;
314 for(ordinal_type k=0; k<spaceDim; ++k)
315 dofCoords(i_card,k) = facePts(j,k);
320 tags[i_card][3] = numPtsPerFace;
327 if (numPtsPerCell > 0) {
328 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
329 cellPoints(
"Hcurl::Tet::In::cellPoints", numPtsPerCell , spaceDim );
337 for (ordinal_type j=0;j<numPtsPerCell;j++) {
339 const ordinal_type i_card = numVertexes+numEdges*numPtsPerEdge+numFaces*numPtsPerFace+j;
342 for(ordinal_type dim=0; dim<spaceDim; ++dim)
343 dofCoords(i_card,dim) = cellPoints(j,dim);
345 tags[i_card][0] = spaceDim;
348 tags[i_card][3] = numPtsPerCell;
352 this->dofCoords_ = Kokkos::create_mirror_view(
typename DT::memory_space(), dofCoords);
353 Kokkos::deep_copy(this->dofCoords_, dofCoords);
357 const ordinal_type lwork = card*card;
358 Kokkos::DynRankView<scalarType,Kokkos::LayoutLeft,Kokkos::HostSpace>
359 vmat(
"Hgrad::Tet::Cn::vmat", card, card),
360 work(
"Hgrad::Tet::Cn::work", lwork),
361 ipiv(
"Hgrad::Tet::Cn::ipiv", card);
363 Impl::Basis_HGRAD_TET_Cn_FEM_ORTH::getValues<Kokkos::HostSpace::execution_space,Parameters::MaxNumPtsPerBasisEval>(
typename Kokkos::HostSpace::execution_space{},
369 ordinal_type info = 0;
370 Teuchos::LAPACK<ordinal_type,scalarType> lapack;
372 lapack.GETRF(card, card,
373 vmat.data(), vmat.stride_1(),
374 (ordinal_type*)ipiv.data(),
377 INTREPID2_TEST_FOR_EXCEPTION( info != 0,
379 ">>> ERROR: (Intrepid2::Basis_HGRAD_TET_Cn_FEM) lapack.GETRF returns nonzero info." );
382 vmat.data(), vmat.stride_1(),
383 (ordinal_type*)ipiv.data(),
387 INTREPID2_TEST_FOR_EXCEPTION( info != 0,
389 ">>> ERROR: (Intrepid2::Basis_HGRAD_TET_Cn_FEM) lapack.GETRI returns nonzero info." );
392 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
393 vinv(
"Hgrad::Line::Cn::vinv", card, card);
395 for (ordinal_type i=0;i<card;++i)
396 for (ordinal_type j=0;j<card;++j)
397 vinv(i,j) = vmat(j,i);
399 this->vinv_ = Kokkos::create_mirror_view(
typename DT::memory_space(), vinv);
400 Kokkos::deep_copy(this->vinv_ , vinv);
405 const ordinal_type posScDim = 0;
406 const ordinal_type posScOrd = 1;
407 const ordinal_type posDfOrd = 2;
413 this->setOrdinalTagData(this->tagToOrdinal_,
416 this->basisCardinality_,
424 template<
typename DT,
typename OT,
typename PT>
427 ordinal_type& perTeamSpaceSize,
428 ordinal_type& perThreadSpaceSize,
430 const EOperator operatorType)
const {
431 perTeamSpaceSize = 0;
432 perThreadSpaceSize = getWorkSizePerPoint(operatorType)*get_dimension_scalar(inputPoints)*
sizeof(
typename BasisBase::scalarType);
435 template<
typename DT,
typename OT,
typename PT>
436 KOKKOS_INLINE_FUNCTION
439 OutputViewType outputValues,
440 const PointViewType inputPoints,
441 const EOperator operatorType,
442 const typename Kokkos::TeamPolicy<typename DT::execution_space>::member_type& team_member,
443 const typename DT::execution_space::scratch_memory_space & scratchStorage,
444 const ordinal_type subcellDim,
445 const ordinal_type subcellOrdinal)
const {
447 INTREPID2_TEST_FOR_ABORT( !((subcellDim == -1) && (subcellOrdinal == -1)),
448 ">>> ERROR: (Intrepid2::Basis_HGRAD_TET_Cn_FEM::getValues), The capability of selecting subsets of basis functions has not been implemented yet.");
450 const int numPoints = inputPoints.extent(0);
451 using ScalarType =
typename ScalarTraits<typename PointViewType::value_type>::scalar_type;
452 using WorkViewType = Kokkos::DynRankView< ScalarType,typename DT::execution_space::scratch_memory_space,Kokkos::MemoryTraits<Kokkos::Unmanaged> >;
453 constexpr ordinal_type spaceDim = 3;
454 auto sizePerPoint = (operatorType==OPERATOR_VALUE) ?
455 this->vinv_.extent(0)*get_dimension_scalar(inputPoints) :
456 (2*spaceDim+1)*this->vinv_.extent(0)*get_dimension_scalar(inputPoints);
457 WorkViewType workView(scratchStorage, sizePerPoint*team_member.team_size());
458 using range_type = Kokkos::pair<ordinal_type,ordinal_type>;
459 switch(operatorType) {
461 Kokkos::parallel_for (Kokkos::TeamThreadRange (team_member, numPoints), [=, &vinv_ = this->vinv_, basisDegree_ = this->basisDegree_] (ordinal_type& pt) {
462 auto output = Kokkos::subview( outputValues, Kokkos::ALL(), range_type (pt,pt+1), Kokkos::ALL() );
463 const auto input = Kokkos::subview( inputPoints, range_type(pt, pt+1), Kokkos::ALL() );
464 WorkViewType work(workView.data() + sizePerPoint*team_member.team_rank(), sizePerPoint);
469 Kokkos::parallel_for (Kokkos::TeamThreadRange (team_member, numPoints), [=, &vinv_ = this->vinv_, basisDegree_ = this->basisDegree_] (ordinal_type& pt) {
470 auto output = Kokkos::subview( outputValues, Kokkos::ALL(), range_type(pt,pt+1), Kokkos::ALL() );
471 const auto input = Kokkos::subview( inputPoints, range_type(pt,pt+1), Kokkos::ALL() );
472 WorkViewType work(workView.data() + sizePerPoint*team_member.team_rank(), sizePerPoint);
473 Impl::Basis_HGRAD_TET_Cn_FEM::Serial<OPERATOR_GRAD>::getValues( output, input, work, vinv_, basisDegree_);
477 INTREPID2_TEST_FOR_ABORT(
true,
478 ">>> 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.