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