ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_SolveTridiag.H
Go to the documentation of this file.
1 #ifndef ERF_SOLVE_TRIDIAG
2 #define ERF_SOLVE_TRIDIAG
3 
4 AMREX_GPU_HOST_DEVICE
5 AMREX_FORCE_INLINE
6 void SolveTridiag (int i, int j, int klo, int khi,
7  const amrex::Array4< amrex::Real>& soln_a,
8  const amrex::Array4<const amrex::Real>& coeffA_a, // lower diagonal
9  const amrex::Array4< amrex::Real>& coeffB_a, // main diagonal
10  const amrex::Array4< amrex::Real>& inv_coeffB_a,
11  const amrex::Array4<const amrex::Real>& coeffC_a, // upper diagonal
12  const amrex::Array4<const amrex::Real>& RHS_a)
13 {
14  // Forward sweep
15 
16  amrex::Real bet = coeffB_a(i,j,klo);
17 
18  for (int k(klo+1); k<=khi; ++k) {
19  amrex::Real gam = coeffC_a(i,j,k-1) / bet;
20  bet = coeffB_a(i,j,k) - coeffA_a(i,j,k)*gam;
21  AMREX_ASSERT(bet != 0.0);
22  coeffB_a(i,j,k) = bet;
23  }
24 
25  for (int k(klo); k<=khi; ++k) {
26  inv_coeffB_a(i,j,k) = 1.0 / coeffB_a(i,j,k);
27  }
28 
29  //
30  // Tridiagonal solve
31  //
32  soln_a(i,j,klo) = RHS_a(i,j,klo) * inv_coeffB_a(i,j,klo);
33 
34  for (int k(klo+1); k<=khi; ++k) {
35  soln_a(i,j,k) = (RHS_a(i,j,k)-coeffA_a(i,j,k)*soln_a(i,j,k-1)) * inv_coeffB_a(i,j,k);
36  }
37 
38  for (int k(khi-1); k>=klo; --k) {
39  soln_a(i,j,k) -= ( coeffC_a(i,j,k) * inv_coeffB_a(i,j,k) ) * soln_a(i,j,k+1);
40  }
41 }
42 #endif
amrex::Real Real
Definition: ERF_ShocInterface.H:19
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void SolveTridiag(int i, int j, int klo, int khi, const amrex::Array4< amrex::Real > &soln_a, const amrex::Array4< const amrex::Real > &coeffA_a, const amrex::Array4< amrex::Real > &coeffB_a, const amrex::Array4< amrex::Real > &inv_coeffB_a, const amrex::Array4< const amrex::Real > &coeffC_a, const amrex::Array4< const amrex::Real > &RHS_a)
Definition: ERF_SolveTridiag.H:6