Intrepid2
Intrepid2_CellToolsDefJacobian.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 
43 
49 #ifndef __INTREPID2_CELLTOOLS_DEF_HPP__
50 #define __INTREPID2_CELLTOOLS_DEF_HPP__
51 
52 // disable clang warnings
53 #if defined (__clang__) && !defined (__INTEL_COMPILER)
54 #pragma clang system_header
55 #endif
56 
57 namespace Intrepid2 {
58 
59 
60  //============================================================================================//
61  // //
62  // Jacobian, inverse Jacobian and Jacobian determinant //
63  // //
64  //============================================================================================//
65 
66  namespace FunctorCellTools {
70  template<typename jacobianViewType,
71  typename worksetCellType,
72  typename basisGradType>
73  struct F_setJacobian {
74  jacobianViewType _jacobian;
75  const worksetCellType _worksetCells;
76  const basisGradType _basisGrads;
77 
78  KOKKOS_INLINE_FUNCTION
79  F_setJacobian( jacobianViewType jacobian_,
80  worksetCellType worksetCells_,
81  basisGradType basisGrads_ )
82  : _jacobian(jacobian_), _worksetCells(worksetCells_), _basisGrads(basisGrads_) {}
83 
84  KOKKOS_INLINE_FUNCTION
85  void operator()(const ordinal_type cl,
86  const ordinal_type pt) const {
87  auto jac = Kokkos::subview( _jacobian, cl, pt, Kokkos::ALL(), Kokkos::ALL());
88  const auto dofs = Kokkos::subview( _worksetCells, cl, Kokkos::ALL(), Kokkos::ALL());
89 
90  const ordinal_type gradRank = _basisGrads.rank();
91  const auto grad = ( gradRank == 3 ? Kokkos::subdynrankview( _basisGrads, Kokkos::ALL(), pt, Kokkos::ALL()) :
92  Kokkos::subdynrankview( _basisGrads, cl, Kokkos::ALL(), pt, Kokkos::ALL()));
93 
94  const ordinal_type dim = jac.extent(0); // dim0 and dim1 should match
95  const ordinal_type cardinality = grad.extent(0);
96 
97  for (ordinal_type i=0;i<dim;++i)
98  for (ordinal_type j=0;j<dim;++j) {
99  jac(i, j) = 0;
100  for (ordinal_type bf=0;bf<cardinality;++bf)
101  jac(i, j) += dofs(bf, i)*grad(bf, j);
102  }
103  }
104  };
105  }
106 
107  template<typename SpT>
108  template<typename jacobianValueType, class ...jacobianProperties,
109  typename pointValueType, class ...pointProperties,
110  typename worksetCellValueType, class ...worksetCellProperties,
111  typename HGradBasisPtrType>
112  void
114  setJacobian( Kokkos::DynRankView<jacobianValueType,jacobianProperties...> jacobian,
115  const Kokkos::DynRankView<pointValueType,pointProperties...> points,
116  const Kokkos::DynRankView<worksetCellValueType,worksetCellProperties...> worksetCell,
117  const HGradBasisPtrType basis ) {
118 #ifdef HAVE_INTREPID2_DEBUG
119  CellTools_setJacobianArgs(jacobian, points, worksetCell, basis->getBaseCellTopology());
120  //static_assert(std::is_same( pointValueType, decltype(basis->getDummyOutputValue()) ));
121 #endif
122  const auto cellTopo = basis->getBaseCellTopology();
123  const ordinal_type spaceDim = cellTopo.getDimension();
124  const ordinal_type numCells = worksetCell.extent(0);
125 
126  //points can be rank-2 (P,D), or rank-3 (C,P,D)
127  const ordinal_type pointRank = points.rank();
128  const ordinal_type numPoints = (pointRank == 2 ? points.extent(0) : points.extent(1));
129  const ordinal_type basisCardinality = basis->getCardinality();
130 
131  typedef Kokkos::DynRankView<jacobianValueType,jacobianProperties...> jacobianViewType;
132 
133  // the following does not work for RCP; its * operator returns reference not the object
134  //typedef typename decltype(*basis)::output_value_type gradValueType;
135  //typedef Kokkos::DynRankView<decltype(basis->getDummyOutputValue()),SpT> gradViewType;
136 
137  auto vcprop = Kokkos::common_view_alloc_prop(points);
138  typedef Kokkos::DynRankView<typename decltype(vcprop)::value_type,SpT> gradViewType;
139 
140  gradViewType grads;
141 
142  typedef Kokkos::DynRankView<worksetCellValueType,worksetCellProperties...> worksetCellViewType;
143  typedef typename ExecSpace<typename worksetCellViewType::execution_space,SpT>::ExecSpaceType ExecSpaceType;
144 
145  switch (pointRank) {
146  case 2: {
147  // For most FEMs
148  grads = gradViewType(Kokkos::view_alloc("CellTools::setJacobian::grads", vcprop),basisCardinality, numPoints, spaceDim);
149  basis->getValues(grads,
150  points,
151  OPERATOR_GRAD);
152  break;
153  }
154  case 3: {
155  // For CVFEM
156  grads = gradViewType(Kokkos::view_alloc("CellTools::setJacobian::grads", vcprop), numCells, basisCardinality, numPoints, spaceDim);
157  for (ordinal_type cell=0;cell<numCells;++cell)
158  basis->getValues(Kokkos::subview( grads, cell, Kokkos::ALL(), Kokkos::ALL(), Kokkos::ALL() ),
159  Kokkos::subview( points, cell, Kokkos::ALL(), Kokkos::ALL() ),
160  OPERATOR_GRAD);
161  break;
162  }
163  }
164 
165  typedef Kokkos::DynRankView<worksetCellValueType,worksetCellProperties...> worksetCellViewType;
167  typedef typename ExecSpace<typename worksetCellViewType::execution_space,SpT>::ExecSpaceType ExecSpaceType;
168 
169  using range_policy_type = Kokkos::Experimental::MDRangePolicy
170  < ExecSpaceType, Kokkos::Experimental::Rank<2>, Kokkos::IndexType<ordinal_type> >;
171  range_policy_type policy( { 0, 0 },
172  { jacobian.extent(0), jacobian.extent(1) } );
173  Kokkos::parallel_for( policy, FunctorType(jacobian, worksetCell, grads) );
174  }
175 
176  template<typename SpT>
177  template<typename jacobianInvValueType, class ...jacobianInvProperties,
178  typename jacobianValueType, class ...jacobianProperties>
179  void
181  setJacobianInv( Kokkos::DynRankView<jacobianInvValueType,jacobianInvProperties...> jacobianInv,
182  const Kokkos::DynRankView<jacobianValueType,jacobianProperties...> jacobian ) {
183 #ifdef HAVE_INTREPID2_DEBUG
184  CellTools_setJacobianInvArgs(jacobianInv, jacobian);
185 #endif
186  RealSpaceTools<SpT>::inverse(jacobianInv, jacobian);
187  }
188 
189  template<typename SpT>
190  template<typename jacobianDetValueType, class ...jacobianDetProperties,
191  typename jacobianValueType, class ...jacobianProperties>
192  void
194  setJacobianDet( Kokkos::DynRankView<jacobianDetValueType,jacobianDetProperties...> jacobianDet,
195  const Kokkos::DynRankView<jacobianValueType,jacobianProperties...> jacobian ) {
196 #ifdef HAVE_INTREPID2_DEBUG
197  CellTools_setJacobianDetArgs(jacobianDet, jacobian);
198 #endif
199  RealSpaceTools<SpT>::det(jacobianDet, jacobian);
200  }
201 
202 }
203 
204 #endif
static void setJacobianDet(Kokkos::DynRankView< jacobianDetValueType, jacobianDetProperties...> jacobianDet, const Kokkos::DynRankView< jacobianValueType, jacobianProperties...> jacobian)
Computes the determinant of the Jacobian matrix DF of the reference-to-physical frame map F...
static void setJacobianInv(Kokkos::DynRankView< jacobianInvValueType, jacobianInvProperties...> jacobianInv, const Kokkos::DynRankView< jacobianValueType, jacobianProperties...> jacobian)
Computes the inverse of the Jacobian matrix DF of the reference-to-physical frame map F...
Functor for calculation of Jacobian on cell workset see Intrepid2::CellTools for more.
static void det(Kokkos::DynRankView< detArrayValueType, detArrayProperties...> detArray, const Kokkos::DynRankView< inMatValueType, inMatProperties...> inMats)
Computes determinants of matrices stored in an array of total rank 3 (array of matrices), indexed by (i0, D, D), or 4 (array of arrays of matrices), indexed by (i0, i1, D, D).
static void inverse(Kokkos::DynRankView< inverseMatValueType, inverseMatProperties...> inverseMats, const Kokkos::DynRankView< inMatValueType, inMatProperties...> inMats)
Computes inverses of nonsingular matrices stored in an array of total rank 2 (single matrix)...
static void setJacobian(Kokkos::DynRankView< jacobianValueType, jacobianProperties...> jacobian, const Kokkos::DynRankView< pointValueType, pointProperties...> points, const Kokkos::DynRankView< worksetCellValueType, worksetCellProperties...> worksetCell, const HGradBasisPtrType basis)
Computes the Jacobian matrix DF of the reference-to-physical frame map F.