Go to the documentation of this file.
50 template <
class real,
unsigned int n>
51 YAKL_INLINE void tridiagonal_periodic(
SArray<real,1,n> const &a,
SArray<real,1,n> &b,
SArray<real,1,n> &c,
SArray<real,1,n> &d) {
61 b(n-1) = b(n-1) + a(0)*c(n-1)/b(0);
65 real div =
static_cast<real
>(1) / b(0);
69 for (
int i = 1; i < n-1; i++) {
70 div =
static_cast<real
>(1) / (b(i) - a(i)*c(i-1));
72 d (i) = (d(i) - a(i)*d (i-1)) * div;
73 tmp(i) = ( - a(i)*tmp(i-1)) * div;
75 div =
static_cast<real
>(1) / (b(n-1) - a(n-1)*c(n-2));
76 d (n-1) = (d (n-1) - a(n-1)*d (n-2)) * div;
77 tmp(n-1) = (tmp(n-1) - a(n-1)*tmp(n-2)) * div;
78 for (
int i = n-2; i >= 0; i--) {
79 d (i) -= c(i)*d (i+1);
80 tmp(i) -= c(i)*tmp(i+1);
85 if ( (tmp(0) - a(0)*tmp(n-1)/b0 +
static_cast<real
>(1)) == 0 ) {
88 factor = (d(0) - a(0)*d(n-1)/b0)/(tmp(0) - a(0)*tmp(n-1)/b0 +
static_cast<real
>(1));
92 for (
int i = 0; i < n; i++) {
93 d(i) -= factor*tmp(i);
118 template <
class real,
unsigned int n>
119 YAKL_INLINE void tridiagonal(
SArray<real,1,n> const &a,
SArray<real,1,n> const &b,
SArray<real,1,n> &c,
SArray<real,1,n> &d) {
120 real tmp =
static_cast<real
>(1) / b(0);
123 for (
int i = 1; i < n-1; i++) {
124 real tmp =
static_cast<real
>(1) / (b(i) - a(i)*c(i-1));
126 d(i) = (d(i) - a(i)*d(i-1)) * tmp;
128 d(n-1) = (d(n-1) - a(n-1)*d(n-2)) / (b(n-1) - a(n-1)*c(n-2));
129 for (
int i = n-2; i >= 0; i--) {
#define __YAKL_NAMESPACE_WRAPPER_END__
Definition: YAKL.h:20
#define __YAKL_NAMESPACE_WRAPPER_BEGIN__
Definition: YAKL.h:19
#define YAKL_INLINE
Used to decorate functions called from kernels (parallel_for and parallel_outer) or from CPU function...
Definition: YAKL_defines.h:140
YAKL_INLINE void tridiagonal_periodic(SArray< real, 1, n > const &a, SArray< real, 1, n > &b, SArray< real, 1, n > &c, SArray< real, 1, n > &d)
Performs a small periodic tridiagional solve. Click for more details.
Definition: YAKL_tridiagonal.h:51
C-style array on the stack similar in nature to, e.g., float arr[ny][nx];
Definition: YAKL_CSArray.h:30
YAKL_INLINE void tridiagonal(SArray< real, 1, n > const &a, SArray< real, 1, n > const &b, SArray< real, 1, n > &c, SArray< real, 1, n > &d)
Solves a small non-periodic tridiagional system.
Definition: YAKL_tridiagonal.h:119