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