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