15 #ifndef Intrepid2_Polynomials_h
16 #define Intrepid2_Polynomials_h
21 #if defined(HAVE_INTREPID2_SACADO) && !defined(KOKKOS_ENABLE_IMPL_VIEW_LEGACY)
57 template<
typename OutputValueViewType,
typename ScalarType>
58 KOKKOS_INLINE_FUNCTION
void legendreValues(OutputValueViewType outputValues, Intrepid2::ordinal_type n, ScalarType x)
60 if (n >= 0) outputValues(0) = 1.0;
61 if (n >= 1) outputValues(1) = x;
62 for (
int i=2; i<=n; i++)
64 const ScalarType i_scalar = ScalarType(i);
65 outputValues(i) = (2. - 1. / i_scalar) * x * outputValues(i-1) - (1. - 1. / i_scalar) * outputValues(i-2);
76 template<
typename OutputValueViewType,
typename ScalarType>
77 KOKKOS_INLINE_FUNCTION
void legendreDerivativeValues(OutputValueViewType outputValues,
const OutputValueViewType legendreValues, Intrepid2::ordinal_type n, ScalarType x)
79 if (n >= 0) outputValues(0) = 0.0;
80 if (n >= 1) outputValues(1) = 1.0;
81 for (
int i=2; i<=n; i++)
83 const ScalarType i_scalar = ScalarType(i);
84 outputValues(i) = outputValues(i-2) + (2. * i_scalar - 1.) * legendreValues(i-1);
99 template<
typename OutputValueViewType,
typename Po
intScalarType>
100 KOKKOS_INLINE_FUNCTION
void legendreDerivativeValues(OutputValueViewType outputValues, Intrepid2::ordinal_type n, PointScalarType x, Intrepid2::ordinal_type dn)
102 const OutputValueViewType nullOutputScalarView;
103 const double alpha = 0;
104 const double beta = 0;
105 const int numPoints = 1;
107 using Layout =
typename NaturalLayoutForType<PointScalarType>::layout;
109 using UnmanagedPointScalarView = Kokkos::View<PointScalarType*, Layout, Kokkos::MemoryTraits<Kokkos::Unmanaged> >;
110 UnmanagedPointScalarView pointView;
111 #if defined(HAVE_INTREPID2_SACADO) && defined(SACADO_HAS_NEW_KOKKOS_VIEW_IMPL)
112 if constexpr (Sacado::is_view_fad<UnmanagedPointScalarView>::value) {
114 pointView = UnmanagedPointScalarView(&x.val(), numPoints, 1);
117 pointView = UnmanagedPointScalarView(&x, numPoints);
118 for (
int i=0; i<=n; i++)
120 auto jacobiValue = Kokkos::subview(outputValues,Kokkos::pair<Intrepid2::ordinal_type,Intrepid2::ordinal_type>(i,i+1));
121 jacobiValue(0) = 0.0;
124 double scaleFactor = 1.0;
125 for (
int j=1; j<=dn; j++)
127 scaleFactor *= 0.5 * (j+alpha+beta+i);
130 outputValues(i) = jacobiValue(0) * scaleFactor;
143 template<
typename OutputValueViewType,
typename ScalarType>
144 KOKKOS_INLINE_FUNCTION
void shiftedLegendreValues(OutputValueViewType outputValues, Intrepid2::ordinal_type n, ScalarType x)
146 legendreValues(outputValues, n, 2.*x-1.);
159 template<
typename OutputValueViewType,
typename ScalarType,
typename ScalarTypeForScaling>
160 KOKKOS_INLINE_FUNCTION
void shiftedScaledLegendreValues(OutputValueViewType outputValues, Intrepid2::ordinal_type n, ScalarType x, ScalarTypeForScaling t)
162 using OutputScalar =
typename OutputValueViewType::value_type;
163 OutputScalar two_x_minus_t = 2. * x - t;
164 OutputScalar t_squared = t * t;
165 if (n >= 0) outputValues(0) = 1.0;
166 if (n >= 1) outputValues(1) = two_x_minus_t;
167 for (
int i=2; i<=n; i++)
169 const ScalarType one_over_i = 1.0 / ScalarType(i);
170 outputValues(i) = one_over_i * ( (2. *i - 1. ) * two_x_minus_t * outputValues(i-1) - (i - 1.) * t_squared * outputValues(i-2));
187 template<
typename OutputValueViewType,
typename ScalarType,
typename ScalarTypeForScaling>
188 KOKKOS_INLINE_FUNCTION
void shiftedScaledIntegratedLegendreValues(OutputValueViewType outputValues, Intrepid2::ordinal_type n, ScalarType x, ScalarTypeForScaling t)
191 shiftedScaledLegendreValues(outputValues,n,x,t);
193 ScalarType P_i_minus_two, P_i_minus_one;
194 if (n >= 0) P_i_minus_two = outputValues(0);
195 if (n >= 1) P_i_minus_one = outputValues(1);
197 if (n >= 0) outputValues(0) = 1.0;
198 if (n >= 1) outputValues(1) = x;
199 for (
int i=2; i<=n; i++)
201 const ScalarType & P_i = outputValues(i);
202 const ScalarType i_scalar = ScalarType(i);
203 ScalarType L_i = (P_i - t * t * P_i_minus_two) /( 2. * (2. * i_scalar - 1.));
206 P_i_minus_two = P_i_minus_one;
210 outputValues(i) = L_i;
228 template<
typename OutputValueViewType,
typename ScalarType,
typename ScalarTypeForScaling>
229 KOKKOS_INLINE_FUNCTION
void shiftedScaledIntegratedLegendreValues(OutputValueViewType outputValues,
const OutputValueViewType shiftedScaledLegendreValues,
230 Intrepid2::ordinal_type n, ScalarType x, ScalarTypeForScaling t)
233 if (n >= 0) outputValues(0) = 1.0;
234 if (n >= 1) outputValues(1) = x;
235 for (
int i=2; i<=n; i++)
237 const ScalarType & P_i = shiftedScaledLegendreValues(i);
238 const ScalarType & P_i_minus_two = shiftedScaledLegendreValues(i-2);
239 const ScalarType i_scalar = ScalarType(i);
240 outputValues(i) = (P_i - t * t * P_i_minus_two) /( 2. * (2. * i_scalar - 1.));
282 template<
typename OutputValueViewType,
typename ScalarType,
typename ScalarTypeForScaling>
283 KOKKOS_INLINE_FUNCTION
void shiftedScaledIntegratedLegendreValues_dx(OutputValueViewType outputValues, Intrepid2::ordinal_type n, ScalarType x, ScalarTypeForScaling t)
285 if (n >= 0) outputValues(0) = 0.0;
286 if (n >= 1) outputValues(1) = 1.0;
287 if (n >= 2) outputValues(2) = 2. * x - t;
288 for (
int i=2; i<=n-1; i++)
290 const ScalarType one_over_i = 1.0 / ScalarType(i);
291 outputValues(i+1) = one_over_i * (2. * i - 1.) * (2. * x - t) * outputValues(i) - one_over_i * (i - 1.0) * t * t * outputValues(i-1);
304 template<
typename OutputValueViewType,
typename ScalarType,
typename ScalarTypeForScaling>
305 KOKKOS_INLINE_FUNCTION
void shiftedScaledIntegratedLegendreValues_dt(OutputValueViewType outputValues, Intrepid2::ordinal_type n, ScalarType x, ScalarTypeForScaling t)
308 shiftedScaledLegendreValues(outputValues, n, x, t);
310 ScalarType P_i_minus_2 = outputValues(0);
311 ScalarType P_i_minus_1 = outputValues(1);
313 if (n >= 0) outputValues(0) = 0.0;
314 if (n >= 1) outputValues(1) = 0.0;
316 for (
int i=2; i<=n; i++)
318 const ScalarType L_i_dt = -0.5 * (P_i_minus_1 + t * P_i_minus_2);
320 P_i_minus_2 = P_i_minus_1;
321 P_i_minus_1 = outputValues(i);
323 outputValues(i) = L_i_dt;
337 template<
typename OutputValueViewType,
typename ScalarType,
typename ScalarTypeForScaling>
338 KOKKOS_INLINE_FUNCTION
void shiftedScaledIntegratedLegendreValues_dt(OutputValueViewType outputValues,
const OutputValueViewType shiftedScaledLegendreValues,
339 Intrepid2::ordinal_type n, ScalarType x, ScalarTypeForScaling t)
342 if (n >= 0) outputValues(0) = 0.0;
343 if (n >= 1) outputValues(1) = 0.0;
344 for (
int i=2; i<=n; i++)
346 const ScalarType & P_i_minus_1 = shiftedScaledLegendreValues(i-1);
347 const ScalarType & P_i_minus_2 = shiftedScaledLegendreValues(i-2);
348 outputValues(i) = -0.5 * (P_i_minus_1 + t * P_i_minus_2);
366 template<
typename OutputValueViewType,
typename ScalarType,
typename ScalarTypeForScaling>
367 KOKKOS_INLINE_FUNCTION
void shiftedScaledJacobiValues(OutputValueViewType outputValues,
double alpha, Intrepid2::ordinal_type n, ScalarType x, ScalarTypeForScaling t)
369 ScalarType two_x_minus_t = 2. * x - t;
370 ScalarTypeForScaling alpha_squared_t = alpha * alpha * t;
372 if (n >= 0) outputValues(0) = 1.0;
373 if (n >= 1) outputValues(1) = two_x_minus_t + alpha * x;
375 for (
int i=2; i<=n; i++)
377 const ScalarType & P_i_minus_one = outputValues(i-1);
378 const ScalarType & P_i_minus_two = outputValues(i-2);
380 double a_i = (2. * i) * (i + alpha) * (2. * i + alpha - 2.);
381 double b_i = 2. * i + alpha - 1.;
382 double c_i = (2. * i + alpha) * (2. * i + alpha - 2.);
383 double d_i = 2. * (i + alpha - 1.) * (i - 1.) * (2. * i + alpha);
385 outputValues(i) = (b_i / a_i) * (c_i * two_x_minus_t + alpha_squared_t) * P_i_minus_one - (d_i / a_i) * t * t * P_i_minus_two;
406 template<
typename OutputValueViewType,
typename ScalarType,
typename ScalarTypeForScaling>
407 KOKKOS_INLINE_FUNCTION
void shiftedScaledIntegratedJacobiValues(OutputValueViewType outputValues,
const OutputValueViewType jacobiValues,
408 double alpha, Intrepid2::ordinal_type n, ScalarType x, ScalarTypeForScaling t)
411 if (n >= 0) outputValues(0) = 1.0;
412 if (n >= 1) outputValues(1) = x;
414 ScalarType t_squared = t * t;
415 for (
int i=2; i<=n; i++)
417 const ScalarType & P_i = jacobiValues(i);
418 const ScalarType & P_i_minus_1 = jacobiValues(i-1);
419 const ScalarType & P_i_minus_2 = jacobiValues(i-2);
421 double a_i = (i + alpha) / ((2. * i + alpha - 1.) * (2. * i + alpha ));
422 double b_i = alpha / ((2. * i + alpha - 2.) * (2. * i + alpha ));
423 double c_i = (i - 1.) / ((2. * i + alpha - 2.) * (2. * i + alpha - 1.));
425 outputValues(i) = a_i * P_i + b_i * t * P_i_minus_1 - c_i * t_squared * P_i_minus_2;
446 template<
typename OutputValueViewType,
typename ScalarType,
typename ScalarTypeForScaling>
447 KOKKOS_INLINE_FUNCTION
void shiftedScaledIntegratedJacobiValues(OutputValueViewType outputValues,
448 double alpha, Intrepid2::ordinal_type n, ScalarType x, ScalarTypeForScaling t)
451 shiftedScaledJacobiValues(outputValues, alpha, n, x, t);
453 ScalarType P_i_minus_2 = outputValues(0);
454 ScalarType P_i_minus_1 = outputValues(1);
456 if (n >= 0) outputValues(0) = 1.0;
457 if (n >= 1) outputValues(1) = x;
459 ScalarType t_squared = t * t;
460 for (
int i=2; i<=n; i++)
462 const ScalarType & P_i = outputValues(i);
464 double a_i = (i + alpha) / ((2. * i + alpha - 1.) * (2. * i + alpha ));
465 double b_i = alpha / ((2. * i + alpha - 2.) * (2. * i + alpha ));
466 double c_i = (i - 1.) / ((2. * i + alpha - 2.) * (2. * i + alpha - 1.));
468 ScalarType L_i = a_i * P_i + b_i * t * P_i_minus_1 - c_i * t_squared * P_i_minus_2;
470 P_i_minus_2 = P_i_minus_1;
473 outputValues(i) = L_i;
486 template<
typename OutputValueViewType,
typename ScalarType,
typename ScalarTypeForScaling>
487 KOKKOS_INLINE_FUNCTION
void shiftedScaledIntegratedJacobiValues_dx(OutputValueViewType outputValues,
488 double alpha, Intrepid2::ordinal_type n, ScalarType x, ScalarTypeForScaling t)
492 shiftedScaledJacobiValues(outputValues, alpha, n-1, x, t);
495 ScalarType nextValue = 0.0;
496 ScalarType nextNextValue = 0.0;
497 for (
int i=0; i<=n-1; i++)
499 nextNextValue = outputValues(i);
500 outputValues(i) = nextValue;
501 nextValue = nextNextValue;
503 outputValues(n-1) = nextValue;
516 template<
typename OutputValueViewType,
typename ScalarType,
typename ScalarTypeForScaling>
517 KOKKOS_INLINE_FUNCTION
void shiftedScaledIntegratedJacobiValues_dt(OutputValueViewType outputValues,
const OutputValueViewType jacobiValues,
518 double alpha, Intrepid2::ordinal_type n, ScalarType x, ScalarTypeForScaling t)
521 if (n >= 0) outputValues(0) = 0.0;
522 if (n >= 1) outputValues(1) = 0.0;
523 for (
int i=2; i<=n; i++)
525 const ScalarType & P_i_minus_1 = jacobiValues(i-1);
526 const ScalarType & P_i_minus_2 = jacobiValues(i-2);
527 outputValues(i) = - (i-1.) / (2. * i - 2. + alpha) * (P_i_minus_1 + t * P_i_minus_2);
541 template<
typename OutputValueViewType,
typename ScalarType,
typename ScalarTypeForScaling>
542 KOKKOS_INLINE_FUNCTION
void shiftedScaledIntegratedJacobiValues_dt(OutputValueViewType outputValues,
543 double alpha, Intrepid2::ordinal_type n, ScalarType x, ScalarTypeForScaling t)
546 shiftedScaledJacobiValues(outputValues, alpha, n, x, t);
548 ScalarType P_i_minus_2 = outputValues(0);
549 ScalarType P_i_minus_1 = outputValues(1);
551 if (n >= 0) outputValues(0) = 0.0;
552 if (n >= 1) outputValues(1) = 0.0;
554 for (
int i=2; i<=n; i++)
556 const ScalarType L_i_dt = - (i-1.) / (2. * i - 2. + alpha) * (P_i_minus_1 + t * P_i_minus_2);
558 P_i_minus_2 = P_i_minus_1;
559 P_i_minus_1 = outputValues(i);
561 outputValues(i) = L_i_dt;
Header file for Intrepid2::Polylib class providing orthogonal polynomial calculus and interpolation...
Header function for Intrepid2::Util class and other utility functions.
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, .
Contains definitions of custom data types in Intrepid2.