Intrepid2
Intrepid2_HGRAD_TRI_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_TRI_C1_FEM_DEF_HPP__
50 #define __INTREPID2_HGRAD_TRI_C1_FEM_DEF_HPP__
51 
52 namespace Intrepid2 {
53 
54 
55  // -------------------------------------------------------------------------------------
56 
57  namespace Impl {
58 
59  template<EOperator opType>
60  template<typename OutputViewType,
61  typename inputViewType>
62  KOKKOS_INLINE_FUNCTION
63  void
64  Basis_HGRAD_TRI_C1_FEM::Serial<opType>::
65  getValues( OutputViewType output,
66  const inputViewType input ) {
67  switch (opType) {
68  case OPERATOR_VALUE: {
69  const auto x = input(0);
70  const auto y = input(1);
71 
72  // output is a rank-2 array with dimensions (basisCardinality_)
73  output.access(0) = 1.0 - x - y;
74  output.access(1) = x;
75  output.access(2) = y;
76  break;
77  }
78  case OPERATOR_GRAD: {
79  // output is a rank-3 array with dimensions (basisCardinality_, spaceDim)
80  output.access(0, 0) = -1.0;
81  output.access(0, 1) = -1.0;
82 
83  output.access(1, 0) = 1.0;
84  output.access(1, 1) = 0.0;
85 
86  output.access(2, 0) = 0.0;
87  output.access(2, 1) = 1.0;
88  break;
89  }
90  case OPERATOR_CURL: {
91  output.access(0, 0) = -1.0;
92  output.access(0, 1) = 1.0;
93 
94  output.access(1, 0) = 0.0;
95  output.access(1, 1) = -1.0;
96 
97  output.access(2, 0) = 1.0;
98  output.access(2, 1) = 0.0;
99  break;
100  }
101  case OPERATOR_MAX: {
102  const ordinal_type jend = output.extent(1);
103  const ordinal_type iend = output.extent(0);
104 
105  for (ordinal_type j=0;j<jend;++j)
106  for (ordinal_type i=0;i<iend;++i)
107  output.access(i, j) = 0.0;
108  break;
109  }
110  default: {
111  INTREPID2_TEST_FOR_ABORT( opType != OPERATOR_VALUE &&
112  opType != OPERATOR_GRAD &&
113  opType != OPERATOR_CURL &&
114  opType != OPERATOR_MAX,
115  ">>> ERROR: (Intrepid2::Basis_HGRAD_TRI_C1_FEM::Serial::getValues) operator is not supported");
116  }
117  }
118  }
119 
120 
121  template<typename SpT,
122  typename outputValueValueType, class ...outputValueProperties,
123  typename inputPointValueType, class ...inputPointProperties>
124  void
125  Basis_HGRAD_TRI_C1_FEM::
126  getValues( Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValues,
127  const Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPoints,
128  const EOperator operatorType ) {
129  typedef Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValueViewType;
130  typedef Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPointViewType;
131  typedef typename ExecSpace<typename inputPointViewType::execution_space,SpT>::ExecSpaceType ExecSpaceType;
132 
133  // Number of evaluation points = dim 0 of inputPoints
134  const auto loopSize = inputPoints.extent(0);
135  Kokkos::RangePolicy<ExecSpaceType,Kokkos::Schedule<Kokkos::Static> > policy(0, loopSize);
136 
137  switch (operatorType) {
138  case OPERATOR_VALUE: {
139  typedef Functor<outputValueViewType,inputPointViewType,OPERATOR_VALUE> FunctorType;
140  Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints) );
141  break;
142  }
143  case OPERATOR_GRAD:
144  case OPERATOR_D1: {
145  typedef Functor<outputValueViewType,inputPointViewType,OPERATOR_GRAD> FunctorType;
146  Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints) );
147  break;
148  }
149  case OPERATOR_CURL: {
150  typedef Functor<outputValueViewType,inputPointViewType,OPERATOR_CURL> FunctorType;
151  Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints) );
152  break;
153  }
154  case OPERATOR_DIV: {
155  INTREPID2_TEST_FOR_EXCEPTION( operatorType == OPERATOR_DIV, std::invalid_argument,
156  ">>> ERROR (Basis_HGRAD_TRI_C1_FEM): DIV is invalid operator for rank-0 (scalar) functions in 2D");
157  break;
158  }
159  case OPERATOR_D2:
160  case OPERATOR_D3:
161  case OPERATOR_D4:
162  case OPERATOR_D5:
163  case OPERATOR_D6:
164  case OPERATOR_D7:
165  case OPERATOR_D8:
166  case OPERATOR_D9:
167  case OPERATOR_D10: {
168  typedef Functor<outputValueViewType,inputPointViewType,OPERATOR_MAX> FunctorType;
169  Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints) );
170  break;
171  }
172  default: {
173  INTREPID2_TEST_FOR_EXCEPTION( !Intrepid2::isValidOperator(operatorType), std::invalid_argument,
174  ">>> ERROR (Basis_HGRAD_TRI_C1_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  this->functionSpace_ = FUNCTION_SPACE_HGRAD;
190 
191  // initialize tags
192  {
193  // Basis-dependent initializations
194  const ordinal_type tagSize = 4; // size of DoF tag, i.e., number of fields in the 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 the basis functions, in the order of their local enumeration
200  ordinal_type tags[12] = { 0, 0, 0, 1,
201  0, 1, 0, 1,
202  0, 2, 0, 1 };
203 
204  // host tags
205  OrdinalTypeArray1DHost tagView(&tags[0], 12);
206 
207  // Basis-independent function sets tag and enum data in tagToOrdinal_ and ordinalToTag_ arrays:
208  //OrdinalTypeArray2DHost ordinalToTag;
209  //OrdinalTypeArray3DHost tagToOrdinal;
210  this->setOrdinalTagData(this->tagToOrdinal_,
211  this->ordinalToTag_,
212  tagView,
213  this->basisCardinality_,
214  tagSize,
215  posScDim,
216  posScOrd,
217  posDfOrd);
218 
219  //this->tagToOrdinal_ = Kokkos::create_mirror_view(typename SpT::memory_space(), tagToOrdinal);
220  //Kokkos::deep_copy(this->tagToOrdinal_, tagToOrdinal);
221 
222  //this->ordinalToTag_ = Kokkos::create_mirror_view(typename SpT::memory_space(), ordinalToTag);
223  //Kokkos::deep_copy(this->ordinalToTag_, ordinalToTag);
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) = 0.0;
231  dofCoords(1,0) = 1.0; dofCoords(1,1) = 0.0;
232  dofCoords(2,0) = 0.0; dofCoords(2,1) = 1.0;
233 
234  this->dofCoords_ = Kokkos::create_mirror_view(typename SpT::memory_space(), dofCoords);
235  Kokkos::deep_copy(this->dofCoords_, dofCoords);
236  }
237 
238 }// namespace Intrepid2
239 #endif
Kokkos::View< ordinal_type *, typename ExecSpaceType::array_layout, Kokkos::HostSpace > OrdinalTypeArray1DHost
View type for 1d host array.