Skip to content

Commit a835aab

Browse files
committed
at-points: change at-points operators to use Chebyshev polynomials of the first kind (normalized)
1 parent bc0cf4a commit a835aab

6 files changed

Lines changed: 41 additions & 33 deletions

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Specifically, directories set with `CeedAddJitSourceRoot(ceed, "foo/bar")` will
3030
- Added support to code generation backends `/gpu/cuda/gen` and `/gpu/hip/gen` for operators with both tensor and non-tensor bases.
3131
- Add `CeedGetGitVersion()` to access the Git commit and dirty state of the repository at build time.
3232
- Add `CeedGetBuildConfiguration()` to access compilers, flags, and related information about the build environment.
33-
- Add support for full `CeedOperator` assembly for operators with multiple active fields with different bases for CPU backends and `/gpu/cuda/ref` and `/gpu/hip/gen` backends.
33+
- Add support for full `CeedOperator` assembly for operators with multiple active fields with different bases for CPU backends and `/gpu/cuda/ref` and `/gpu/hip/gen` backends.
3434

3535
### Examples
3636

include/ceed/jit-source/cuda/cuda-ref-basis-tensor-at-points.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,22 @@
1515
template <int Q_1D>
1616
inline __device__ void ChebyshevPolynomialsAtPoint(const CeedScalar x, CeedScalar *chebyshev_x) {
1717
chebyshev_x[0] = 1.0;
18-
chebyshev_x[1] = 2 * x;
18+
chebyshev_x[1] = x;
1919
for (CeedInt i = 2; i < Q_1D; i++) chebyshev_x[i] = 2 * x * chebyshev_x[i - 1] - chebyshev_x[i - 2];
2020
}
2121

2222
template <int Q_1D>
2323
inline __device__ void ChebyshevDerivativeAtPoint(const CeedScalar x, CeedScalar *chebyshev_dx) {
24-
CeedScalar chebyshev_x[3];
24+
CeedScalar chebyshev_x[2];
2525

26-
chebyshev_x[1] = 1.0;
27-
chebyshev_x[2] = 2 * x;
26+
chebyshev_x[0] = 1.0;
27+
chebyshev_x[1] = 2 * x;
2828
chebyshev_dx[0] = 0.0;
29-
chebyshev_dx[1] = 2.0;
29+
chebyshev_dx[1] = 1.0;
3030
for (CeedInt i = 2; i < Q_1D; i++) {
31-
chebyshev_x[(i + 1) % 3] = 2 * x * chebyshev_x[(i + 0) % 3] - chebyshev_x[(i + 2) % 3];
32-
chebyshev_dx[i] = 2 * x * chebyshev_dx[i - 1] + 2 * chebyshev_x[(i + 0) % 3] - chebyshev_dx[i - 2];
31+
// dT_i/dx = i * dU_{i-1}/dx
32+
chebyshev_dx[i] = i * chebyshev_x[(i + 1) % 2];
33+
chebyshev_x[i % 2] = 2 * x * chebyshev_x[(i + 1) % 2] - chebyshev_x[i % 2];
3334
}
3435
}
3536

include/ceed/jit-source/cuda/cuda-shared-basis-tensor-at-points-templates.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,22 @@
1515
template <int Q_1D>
1616
inline __device__ void ChebyshevPolynomialsAtPoint(const CeedScalar x, CeedScalar *chebyshev_x) {
1717
chebyshev_x[0] = 1.0;
18-
chebyshev_x[1] = 2 * x;
18+
chebyshev_x[1] = x;
1919
for (CeedInt i = 2; i < Q_1D; i++) chebyshev_x[i] = 2 * x * chebyshev_x[i - 1] - chebyshev_x[i - 2];
2020
}
2121

2222
template <int Q_1D>
2323
inline __device__ void ChebyshevDerivativeAtPoint(const CeedScalar x, CeedScalar *chebyshev_dx) {
24-
CeedScalar chebyshev_x[3];
24+
CeedScalar chebyshev_x[2];
2525

26-
chebyshev_x[1] = 1.0;
27-
chebyshev_x[2] = 2 * x;
26+
chebyshev_x[0] = 1.0;
27+
chebyshev_x[1] = 2 * x;
2828
chebyshev_dx[0] = 0.0;
29-
chebyshev_dx[1] = 2.0;
29+
chebyshev_dx[1] = 1.0;
3030
for (CeedInt i = 2; i < Q_1D; i++) {
31-
chebyshev_x[(i + 1) % 3] = 2 * x * chebyshev_x[(i + 0) % 3] - chebyshev_x[(i + 2) % 3];
32-
chebyshev_dx[i] = 2 * x * chebyshev_dx[i - 1] + 2 * chebyshev_x[(i + 0) % 3] - chebyshev_dx[i - 2];
31+
// dT_i/dx = i * dU_{i-1}/dx
32+
chebyshev_dx[i] = i * chebyshev_x[(i + 1) % 2];
33+
chebyshev_x[i % 2] = 2 * x * chebyshev_x[(i + 1) % 2] - chebyshev_x[i % 2];
3334
}
3435
}
3536

include/ceed/jit-source/hip/hip-ref-basis-tensor-at-points.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,22 @@
1515
template <int Q_1D>
1616
inline __device__ void ChebyshevPolynomialsAtPoint(const CeedScalar x, CeedScalar *chebyshev_x) {
1717
chebyshev_x[0] = 1.0;
18-
chebyshev_x[1] = 2 * x;
18+
chebyshev_x[1] = x;
1919
for (CeedInt i = 2; i < Q_1D; i++) chebyshev_x[i] = 2 * x * chebyshev_x[i - 1] - chebyshev_x[i - 2];
2020
}
2121

2222
template <int Q_1D>
2323
inline __device__ void ChebyshevDerivativeAtPoint(const CeedScalar x, CeedScalar *chebyshev_dx) {
24-
CeedScalar chebyshev_x[3];
24+
CeedScalar chebyshev_x[2];
2525

26-
chebyshev_x[1] = 1.0;
27-
chebyshev_x[2] = 2 * x;
26+
chebyshev_x[0] = 1.0;
27+
chebyshev_x[1] = 2 * x;
2828
chebyshev_dx[0] = 0.0;
29-
chebyshev_dx[1] = 2.0;
29+
chebyshev_dx[1] = 1.0;
3030
for (CeedInt i = 2; i < Q_1D; i++) {
31-
chebyshev_x[(i + 1) % 3] = 2 * x * chebyshev_x[(i + 0) % 3] - chebyshev_x[(i + 2) % 3];
32-
chebyshev_dx[i] = 2 * x * chebyshev_dx[i - 1] + 2 * chebyshev_x[(i + 0) % 3] - chebyshev_dx[i - 2];
31+
// dT_i/dx = i * dU_{i-1}/dx
32+
chebyshev_dx[i] = i * chebyshev_x[(i + 1) % 2];
33+
chebyshev_x[i % 2] = 2 * x * chebyshev_x[(i + 1) % 2] - chebyshev_x[i % 2];
3334
}
3435
}
3536

include/ceed/jit-source/hip/hip-shared-basis-tensor-at-points-templates.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,22 @@
1515
template <int Q_1D>
1616
inline __device__ void ChebyshevPolynomialsAtPoint(const CeedScalar x, CeedScalar *chebyshev_x) {
1717
chebyshev_x[0] = 1.0;
18-
chebyshev_x[1] = 2 * x;
18+
chebyshev_x[1] = x;
1919
for (CeedInt i = 2; i < Q_1D; i++) chebyshev_x[i] = 2 * x * chebyshev_x[i - 1] - chebyshev_x[i - 2];
2020
}
2121

2222
template <int Q_1D>
2323
inline __device__ void ChebyshevDerivativeAtPoint(const CeedScalar x, CeedScalar *chebyshev_dx) {
24-
CeedScalar chebyshev_x[3];
24+
CeedScalar chebyshev_x[2];
2525

26-
chebyshev_x[1] = 1.0;
27-
chebyshev_x[2] = 2 * x;
26+
chebyshev_x[0] = 1.0;
27+
chebyshev_x[1] = 2 * x;
2828
chebyshev_dx[0] = 0.0;
29-
chebyshev_dx[1] = 2.0;
29+
chebyshev_dx[1] = 1.0;
3030
for (CeedInt i = 2; i < Q_1D; i++) {
31-
chebyshev_x[(i + 1) % 3] = 2 * x * chebyshev_x[(i + 0) % 3] - chebyshev_x[(i + 2) % 3];
32-
chebyshev_dx[i] = 2 * x * chebyshev_dx[i - 1] + 2 * chebyshev_x[(i + 0) % 3] - chebyshev_dx[i - 2];
31+
// dT_i/dx = i * dU_{i-1}/dx
32+
chebyshev_dx[i] = i * chebyshev_x[(i + 1) % 2];
33+
chebyshev_x[i % 2] = 2 * x * chebyshev_x[(i + 1) % 2] - chebyshev_x[i % 2];
3334
}
3435
}
3536

interface/ceed-basis.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ const CeedBasis CEED_BASIS_NONE = &ceed_basis_none;
4646
@ref Developer
4747
**/
4848
static int CeedChebyshevPolynomialsAtPoint(CeedScalar x, CeedInt n, CeedScalar *chebyshev_x) {
49+
// Chebyshev polynomials of the first kind, 3 term recurrence: T_0(x) = 1, T_1(x) = x, T_n = 2 x T_{n-1} - T_{n-2}
50+
// For more info, see e.g. https://en.wikipedia.org/wiki/Chebyshev_polynomials#Recurrence_definition
4951
chebyshev_x[0] = 1.0;
50-
chebyshev_x[1] = 2 * x;
52+
chebyshev_x[1] = x;
5153
for (CeedInt i = 2; i < n; i++) chebyshev_x[i] = 2 * x * chebyshev_x[i - 1] - chebyshev_x[i - 2];
5254
return CEED_ERROR_SUCCESS;
5355
}
@@ -64,17 +66,20 @@ static int CeedChebyshevPolynomialsAtPoint(CeedScalar x, CeedInt n, CeedScalar *
6466
@ref Developer
6567
**/
6668
static int CeedChebyshevDerivativeAtPoint(CeedScalar x, CeedInt n, CeedScalar *chebyshev_dx) {
69+
// Note, these are Chebyshev polynomials of the 2nd kind, used for derivatives
70+
// See e.g. https://en.wikipedia.org/wiki/Chebyshev_polynomials#Differentiation_and_integration for the recurrence
6771
CeedScalar chebyshev_x[3];
6872

6973
chebyshev_x[1] = 1.0;
7074
chebyshev_x[2] = 2 * x;
7175
chebyshev_dx[0] = 0.0;
72-
chebyshev_dx[1] = 2.0;
76+
chebyshev_dx[1] = 1.0;
7377
for (CeedInt i = 2; i < n; i++) {
78+
// dT_i/dx = i * dU_{i-1}/dx
7479
chebyshev_x[0] = chebyshev_x[1];
7580
chebyshev_x[1] = chebyshev_x[2];
81+
chebyshev_dx[i] = i * chebyshev_x[1];
7682
chebyshev_x[2] = 2 * x * chebyshev_x[1] - chebyshev_x[0];
77-
chebyshev_dx[i] = 2 * x * chebyshev_dx[i - 1] + 2 * chebyshev_x[1] - chebyshev_dx[i - 2];
7883
}
7984
return CEED_ERROR_SUCCESS;
8085
}
@@ -607,7 +612,6 @@ static int CeedBasisApplyAtPoints_Core(CeedBasis basis, bool apply_add, CeedInt
607612
break;
608613
}
609614
case CEED_TRANSPOSE: {
610-
// Note: No switch on e_mode here because only CEED_EVAL_INTERP is supported at this time
611615
// Arbitrary points to nodes
612616
CeedScalar *chebyshev_coeffs;
613617
const CeedScalar *u_array, *x_array_read;

0 commit comments

Comments
 (0)