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