Intrepid2
Intrepid2_CubatureDirect.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_DIRECT_HPP__
50 #define __INTREPID2_CUBATURE_DIRECT_HPP__
51 
52 #include "Intrepid2_ConfigDefs.hpp"
53 #include "Intrepid2_Cubature.hpp"
54 
55 namespace Intrepid2 {
56 
73  template<typename ExecSpaceType = void,
74  typename pointValueType = double,
75  typename weightValueType = double>
77  : public Cubature<ExecSpaceType,pointValueType,weightValueType> {
78  protected:
79 
84 
87  ordinal_type numPoints_;
88 
92 
96  };
97 
101  struct CubatureData {
102 
105  ordinal_type numPoints_;
106 
109  Kokkos::DynRankView<pointValueType,ExecSpaceType> points_;
110 
113  Kokkos::DynRankView<weightValueType,ExecSpaceType> weights_;
114  };
115 
119  ordinal_type degree_;
120 
123  ordinal_type dimension_;
124 
128 
135  template<typename cubPointValueType, class ...cubPointProperties,
136  typename cubWeightValueType, class ...cubWeightProperties>
137  void
138  getCubatureFromData( Kokkos::DynRankView<cubPointValueType, cubPointProperties...> cubPoints,
139  Kokkos::DynRankView<cubWeightValueType,cubWeightProperties...> cubWeights,
140  const CubatureData cubData) const {
141 #ifdef HAVE_INTREPID2_DEBUG
142  // check size of cubPoints and cubWeights
143  INTREPID2_TEST_FOR_EXCEPTION( cubPoints.rank() != 2, std::invalid_argument,
144  ">>> ERROR (CubatureDirect): cubPoints must be rank 2." );
145 
146  INTREPID2_TEST_FOR_EXCEPTION( cubWeights.rank() != 1, std::invalid_argument,
147  ">>> ERROR (CubatureDirect): cubPoints must be rank 1." );
148 
149  INTREPID2_TEST_FOR_EXCEPTION( static_cast<ordinal_type>(cubPoints.extent(0)) < this->getNumPoints() ||
150  static_cast<ordinal_type>(cubPoints.extent(1)) < this->getDimension(), std::out_of_range,
151  ">>> ERROR (CubatureDirect): Insufficient space allocated for cubature points.");
152 
153  INTREPID2_TEST_FOR_EXCEPTION( static_cast<ordinal_type>(cubWeights.extent(0)) < this->getNumPoints(), std::out_of_range,
154  ">>> ERROR (CubatureDirect): Insufficient space allocated for cubature weights.");
155 #endif
156  // need subview here
157  typedef Kokkos::pair<ordinal_type,ordinal_type> range_type;
158 
159  range_type pointRange(0, this->getNumPoints());
160  range_type dimRange (0, this->getDimension());
161  {
162  const auto src = Kokkos::subdynrankview(cubData.points_, pointRange, dimRange);
163  auto dst = Kokkos::subdynrankview(cubPoints, pointRange, dimRange);
164 
165  Kokkos::deep_copy( dst, src );
166  }
167  {
168  const auto src = Kokkos::subdynrankview(cubData.weights_, pointRange);
169  auto dst = Kokkos::subdynrankview(cubWeights, pointRange);
170 
171  Kokkos::deep_copy(dst ,src);
172  }
173  }
174 
175  public:
176 
177  //
178  // Cubature public functions
179  //
180  typedef typename Cubature<ExecSpaceType,pointValueType,weightValueType>::pointViewType pointViewType;
181  typedef typename Cubature<ExecSpaceType,pointValueType,weightValueType>::weightViewType weightViewType;
182 
184 
185  virtual
186  void
187  getCubature( pointViewType cubPoints,
188  weightViewType cubWeights ) const {
189  this->getCubatureFromData(cubPoints, cubWeights, this->cubatureData_);
190  }
191 
194  virtual
195  ordinal_type
196  getNumPoints() const {
197  return cubatureData_.numPoints_;
198  }
199 
202  virtual
203  ordinal_type
204  getDimension() const {
205  return dimension_;
206  }
207 
210  virtual
211  const char*
212  getName() const {
213  return "CubatureDirect";
214  }
215 
219  virtual
220  ordinal_type
221  getAccuracy() const {
222  return degree_;
223  }
224 
226  : degree_(),
227  dimension_(),
228  cubatureData_() {}
229 
230  CubatureDirect(const CubatureDirect &b)
231  : degree_(b.degree_),
234 
235  CubatureDirect(const ordinal_type degree,
236  const ordinal_type dimension)
237  : degree_(degree),
238  dimension_(dimension),
239  cubatureData_() {}
240 
241  };
242 
243 } // end namespace Intrepid2
244 
245 
246 #endif
Intrepid2::Parameters::MaxDimension
static constexpr ordinal_type MaxDimension
The maximum ambient space dimension.
Definition: Intrepid2_Types.hpp:135
Intrepid2::CubatureDirect::CubatureData
Cubature data is defined on exec space and deep-copied when an object is created.
Definition: Intrepid2_CubatureDirect.hpp:101
Intrepid2::Cubature
Defines the base class for cubature (integration) rules in Intrepid.
Definition: Intrepid2_Cubature.hpp:122
Intrepid2::CubatureDirect::getNumPoints
virtual ordinal_type getNumPoints() const
Returns the number of cubature points.
Definition: Intrepid2_CubatureDirect.hpp:196
Intrepid2::CubatureDirect::CubatureData::points_
Kokkos::DynRankView< pointValueType, ExecSpaceType > points_
Array with the (X,Y,Z) coordinates of the cubature points.
Definition: Intrepid2_CubatureDirect.hpp:109
Intrepid2::CubatureDirect::CubatureData::numPoints_
ordinal_type numPoints_
Number of cubature points stored in the template.
Definition: Intrepid2_CubatureDirect.hpp:105
Intrepid2::CubatureDirect::degree_
ordinal_type degree_
The degree of polynomials that are integrated exactly by this cubature rule.
Definition: Intrepid2_CubatureDirect.hpp:119
Intrepid2::CubatureDirect::cubatureData_
CubatureData cubatureData_
Cubature data on device.
Definition: Intrepid2_CubatureDirect.hpp:127
Intrepid2::CubatureDirect::CubatureDataStatic::numPoints_
ordinal_type numPoints_
Number of cubature points stored in the template.
Definition: Intrepid2_CubatureDirect.hpp:87
Intrepid2::CubatureDirect::getCubature
virtual void getCubature(pointViewType cubPoints, weightViewType cubWeights) const
Returns cubature points and weights (return arrays must be pre-sized/pre-allocated).
Definition: Intrepid2_CubatureDirect.hpp:187
Intrepid2::Parameters::MaxIntegrationPoints
static constexpr ordinal_type MaxIntegrationPoints
The maximum number of integration points for direct cubature rules.
Definition: Intrepid2_Types.hpp:125
Intrepid2::CubatureDirect::getDimension
virtual ordinal_type getDimension() const
Returns dimension of integration domain.
Definition: Intrepid2_CubatureDirect.hpp:204
Intrepid2::CubatureDirect::dimension_
ordinal_type dimension_
Dimension of integration domain.
Definition: Intrepid2_CubatureDirect.hpp:123
Intrepid2::CubatureDirect::CubatureDataStatic
Cubature data is defined on the host space and is static.
Definition: Intrepid2_CubatureDirect.hpp:83
Intrepid2::CubatureDirect::CubatureDataStatic::weights_
weightValueType weights_[Parameters::MaxIntegrationPoints]
Array with the associated cubature weights.
Definition: Intrepid2_CubatureDirect.hpp:95
Intrepid2::CubatureDirect::CubatureData::weights_
Kokkos::DynRankView< weightValueType, ExecSpaceType > weights_
Array with the associated cubature weights.
Definition: Intrepid2_CubatureDirect.hpp:113
Intrepid2::CubatureDirect::getCubatureFromData
void getCubatureFromData(Kokkos::DynRankView< cubPointValueType, cubPointProperties... > cubPoints, Kokkos::DynRankView< cubWeightValueType, cubWeightProperties... > cubWeights, const CubatureData cubData) const
Returns cubature points and weights.
Definition: Intrepid2_CubatureDirect.hpp:138
Intrepid2_Cubature.hpp
Header file for the Intrepid2::Cubature class.
Intrepid2::CubatureDirect::getName
virtual const char * getName() const
Returns cubature name.
Definition: Intrepid2_CubatureDirect.hpp:212
Intrepid2::CubatureDirect::getAccuracy
virtual ordinal_type getAccuracy() const
Returns max. degree of polynomials that are integrated exactly. The return vector has size 1.
Definition: Intrepid2_CubatureDirect.hpp:221
Intrepid2::CubatureDirect
Defines direct cubature (integration) rules in Intrepid.
Definition: Intrepid2_CubatureDirect.hpp:76
Intrepid2::CubatureDirect::CubatureDataStatic::points_
pointValueType points_[Parameters::MaxIntegrationPoints][Parameters::MaxDimension]
Array with the (X,Y,Z) coordinates of the cubature points.
Definition: Intrepid2_CubatureDirect.hpp:91