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