Update second stage preconditioner for CPR instead of recreate

This commit is contained in:
jakobtorben 2024-11-21 13:18:35 +01:00
parent 5b002b2a77
commit 3ec01f7d7b
2 changed files with 4 additions and 7 deletions

View File

@ -183,28 +183,24 @@ private:
FlexibleSolver<CoarseOperator>,
LevelTransferPolicy>;
using TwoLevelMethod
= Dune::Amg::TwoLevelMethodCpr<OperatorType, CoarseSolverPolicy, Dune::Preconditioner<VectorType, VectorType>>;
= Dune::Amg::TwoLevelMethodCpr<OperatorType, CoarseSolverPolicy, Dune::PreconditionerWithUpdate<VectorType, VectorType>>;
// Handling parallel vs serial instantiation of preconditioner factory.
template <class Comm>
void updateImpl(const Comm*)
{
// Parallel case.
auto child = prm_.get_child_optional("finesmoother");
finesmoother_ = PrecFactory::create(linear_operator_, child ? *child : Opm::PropertyTree(), *comm_);
twolevel_method_.updatePreconditioner(finesmoother_, coarseSolverPolicy_);
}
void updateImpl(const Dune::Amg::SequentialInformation*)
{
// Serial case.
auto child = prm_.get_child_optional("finesmoother");
finesmoother_ = PrecFactory::create(linear_operator_, child ? *child : Opm::PropertyTree());
twolevel_method_.updatePreconditioner(finesmoother_, coarseSolverPolicy_);
}
const OperatorType& linear_operator_;
std::shared_ptr<Dune::Preconditioner<VectorType, VectorType>> finesmoother_;
std::shared_ptr<PreconditionerWithUpdate<VectorType, VectorType>> finesmoother_;
const Communication* comm_;
std::function<VectorType()> weightsCalculator_;
VectorType weights_;

View File

@ -472,8 +472,9 @@ public:
void updatePreconditioner(std::shared_ptr<SmootherType> smoother,
CoarseLevelSolverPolicy& coarsePolicy)
{
//assume new matrix is not reallocated the new precondition should anyway be made
smoother_ = smoother;
// We assume the matrix has the same sparsity structure and memory locations throughout, only the values are changed.
smoother_->update();
if (coarseSolver_) {
policy_->calculateCoarseEntries(*operator_);
coarsePolicy.setCoarseOperator(*policy_);