Intrepid2
Intrepid2_HGRAD_LINE_Cn_FEM.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ************************************************************************
3 //
4 // Intrepid2 Package
5 // Copyright (2007) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Kyungjoo Kim (kyukim@sandia.gov), or
38 // Mauro Perego (mperego@sandia.gov)
39 //
40 // ************************************************************************
41 // @HEADER
42 
49 #ifndef __INTREPID2_HGRAD_LINE_CN_FEM_HPP__
50 #define __INTREPID2_HGRAD_LINE_CN_FEM_HPP__
51 
52 #include "Intrepid2_Basis.hpp"
54 
55 #include "Intrepid2_PointTools.hpp"
56 #include "Teuchos_LAPACK.hpp"
57 
58 namespace Intrepid2 {
59 
76  namespace Impl {
77 
82  public:
83  typedef struct Line<2> cell_topology_type;
87  template<EOperator opType>
88  struct Serial {
89  template<typename outputValueViewType,
90  typename inputPointViewType,
91  typename workViewType,
92  typename vinvViewType>
93  KOKKOS_INLINE_FUNCTION
94  static void
95  getValues( outputValueViewType outputValues,
96  const inputPointViewType inputPoints,
97  workViewType work,
98  const vinvViewType vinv,
99  const ordinal_type operatorDn = 0 );
100  };
101 
102  template<typename DeviceType, ordinal_type numPtsPerEval,
103  typename outputValueValueType, class ...outputValueProperties,
104  typename inputPointValueType, class ...inputPointProperties,
105  typename vinvValueType, class ...vinvProperties>
106  static void
107  getValues( const typename DeviceType::execution_space& space,
108  Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValues,
109  const Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPoints,
110  const Kokkos::DynRankView<vinvValueType, vinvProperties...> vinv,
111  const EOperator operatorType );
112 
116  template<typename outputValueViewType,
117  typename inputPointViewType,
118  typename vinvViewType,
119  typename workViewType,
120  EOperator opType,
121  ordinal_type numPtsEval>
122  struct Functor {
123  outputValueViewType _outputValues;
124  const inputPointViewType _inputPoints;
125  const vinvViewType _vinv;
126  workViewType _work;
127  const ordinal_type _opDn;
128 
129  KOKKOS_INLINE_FUNCTION
130  Functor( outputValueViewType outputValues_,
131  inputPointViewType inputPoints_,
132  vinvViewType vinv_,
133  workViewType work_,
134  const ordinal_type opDn_ = 0 )
135  : _outputValues(outputValues_), _inputPoints(inputPoints_),
136  _vinv(vinv_), _work(work_), _opDn(opDn_) {}
137 
138  KOKKOS_INLINE_FUNCTION
139  void operator()(const size_type iter) const {
140  const auto ptBegin = Util<ordinal_type>::min(iter*numPtsEval, _inputPoints.extent(0));
141  const auto ptEnd = Util<ordinal_type>::min(ptBegin+numPtsEval, _inputPoints.extent(0));
142 
143  const auto ptRange = Kokkos::pair<ordinal_type,ordinal_type>(ptBegin, ptEnd);
144  const auto input = Kokkos::subview( _inputPoints, ptRange, Kokkos::ALL() );
145 
146  typename workViewType::pointer_type ptr = _work.data() + _work.extent(0)*ptBegin*get_dimension_scalar(_work);
147 
148  auto vcprop = Kokkos::common_view_alloc_prop(_work);
149  workViewType work(Kokkos::view_wrap(ptr,vcprop), (ptEnd-ptBegin)*_work.extent(0));
150 
151  switch (opType) {
152  case OPERATOR_VALUE : {
153  auto output = Kokkos::subview( _outputValues, Kokkos::ALL(), ptRange );
154  Serial<opType>::getValues( output, input, work, _vinv );
155  break;
156  }
157  case OPERATOR_Dn : {
158  auto output = Kokkos::subview( _outputValues, Kokkos::ALL(), ptRange, Kokkos::ALL() );
159  Serial<opType>::getValues( output, input, work, _vinv, _opDn );
160  break;
161  }
162  default: {
163  INTREPID2_TEST_FOR_ABORT( true,
164  ">>> ERROR: (Intrepid2::Basis_HGRAD_LINE_Cn_FEM::Functor) operator is not supported");
165 
166  }
167  }
168  }
169  };
170  };
171  }
172 
173  template<typename DeviceType = void,
174  typename outputValueType = double,
175  typename pointValueType = double>
177  : public Basis<DeviceType,outputValueType,pointValueType> {
178  public:
180  using typename BasisBase::ExecutionSpace;
181 
183 
184  using typename BasisBase::OrdinalTypeArray1DHost;
185  using typename BasisBase::OrdinalTypeArray2DHost;
186  using typename BasisBase::OrdinalTypeArray3DHost;
187 
188  using typename BasisBase::OutputViewType;
189  using typename BasisBase::PointViewType ;
190  using typename BasisBase::ScalarViewType;
191 
192  private:
193 
196  Kokkos::DynRankView<typename ScalarViewType::value_type,DeviceType> vinv_;
197  EPointType pointType_;
198  public:
201  Basis_HGRAD_LINE_Cn_FEM(const ordinal_type order,
202  const EPointType pointType = POINTTYPE_EQUISPACED);
203 
204  using BasisBase::getValues;
205 
206  virtual
207  void
208  getValues( const ExecutionSpace& space,
209  OutputViewType outputValues,
210  const PointViewType inputPoints,
211  const EOperator operatorType = OPERATOR_VALUE ) const override {
212 #ifdef HAVE_INTREPID2_DEBUG
213  Intrepid2::getValues_HGRAD_Args(outputValues,
214  inputPoints,
215  operatorType,
216  this->getBaseCellTopology(),
217  this->getCardinality() );
218 #endif
219  constexpr ordinal_type numPtsPerEval = 1;
220  Impl::Basis_HGRAD_LINE_Cn_FEM::
221  getValues<DeviceType,numPtsPerEval>(space,
222  outputValues,
223  inputPoints,
224  this->vinv_,
225  operatorType);
226  }
227 
228  virtual
229  void
230  getDofCoords( ScalarViewType dofCoords ) const override {
231 #ifdef HAVE_INTREPID2_DEBUG
232  // Verify rank of output array.
233  INTREPID2_TEST_FOR_EXCEPTION( rank(dofCoords) != 2, std::invalid_argument,
234  ">>> ERROR: (Intrepid2::Basis_HGRAD_LINE_Cn_FEM::getDofCoords) rank = 2 required for dofCoords array");
235  // Verify 0th dimension of output array.
236  INTREPID2_TEST_FOR_EXCEPTION( static_cast<ordinal_type>(dofCoords.extent(0)) != this->getCardinality(), std::invalid_argument,
237  ">>> ERROR: (Intrepid2::Basis_HGRAD_LINE_Cn_FEM::getDofCoords) mismatch in number of dof and 0th dimension of dofCoords array");
238  // Verify 1st dimension of output array.
239  INTREPID2_TEST_FOR_EXCEPTION( dofCoords.extent(1) != this->getBaseCellTopology().getDimension(), std::invalid_argument,
240  ">>> ERROR: (Intrepid2::Basis_HGRAD_LINE_Cn_FEM::getDofCoords) incorrect reference cell (1st) dimension in dofCoords array");
241 #endif
242  Kokkos::deep_copy(dofCoords, this->dofCoords_);
243  }
244 
245  virtual
246  void
247  getDofCoeffs( ScalarViewType dofCoeffs ) const override {
248 #ifdef HAVE_INTREPID2_DEBUG
249  // Verify rank of output array.
250  INTREPID2_TEST_FOR_EXCEPTION( rank(dofCoeffs) != 1, std::invalid_argument,
251  ">>> ERROR: (Intrepid2::Basis_HGRAD_LINE_Cn_FEM::getdofCoeffs) rank = 1 required for dofCoeffs array");
252  // Verify 0th dimension of output array.
253  INTREPID2_TEST_FOR_EXCEPTION( static_cast<ordinal_type>(dofCoeffs.extent(0)) != this->getCardinality(), std::invalid_argument,
254  ">>> ERROR: (Intrepid2::Basis_HGRAD_LINE_Cn_FEM::getdofCoeffs) mismatch in number of dof and 0th dimension of dofCoeffs array");
255 #endif
256  Kokkos::deep_copy(dofCoeffs, 1.0);
257  }
258 
259  virtual
260  const char*
261  getName() const override {
262  return "Intrepid2_HGRAD_LINE_Cn_FEM";
263  }
264 
265  void
266  getVandermondeInverse( ScalarViewType vinv ) const {
267  // has to be same rank and dimensions
268  Kokkos::deep_copy(vinv, this->vinv_);
269  }
270 
271  Kokkos::DynRankView<typename ScalarViewType::const_value_type,DeviceType>
272  getVandermondeInverse() const {
273  return vinv_;
274  }
275 
276  ordinal_type
277  getWorkSizePerPoint(const EOperator operatorType) const {
278  return getPnCardinality<1>(this->basisDegree_);
279  }
280 
285  virtual HostBasisPtr<outputValueType,pointValueType>
286  getHostBasis() const override {
287  auto hostBasis = Teuchos::rcp(new HostBasis(this->basisDegree_, pointType_));
288 
289  return hostBasis;
290  }
291  };
292 
293 }// namespace Intrepid2
294 
296 
297 #endif
Kokkos::View< ordinal_type *, typename ExecutionSpace::array_layout, Kokkos::HostSpace > OrdinalTypeArray1DHost
View type for 1d host array.
virtual const char * getName() const override
Returns basis name.
small utility functions
ordinal_type getCardinality() const
Returns cardinality of the basis.
virtual void getValues(const ExecutionSpace &space, OutputViewType outputValues, const PointViewType inputPoints, const EOperator operatorType=OPERATOR_VALUE) const override
Evaluation of a FEM basis on a reference cell.
virtual void getValues(const ExecutionSpace &, OutputViewType, const PointViewType, const EOperator=OPERATOR_VALUE) const
Evaluation of a FEM basis on a reference cell.
Kokkos::DynRankView< typename ScalarViewType::value_type, DeviceType > vinv_
inverse of Generalized Vandermonde matrix, whose columns store the expansion coefficients of the noda...
An abstract base class that defines interface for concrete basis implementations for Finite Element (...
shards::CellTopology getBaseCellTopology() const
Returns the base cell topology for which the basis is defined. See Shards documentation https://trili...
Kokkos::DynRankView< scalarType, Kokkos::LayoutStride, DeviceType > ScalarViewType
View type for scalars.
ordinal_type basisDegree_
Degree of the largest complete polynomial space that can be represented by the basis.
Kokkos::DynRankView< PointValueType, Kokkos::LayoutStride, DeviceType > PointViewType
View type for input points.
Kokkos::DynRankView< scalarType, Kokkos::LayoutStride, DeviceType > ScalarViewType
View type for scalars.
virtual void getDofCoords(ScalarViewType dofCoords) const override
Returns spatial locations (coordinates) of degrees of freedom on the reference cell.
Kokkos::View< ordinal_type **, typename ExecutionSpace::array_layout, Kokkos::HostSpace > OrdinalTypeArray2DHost
View type for 2d host array.
Header file for the Intrepid2::Basis_HGRAD_LINE_Cn_FEM_JACOBI class.
Kokkos::DynRankView< OutputValueType, Kokkos::LayoutStride, DeviceType > OutputViewType
View type for basis value output.
See Intrepid2::Basis_HGRAD_LINE_Cn_FEM.
virtual void getDofCoeffs(ScalarViewType dofCoeffs) const override
Coefficients for computing degrees of freedom for Lagrangian basis If P is an element of the space sp...
typename DeviceType::execution_space ExecutionSpace
(Kokkos) Execution space for basis.
Implementation of the locally H(grad)-compatible FEM basis of variable order on the [-1...
Definition file for FEM basis functions of degree n for H(grad) functions on LINE.
Kokkos::View< ordinal_type ***, typename ExecutionSpace::array_layout, Kokkos::HostSpace > OrdinalTypeArray3DHost
View type for 3d host array.
Basis_HGRAD_LINE_Cn_FEM(const ordinal_type order, const EPointType pointType=POINTTYPE_EQUISPACED)
Constructor.
Kokkos::DynRankView< OutputValueType, Kokkos::LayoutStride, DeviceType > OutputViewType
View type for basis value output.
virtual HostBasisPtr< outputValueType, pointValueType > getHostBasis() const override
Creates and returns a Basis object whose DeviceType template argument is Kokkos::HostSpace::device_ty...
Kokkos::DynRankView< scalarType, DeviceType > dofCoords_
Coordinates of degrees-of-freedom for basis functions defined in physical space.
Kokkos::DynRankView< PointValueType, Kokkos::LayoutStride, DeviceType > PointViewType
View type for input points.
Header file for the abstract base class Intrepid2::Basis.
typename DeviceType::execution_space ExecutionSpace
(Kokkos) Execution space for basis.
Header file for Intrepid2::PointTools class to provide utilities for barycentric coordinates, equispaced lattices, and warp-blend point distrubtions.