Intrepid2
Intrepid2_HVOL_LINE_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_LINE_CN_FEM_DEF_HPP__
49 #define __INTREPID2_HVOL_LINE_CN_FEM_DEF_HPP__
50 
51 namespace Intrepid2 {
52 
53  // -------------------------------------------------------------------------------------
54  namespace Impl {
55 
56  template<EOperator opType>
57  template<typename OutputViewType,
58  typename inputViewType,
59  typename workViewType,
60  typename vinvViewType>
61  KOKKOS_INLINE_FUNCTION
62  void
63  Basis_HVOL_LINE_Cn_FEM::Serial<opType>::
64  getValues( OutputViewType output,
65  const inputViewType input,
66  workViewType work,
67  const vinvViewType vinv,
68  const ordinal_type operatorDn ) {
69  ordinal_type opDn = operatorDn;
70 
71  const ordinal_type card = vinv.extent(0);
72  const ordinal_type npts = input.extent(0);
73 
74  const ordinal_type order = card - 1;
75  const double alpha = 0.0, beta = 0.0;
76 
77  typedef typename Kokkos::DynRankView<typename workViewType::value_type, typename workViewType::memory_space> viewType;
78  auto vcprop = Kokkos::common_view_alloc_prop(work);
79 
80  switch (opType) {
81  case OPERATOR_VALUE: {
82  viewType phis(Kokkos::view_wrap(work.data(), vcprop), card, npts);
83 
84  Impl::Basis_HGRAD_LINE_Cn_FEM_JACOBI::
85  Serial<opType>::getValues(phis, input, order, alpha, beta);
86 
87  for (ordinal_type i=0;i<card;++i)
88  for (ordinal_type j=0;j<npts;++j) {
89  output.access(i,j) = 0.0;
90  for (ordinal_type k=0;k<card;++k)
91  output.access(i,j) += vinv(k,i)*phis.access(k,j);
92  }
93  break;
94  }
95  case OPERATOR_GRAD:
96  case OPERATOR_D1:
97  case OPERATOR_D2:
98  case OPERATOR_D3:
99  case OPERATOR_D4:
100  case OPERATOR_D5:
101  case OPERATOR_D6:
102  case OPERATOR_D7:
103  case OPERATOR_D8:
104  case OPERATOR_D9:
105  case OPERATOR_D10:
106  opDn = getOperatorOrder(opType);
107  case OPERATOR_Dn: {
108  // dkcard is always 1 for 1D element
109  const ordinal_type dkcard = 1;
110  viewType phis(Kokkos::view_wrap(work.data(), vcprop), card, npts, dkcard);
111  Impl::Basis_HGRAD_LINE_Cn_FEM_JACOBI::
112  Serial<opType>::getValues(phis, input, order, alpha, beta, opDn);
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<dkcard;++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  default: {
124  INTREPID2_TEST_FOR_ABORT( true,
125  ">>> ERROR: (Intrepid2::Basis_HVOL_LINE_Cn_FEM::Serial::getValues) operator is not supported." );
126  }
127  }
128  }
129 
130 
131  template<typename DT, ordinal_type numPtsPerEval,
132  typename outputValueValueType, class ...outputValueProperties,
133  typename inputPointValueType, class ...inputPointProperties,
134  typename vinvValueType, class ...vinvProperties>
135  void
136  Basis_HVOL_LINE_Cn_FEM::
137  getValues( Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValues,
138  const Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPoints,
139  const Kokkos::DynRankView<vinvValueType, vinvProperties...> vinv,
140  const EOperator operatorType ) {
141  typedef Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValueViewType;
142  typedef Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPointViewType;
143  typedef Kokkos::DynRankView<vinvValueType, vinvProperties...> vinvViewType;
144  typedef typename ExecSpace<typename inputPointViewType::execution_space,typename DT::execution_space>::ExecSpaceType ExecSpaceType;
145 
146  // loopSize corresponds to cardinality
147  const auto loopSizeTmp1 = (inputPoints.extent(0)/numPtsPerEval);
148  const auto loopSizeTmp2 = (inputPoints.extent(0)%numPtsPerEval != 0);
149  const auto loopSize = loopSizeTmp1 + loopSizeTmp2;
150  Kokkos::RangePolicy<ExecSpaceType,Kokkos::Schedule<Kokkos::Static> > policy(0, loopSize);
151 
152  typedef typename inputPointViewType::value_type inputPointType;
153 
154  const ordinal_type cardinality = outputValues.extent(0);
155 
156  auto vcprop = Kokkos::common_view_alloc_prop(inputPoints);
157  typedef typename Kokkos::DynRankView< inputPointType, typename inputPointViewType::memory_space> workViewType;
158  workViewType work(Kokkos::view_alloc("Basis_HVOL_LINE_Cn_FEM::getValues::work", vcprop), cardinality, inputPoints.extent(0));
159 
160  switch (operatorType) {
161  case OPERATOR_VALUE: {
162  typedef Functor<outputValueViewType,inputPointViewType,vinvViewType,workViewType,
163  OPERATOR_VALUE,numPtsPerEval> FunctorType;
164  Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, vinv, work) );
165  break;
166  }
167  case OPERATOR_GRAD:
168  case OPERATOR_D1:
169  case OPERATOR_D2:
170  case OPERATOR_D3:
171  case OPERATOR_D4:
172  case OPERATOR_D5:
173  case OPERATOR_D6:
174  case OPERATOR_D7:
175  case OPERATOR_D8:
176  case OPERATOR_D9:
177  case OPERATOR_D10: {
178  typedef Functor<outputValueViewType,inputPointViewType,vinvViewType,workViewType,
179  OPERATOR_Dn,numPtsPerEval> FunctorType;
180  Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints, vinv, work,
181  getOperatorOrder(operatorType)) );
182  break;
183  }
184  default: {
185  INTREPID2_TEST_FOR_EXCEPTION( true , std::invalid_argument,
186  ">>> ERROR (Basis_HVOL_LINE_Cn_FEM): Operator type not implemented" );
187  //break; commented out because this always throws
188  }
189  }
190  }
191  }
192 
193  // -------------------------------------------------------------------------------------
194 
195  template<typename DT, typename OT, typename PT>
197  Basis_HVOL_LINE_Cn_FEM( const ordinal_type order,
198  const EPointType pointType ) {
199  this->pointType_ = pointType;
200  this->basisCardinality_ = order+1;
201  this->basisDegree_ = order;
202  this->basisCellTopology_ = shards::CellTopology(shards::getCellTopologyData<shards::Line<2> >() );
203  this->basisType_ = BASIS_FEM_LAGRANGIAN;
204  this->basisCoordinates_ = COORDINATES_CARTESIAN;
205  this->functionSpace_ = FUNCTION_SPACE_HVOL;
206 
207  const ordinal_type card = this->basisCardinality_;
208 
209  // points are computed in the host and will be copied
210  Kokkos::DynRankView<typename ScalarViewType::value_type,typename DT::execution_space::array_layout,Kokkos::HostSpace>
211  dofCoords("HVOL::Line::Cn::dofCoords", card, 1);
212 
213  //Default is Equispaced
214  auto pointT = (pointType == POINTTYPE_DEFAULT) ? POINTTYPE_EQUISPACED : pointType;
215 
216  switch (pointT) {
217  case POINTTYPE_EQUISPACED:
218  case POINTTYPE_WARPBLEND: {
219  // lattice ordering
220  {
221  const ordinal_type offset = 1;
222  PointTools::getLattice( dofCoords,
223  this->basisCellTopology_,
224  order+1+offset, offset,
225  pointT );
226 
227  }
228  // topological order
229  // {
230 
231  // // internal points
232  // typedef Kokkos::pair<ordinal_type,ordinal_type> range_type;
233  // auto pts = Kokkos::subview(dofCoords, range_type(2, card), Kokkos::ALL());
234 
235  // const auto offset = 1;
236  // PointTools::getLattice( pts,
237  // this->basisCellTopology_,
238  // order, offset,
239  // pointType );
240  // }
241  break;
242  }
243  case POINTTYPE_GAUSS: {
244  // internal points only
245  PointTools::getGaussPoints( dofCoords,
246  order );
247  break;
248  }
249  default: {
250  INTREPID2_TEST_FOR_EXCEPTION( !isValidPointType(pointT),
251  std::invalid_argument ,
252  ">>> ERROR: (Intrepid2::Basis_HVOL_LINE_Cn_FEM) invalid pointType." );
253  }
254  }
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  // this matrix is used in LAPACK so it should be column major and left layout
261  const ordinal_type lwork = card*card;
262  Kokkos::DynRankView<typename ScalarViewType::value_type,Kokkos::LayoutLeft,Kokkos::HostSpace>
263  vmat("HVOL::Line::Cn::vmat", card, card),
264  work("HVOL::Line::Cn::work", lwork),
265  ipiv("HVOL::Line::Cn::ipiv", card);
266 
267  const double alpha = 0.0, beta = 0.0;
268  Impl::Basis_HGRAD_LINE_Cn_FEM_JACOBI::
269  getValues<Kokkos::HostSpace::execution_space,Parameters::MaxNumPtsPerBasisEval>
270  (vmat, dofCoords, order, alpha, beta, OPERATOR_VALUE);
271 
272  ordinal_type info = 0;
273  Teuchos::LAPACK<ordinal_type,typename ScalarViewType::value_type> lapack;
274 
275  lapack.GETRF(card, card,
276  vmat.data(), vmat.stride_1(),
277  (ordinal_type*)ipiv.data(),
278  &info);
279 
280  INTREPID2_TEST_FOR_EXCEPTION( info != 0,
281  std::runtime_error ,
282  ">>> ERROR: (Intrepid2::Basis_HVOL_LINE_Cn_FEM) lapack.GETRF returns nonzero info." );
283 
284  lapack.GETRI(card,
285  vmat.data(), vmat.stride_1(),
286  (ordinal_type*)ipiv.data(),
287  work.data(), lwork,
288  &info);
289 
290  INTREPID2_TEST_FOR_EXCEPTION( info != 0,
291  std::runtime_error ,
292  ">>> ERROR: (Intrepid2::Basis_HVOL_LINE_Cn_FEM) lapack.GETRI returns nonzero info." );
293 
294  // create host mirror
295  Kokkos::DynRankView<typename ScalarViewType::value_type,typename DT::execution_space::array_layout,Kokkos::HostSpace>
296  vinv("HVOL::Line::Cn::vinv", card, card);
297 
298  for (ordinal_type i=0;i<card;++i)
299  for (ordinal_type j=0;j<card;++j)
300  vinv(i,j) = vmat(j,i);
301 
302  this->vinv_ = Kokkos::create_mirror_view(typename DT::memory_space(), vinv);
303  Kokkos::deep_copy(this->vinv_ , vinv);
304 
305  // initialize tags
306  {
307  // Basis-dependent initializations
308  const ordinal_type tagSize = 4; // size of DoF tag, i.e., number of fields in the tag
309  const ordinal_type posScDim = 0; // position in the tag, counting from 0, of the subcell dim
310  const ordinal_type posScOrd = 1; // position in the tag, counting from 0, of the subcell ordinal
311  const ordinal_type posDfOrd = 2; // position in the tag, counting from 0, of DoF ordinal relative to the subcell
312 
313 
314  ordinal_type tags[Parameters::MaxOrder+1][4];
315 
316  for (ordinal_type i=0;i<card;++i) {
317  tags[i][0] = 1; // edge dof
318  tags[i][1] = 0; // edge id
319  tags[i][2] = i; // local dof id
320  tags[i][3] = card; // total number of dofs in this edge
321  }
322 
323  OrdinalTypeArray1DHost tagView(&tags[0][0], card*4);
324 
325  // Basis-independent function sets tag and enum data in tagToOrdinal_ and ordinalToTag_ arrays:
326  // tags are constructed on host
327  this->setOrdinalTagData(this->tagToOrdinal_,
328  this->ordinalToTag_,
329  tagView,
330  this->basisCardinality_,
331  tagSize,
332  posScDim,
333  posScOrd,
334  posDfOrd);
335  }
336  }
337 
338 }// namespace Intrepid2
339 
340 #endif
341 
342 
343 
344 
345 
346 
347 
348 
349 
350 
351 
352 
353 
354 
355 
KOKKOS_FORCEINLINE_FUNCTION bool isValidPointType(const EPointType pointType)
Verifies validity of a point type enum.
static void getGaussPoints(Kokkos::DynRankView< pointValueType, pointProperties... > points, const ordinal_type order)
EPointType
Enumeration of types of point distributions in Intrepid.
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_INLINE_FUNCTION ordinal_type getOperatorOrder(const EOperator operatorType)
Returns order of an operator.
Basis_HVOL_LINE_Cn_FEM(const ordinal_type order, const EPointType pointType=POINTTYPE_EQUISPACED)
Constructor.
static constexpr ordinal_type MaxOrder
The maximum reconstruction order.