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