Intrepid2
Intrepid2_HVOL_TET_Cn_FEMDef.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Intrepid2 Package
4//
5// Copyright 2007 NTESS and the Intrepid2 contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
14
15#ifndef __INTREPID2_HVOL_TET_CN_FEM_DEF_HPP__
16#define __INTREPID2_HVOL_TET_CN_FEM_DEF_HPP__
17
19
20namespace Intrepid2 {
21
22 // -------------------------------------------------------------------------------------
23
24 namespace Impl {
25
26 template<EOperator OpType>
27 template<typename OutputViewType,
28 typename InputViewType,
29 typename WorkViewType,
30 typename VinvViewType>
31 KOKKOS_INLINE_FUNCTION
32 void
34 getValues( OutputViewType output,
35 const InputViewType input,
36 WorkViewType work,
37 const VinvViewType vinv ) {
38
39 constexpr ordinal_type spaceDim = 3;
40 const ordinal_type
41 card = vinv.extent(0),
42 npts = input.extent(0);
43
44 // compute order
45 ordinal_type order = 0;
46 for (ordinal_type p=0;p<=Parameters::MaxOrder;++p) {
47 if (card == Intrepid2::getPnCardinality<spaceDim>(p)) {
48 order = p;
49 break;
50 }
51 }
52
53 typedef typename Kokkos::DynRankView<typename InputViewType::value_type, typename WorkViewType::memory_space> ViewType;
54 auto ptr = work.data();
55
56 switch (OpType) {
57 case OPERATOR_VALUE: {
58 const ViewType phis = createMatchingUnmanagedView<ViewType>(input, ptr, card, npts);
59 ViewType dummyView;
60
61 Impl::Basis_HGRAD_TET_Cn_FEM_ORTH::
62 Serial<OpType>::getValues(phis, input, dummyView, order);
63
64 for (ordinal_type i=0;i<card;++i)
65 for (ordinal_type j=0;j<npts;++j) {
66 output.access(i,j) = 0.0;
67 for (ordinal_type k=0;k<card;++k)
68 output.access(i,j) += vinv(k,i)*phis.access(k,j);
69 }
70 break;
71 }
72 case OPERATOR_GRAD:
73 case OPERATOR_D1: {
74 const ViewType phis = createMatchingUnmanagedView<ViewType>(input, ptr, card, npts, spaceDim);
75 ptr += card*npts*spaceDim*get_dimension_scalar(input);
76 const ViewType workView = createMatchingUnmanagedView<ViewType>(input, ptr, card, npts, spaceDim+1);
77 Impl::Basis_HGRAD_TET_Cn_FEM_ORTH::
78 Serial<OpType>::getValues(phis, input, workView, order);
79
80 for (ordinal_type i=0;i<card;++i)
81 for (ordinal_type j=0;j<npts;++j)
82 for (ordinal_type k=0;k<spaceDim;++k) {
83 output.access(i,j,k) = 0.0;
84 for (ordinal_type l=0;l<card;++l)
85 output.access(i,j,k) += vinv(l,i)*phis.access(l,j,k);
86 }
87 break;
88 }
89 case OPERATOR_D2:
90 case OPERATOR_D3:
91 case OPERATOR_D4:
92 case OPERATOR_D5:
93 case OPERATOR_D6:
94 case OPERATOR_D7:
95 case OPERATOR_D8:
96 case OPERATOR_D9:
97 case OPERATOR_D10: {
98 const ordinal_type dkcard = getDkCardinality<OpType,spaceDim>(); //(orDn + 1);
99 const
100 ViewType phis = createMatchingUnmanagedView<ViewType>(input, ptr, card, npts, dkcard);
101 ViewType dummyView;
102
103 Impl::Basis_HGRAD_TET_Cn_FEM_ORTH::
104 Serial<OpType>::getValues(phis, input, dummyView, order);
105
106 for (ordinal_type i=0;i<card;++i)
107 for (ordinal_type j=0;j<npts;++j)
108 for (ordinal_type k=0;k<dkcard;++k) {
109 output.access(i,j,k) = 0.0;
110 for (ordinal_type l=0;l<card;++l)
111 output.access(i,j,k) += vinv(l,i)*phis.access(l,j,k);
112 }
113 break;
114 }
115 default: {
116 INTREPID2_TEST_FOR_ABORT( true,
117 ">>> ERROR (Basis_HVOL_TET_Cn_FEM): Operator type not implemented");
118 }
119 }
120 }
121
122 template<typename DT, ordinal_type numPtsPerEval,
123 typename outputValueValueType, class ...outputValueProperties,
124 typename inputPointValueType, class ...inputPointProperties,
125 typename vinvValueType, class ...vinvProperties>
126 void
127 Basis_HVOL_TET_Cn_FEM::
128 getValues( Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValues,
129 const Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPoints,
130 const Kokkos::DynRankView<vinvValueType, vinvProperties...> vinv,
131 const EOperator operatorType) {
132 typedef Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValueViewType;
133 typedef Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPointViewType;
134 typedef Kokkos::DynRankView<vinvValueType, vinvProperties...> vinvViewType;
135 typedef typename ExecSpace<typename inputPointViewType::execution_space,typename DT::execution_space>::ExecSpaceType ExecSpaceType;
136
137 // loopSize corresponds to cardinality
138 const auto loopSizeTmp1 = (inputPoints.extent(0)/numPtsPerEval);
139 const auto loopSizeTmp2 = (inputPoints.extent(0)%numPtsPerEval != 0);
140 const auto loopSize = loopSizeTmp1 + loopSizeTmp2;
141 Kokkos::RangePolicy<ExecSpaceType,Kokkos::Schedule<Kokkos::Static> > policy(0, loopSize);
142
143 const ordinal_type cardinality = outputValues.extent(0);
144 const ordinal_type spaceDim = 3;
145
146 ordinal_type order = 0;
147 while((Intrepid2::getPnCardinality<spaceDim>(++order) != cardinality) && (order != Parameters::MaxOrder));
148
149 typedef typename DeduceDynRankView<inputPointViewType>::type workViewType;
150
151 switch (operatorType) {
152 case OPERATOR_VALUE: {
153 auto bufferSize = Basis_HVOL_TET_Cn_FEM::Serial<OPERATOR_VALUE>::getWorkSizePerPoint(order);
154 workViewType work = createMatchingView<workViewType>(inputPoints, "Basis_HVOL_TET_Cn_FEM::getValues::work", bufferSize, inputPoints.extent(0));
155 typedef Functor<outputValueViewType,inputPointViewType,vinvViewType, workViewType,
156 OPERATOR_VALUE,numPtsPerEval> FunctorType;
157 Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, vinv, work) );
158 break;
159 }
160 case OPERATOR_GRAD:
161 case OPERATOR_D1: {
162 auto bufferSize = Basis_HVOL_TET_Cn_FEM::Serial<OPERATOR_D1>::getWorkSizePerPoint(order);
163 workViewType work = createMatchingView<workViewType>(inputPoints, "Basis_HVOL_TET_Cn_FEM::getValues::work", bufferSize, inputPoints.extent(0));
164 typedef Functor<outputValueViewType,inputPointViewType,vinvViewType, workViewType,
165 OPERATOR_D1,numPtsPerEval> FunctorType;
166 Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, vinv, work) );
167 break;
168 }
169 case OPERATOR_D2: {
170 auto bufferSize = Basis_HVOL_TET_Cn_FEM::Serial<OPERATOR_D2>::getWorkSizePerPoint(order);
171 typedef Functor<outputValueViewType,inputPointViewType,vinvViewType, workViewType,
172 OPERATOR_D2,numPtsPerEval> FunctorType;
173 workViewType work = createMatchingView<workViewType>(inputPoints, "Basis_HVOL_TET_Cn_FEM::getValues::work", bufferSize, inputPoints.extent(0));
174 Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, vinv, work) );
175 break;
176 }
177 /* case OPERATOR_D3: {
178 typedef Functor<outputValueViewType,inputPointViewType,vinvViewType, workViewType
179 OPERATOR_D3,numPtsPerEval> FunctorType;
180 workViewType work = createMatchingView<workViewType>(inputPoints, "Basis_HVOL_TET_Cn_FEM::getValues::work", cardinality, inputPoints.extent(0), outputValues.extent(2));
181 Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, vinv, work) );
182 break;
183 }*/
184 default: {
185 INTREPID2_TEST_FOR_EXCEPTION( true , std::invalid_argument,
186 ">>> ERROR (Basis_HVOL_TET_Cn_FEM): Operator type not implemented" );
187 }
188 }
189 }
190 }
191
192 // -------------------------------------------------------------------------------------
193 template<typename DT, typename OT, typename PT>
195 Basis_HVOL_TET_Cn_FEM( const ordinal_type order,
196 const EPointType pointType ) {
197 constexpr ordinal_type spaceDim = 3;
198
199 this->pointType_ = pointType;
201 this->basisDegree_ = order; // small n
202 this->basisCellTopologyKey_ = shards::Tetrahedron<4>::key;
203 this->basisType_ = BASIS_FEM_LAGRANGIAN;
204 this->basisCoordinates_ = COORDINATES_CARTESIAN;
205 this->functionSpace_ = FUNCTION_SPACE_HVOL;
206
207 const ordinal_type card = this->basisCardinality_;
208
209 // points are computed in the host and will be copied
210 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
211 dofCoords("HVOL::Tet::Cn::dofCoords", card, spaceDim);
212
213 // construct lattice (only internal nodes for HVOL element)
214 const ordinal_type offset = 1;
215 const shards::CellTopology cellTopo(shards::getCellTopologyData<shards::Tetrahedron<4> >());
216 PointTools::getLattice( dofCoords,
217 cellTopo,
218 order+spaceDim+offset, offset,
219 pointType );
220
221 this->dofCoords_ = Kokkos::create_mirror_view(typename DT::memory_space(), dofCoords);
222 Kokkos::deep_copy(this->dofCoords_, dofCoords);
223
224 // form Vandermonde matrix. Actually, this is the transpose of the VDM,
225 // so we transpose on copy below.
226 const ordinal_type lwork = card*card;
227 Kokkos::DynRankView<scalarType,Kokkos::LayoutLeft,Kokkos::HostSpace>
228 vmat("HVOL::Tet::Cn::vmat", card, card),
229 work("HVOL::Tet::Cn::work", lwork),
230 ipiv("HVOL::Tet::Cn::ipiv", card);
231
232 Impl::Basis_HGRAD_TET_Cn_FEM_ORTH::getValues<Kokkos::HostSpace::execution_space,Parameters::MaxNumPtsPerBasisEval>(typename Kokkos::HostSpace::execution_space{},
233 vmat,
234 dofCoords,
235 order,
236 OPERATOR_VALUE);
237
238 ordinal_type info = 0;
239 Teuchos::LAPACK<ordinal_type,scalarType> lapack;
240
241 lapack.GETRF(card, card,
242 vmat.data(), vmat.stride(1),
243 (ordinal_type*)ipiv.data(),
244 &info);
245
246 INTREPID2_TEST_FOR_EXCEPTION( info != 0,
247 std::runtime_error ,
248 ">>> ERROR: (Intrepid2::Basis_HVOL_TET_Cn_FEM) lapack.GETRF returns nonzero info." );
249
250 lapack.GETRI(card,
251 vmat.data(), vmat.stride(1),
252 (ordinal_type*)ipiv.data(),
253 work.data(), lwork,
254 &info);
255
256 INTREPID2_TEST_FOR_EXCEPTION( info != 0,
257 std::runtime_error ,
258 ">>> ERROR: (Intrepid2::Basis_HVOL_TET_Cn_FEM) lapack.GETRI returns nonzero info." );
259
260 // create host mirror
261 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
262 vinv("HVOL::Line::Cn::vinv", card, card);
263
264 for (ordinal_type i=0;i<card;++i)
265 for (ordinal_type j=0;j<card;++j)
266 vinv(i,j) = vmat(j,i);
267
268 this->vinv_ = Kokkos::create_mirror_view(typename DT::memory_space(), vinv);
269 Kokkos::deep_copy(this->vinv_ , vinv);
270
271 // initialize tags
272 {
273 // Basis-dependent initializations
274 constexpr ordinal_type tagSize = 4; // size of DoF tag, i.e., number of fields in the tag
275 const ordinal_type posScDim = 0; // position in the tag, counting from 0, of the subcell dim
276 const ordinal_type posScOrd = 1; // position in the tag, counting from 0, of the subcell ordinal
277 const ordinal_type posDfOrd = 2; // position in the tag, counting from 0, of DoF ordinal relative to the subcell
278
279 constexpr ordinal_type maxCard = Intrepid2::getPnCardinality<spaceDim, Parameters::MaxOrder>();
280 ordinal_type tags[maxCard][tagSize];
281
282 const ordinal_type
283 numElemDof = this->basisCardinality_; //all the degrees of freedom are internal.
284
285
286 ordinal_type elemId = 0;
287 for (ordinal_type i=0;i<this->basisCardinality_;++i) {
288 // elem
289 tags[i][0] = spaceDim; // intr dof
290 tags[i][1] = 0; // intr id
291 tags[i][2] = elemId++; // local dof id
292 tags[i][3] = numElemDof; // total vert dof
293 }
294
295 OrdinalTypeArray1DHost tagView(&tags[0][0], card*tagSize);
296
297 // Basis-independent function sets tag and enum data in tagToOrdinal_ and ordinalToTag_ arrays:
298 // tags are constructed on host
300 this->ordinalToTag_,
301 tagView,
302 this->basisCardinality_,
303 tagSize,
304 posScDim,
305 posScOrd,
306 posDfOrd);
307 }
308 }
309
310 template<typename DT, typename OT, typename PT>
311 void
312 Basis_HVOL_TET_Cn_FEM<DT,OT,PT>::getScratchSpaceSize(
313 ordinal_type& perTeamSpaceSize,
314 ordinal_type& perThreadSpaceSize,
315 const PointViewType inputPoints,
316 const EOperator operatorType) const {
317 perTeamSpaceSize = 0;
318 perThreadSpaceSize = this->vinv_.extent(0)*get_dimension_scalar(inputPoints)*sizeof(typename BasisBase::scalarType);
319 }
320
321 template<typename DT, typename OT, typename PT>
322 KOKKOS_INLINE_FUNCTION
323 void
324 Basis_HVOL_TET_Cn_FEM<DT,OT,PT>::getValues(
325 OutputViewType outputValues,
326 const PointViewType inputPoints,
327 const EOperator operatorType,
328 const typename Kokkos::TeamPolicy<typename DT::execution_space>::member_type& team_member,
329 const typename DT::execution_space::scratch_memory_space & scratchStorage,
330 const ordinal_type subcellDim,
331 const ordinal_type subcellOrdinal) const {
332
333 INTREPID2_TEST_FOR_ABORT( !((subcellDim == -1) && (subcellOrdinal == -1)),
334 ">>> ERROR: (Intrepid2::Basis_HVOL_TET_Cn_FEM::getValues), The capability of selecting subsets of basis functions has not been implemented yet.");
335
336 const int numPoints = inputPoints.extent(0);
337 using ScalarType = typename ScalarTraits<typename PointViewType::value_type>::scalar_type;
338 using WorkViewType = Kokkos::DynRankView< ScalarType,typename DT::execution_space::scratch_memory_space,Kokkos::MemoryTraits<Kokkos::Unmanaged> >;
339 auto sizePerPoint = this->vinv_.extent(0)*get_dimension_scalar(inputPoints);
340 WorkViewType workView(scratchStorage, sizePerPoint*team_member.team_size());
341 using range_type = Kokkos::pair<ordinal_type,ordinal_type>;
342 switch(operatorType) {
343 case OPERATOR_VALUE:
344 Kokkos::parallel_for (Kokkos::TeamThreadRange (team_member, numPoints), [=, &vinv_ = this->vinv_] (ordinal_type& pt) {
345 auto output = Kokkos::subview( outputValues, Kokkos::ALL(), range_type (pt,pt+1), Kokkos::ALL() );
346 const auto input = Kokkos::subview( inputPoints, range_type(pt, pt+1), Kokkos::ALL() );
347 WorkViewType work(workView.data() + sizePerPoint*team_member.team_rank(), sizePerPoint);
348 Impl::Basis_HVOL_TET_Cn_FEM::Serial<OPERATOR_VALUE>::getValues( output, input, work, vinv_);
349 });
350 break;
351 default: {
352 INTREPID2_TEST_FOR_ABORT( true,
353 ">>> ERROR (Basis_HVOL_TET_Cn_FEM): getValues not implemented for this operator");
354 }
355 }
356 }
357
358} // namespace Intrepid2
359#endif
KOKKOS_INLINE_FUNCTION ordinal_type getPnCardinality(ordinal_type n)
Returns cardinality of Polynomials of order n (P^n).
Header file for the Intrepid2::Basis_HGRAD_TET_Cn_FEM_ORTH class.
KOKKOS_INLINE_FUNCTION std::enable_if< std::is_pointer_v< CtorProp > &&!std::is_convertible_v< CtorProp, constchar * >, OutViewType >::type createMatchingUnmanagedView(const InViewType &view, const CtorProp &data, const Dims... dims)
Creates an unmanaged view that matches the value_type of the provided view The type of the output vie...
Basis_HVOL_TET_Cn_FEM(const ordinal_type order, const EPointType pointType=POINTTYPE_EQUISPACED)
Constructor.
Kokkos::DynRankView< scalarType, DeviceType > vinv_
inverse of Generalized Vandermonde matrix, whose columns store the expansion coefficients of the noda...
void setOrdinalTagData(OrdinalTypeView3D &tagToOrdinal, OrdinalTypeView2D &ordinalToTag, const OrdinalTypeView1D tags, const ordinal_type basisCard, const ordinal_type tagSize, const ordinal_type posScDim, const ordinal_type posScOrd, const ordinal_type posDfOrd)
Kokkos::DynRankView< scalarType, DeviceType > dofCoords_
Kokkos::View< ordinal_type *, typename ExecutionSpace::array_layout, Kokkos::HostSpace > OrdinalTypeArray1DHost
static constexpr ordinal_type MaxOrder
The maximum reconstruction order.
static void getLattice(Kokkos::DynRankView< pointValueType, pointProperties... > points, const shards::CellTopology cellType, const ordinal_type order, const ordinal_type offset=0, const EPointType pointType=POINTTYPE_EQUISPACED)
Computes a lattice of points of a given order on a reference simplex, quadrilateral or hexahedron (cu...