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