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 SpT, 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,SpT>::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 SpT, 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_FIAT;
234  this->basisCoordinates_ = COORDINATES_CARTESIAN;
235 
236  const ordinal_type card = this->basisCardinality_;
237 
238  // points are computed in the host and will be copied
239  Kokkos::DynRankView<scalarType,typename SpT::array_layout,Kokkos::HostSpace>
240  dofCoords("Hgrad::Tet::Cn::dofCoords", card, spaceDim);
241 
242  // Basis-dependent initializations
243  constexpr ordinal_type tagSize = 4; // size of DoF tag, i.e., number of fields in the tag
244  constexpr ordinal_type maxCard = Intrepid2::getPnCardinality<spaceDim, Parameters::MaxOrder>();
245  ordinal_type tags[maxCard][tagSize];
246 
247  // construct lattice
248 
249  const ordinal_type numEdges = this->basisCellTopology_.getEdgeCount();
250  const ordinal_type numFaces = this->basisCellTopology_.getFaceCount();
251 
252  shards::CellTopology edgeTop(shards::getCellTopologyData<shards::Line<2> >() );
253  shards::CellTopology faceTop(shards::getCellTopologyData<shards::Triangle<3> >() );
254 
255  const int numVertexes = PointTools::getLatticeSize( this->basisCellTopology_ ,
256  1 ,
257  0 );
258 
259  const int numPtsPerEdge = PointTools::getLatticeSize( edgeTop ,
260  order ,
261  1 );
262 
263  const int numPtsPerFace = PointTools::getLatticeSize( faceTop ,
264  order ,
265  1 );
266 
267  const int numPtsPerCell = PointTools::getLatticeSize( this->basisCellTopology_ ,
268  order ,
269  1 );
270 
271  Kokkos::DynRankView<scalarType,typename SpT::array_layout,Kokkos::HostSpace> vertexes("Hcurl::Tet::In::vertexes", numVertexes , spaceDim );
272  Kokkos::DynRankView<scalarType,typename SpT::array_layout,Kokkos::HostSpace> linePts("Hcurl::Tet::In::linePts", numPtsPerEdge , 1 );
273  Kokkos::DynRankView<scalarType,typename SpT::array_layout,Kokkos::HostSpace> triPts("Hcurl::Tet::In::triPts", numPtsPerFace , 2 );
274 
275  // construct lattice
276  const ordinal_type offset = 1;
277 
278 
279  PointTools::getLattice( vertexes,
280  this->basisCellTopology_ ,
281  1, 0,
282  pointType );
283 
284  PointTools::getLattice( linePts,
285  edgeTop,
286  order, offset,
287  pointType );
288 
289  PointTools::getLattice( triPts,
290  faceTop,
291  order, offset,
292  pointType );
293 
294  // holds the image of the line points
295  Kokkos::DynRankView<scalarType,typename SpT::array_layout,Kokkos::HostSpace> edgePts("Hcurl::Tet::In::edgePts", numPtsPerEdge , spaceDim );
296  Kokkos::DynRankView<scalarType,typename SpT::array_layout,Kokkos::HostSpace> facePts("Hcurl::Tet::In::facePts", numPtsPerFace , spaceDim );
297 
298  for (ordinal_type i=0;i<numVertexes;i++) {
299  auto i_card=i;
300  for(ordinal_type k=0; k<spaceDim; ++k)
301  dofCoords(i_card,k) = vertexes(i,k);
302  tags[i_card][0] = 0; // vertex dof
303  tags[i_card][1] = i; // vertex id
304  tags[i_card][2] = 0; // local dof id
305  tags[i_card][3] = 1; // total vert dof
306  }
307 
308 
309  // these are tangents scaled by the appropriate edge lengths.
310  for (ordinal_type i=0;i<numEdges;i++) { // loop over edges
312  linePts ,
313  1 ,
314  i ,
315  this->basisCellTopology_ );
316 
317 
318  // loop over points (rows of V2)
319  for (ordinal_type j=0;j<numPtsPerEdge;j++) {
320 
321  const ordinal_type i_card = numVertexes + numPtsPerEdge*i+j;
322 
323  //save dof coordinates and coefficients
324  for(ordinal_type k=0; k<spaceDim; ++k)
325  dofCoords(i_card,k) = edgePts(j,k);
326 
327  tags[i_card][0] = 1; // edge dof
328  tags[i_card][1] = i; // edge id
329  tags[i_card][2] = j; // local dof id
330  tags[i_card][3] = numPtsPerEdge; // total edge dof
331 
332  }
333  }
334 
335  if(numPtsPerFace >0) {//handle faces if needed (order >1)
336 
337  for (ordinal_type i=0;i<numFaces;i++) { // loop over faces
338 
340  triPts ,
341  2 ,
342  i ,
343  this->basisCellTopology_ );
344  for (ordinal_type j=0;j<numPtsPerFace;j++) {
345 
346  const ordinal_type i_card = numVertexes+numEdges*numPtsPerEdge+numPtsPerFace*i+j;
347 
348  //save dof coordinates
349  for(ordinal_type k=0; k<spaceDim; ++k)
350  dofCoords(i_card,k) = facePts(j,k);
351 
352  tags[i_card][0] = 2; // face dof
353  tags[i_card][1] = i; // face id
354  tags[i_card][2] = j; // local face id
355  tags[i_card][3] = numPtsPerFace; // total face dof
356  }
357  }
358  }
359 
360 
361  // internal dof, if needed
362  if (numPtsPerCell > 0) {
363  Kokkos::DynRankView<scalarType,typename SpT::array_layout,Kokkos::HostSpace>
364  cellPoints( "Hcurl::Tet::In::cellPoints", numPtsPerCell , spaceDim );
365  PointTools::getLattice( cellPoints ,
366  this->basisCellTopology_ ,
367  order,
368  1 ,
369  pointType );
370 
371  // copy values into right positions of V2
372  for (ordinal_type j=0;j<numPtsPerCell;j++) {
373 
374  const ordinal_type i_card = numVertexes+numEdges*numPtsPerEdge+numFaces*numPtsPerFace+j;
375 
376  //save dof coordinates
377  for(ordinal_type dim=0; dim<spaceDim; ++dim)
378  dofCoords(i_card,dim) = cellPoints(j,dim);
379 
380  tags[i_card][0] = spaceDim; // elem dof
381  tags[i_card][1] = 0; // elem id
382  tags[i_card][2] = j; // local dof id
383  tags[i_card][3] = numPtsPerCell; // total vert dof
384  }
385  }
386 
387  this->dofCoords_ = Kokkos::create_mirror_view(typename SpT::memory_space(), dofCoords);
388  Kokkos::deep_copy(this->dofCoords_, dofCoords);
389 
390  // form Vandermonde matrix. Actually, this is the transpose of the VDM,
391  // so we transpose on copy below.
392  const ordinal_type lwork = card*card;
393  Kokkos::DynRankView<scalarType,Kokkos::LayoutLeft,Kokkos::HostSpace>
394  vmat("Hgrad::Tet::Cn::vmat", card, card),
395  work("Hgrad::Tet::Cn::work", lwork),
396  ipiv("Hgrad::Tet::Cn::ipiv", card);
397 
398  Impl::Basis_HGRAD_TET_Cn_FEM_ORTH::getValues<Kokkos::HostSpace::execution_space,Parameters::MaxNumPtsPerBasisEval>(vmat, dofCoords, order, OPERATOR_VALUE);
399 
400  ordinal_type info = 0;
401  Teuchos::LAPACK<ordinal_type,scalarType> lapack;
402 
403  lapack.GETRF(card, card,
404  vmat.data(), vmat.stride_1(),
405  (ordinal_type*)ipiv.data(),
406  &info);
407 
408  INTREPID2_TEST_FOR_EXCEPTION( info != 0,
409  std::runtime_error ,
410  ">>> ERROR: (Intrepid2::Basis_HGRAD_TET_Cn_FEM) lapack.GETRF returns nonzero info." );
411 
412  lapack.GETRI(card,
413  vmat.data(), vmat.stride_1(),
414  (ordinal_type*)ipiv.data(),
415  work.data(), lwork,
416  &info);
417 
418  INTREPID2_TEST_FOR_EXCEPTION( info != 0,
419  std::runtime_error ,
420  ">>> ERROR: (Intrepid2::Basis_HGRAD_TET_Cn_FEM) lapack.GETRI returns nonzero info." );
421 
422  // create host mirror
423  Kokkos::DynRankView<scalarType,typename SpT::array_layout,Kokkos::HostSpace>
424  vinv("Hgrad::Line::Cn::vinv", card, card);
425 
426  for (ordinal_type i=0;i<card;++i)
427  for (ordinal_type j=0;j<card;++j)
428  vinv(i,j) = vmat(j,i);
429 
430  this->vinv_ = Kokkos::create_mirror_view(typename SpT::memory_space(), vinv);
431  Kokkos::deep_copy(this->vinv_ , vinv);
432 
433  // initialize tags
434  {
435  // Basis-dependent initializations
436  const ordinal_type posScDim = 0; // position in the tag, counting from 0, of the subcell dim
437  const ordinal_type posScOrd = 1; // position in the tag, counting from 0, of the subcell ordinal
438  const ordinal_type posDfOrd = 2; // position in the tag, counting from 0, of DoF ordinal relative to the subcell
439 
440  ordinal_type_array_1d_host tagView(&tags[0][0], card*tagSize);
441 
442  // Basis-independent function sets tag and enum data in tagToOrdinal_ and ordinalToTag_ arrays:
443  // tags are constructed on host
444  this->setOrdinalTagData(this->tagToOrdinal_,
445  this->ordinalToTag_,
446  tagView,
447  this->basisCardinality_,
448  tagSize,
449  posScDim,
450  posScOrd,
451  posDfOrd);
452  }
453 }
454 } // namespace Intrepid2
455 #endif
Basis_HGRAD_TET_Cn_FEM(const ordinal_type order, const EPointType pointType=POINTTYPE_EQUISPACED)
Constructor.
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...
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.
Header file for the Intrepid2::Basis_HGRAD_TET_Cn_FEM class.
Kokkos::View< ordinal_type *,typename ExecSpaceType::array_layout, Kokkos::HostSpace > ordinal_type_array_1d_host
View type for 1d host array.
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...