Intrepid2
Intrepid2_HVOL_TET_Cn_FEMDef.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 
48 #ifndef __INTREPID2_HVOL_TET_CN_FEM_DEF_HPP__
49 #define __INTREPID2_HVOL_TET_CN_FEM_DEF_HPP__
50 
52 
53 namespace Intrepid2 {
54 
55  // -------------------------------------------------------------------------------------
56 
57  namespace Impl {
58 
59  template<EOperator opType>
60  template<typename OutputViewType,
61  typename inputViewType,
62  typename workViewType,
63  typename vinvViewType>
64  KOKKOS_INLINE_FUNCTION
65  void
66  Basis_HVOL_TET_Cn_FEM::Serial<opType>::
67  getValues( OutputViewType output,
68  const inputViewType input,
69  workViewType work,
70  const vinvViewType vinv ) {
71 
72  constexpr ordinal_type spaceDim = 3;
73  const ordinal_type
74  card = vinv.extent(0),
75  npts = input.extent(0);
76 
77  // compute order
78  ordinal_type order = 0;
79  for (ordinal_type p=0;p<=Parameters::MaxOrder;++p) {
80  if (card == Intrepid2::getPnCardinality<spaceDim>(p)) {
81  order = p;
82  break;
83  }
84  }
85 
86  typedef typename Kokkos::DynRankView<typename workViewType::value_type, typename workViewType::memory_space> viewType;
87  auto vcprop = Kokkos::common_view_alloc_prop(work);
88  auto ptr = work.data();
89 
90  switch (opType) {
91  case OPERATOR_VALUE: {
92  const viewType phis(Kokkos::view_wrap(ptr, vcprop), card, npts);
93  workViewType dummyView;
94 
95  Impl::Basis_HGRAD_TET_Cn_FEM_ORTH::
96  Serial<opType>::getValues(phis, input, dummyView, order);
97 
98  for (ordinal_type i=0;i<card;++i)
99  for (ordinal_type j=0;j<npts;++j) {
100  output.access(i,j) = 0.0;
101  for (ordinal_type k=0;k<card;++k)
102  output.access(i,j) += vinv(k,i)*phis.access(k,j);
103  }
104  break;
105  }
106  case OPERATOR_GRAD:
107  case OPERATOR_D1: {
108  const viewType phis(Kokkos::view_wrap(ptr, vcprop), card, npts, spaceDim);
109  ptr += card*npts*spaceDim*get_dimension_scalar(work);
110  const viewType workView(Kokkos::view_wrap(ptr, vcprop), card, npts, spaceDim+1);
111  Impl::Basis_HGRAD_TET_Cn_FEM_ORTH::
112  Serial<opType>::getValues(phis, input, workView, order);
113 
114  for (ordinal_type i=0;i<card;++i)
115  for (ordinal_type j=0;j<npts;++j)
116  for (ordinal_type k=0;k<spaceDim;++k) {
117  output.access(i,j,k) = 0.0;
118  for (ordinal_type l=0;l<card;++l)
119  output.access(i,j,k) += vinv(l,i)*phis.access(l,j,k);
120  }
121  break;
122  }
123  case OPERATOR_D2:
124  case OPERATOR_D3:
125  case OPERATOR_D4:
126  case OPERATOR_D5:
127  case OPERATOR_D6:
128  case OPERATOR_D7:
129  case OPERATOR_D8:
130  case OPERATOR_D9:
131  case OPERATOR_D10: {
132  const ordinal_type dkcard = getDkCardinality<opType,spaceDim>(); //(orDn + 1);
133  const viewType phis(Kokkos::view_wrap(ptr, vcprop), card, npts, dkcard);
134  workViewType dummyView;
135 
136  Impl::Basis_HGRAD_TET_Cn_FEM_ORTH::
137  Serial<opType>::getValues(phis, input, dummyView, order);
138 
139  for (ordinal_type i=0;i<card;++i)
140  for (ordinal_type j=0;j<npts;++j)
141  for (ordinal_type k=0;k<dkcard;++k) {
142  output.access(i,j,k) = 0.0;
143  for (ordinal_type l=0;l<card;++l)
144  output.access(i,j,k) += vinv(l,i)*phis.access(l,j,k);
145  }
146  break;
147  }
148  default: {
149  INTREPID2_TEST_FOR_ABORT( true,
150  ">>> ERROR (Basis_HVOL_TET_Cn_FEM): Operator type not implemented");
151  }
152  }
153  }
154 
155  template<typename DT, ordinal_type numPtsPerEval,
156  typename outputValueValueType, class ...outputValueProperties,
157  typename inputPointValueType, class ...inputPointProperties,
158  typename vinvValueType, class ...vinvProperties>
159  void
160  Basis_HVOL_TET_Cn_FEM::
161  getValues( Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValues,
162  const Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPoints,
163  const Kokkos::DynRankView<vinvValueType, vinvProperties...> vinv,
164  const EOperator operatorType) {
165  typedef Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValueViewType;
166  typedef Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPointViewType;
167  typedef Kokkos::DynRankView<vinvValueType, vinvProperties...> vinvViewType;
168  typedef typename ExecSpace<typename inputPointViewType::execution_space,typename DT::execution_space>::ExecSpaceType ExecSpaceType;
169 
170  // loopSize corresponds to cardinality
171  const auto loopSizeTmp1 = (inputPoints.extent(0)/numPtsPerEval);
172  const auto loopSizeTmp2 = (inputPoints.extent(0)%numPtsPerEval != 0);
173  const auto loopSize = loopSizeTmp1 + loopSizeTmp2;
174  Kokkos::RangePolicy<ExecSpaceType,Kokkos::Schedule<Kokkos::Static> > policy(0, loopSize);
175 
176  typedef typename inputPointViewType::value_type inputPointType;
177 
178  const ordinal_type cardinality = outputValues.extent(0);
179  const ordinal_type spaceDim = 3;
180 
181  ordinal_type order = 0;
182  while((Intrepid2::getPnCardinality<spaceDim>(++order) != cardinality) && (order != Parameters::MaxOrder));
183 
184  auto vcprop = Kokkos::common_view_alloc_prop(inputPoints);
185  typedef typename Kokkos::DynRankView< inputPointType, typename inputPointViewType::memory_space> workViewType;
186 
187  switch (operatorType) {
188  case OPERATOR_VALUE: {
189  auto bufferSize = Basis_HVOL_TET_Cn_FEM::Serial<OPERATOR_VALUE>::getWorkSizePerPoint(order);
190  workViewType work(Kokkos::view_alloc("Basis_HVOL_TET_Cn_FEM::getValues::work", vcprop), bufferSize, inputPoints.extent(0));
191  typedef Functor<outputValueViewType,inputPointViewType,vinvViewType, workViewType,
192  OPERATOR_VALUE,numPtsPerEval> FunctorType;
193  Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, vinv, work) );
194  break;
195  }
196  case OPERATOR_GRAD:
197  case OPERATOR_D1: {
198  auto bufferSize = Basis_HVOL_TET_Cn_FEM::Serial<OPERATOR_D1>::getWorkSizePerPoint(order);
199  workViewType work(Kokkos::view_alloc("Basis_HVOL_TET_Cn_FEM::getValues::work", vcprop), bufferSize, inputPoints.extent(0));
200  typedef Functor<outputValueViewType,inputPointViewType,vinvViewType, workViewType,
201  OPERATOR_D1,numPtsPerEval> FunctorType;
202  Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, vinv, work) );
203  break;
204  }
205  case OPERATOR_D2: {
206  auto bufferSize = Basis_HVOL_TET_Cn_FEM::Serial<OPERATOR_D2>::getWorkSizePerPoint(order);
207  typedef Functor<outputValueViewType,inputPointViewType,vinvViewType, workViewType,
208  OPERATOR_D2,numPtsPerEval> FunctorType;
209  workViewType work(Kokkos::view_alloc("Basis_HVOL_TET_Cn_FEM::getValues::work", vcprop), bufferSize, inputPoints.extent(0));
210  Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, vinv, work) );
211  break;
212  }
213  /* case OPERATOR_D3: {
214  typedef Functor<outputValueViewType,inputPointViewType,vinvViewType, workViewType
215  OPERATOR_D3,numPtsPerEval> FunctorType;
216  workViewType work(Kokkos::view_alloc("Basis_HVOL_TET_Cn_FEM::getValues::work", vcprop), cardinality, inputPoints.extent(0), outputValues.extent(2));
217  Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, vinv, work) );
218  break;
219  }*/
220  default: {
221  INTREPID2_TEST_FOR_EXCEPTION( true , std::invalid_argument,
222  ">>> ERROR (Basis_HVOL_TET_Cn_FEM): Operator type not implemented" );
223  }
224  }
225  }
226  }
227 
228  // -------------------------------------------------------------------------------------
229  template<typename DT, typename OT, typename PT>
231  Basis_HVOL_TET_Cn_FEM( const ordinal_type order,
232  const EPointType pointType ) {
233  constexpr ordinal_type spaceDim = 3;
234 
235  this->pointType_ = pointType;
236  this->basisCardinality_ = Intrepid2::getPnCardinality<spaceDim>(order); // bigN
237  this->basisDegree_ = order; // small n
238  this->basisCellTopology_ = shards::CellTopology(shards::getCellTopologyData<shards::Tetrahedron<4> >() );
239  this->basisType_ = BASIS_FEM_LAGRANGIAN;
240  this->basisCoordinates_ = COORDINATES_CARTESIAN;
241  this->functionSpace_ = FUNCTION_SPACE_HVOL;
242 
243  const ordinal_type card = this->basisCardinality_;
244 
245  // points are computed in the host and will be copied
246  Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
247  dofCoords("HVOL::Tet::Cn::dofCoords", card, spaceDim);
248 
249  // construct lattice (only internal nodes for HVOL element)
250  const ordinal_type offset = 1;
251  PointTools::getLattice( dofCoords,
252  this->basisCellTopology_,
253  order+spaceDim+offset, offset,
254  pointType );
255 
256  this->dofCoords_ = Kokkos::create_mirror_view(typename DT::memory_space(), dofCoords);
257  Kokkos::deep_copy(this->dofCoords_, dofCoords);
258 
259  // form Vandermonde matrix. Actually, this is the transpose of the VDM,
260  // so we transpose on copy below.
261  const ordinal_type lwork = card*card;
262  Kokkos::DynRankView<scalarType,Kokkos::LayoutLeft,Kokkos::HostSpace>
263  vmat("HVOL::Tet::Cn::vmat", card, card),
264  work("HVOL::Tet::Cn::work", lwork),
265  ipiv("HVOL::Tet::Cn::ipiv", card);
266 
267  Impl::Basis_HGRAD_TET_Cn_FEM_ORTH::getValues<Kokkos::HostSpace::execution_space,Parameters::MaxNumPtsPerBasisEval>(typename Kokkos::HostSpace::execution_space{},
268  vmat,
269  dofCoords,
270  order,
271  OPERATOR_VALUE);
272 
273  ordinal_type info = 0;
274  Teuchos::LAPACK<ordinal_type,scalarType> lapack;
275 
276  lapack.GETRF(card, card,
277  vmat.data(), vmat.stride_1(),
278  (ordinal_type*)ipiv.data(),
279  &info);
280 
281  INTREPID2_TEST_FOR_EXCEPTION( info != 0,
282  std::runtime_error ,
283  ">>> ERROR: (Intrepid2::Basis_HVOL_TET_Cn_FEM) lapack.GETRF returns nonzero info." );
284 
285  lapack.GETRI(card,
286  vmat.data(), vmat.stride_1(),
287  (ordinal_type*)ipiv.data(),
288  work.data(), lwork,
289  &info);
290 
291  INTREPID2_TEST_FOR_EXCEPTION( info != 0,
292  std::runtime_error ,
293  ">>> ERROR: (Intrepid2::Basis_HVOL_TET_Cn_FEM) lapack.GETRI returns nonzero info." );
294 
295  // create host mirror
296  Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
297  vinv("HVOL::Line::Cn::vinv", card, card);
298 
299  for (ordinal_type i=0;i<card;++i)
300  for (ordinal_type j=0;j<card;++j)
301  vinv(i,j) = vmat(j,i);
302 
303  this->vinv_ = Kokkos::create_mirror_view(typename DT::memory_space(), vinv);
304  Kokkos::deep_copy(this->vinv_ , vinv);
305 
306  // initialize tags
307  {
308  // Basis-dependent initializations
309  constexpr ordinal_type tagSize = 4; // size of DoF tag, i.e., number of fields in the tag
310  const ordinal_type posScDim = 0; // position in the tag, counting from 0, of the subcell dim
311  const ordinal_type posScOrd = 1; // position in the tag, counting from 0, of the subcell ordinal
312  const ordinal_type posDfOrd = 2; // position in the tag, counting from 0, of DoF ordinal relative to the subcell
313 
314  constexpr ordinal_type maxCard = Intrepid2::getPnCardinality<spaceDim, Parameters::MaxOrder>();
315  ordinal_type tags[maxCard][tagSize];
316 
317  const ordinal_type
318  numElemDof = this->basisCardinality_; //all the degrees of freedom are internal.
319 
320 
321  ordinal_type elemId = 0;
322  for (ordinal_type i=0;i<this->basisCardinality_;++i) {
323  // elem
324  tags[i][0] = spaceDim; // intr dof
325  tags[i][1] = 0; // intr id
326  tags[i][2] = elemId++; // local dof id
327  tags[i][3] = numElemDof; // total vert dof
328  }
329 
330  OrdinalTypeArray1DHost tagView(&tags[0][0], card*tagSize);
331 
332  // Basis-independent function sets tag and enum data in tagToOrdinal_ and ordinalToTag_ arrays:
333  // tags are constructed on host
334  this->setOrdinalTagData(this->tagToOrdinal_,
335  this->ordinalToTag_,
336  tagView,
337  this->basisCardinality_,
338  tagSize,
339  posScDim,
340  posScOrd,
341  posDfOrd);
342  }
343  }
344 } // namespace Intrepid2
345 #endif
static void getLattice(Kokkos::DynRankView< pointValueType, pointProperties...> points, const shards::CellTopology cellType, const ordinal_type order, const ordinal_type offset=0, const EPointType pointType=POINTTYPE_EQUISPACED)
Computes a lattice of points of a given order on a reference simplex, quadrilateral or hexahedron (cu...
Basis_HVOL_TET_Cn_FEM(const ordinal_type order, const EPointType pointType=POINTTYPE_EQUISPACED)
Constructor.
Header file for the Intrepid2::Basis_HGRAD_TET_Cn_FEM_ORTH class.
static constexpr ordinal_type MaxOrder
The maximum reconstruction order.