Intrepid2
Intrepid2_HCURL_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 
16 #ifndef __INTREPID2_HCURL_TRI_I1_FEM_DEF_HPP__
17 #define __INTREPID2_HCURL_TRI_I1_FEM_DEF_HPP__
18 
19 namespace Intrepid2 {
20 
21  // -------------------------------------------------------------------------------------
22  namespace Impl {
23 
24  template<EOperator opType>
25  template<typename OutputViewType,
26  typename inputViewType>
27  KOKKOS_INLINE_FUNCTION
28  void
29  Basis_HCURL_TRI_I1_FEM::Serial<opType>::
30  getValues( OutputViewType output,
31  const inputViewType input ) {
32  switch (opType) {
33  case OPERATOR_VALUE: {
34  const auto x = input(0);
35  const auto y = input(1);
36 
37  // output is a subview of a rank-3 array with dimensions (basisCardinality_, dim0, spaceDim), dim0 iteration of range
38  output.access(0, 0) = 2.0*(1.0 - y);
39  output.access(0, 1) = 2.0*x;
40 
41  output.access(1, 0) = -2.0*y;
42  output.access(1, 1) = 2.0*x;
43 
44  output.access(2, 0) = -2.0*y;
45  output.access(2, 1) = 2.0*(-1.0 + x);
46  break;
47  }
48  case OPERATOR_CURL: {
49  // outputValues is a subview of a rank-2 array with dimensions (basisCardinality_, dim0), dim0 iteration of range
50  output.access(0) = 4.0;
51  output.access(1) = 4.0;
52  output.access(2) = 4.0;
53 
54  break;
55  }
56  default: {
57  INTREPID2_TEST_FOR_ABORT( opType != OPERATOR_VALUE &&
58  opType != OPERATOR_CURL,
59  ">>> ERROR: (Intrepid2::Basis_HCURL_TRI_I1_FEM::Serial::getValues) operator is not supported");
60  }
61  }
62  }
63 
64  template< typename DT,
65  typename outputValueValueType, class ...outputValueProperties,
66  typename inputPointValueType, class ...inputPointProperties>
67  void
68  Basis_HCURL_TRI_I1_FEM::
69  getValues( const typename DT::execution_space& space,
70  Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValues,
71  const Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPoints,
72  const EOperator operatorType ) {
73  typedef Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValueViewType;
74  typedef Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPointViewType;
75  typedef typename ExecSpace<typename inputPointViewType::execution_space,typename DT::execution_space>::ExecSpaceType ExecSpaceType;
76 
77  // Number of evaluation points = dim 0 of inputPoints
78  const auto loopSize = inputPoints.extent(0);
79  Kokkos::RangePolicy<ExecSpaceType,Kokkos::Schedule<Kokkos::Static> > policy(space, 0, loopSize);
80 
81  switch (operatorType) {
82  case OPERATOR_VALUE: {
83  typedef Functor<outputValueViewType,inputPointViewType,OPERATOR_VALUE> FunctorType;
84  Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints) );
85  break;
86  }
87  case OPERATOR_CURL: {
88  typedef Functor<outputValueViewType,inputPointViewType,OPERATOR_CURL> FunctorType;
89  Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints) );
90  break;
91  }
92  case OPERATOR_DIV: {
93  INTREPID2_TEST_FOR_EXCEPTION( (operatorType == OPERATOR_DIV), std::invalid_argument,
94  ">>> ERROR (Basis_HCURL_TRI_I1_FEM): DIV is invalid operator for HCURL Basis Functions");
95  break;
96  }
97  case OPERATOR_GRAD: {
98  INTREPID2_TEST_FOR_EXCEPTION( (operatorType == OPERATOR_GRAD), std::invalid_argument,
99  ">>> ERROR (Basis_HCURL_TRI_I1_FEM): GRAD is invalid operator for HCURL 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_HCURL_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_HCURL_TRI_I1_FEM): Invalid operator type");
143  }
144  }
145  }
146  }
147 
148  template< typename DT, typename OT, typename PT >
151  const ordinal_type spaceDim = 2;
152  this->basisCardinality_ = 3;
153  this->basisDegree_ = 1;
154  this->basisCellTopologyKey_ = shards::Triangle<3>::key;
155  this->basisType_ = BASIS_FEM_DEFAULT;
156  this->basisCoordinates_ = COORDINATES_CARTESIAN;
157  this->functionSpace_ = FUNCTION_SPACE_HCURL;
158 
159  // initialize tags
160  {
161  // Basis-dependent intializations
162  const ordinal_type tagSize = 4; // size of DoF tag
163  const ordinal_type posScDim = 0; // position in the tag, counting from 0, of the subcell dim
164  const ordinal_type posScOrd = 1; // position in the tag, counting from 0, of the subcell ordinal
165  const ordinal_type posDfOrd = 2; // position in the tag, counting from 0, of DoF ordinal relative to the subcell
166 
167  // An array with local DoF tags assigned to basis functions, in the order of their local enumeration
168  ordinal_type tags[12] = {
169  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  this->setOrdinalTagData(this->tagToOrdinal_,
178  this->ordinalToTag_,
179  tagView,
180  this->basisCardinality_,
181  tagSize,
182  posScDim,
183  posScOrd,
184  posDfOrd);
185 
186  }
187  // dofCoords on host and create its mirror view to device
188  Kokkos::DynRankView<typename ScalarViewType::value_type,typename DT::execution_space::array_layout,Kokkos::HostSpace>
189  dofCoords("dofCoordsHost", this->basisCardinality_,spaceDim);
190 
191  dofCoords(0,0) = 0.5; dofCoords(0,1) = 0.0;
192  dofCoords(1,0) = 0.5; dofCoords(1,1) = 0.5;
193  dofCoords(2,0) = 0.0; dofCoords(2,1) = 0.5;
194 
195  this->dofCoords_ = Kokkos::create_mirror_view(typename DT::memory_space(), dofCoords);
196  Kokkos::deep_copy(this->dofCoords_, dofCoords);
197 
198  // dofCoeffs on host and create its mirror view to device
199  Kokkos::DynRankView<typename ScalarViewType::value_type,typename DT::execution_space::array_layout,Kokkos::HostSpace>
200  dofCoeffs("dofCoeffsHost", this->basisCardinality_,spaceDim);
201 
202  dofCoeffs(0,0) = 0.5; dofCoeffs(0,1) = 0.0;
203  dofCoeffs(1,0) = -0.5; dofCoeffs(1,1) = 0.5;
204  dofCoeffs(2,0) = 0.0; dofCoeffs(2,1) = -0.5;
205 
206  this->dofCoeffs_ = Kokkos::create_mirror_view(typename DT::memory_space(), dofCoeffs);
207  Kokkos::deep_copy(this->dofCoeffs_, dofCoeffs);
208 
209  }
210 
211  template<typename DT, typename OT, typename PT>
212  void
214  ordinal_type& perTeamSpaceSize,
215  ordinal_type& perThreadSpaceSize,
216  const PointViewType inputPoints,
217  const EOperator operatorType) const {
218  perTeamSpaceSize = 0;
219  perThreadSpaceSize = 0;
220  }
221 
222  template<typename DT, typename OT, typename PT>
223  KOKKOS_INLINE_FUNCTION
224  void
226  OutputViewType outputValues,
227  const PointViewType inputPoints,
228  const EOperator operatorType,
229  const typename Kokkos::TeamPolicy<typename DT::execution_space>::member_type& team_member,
230  const typename DT::execution_space::scratch_memory_space & scratchStorage,
231  const ordinal_type subcellDim,
232  const ordinal_type subcellOrdinal) const {
233 
234  INTREPID2_TEST_FOR_ABORT( !((subcellDim == -1) && (subcellOrdinal == -1)),
235  ">>> ERROR: (Intrepid2::Basis_HCURL_TRI_I1_FEM::getValues), The capability of selecting subsets of basis functions has not been implemented yet.");
236 
237  (void) scratchStorage; //avoid unused variable warning
238 
239  const int numPoints = inputPoints.extent(0);
240 
241  switch(operatorType) {
242  case OPERATOR_VALUE:
243  Kokkos::parallel_for (Kokkos::TeamThreadRange (team_member, numPoints), [=] (ordinal_type& pt) {
244  auto output = Kokkos::subview( outputValues, Kokkos::ALL(), pt, Kokkos::ALL() );
245  const auto input = Kokkos::subview( inputPoints, pt, Kokkos::ALL() );
247  });
248  break;
249  case OPERATOR_CURL:
250  Kokkos::parallel_for (Kokkos::TeamThreadRange (team_member, numPoints), [=] (ordinal_type& pt) {
251  auto output = Kokkos::subview( outputValues, Kokkos::ALL(), pt, Kokkos::ALL() );
252  const auto input = Kokkos::subview( inputPoints, pt, Kokkos::ALL() );
253  Impl::Basis_HCURL_TRI_I1_FEM::Serial<OPERATOR_CURL>::getValues( output, input);
254  });
255  break;
256  default: {
257  INTREPID2_TEST_FOR_ABORT( true, ">>> ERROR: (Intrepid2::Basis_HCURL_TRI_!1_FEM::getValues), Operator Type not supported.");
258  }
259  }
260  }
261 
262 }// namespace Intrepid2
263 #endif
virtual void getValues(const ExecutionSpace &space, OutputViewType outputValues, const PointViewType inputPoints, const EOperator operatorType=OPERATOR_VALUE) const override
Evaluation of a FEM basis on a reference cell.
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...
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.