Fluid structure interaction suite
ParsedLAC::InverseOperator Class Reference

A factory that can generate inverse operators according to parameter files. More...

#include <inverse_operator.h>

Inheritance diagram for ParsedLAC::InverseOperator:
[legend]

Public Member Functions

 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. 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< SolverControlsetup_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...
 
- Public Member Functions inherited from ParameterAcceptor
 ParameterAcceptor (const std::string &section_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 &parameter, 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
 
- Public Member Functions inherited from Subscriptor
 Subscriptor ()
 
 Subscriptor (const Subscriptor &)
 
 Subscriptor (Subscriptor &&) noexcept
 
virtual ~Subscriptor ()
 
Subscriptoroperator= (const Subscriptor &)
 
Subscriptoroperator= (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< SolverControlcontrol
 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 Public Member Functions inherited from ParameterAcceptor
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 ::ExceptionBaseExcInUse (int arg1, std::string arg2, std::string arg3)
 
static ::ExceptionBaseExcNoSubscriber (std::string arg1, std::string arg2)
 
- Static Public Member Functions inherited from Subscriptor
static ::ExceptionBaseExcInUse (int arg1, std::string arg2, std::string arg3)
 
static ::ExceptionBaseExcNoSubscriber (std::string arg1, std::string arg2)
 
- Public Attributes inherited from ParameterAcceptor
boost::signals2::signal< void()> declare_parameters_call_back
 
boost::signals2::signal< void()> parse_parameters_call_back
 
- Static Public Attributes inherited from ParameterAcceptor
static ParameterHandler prm
 
- Protected Attributes inherited from ParameterAcceptor
const std::string section_name
 
std::vector< std::string > subsections
 

Detailed Description

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:

InverseOperator inverse("/", "cg");
auto Ainv = inverse(linear_operator<VEC>(A), preconditioner);
x = Ainv*b;
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)
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 inve...
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)

The parameter file is expected to have the following structure:

set Solver name = cg
set Solver control type = tolerance
set Absolute tolerance = 1e-12
set Relative tolerance = 1e-12
set Maximum iterations = 1000
set Consecutive iterations = 2
set Log history = false
set Log result = false

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.

Constructor & Destructor Documentation

◆ InverseOperator()

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.

Parameters
section_nameThe name of the section in the parameter file where the pamaeters are stored. If empty, the section name is the class name.
default_solverThe default solver type.
control_typeThe type of solver control to use.
max_iterationsMaximum number of iterations.
toleranceAbsolute tolerance.
reductionRelative tolerance. Used only if control_type is SolverControlType::reduction.
consecutive_iterationsNumber of consecutive iterations. Used only if control_type is SolverControlType::consecutive_iterations.
log_historyPrint the residual at each iteration on deallog.
log_resultPrint 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.

Member Function Documentation

◆ operator()()

template<typename Domain , typename Payload , typename PreconditionerType , typename Range = Domain>
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.

Parameters
opThe operator to invert.
preconditionerThe preconditioner to use.

◆ solver()

template<typename Range , typename Payload = internal::LinearOperatorImplementation::EmptyPayload, typename Domain = Range, typename MatrixType , typename PreconditionerType >
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.

◆ solve()

template<typename MatrixType , typename PreconditionerType , typename VectorType >
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.

◆ get_solver_name()

std::string ParsedLAC::InverseOperator::get_solver_name ( ) const

Get the solver name.

Definition at line 61 of file inverse_operator.cc.

References solver_name.

◆ setup_new_solver_control()

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.

◆ setup_new_solver()

template<typename Range , typename Payload >
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.

Member Data Documentation

◆ control_type

SolverControlType ParsedLAC::InverseOperator::control_type
private

Defines the behaviour of the solver control.

Definition at line 212 of file inverse_operator.h.

Referenced by setup_new_solver_control().

◆ control

std::unique_ptr<SolverControl> ParsedLAC::InverseOperator::control
mutableprivate

Used internally by the solver.

Definition at line 217 of file inverse_operator.h.

Referenced by setup_new_solver_control().

◆ solver_name

std::string ParsedLAC::InverseOperator::solver_name
private

Solver name.

Definition at line 222 of file inverse_operator.h.

Referenced by get_solver_name().

◆ max_iterations

unsigned int ParsedLAC::InverseOperator::max_iterations
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().

◆ consecutive_iterations

unsigned int ParsedLAC::InverseOperator::consecutive_iterations
private

Number of consecutive iterations (used only for ConsecutiveControl).

Definition at line 233 of file inverse_operator.h.

Referenced by setup_new_solver_control().

◆ tolerance

double ParsedLAC::InverseOperator::tolerance
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().

◆ reduction

double ParsedLAC::InverseOperator::reduction
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().

◆ log_history

bool ParsedLAC::InverseOperator::log_history
private

Log the solver history.

Definition at line 250 of file inverse_operator.h.

Referenced by setup_new_solver_control().

◆ log_result

bool ParsedLAC::InverseOperator::log_result
private

Log the final result.

Definition at line 255 of file inverse_operator.h.

Referenced by setup_new_solver_control().

◆ storage

GeneralDataStorage ParsedLAC::InverseOperator::storage
mutableprivate

Local storage for the actual solver object.

Definition at line 260 of file inverse_operator.h.


The documentation for this class was generated from the following files: