Intrepid2
Intrepid2_HDIV_TRI_I1_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_HDIV_TRI_I1_FEM_DEF_HPP__
49#define __INTREPID2_HDIV_TRI_I1_FEM_DEF_HPP__
50
51namespace Intrepid2 {
52
53 // -------------------------------------------------------------------------------------
54 namespace Impl {
55
56 template<EOperator opType>
57 template<typename OutputViewType,
58 typename inputViewType>
59 KOKKOS_INLINE_FUNCTION
60 void
61 Basis_HDIV_TRI_I1_FEM::Serial<opType>::
62 getValues( OutputViewType output,
63 const inputViewType input ) {
64 switch (opType) {
65 case OPERATOR_VALUE: {
66 const auto x = input(0);
67 const auto y = input(1);
68
69 // output is a rank-2 array with dimensions (basisCardinality_)
70 output.access(0, 0) = 2.0*x;
71 output.access(0, 1) = 2.0*(y - 1.0);
72
73 output.access(1, 0) = 2.0*x;
74 output.access(1, 1) = 2.0*y;
75
76 output.access(2, 0) = 2.0*(x - 1.0);
77 output.access(2, 1) = 2.0*y;
78 break;
79 }
80 case OPERATOR_DIV: {
81 // output is a rank-3 array with dimensions (basisCardinality_, spaceDim)
82 output.access(0) = 4.0;
83 output.access(1) = 4.0;
84 output.access(2) = 4.0;
85 break;
86 }
87 default: {
88 INTREPID2_TEST_FOR_ABORT( opType != OPERATOR_VALUE &&
89 opType != OPERATOR_DIV,
90 ">>> ERROR: (Intrepid2::Basis_HDIV_TRI_I1_FEM::Serial::getValues) operator is not supported");
91 }
92 }
93 }
94
95
96 template<typename DT,
97 typename outputValueValueType, class ...outputValueProperties,
98 typename inputPointValueType, class ...inputPointProperties>
99 void
100 Basis_HDIV_TRI_I1_FEM::
101 getValues( Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValues,
102 const Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPoints,
103 const EOperator operatorType ) {
104 typedef Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValueViewType;
105 typedef Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPointViewType;
106 typedef typename ExecSpace<typename inputPointViewType::execution_space,typename DT::execution_space>::ExecSpaceType ExecSpaceType;
107
108 // Number of evaluation points = dim 0 of inputPoints
109 const auto loopSize = inputPoints.extent(0);
110 Kokkos::RangePolicy<ExecSpaceType,Kokkos::Schedule<Kokkos::Static> > policy(0, loopSize);
111
112 switch (operatorType) {
113 case OPERATOR_VALUE: {
114 typedef Functor<outputValueViewType,inputPointViewType,OPERATOR_VALUE> FunctorType;
115 Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints) );
116 break;
117 }
118 case OPERATOR_DIV: {
119 typedef Functor<outputValueViewType,inputPointViewType,OPERATOR_DIV> FunctorType;
120 Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints) );
121 break;
122 }
123 case OPERATOR_CURL: {
124 INTREPID2_TEST_FOR_EXCEPTION( (operatorType == OPERATOR_CURL), std::invalid_argument,
125 ">>> ERROR (Basis_HDIV_TRI_I1_FEM): CURL is invalid operator for HDIV Basis Functions");
126 break;
127 }
128
129 case OPERATOR_GRAD: {
130 INTREPID2_TEST_FOR_EXCEPTION( (operatorType == OPERATOR_GRAD), std::invalid_argument,
131 ">>> ERROR (Basis_HDIV_TRI_I1_FEM): GRAD is invalid operator for HDIV Basis Functions");
132 break;
133 }
134 case OPERATOR_D1:
135 case OPERATOR_D2:
136 case OPERATOR_D3:
137 case OPERATOR_D4:
138 case OPERATOR_D5:
139 case OPERATOR_D6:
140 case OPERATOR_D7:
141 case OPERATOR_D8:
142 case OPERATOR_D9:
143 case OPERATOR_D10: {
144 INTREPID2_TEST_FOR_EXCEPTION( ( (operatorType == OPERATOR_D1) &&
145 (operatorType == OPERATOR_D2) &&
146 (operatorType == OPERATOR_D3) &&
147 (operatorType == OPERATOR_D4) &&
148 (operatorType == OPERATOR_D5) &&
149 (operatorType == OPERATOR_D6) &&
150 (operatorType == OPERATOR_D7) &&
151 (operatorType == OPERATOR_D8) &&
152 (operatorType == OPERATOR_D9) &&
153 (operatorType == OPERATOR_D10) ),
154 std::invalid_argument,
155 ">>> ERROR (Basis_HDIV_TRI_I1_FEM): Invalid operator type");
156 break;
157 }
158 default: {
159 INTREPID2_TEST_FOR_EXCEPTION( ( (operatorType != OPERATOR_VALUE) &&
160 (operatorType != OPERATOR_GRAD) &&
161 (operatorType != OPERATOR_CURL) &&
162 (operatorType != OPERATOR_DIV) &&
163 (operatorType != OPERATOR_D1) &&
164 (operatorType != OPERATOR_D2) &&
165 (operatorType != OPERATOR_D3) &&
166 (operatorType != OPERATOR_D4) &&
167 (operatorType != OPERATOR_D5) &&
168 (operatorType != OPERATOR_D6) &&
169 (operatorType != OPERATOR_D7) &&
170 (operatorType != OPERATOR_D8) &&
171 (operatorType != OPERATOR_D9) &&
172 (operatorType != OPERATOR_D10) ),
173 std::invalid_argument,
174 ">>> ERROR (Basis_HDIV_TRI_I1_FEM): Invalid operator type");
175 }
176 }
177 }
178 }
179 // -------------------------------------------------------------------------------------
180
181 template<typename DT, typename OT, typename PT>
184 this->basisCardinality_ = 3;
185 this->basisDegree_ = 1;
186 this->basisCellTopology_ = shards::CellTopology(shards::getCellTopologyData<shards::Triangle<3> >() );
187 this->basisType_ = BASIS_FEM_DEFAULT;
188 this->basisCoordinates_ = COORDINATES_CARTESIAN;
189 this->functionSpace_ = FUNCTION_SPACE_HDIV;
190
191 // initialize tags
192 {
193 // Basis-dependent initializations
194 const ordinal_type tagSize = 4; // size of DoF tag, i.e., number of fields in the tag
195 const ordinal_type posScDim = 0; // position in the tag, counting from 0, of the subcell dim
196 const ordinal_type posScOrd = 1; // position in the tag, counting from 0, of the subcell ordinal
197 const ordinal_type posDfOrd = 2; // position in the tag, counting from 0, of DoF ordinal relative to the subcell
198
199 // An array with local DoF tags assigned to the basis functions, in the order of their local enumeration
200 ordinal_type tags[12] = { 1, 0, 0, 1,
201 1, 1, 0, 1,
202 1, 2, 0, 1 };
203
204 // host tags
205 OrdinalTypeArray1DHost tagView(&tags[0], 12);
206
207 // Basis-independent function sets tag and enum data in tagToOrdinal_ and ordinalToTag_ arrays:
208 //OrdinalTypeArray2DHost ordinalToTag;
209 //OrdinalTypeArray3DHost tagToOrdinal;
210 this->setOrdinalTagData(this->tagToOrdinal_,
211 this->ordinalToTag_,
212 tagView,
213 this->basisCardinality_,
214 tagSize,
215 posScDim,
216 posScOrd,
217 posDfOrd);
218
219 //this->tagToOrdinal_ = Kokkos::create_mirror_view(typename DT::memory_space(), tagToOrdinal);
220 //Kokkos::deep_copy(this->tagToOrdinal_, tagToOrdinal);
221
222 //this->ordinalToTag_ = Kokkos::create_mirror_view(typename DT::memory_space(), ordinalToTag);
223 //Kokkos::deep_copy(this->ordinalToTag_, ordinalToTag);
224 }
225
226 // dofCoords on host and create its mirror view to device
227 Kokkos::DynRankView<typename ScalarViewType::value_type,typename DT::execution_space::array_layout,Kokkos::HostSpace>
228 dofCoords("dofCoordsHost", this->basisCardinality_,this->basisCellTopology_.getDimension());
229
230 dofCoords(0,0) = 0.5; dofCoords(0,1) = 0.0;
231 dofCoords(1,0) = 0.5; dofCoords(1,1) = 0.5;
232 dofCoords(2,0) = 0.0; dofCoords(2,1) = 0.5;
233
234 this->dofCoords_ = Kokkos::create_mirror_view(typename DT::memory_space(), dofCoords);
235 Kokkos::deep_copy(this->dofCoords_, dofCoords);
236
237 // dofCoords on host and create its mirror view to device
238 Kokkos::DynRankView<typename ScalarViewType::value_type,typename DT::execution_space::array_layout,Kokkos::HostSpace>
239 dofCoeffs("dofCoeffsHost", this->basisCardinality_,this->basisCellTopology_.getDimension());
240
241 // dofCoeffs are normals to edges, having magnitude equal to edges' measures
242 dofCoeffs(0,0) = 0.0; dofCoeffs(0,1) = -0.5;
243 dofCoeffs(1,0) = 0.5; dofCoeffs(1,1) = 0.5;
244 dofCoeffs(2,0) = -0.5; dofCoeffs(2,1) = 0.0;
245
246 this->dofCoeffs_ = Kokkos::create_mirror_view(typename DT::memory_space(), dofCoeffs); Kokkos::deep_copy(this->dofCoeffs_, dofCoeffs);
247
248 }
249
250}// namespace Intrepid2
251#endif