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