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