Merge pull request #5758 from jakobtorben/remove_recreation_of_second_stage_preconditioner_for_cpr

Update second stage preconditioner for CPR instead of recreate
This commit is contained in:
Atgeirr Flø Rasmussen
2024-11-27 13:29:43 +01:00
committed by GitHub
2 changed files with 4 additions and 7 deletions

View File

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

View File

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