Add method for defining if preconditioners should be recreated

This commit is contained in:
jakobtorben 2024-06-27 12:50:26 +02:00
parent ac1cbd8987
commit 5d54c50ba0
15 changed files with 71 additions and 3 deletions

View File

@ -162,6 +162,10 @@ public:
return SolverCategory::sequential;
}
virtual bool hasPerfectUpdate() const override {
return true;
}
private:
//! \brief The matrix we operate on.
const M& A_;

View File

@ -495,6 +495,13 @@ std::unique_ptr<Matrix> blockJacobiAdjacency(const Grid& grid,
if (!flexibleSolver_[activeSolverNum_].solver_) {
return true;
}
if (flexibleSolver_[activeSolverNum_].pre_->hasPerfectUpdate()) {
return false;
}
// For AMG based preconditioners, the hierarchy depends on the matrix values
// so it is recreated at certain intervals
if (this->parameters_[activeSolverNum_].cpr_reuse_setup_ == 0) {
// Always recreate solver.
return true;
@ -509,7 +516,7 @@ std::unique_ptr<Matrix> blockJacobiAdjacency(const Grid& grid,
return this->iterations() > 10;
}
if (this->parameters_[activeSolverNum_].cpr_reuse_setup_ == 3) {
// Recreate solver if the last solve used more than 10 iterations.
// Never recreate the solver
return false;
}
if (this->parameters_[activeSolverNum_].cpr_reuse_setup_ == 4) {
@ -518,7 +525,6 @@ std::unique_ptr<Matrix> blockJacobiAdjacency(const Grid& grid,
const bool create = ((solveCount_ % step) == 0);
return create;
}
// If here, we have an invalid parameter.
const bool on_io_rank = (simulator_.gridView().comm().rank() == 0);
std::string msg = "Invalid value: " + std::to_string(this->parameters_[activeSolverNum_].cpr_reuse_setup_)
@ -528,7 +534,6 @@ std::unique_ptr<Matrix> blockJacobiAdjacency(const Grid& grid,
}
throw std::runtime_error(msg);
// Never reached.
return false;
}

View File

@ -74,6 +74,10 @@ public:
orig_precond_.update();
}
virtual bool hasPerfectUpdate() const override {
return orig_precond_.hasPerfectUpdate();
}
private:
OriginalPreconditioner orig_precond_;
BlockPreconditioner<X, Y, Comm, OriginalPreconditioner> block_precond_;

View File

@ -173,6 +173,10 @@ public:
return linear_operator_.category();
}
virtual bool hasPerfectUpdate() const override {
return false;
}
private:
using CoarseOperator = typename LevelTransferPolicy::CoarseOperator;
using CoarseSolverPolicy = Dune::Amg::PressureSolverPolicy<CoarseOperator,

View File

@ -144,6 +144,10 @@ public:
using block_type = typename matrix_type::block_type;
using size_type = typename matrix_type::size_type;
virtual bool hasPerfectUpdate() const override {
return true;
}
protected:
struct CRS
{

View File

@ -32,6 +32,9 @@ class PreconditionerWithUpdate : public Preconditioner<X, Y>
{
public:
virtual void update() = 0;
// Force derived classes to define if preconditioner has perfect update
virtual bool hasPerfectUpdate() const = 0;
};
template <class OriginalPreconditioner>
@ -73,6 +76,10 @@ public:
{
}
virtual bool hasPerfectUpdate() const override {
return true;
}
private:
OriginalPreconditioner orig_precond_;
};
@ -162,6 +169,10 @@ public:
orig_precond_ = preconditioner_maker_->make();
}
virtual bool hasPerfectUpdate() const override {
return true;
}
private:
using AbstractMakerType = GeneralPreconditionerMaker<OriginalPreconditioner>;
using GenericPreconditioner = Preconditioner<typename OriginalPreconditioner::domain_type, typename OriginalPreconditioner::range_type>;

View File

@ -169,6 +169,10 @@ namespace Dune
return category_;
}
virtual bool hasPerfectUpdate() const override {
return false;
}
/** \copydoc Preconditioner::post */
void post(Domain& x);

View File

@ -113,6 +113,10 @@ public:
return m_preconditioner;
}
virtual bool hasPerfectUpdate() const override {
return true;
}
private:
//! \brief a sequential preconditioner

View File

@ -98,6 +98,10 @@ public:
return false;
}
virtual bool hasPerfectUpdate() const override {
return true;
}
private:
//! \brief Reference to the underlying matrix

View File

@ -93,6 +93,10 @@ public:
return false;
}
virtual bool hasPerfectUpdate() const override {
return true;
}
private:
//! \brief Reference to the underlying matrix

View File

@ -96,6 +96,10 @@ public:
return false;
}
virtual bool hasPerfectUpdate() const override {
return true;
}
private:
//! \brief Reference to the underlying matrix

View File

@ -99,6 +99,10 @@ public:
return false;
}
virtual bool hasPerfectUpdate() const override {
return true;
}
private:
//! \brief Reference to the underlying matrix

View File

@ -123,6 +123,10 @@ public:
return m_underlyingPreconditioner;
}
virtual bool hasPerfectUpdate() const override {
return m_underlyingPreconditioner->hasPerfectUpdate();
}
private:
//! \brief the underlying preconditioner to use
std::shared_ptr<CudaPreconditionerType> m_underlyingPreconditioner;

View File

@ -189,6 +189,10 @@ public:
m_underlyingPreconditioner = conditioner;
}
virtual bool hasPerfectUpdate() const override {
return m_underlyingPreconditioner->hasPerfectUpdate();
}
private:
void updateMatrix()

View File

@ -110,6 +110,10 @@ public:
return false;
}
virtual bool hasPerfectUpdate() const override {
return false;
}
private:
const SpMatrixFloat& m_matrix;