Intrepid2
Intrepid2_HGRAD_LINE_Cn_FEM_JACOBIDef.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Intrepid2 Package
4//
5// Copyright 2007 NTESS and the Intrepid2 contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
17#ifndef __INTREPID2_HGRAD_LINE_CN_FEM_JACOBI_DEF_HPP__
18#define __INTREPID2_HGRAD_LINE_CN_FEM_JACOBI_DEF_HPP__
19
20namespace Intrepid2 {
21 // -------------------------------------------------------------------------------------
22
23 namespace Impl {
24
25 // output (N,P,D)
26 // input (P,D) - assumes that it has a set of points to amortize the function call cost for jacobi polynomial.
27 template<EOperator opType>
28 template<typename OutputViewType,
29 typename inputViewType>
30 KOKKOS_INLINE_FUNCTION
31 void
32 Basis_HGRAD_LINE_Cn_FEM_JACOBI::Serial<opType>::
33 getValues( OutputViewType output,
34 const inputViewType input,
35 const ordinal_type order,
36 const double alpha,
37 const double beta,
38 const ordinal_type operatorDn ) {
39 // cardinality of the evaluation order
40 const ordinal_type card = order + 1;
41 ordinal_type opDn = operatorDn;
42
43 const auto pts = Kokkos::subview( input, Kokkos::ALL(), 0 );
44 const ordinal_type np = input.extent(0);
45
46 switch (opType) {
47 case OPERATOR_VALUE: {
48 const Kokkos::View<typename inputViewType::value_type*,
49 typename inputViewType::memory_space,Kokkos::MemoryUnmanaged> null;
50 for (ordinal_type p=0;p<card;++p) {
51 auto poly = Kokkos::subview( output, p, Kokkos::ALL() );
52 Polylib::Serial::JacobiPolynomial(np, pts, poly, null, p, alpha, beta);
53 }
54 break;
55 }
56 case OPERATOR_GRAD:
57 case OPERATOR_D1: {
58 for (ordinal_type p=0;p<card;++p) {
59 auto polyd = Kokkos::subview( output, p, Kokkos::ALL(), 0 );
60 Polylib::Serial::JacobiPolynomialDerivative(np, pts, polyd, p, alpha, beta);
61 }
62 break;
63 }
64 case OPERATOR_D2:
65 case OPERATOR_D3:
66 case OPERATOR_D4:
67 case OPERATOR_D5:
68 case OPERATOR_D6:
69 case OPERATOR_D7:
70 case OPERATOR_D8:
71 case OPERATOR_D9:
72 case OPERATOR_D10:
73 opDn = getOperatorOrder(opType);
74 case OPERATOR_Dn: {
75 {
76 const ordinal_type pend = output.extent(0);
77 const ordinal_type iend = output.extent(1);
78 const ordinal_type jend = output.extent(2);
79
80 for (ordinal_type p=0;p<pend;++p)
81 for (ordinal_type i=0;i<iend;++i)
82 for (ordinal_type j=0;j<jend;++j)
83 output.access(p, i, j) = 0.0;
84 }
85 {
86 const Kokkos::View<typename inputViewType::value_type*,
87 typename inputViewType::memory_space,Kokkos::MemoryUnmanaged> null;
88
89 for (ordinal_type p=opDn;p<card;++p) {
90 double scaleFactor = 1.0;
91 for (ordinal_type i=1;i<=opDn;++i)
92 scaleFactor *= 0.5*(p + alpha + beta + i);
93
94 const auto poly = Kokkos::subview( output, p, Kokkos::ALL(), 0 );
95 Polylib::Serial::JacobiPolynomial(np, pts, poly, null, p-opDn, alpha+opDn, beta+opDn);
96 for (ordinal_type i=0;i<np;++i)
97 poly(i) = scaleFactor*poly(i);
98 }
99 }
100 break;
101 }
102 default: {
103 INTREPID2_TEST_FOR_ABORT( true,
104 ">>> ERROR: (Intrepid2::Basis_HGRAD_LINE_Cn_FEM_JACOBI::Serial::getValues) operator is not supported");
105 }
106 }
107 }
108
109 // -------------------------------------------------------------------------------------
110
111 template<typename DT, ordinal_type numPtsPerEval,
112 typename outputValueValueType, class ...outputValueProperties,
113 typename inputPointValueType, class ...inputPointProperties>
114 void
115 Basis_HGRAD_LINE_Cn_FEM_JACOBI::
116 getValues( const typename DT::execution_space& space,
117 Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValues,
118 const Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPoints,
119 const ordinal_type order,
120 const double alpha,
121 const double beta,
122 const EOperator operatorType ) {
123 typedef Kokkos::DynRankView<outputValueValueType,outputValueProperties...> outputValueViewType;
124 typedef Kokkos::DynRankView<inputPointValueType, inputPointProperties...> inputPointViewType;
125 typedef typename DT::execution_space ExecSpaceType;
126
127 // loopSize corresponds to the # of points
128 const auto loopSizeTmp1 = (inputPoints.extent(0)/numPtsPerEval);
129 const auto loopSizeTmp2 = (inputPoints.extent(0)%numPtsPerEval != 0);
130 const auto loopSize = loopSizeTmp1 + loopSizeTmp2;
131 Kokkos::RangePolicy<ExecSpaceType,Kokkos::Schedule<Kokkos::Static> > policy(space, 0, loopSize);
132
133 switch (operatorType) {
134 case OPERATOR_VALUE: {
135 typedef Functor<outputValueViewType,inputPointViewType,OPERATOR_VALUE,numPtsPerEval> FunctorType;
136 Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints,
137 order, alpha, beta) );
138 break;
139 }
140 case OPERATOR_GRAD:
141 case OPERATOR_D1: {
142 typedef Functor<outputValueViewType,inputPointViewType,OPERATOR_GRAD,numPtsPerEval> FunctorType;
143 Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints,
144 order, alpha, beta) );
145 break;
146 }
147 case OPERATOR_D2:
148 case OPERATOR_D3:
149 case OPERATOR_D4:
150 case OPERATOR_D5:
151 case OPERATOR_D6:
152 case OPERATOR_D7:
153 case OPERATOR_D8:
154 case OPERATOR_D9:
155 case OPERATOR_D10: {
156 typedef Functor<outputValueViewType,inputPointViewType,OPERATOR_Dn,numPtsPerEval> FunctorType;
157 Kokkos::parallel_for( policy, FunctorType(outputValues, inputPoints,
158 order, alpha, beta,
159 getOperatorOrder(operatorType)) );
160 break;
161 }
162 case OPERATOR_DIV:
163 case OPERATOR_CURL: {
164 INTREPID2_TEST_FOR_EXCEPTION( operatorType == OPERATOR_DIV ||
165 operatorType == OPERATOR_CURL, std::invalid_argument,
166 ">>> ERROR (Basis_HGRAD_LINE_Cn_FEM_JACOBI): invalid operator type (div and curl).");
167 break;
168 }
169 default: {
170 INTREPID2_TEST_FOR_EXCEPTION( !Intrepid2::isValidOperator(operatorType), std::invalid_argument,
171 ">>> ERROR (Basis_HGRAD_LINE_Cn_FEM_JACOBI): invalid operator type");
172 }
173 }
174 }
175 }
176
177 // -------------------------------------------------------------------------------------
178
179 template<typename DT, typename OT, typename PT>
181 Basis_HGRAD_LINE_Cn_FEM_JACOBI( const ordinal_type order,
182 const double alpha,
183 const double beta ) {
184 this->basisCardinality_ = order+1;
185 this->basisDegree_ = order;
186 this->basisCellTopologyKey_ = shards::Line<>::key;
187 this->basisType_ = BASIS_FEM_HIERARCHICAL;
188 this->basisCoordinates_ = COORDINATES_CARTESIAN;
189 this->functionSpace_ = FUNCTION_SPACE_HGRAD;
190
191 // jacobi
192 this->alpha_ = alpha;
193 this->beta_ = beta;
194
195 // initialize tags
196 {
197 // Basis-dependent intializations
198 const ordinal_type tagSize = 4; // size of DoF tag, i.e., number of fields in the tag
199 const ordinal_type posScDim = 0; // position in the tag, counting from 0, of the subcell dim
200 const ordinal_type posScOrd = 1; // position in the tag, counting from 0, of the subcell ordinal
201 const ordinal_type posDfOrd = 2; // position in the tag, counting from 0, of DoF ordinal relative to the subcell
202
203 ordinal_type tags[Parameters::MaxOrder+1][4];
204 const ordinal_type card = this->basisCardinality_;
205 for (ordinal_type i=0;i<card;++i) {
206 tags[i][0] = 1; // these are all "internal" i.e. "volume" DoFs
207 tags[i][1] = 0; // there is only one line
208 tags[i][2] = i; // local DoF id
209 tags[i][3] = card; // total number of DoFs
210 }
211
212 OrdinalTypeArray1DHost tagView(&tags[0][0], card*4);
213
214 // Basis-independent function sets tag and enum data in tagToOrdinal_ and ordinalToTag_ arrays:
215 // tags are constructed on host
216 this->setOrdinalTagData(this->tagToOrdinal_,
217 this->ordinalToTag_,
218 tagView,
219 this->basisCardinality_,
220 tagSize,
221 posScDim,
222 posScOrd,
223 posDfOrd);
224 }
225
226 // dof coords is not applicable to hierarchical functions
227 }
228
229
230}
231
232#endif
KOKKOS_INLINE_FUNCTION ordinal_type getOperatorOrder(const EOperator operatorType)
Returns order of an operator.
Basis_HGRAD_LINE_Cn_FEM_JACOBI(const ordinal_type order, const double alpha=0, const double beta=0)
Constructor.
Kokkos::View< ordinal_type *, typename ExecutionSpace::array_layout, Kokkos::HostSpace > OrdinalTypeArray1DHost
View type for 1d host array.
static constexpr ordinal_type MaxOrder
The maximum reconstruction order.
static KOKKOS_INLINE_FUNCTION void JacobiPolynomialDerivative(const ordinal_type np, const zViewType z, polydViewType polyd, const ordinal_type n, const double alpha, const double beta)
Calculate the derivative of Jacobi polynomials.
static KOKKOS_INLINE_FUNCTION void JacobiPolynomial(const ordinal_type np, const zViewType z, polyiViewType poly_in, polydViewType polyd, const ordinal_type n, const double alpha, const double beta)
Routine to calculate Jacobi polynomials, , and their first derivative, .