Intrepid2
Intrepid2_CubatureTensor.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_CUBATURE_TENSOR_HPP__
50 #define __INTREPID2_CUBATURE_TENSOR_HPP__
51 
52 #include "Intrepid2_ConfigDefs.hpp"
53 #include "Intrepid2_Cubature.hpp"
55 
56 namespace Intrepid2 {
57 
61  template<typename DeviceType = void,
62  typename pointValueType = double,
63  typename weightValueType = double>
65  : public Cubature<DeviceType,pointValueType,weightValueType> {
66  private:
67 
70  ordinal_type numCubatures_;
71 
73 
76  ordinal_type dimension_;
77 
78  public:
79 
80  template<typename cubPointValueType, class ...cubPointProperties,
81  typename cubWeightValueType, class ...cubWeightProperties>
82  void
83  getCubatureImpl( Kokkos::DynRankView<cubPointValueType, cubPointProperties...> cubPoints,
84  Kokkos::DynRankView<cubWeightValueType,cubWeightProperties...> cubWeights ) const;
85 
86  using PointViewType = typename Cubature<DeviceType,pointValueType,weightValueType>::PointViewType;
87  using weightViewType = typename Cubature<DeviceType,pointValueType,weightValueType>::weightViewType;
88 
90  using PointViewTypeAllocatable = typename Cubature<DeviceType,pointValueType,weightValueType>::PointViewTypeAllocatable;
91  using WeightViewTypeAllocatable = typename Cubature<DeviceType,pointValueType,weightValueType>::WeightViewTypeAllocatable;
94 
96 
97  virtual
98  void
99  getCubature( PointViewType cubPoints,
100  weightViewType cubWeights ) const override {
101  getCubatureImpl( cubPoints,
102  cubWeights );
103  }
104 
110  {
111  std::vector< PointViewTypeAllocatable > cubaturePointComponents(numCubatures_);
112 
113  for (ordinal_type i=0;i<numCubatures_;++i)
114  {
115  cubaturePointComponents[i] = PointViewTypeAllocatable("cubature points", cubatures_[i].getNumPoints(), cubatures_[i].getDimension());
116  }
117 
118  return TensorPointDataType(cubaturePointComponents);
119  }
120 
126  {
127  using WeightDataType = Data<weightValueType,DeviceType>;
128 
129  std::vector< WeightDataType > cubatureWeightComponents(numCubatures_);
130  for (ordinal_type i=0;i<numCubatures_;++i)
131  {
132  cubatureWeightComponents[i] = WeightDataType(WeightViewTypeAllocatable("cubature weights", cubatures_[i].getNumPoints()));
133  }
134 
135  return TensorWeightDataType(cubatureWeightComponents);
136  }
137 
143  virtual
144  void
145  getCubature( const TensorPointDataType & tensorCubPoints,
146  const TensorWeightDataType & tensorCubWeights) const override {
147  for (ordinal_type i=0;i<numCubatures_;++i)
148  {
149  cubatures_[i].getCubature(tensorCubPoints.getTensorComponent(i), tensorCubWeights.getTensorComponent(i).getUnderlyingView());
150  }
151  }
152 
155  virtual
156  ordinal_type
157  getNumPoints() const override {
158  ordinal_type numCubPoints = 1;
159  for (ordinal_type i=0;i<numCubatures_;++i)
160  numCubPoints *= cubatures_[i].getNumPoints();
161  return numCubPoints;
162  }
163 
166  virtual
167  ordinal_type
168  getDimension() const override {
169  return dimension_;
170  }
171 
174  virtual
175  const char*
176  getName() const override {
177  return "CubatureTensor";
178  }
179 
180  virtual
181  ordinal_type
182  getAccuracy() const override {
183  ordinal_type r_val = 0;
184  for (ordinal_type i=0;i<numCubatures_;++i)
185  r_val = Util<ordinal_type>::max(r_val, cubatures_[i].getAccuracy());
186  return r_val;
187  }
188 
191  ordinal_type getNumCubatures() const {
192  return numCubatures_;
193  }
194 
197  void getAccuracy( ordinal_type *accuracy ) const {
198  for (ordinal_type i=0;i<numCubatures_;++i)
199  accuracy[i] = cubatures_[i].getAccuracy();
200  }
201 
202  CubatureTensor()
203  : numCubatures_(0),
204  dimension_(0) {}
205 
206  CubatureTensor(const CubatureTensor &b)
209  for (ordinal_type i=0;i<numCubatures_;++i)
210  cubatures_[i] = b.cubatures_[i];
211  }
212 
218  template<typename CubatureType0,
219  typename CubatureType1>
220  CubatureTensor( const CubatureType0 cubature0,
221  const CubatureType1 cubature1 )
222  : numCubatures_(2),
223  dimension_(cubature0.getDimension()+cubature1.getDimension()) {
224  cubatures_[0] = cubature0;
225  cubatures_[1] = cubature1;
226  }
227 
234  template<typename CubatureType0,
235  typename CubatureType1,
236  typename CubatureType2>
237  CubatureTensor( const CubatureType0 cubature0,
238  const CubatureType1 cubature1,
239  const CubatureType2 cubature2 )
240  : numCubatures_(3),
241  dimension_(cubature0.getDimension()+cubature1.getDimension()+cubature2.getDimension()) {
242  cubatures_[0] = cubature0;
243  cubatures_[1] = cubature1;
244  cubatures_[2] = cubature2;
245  }
246 
252  template<typename DirectCubature>
253  CubatureTensor( const CubatureTensor cubatureTensor,
254  const DirectCubature cubatureExtension )
255  : numCubatures_(cubatureTensor.getNumCubatures()+1),
256  dimension_(cubatureTensor.getDimension()+cubatureExtension.getDimension()) {
257  for (ordinal_type i=0;i<cubatureTensor.getNumCubatures();++i)
258  cubatures_[i] = cubatureTensor.cubatures_[i];
259  cubatures_[cubatureTensor.getNumCubatures()] = cubatureExtension;
260  }
261  };
262 
263 
264 } // end namespace Intrepid2
265 
266 
267 // include templated definitions
269 
270 #endif
Defines the base class for cubature (integration) rules in Intrepid.
virtual ordinal_type getAccuracy() const override
Returns dimension of the integration domain.
small utility functions
View-like interface to tensor points; point components are stored separately; the appropriate coordin...
typename Cubature< DeviceType, pointValueType, weightValueType >::PointViewTypeAllocatable PointViewTypeAllocatable
KK: following should be updated with nate&#39;s tensor work.
ordinal_type getNumCubatures() const
Return the number of cubatures.
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...
Defines tensor-product cubature (integration) rules in Intrepid.
virtual ordinal_type getDimension() const override
Returns dimension of integration domain.
CubatureTensor(const CubatureTensor cubatureTensor, const DirectCubature cubatureExtension)
Constructor for extending an existing CubatureTensor object with an additional direct cubature rule...
Wrapper around a Kokkos::View that allows data that is constant or repeating in various logical dimen...
ordinal_type numCubatures_
Array of cubature rules.
void getAccuracy(ordinal_type *accuracy) const
Returns max. degree of polynomials that are integrated exactly.
KOKKOS_INLINE_FUNCTION const Data< Scalar, DeviceType > & getTensorComponent(const ordinal_type &r) const
Returns the requested tensor component.
virtual ordinal_type getNumPoints() const override
Returns the number of cubature points.
virtual void getCubature(const TensorPointDataType &tensorCubPoints, const TensorWeightDataType &tensorCubWeights) const override
Returns tensor cubature points and weights. For non-tensor cubatures, the tensor structures are trivi...
void getCubatureImpl(Kokkos::DynRankView< cubPointValueType, cubPointProperties...> cubPoints, Kokkos::DynRankView< cubWeightValueType, cubWeightProperties...> cubWeights) const
CubatureTensor(const CubatureType0 cubature0, const CubatureType1 cubature1)
Constructor.
Header file for the Intrepid2::Cubature class.
virtual TensorWeightDataType allocateCubatureWeights() const override
Returns a weight container appropriate for passing to getCubature().
virtual void getCubature(PointViewType cubPoints, weightViewType cubWeights) const override
Returns cubature points and weights (return arrays must be pre-sized/pre-allocated).
ordinal_type dimension_
Dimension of integration domain.
virtual const char * getName() const override
Returns cubature name.
Definition file for the Intrepid2::CubatureTensor class.
Defines direct cubature (integration) rules in Intrepid.
View-like interface to tensor data; tensor components are stored separately and multiplied together a...
virtual TensorPointDataType allocateCubaturePoints() const override
Returns a points container appropriate for passing to getCubature().
KOKKOS_INLINE_FUNCTION ScalarView< PointScalar, DeviceType > getTensorComponent(const ordinal_type &r) const
Returns the requested tensor component.
Header file for the Intrepid2::CubatureDirect class.
static constexpr ordinal_type MaxTensorComponents
Maximum number of tensor/Cartesian products that can be taken: this allows hypercube basis in 7D to b...
CubatureTensor(const CubatureType0 cubature0, const CubatureType1 cubature1, const CubatureType2 cubature2)
Constructor.