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