Skip to content
Snippets Groups Projects
Commit ec60f0da authored by Steffen Müthing's avatar Steffen Müthing
Browse files

[!310] Add constructors that take shared ptr to iterative solvers

Merge branch 'add_constructors_that_take_shared_ptr_to_iterative_solvers' into 'master'

ref:core/dune-istl This MR add constructors for IterativeSolvers that take
std::shared_ptr instead of references.

See merge request [!310]

  [!310]: gitlab.dune-project.org/core/dune-istl/merge_requests/310
parents a5cbbad0 c10ec539
No related branches found
No related tags found
1 merge request!310Add constructors that take shared ptr to iterative solvers
Pipeline #20222 passed
......@@ -266,6 +266,43 @@ namespace Dune
DUNE_THROW(InvalidSolverCategory, "LinearOperator and ScalarProduct must have the same SolverCategory!");
}
/**
\brief General constructor to initialize an iterative solver
\param op The operator we solve.
\param sp The scalar product to use, e. g. SeqScalarproduct.
\param prec The preconditioner to apply in each iteration of the loop.
Has to inherit from Preconditioner.
\param reduction The relative defect reduction to achieve when applying
the operator.
\param maxit The maximum number of iteration steps allowed when applying
the operator.
\param verbose The verbosity level.
Verbose levels are:
<ul>
<li> 0 : print nothing </li>
<li> 1 : print initial and final defect and statistics </li>
<li> 2 : print line for each iteration </li>
</ul>
*/
IterativeSolver (std::shared_ptr<LinearOperator<X,Y>> op,
std::shared_ptr<ScalarProduct<X>> sp,
std::shared_ptr<Preconditioner<X,Y>> prec,
scalar_real_type reduction, int maxit, int verbose) :
_op(op),
_prec(prec),
_sp(sp),
_reduction(reduction), _maxit(maxit), _verbose(verbose),
_category(SolverCategory::category(op))
{
if(SolverCategory::category(*op) != SolverCategory::category(*prec))
DUNE_THROW(InvalidSolverCategory, "LinearOperator and Preconditioner must have the same SolverCategory!");
if(SolverCategory::category(*op) != SolverCategory::category(*sp))
DUNE_THROW(InvalidSolverCategory, "LinearOperator and ScalarProduct must have the same SolverCategory!");
}
// #warning actually we want to have this as the default and just implement the second one
// //! \copydoc InverseOperator::apply(X&,Y&,InverseOperatorResult&)
// virtual void apply (X& x, Y& b, InverseOperatorResult& res)
......
......@@ -308,6 +308,24 @@ namespace Dune {
}
}
/*!
\brief Constructor to initialize a CG solver.
\copydetails IterativeSolver::IterativeSolver(std::shared_ptr<LinearOperator<X,Y>>, std::shared_ptr<ScalarProduct<X>>, std::shared_ptr<Preconditioner<X,Y>>, real_type, int, int)
\param condition_estimate Whether to calculate an estimate of the condition number.
The estimate is given in the InverseOperatorResult returned by apply().
This is only supported for float and double field types.
*/
CGSolver (std::shared_ptr<LinearOperator<X,X>> op, std::shared_ptr<ScalarProduct<X>> sp,
std::shared_ptr<Preconditioner<X,X>> prec,
scalar_real_type reduction, int maxit, int verbose, bool condition_estimate)
: IterativeSolver<X,X>(op, sp, prec, reduction, maxit, verbose),
condition_estimate_(condition_estimate)
{
if (condition_estimate && !(std::is_same<field_type,float>::value || std::is_same<field_type,double>::value)) {
condition_estimate_ = false;
std::cerr << "WARNING: Condition estimate was disabled. It is only available for double and float field types!" << std::endl;
}
}
/*!
\brief Apply inverse operator.
......@@ -1060,6 +1078,20 @@ namespace Dune {
_restart(restart)
{}
/*!
\brief Set up RestartedGMResSolver solver.
\copydoc LoopSolver::LoopSolver(std::shared_ptr<L>,std::shared_ptr<S>,std::shared_ptr<P>,double,int,int)
\param restart number of GMRes cycles before restart
*/
RestartedGMResSolver (std::shared_ptr<LinearOperator<X,Y>> op,
std::shared_ptr<ScalarProduct<X>> sp,
std::shared_ptr<Preconditioner<X,Y>> prec,
scalar_real_type reduction, int restart, int maxit, int verbose) :
IterativeSolver<X,Y>::IterativeSolver(op,sp,prec,reduction,maxit,verbose),
_restart(restart)
{}
/*!
\brief Apply inverse operator.
......@@ -1586,6 +1618,22 @@ private:
_restart(restart)
{}
/*!
\brief Set up nonlinear preconditioned conjugate gradient solver.
\copydoc LoopSolver::LoopSolver(std::shared_ptr<L>,std::shared_ptr<S>,std::shared_ptr<P>,double,int,int)
\param restart When to restart the construction of
the Krylov search space.
*/
GeneralizedPCGSolver (std::shared_ptr<LinearOperator<X,X>> op,
std::shared_ptr<ScalarProduct<X>> sp,
std::shared_ptr<Preconditioner<X,X>> prec,
scalar_real_type reduction, int maxit, int verbose,
int restart = 10) :
IterativeSolver<X,X>::IterativeSolver(op,sp,prec,reduction,maxit,verbose),
_restart(restart)
{}
/*!
\brief Apply inverse operator.
......@@ -1784,6 +1832,19 @@ private:
{
}
/*!
\brief Constructor to initialize a RestartedFCG solver.
\copydetails IterativeSolver::IterativeSolver(std::shared_ptr<LinearOperator<X,Y>>, std::shared_ptr<ScalarProduct<X>>, std::shared_ptr<Preconditioner<X,Y>>, real_type, int, int,int)
\param mmax is the maximal number of previous vectors which are orthogonalized against the new search direction.
*/
RestartedFCGSolver (std::shared_ptr<LinearOperator<X,X>> op,
std::shared_ptr<ScalarProduct<X>> sp,
std::shared_ptr<Preconditioner<X,X>> prec,
scalar_real_type reduction, int maxit, int verbose,
int mmax = 10)
: IterativeSolver<X,X>(op, sp, prec, reduction, maxit, verbose), _mmax(mmax)
{}
/*!
\brief Apply inverse operator.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment