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(
163  const typename DT::execution_space& space,
164  Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValues,
165  const Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPoints,
166  const Kokkos::DynRankView<vinvValueType, vinvProperties...> vinv,
167  const EOperator operatorType) {
168  typedef Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValueViewType;
169  typedef Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPointViewType;
170  typedef Kokkos::DynRankView<vinvValueType, vinvProperties...> vinvViewType;
171  typedef typename ExecSpace<typename inputPointViewType::execution_space,typename DT::execution_space>::ExecSpaceType ExecSpaceType;
172 
173  // loopSize corresponds to cardinality
174  const auto loopSizeTmp1 = (inputPoints.extent(0)/numPtsPerEval);
175  const auto loopSizeTmp2 = (inputPoints.extent(0)%numPtsPerEval != 0);
176  const auto loopSize = loopSizeTmp1 + loopSizeTmp2;
177  Kokkos::RangePolicy<ExecSpaceType,Kokkos::Schedule<Kokkos::Static> > policy(space, 0, loopSize);
178 
179  typedef typename inputPointViewType::value_type inputPointType;
180 
181  const ordinal_type cardinality = outputValues.extent(0);
182  const ordinal_type spaceDim = 3;
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  workViewType work(Kokkos::view_alloc(space, "Basis_HGRAD_TET_Cn_FEM::getValues::work", vcprop), cardinality, inputPoints.extent(0));
190  typedef Functor<outputValueViewType,inputPointViewType,vinvViewType, workViewType,
191  OPERATOR_VALUE,numPtsPerEval> FunctorType;
192  Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, vinv, work) );
193  break;
194  }
195  case OPERATOR_GRAD:
196  case OPERATOR_D1: {
197  workViewType work(Kokkos::view_alloc(space, "Basis_HGRAD_TET_Cn_FEM::getValues::work", vcprop), cardinality*(2*spaceDim+1), inputPoints.extent(0));
198  typedef Functor<outputValueViewType,inputPointViewType,vinvViewType, workViewType,
199  OPERATOR_D1,numPtsPerEval> FunctorType;
200  Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, vinv, work) );
201  break;
202  }
203  case OPERATOR_D2: {
204  typedef Functor<outputValueViewType,inputPointViewType,vinvViewType, workViewType,
205  OPERATOR_D2,numPtsPerEval> FunctorType;
206  workViewType work(Kokkos::view_alloc(space, "Basis_HGRAD_TET_Cn_FEM::getValues::work", vcprop), cardinality*outputValues.extent(2), inputPoints.extent(0));
207  Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, vinv, work) );
208  break;
209  }
210  /* case OPERATOR_D3: {
211  typedef Functor<outputValueViewType,inputPointViewType,vinvViewType, workViewType
212  OPERATOR_D3,numPtsPerEval> FunctorType;
213  workViewType work(Kokkos::view_alloc("Basis_HGRAD_TET_Cn_FEM::getValues::work", vcprop), cardinality, inputPoints.extent(0), outputValues.extent(2));
214  Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, vinv, work) );
215  break;
216  }*/
217  default: {
218  INTREPID2_TEST_FOR_EXCEPTION( true , std::invalid_argument,
219  ">>> ERROR (Basis_HGRAD_TET_Cn_FEM): Operator type not implemented" );
220  }
221  }
222 }
223 }
224 
225 // -------------------------------------------------------------------------------------
226 template<typename DT, typename OT, typename PT>
228 Basis_HGRAD_TET_Cn_FEM( const ordinal_type order,
229  const EPointType pointType ) {
230  constexpr ordinal_type spaceDim = 3;
231 
232  this->basisCardinality_ = Intrepid2::getPnCardinality<spaceDim>(order); // bigN
233  this->basisDegree_ = order; // small n
234  this->basisCellTopology_ = shards::CellTopology(shards::getCellTopologyData<shards::Tetrahedron<4> >() );
235  this->basisType_ = BASIS_FEM_LAGRANGIAN;
236  this->basisCoordinates_ = COORDINATES_CARTESIAN;
237  this->functionSpace_ = FUNCTION_SPACE_HGRAD;
238  pointType_ = (pointType == POINTTYPE_DEFAULT) ? POINTTYPE_EQUISPACED : pointType;
239 
240  const ordinal_type card = this->basisCardinality_;
241 
242  // points are computed in the host and will be copied
243  Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
244  dofCoords("Hgrad::Tet::Cn::dofCoords", card, spaceDim);
245 
246  // Note: the only reason why equispaced can't support higher order than Parameters::MaxOrder appears to be the fact that the tags below get stored into a fixed-length array.
247  // TODO: relax the maximum order requirement by setting up tags in a different container, perhaps directly into an OrdinalTypeArray1DHost (tagView, below). (As of this writing (1/25/22), looks like other nodal bases do this in a similar way -- those should be fixed at the same time; maybe search for Parameters::MaxOrder.)
248  INTREPID2_TEST_FOR_EXCEPTION( order > Parameters::MaxOrder, std::invalid_argument, "polynomial order exceeds the max supported by this class");
249 
250  // Basis-dependent initializations
251  constexpr ordinal_type tagSize = 4; // size of DoF tag, i.e., number of fields in the tag
252  constexpr ordinal_type maxCard = Intrepid2::getPnCardinality<spaceDim, Parameters::MaxOrder>();
253  ordinal_type tags[maxCard][tagSize];
254 
255  // construct lattice
256 
257  const ordinal_type numEdges = this->basisCellTopology_.getEdgeCount();
258  const ordinal_type numFaces = this->basisCellTopology_.getFaceCount();
259 
260  shards::CellTopology edgeTop(shards::getCellTopologyData<shards::Line<2> >() );
261  shards::CellTopology faceTop(shards::getCellTopologyData<shards::Triangle<3> >() );
262 
263  const int numVertexes = PointTools::getLatticeSize( this->basisCellTopology_ ,
264  1 ,
265  0 );
266 
267  const int numPtsPerEdge = PointTools::getLatticeSize( edgeTop ,
268  order ,
269  1 );
270 
271  const int numPtsPerFace = PointTools::getLatticeSize( faceTop ,
272  order ,
273  1 );
274 
275  const int numPtsPerCell = PointTools::getLatticeSize( this->basisCellTopology_ ,
276  order ,
277  1 );
278 
279  Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> vertexes("Hcurl::Tet::In::vertexes", numVertexes , spaceDim );
280  Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> linePts("Hcurl::Tet::In::linePts", numPtsPerEdge , 1 );
281  Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> triPts("Hcurl::Tet::In::triPts", numPtsPerFace , 2 );
282 
283  // construct lattice
284  const ordinal_type offset = 1;
285 
286 
287  PointTools::getLattice( vertexes,
288  this->basisCellTopology_ ,
289  1, 0,
290  this->pointType_ );
291 
292  PointTools::getLattice( linePts,
293  edgeTop,
294  order, offset,
295  this->pointType_ );
296 
297  PointTools::getLattice( triPts,
298  faceTop,
299  order, offset,
300  this->pointType_ );
301 
302  // holds the image of the line points
303  Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> edgePts("Hcurl::Tet::In::edgePts", numPtsPerEdge , spaceDim );
304  Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace> facePts("Hcurl::Tet::In::facePts", numPtsPerFace , spaceDim );
305 
306  for (ordinal_type i=0;i<numVertexes;i++) {
307  auto i_card=i;
308  for(ordinal_type k=0; k<spaceDim; ++k)
309  dofCoords(i_card,k) = vertexes(i,k);
310  tags[i_card][0] = 0; // vertex dof
311  tags[i_card][1] = i; // vertex id
312  tags[i_card][2] = 0; // local dof id
313  tags[i_card][3] = 1; // total vert dof
314  }
315 
316 
317  // these are tangents scaled by the appropriate edge lengths.
318  for (ordinal_type i=0;i<numEdges;i++) { // loop over edges
320  linePts ,
321  1 ,
322  i ,
323  this->basisCellTopology_ );
324 
325 
326  // loop over points (rows of V2)
327  for (ordinal_type j=0;j<numPtsPerEdge;j++) {
328 
329  const ordinal_type i_card = numVertexes + numPtsPerEdge*i+j;
330 
331  //save dof coordinates and coefficients
332  for(ordinal_type k=0; k<spaceDim; ++k)
333  dofCoords(i_card,k) = edgePts(j,k);
334 
335  tags[i_card][0] = 1; // edge dof
336  tags[i_card][1] = i; // edge id
337  tags[i_card][2] = j; // local dof id
338  tags[i_card][3] = numPtsPerEdge; // total edge dof
339 
340  }
341  }
342 
343  if(numPtsPerFace >0) {//handle faces if needed (order >1)
344 
345  for (ordinal_type i=0;i<numFaces;i++) { // loop over faces
346 
348  triPts ,
349  2 ,
350  i ,
351  this->basisCellTopology_ );
352  for (ordinal_type j=0;j<numPtsPerFace;j++) {
353 
354  const ordinal_type i_card = numVertexes+numEdges*numPtsPerEdge+numPtsPerFace*i+j;
355 
356  //save dof coordinates
357  for(ordinal_type k=0; k<spaceDim; ++k)
358  dofCoords(i_card,k) = facePts(j,k);
359 
360  tags[i_card][0] = 2; // face dof
361  tags[i_card][1] = i; // face id
362  tags[i_card][2] = j; // local face id
363  tags[i_card][3] = numPtsPerFace; // total face dof
364  }
365  }
366  }
367 
368 
369  // internal dof, if needed
370  if (numPtsPerCell > 0) {
371  Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
372  cellPoints( "Hcurl::Tet::In::cellPoints", numPtsPerCell , spaceDim );
373  PointTools::getLattice( cellPoints ,
374  this->basisCellTopology_ ,
375  order,
376  1 ,
377  this->pointType_ );
378 
379  // copy values into right positions of V2
380  for (ordinal_type j=0;j<numPtsPerCell;j++) {
381 
382  const ordinal_type i_card = numVertexes+numEdges*numPtsPerEdge+numFaces*numPtsPerFace+j;
383 
384  //save dof coordinates
385  for(ordinal_type dim=0; dim<spaceDim; ++dim)
386  dofCoords(i_card,dim) = cellPoints(j,dim);
387 
388  tags[i_card][0] = spaceDim; // elem dof
389  tags[i_card][1] = 0; // elem id
390  tags[i_card][2] = j; // local dof id
391  tags[i_card][3] = numPtsPerCell; // total vert dof
392  }
393  }
394 
395  this->dofCoords_ = Kokkos::create_mirror_view(typename DT::memory_space(), dofCoords);
396  Kokkos::deep_copy(this->dofCoords_, dofCoords);
397 
398  // form Vandermonde matrix. Actually, this is the transpose of the VDM,
399  // so we transpose on copy below.
400  const ordinal_type lwork = card*card;
401  Kokkos::DynRankView<scalarType,Kokkos::LayoutLeft,Kokkos::HostSpace>
402  vmat("Hgrad::Tet::Cn::vmat", card, card),
403  work("Hgrad::Tet::Cn::work", lwork),
404  ipiv("Hgrad::Tet::Cn::ipiv", card);
405 
406  Impl::Basis_HGRAD_TET_Cn_FEM_ORTH::getValues<Kokkos::HostSpace::execution_space,Parameters::MaxNumPtsPerBasisEval>(typename Kokkos::HostSpace::execution_space{},
407  vmat,
408  dofCoords,
409  order,
410  OPERATOR_VALUE);
411 
412  ordinal_type info = 0;
413  Teuchos::LAPACK<ordinal_type,scalarType> lapack;
414 
415  lapack.GETRF(card, card,
416  vmat.data(), vmat.stride_1(),
417  (ordinal_type*)ipiv.data(),
418  &info);
419 
420  INTREPID2_TEST_FOR_EXCEPTION( info != 0,
421  std::runtime_error ,
422  ">>> ERROR: (Intrepid2::Basis_HGRAD_TET_Cn_FEM) lapack.GETRF returns nonzero info." );
423 
424  lapack.GETRI(card,
425  vmat.data(), vmat.stride_1(),
426  (ordinal_type*)ipiv.data(),
427  work.data(), lwork,
428  &info);
429 
430  INTREPID2_TEST_FOR_EXCEPTION( info != 0,
431  std::runtime_error ,
432  ">>> ERROR: (Intrepid2::Basis_HGRAD_TET_Cn_FEM) lapack.GETRI returns nonzero info." );
433 
434  // create host mirror
435  Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
436  vinv("Hgrad::Line::Cn::vinv", card, card);
437 
438  for (ordinal_type i=0;i<card;++i)
439  for (ordinal_type j=0;j<card;++j)
440  vinv(i,j) = vmat(j,i);
441 
442  this->vinv_ = Kokkos::create_mirror_view(typename DT::memory_space(), vinv);
443  Kokkos::deep_copy(this->vinv_ , vinv);
444 
445  // initialize tags
446  {
447  // Basis-dependent initializations
448  const ordinal_type posScDim = 0; // position in the tag, counting from 0, of the subcell dim
449  const ordinal_type posScOrd = 1; // position in the tag, counting from 0, of the subcell ordinal
450  const ordinal_type posDfOrd = 2; // position in the tag, counting from 0, of DoF ordinal relative to the subcell
451 
452  OrdinalTypeArray1DHost tagView(&tags[0][0], card*tagSize);
453 
454  // Basis-independent function sets tag and enum data in tagToOrdinal_ and ordinalToTag_ arrays:
455  // tags are constructed on host
456  this->setOrdinalTagData(this->tagToOrdinal_,
457  this->ordinalToTag_,
458  tagView,
459  this->basisCardinality_,
460  tagSize,
461  posScDim,
462  posScOrd,
463  posDfOrd);
464  }
465 }
466 } // namespace Intrepid2
467 #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...
Kokkos::View< ordinal_type *, typename ExecutionSpace::array_layout, Kokkos::HostSpace > OrdinalTypeArray1DHost
View type for 1d host array.
Header file for the Intrepid2::Basis_HGRAD_TET_Cn_FEM class.
static void mapToReferenceSubcell(refSubcellViewType refSubcellPoints, const paramPointViewType paramPoints, const ordinal_type subcellDim, const ordinal_type subcellOrd, const shards::CellTopology parentCell)
Computes parameterization maps of 1- and 2-subcells of reference cells.
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...