mirror of
https://github.com/paboyle/Grid.git
synced 2025-04-09 21:50:45 +01:00
Added option to prevent CG from exiting when it fails to converge
This commit is contained in:
parent
61ba50665e
commit
15f22425c8
@ -40,9 +40,10 @@ namespace Grid {
|
|||||||
template<class Field>
|
template<class Field>
|
||||||
class ConjugateGradient : public OperatorFunction<Field> {
|
class ConjugateGradient : public OperatorFunction<Field> {
|
||||||
public:
|
public:
|
||||||
|
bool ErrorOnNoConverge; //throw an assert when the CG fails to converge. Defaults true.
|
||||||
RealD Tolerance;
|
RealD Tolerance;
|
||||||
Integer MaxIterations;
|
Integer MaxIterations;
|
||||||
ConjugateGradient(RealD tol,Integer maxit) : Tolerance(tol), MaxIterations(maxit) {
|
ConjugateGradient(RealD tol,Integer maxit, bool err_on_no_conv = true) : Tolerance(tol), MaxIterations(maxit), ErrorOnNoConverge(err_on_no_conv){
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -137,13 +138,15 @@ public:
|
|||||||
std::cout<<GridLogMessage<<"Time elapsed: Total "<< SolverTimer.Elapsed() << " Matrix "<<MatrixTimer.Elapsed() << " Linalg "<<LinalgTimer.Elapsed();
|
std::cout<<GridLogMessage<<"Time elapsed: Total "<< SolverTimer.Elapsed() << " Matrix "<<MatrixTimer.Elapsed() << " Linalg "<<LinalgTimer.Elapsed();
|
||||||
std::cout<<std::endl;
|
std::cout<<std::endl;
|
||||||
|
|
||||||
assert(true_residual/Tolerance < 1000.0);
|
if(ErrorOnNoConverge)
|
||||||
|
assert(true_residual/Tolerance < 1000.0);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::cout<<GridLogMessage<<"ConjugateGradient did NOT converge"<<std::endl;
|
std::cout<<GridLogMessage<<"ConjugateGradient did NOT converge"<<std::endl;
|
||||||
assert(0);
|
if(ErrorOnNoConverge)
|
||||||
|
assert(0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user