Intrepid2
Intrepid2_HGRAD_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 
49 #ifndef __INTREPID2_HGRAD_TET_CN_FEM_DEF_HPP__
50 #define __INTREPID2_HGRAD_TET_CN_FEM_DEF_HPP__
51 
54 
55 namespace Intrepid2 {
56 
57 // -------------------------------------------------------------------------------------
58 namespace Impl {
59 
60 template<EOperator opType>
61 template<typename OutputViewType,
62 typename inputViewType,
63 typename workViewType,
64 typename vinvViewType>
65 KOKKOS_INLINE_FUNCTION
66 void
67 Basis_HGRAD_TET_Cn_FEM::Serial<opType>::
68 getValues( OutputViewType output,
69  const inputViewType input,
70  workViewType work,
71  const vinvViewType vinv ) {
72 
73  constexpr ordinal_type spaceDim = 3;
74  const ordinal_type
75  card = vinv.extent(0),
76  npts = input.extent(0);
77 
78  // compute order
79  ordinal_type order = 0;
80  for (ordinal_type p=0;p<=Parameters::MaxOrder;++p) {
81  if (card == Intrepid2::getPnCardinality<spaceDim>(p)) {
82  order = p;
83  break;
84  }
85  }
86 
87  typedef typename Kokkos::DynRankView<typename workViewType::value_type, typename workViewType::memory_space> viewType;
88  auto vcprop = Kokkos::common_view_alloc_prop(work);
89  auto ptr = work.data();
90 
91  switch (opType) {
92  case OPERATOR_VALUE: {
93  const viewType phis(Kokkos::view_wrap(ptr, vcprop), card, npts);
94  viewType dummyView;
95 
96  Impl::Basis_HGRAD_TET_Cn_FEM_ORTH::
97  Serial<opType>::getValues(phis, input, dummyView, order);
98 
99  for (ordinal_type i=0;i<card;++i)
100  for (ordinal_type j=0;j<npts;++j) {
101  output.access(i,j) = 0.0;
102  for (ordinal_type k=0;k<card;++k)
103  output.access(i,j) += vinv(k,i)*phis.access(k,j);
104  }
105  break;
106  }
107  case OPERATOR_GRAD:
108  case OPERATOR_D1: {
109  const viewType phis(Kokkos::view_wrap(ptr, vcprop), card, npts, spaceDim);
110  ptr += card*npts*spaceDim*get_dimension_scalar(work);
111  const viewType workView(Kokkos::view_wrap(ptr, vcprop), card, npts, spaceDim+1);
112  Impl::Basis_HGRAD_TET_Cn_FEM_ORTH::
113  Serial<opType>::getValues(phis, input, workView, order);
114 
115  for (ordinal_type i=0;i<card;++i)
116  for (ordinal_type j=0;j<npts;++j)
117  for (ordinal_type k=0;k<spaceDim;++k) {
118  output.access(i,j,k) = 0.0;
119  for (ordinal_type l=0;l<card;++l)
120  output.access(i,j,k) += vinv(l,i)*phis.access(l,j,k);
121  }
122  break;
123  }
124  case OPERATOR_D2:
125  case OPERATOR_D3:
126  case OPERATOR_D4:
127  case OPERATOR_D5:
128  case OPERATOR_D6:
129  case OPERATOR_D7:
130  case OPERATOR_D8:
131  case OPERATOR_D9:
132  case OPERATOR_D10: {
133  const ordinal_type dkcard = getDkCardinality<opType,spaceDim>(); //(orDn + 1);
134  const viewType phis(Kokkos::view_wrap(ptr, vcprop), card, npts, dkcard);
135  viewType dummyView;
136 
137  Impl::Basis_HGRAD_TET_Cn_FEM_ORTH::
138  Serial<opType>::getValues(phis, input, dummyView, order);
139 
140  for (ordinal_type i=0;i<card;++i)
141  for (ordinal_type j=0;j<npts;++j)
142  for (ordinal_type k=0;k<dkcard;++k) {
143  output.access(i,j,k) = 0.0;
144  for (ordinal_type l=0;l<card;++l)
145  output.access(i,j,k) += vinv(l,i)*phis.access(l,j,k);
146  }
147  break;
148  }
149  default: {
150  INTREPID2_TEST_FOR_ABORT( true,
151  ">>> ERROR (Basis_HGRAD_TET_Cn_FEM): Operator type not implemented");
152  }
153  }
154 }
155 
156 template<typename DT, ordinal_type numPtsPerEval,
157 typename outputValueValueType, class ...outputValueProperties,
158 typename inputPointValueType, class ...inputPointProperties,
159 typename vinvValueType, class ...vinvProperties>
160 void
161 Basis_HGRAD_TET_Cn_FEM::
162 getValues( Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValues,
163  const Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPoints,
164  const Kokkos::DynRankView<vinvValueType, vinvProperties...> vinv,
165  const EOperator operatorType) {
166  typedef Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValueViewType;
167  typedef Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPointViewType;
168  typedef Kokkos::DynRankView<vinvValueType, vinvProperties...> vinvViewType;
169  typedef typename ExecSpace<typename inputPointViewType::execution_space,typename DT::execution_space>::ExecSpaceType ExecSpaceType;
170 
171  // loopSize corresponds to cardinality
172  const auto loopSizeTmp1 = (inputPoints.extent(0)/numPtsPerEval);
173  const auto loopSizeTmp2 = (inputPoints.extent(0)%numPtsPerEval != 0);
174  const auto loopSize = loopSizeTmp1 + loopSizeTmp2;
175  Kokkos::RangePolicy<ExecSpaceType,Kokkos::Schedule<Kokkos::Static> > policy(0, loopSize);
176 
177  typedef typename inputPointViewType::value_type inputPointType;
178 
179  const ordinal_type cardinality = outputValues.extent(0);
180  const ordinal_type spaceDim = 3;
181 
182  auto vcprop = Kokkos::common_view_alloc_prop(inputPoints);
183  typedef typename Kokkos::DynRankView< inputPointType, typename inputPointViewType::memory_space> workViewType;
184 
185  switch (operatorType) {
186  case OPERATOR_VALUE: {
187  workViewType work(Kokkos::view_alloc("Basis_HGRAD_TET_Cn_FEM::getValues::work", vcprop), cardinality, inputPoints.extent(0));
188  typedef Functor<outputValueViewType,inputPointViewType,vinvViewType, workViewType,
189  OPERATOR_VALUE,numPtsPerEval> FunctorType;
190  Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, vinv, work) );
191  break;
192  }
193  case OPERATOR_GRAD:
194  case OPERATOR_D1: {
195  workViewType work(Kokkos::view_alloc("Basis_HGRAD_TET_Cn_FEM::getValues::work", vcprop), cardinality*(2*spaceDim+1), inputPoints.extent(0));
196  typedef Functor<outputValueViewType,inputPointViewType,vinvViewType, workViewType,
197  OPERATOR_D1,numPtsPerEval> FunctorType;
198  Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, vinv, work) );
199  break;
200  }
201  case OPERATOR_D2: {
202  typedef Functor<outputValueViewType,inputPointViewType,vinvViewType, workViewType,
203  OPERATOR_D2,numPtsPerEval> FunctorType;
204  workViewType work(Kokkos::view_alloc("Basis_HGRAD_TET_Cn_FEM::getValues::work", vcprop), cardinality*outputValues.extent(2), inputPoints.extent(0));
205  Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, vinv, work) );
206  break;
207  }
208  /* case OPERATOR_D3: {
209  typedef Functor<outputValueViewType,inputPointViewType,vinvViewType, workViewType
210  OPERATOR_D3,numPtsPerEval> FunctorType;
211  workViewType work(Kokkos::view_alloc("Basis_HGRAD_TET_Cn_FEM::getValues::work", vcprop), cardinality, inputPoints.extent(0), outputValues.extent(2));
212  Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, vinv, work) );
213  break;
214  }*/
215  default: {
216  INTREPID2_TEST_FOR_EXCEPTION( true , std::invalid_argument,
217  ">>> ERROR (Basis_HGRAD_TET_Cn_FEM): Operator type not implemented" );
218  }
219  }
220 }
221 }
222 
223 // -------------------------------------------------------------------------------------
224 template<typename DT, typename OT, typename PT>
226 Basis_HGRAD_TET_Cn_FEM( const ordinal_type order,
227  const EPointType pointType ) {
228  constexpr ordinal_type spaceDim = 3;
229 
230  this->basisCardinality_ = Intrepid2::getPnCardinality<spaceDim>(order); // bigN
231  this->basisDegree_ = order; // small n
232  this->basisCellTopology_ = shards::CellTopology(shards::getCellTopologyData<shards::Tetrahedron<4> >() );
233  this->basisType_ = BASIS_FEM_LAGRANGIAN;
234  this->basisCoordinates_ = COORDINATES_CARTESIAN;
235  this->functionSpace_ = FUNCTION_SPACE_HGRAD;
236  pointType_ = (pointType == POINTTYPE_DEFAULT) ? POINTTYPE_EQUISPACED : pointType;
237 
238  const ordinal_type card = this->basisCardinality_;
239 
240  // points are computed in the host and will be copied
241  Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
242  dofCoords("Hgrad::Tet::Cn::dofCoords", card, spaceDim);
243 
244  // Basis-dependent initializations
245  constexpr ordinal_type tagSize = 4; // size of DoF tag, i.e., number of fields in the tag
246  constexpr ordinal_type maxCard = Intrepid2::getPnCardinality<spaceDim, Parameters::MaxOrder>();
247  ordinal_type tags[maxCard][tagSize];
248 
249  // construct lattice
250 
251  const ordinal_type numEdges = this->basisCellTopology_.getEdgeCount();
252  const ordinal_type numFaces = this->basisCellTopology_.getFaceCount();
253 
254  shards::CellTopology edgeTop(shards::getCellTopologyData<shards::Line<2> >() );
255  shards::CellTopology faceTop(shards::getCellTopologyData<shards::Triangle<3> >() );
256 
257  const int numVertexes = PointTools::getLatticeSize( this->basisCellTopology_ ,
258  1 ,
259  0 );
260 
261  const int numPtsPerEdge = PointTools::getLatticeSize( edgeTop ,
262  order ,
263  1 );
264 
265  const int numPtsPerFace = PointTools::getLatticeSize( faceTop ,
266  order ,
267  1 );
268 
269  const int numPtsPerCell = PointTools::getLatticeSize( this->basisCellTopology_ ,
270  order ,
271  1 );
272 
273  Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> vertexes("Hcurl::Tet::In::vertexes", numVertexes , spaceDim );
274  Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> linePts("Hcurl::Tet::In::linePts", numPtsPerEdge , 1 );
275  Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> triPts("Hcurl::Tet::In::triPts", numPtsPerFace , 2 );
276 
277  // construct lattice
278  const ordinal_type offset = 1;
279 
280 
281  PointTools::getLattice( vertexes,
282  this->basisCellTopology_ ,
283  1, 0,
284  this->pointType_ );
285 
286  PointTools::getLattice( linePts,
287  edgeTop,
288  order, offset,
289  this->pointType_ );
290 
291  PointTools::getLattice( triPts,
292  faceTop,
293  order, offset,
294  this->pointType_ );
295 
296  // holds the image of the line points
297  Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> edgePts("Hcurl::Tet::In::edgePts", numPtsPerEdge , spaceDim );
298  Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> facePts("Hcurl::Tet::In::facePts", numPtsPerFace , spaceDim );
299 
300  for (ordinal_type i=0;i<numVertexes;i++) {
301  auto i_card=i;
302  for(ordinal_type k=0; k<spaceDim; ++k)
303  dofCoords(i_card,k) = vertexes(i,k);
304  tags[i_card][0] = 0; // vertex dof
305  tags[i_card][1] = i; // vertex id
306  tags[i_card][2] = 0; // local dof id
307  tags[i_card][3] = 1; // total vert dof
308  }
309 
310 
311  // these are tangents scaled by the appropriate edge lengths.
312  for (ordinal_type i=0;i<numEdges;i++) { // loop over edges
314  linePts ,
315  1 ,
316  i ,
317  this->basisCellTopology_ );
318 
319 
320  // loop over points (rows of V2)
321  for (ordinal_type j=0;j<numPtsPerEdge;j++) {
322 
323  const ordinal_type i_card = numVertexes + numPtsPerEdge*i+j;
324 
325  //save dof coordinates and coefficients
326  for(ordinal_type k=0; k<spaceDim; ++k)
327  dofCoords(i_card,k) = edgePts(j,k);
328 
329  tags[i_card][0] = 1; // edge dof
330  tags[i_card][1] = i; // edge id
331  tags[i_card][2] = j; // local dof id
332  tags[i_card][3] = numPtsPerEdge; // total edge dof
333 
334  }
335  }
336 
337  if(numPtsPerFace >0) {//handle faces if needed (order >1)
338 
339  for (ordinal_type i=0;i<numFaces;i++) { // loop over faces
340 
342  triPts ,
343  2 ,
344  i ,
345  this->basisCellTopology_ );
346  for (ordinal_type j=0;j<numPtsPerFace;j++) {
347 
348  const ordinal_type i_card = numVertexes+numEdges*numPtsPerEdge+numPtsPerFace*i+j;
349 
350  //save dof coordinates
351  for(ordinal_type k=0; k<spaceDim; ++k)
352  dofCoords(i_card,k) = facePts(j,k);
353 
354  tags[i_card][0] = 2; // face dof
355  tags[i_card][1] = i; // face id
356  tags[i_card][2] = j; // local face id
357  tags[i_card][3] = numPtsPerFace; // total face dof
358  }
359  }
360  }
361 
362 
363  // internal dof, if needed
364  if (numPtsPerCell > 0) {
365  Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
366  cellPoints( "Hcurl::Tet::In::cellPoints", numPtsPerCell , spaceDim );
367  PointTools::getLattice( cellPoints ,
368  this->basisCellTopology_ ,
369  order,
370  1 ,
371  this->pointType_ );
372 
373  // copy values into right positions of V2
374  for (ordinal_type j=0;j<numPtsPerCell;j++) {
375 
376  const ordinal_type i_card = numVertexes+numEdges*numPtsPerEdge+numFaces*numPtsPerFace+j;
377 
378  //save dof coordinates
379  for(ordinal_type dim=0; dim<spaceDim; ++dim)
380  dofCoords(i_card,dim) = cellPoints(j,dim);
381 
382  tags[i_card][0] = spaceDim; // elem dof
383  tags[i_card][1] = 0; // elem id
384  tags[i_card][2] = j; // local dof id
385  tags[i_card][3] = numPtsPerCell; // total vert dof
386  }
387  }
388 
389  this->dofCoords_ = Kokkos::create_mirror_view(typename DT::memory_space(), dofCoords);
390  Kokkos::deep_copy(this->dofCoords_, dofCoords);
391 
392  // form Vandermonde matrix. Actually, this is the transpose of the VDM,
393  // so we transpose on copy below.
394  const ordinal_type lwork = card*card;
395  Kokkos::DynRankView<scalarType,Kokkos::LayoutLeft,Kokkos::HostSpace>
396  vmat("Hgrad::Tet::Cn::vmat", card, card),
397  work("Hgrad::Tet::Cn::work", lwork),
398  ipiv("Hgrad::Tet::Cn::ipiv", card);
399 
400  Impl::Basis_HGRAD_TET_Cn_FEM_ORTH::getValues<Kokkos::HostSpace::device_type,Parameters::MaxNumPtsPerBasisEval>(vmat, dofCoords, order, OPERATOR_VALUE);
401 
402  ordinal_type info = 0;
403  Teuchos::LAPACK<ordinal_type,scalarType> lapack;
404 
405  lapack.GETRF(card, card,
406  vmat.data(), vmat.stride_1(),
407  (ordinal_type*)ipiv.data(),
408  &info);
409 
410  INTREPID2_TEST_FOR_EXCEPTION( info != 0,
411  std::runtime_error ,
412  ">>> ERROR: (Intrepid2::Basis_HGRAD_TET_Cn_FEM) lapack.GETRF returns nonzero info." );
413 
414  lapack.GETRI(card,
415  vmat.data(), vmat.stride_1(),
416  (ordinal_type*)ipiv.data(),
417  work.data(), lwork,
418  &info);
419 
420  INTREPID2_TEST_FOR_EXCEPTION( info != 0,
421  std::runtime_error ,
422  ">>> ERROR: (Intrepid2::Basis_HGRAD_TET_Cn_FEM) lapack.GETRI returns nonzero info." );
423 
424  // create host mirror
425  Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
426  vinv("Hgrad::Line::Cn::vinv", card, card);
427 
428  for (ordinal_type i=0;i<card;++i)
429  for (ordinal_type j=0;j<card;++j)
430  vinv(i,j) = vmat(j,i);
431 
432  this->vinv_ = Kokkos::create_mirror_view(typename DT::memory_space(), vinv);
433  Kokkos::deep_copy(this->vinv_ , vinv);
434 
435  // initialize tags
436  {
437  // Basis-dependent initializations
438  const ordinal_type posScDim = 0; // position in the tag, counting from 0, of the subcell dim
439  const ordinal_type posScOrd = 1; // position in the tag, counting from 0, of the subcell ordinal
440  const ordinal_type posDfOrd = 2; // position in the tag, counting from 0, of DoF ordinal relative to the subcell
441 
442  OrdinalTypeArray1DHost tagView(&tags[0][0], card*tagSize);
443 
444  // Basis-independent function sets tag and enum data in tagToOrdinal_ and ordinalToTag_ arrays:
445  // tags are constructed on host
446  this->setOrdinalTagData(this->tagToOrdinal_,
447  this->ordinalToTag_,
448  tagView,
449  this->basisCardinality_,
450  tagSize,
451  posScDim,
452  posScOrd,
453  posDfOrd);
454  }
455 }
456 } // namespace Intrepid2
457 #endif
Header file for the Intrepid2::Basis_HGRAD_TET_Cn_FEM class.
static void mapToReferenceSubcell(Kokkos::DynRankView< refSubcellPointValueType, refSubcellPointProperties... > refSubcellPoints, const Kokkos::DynRankView< paramPointValueType, paramPointProperties... > paramPoints, const ordinal_type subcellDim, const ordinal_type subcellOrd, const shards::CellTopology parentCell)
Computes parameterization maps of 1- and 2-subcells of reference cells.
EPointType
Enumeration of types of point distributions in Intrepid.
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_HGRAD_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.
static ordinal_type getLatticeSize(const shards::CellTopology cellType, const ordinal_type order, const ordinal_type offset=0)
Computes the number of points in a lattice of a given order on a simplex (currently disabled for othe...