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 
51 namespace 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) = x;
71  output.access(0, 1) = y - 1.0;
72 
73  output.access(1, 0) = x;
74  output.access(1, 1) = y;
75 
76  output.access(2, 0) = x - 1.0;
77  output.access(2, 1) = y;
78  break;
79  }
80  case OPERATOR_DIV: {
81  // output is a rank-3 array with dimensions (basisCardinality_, spaceDim)
82  output.access(0) = 2;
83  output.access(1) = 2;
84  output.access(2) = 2;
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 SpT,
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,SpT>::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 SpT, 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 
190  // initialize tags
191  {
192  // Basis-dependent initializations
193  const ordinal_type tagSize = 4; // size of DoF tag, i.e., number of fields in the tag
194  const ordinal_type posScDim = 0; // position in the tag, counting from 0, of the subcell dim
195  const ordinal_type posScOrd = 1; // position in the tag, counting from 0, of the subcell ordinal
196  const ordinal_type posDfOrd = 2; // position in the tag, counting from 0, of DoF ordinal relative to the subcell
197 
198  // An array with local DoF tags assigned to the basis functions, in the order of their local enumeration
199  ordinal_type tags[12] = { 1, 0, 0, 1,
200  1, 1, 0, 1,
201  1, 2, 0, 1 };
202 
203  // host tags
204  ordinal_type_array_1d_host tagView(&tags[0], 12);
205 
206  // Basis-independent function sets tag and enum data in tagToOrdinal_ and ordinalToTag_ arrays:
207  //ordinal_type_array_2d_host ordinalToTag;
208  //ordinal_type_array_3d_host tagToOrdinal;
209  this->setOrdinalTagData(this->tagToOrdinal_,
210  this->ordinalToTag_,
211  tagView,
212  this->basisCardinality_,
213  tagSize,
214  posScDim,
215  posScOrd,
216  posDfOrd);
217 
218  //this->tagToOrdinal_ = Kokkos::create_mirror_view(typename SpT::memory_space(), tagToOrdinal);
219  //Kokkos::deep_copy(this->tagToOrdinal_, tagToOrdinal);
220 
221  //this->ordinalToTag_ = Kokkos::create_mirror_view(typename SpT::memory_space(), ordinalToTag);
222  //Kokkos::deep_copy(this->ordinalToTag_, ordinalToTag);
223  }
224 
225  // dofCoords on host and create its mirror view to device
226  Kokkos::DynRankView<typename scalarViewType::value_type,typename SpT::array_layout,Kokkos::HostSpace>
227  dofCoords("dofCoordsHost", this->basisCardinality_,this->basisCellTopology_.getDimension());
228 
229  dofCoords(0,0) = 0.5; dofCoords(0,1) = 0.0;
230  dofCoords(1,0) = 0.5; dofCoords(1,1) = 0.5;
231  dofCoords(2,0) = 0.0; dofCoords(2,1) = 0.5;
232 
233  this->dofCoords_ = Kokkos::create_mirror_view(typename SpT::memory_space(), dofCoords);
234  Kokkos::deep_copy(this->dofCoords_, dofCoords);
235 
236  // dofCoords on host and create its mirror view to device
237  Kokkos::DynRankView<typename scalarViewType::value_type,typename SpT::array_layout,Kokkos::HostSpace>
238  dofCoeffs("dofCoeffsHost", this->basisCardinality_,this->basisCellTopology_.getDimension());
239 
240  // dofCoeffs are normals to edges, having magnitude equal to edges' measures
241  dofCoeffs(0,0) = 0.0; dofCoeffs(0,1) = -1.0;
242  dofCoeffs(1,0) = 1.0; dofCoeffs(1,1) = 1.0;
243  dofCoeffs(2,0) = -1.0; dofCoeffs(2,1) = 0.0;
244 
245  this->dofCoeffs_ = Kokkos::create_mirror_view(typename SpT::memory_space(), dofCoeffs); Kokkos::deep_copy(this->dofCoeffs_, dofCoeffs);
246 
247  }
248 
249 }// namespace Intrepid2
250 #endif
Kokkos::View< ordinal_type *,typename ExecSpaceType::array_layout, Kokkos::HostSpace > ordinal_type_array_1d_host
View type for 1d host array.