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