Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solve_cg: consistent RT casting #3638

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions Src/LinearSolvers/MLMG/AMReX_MLCGSolver.H
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,11 @@ MLCGSolverT<MF>::solve_cg (MF& sol, const MF& rhs, RT eps_rel, RT eps_abs)
amrex::Print() << "MLCGSolver_CG: Initial error (error0) : " << rnorm0 << '\n';
}

RT rho_1 = 0;
RT rho_1 = RT(0.0);
int ret = 0;
iter = 1;

if ( rnorm0 == 0 || rnorm0 < eps_abs )
if ( rnorm0 == RT(0.0) || rnorm0 < eps_abs )
{
if ( verbose > 0 ) {
amrex::Print() << "MLCGSolver_CG: niter = 0,"
Expand All @@ -294,9 +294,9 @@ MLCGSolverT<MF>::solve_cg (MF& sol, const MF& rhs, RT eps_rel, RT eps_abs)

for (; iter <= maxiter; ++iter)
{
RT rho = dotxy(r,r);
const RT rho = dotxy(r,r);

if ( rho == 0 )
if ( rho == RT(0.0) )
{
ret = 1; break;
}
Expand All @@ -306,21 +306,17 @@ MLCGSolverT<MF>::solve_cg (MF& sol, const MF& rhs, RT eps_rel, RT eps_abs)
}
else
{
RT beta = rho/rho_1;
const RT beta = rho/rho_1;
MF::Xpay(p, beta, r, 0, 0, ncomp, nghost); // p = r + beta * p
}
Lp.apply(amrlev, mglev, q, p, MLLinOpT<MF>::BCMode::Homogeneous, MLLinOpT<MF>::StateMode::Correction);

RT alpha;
RT pw = dotxy(p,q);
if ( pw != RT(0.0))
{
alpha = rho/pw;
}
else
const RT pw = dotxy(p,q);
if ( pw == RT(0.0) )
{
ret = 1; break;
}
const RT alpha = rho/pw;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This restructuring of the divide by zero check allows alpha to be defined and declared in one line as a const RT instead of the current RT declaration.


if ( verbose > 2 )
{
Expand Down