Intrepid2
Intrepid2_Cubature.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 
16 #ifndef __INTREPID2_CUBATURE_HPP__
17 #define __INTREPID2_CUBATURE_HPP__
18 
19 #include "Intrepid2_ConfigDefs.hpp"
20 #include "Intrepid2_TensorData.hpp"
22 #include "Intrepid2_Types.hpp"
23 #include "Intrepid2_Utils.hpp"
24 
25 namespace Intrepid2 {
26 
27  /* \struct Intrepid2::CubatureTemplate
28  \brief Template for the cubature rules used by Intrepid. Cubature template consists of
29  cubature points and cubature weights. Intrepid provides a collection of cubature
30  templates for most standard cell topologies. The templates are defined in reference
31  coordinates using a standard reference cell for each canonical cell type. Cubature
32  points are always specified by a triple of (X,Y,Z) coordinates even if the cell
33  dimension is less than 3. The unused dimensions should be padded by zeroes.
34 
35  For example, a set of Gauss rules on [-1,1] looks as the following array of CubatureTemplate structs:
36 
37  \verbatim
38  cubature_rule[4] =
39  { // Collection of Gauss rules on [-1,1]
40  {
41  1, ----> number of points in the rule
42  {{0.0,0.0,0.0}}, ----> X,Y,Z coordinates of the cubature points
43  {0.5} ----> the cubature weight
44  },
45  {
46  2,
47  {{-sqrt(1.0/3.0),0.0,0.0},
48  {+sqrt(1.0/3.0),0.0,0.0}},
49  {1.0,1.0}
50  },
51  {
52  3,
53  {{-sqrt(3.0/5.0),0.0,0.0},
54  {0.0,0.0,0.0},
55  {+sqrt(3.0/5.0),0.0,0.0}},
56  {5.0/9.0, 8.0/9.0,5.0/9.0}
57  },
58  {
59  4,
60  {{-sqrt((3.0+4.0*sqrt(0.3))/7.0),0.0,0.0},
61  {-sqrt((3.0-4.0*sqrt(0.3))/7.0),0.0,0.0},
62  {+sqrt((3.0-4.0*sqrt(0.3))/7.0),0.0,0.0},
63  {+sqrt((3.0+4.0*sqrt(0.3))/7.0),0.0,0.0}},
64  //
65  {0.5-sqrt(10.0/3.0)/12.0,
66  0.5+sqrt(10.0/3.0)/12.0,
67  0.5+sqrt(10.0/3.0)/12.0,
68  0.5-sqrt(10.0/3.0)/12.0}
69  }
70  }; // end Gauss
71  \endverbatim
72 
73  Also see data member documentation.
74  */
75 
76 
88  template<typename DeviceType = void,
89  typename pointValueType = double,
90  typename weightValueType = double>
91  class Cubature {
92  public:
93  using ExecSpaceType = typename DeviceType::execution_space;
94  using PointViewType = Kokkos::DynRankView<pointValueType,Kokkos::LayoutStride,DeviceType>;
95  using weightViewType = Kokkos::DynRankView<weightValueType,Kokkos::LayoutStride,DeviceType>;
96 
97  using PointViewTypeAllocatable = Kokkos::DynRankView<pointValueType,DeviceType>; // uses default layout; allows us to allocate (in contrast to LayoutStride)
98  using WeightViewTypeAllocatable = Kokkos::DynRankView<weightValueType,DeviceType>; // uses default layout; allows us to allocate (in contrast to LayoutStride)
101 
107  {
108  // default implementation has trivial tensor structure
109  PointViewTypeAllocatable allPointData("cubature points",this->getNumPoints(),this->getDimension());
110  Kokkos::Array< PointViewTypeAllocatable, 1> cubaturePointComponents;
111  cubaturePointComponents[0] = allPointData;
112  return TensorPointDataType(cubaturePointComponents);
113  }
114 
120  {
121  // default implementation has trivial tensor structure
122  using WeightDataType = Data<weightValueType,DeviceType>;
123  WeightViewTypeAllocatable allWeightData("cubature weights",this->getNumPoints());
124  Kokkos::Array< WeightDataType, 1> cubatureWeightComponents;
125  cubatureWeightComponents[0] = WeightDataType(allWeightData);
126  return TensorWeightDataType(cubatureWeightComponents);
127  }
128 
135  virtual
136  void
137  getCubature( PointViewType /* cubPoints */,
138  weightViewType /* cubWeights */ ) const {
139  INTREPID2_TEST_FOR_EXCEPTION( true, std::logic_error,
140  ">>> ERROR (Cubature::getCubature): this method should be overridden by derived classes.");
141  }
142 
150  virtual
151  void
152  getCubature( PointViewType /* cubPoints */,
153  weightViewType /* cubWeights */,
154  PointViewType /* cellVertices */) const {
155  INTREPID2_TEST_FOR_EXCEPTION( true, std::logic_error,
156  ">>> ERROR (Cubature::getCubature): this method should be overridden by derived classes.");
157  }
158 
164  virtual
165  void
166  getCubature( const TensorPointDataType & tensorCubPoints,
167  const TensorWeightDataType & tensorCubWeights) const {
168  // default implementation has trivial tensor product structure.
169 
170  INTREPID2_TEST_FOR_EXCEPTION(1 != tensorCubPoints.numTensorComponents(), std::logic_error, "default implementation of getCubature only supports trivial tensor structure -- numTensorComponents() must be 1");
171  INTREPID2_TEST_FOR_EXCEPTION(1 != tensorCubWeights.numTensorComponents(), std::logic_error, "default implementation of getCubature only supports trivial tensor structure -- numTensorComponents() must be 1");
172 
173  auto underlyingPointView = tensorCubPoints.getTensorComponent(0);
174 
175  this->getCubature(underlyingPointView, tensorCubWeights.getTensorComponent(0).getUnderlyingView());
176  }
177 
180  virtual
181  ordinal_type
182  getNumPoints() const {
183  INTREPID2_TEST_FOR_WARNING( true,
184  ">>> ERROR (Cubature::getNumPoints): this method should be overridden by derived classes.");
185  return 0;
186  }
187 
188 
191  virtual
192  ordinal_type
193  getDimension() const {
194  INTREPID2_TEST_FOR_WARNING( true,
195  ">>> ERROR (Cubature::getDimension): this method should be overridden by derived classes.");
196  return 0;
197  }
198 
201  virtual
202  ordinal_type
203  getAccuracy() const {
204  INTREPID2_TEST_FOR_WARNING( true,
205  ">>> ERROR (Cubature::getDimension): this method should be overridden by derived classes.");
206  return 0;
207  }
208 
211  virtual
212  const char*
213  getName() const {
214  return "Cubature";
215  }
216 
217  Cubature() = default;
218  virtual ~Cubature() {}
219 
220  };
221 
222 }// end namespace Intrepid2
223 
224 
355 #endif
Defines the base class for cubature (integration) rules in Intrepid.
View-like interface to tensor points; point components are stored separately; the appropriate coordin...
virtual void getCubature(const TensorPointDataType &tensorCubPoints, const TensorWeightDataType &tensorCubWeights) const
Returns tensor cubature points and weights. For non-tensor cubatures, the tensor structures are trivi...
virtual void getCubature(PointViewType, weightViewType) const
Returns cubature points and weights (return arrays must be pre-sized/pre-allocated).
virtual void getCubature(PointViewType, weightViewType, PointViewType) const
Returns cubature points and weights on physical cells (return arrays must be pre-sized/pre-allocated)...
View-like interface to tensor points; point components are stored separately; the appropriate coordin...
KOKKOS_INLINE_FUNCTION enable_if_t< rank==1, const Kokkos::View< typename RankExpander< DataScalar, rank >::value_type, DeviceType > & > getUnderlyingView() const
Returns the underlying view. Throws an exception if the underlying view is not rank 1...
Wrapper around a Kokkos::View that allows data that is constant or repeating in various logical dimen...
KOKKOS_INLINE_FUNCTION const Data< Scalar, DeviceType > & getTensorComponent(const ordinal_type &r) const
Returns the requested tensor component.
Header function for Intrepid2::Util class and other utility functions.
virtual TensorWeightDataType allocateCubatureWeights() const
Returns a weight container appropriate for passing to getCubature().
virtual ordinal_type getDimension() const
Returns dimension of the integration domain.
virtual const char * getName() const
Returns cubature name.
KOKKOS_INLINE_FUNCTION ordinal_type numTensorComponents() const
Returns the number of tensorial components.
Contains definitions of custom data types in Intrepid2.
virtual TensorPointDataType allocateCubaturePoints() const
Returns a points container appropriate for passing to getCubature().
virtual ordinal_type getNumPoints() const
Returns the number of cubature points.
View-like interface to tensor data; tensor components are stored separately and multiplied together a...
View-like interface to tensor data; tensor components are stored separately and multiplied together a...
virtual ordinal_type getAccuracy() const
Returns dimension of the integration domain.
KOKKOS_INLINE_FUNCTION ordinal_type numTensorComponents() const
Return the number of tensorial components.
KOKKOS_INLINE_FUNCTION ScalarView< PointScalar, DeviceType > getTensorComponent(const ordinal_type &r) const
Returns the requested tensor component.