15 #ifndef Intrepid2_Polynomials_h
16 #define Intrepid2_Polynomials_h
54 template<
typename OutputValueViewType,
typename ScalarType>
55 KOKKOS_INLINE_FUNCTION
void legendreValues(OutputValueViewType outputValues, Intrepid2::ordinal_type n, ScalarType x)
57 if (n >= 0) outputValues(0) = 1.0;
58 if (n >= 1) outputValues(1) = x;
59 for (
int i=2; i<=n; i++)
61 const ScalarType i_scalar = ScalarType(i);
62 outputValues(i) = (2. - 1. / i_scalar) * x * outputValues(i-1) - (1. - 1. / i_scalar) * outputValues(i-2);
73 template<
typename OutputValueViewType,
typename ScalarType>
74 KOKKOS_INLINE_FUNCTION
void legendreDerivativeValues(OutputValueViewType outputValues,
const OutputValueViewType legendreValues, Intrepid2::ordinal_type n, ScalarType x)
76 if (n >= 0) outputValues(0) = 0.0;
77 if (n >= 1) outputValues(1) = 1.0;
78 for (
int i=2; i<=n; i++)
80 const ScalarType i_scalar = ScalarType(i);
81 outputValues(i) = outputValues(i-2) + (2. * i_scalar - 1.) * legendreValues(i-1);
96 template<
typename OutputValueViewType,
typename Po
intScalarType>
97 KOKKOS_INLINE_FUNCTION
void legendreDerivativeValues(OutputValueViewType outputValues, Intrepid2::ordinal_type n, PointScalarType x, Intrepid2::ordinal_type dn)
99 const OutputValueViewType nullOutputScalarView;
100 const double alpha = 0;
101 const double beta = 0;
102 const int numPoints = 1;
104 using Layout =
typename NaturalLayoutForType<PointScalarType>::layout;
106 using UnmanagedPointScalarView = Kokkos::View<PointScalarType*, Layout, Kokkos::MemoryTraits<Kokkos::Unmanaged> >;
107 UnmanagedPointScalarView pointView = UnmanagedPointScalarView(&x,numPoints);
109 for (
int i=0; i<=n; i++)
111 auto jacobiValue = Kokkos::subview(outputValues,Kokkos::pair<Intrepid2::ordinal_type,Intrepid2::ordinal_type>(i,i+1));
112 jacobiValue(0) = 0.0;
115 double scaleFactor = 1.0;
116 for (
int j=1; j<=dn; j++)
118 scaleFactor *= 0.5 * (j+alpha+beta+i);
121 outputValues(i) = jacobiValue(0) * scaleFactor;
134 template<
typename OutputValueViewType,
typename ScalarType>
135 KOKKOS_INLINE_FUNCTION
void shiftedLegendreValues(OutputValueViewType outputValues, Intrepid2::ordinal_type n, ScalarType x)
137 legendreValues(outputValues, n, 2.*x-1.);
150 template<
typename OutputValueViewType,
typename ScalarType,
typename ScalarTypeForScaling>
151 KOKKOS_INLINE_FUNCTION
void shiftedScaledLegendreValues(OutputValueViewType outputValues, Intrepid2::ordinal_type n, ScalarType x, ScalarTypeForScaling t)
153 using OutputScalar =
typename OutputValueViewType::value_type;
154 OutputScalar two_x_minus_t = 2. * x - t;
155 OutputScalar t_squared = t * t;
156 if (n >= 0) outputValues(0) = 1.0;
157 if (n >= 1) outputValues(1) = two_x_minus_t;
158 for (
int i=2; i<=n; i++)
160 const ScalarType one_over_i = 1.0 / ScalarType(i);
161 outputValues(i) = one_over_i * ( (2. *i - 1. ) * two_x_minus_t * outputValues(i-1) - (i - 1.) * t_squared * outputValues(i-2));
178 template<
typename OutputValueViewType,
typename ScalarType,
typename ScalarTypeForScaling>
179 KOKKOS_INLINE_FUNCTION
void shiftedScaledIntegratedLegendreValues(OutputValueViewType outputValues, Intrepid2::ordinal_type n, ScalarType x, ScalarTypeForScaling t)
182 shiftedScaledLegendreValues(outputValues,n,x,t);
184 ScalarType P_i_minus_two, P_i_minus_one;
185 if (n >= 0) P_i_minus_two = outputValues(0);
186 if (n >= 1) P_i_minus_one = outputValues(1);
188 if (n >= 0) outputValues(0) = 1.0;
189 if (n >= 1) outputValues(1) = x;
190 for (
int i=2; i<=n; i++)
192 const ScalarType & P_i = outputValues(i);
193 const ScalarType i_scalar = ScalarType(i);
194 ScalarType L_i = (P_i - t * t * P_i_minus_two) /( 2. * (2. * i_scalar - 1.));
197 P_i_minus_two = P_i_minus_one;
201 outputValues(i) = L_i;
219 template<
typename OutputValueViewType,
typename ScalarType,
typename ScalarTypeForScaling>
220 KOKKOS_INLINE_FUNCTION
void shiftedScaledIntegratedLegendreValues(OutputValueViewType outputValues,
const OutputValueViewType shiftedScaledLegendreValues,
221 Intrepid2::ordinal_type n, ScalarType x, ScalarTypeForScaling t)
224 if (n >= 0) outputValues(0) = 1.0;
225 if (n >= 1) outputValues(1) = x;
226 for (
int i=2; i<=n; i++)
228 const ScalarType & P_i = shiftedScaledLegendreValues(i);
229 const ScalarType & P_i_minus_two = shiftedScaledLegendreValues(i-2);
230 const ScalarType i_scalar = ScalarType(i);
231 outputValues(i) = (P_i - t * t * P_i_minus_two) /( 2. * (2. * i_scalar - 1.));
273 template<
typename OutputValueViewType,
typename ScalarType,
typename ScalarTypeForScaling>
274 KOKKOS_INLINE_FUNCTION
void shiftedScaledIntegratedLegendreValues_dx(OutputValueViewType outputValues, Intrepid2::ordinal_type n, ScalarType x, ScalarTypeForScaling t)
276 if (n >= 0) outputValues(0) = 0.0;
277 if (n >= 1) outputValues(1) = 1.0;
278 if (n >= 2) outputValues(2) = 2. * x - t;
279 for (
int i=2; i<=n-1; i++)
281 const ScalarType one_over_i = 1.0 / ScalarType(i);
282 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);
295 template<
typename OutputValueViewType,
typename ScalarType,
typename ScalarTypeForScaling>
296 KOKKOS_INLINE_FUNCTION
void shiftedScaledIntegratedLegendreValues_dt(OutputValueViewType outputValues, Intrepid2::ordinal_type n, ScalarType x, ScalarTypeForScaling t)
299 shiftedScaledLegendreValues(outputValues, n, x, t);
301 ScalarType P_i_minus_2 = outputValues(0);
302 ScalarType P_i_minus_1 = outputValues(1);
304 if (n >= 0) outputValues(0) = 0.0;
305 if (n >= 1) outputValues(1) = 0.0;
307 for (
int i=2; i<=n; i++)
309 const ScalarType L_i_dt = -0.5 * (P_i_minus_1 + t * P_i_minus_2);
311 P_i_minus_2 = P_i_minus_1;
312 P_i_minus_1 = outputValues(i);
314 outputValues(i) = L_i_dt;
328 template<
typename OutputValueViewType,
typename ScalarType,
typename ScalarTypeForScaling>
329 KOKKOS_INLINE_FUNCTION
void shiftedScaledIntegratedLegendreValues_dt(OutputValueViewType outputValues,
const OutputValueViewType shiftedScaledLegendreValues,
330 Intrepid2::ordinal_type n, ScalarType x, ScalarTypeForScaling t)
333 if (n >= 0) outputValues(0) = 0.0;
334 if (n >= 1) outputValues(1) = 0.0;
335 for (
int i=2; i<=n; i++)
337 const ScalarType & P_i_minus_1 = shiftedScaledLegendreValues(i-1);
338 const ScalarType & P_i_minus_2 = shiftedScaledLegendreValues(i-2);
339 outputValues(i) = -0.5 * (P_i_minus_1 + t * P_i_minus_2);
357 template<
typename OutputValueViewType,
typename ScalarType,
typename ScalarTypeForScaling>
358 KOKKOS_INLINE_FUNCTION
void shiftedScaledJacobiValues(OutputValueViewType outputValues,
double alpha, Intrepid2::ordinal_type n, ScalarType x, ScalarTypeForScaling t)
360 ScalarType two_x_minus_t = 2. * x - t;
361 ScalarTypeForScaling alpha_squared_t = alpha * alpha * t;
363 if (n >= 0) outputValues(0) = 1.0;
364 if (n >= 1) outputValues(1) = two_x_minus_t + alpha * x;
366 for (
int i=2; i<=n; i++)
368 const ScalarType & P_i_minus_one = outputValues(i-1);
369 const ScalarType & P_i_minus_two = outputValues(i-2);
371 double a_i = (2. * i) * (i + alpha) * (2. * i + alpha - 2.);
372 double b_i = 2. * i + alpha - 1.;
373 double c_i = (2. * i + alpha) * (2. * i + alpha - 2.);
374 double d_i = 2. * (i + alpha - 1.) * (i - 1.) * (2. * i + alpha);
376 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;
397 template<
typename OutputValueViewType,
typename ScalarType,
typename ScalarTypeForScaling>
398 KOKKOS_INLINE_FUNCTION
void shiftedScaledIntegratedJacobiValues(OutputValueViewType outputValues,
const OutputValueViewType jacobiValues,
399 double alpha, Intrepid2::ordinal_type n, ScalarType x, ScalarTypeForScaling t)
402 if (n >= 0) outputValues(0) = 1.0;
403 if (n >= 1) outputValues(1) = x;
405 ScalarType t_squared = t * t;
406 for (
int i=2; i<=n; i++)
408 const ScalarType & P_i = jacobiValues(i);
409 const ScalarType & P_i_minus_1 = jacobiValues(i-1);
410 const ScalarType & P_i_minus_2 = jacobiValues(i-2);
412 double a_i = (i + alpha) / ((2. * i + alpha - 1.) * (2. * i + alpha ));
413 double b_i = alpha / ((2. * i + alpha - 2.) * (2. * i + alpha ));
414 double c_i = (i - 1.) / ((2. * i + alpha - 2.) * (2. * i + alpha - 1.));
416 outputValues(i) = a_i * P_i + b_i * t * P_i_minus_1 - c_i * t_squared * P_i_minus_2;
437 template<
typename OutputValueViewType,
typename ScalarType,
typename ScalarTypeForScaling>
438 KOKKOS_INLINE_FUNCTION
void shiftedScaledIntegratedJacobiValues(OutputValueViewType outputValues,
439 double alpha, Intrepid2::ordinal_type n, ScalarType x, ScalarTypeForScaling t)
442 shiftedScaledJacobiValues(outputValues, alpha, n, x, t);
444 ScalarType P_i_minus_2 = outputValues(0);
445 ScalarType P_i_minus_1 = outputValues(1);
447 if (n >= 0) outputValues(0) = 1.0;
448 if (n >= 1) outputValues(1) = x;
450 ScalarType t_squared = t * t;
451 for (
int i=2; i<=n; i++)
453 const ScalarType & P_i = outputValues(i);
455 double a_i = (i + alpha) / ((2. * i + alpha - 1.) * (2. * i + alpha ));
456 double b_i = alpha / ((2. * i + alpha - 2.) * (2. * i + alpha ));
457 double c_i = (i - 1.) / ((2. * i + alpha - 2.) * (2. * i + alpha - 1.));
459 ScalarType L_i = a_i * P_i + b_i * t * P_i_minus_1 - c_i * t_squared * P_i_minus_2;
461 P_i_minus_2 = P_i_minus_1;
464 outputValues(i) = L_i;
477 template<
typename OutputValueViewType,
typename ScalarType,
typename ScalarTypeForScaling>
478 KOKKOS_INLINE_FUNCTION
void shiftedScaledIntegratedJacobiValues_dx(OutputValueViewType outputValues,
479 double alpha, Intrepid2::ordinal_type n, ScalarType x, ScalarTypeForScaling t)
483 shiftedScaledJacobiValues(outputValues, alpha, n-1, x, t);
486 ScalarType nextValue = 0.0;
487 ScalarType nextNextValue = 0.0;
488 for (
int i=0; i<=n-1; i++)
490 nextNextValue = outputValues(i);
491 outputValues(i) = nextValue;
492 nextValue = nextNextValue;
494 outputValues(n-1) = nextValue;
507 template<
typename OutputValueViewType,
typename ScalarType,
typename ScalarTypeForScaling>
508 KOKKOS_INLINE_FUNCTION
void shiftedScaledIntegratedJacobiValues_dt(OutputValueViewType outputValues,
const OutputValueViewType jacobiValues,
509 double alpha, Intrepid2::ordinal_type n, ScalarType x, ScalarTypeForScaling t)
512 if (n >= 0) outputValues(0) = 0.0;
513 if (n >= 1) outputValues(1) = 0.0;
514 for (
int i=2; i<=n; i++)
516 const ScalarType & P_i_minus_1 = jacobiValues(i-1);
517 const ScalarType & P_i_minus_2 = jacobiValues(i-2);
518 outputValues(i) = - (i-1.) / (2. * i - 2. + alpha) * (P_i_minus_1 + t * P_i_minus_2);
532 template<
typename OutputValueViewType,
typename ScalarType,
typename ScalarTypeForScaling>
533 KOKKOS_INLINE_FUNCTION
void shiftedScaledIntegratedJacobiValues_dt(OutputValueViewType outputValues,
534 double alpha, Intrepid2::ordinal_type n, ScalarType x, ScalarTypeForScaling t)
537 shiftedScaledJacobiValues(outputValues, alpha, n, x, t);
539 ScalarType P_i_minus_2 = outputValues(0);
540 ScalarType P_i_minus_1 = outputValues(1);
542 if (n >= 0) outputValues(0) = 0.0;
543 if (n >= 1) outputValues(1) = 0.0;
545 for (
int i=2; i<=n; i++)
547 const ScalarType L_i_dt = - (i-1.) / (2. * i - 2. + alpha) * (P_i_minus_1 + t * P_i_minus_2);
549 P_i_minus_2 = P_i_minus_1;
550 P_i_minus_1 = outputValues(i);
552 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.