11 #ifndef OOPS_ASSIMILATION_TRIDIAGSOLVE_H_ 12 #define OOPS_ASSIMILATION_TRIDIAGSOLVE_H_ 18 void TriDiagSolve(
const std::vector<double> & diag,
const std::vector<double> & sub,
19 const std::vector<double> & rhs, std::vector<double> & sol) {
20 const double n = rhs.size();
21 ASSERT(sub.size() ==
n-1);
22 ASSERT(diag.size() ==
n);
24 std::vector<double>
c(sub);
25 std::vector<double>
d(rhs);
28 c[0] =
c[0] / diag[0];
29 d[0] =
d[0] / diag[0];
31 for (
int iiter = 1; iiter <=
n-2; ++iiter) {
32 double denom = diag[iiter]-sub[iiter-1]*
c[iiter-1];
33 c[iiter] =
c[iiter]/denom;
34 d[iiter] = (
d[iiter]-sub[iiter-1]*
d[iiter-1])/denom;
37 d[
n-1] = (
d[
n-1]-sub[
n-2]*
d[
n-2])/(diag[
n-1]-sub[
n-2]*
c[
n-2]);
40 for (
int iiter =
n-2; iiter >= 0; --iiter) {
41 sol[iiter] = (
d[iiter]-(
c[iiter]*sol[iiter+1]));
47 #endif // OOPS_ASSIMILATION_TRIDIAGSOLVE_H_
void TriDiagSolve(const std::vector< double > &diag, const std::vector< double > &sub, const std::vector< double > &rhs, std::vector< double > &sol)
The namespace for the main oops code.