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