DOpE
gmreslinearsolver.h
Go to the documentation of this file.
1 
24 #ifndef GMRES_LINEAR_SOLVER_H_
25 #define GMRES_LINEAR_SOLVER_H_
26 
27 #include <deal.II/lac/vector.h>
28 #include <deal.II/lac/block_sparsity_pattern.h>
29 #include <deal.II/lac/block_sparse_matrix.h>
30 #include <deal.II/lac/compressed_simple_sparsity_pattern.h>
31 #include <deal.II/lac/solver_gmres.h>
32 #include <deal.II/lac/precondition.h>
33 #include <deal.II/lac/full_matrix.h>
34 
35 #include <deal.II/dofs/dof_tools.h>
36 
37 #include <deal.II/numerics/vector_tools.h>
38 
39 #include <vector>
40 
41 namespace DOpE
42 {
43 
56  template <typename PRECONDITIONER, typename SPARSITYPATTERN, typename MATRIX, typename VECTOR>
58  {
59  public:
62 
63  static void declare_params(ParameterReader &param_reader);
64 
69  template<typename PROBLEM>
70  void ReInit(PROBLEM& pde);
71 
90  template<typename PROBLEM, typename INTEGRATOR>
91  void Solve(PROBLEM& pde,INTEGRATOR& integr, VECTOR &rhs, VECTOR &solution, bool force_matrix_build=false);
92 
93  protected:
94 
95  private:
96  SPARSITYPATTERN sparsity_pattern_;
97  MATRIX matrix_;
98 
99  double linear_global_tol_, linear_tol_;
100  int linear_maxiter_, no_tmp_vectors_;
101  };
102 
103 /*********************************Implementation************************************************/
104 
105 template <typename PRECONDITIONER,typename SPARSITYPATTERN, typename MATRIX, typename VECTOR>
107  {
108  param_reader.SetSubsection("gmres_withmatrix parameters");
109  param_reader.declare_entry("linear_global_tol", "1.e-10",Patterns::Double(0),"global tolerance for the gmres iteration");
110  param_reader.declare_entry("linear_maxiter", "1000",Patterns::Integer(0),"maximal number of gmres steps");
111  param_reader.declare_entry("no_tmp_vectors", "100",Patterns::Integer(0),"Number of temporary vectors");
112  }
113 /******************************************************/
114 
115  template <typename PRECONDITIONER,typename SPARSITYPATTERN, typename MATRIX, typename VECTOR>
118 {
119  param_reader.SetSubsection("gmres_withmatrix parameters");
120  linear_global_tol_ = param_reader.get_double ("linear_global_tol");
121  linear_maxiter_ = param_reader.get_integer ("linear_maxiter");
122  no_tmp_vectors_ = param_reader.get_integer ("no_tmp_vectors");
123 
124 }
125 
126 /******************************************************/
127 
128 template <typename PRECONDITIONER,typename SPARSITYPATTERN, typename MATRIX, typename VECTOR>
130 {
131 }
132 
133 /******************************************************/
134 
135 template <typename PRECONDITIONER,typename SPARSITYPATTERN, typename MATRIX, typename VECTOR>
136  template<typename PROBLEM>
138 {
139  matrix_.clear();
140  pde.ComputeSparsityPattern(sparsity_pattern_);
141  matrix_.reinit(sparsity_pattern_);
142 }
143 
144 /******************************************************/
145 
146 template <typename PRECONDITIONER,typename SPARSITYPATTERN, typename MATRIX, typename VECTOR>
147  template<typename PROBLEM, typename INTEGRATOR>
149  INTEGRATOR& integr,
150  VECTOR &rhs,
151  VECTOR &solution,
152  bool force_matrix_build)
153 {
154  if(force_matrix_build)
155  {
156  integr.ComputeMatrix (pde,matrix_);
157  }
158 
159  integr.ApplyNewtonBoundaryValues(pde,matrix_,rhs,solution);
160 
161  dealii::SolverControl solver_control (linear_maxiter_, linear_global_tol_,false,false);
162 
163  // This is gmres specific
164  dealii::GrowingVectorMemory<VECTOR> vector_memory;
165  typename dealii::SolverGMRES<VECTOR>::AdditionalData gmres_data;
166  gmres_data.max_n_tmp_vectors = no_tmp_vectors_;
167 
168 
169  dealii::SolverGMRES<VECTOR> gmres (solver_control, vector_memory, gmres_data);
170  PRECONDITIONER precondition;
171  precondition.initialize(matrix_);
172  gmres.solve (matrix_, solution, rhs,
173  precondition);
174 
175  pde.GetDoFConstraints().distribute(solution);
176 }
177 
178 
179 }
180 #endif
~GMRESLinearSolverWithMatrix()
Definition: gmreslinearsolver.h:129
double get_double(const std::string &entry_name)
Definition: parameterreader.h:115
Definition: parameterreader.h:36
void Solve(PROBLEM &pde, INTEGRATOR &integr, VECTOR &rhs, VECTOR &solution, bool force_matrix_build=false)
Definition: gmreslinearsolver.h:148
void declare_entry(const std::string &entry, const std::string &default_value, const Patterns::PatternBase &pattern=Patterns::Anything(), const std::string &documentation=std::string())
Definition: parameterreader.h:98
GMRESLinearSolverWithMatrix(ParameterReader &param_reader)
Definition: gmreslinearsolver.h:117
static void declare_params(ParameterReader &param_reader)
Definition: gmreslinearsolver.h:106
int get_integer(const std::string &entry_name)
Definition: parameterreader.h:126
void SetSubsection(const std::string subsection)
Definition: parameterreader.h:93
Definition: gmreslinearsolver.h:57
void ReInit(PROBLEM &pde)
Definition: gmreslinearsolver.h:137