Intrepid2
Intrepid2_HGRAD_TRI_C1_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_HGRAD_TRI_C1_FEM_DEF_HPP__
17#define __INTREPID2_HGRAD_TRI_C1_FEM_DEF_HPP__
18
19namespace Intrepid2 {
20
21
22 // -------------------------------------------------------------------------------------
23
24 namespace Impl {
25
26 template<EOperator opType>
27 template<typename OutputViewType,
28 typename inputViewType>
29 KOKKOS_INLINE_FUNCTION
30 void
31 Basis_HGRAD_TRI_C1_FEM::Serial<opType>::
32 getValues( OutputViewType output,
33 const inputViewType input ) {
34 switch (opType) {
35 case OPERATOR_VALUE: {
36 const auto x = input(0);
37 const auto y = input(1);
38
39 // output is a rank-2 array with dimensions (basisCardinality_)
40 output.access(0) = 1.0 - x - y;
41 output.access(1) = x;
42 output.access(2) = y;
43 break;
44 }
45 case OPERATOR_GRAD: {
46 // output is a rank-3 array with dimensions (basisCardinality_, spaceDim)
47 output.access(0, 0) = -1.0;
48 output.access(0, 1) = -1.0;
49
50 output.access(1, 0) = 1.0;
51 output.access(1, 1) = 0.0;
52
53 output.access(2, 0) = 0.0;
54 output.access(2, 1) = 1.0;
55 break;
56 }
57 case OPERATOR_CURL: {
58 output.access(0, 0) = -1.0;
59 output.access(0, 1) = 1.0;
60
61 output.access(1, 0) = 0.0;
62 output.access(1, 1) = -1.0;
63
64 output.access(2, 0) = 1.0;
65 output.access(2, 1) = 0.0;
66 break;
67 }
68 case OPERATOR_MAX: {
69 const ordinal_type jend = output.extent(1);
70 const ordinal_type iend = output.extent(0);
71
72 for (ordinal_type j=0;j<jend;++j)
73 for (ordinal_type i=0;i<iend;++i)
74 output.access(i, j) = 0.0;
75 break;
76 }
77 default: {
78 INTREPID2_TEST_FOR_ABORT( opType != OPERATOR_VALUE &&
79 opType != OPERATOR_GRAD &&
80 opType != OPERATOR_CURL &&
81 opType != OPERATOR_MAX,
82 ">>> ERROR: (Intrepid2::Basis_HGRAD_TRI_C1_FEM::Serial::getValues) operator is not supported");
83 }
84 }
85 }
86
87
88 template<typename DT,
89 typename outputValueValueType, class ...outputValueProperties,
90 typename inputPointValueType, class ...inputPointProperties>
91 void
92 Basis_HGRAD_TRI_C1_FEM::
93 getValues( const typename DT::execution_space& space,
94 Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValues,
95 const Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPoints,
96 const EOperator operatorType ) {
97 typedef Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValueViewType;
98 typedef Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPointViewType;
99 typedef typename ExecSpace<typename inputPointViewType::execution_space,typename DT::execution_space>::ExecSpaceType ExecSpaceType;
100
101 // Number of evaluation points = dim 0 of inputPoints
102 const auto loopSize = inputPoints.extent(0);
103 Kokkos::RangePolicy<ExecSpaceType,Kokkos::Schedule<Kokkos::Static> > policy(space, 0, loopSize);
104
105 switch (operatorType) {
106 case OPERATOR_VALUE: {
107 typedef Functor<outputValueViewType,inputPointViewType,OPERATOR_VALUE> FunctorType;
108 Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints) );
109 break;
110 }
111 case OPERATOR_GRAD:
112 case OPERATOR_D1: {
113 typedef Functor<outputValueViewType,inputPointViewType,OPERATOR_GRAD> FunctorType;
114 Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints) );
115 break;
116 }
117 case OPERATOR_CURL: {
118 typedef Functor<outputValueViewType,inputPointViewType,OPERATOR_CURL> FunctorType;
119 Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints) );
120 break;
121 }
122 case OPERATOR_DIV: {
123 INTREPID2_TEST_FOR_EXCEPTION( operatorType == OPERATOR_DIV, std::invalid_argument,
124 ">>> ERROR (Basis_HGRAD_TRI_C1_FEM): DIV is invalid operator for rank-0 (scalar) functions in 2D");
125 break;
126 }
127 case OPERATOR_D2:
128 case OPERATOR_D3:
129 case OPERATOR_D4:
130 case OPERATOR_D5:
131 case OPERATOR_D6:
132 case OPERATOR_D7:
133 case OPERATOR_D8:
134 case OPERATOR_D9:
135 case OPERATOR_D10: {
136 typedef Functor<outputValueViewType,inputPointViewType,OPERATOR_MAX> FunctorType;
137 Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints) );
138 break;
139 }
140 default: {
141 INTREPID2_TEST_FOR_EXCEPTION( !Intrepid2::isValidOperator(operatorType), std::invalid_argument,
142 ">>> ERROR (Basis_HGRAD_TRI_C1_FEM): Invalid operator type");
143 }
144 }
145 }
146 }
147 // -------------------------------------------------------------------------------------
148
149 template<typename DT, typename OT, typename PT>
152 const ordinal_type spaceDim = 2;
153 this->basisCardinality_ = 3;
154 this->basisDegree_ = 1;
155 this->basisCellTopologyKey_ = shards::Triangle<3>::key;
156 this->basisType_ = BASIS_FEM_DEFAULT;
157 this->basisCoordinates_ = COORDINATES_CARTESIAN;
158 this->functionSpace_ = FUNCTION_SPACE_HGRAD;
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] = { 0, 0, 0, 1,
170 0, 1, 0, 1,
171 0, 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.0; dofCoords(0,1) = 0.0;
200 dofCoords(1,0) = 1.0; dofCoords(1,1) = 0.0;
201 dofCoords(2,0) = 0.0; dofCoords(2,1) = 1.0;
202
203 this->dofCoords_ = Kokkos::create_mirror_view(typename DT::memory_space(), dofCoords);
204 Kokkos::deep_copy(this->dofCoords_, dofCoords);
205 }
206
207 template<typename DT, typename OT, typename PT>
208 void
210 ordinal_type& perTeamSpaceSize,
211 ordinal_type& perThreadSpaceSize,
212 const PointViewType inputPoints,
213 const EOperator operatorType) const {
214 perTeamSpaceSize = 0;
215 perThreadSpaceSize = 0;
216 }
217
218 template<typename DT, typename OT, typename PT>
219 KOKKOS_INLINE_FUNCTION
220 void
222 OutputViewType outputValues,
223 const PointViewType inputPoints,
224 const EOperator operatorType,
225 const typename Kokkos::TeamPolicy<typename DT::execution_space>::member_type& team_member,
226 const typename DT::execution_space::scratch_memory_space & scratchStorage,
227 const ordinal_type subcellDim,
228 const ordinal_type subcellOrdinal) const {
229
230 INTREPID2_TEST_FOR_ABORT( !((subcellDim <= 0) && (subcellOrdinal == -1)),
231 ">>> ERROR: (Intrepid2::Basis_HGRAD_TRI_C1_FEM::getValues), The capability of selecting subsets of basis functions has not been implemented yet.");
232
233 (void) scratchStorage; //avoid unused variable warning
234
235 const int numPoints = inputPoints.extent(0);
236
237 switch(operatorType) {
238 case OPERATOR_VALUE:
239 Kokkos::parallel_for (Kokkos::TeamThreadRange (team_member, numPoints), [=] (ordinal_type& pt) {
240 auto output = Kokkos::subview( outputValues, Kokkos::ALL(), pt, Kokkos::ALL() );
241 const auto input = Kokkos::subview( inputPoints, pt, Kokkos::ALL() );
243 });
244 break;
245 case OPERATOR_GRAD:
246 Kokkos::parallel_for (Kokkos::TeamThreadRange (team_member, numPoints), [=] (ordinal_type& pt) {
247 auto output = Kokkos::subview( outputValues, Kokkos::ALL(), pt, Kokkos::ALL() );
248 const auto input = Kokkos::subview( inputPoints, pt, Kokkos::ALL() );
249 Impl::Basis_HGRAD_TRI_C1_FEM::Serial<OPERATOR_GRAD>::getValues( output, input);
250 });
251 break;
252 case OPERATOR_CURL:
253 Kokkos::parallel_for (Kokkos::TeamThreadRange (team_member, numPoints), [=] (ordinal_type& pt) {
254 auto output = Kokkos::subview( outputValues, Kokkos::ALL(), pt, Kokkos::ALL() );
255 const auto input = Kokkos::subview( inputPoints, pt, Kokkos::ALL() );
256 Impl::Basis_HGRAD_TRI_C1_FEM::Serial<OPERATOR_CURL>::getValues( output, input);
257 });
258 break;
259 default: {
260 INTREPID2_TEST_FOR_ABORT( true, ">>> ERROR: (Intrepid2::Basis_HGRAD_TRI_C1_FEM::getValues), Operator Type not supported.");
261 }
262 }
263 }
264
265}// namespace Intrepid2
266#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::DynRankView< PointValueType, Kokkos::LayoutStride, DeviceType > PointViewType
View type for input points.
Kokkos::View< ordinal_type *, typename ExecutionSpace::array_layout, Kokkos::HostSpace > OrdinalTypeArray1DHost
View type for 1d host array.