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 SpT, 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,SpT>::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 SpT, 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->basisCardinality_ = Intrepid2::getPnCardinality<spaceDim>(order); // bigN
236  this->basisDegree_ = order; // small n
237  this->basisCellTopology_ = shards::CellTopology(shards::getCellTopologyData<shards::Tetrahedron<4> >() );
238  this->basisType_ = BASIS_FEM_FIAT;
239  this->basisCoordinates_ = COORDINATES_CARTESIAN;
240  this->functionSpace_ = FUNCTION_SPACE_HVOL;
241 
242  const ordinal_type card = this->basisCardinality_;
243 
244  // points are computed in the host and will be copied
245  Kokkos::DynRankView<scalarType,typename SpT::array_layout,Kokkos::HostSpace>
246  dofCoords("HVOL::Tet::Cn::dofCoords", card, spaceDim);
247 
248  // construct lattice (only internal nodes for HVOL element)
249  const ordinal_type offset = 1;
250  PointTools::getLattice( dofCoords,
251  this->basisCellTopology_,
252  order+spaceDim+offset, offset,
253  pointType );
254 
255  this->dofCoords_ = Kokkos::create_mirror_view(typename SpT::memory_space(), dofCoords);
256  Kokkos::deep_copy(this->dofCoords_, dofCoords);
257 
258  // form Vandermonde matrix. Actually, this is the transpose of the VDM,
259  // so we transpose on copy below.
260  const ordinal_type lwork = card*card;
261  Kokkos::DynRankView<scalarType,Kokkos::LayoutLeft,Kokkos::HostSpace>
262  vmat("HVOL::Tet::Cn::vmat", card, card),
263  work("HVOL::Tet::Cn::work", lwork),
264  ipiv("HVOL::Tet::Cn::ipiv", card);
265 
266  Impl::Basis_HGRAD_TET_Cn_FEM_ORTH::getValues<Kokkos::HostSpace::execution_space,Parameters::MaxNumPtsPerBasisEval>(vmat, dofCoords, order, OPERATOR_VALUE);
267 
268  ordinal_type info = 0;
269  Teuchos::LAPACK<ordinal_type,scalarType> lapack;
270 
271  lapack.GETRF(card, card,
272  vmat.data(), vmat.stride_1(),
273  (ordinal_type*)ipiv.data(),
274  &info);
275 
276  INTREPID2_TEST_FOR_EXCEPTION( info != 0,
277  std::runtime_error ,
278  ">>> ERROR: (Intrepid2::Basis_HVOL_TET_Cn_FEM) lapack.GETRF returns nonzero info." );
279 
280  lapack.GETRI(card,
281  vmat.data(), vmat.stride_1(),
282  (ordinal_type*)ipiv.data(),
283  work.data(), lwork,
284  &info);
285 
286  INTREPID2_TEST_FOR_EXCEPTION( info != 0,
287  std::runtime_error ,
288  ">>> ERROR: (Intrepid2::Basis_HVOL_TET_Cn_FEM) lapack.GETRI returns nonzero info." );
289 
290  // create host mirror
291  Kokkos::DynRankView<scalarType,typename SpT::array_layout,Kokkos::HostSpace>
292  vinv("HVOL::Line::Cn::vinv", card, card);
293 
294  for (ordinal_type i=0;i<card;++i)
295  for (ordinal_type j=0;j<card;++j)
296  vinv(i,j) = vmat(j,i);
297 
298  this->vinv_ = Kokkos::create_mirror_view(typename SpT::memory_space(), vinv);
299  Kokkos::deep_copy(this->vinv_ , vinv);
300 
301  // initialize tags
302  {
303  // Basis-dependent initializations
304  constexpr ordinal_type tagSize = 4; // size of DoF tag, i.e., number of fields in the tag
305  const ordinal_type posScDim = 0; // position in the tag, counting from 0, of the subcell dim
306  const ordinal_type posScOrd = 1; // position in the tag, counting from 0, of the subcell ordinal
307  const ordinal_type posDfOrd = 2; // position in the tag, counting from 0, of DoF ordinal relative to the subcell
308 
309  constexpr ordinal_type maxCard = Intrepid2::getPnCardinality<spaceDim, Parameters::MaxOrder>();
310  ordinal_type tags[maxCard][tagSize];
311 
312  const ordinal_type
313  numElemDof = this->basisCardinality_; //all the degrees of freedom are internal.
314 
315 
316  ordinal_type elemId = 0;
317  for (ordinal_type i=0;i<this->basisCardinality_;++i) {
318  // elem
319  tags[i][0] = spaceDim; // intr dof
320  tags[i][1] = 0; // intr id
321  tags[i][2] = elemId++; // local dof id
322  tags[i][3] = numElemDof; // total vert dof
323  }
324 
325  OrdinalTypeArray1DHost tagView(&tags[0][0], card*tagSize);
326 
327  // Basis-independent function sets tag and enum data in tagToOrdinal_ and ordinalToTag_ arrays:
328  // tags are constructed on host
329  this->setOrdinalTagData(this->tagToOrdinal_,
330  this->ordinalToTag_,
331  tagView,
332  this->basisCardinality_,
333  tagSize,
334  posScDim,
335  posScOrd,
336  posDfOrd);
337  }
338  }
339 } // namespace Intrepid2
340 #endif
Kokkos::View< ordinal_type *, typename ExecSpaceType::array_layout, Kokkos::HostSpace > OrdinalTypeArray1DHost
View type for 1d host array.
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 (currently disabled for other ce...
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.