Merge pull request #5445 from jakobtorben/make_cpr_reuse_option_only_apply_to_cpr

Make CPR reuse setup option only apply to CPR
This commit is contained in:
Atgeirr Flø Rasmussen 2024-08-21 08:45:09 +02:00 committed by GitHub
commit 908a9b37ff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 71 additions and 3 deletions

View File

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

View File

@ -495,6 +495,13 @@ std::unique_ptr<Matrix> blockJacobiAdjacency(const Grid& grid,
if (!flexibleSolver_[activeSolverNum_].solver_) { if (!flexibleSolver_[activeSolverNum_].solver_) {
return true; 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) { if (this->parameters_[activeSolverNum_].cpr_reuse_setup_ == 0) {
// Always recreate solver. // Always recreate solver.
return true; return true;
@ -509,7 +516,7 @@ std::unique_ptr<Matrix> blockJacobiAdjacency(const Grid& grid,
return this->iterations() > 10; return this->iterations() > 10;
} }
if (this->parameters_[activeSolverNum_].cpr_reuse_setup_ == 3) { 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; return false;
} }
if (this->parameters_[activeSolverNum_].cpr_reuse_setup_ == 4) { 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); const bool create = ((solveCount_ % step) == 0);
return create; return create;
} }
// If here, we have an invalid parameter. // If here, we have an invalid parameter.
const bool on_io_rank = (simulator_.gridView().comm().rank() == 0); const bool on_io_rank = (simulator_.gridView().comm().rank() == 0);
std::string msg = "Invalid value: " + std::to_string(this->parameters_[activeSolverNum_].cpr_reuse_setup_) 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); throw std::runtime_error(msg);
// Never reached.
return false; return false;
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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