Intrepid2
Intrepid2_HDIV_TRI_I1_FEMDef.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Intrepid2 Package
4 //
5 // Copyright 2007 NTESS and the Intrepid2 contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
15 #ifndef __INTREPID2_HDIV_TRI_I1_FEM_DEF_HPP__
16 #define __INTREPID2_HDIV_TRI_I1_FEM_DEF_HPP__
17 
18 namespace Intrepid2 {
19 
20  // -------------------------------------------------------------------------------------
21  namespace Impl {
22 
23  template<EOperator opType>
24  template<typename OutputViewType,
25  typename inputViewType>
26  KOKKOS_INLINE_FUNCTION
27  void
28  Basis_HDIV_TRI_I1_FEM::Serial<opType>::
29  getValues( OutputViewType output,
30  const inputViewType input ) {
31  switch (opType) {
32  case OPERATOR_VALUE: {
33  const auto x = input(0);
34  const auto y = input(1);
35 
36  // output is a rank-2 array with dimensions (basisCardinality_)
37  output.access(0, 0) = 2.0*x;
38  output.access(0, 1) = 2.0*(y - 1.0);
39 
40  output.access(1, 0) = 2.0*x;
41  output.access(1, 1) = 2.0*y;
42 
43  output.access(2, 0) = 2.0*(x - 1.0);
44  output.access(2, 1) = 2.0*y;
45  break;
46  }
47  case OPERATOR_DIV: {
48  // output is a rank-3 array with dimensions (basisCardinality_, spaceDim)
49  output.access(0) = 4.0;
50  output.access(1) = 4.0;
51  output.access(2) = 4.0;
52  break;
53  }
54  default: {
55  INTREPID2_TEST_FOR_ABORT( opType != OPERATOR_VALUE &&
56  opType != OPERATOR_DIV,
57  ">>> ERROR: (Intrepid2::Basis_HDIV_TRI_I1_FEM::Serial::getValues) operator is not supported");
58  }
59  }
60  }
61 
62 
63  template<typename DT,
64  typename outputValueValueType, class ...outputValueProperties,
65  typename inputPointValueType, class ...inputPointProperties>
66  void
67  Basis_HDIV_TRI_I1_FEM::
68  getValues( Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValues,
69  const Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPoints,
70  const EOperator operatorType ) {
71  typedef Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValueViewType;
72  typedef Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPointViewType;
73  typedef typename ExecSpace<typename inputPointViewType::execution_space,typename DT::execution_space>::ExecSpaceType ExecSpaceType;
74 
75 
76  // Number of evaluation points = dim 0 of inputPoints
77  const auto loopSize = inputPoints.extent(0);
78  Kokkos::RangePolicy<ExecSpaceType,Kokkos::Schedule<Kokkos::Static> > policy(0, loopSize);
79 
80  switch (operatorType) {
81  case OPERATOR_VALUE: {
82  typedef Functor<outputValueViewType,inputPointViewType,OPERATOR_VALUE> FunctorType;
83  Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints) );
84  break;
85  }
86  case OPERATOR_DIV: {
87  typedef Functor<outputValueViewType,inputPointViewType,OPERATOR_DIV> FunctorType;
88  Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints) );
89  break;
90  }
91  case OPERATOR_CURL: {
92  INTREPID2_TEST_FOR_EXCEPTION( (operatorType == OPERATOR_CURL), std::invalid_argument,
93  ">>> ERROR (Basis_HDIV_TRI_I1_FEM): CURL is invalid operator for HDIV Basis Functions");
94  break;
95  }
96 
97  case OPERATOR_GRAD: {
98  INTREPID2_TEST_FOR_EXCEPTION( (operatorType == OPERATOR_GRAD), std::invalid_argument,
99  ">>> ERROR (Basis_HDIV_TRI_I1_FEM): GRAD is invalid operator for HDIV Basis Functions");
100  break;
101  }
102  case OPERATOR_D1:
103  case OPERATOR_D2:
104  case OPERATOR_D3:
105  case OPERATOR_D4:
106  case OPERATOR_D5:
107  case OPERATOR_D6:
108  case OPERATOR_D7:
109  case OPERATOR_D8:
110  case OPERATOR_D9:
111  case OPERATOR_D10: {
112  INTREPID2_TEST_FOR_EXCEPTION( ( (operatorType == OPERATOR_D1) &&
113  (operatorType == OPERATOR_D2) &&
114  (operatorType == OPERATOR_D3) &&
115  (operatorType == OPERATOR_D4) &&
116  (operatorType == OPERATOR_D5) &&
117  (operatorType == OPERATOR_D6) &&
118  (operatorType == OPERATOR_D7) &&
119  (operatorType == OPERATOR_D8) &&
120  (operatorType == OPERATOR_D9) &&
121  (operatorType == OPERATOR_D10) ),
122  std::invalid_argument,
123  ">>> ERROR (Basis_HDIV_TRI_I1_FEM): Invalid operator type");
124  break;
125  }
126  default: {
127  INTREPID2_TEST_FOR_EXCEPTION( ( (operatorType != OPERATOR_VALUE) &&
128  (operatorType != OPERATOR_GRAD) &&
129  (operatorType != OPERATOR_CURL) &&
130  (operatorType != OPERATOR_DIV) &&
131  (operatorType != OPERATOR_D1) &&
132  (operatorType != OPERATOR_D2) &&
133  (operatorType != OPERATOR_D3) &&
134  (operatorType != OPERATOR_D4) &&
135  (operatorType != OPERATOR_D5) &&
136  (operatorType != OPERATOR_D6) &&
137  (operatorType != OPERATOR_D7) &&
138  (operatorType != OPERATOR_D8) &&
139  (operatorType != OPERATOR_D9) &&
140  (operatorType != OPERATOR_D10) ),
141  std::invalid_argument,
142  ">>> ERROR (Basis_HDIV_TRI_I1_FEM): Invalid operator type");
143  }
144  }
145  }
146  }
147  // -------------------------------------------------------------------------------------
148 
149  template<typename DT, typename OT, typename PT>
152  this->basisCardinality_ = 3;
153  this->basisDegree_ = 1;
154  constexpr ordinal_type spaceDim = 2;
155  this->basisCellTopologyKey_ = shards::Triangle<3>::key;
156  this->basisType_ = BASIS_FEM_DEFAULT;
157  this->basisCoordinates_ = COORDINATES_CARTESIAN;
158  this->functionSpace_ = FUNCTION_SPACE_HDIV;
159 
160  // initialize tags
161  {
162  // Basis-dependent initializations
163  const ordinal_type tagSize = 4; // size of DoF tag, i.e., number of fields in the tag
164  const ordinal_type posScDim = 0; // position in the tag, counting from 0, of the subcell dim
165  const ordinal_type posScOrd = 1; // position in the tag, counting from 0, of the subcell ordinal
166  const ordinal_type posDfOrd = 2; // position in the tag, counting from 0, of DoF ordinal relative to the subcell
167 
168  // An array with local DoF tags assigned to the basis functions, in the order of their local enumeration
169  ordinal_type tags[12] = { 1, 0, 0, 1,
170  1, 1, 0, 1,
171  1, 2, 0, 1 };
172 
173  // host tags
174  OrdinalTypeArray1DHost tagView(&tags[0], 12);
175 
176  // Basis-independent function sets tag and enum data in tagToOrdinal_ and ordinalToTag_ arrays:
177  //OrdinalTypeArray2DHost ordinalToTag;
178  //OrdinalTypeArray3DHost tagToOrdinal;
179  this->setOrdinalTagData(this->tagToOrdinal_,
180  this->ordinalToTag_,
181  tagView,
182  this->basisCardinality_,
183  tagSize,
184  posScDim,
185  posScOrd,
186  posDfOrd);
187 
188  //this->tagToOrdinal_ = Kokkos::create_mirror_view(typename DT::memory_space(), tagToOrdinal);
189  //Kokkos::deep_copy(this->tagToOrdinal_, tagToOrdinal);
190 
191  //this->ordinalToTag_ = Kokkos::create_mirror_view(typename DT::memory_space(), ordinalToTag);
192  //Kokkos::deep_copy(this->ordinalToTag_, ordinalToTag);
193  }
194 
195  // dofCoords on host and create its mirror view to device
196  Kokkos::DynRankView<typename ScalarViewType::value_type,typename DT::execution_space::array_layout,Kokkos::HostSpace>
197  dofCoords("dofCoordsHost", this->basisCardinality_,spaceDim);
198 
199  dofCoords(0,0) = 0.5; dofCoords(0,1) = 0.0;
200  dofCoords(1,0) = 0.5; dofCoords(1,1) = 0.5;
201  dofCoords(2,0) = 0.0; dofCoords(2,1) = 0.5;
202 
203  this->dofCoords_ = Kokkos::create_mirror_view(typename DT::memory_space(), dofCoords);
204  Kokkos::deep_copy(this->dofCoords_, dofCoords);
205 
206  // dofCoords on host and create its mirror view to device
207  Kokkos::DynRankView<typename ScalarViewType::value_type,typename DT::execution_space::array_layout,Kokkos::HostSpace>
208  dofCoeffs("dofCoeffsHost", this->basisCardinality_,spaceDim);
209 
210  // dofCoeffs are normals to edges, having magnitude equal to edges' measures
211  dofCoeffs(0,0) = 0.0; dofCoeffs(0,1) = -0.5;
212  dofCoeffs(1,0) = 0.5; dofCoeffs(1,1) = 0.5;
213  dofCoeffs(2,0) = -0.5; dofCoeffs(2,1) = 0.0;
214 
215  this->dofCoeffs_ = Kokkos::create_mirror_view(typename DT::memory_space(), dofCoeffs); Kokkos::deep_copy(this->dofCoeffs_, dofCoeffs);
216 
217  }
218 
219  template<typename DT, typename OT, typename PT>
220  void
222  ordinal_type& perTeamSpaceSize,
223  ordinal_type& perThreadSpaceSize,
224  const PointViewType inputPoints,
225  const EOperator operatorType) const {
226  perTeamSpaceSize = 0;
227  perThreadSpaceSize = 0;
228  }
229 
230  template<typename DT, typename OT, typename PT>
231  KOKKOS_INLINE_FUNCTION
232  void
234  OutputViewType outputValues,
235  const PointViewType inputPoints,
236  const EOperator operatorType,
237  const typename Kokkos::TeamPolicy<typename DT::execution_space>::member_type& team_member,
238  const typename DT::execution_space::scratch_memory_space & scratchStorage,
239  const ordinal_type subcellDim,
240  const ordinal_type subcellOrdinal) const {
241 
242  INTREPID2_TEST_FOR_ABORT( !((subcellDim == -1) && (subcellOrdinal == -1)),
243  ">>> ERROR: (Intrepid2::Basis_HDIV_TRI_I1_FEM::getValues), The capability of selecting subsets of basis functions has not been implemented yet.");
244 
245  (void) scratchStorage; //avoid unused variable warning
246 
247  const int numPoints = inputPoints.extent(0);
248 
249  switch(operatorType) {
250  case OPERATOR_VALUE:
251  Kokkos::parallel_for (Kokkos::TeamThreadRange (team_member, numPoints), [=] (ordinal_type& pt) {
252  auto output = Kokkos::subview( outputValues, Kokkos::ALL(), pt, Kokkos::ALL() );
253  const auto input = Kokkos::subview( inputPoints, pt, Kokkos::ALL() );
255  });
256  break;
257  case OPERATOR_DIV:
258  Kokkos::parallel_for (Kokkos::TeamThreadRange (team_member, numPoints), [=] (ordinal_type& pt) {
259  auto output = Kokkos::subview( outputValues, Kokkos::ALL(), pt, Kokkos::ALL() );
260  const auto input = Kokkos::subview( inputPoints, pt, Kokkos::ALL() );
261  Impl::Basis_HDIV_TRI_I1_FEM::Serial<OPERATOR_DIV>::getValues( output, input);
262  });
263  break;
264  default: {
265  INTREPID2_TEST_FOR_ABORT( true, ">>> ERROR: (Intrepid2::Basis_HDIV_TRI_!1_FEM::getValues), Operator Type not supported.");
266  }
267  }
268  }
269 
270 }// namespace Intrepid2
271 #endif
Kokkos::View< ordinal_type *, typename ExecutionSpace::array_layout, Kokkos::HostSpace > OrdinalTypeArray1DHost
View type for 1d host array.
Kokkos::DynRankView< PointValueType, Kokkos::LayoutStride, DeviceType > PointViewType
View type for input points.
virtual void getScratchSpaceSize(ordinal_type &perTeamSpaceSize, ordinal_type &perThreadSpaceSize, const PointViewType inputPointsconst, const EOperator operatorType=OPERATOR_VALUE) const override
Return the size of the scratch space, in bytes, needed for using the team-level implementation of get...
virtual void getValues(OutputViewType outputValues, const PointViewType inputPoints, const EOperator operatorType=OPERATOR_VALUE) const override