Intrepid2
Intrepid2_HGRAD_LINE_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
15
16#ifndef __INTREPID2_HGRAD_LINE_CN_FEM_DEF_HPP__
17#define __INTREPID2_HGRAD_LINE_CN_FEM_DEF_HPP__
18
19namespace Intrepid2 {
20
21 // -------------------------------------------------------------------------------------
22 namespace Impl {
23
24 template<EOperator opType>
25 template<typename OutputViewType,
26 typename InputViewType,
27 typename WorkViewType,
28 typename VinvViewType>
29 KOKKOS_INLINE_FUNCTION
30 void
32 getValues( OutputViewType output,
33 const InputViewType input,
34 WorkViewType work,
35 const VinvViewType vinv,
36 const ordinal_type operatorDn ) {
37 ordinal_type opDn = operatorDn;
38
39 const ordinal_type card = vinv.extent(0);
40 const ordinal_type npts = input.extent(0);
41
42 const ordinal_type order = card - 1;
43 const double alpha = 0.0, beta = 0.0;
44
45 typedef typename Kokkos::DynRankView<typename InputViewType::value_type, typename WorkViewType::memory_space> ViewType;
46
47 switch (opType) {
48 case OPERATOR_VALUE: {
49 ViewType phis = createMatchingUnmanagedView<ViewType>(input, work.data(), card, npts);
50
51 Impl::Basis_HGRAD_LINE_Cn_FEM_JACOBI::
52 Serial<opType>::getValues(phis, input, order, alpha, beta);
53
54 for (ordinal_type i=0;i<card;++i)
55 for (ordinal_type j=0;j<npts;++j) {
56 output.access(i,j) = 0.0;
57 for (ordinal_type k=0;k<card;++k)
58 output.access(i,j) += vinv(k,i)*phis.access(k,j);
59 }
60 break;
61 }
62 case OPERATOR_GRAD:
63 case OPERATOR_D1:
64 case OPERATOR_D2:
65 case OPERATOR_D3:
66 case OPERATOR_D4:
67 case OPERATOR_D5:
68 case OPERATOR_D6:
69 case OPERATOR_D7:
70 case OPERATOR_D8:
71 case OPERATOR_D9:
72 case OPERATOR_D10:
73 opDn = getOperatorOrder(opType);
74 case OPERATOR_Dn: {
75 // dkcard is always 1 for 1D element
76 const ordinal_type dkcard = 1;
77 ViewType phis = createMatchingUnmanagedView<ViewType>(input, work.data(), card, npts, dkcard);
78 Impl::Basis_HGRAD_LINE_Cn_FEM_JACOBI::
79 Serial<opType>::getValues(phis, input, order, alpha, beta, opDn);
80
81 for (ordinal_type i=0;i<card;++i)
82 for (ordinal_type j=0;j<npts;++j)
83 for (ordinal_type k=0;k<dkcard;++k) {
84 output.access(i,j,k) = 0.0;
85 for (ordinal_type l=0;l<card;++l)
86 output.access(i,j,k) += vinv(l,i)*phis.access(l,j,k);
87 }
88 break;
89 }
90 default: {
91 INTREPID2_TEST_FOR_ABORT( true,
92 ">>> ERROR: (Intrepid2::Basis_HGRAD_LINE_Cn_FEM::Serial::getValues) operator is not supported." );
93 }
94 }
95 }
96
97
98 template<typename DT, ordinal_type numPtsPerEval,
99 typename outputValueValueType, class ...outputValueProperties,
100 typename inputPointValueType, class ...inputPointProperties,
101 typename vinvValueType, class ...vinvProperties>
102 void
103 Basis_HGRAD_LINE_Cn_FEM::
104 getValues( const typename DT::execution_space& space,
105 Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValues,
106 const Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPoints,
107 const Kokkos::DynRankView<vinvValueType, vinvProperties...> vinv,
108 const EOperator operatorType ) {
109 typedef Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValueViewType;
110 typedef Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPointViewType;
111 typedef Kokkos::DynRankView<vinvValueType, vinvProperties...> vinvViewType;
112 typedef typename ExecSpace<typename inputPointViewType::execution_space,typename DT::execution_space>::ExecSpaceType ExecSpaceType;
113
114 // loopSize corresponds to cardinality
115 const auto loopSizeTmp1 = (inputPoints.extent(0)/numPtsPerEval);
116 const auto loopSizeTmp2 = (inputPoints.extent(0)%numPtsPerEval != 0);
117 const auto loopSize = loopSizeTmp1 + loopSizeTmp2;
118 Kokkos::RangePolicy<ExecSpaceType,Kokkos::Schedule<Kokkos::Static> > policy(space, 0, loopSize);
119
120 const ordinal_type cardinality = outputValues.extent(0);
121
122 auto work = createMatchingDynRankView(inputPoints, "Basis_HGRAD_LINE_Cn_FEM::getValues::work", cardinality, inputPoints.extent(0));
123
124 switch (operatorType) {
125 case OPERATOR_VALUE: {
126 typedef Functor<outputValueViewType,inputPointViewType,vinvViewType,decltype(work),
127 OPERATOR_VALUE,numPtsPerEval> FunctorType;
128 Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, vinv, work) );
129 break;
130 }
131 case OPERATOR_GRAD:
132 case OPERATOR_D1:
133 case OPERATOR_D2:
134 case OPERATOR_D3:
135 case OPERATOR_D4:
136 case OPERATOR_D5:
137 case OPERATOR_D6:
138 case OPERATOR_D7:
139 case OPERATOR_D8:
140 case OPERATOR_D9:
141 case OPERATOR_D10: {
142 typedef Functor<outputValueViewType,inputPointViewType,vinvViewType,decltype(work),
143 OPERATOR_Dn,numPtsPerEval> FunctorType;
144 Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, vinv, work,
145 getOperatorOrder(operatorType)) );
146 break;
147 }
148 default: {
149 INTREPID2_TEST_FOR_EXCEPTION( true , std::invalid_argument,
150 ">>> ERROR (Basis_HGRAD_LINE_Cn_FEM): Operator type not implemented" );
151 //break; commented out because this always throws
152 }
153 }
154 }
155 }
156
157 // -------------------------------------------------------------------------------------
158 template<typename DT, typename OT, typename PT>
160 Basis_HGRAD_LINE_Cn_FEM( const ordinal_type order,
161 const EPointType pointType ) {
162 this->pointType_ = pointType;
163 this->basisCardinality_ = order+1;
164 this->basisDegree_ = order;
165 this->basisCellTopologyKey_ = shards::Line<2>::key;
166 this->basisType_ = BASIS_FEM_LAGRANGIAN;
167 this->basisCoordinates_ = COORDINATES_CARTESIAN;
168 this->functionSpace_ = FUNCTION_SPACE_HGRAD;
169
170 const ordinal_type card = this->basisCardinality_;
171
172 // points are computed in the host and will be copied
173 Kokkos::DynRankView<typename ScalarViewType::value_type,typename DT::execution_space::array_layout,Kokkos::HostSpace>
174 dofCoords("Hgrad::Line::Cn::dofCoords", card, 1);
175
176 //Default is Equispaced
177 auto pointT = (pointType == POINTTYPE_DEFAULT) ? POINTTYPE_EQUISPACED : pointType;
178
179 switch (pointT) {
180 case POINTTYPE_EQUISPACED:
181 case POINTTYPE_WARPBLEND: {
182 // lattice ordering
183 {
184 shards::CellTopology cellTopo(shards::getCellTopologyData<shards::Line<2>>());
185 const ordinal_type offset = 0;
186 PointTools::getLattice( dofCoords,
187 cellTopo,
188 order, offset,
189 pointT );
190
191 }
192 break;
193 }
194 default: {
195 INTREPID2_TEST_FOR_EXCEPTION( !isValidPointType(pointT),
196 std::invalid_argument ,
197 ">>> ERROR: (Intrepid2::Basis_HGRAD_LINE_Cn_FEM) invalid pointType." );
198 }
199 }
200
201 this->dofCoords_ = Kokkos::create_mirror_view(typename DT::memory_space(), dofCoords);
202 Kokkos::deep_copy(this->dofCoords_, dofCoords);
203
204 // form Vandermonde matrix; actually, this is the transpose of the VDM,
205 // this matrix is used in LAPACK so it should be column major and left layout
206 const ordinal_type lwork = card*card;
207 Kokkos::DynRankView<typename ScalarViewType::value_type,Kokkos::LayoutLeft,Kokkos::HostSpace>
208 vmat("Hgrad::Line::Cn::vmat", card, card),
209 work("Hgrad::Line::Cn::work", lwork),
210 ipiv("Hgrad::Line::Cn::ipiv", card);
211
212 const double alpha = 0.0, beta = 0.0;
213 Impl::Basis_HGRAD_LINE_Cn_FEM_JACOBI::
214 getValues<Kokkos::HostSpace::execution_space,Parameters::MaxNumPtsPerBasisEval>
215 (typename Kokkos::HostSpace::execution_space{}, vmat, dofCoords, order, alpha, beta, OPERATOR_VALUE);
216
217 ordinal_type info = 0;
218 Teuchos::LAPACK<ordinal_type,typename ScalarViewType::value_type> lapack;
219
220 lapack.GETRF(card, card,
221 vmat.data(), vmat.stride(1),
222 (ordinal_type*)ipiv.data(),
223 &info);
224
225 INTREPID2_TEST_FOR_EXCEPTION( info != 0,
226 std::runtime_error ,
227 ">>> ERROR: (Intrepid2::Basis_HGRAD_LINE_Cn_FEM) lapack.GETRF returns nonzero info." );
228
229 lapack.GETRI(card,
230 vmat.data(), vmat.stride(1),
231 (ordinal_type*)ipiv.data(),
232 work.data(), lwork,
233 &info);
234
235 INTREPID2_TEST_FOR_EXCEPTION( info != 0,
236 std::runtime_error ,
237 ">>> ERROR: (Intrepid2::Basis_HGRAD_LINE_Cn_FEM) lapack.GETRI returns nonzero info." );
238
239 // create host mirror
240 Kokkos::DynRankView<typename ScalarViewType::value_type,typename DT::execution_space::array_layout,Kokkos::HostSpace>
241 vinv("Hgrad::Line::Cn::vinv", card, card);
242
243 for (ordinal_type i=0;i<card;++i)
244 for (ordinal_type j=0;j<card;++j)
245 vinv(i,j) = vmat(j,i);
246
247 this->vinv_ = Kokkos::create_mirror_view(typename DT::memory_space(), vinv);
248 Kokkos::deep_copy(this->vinv_ , vinv);
249
250 // initialize tags
251 {
252 // Basis-dependent initializations
253 const ordinal_type tagSize = 4; // size of DoF tag, i.e., number of fields in the tag
254 const ordinal_type posScDim = 0; // position in the tag, counting from 0, of the subcell dim
255 const ordinal_type posScOrd = 1; // position in the tag, counting from 0, of the subcell ordinal
256 const ordinal_type posDfOrd = 2; // position in the tag, counting from 0, of DoF ordinal relative to the subcell
257
258 // Note: the only reason why equispaced can't support higher order than Parameters::MaxOrder appears to be the fact that the tags below get stored into a fixed-length array.
259 // TODO: relax the maximum order requirement by setting up tags in a different container, perhaps directly into an OrdinalTypeArray1DHost (tagView, below). (As of this writing (1/25/22), looks like other nodal bases do this in a similar way -- those should be fixed at the same time; maybe search for Parameters::MaxOrder.)
260 INTREPID2_TEST_FOR_EXCEPTION( order > Parameters::MaxOrder, std::invalid_argument, "polynomial order exceeds the max supported by this class");
261 ordinal_type tags[Parameters::MaxOrder+1][4];
262
263 // lattice order
264 {
265 const auto v0 = 0;
266 tags[v0][0] = 0; // vertex dof
267 tags[v0][1] = 0; // vertex id
268 tags[v0][2] = 0; // local dof id
269 tags[v0][3] = 1; // total number of dofs in this vertex
270
271 const ordinal_type iend = card - 2;
272 for (ordinal_type i=0;i<iend;++i) {
273 const auto e = i + 1;
274 tags[e][0] = 1; // edge dof
275 tags[e][1] = 0; // edge id
276 tags[e][2] = i; // local dof id
277 tags[e][3] = iend; // total number of dofs in this edge
278 }
279
280 const auto v1 = card -1;
281 tags[v1][0] = 0; // vertex dof
282 tags[v1][1] = 1; // vertex id
283 tags[v1][2] = 0; // local dof id
284 tags[v1][3] = 1; // total number of dofs in this vertex
285 }
286
287 // topological order
288 // {
289 // tags[0][0] = 0; // vertex dof
290 // tags[0][1] = 0; // vertex id
291 // tags[0][2] = 0; // local dof id
292 // tags[0][3] = 1; // total number of dofs in this vertex
293
294 // tags[1][0] = 0; // vertex dof
295 // tags[1][1] = 1; // vertex id
296 // tags[1][2] = 0; // local dof id
297 // tags[1][3] = 1; // total number of dofs in this vertex
298
299 // const ordinal_type iend = card - 2;
300 // for (ordinal_type i=0;i<iend;++i) {
301 // const auto ii = i + 2;
302 // tags[ii][0] = 1; // edge dof
303 // tags[ii][1] = 0; // edge id
304 // tags[ii][2] = i; // local dof id
305 // tags[ii][3] = iend; // total number of dofs in this edge
306 // }
307 // }
308
309
310 OrdinalTypeArray1DHost tagView(&tags[0][0], card*4);
311
312 // Basis-independent function sets tag and enum data in tagToOrdinal_ and ordinalToTag_ arrays:
313 // tags are constructed on host
315 this->ordinalToTag_,
316 tagView,
317 this->basisCardinality_,
318 tagSize,
319 posScDim,
320 posScOrd,
321 posDfOrd);
322 }
323 }
324
325 template<typename DT, typename OT, typename PT>
326 void
327 Basis_HGRAD_LINE_Cn_FEM<DT,OT,PT>::getScratchSpaceSize(
328 ordinal_type& perTeamSpaceSize,
329 ordinal_type& perThreadSpaceSize,
330 const PointViewType inputPoints,
331 const EOperator operatorType) const {
332 perTeamSpaceSize = 0;
333 perThreadSpaceSize = this->vinv_.extent(0)*get_dimension_scalar(inputPoints)*sizeof(typename BasisBase::scalarType);
334 }
335
336 template<typename DT, typename OT, typename PT>
337 KOKKOS_INLINE_FUNCTION
338 void
339 Basis_HGRAD_LINE_Cn_FEM<DT,OT,PT>::getValues(
340 OutputViewType outputValues,
341 const PointViewType inputPoints,
342 const EOperator operatorType,
343 const typename Kokkos::TeamPolicy<typename DT::execution_space>::member_type& team_member,
344 const typename DT::execution_space::scratch_memory_space & scratchStorage,
345 const ordinal_type subcellDim,
346 const ordinal_type subcellOrdinal) const {
347
348 INTREPID2_TEST_FOR_ABORT( !((subcellDim == -1) && (subcellOrdinal == -1)),
349 ">>> ERROR: (Intrepid2::Basis_HGRAD_LINE_Cn_FEM::getValues), The capability of selecting subsets of basis functions has not been implemented yet.");
350
351 const int numPoints = inputPoints.extent(0);
352 using ScalarType = typename ScalarTraits<typename PointViewType::value_type>::scalar_type;
353 using WorkViewType = Kokkos::DynRankView< ScalarType,typename DT::execution_space::scratch_memory_space,Kokkos::MemoryTraits<Kokkos::Unmanaged> >;
354 ordinal_type sizePerPoint = this->vinv_.extent(0)*get_dimension_scalar(inputPoints);
355 WorkViewType workView(scratchStorage, sizePerPoint*team_member.team_size());
356 using range_type = Kokkos::pair<ordinal_type,ordinal_type>;
357
358 switch(operatorType) {
359 case OPERATOR_VALUE:
360 Kokkos::parallel_for (Kokkos::TeamThreadRange (team_member, numPoints), [=, &vinv_ = this->vinv_] (ordinal_type& pt) {
361 auto output = Kokkos::subview( outputValues, Kokkos::ALL(), range_type (pt,pt+1), Kokkos::ALL() );
362 const auto input = Kokkos::subview( inputPoints, range_type(pt, pt+1), Kokkos::ALL() );
363 WorkViewType work(workView.data() + sizePerPoint*team_member.team_rank(), sizePerPoint);
364 Impl::Basis_HGRAD_LINE_Cn_FEM::Serial<OPERATOR_VALUE>::getValues( output, input, work, vinv_ );
365 });
366 break;
367 case OPERATOR_GRAD:
368 Kokkos::parallel_for (Kokkos::TeamThreadRange (team_member, numPoints), [=, &vinv_ = this->vinv_] (ordinal_type& pt) {
369 auto output = Kokkos::subview( outputValues, Kokkos::ALL(), range_type(pt,pt+1), Kokkos::ALL() );
370 const auto input = Kokkos::subview( inputPoints, range_type(pt,pt+1), Kokkos::ALL() );
371 WorkViewType work(workView.data() + sizePerPoint*team_member.team_rank(), sizePerPoint);
372 Impl::Basis_HGRAD_LINE_Cn_FEM::Serial<OPERATOR_GRAD>::getValues( output, input, work, vinv_ );
373 });
374 break;
375 default: {
376 INTREPID2_TEST_FOR_ABORT( true,
377 ">>> ERROR (Basis_HGRAD_LINE_Cn_FEM): getValues not implemented for this operator");
378 }
379 }
380 }
381
382}// namespace Intrepid2
383
384#endif
KOKKOS_INLINE_FUNCTION ordinal_type getOperatorOrder(const EOperator operatorType)
Returns order of an operator.
KOKKOS_FORCEINLINE_FUNCTION bool isValidPointType(const EPointType pointType)
Verifies validity of a point type enum.
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...
DeduceDynRankView< InViewType >::type createMatchingDynRankView(const InViewType &view, const CtorProp &prop, const Dims... dims)
Creates and returns a view that matches the value_type of the provided view The output view type is d...
Kokkos::DynRankView< typename ScalarViewType::value_type, DeviceType > vinv_
inverse of Generalized Vandermonde matrix, whose columns store the expansion coefficients of the noda...
Basis_HGRAD_LINE_Cn_FEM(const ordinal_type order, const EPointType pointType=POINTTYPE_EQUISPACED)
Constructor.
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...