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