DOpE
qmrslinearsolver.h
Go to the documentation of this file.
1 
24 #ifndef _QMRS_LINEAR_SOLVER_H_
25 #define _QMRS_LINEAR_SOLVER_H_
26 
27 #include <lac/vector.h>
28 #include <lac/block_sparsity_pattern.h>
29 #include <lac/block_sparse_matrix.h>
30 #include <lac/compressed_simple_sparsity_pattern.h>
31 #include <lac/solver_qmrs.h>
32 #include <lac/precondition.h>
33 #include <lac/full_matrix.h>
34 
35 #include <dofs/dof_tools.h>
36 
37 #include <numerics/vector_tools.h>
38 
39 #include <vector>
40 
41 namespace DOpE
42 {
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;
101  };
102 
103 /*********************************Implementation************************************************/
104 
105 template <typename PRECONDITIONER,typename SPARSITYPATTERN, typename MATRIX, typename VECTOR>
107  {
108  param_reader.SetSubsection("qmrslinearsolver_withmatrix parameters");
109  param_reader.declare_entry("linear_global_tol", "1.e-16",Patterns::Double(0),"global tolerance for the cg iteration");
110  param_reader.declare_entry("linear_tol", "1.e-12",Patterns::Double(0),"relative tolerance for the cg iteration");
111  param_reader.declare_entry("linear_maxiter", "1000",Patterns::Integer(0),"maximal number of cg steps");
112  }
113 /******************************************************/
114 
115  template <typename PRECONDITIONER,typename SPARSITYPATTERN, typename MATRIX, typename VECTOR>
118 {
119  param_reader.SetSubsection("qmrslinearsolver_withmatrix parameters");
120  _linear_global_tol = param_reader.get_double ("linear_global_tol");
121  _linear_tol = param_reader.get_double ("linear_tol");
122  _linear_maxiter = param_reader.get_integer ("linear_maxiter");
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 template <typename PRECONDITIONER,typename SPARSITYPATTERN, typename MATRIX, typename VECTOR>
146  template<typename PROBLEM, typename INTEGRATOR>
148  INTEGRATOR& integr,
149  VECTOR &rhs,
150  VECTOR &solution,
151  bool force_matrix_build)
152 {
153  if(force_matrix_build)
154  {
155  integr.ComputeMatrix (pde,_matrix);
156  }
157 
158  integr.ApplyNewtonBoundaryValues(pde,_matrix,rhs,solution);
159 
160  dealii::SolverControl solver_control (_linear_maxiter, _linear_global_tol,false,true);//letzte Arg = false!
161  dealii::SolverQMRS<VECTOR> qmres (solver_control);
162  PRECONDITIONER precondition;
163  precondition.initialize(_matrix);
164  qmres.solve (_matrix, solution, rhs,
165  precondition);
166  VECTOR tmp(solution.size());
167  _matrix.vmult(tmp,solution);
168  tmp-= rhs;
169  std::cout<<"XXX"<<tmp.linfty_norm()<<" ---- "<<tmp.l2_norm()<<std::endl;
170  pde.GetDoFConstraints().distribute(solution);
171 }
172 /******************************************************/
173 
174 
175 
176 }
177 #endif
double get_double(const std::string &entry_name)
Definition: parameterreader.h:115
void Solve(PROBLEM &pde, INTEGRATOR &integr, VECTOR &rhs, VECTOR &solution, bool force_matrix_build=false)
Definition: qmrslinearsolver.h:147
Definition: parameterreader.h:36
Definition: qmrslinearsolver.h:57
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
static void declare_params(ParameterReader &param_reader)
Definition: qmrslinearsolver.h:106
void ReInit(PROBLEM &pde)
Definition: qmrslinearsolver.h:137
int get_integer(const std::string &entry_name)
Definition: parameterreader.h:126
void SetSubsection(const std::string subsection)
Definition: parameterreader.h:93
~QMRSLinearSolverWithMatrix()
Definition: qmrslinearsolver.h:129
QMRSLinearSolverWithMatrix(ParameterReader &param_reader)
Definition: qmrslinearsolver.h:117