DOpE
directlinearsolver.h
Go to the documentation of this file.
1 
24 #ifndef DIRECT_LINEAR_SOLVER_H_
25 #define DIRECT_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_cg.h>
32 #include <deal.II/lac/precondition.h>
33 #include <deal.II/lac/full_matrix.h>
34 #include <deal.II/lac/sparse_direct.h>
35 #include <deal.II/dofs/dof_tools.h>
36 #include <deal.II/numerics/vector_tools.h>
37 
38 #include <vector>
39 
40 #include "parameterreader.h"
41 
42 namespace DOpE
43 {
57  template <typename SPARSITYPATTERN, typename MATRIX, typename VECTOR>
59  {
60  public:
63 
64  static void declare_params(ParameterReader &param_reader);
65 
70  template<typename PROBLEM>
71  void ReInit(PROBLEM& pde);
72 
91  template<typename PROBLEM, typename INTEGRATOR>
92  void Solve(PROBLEM& pde, INTEGRATOR& integr, VECTOR &rhs, VECTOR &solution, bool force_matrix_build=false);
93 
94  protected:
95 
96  private:
97  SPARSITYPATTERN sparsity_pattern_;
98  MATRIX matrix_;
99 
100  dealii::SparseDirectUMFPACK* A_direct_;
101 
102  };
103 
104 /*********************************Implementation************************************************/
105 
106  template <typename SPARSITYPATTERN, typename MATRIX, typename VECTOR>
108  {
109  }
110 
111  /******************************************************/
112 
113  template <typename SPARSITYPATTERN, typename MATRIX, typename VECTOR>
115  ParameterReader &/*param_reader*/)
116  {
117  A_direct_ = NULL;
118  }
119 
120 /******************************************************/
121 
122 template <typename SPARSITYPATTERN, typename MATRIX, typename VECTOR>
124 {
125  if(A_direct_ != NULL)
126  {
127  delete A_direct_;
128  }
129 }
130 
131 /******************************************************/
132 
133 template <typename SPARSITYPATTERN, typename MATRIX, typename VECTOR>
134  template<typename PROBLEM>
136 {
137  matrix_.clear();
138  pde.ComputeSparsityPattern(sparsity_pattern_);
139  matrix_.reinit(sparsity_pattern_);
140 
141  if(A_direct_ != NULL)
142  {
143  delete A_direct_;
144  A_direct_= NULL;
145  }
146 }
147 
148 /******************************************************/
149 
150 template <typename SPARSITYPATTERN, typename MATRIX, typename VECTOR>
151  template<typename PROBLEM, typename INTEGRATOR>
153  INTEGRATOR& integr,
154  VECTOR &rhs,
155  VECTOR &solution,
156  bool force_matrix_build)
157 {
158  if(force_matrix_build)
159  {
160  integr.ComputeMatrix (pde,matrix_);
161  }
162 
163  integr.ApplyNewtonBoundaryValues(pde,matrix_,rhs,solution);
164 
165  if(A_direct_ == NULL)
166  {
167  A_direct_ = new dealii::SparseDirectUMFPACK;
168  A_direct_->initialize(matrix_);
169  }
170  else if(force_matrix_build)
171  {
172  A_direct_->factorize(matrix_);
173  }
174 
175  dealii::Vector<double> sol;
176  sol = rhs;
177  A_direct_->solve(sol);
178  solution = sol;
179 
180  pde.GetDoFConstraints().distribute(solution);
181 
182 }
183 
184 
185 }
186 #endif
Definition: parameterreader.h:36
~DirectLinearSolverWithMatrix()
Definition: directlinearsolver.h:123
static void declare_params(ParameterReader &param_reader)
Definition: directlinearsolver.h:107
void ReInit(PROBLEM &pde)
Definition: directlinearsolver.h:135
DirectLinearSolverWithMatrix(ParameterReader &param_reader)
Definition: directlinearsolver.h:114
void Solve(PROBLEM &pde, INTEGRATOR &integr, VECTOR &rhs, VECTOR &solution, bool force_matrix_build=false)
Definition: directlinearsolver.h:152
Definition: directlinearsolver.h:58