A factory that can generate inverse operators according to parameter files. More...
#include <inverse_operator.h>
Public Member Functions | |
InverseOperator (const std::string §ion_name="", const std::string &default_solver="cg", const SolverControlType &control_type=SolverControlType::tolerance, const unsigned int max_iterations=1000, const double tolerance=1e-12, const double reduction=1e-6, const unsigned int consecutive_iterations=2, const bool &log_history=false, const bool &log_result=false) | |
Store and parse the parameters that will be needed to create a linear operator that computes the inverse of a matrix via an iterative solver. More... | |
template<typename Domain , typename Payload , typename PreconditionerType , typename Range = Domain> | |
LinearOperator< Domain, Range, Payload > | operator() (const LinearOperator< Range, Domain, Payload > &op, const PreconditionerType &prec, const double abs_tol=0.0, const std::string &prefix="") const |
Create an inverse operator according to the parameters given in the parameter file. More... | |
template<typename Range , typename Payload = internal::LinearOperatorImplementation::EmptyPayload, typename Domain = Range, typename MatrixType , typename PreconditionerType > | |
LinearOperator< Range, Domain, Payload > | solver (const MatrixType &op, const PreconditionerType &prec, const double abs_tol=0.0, const std::string &prefix="") const |
Create a solver. More... | |
template<typename MatrixType , typename PreconditionerType , typename VectorType > | |
void | solve (const MatrixType &matrix, const PreconditionerType &preconditioner, const VectorType &src, VectorType &dst, const double abs_tol=0.0) const |
Solve using the specified solver, preconditioner, and tolerance. More... | |
std::string | get_solver_name () const |
Get the solver name. More... | |
std::unique_ptr< SolverControl > | setup_new_solver_control (const double abs_tol=0.0) const |
Create a new solver control according to the parameters. More... | |
template<typename Range , typename Payload > | |
std::shared_ptr< SolverBase< Range > > | setup_new_solver (const double abs_tol=0.0) const |
Create a new solver according to the parameters. More... | |
![]() | |
ParameterAcceptor (const std::string §ion_name="") | |
unsigned int | get_acceptor_id () const |
virtual | ~ParameterAcceptor () override |
virtual void | declare_parameters (ParameterHandler &prm) |
virtual void | parse_parameters (ParameterHandler &prm) |
std::string | get_section_name () const |
std::vector< std::string > | get_section_path () const |
void | add_parameter (const std::string &entry, ParameterType ¶meter, const std::string &documentation="", ParameterHandler &prm_=prm, const Patterns::PatternBase &pattern=*Patterns::Tools::Convert< ParameterType >::to_pattern()) |
void | enter_subsection (const std::string &subsection) |
void | leave_subsection () |
void | enter_my_subsection (ParameterHandler &prm) |
void | leave_my_subsection (ParameterHandler &prm) |
void | serialize (Archive &ar, const unsigned int version) |
void | subscribe (std::atomic< bool > *const validity, const std::string &identifier="") const |
void | unsubscribe (std::atomic< bool > *const validity, const std::string &identifier="") const |
unsigned int | n_subscriptions () const |
void | list_subscribers (StreamType &stream) const |
void | list_subscribers () const |
void | subscribe (std::atomic< bool > *const validity, const std::string &identifier="") const |
void | unsubscribe (std::atomic< bool > *const validity, const std::string &identifier="") const |
unsigned int | n_subscriptions () const |
void | list_subscribers (StreamType &stream) const |
void | list_subscribers () const |
![]() | |
Subscriptor () | |
Subscriptor (const Subscriptor &) | |
Subscriptor (Subscriptor &&) noexcept | |
virtual | ~Subscriptor () |
Subscriptor & | operator= (const Subscriptor &) |
Subscriptor & | operator= (Subscriptor &&) noexcept |
void | serialize (Archive &ar, const unsigned int version) |
void | subscribe (std::atomic< bool > *const validity, const std::string &identifier="") const |
void | unsubscribe (std::atomic< bool > *const validity, const std::string &identifier="") const |
unsigned int | n_subscriptions () const |
void | list_subscribers (StreamType &stream) const |
void | list_subscribers () const |
void | subscribe (std::atomic< bool > *const validity, const std::string &identifier="") const |
void | unsubscribe (std::atomic< bool > *const validity, const std::string &identifier="") const |
unsigned int | n_subscriptions () const |
void | list_subscribers (StreamType &stream) const |
void | list_subscribers () const |
Private Attributes | |
SolverControlType | control_type |
Defines the behaviour of the solver control. More... | |
std::unique_ptr< SolverControl > | control |
Used internally by the solver. More... | |
std::string | solver_name |
Solver name. More... | |
unsigned int | max_iterations |
Default number of maximum iterations required to succesfully complete a solution step. More... | |
unsigned int | consecutive_iterations |
Number of consecutive iterations (used only for ConsecutiveControl). More... | |
double | tolerance |
Default reduction required to succesfully complete a solution step. More... | |
double | reduction |
Default reduction required to succesfully complete a solution step. More... | |
bool | log_history |
Log the solver history. More... | |
bool | log_result |
Log the final result. More... | |
GeneralDataStorage | storage |
Local storage for the actual solver object. More... | |
Additional Inherited Members | |
![]() | |
static void | initialize (const std::string &filename="", const std::string &output_filename="", const ParameterHandler::OutputStyle output_style_for_output_filename=ParameterHandler::Short, ParameterHandler &prm=ParameterAcceptor::prm, const ParameterHandler::OutputStyle output_style_for_filename=ParameterHandler::DefaultStyle) |
static void | initialize (std::istream &input_stream, ParameterHandler &prm=ParameterAcceptor::prm) |
static void | clear () |
static void | parse_all_parameters (ParameterHandler &prm=ParameterAcceptor::prm) |
static void | declare_all_parameters (ParameterHandler &prm=ParameterAcceptor::prm) |
static ::ExceptionBase & | ExcInUse (int arg1, std::string arg2, std::string arg3) |
static ::ExceptionBase & | ExcNoSubscriber (std::string arg1, std::string arg2) |
![]() | |
static ::ExceptionBase & | ExcInUse (int arg1, std::string arg2, std::string arg3) |
static ::ExceptionBase & | ExcNoSubscriber (std::string arg1, std::string arg2) |
![]() | |
boost::signals2::signal< void()> | declare_parameters_call_back |
boost::signals2::signal< void()> | parse_parameters_call_back |
![]() | |
static ParameterHandler | prm |
![]() | |
const std::string | section_name |
std::vector< std::string > | subsections |
A factory that can generate inverse operators according to parameter files.
This object is a parsed inverse operator, which uses a parameter file to select a Solver type and SolverControl type.
Example usage is the following:
The parameter file is expected to have the following structure:
Every solver control type uses the absolute tolerance, the maximum iterations, and the log parameters. The relative tolerance is used only by the ReductionControl type, i.e., SolverControlType::reduction, while consecutive iterations is used only by the ConsecutiveControl, i.e., SolverControlType::consecutive_iterations. The special case SolverControlType::iteration_number uses the same parameters of the default one, but it does not fail when reaching the maximum number of iterations. It is thought to be used as an inner solver, for the cases in which you want to apply a fixed number of smoothing iterations, regardless of the reached tolerance.
Definition at line 89 of file inverse_operator.h.
ParsedLAC::InverseOperator::InverseOperator | ( | const std::string & | section_name = "" , |
const std::string & | default_solver = "cg" , |
||
const SolverControlType & | control_type = SolverControlType::tolerance , |
||
const unsigned int | max_iterations = 1000 , |
||
const double | tolerance = 1e-12 , |
||
const double | reduction = 1e-6 , |
||
const unsigned int | consecutive_iterations = 2 , |
||
const bool & | log_history = false , |
||
const bool & | log_result = false |
||
) |
Store and parse the parameters that will be needed to create a linear operator that computes the inverse of a matrix via an iterative solver.
This object allows you to create an instance of an inverse_operator() LinearOperator, using the selected linear solver and the the selected SolverControl type.
section_name | The name of the section in the parameter file where the pamaeters are stored. If empty, the section name is the class name. |
default_solver | The default solver type. |
control_type | The type of solver control to use. |
max_iterations | Maximum number of iterations. |
tolerance | Absolute tolerance. |
reduction | Relative tolerance. Used only if control_type is SolverControlType::reduction. |
consecutive_iterations | Number of consecutive iterations. Used only if control_type is SolverControlType::consecutive_iterations. |
log_history | Print the residual at each iteration on deallog. |
log_result | Print the number of iterations and the final residual on deallog. |
Definition at line 25 of file inverse_operator.cc.
References ParameterAcceptor::add_parameter(), ParsedLAC::consecutive_iterations, ParameterAcceptor::prm, and ParsedLAC::tolerance.
LinearOperator<Domain, Range, Payload> ParsedLAC::InverseOperator::operator() | ( | const LinearOperator< Range, Domain, Payload > & | op, |
const PreconditionerType & | prec, | ||
const double | abs_tol = 0.0 , |
||
const std::string & | prefix = "" |
||
) | const |
Create an inverse operator according to the parameters given in the parameter file.
You can create many solvers using the same call, by specifying different prefixes each time. If you specify the same prefix, the previous solver stored with that prefix will be destroied.
op | The operator to invert. |
preconditioner | The preconditioner to use. |
LinearOperator<Range, Domain, Payload> ParsedLAC::InverseOperator::solver | ( | const MatrixType & | op, |
const PreconditionerType & | prec, | ||
const double | abs_tol = 0.0 , |
||
const std::string & | prefix = "" |
||
) | const |
Create a solver.
The solver will use all parameters specified in the parameter file. If abs_tol is non-zero, then a ReductionControl will be used. You can create many solvers using the same call, by specifying different prefixes each time.
If you specify the same prefix, the previous solver stored with that prefix will be destroied.
void ParsedLAC::InverseOperator::solve | ( | const MatrixType & | matrix, |
const PreconditionerType & | preconditioner, | ||
const VectorType & | src, | ||
VectorType & | dst, | ||
const double | abs_tol = 0.0 |
||
) | const |
Solve using the specified solver, preconditioner, and tolerance.
If the tolerance is non-zero, then a ReductionControl will be used with the given argument, otherwise the parameter file is used to determine all the solver and control parameters.
std::string ParsedLAC::InverseOperator::get_solver_name | ( | ) | const |
std::unique_ptr< SolverControl > ParsedLAC::InverseOperator::setup_new_solver_control | ( | const double | abs_tol = 0.0 | ) | const |
Create a new solver control according to the parameters.
If the user supplies a abs_tol
parameter, the generated SolverControl is a SolverControl with this tolerance.
Definition at line 68 of file inverse_operator.cc.
References Assert, ParsedLAC::consecutive_iterations, consecutive_iterations, control, control_type, StandardExceptions::ExcInternalError(), ParsedLAC::iteration_number, log_history, log_result, max_iterations, ParsedLAC::reduction, reduction, ParsedLAC::tolerance, and tolerance.
std::shared_ptr<SolverBase<Range> > ParsedLAC::InverseOperator::setup_new_solver | ( | const double | abs_tol = 0.0 | ) | const |
Create a new solver according to the parameters.
If the user supplies a abs_tol
parameter, the used SolverControl is a SolverControl with this tolerance.
|
private |
Defines the behaviour of the solver control.
Definition at line 212 of file inverse_operator.h.
Referenced by setup_new_solver_control().
|
mutableprivate |
Used internally by the solver.
Definition at line 217 of file inverse_operator.h.
Referenced by setup_new_solver_control().
|
private |
|
private |
Default number of maximum iterations required to succesfully complete a solution step.
Definition at line 228 of file inverse_operator.h.
Referenced by setup_new_solver_control().
|
private |
Number of consecutive iterations (used only for ConsecutiveControl).
Definition at line 233 of file inverse_operator.h.
Referenced by setup_new_solver_control().
|
private |
Default reduction required to succesfully complete a solution step.
Definition at line 239 of file inverse_operator.h.
Referenced by setup_new_solver_control().
|
private |
Default reduction required to succesfully complete a solution step.
Definition at line 245 of file inverse_operator.h.
Referenced by setup_new_solver_control().
|
private |
Log the solver history.
Definition at line 250 of file inverse_operator.h.
Referenced by setup_new_solver_control().
|
private |
Log the final result.
Definition at line 255 of file inverse_operator.h.
Referenced by setup_new_solver_control().
|
mutableprivate |
Local storage for the actual solver object.
Definition at line 260 of file inverse_operator.h.