Intrepid2
Intrepid2_CubatureTensorDef.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_DEF_HPP__
50 #define __INTREPID2_CUBATURE_TENSOR_DEF_HPP__
51 
52 namespace Intrepid2 {
53 
54  template<typename SpT, typename PT, typename WT>
55  template<typename cubPointValueType, class ...cubPointProperties,
56  typename cubWeightValueType, class ...cubWeightProperties>
57  void
58  CubatureTensor<SpT,PT,WT>::
59  getCubatureImpl( Kokkos::DynRankView<cubPointValueType, cubPointProperties...> cubPoints,
60  Kokkos::DynRankView<cubWeightValueType,cubWeightProperties...> cubWeights ) const {
61 #ifdef HAVE_INTREPID2_DEBUG
62  // check size of cubPoints and cubWeights
63  INTREPID2_TEST_FOR_EXCEPTION( static_cast<ordinal_type>(cubPoints.extent(0)) < this->getNumPoints() ||
64  static_cast<ordinal_type>(cubPoints.extent(1)) < this->getDimension() ||
65  static_cast<ordinal_type>(cubWeights.extent(0)) < this->getNumPoints(), std::out_of_range,
66  ">>> ERROR (CubatureTensor): Insufficient space allocated for cubature points or weights.");
67 #endif
68  typedef Kokkos::DynRankView<cubPointValueType, SpT> cubPointViewType;
69  typedef Kokkos::DynRankView<cubWeightValueType,SpT> cubWeightViewType;
70 
71  // mirroring and where the data is problematic... when it becomes a problem, then deal with it.
72  cubPointViewType tmpPoints [Parameters::MaxDimension];
73  cubWeightViewType tmpWeights[Parameters::MaxDimension];
74 
75  // this temporary allocation can be member of cubature; for now, let's do this way.
76  // this is cubature setup on the reference cell and called for tensor elements.
77  for (auto k=0;k<this->numCubatures_;++k) {
78  const auto &cub = this->cubatures_[k];
79  tmpPoints [k] = cubPointViewType ("CubatureTensor::getCubature::tmpPoints", cub.getNumPoints(), cub.getDimension());
80  tmpWeights[k] = cubWeightViewType("CubatureTensor::getCubature::tmpWeights", cub.getNumPoints());
81  cub.getCubature(tmpPoints[k], tmpWeights[k]);
82  }
83 
84  {
85  const auto npts = this->getNumPoints();
86  const auto dim = this->getDimension();
87 
88  const Kokkos::pair<ordinal_type,ordinal_type> pointRange(0, npts);
89  const Kokkos::pair<ordinal_type,ordinal_type> dimRange(0, dim);
90 
91  Kokkos::deep_copy(Kokkos::subdynrankview(cubPoints, pointRange, dimRange), 0.0);
92  Kokkos::deep_copy(Kokkos::subdynrankview(cubWeights, pointRange), 1.0);
93  }
94 
95  // when the input containers are device space, this is better computed on host and copy to devices
96  // fill tensor cubature
97  {
98  ordinal_type offset[Parameters::MaxDimension+1] = {};
99  for (auto k=0;k<this->numCubatures_;++k) {
100  offset[k+1] = offset[k] + this->cubatures_[k].getDimension();
101  }
102  ordinal_type ii = 0, i[3] = {};
103  switch (this->numCubatures_) {
104  case 2: {
105  const ordinal_type npts[] = { this->cubatures_[0].getNumPoints(), this->cubatures_[1].getNumPoints() };
106  const ordinal_type dim [] = { this->cubatures_[0].getDimension(), this->cubatures_[1].getDimension() };
107 
108  for (i[1]=0;i[1]<npts[1];++i[1])
109  for (i[0]=0;i[0]<npts[0];++i[0]) {
110  for (auto nc=0;nc<2;++nc) {
111  cubWeights(ii) *= tmpWeights[nc](i[nc]);
112  for (ordinal_type j=0;j<dim[nc];++j)
113  cubPoints(ii, offset[nc]+j) = tmpPoints[nc](i[nc], j);
114  }
115  ++ii;
116  }
117  break;
118  }
119  case 3: {
120  const ordinal_type npts[] = { this->cubatures_[0].getNumPoints(), this->cubatures_[1].getNumPoints(), this->cubatures_[2].getNumPoints() };
121  const ordinal_type dim [] = { this->cubatures_[0].getDimension(), this->cubatures_[1].getDimension(), this->cubatures_[2].getDimension() };
122 
123  for (i[2]=0;i[2]<npts[2];++i[2])
124  for (i[1]=0;i[1]<npts[1];++i[1])
125  for (i[0]=0;i[0]<npts[0];++i[0]) {
126  for (auto nc=0;nc<3;++nc) {
127  cubWeights(ii) *= tmpWeights[nc](i[nc]);
128  for (ordinal_type j=0;j<dim[nc];++j)
129  cubPoints(ii, offset[nc]+j) = tmpPoints[nc](i[nc], j);
130  }
131  ++ii;
132  }
133  break;
134  }
135  default: {
136  INTREPID2_TEST_FOR_EXCEPTION( this->numCubatures_ != 2 || this->numCubatures_ != 3, std::runtime_error,
137  ">>> ERROR (CubatureTensor::getCubature): CubatureTensor supports only 2 or 3 component direct cubatures.");
138  }
139  }
140  }
141  }
142 
143 } // end namespace Intrepid2
144 
145 #endif
static constexpr ordinal_type MaxDimension
The maximum ambient space dimension.