Fluid structure interaction suite
inverse_operator.cc
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2022 by Luca Heltai
4 //
5 // This file is part of the FSI-suite platform, based on the deal.II library.
6 //
7 // The FSI-suite platform is free software; you can use it, redistribute it,
8 // and/or modify it under the terms of the GNU Lesser General Public License as
9 // published by the Free Software Foundation; either version 3.0 of the License,
10 // or (at your option) any later version. The full text of the license can be
11 // found in the file LICENSE at the top level of the FSI-suite platform
12 // distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 
18 
19 #include "parsed_tools/enum.h"
20 
21 using namespace dealii;
22 
23 namespace ParsedLAC
24 {
25  InverseOperator::InverseOperator(const std::string &section_name,
26  const std::string &solver_name,
27  const SolverControlType &control_type,
28  const unsigned int max_iterations,
29  const double tolerance,
30  const double reduction,
31  const unsigned int consecutive_iterations,
32  const bool &log_history,
33  const bool &log_result)
34  : ParameterAcceptor(section_name)
35  , control_type(control_type)
36  , solver_name(solver_name)
37  , max_iterations(max_iterations)
40  , reduction(reduction)
41  , log_history(log_history)
42  , log_result(log_result)
43  {
44  add_parameter("Solver name",
45  this->solver_name,
46  "Name of the solver to use. One of cg,bicgstab,gmres,fgmres,"
47  "minres,qmrs, or richardson.",
48  dealii::ParameterAcceptor::prm,
49  dealii::Patterns::Selection("cg|bicgstab|gmres|fgmres|"
50  "minres|qmrs|richardson"));
51  add_parameter("Solver control type", this->control_type);
52  add_parameter("Maximum iterations", this->max_iterations);
53  add_parameter("Consecutive iterations", this->consecutive_iterations);
54  add_parameter("Absolute tolerance", this->tolerance);
55  add_parameter("Relative tolerance", this->reduction);
56  add_parameter("Log history", this->log_history);
57  add_parameter("Log result", this->log_result);
58  }
59 
60  std::string
62  {
63  return solver_name;
64  }
65 
66 
67  std::unique_ptr<dealii::SolverControl>
68  InverseOperator::setup_new_solver_control(const double abs_tol) const
69  {
70  std::unique_ptr<dealii::SolverControl> result;
71  auto control = abs_tol == 0.0 ? control_type : SolverControlType::tolerance;
72  switch (control)
73  {
75  result.reset(new SolverControl(max_iterations,
76  abs_tol == 0.0 ? tolerance : abs_tol,
78  log_result));
79  break;
81  result.reset(new ReductionControl(
83  break;
85  result.reset(new ConsecutiveControl(max_iterations,
86  tolerance,
89  log_result));
90  break;
92  result.reset(new IterationNumberControl(
94  break;
95  default:
96  Assert(false, ExcInternalError());
97  break;
98  }
99  return result;
100  }
101 
102 } // namespace ParsedLAC
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())
bool log_result
Log the final result.
double tolerance
Default reduction required to succesfully complete a solution step.
std::string get_solver_name() const
Get the solver name.
std::string solver_name
Solver name.
unsigned int consecutive_iterations
Number of consecutive iterations (used only for ConsecutiveControl).
bool log_history
Log the solver history.
double reduction
Default reduction required to succesfully complete a solution step.
SolverControlType control_type
Defines the behaviour of the solver control.
std::unique_ptr< SolverControl > setup_new_solver_control(const double abs_tol=0.0) const
Create a new solver control according to the parameters.
unsigned int max_iterations
Default number of maximum iterations required to succesfully complete a solution step.
std::unique_ptr< SolverControl > control
Used internally by the solver.
#define Assert(cond, exc)
static ::ExceptionBase & ExcInternalError()
Definition: amg.h:28
SolverControlType
An enum class used to identify different classes derived from SolverControl.
@ iteration_number
Use IterationNumberControl.
@ tolerance
Use SolverControl.
@ reduction
Use ReductionControl.
@ consecutive_iterations
Use ConsecutiveControl.