Intrepid2
Intrepid2_HVOL_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
48#ifndef __INTREPID2_HVOL_TET_CN_FEM_DEF_HPP__
49#define __INTREPID2_HVOL_TET_CN_FEM_DEF_HPP__
50
52
53namespace Intrepid2 {
54
55 // -------------------------------------------------------------------------------------
56
57 namespace Impl {
58
59 template<EOperator opType>
60 template<typename OutputViewType,
61 typename inputViewType,
62 typename workViewType,
63 typename vinvViewType>
64 KOKKOS_INLINE_FUNCTION
65 void
66 Basis_HVOL_TET_Cn_FEM::Serial<opType>::
67 getValues( OutputViewType output,
68 const inputViewType input,
69 workViewType work,
70 const vinvViewType vinv ) {
71
72 constexpr ordinal_type spaceDim = 3;
73 const ordinal_type
74 card = vinv.extent(0),
75 npts = input.extent(0);
76
77 // compute order
78 ordinal_type order = 0;
79 for (ordinal_type p=0;p<=Parameters::MaxOrder;++p) {
80 if (card == Intrepid2::getPnCardinality<spaceDim>(p)) {
81 order = p;
82 break;
83 }
84 }
85
86 typedef typename Kokkos::DynRankView<typename workViewType::value_type, typename workViewType::memory_space> viewType;
87 auto vcprop = Kokkos::common_view_alloc_prop(work);
88 auto ptr = work.data();
89
90 switch (opType) {
91 case OPERATOR_VALUE: {
92 const viewType phis(Kokkos::view_wrap(ptr, vcprop), card, npts);
93 workViewType dummyView;
94
95 Impl::Basis_HGRAD_TET_Cn_FEM_ORTH::
96 Serial<opType>::getValues(phis, input, dummyView, order);
97
98 for (ordinal_type i=0;i<card;++i)
99 for (ordinal_type j=0;j<npts;++j) {
100 output.access(i,j) = 0.0;
101 for (ordinal_type k=0;k<card;++k)
102 output.access(i,j) += vinv(k,i)*phis.access(k,j);
103 }
104 break;
105 }
106 case OPERATOR_GRAD:
107 case OPERATOR_D1: {
108 const viewType phis(Kokkos::view_wrap(ptr, vcprop), card, npts, spaceDim);
109 ptr += card*npts*spaceDim*get_dimension_scalar(work);
110 const viewType workView(Kokkos::view_wrap(ptr, vcprop), card, npts, spaceDim+1);
111 Impl::Basis_HGRAD_TET_Cn_FEM_ORTH::
112 Serial<opType>::getValues(phis, input, workView, order);
113
114 for (ordinal_type i=0;i<card;++i)
115 for (ordinal_type j=0;j<npts;++j)
116 for (ordinal_type k=0;k<spaceDim;++k) {
117 output.access(i,j,k) = 0.0;
118 for (ordinal_type l=0;l<card;++l)
119 output.access(i,j,k) += vinv(l,i)*phis.access(l,j,k);
120 }
121 break;
122 }
123 case OPERATOR_D2:
124 case OPERATOR_D3:
125 case OPERATOR_D4:
126 case OPERATOR_D5:
127 case OPERATOR_D6:
128 case OPERATOR_D7:
129 case OPERATOR_D8:
130 case OPERATOR_D9:
131 case OPERATOR_D10: {
132 const ordinal_type dkcard = getDkCardinality<opType,spaceDim>(); //(orDn + 1);
133 const viewType phis(Kokkos::view_wrap(ptr, vcprop), card, npts, dkcard);
134 workViewType dummyView;
135
136 Impl::Basis_HGRAD_TET_Cn_FEM_ORTH::
137 Serial<opType>::getValues(phis, input, dummyView, order);
138
139 for (ordinal_type i=0;i<card;++i)
140 for (ordinal_type j=0;j<npts;++j)
141 for (ordinal_type k=0;k<dkcard;++k) {
142 output.access(i,j,k) = 0.0;
143 for (ordinal_type l=0;l<card;++l)
144 output.access(i,j,k) += vinv(l,i)*phis.access(l,j,k);
145 }
146 break;
147 }
148 default: {
149 INTREPID2_TEST_FOR_ABORT( true,
150 ">>> ERROR (Basis_HVOL_TET_Cn_FEM): Operator type not implemented");
151 }
152 }
153 }
154
155 template<typename DT, ordinal_type numPtsPerEval,
156 typename outputValueValueType, class ...outputValueProperties,
157 typename inputPointValueType, class ...inputPointProperties,
158 typename vinvValueType, class ...vinvProperties>
159 void
160 Basis_HVOL_TET_Cn_FEM::
161 getValues( Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValues,
162 const Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPoints,
163 const Kokkos::DynRankView<vinvValueType, vinvProperties...> vinv,
164 const EOperator operatorType) {
165 typedef Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValueViewType;
166 typedef Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPointViewType;
167 typedef Kokkos::DynRankView<vinvValueType, vinvProperties...> vinvViewType;
168 typedef typename ExecSpace<typename inputPointViewType::execution_space,typename DT::execution_space>::ExecSpaceType ExecSpaceType;
169
170 // loopSize corresponds to cardinality
171 const auto loopSizeTmp1 = (inputPoints.extent(0)/numPtsPerEval);
172 const auto loopSizeTmp2 = (inputPoints.extent(0)%numPtsPerEval != 0);
173 const auto loopSize = loopSizeTmp1 + loopSizeTmp2;
174 Kokkos::RangePolicy<ExecSpaceType,Kokkos::Schedule<Kokkos::Static> > policy(0, loopSize);
175
176 typedef typename inputPointViewType::value_type inputPointType;
177
178 const ordinal_type cardinality = outputValues.extent(0);
179 const ordinal_type spaceDim = 3;
180
181 ordinal_type order = 0;
182 while((Intrepid2::getPnCardinality<spaceDim>(++order) != cardinality) && (order != Parameters::MaxOrder));
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 auto bufferSize = Basis_HVOL_TET_Cn_FEM::Serial<OPERATOR_VALUE>::getWorkSizePerPoint(order);
190 workViewType work(Kokkos::view_alloc("Basis_HVOL_TET_Cn_FEM::getValues::work", vcprop), bufferSize, inputPoints.extent(0));
191 typedef Functor<outputValueViewType,inputPointViewType,vinvViewType, workViewType,
192 OPERATOR_VALUE,numPtsPerEval> FunctorType;
193 Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, vinv, work) );
194 break;
195 }
196 case OPERATOR_GRAD:
197 case OPERATOR_D1: {
198 auto bufferSize = Basis_HVOL_TET_Cn_FEM::Serial<OPERATOR_D1>::getWorkSizePerPoint(order);
199 workViewType work(Kokkos::view_alloc("Basis_HVOL_TET_Cn_FEM::getValues::work", vcprop), bufferSize, inputPoints.extent(0));
200 typedef Functor<outputValueViewType,inputPointViewType,vinvViewType, workViewType,
201 OPERATOR_D1,numPtsPerEval> FunctorType;
202 Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, vinv, work) );
203 break;
204 }
205 case OPERATOR_D2: {
206 auto bufferSize = Basis_HVOL_TET_Cn_FEM::Serial<OPERATOR_D2>::getWorkSizePerPoint(order);
207 typedef Functor<outputValueViewType,inputPointViewType,vinvViewType, workViewType,
208 OPERATOR_D2,numPtsPerEval> FunctorType;
209 workViewType work(Kokkos::view_alloc("Basis_HVOL_TET_Cn_FEM::getValues::work", vcprop), bufferSize, inputPoints.extent(0));
210 Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, vinv, work) );
211 break;
212 }
213 /* case OPERATOR_D3: {
214 typedef Functor<outputValueViewType,inputPointViewType,vinvViewType, workViewType
215 OPERATOR_D3,numPtsPerEval> FunctorType;
216 workViewType work(Kokkos::view_alloc("Basis_HVOL_TET_Cn_FEM::getValues::work", vcprop), cardinality, inputPoints.extent(0), outputValues.extent(2));
217 Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, vinv, work) );
218 break;
219 }*/
220 default: {
221 INTREPID2_TEST_FOR_EXCEPTION( true , std::invalid_argument,
222 ">>> ERROR (Basis_HVOL_TET_Cn_FEM): Operator type not implemented" );
223 }
224 }
225 }
226 }
227
228 // -------------------------------------------------------------------------------------
229 template<typename DT, typename OT, typename PT>
231 Basis_HVOL_TET_Cn_FEM( const ordinal_type order,
232 const EPointType pointType ) {
233 constexpr ordinal_type spaceDim = 3;
234
235 this->pointType_ = pointType;
236 this->basisCardinality_ = Intrepid2::getPnCardinality<spaceDim>(order); // bigN
237 this->basisDegree_ = order; // small n
238 this->basisCellTopology_ = shards::CellTopology(shards::getCellTopologyData<shards::Tetrahedron<4> >() );
239 this->basisType_ = BASIS_FEM_LAGRANGIAN;
240 this->basisCoordinates_ = COORDINATES_CARTESIAN;
241 this->functionSpace_ = FUNCTION_SPACE_HVOL;
242
243 const ordinal_type card = this->basisCardinality_;
244
245 // points are computed in the host and will be copied
246 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
247 dofCoords("HVOL::Tet::Cn::dofCoords", card, spaceDim);
248
249 // construct lattice (only internal nodes for HVOL element)
250 const ordinal_type offset = 1;
251 PointTools::getLattice( dofCoords,
252 this->basisCellTopology_,
253 order+spaceDim+offset, offset,
254 pointType );
255
256 this->dofCoords_ = Kokkos::create_mirror_view(typename DT::memory_space(), dofCoords);
257 Kokkos::deep_copy(this->dofCoords_, dofCoords);
258
259 // form Vandermonde matrix. Actually, this is the transpose of the VDM,
260 // so we transpose on copy below.
261 const ordinal_type lwork = card*card;
262 Kokkos::DynRankView<scalarType,Kokkos::LayoutLeft,Kokkos::HostSpace>
263 vmat("HVOL::Tet::Cn::vmat", card, card),
264 work("HVOL::Tet::Cn::work", lwork),
265 ipiv("HVOL::Tet::Cn::ipiv", card);
266
267 Impl::Basis_HGRAD_TET_Cn_FEM_ORTH::getValues<Kokkos::HostSpace::execution_space,Parameters::MaxNumPtsPerBasisEval>(vmat, dofCoords, order, OPERATOR_VALUE);
268
269 ordinal_type info = 0;
270 Teuchos::LAPACK<ordinal_type,scalarType> lapack;
271
272 lapack.GETRF(card, card,
273 vmat.data(), vmat.stride_1(),
274 (ordinal_type*)ipiv.data(),
275 &info);
276
277 INTREPID2_TEST_FOR_EXCEPTION( info != 0,
278 std::runtime_error ,
279 ">>> ERROR: (Intrepid2::Basis_HVOL_TET_Cn_FEM) lapack.GETRF returns nonzero info." );
280
281 lapack.GETRI(card,
282 vmat.data(), vmat.stride_1(),
283 (ordinal_type*)ipiv.data(),
284 work.data(), lwork,
285 &info);
286
287 INTREPID2_TEST_FOR_EXCEPTION( info != 0,
288 std::runtime_error ,
289 ">>> ERROR: (Intrepid2::Basis_HVOL_TET_Cn_FEM) lapack.GETRI returns nonzero info." );
290
291 // create host mirror
292 Kokkos::DynRankView<scalarType,typename DT::execution_space::array_layout,Kokkos::HostSpace>
293 vinv("HVOL::Line::Cn::vinv", card, card);
294
295 for (ordinal_type i=0;i<card;++i)
296 for (ordinal_type j=0;j<card;++j)
297 vinv(i,j) = vmat(j,i);
298
299 this->vinv_ = Kokkos::create_mirror_view(typename DT::memory_space(), vinv);
300 Kokkos::deep_copy(this->vinv_ , vinv);
301
302 // initialize tags
303 {
304 // Basis-dependent initializations
305 constexpr ordinal_type tagSize = 4; // size of DoF tag, i.e., number of fields in the tag
306 const ordinal_type posScDim = 0; // position in the tag, counting from 0, of the subcell dim
307 const ordinal_type posScOrd = 1; // position in the tag, counting from 0, of the subcell ordinal
308 const ordinal_type posDfOrd = 2; // position in the tag, counting from 0, of DoF ordinal relative to the subcell
309
310 constexpr ordinal_type maxCard = Intrepid2::getPnCardinality<spaceDim, Parameters::MaxOrder>();
311 ordinal_type tags[maxCard][tagSize];
312
313 const ordinal_type
314 numElemDof = this->basisCardinality_; //all the degrees of freedom are internal.
315
316
317 ordinal_type elemId = 0;
318 for (ordinal_type i=0;i<this->basisCardinality_;++i) {
319 // elem
320 tags[i][0] = spaceDim; // intr dof
321 tags[i][1] = 0; // intr id
322 tags[i][2] = elemId++; // local dof id
323 tags[i][3] = numElemDof; // total vert dof
324 }
325
326 OrdinalTypeArray1DHost tagView(&tags[0][0], card*tagSize);
327
328 // Basis-independent function sets tag and enum data in tagToOrdinal_ and ordinalToTag_ arrays:
329 // tags are constructed on host
330 this->setOrdinalTagData(this->tagToOrdinal_,
331 this->ordinalToTag_,
332 tagView,
333 this->basisCardinality_,
334 tagSize,
335 posScDim,
336 posScOrd,
337 posDfOrd);
338 }
339 }
340} // namespace Intrepid2
341#endif
Header file for the Intrepid2::Basis_HGRAD_TET_Cn_FEM_ORTH class.
Basis_HVOL_TET_Cn_FEM(const ordinal_type order, const EPointType pointType=POINTTYPE_EQUISPACED)
Constructor.
static constexpr ordinal_type MaxOrder
The maximum reconstruction order.
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...