16 #ifndef dealii_solver_minres_h 17 #define dealii_solver_minres_h 20 #include <deal.II/base/config.h> 21 #include <deal.II/lac/solver.h> 22 #include <deal.II/lac/solver_control.h> 23 #include <deal.II/base/logstream.h> 25 #include <deal.II/base/subscriptor.h> 26 #include <deal.II/base/signaling_nan.h> 28 DEAL_II_NAMESPACE_OPEN
68 template <
class VectorType = Vector<
double> >
102 template <
typename MatrixType,
typename PreconditionerType>
104 solve (
const MatrixType &A,
107 const PreconditionerType &preconditioner);
134 const VectorType &d)
const;
150 template <
class VectorType>
153 const AdditionalData &)
155 Solver<VectorType>(cn,mem),
156 res2(
numbers::signaling_nan<double>())
161 template <
class VectorType>
163 const AdditionalData &)
171 template <
class VectorType>
179 template <
class VectorType>
184 const VectorType &)
const 189 template <
class VectorType>
190 template <
typename MatrixType,
typename PreconditionerType>
195 const PreconditionerType &preconditioner)
211 typedef VectorType *vecptr;
212 vecptr u[3] = {Vu0.get(), Vu1.get(), Vu2.get()};
213 vecptr m[3] = {Vm0.get(), Vm1.get(), Vm2.get()};
218 u[0]->reinit(b,
true);
219 u[1]->reinit(b,
true);
220 u[2]->reinit(b,
true);
221 m[0]->reinit(b,
true);
222 m[1]->reinit(b,
true);
223 m[2]->reinit(b,
true);
227 double delta[3] = { 0, 0, 0 };
228 double f[2] = { 0, 0 };
229 double e[2] = { 0, 0 };
251 preconditioner.vmult (v,*u[1]);
253 delta[1] = v * (*u[1]);
255 Assert (delta[1]>=0, ExcPreconditionerNotDefinite());
257 r0 = std::sqrt(delta[1]);
271 v *= 1./std::sqrt(delta[1]);
276 u[2]->add (-std::sqrt(delta[1]/delta[0]), *u[0]);
278 const double gamma = *u[2] * v;
279 u[2]->add (-gamma / std::sqrt(delta[1]), *u[1]);
285 preconditioner.vmult(v,*u[2]);
287 delta[2] = v * (*u[2]);
289 Assert (delta[2]>=0, ExcPreconditionerNotDefinite());
294 e[1] = std::sqrt(delta[2]);
298 d_ = s *
e[0] - c * gamma;
299 e[0] = c *
e[0] + s * gamma;
300 f[1] = s * std::sqrt(delta[2]);
301 e[1] = -c * std::sqrt(delta[2]);
304 const double d = std::sqrt (d_*d_ + delta[2]);
311 s = std::sqrt(delta[2]) /
d;
316 m[0]->add (-e[0], *m[1]);
318 m[0]->add (-f[0], *m[2]);
321 r_l2 *= std::fabs(s);
323 conv = this->iteration_status(j, r_l2, x);
363 DEAL_II_NAMESPACE_CLOSE
void solve(const MatrixType &A, VectorType &x, const VectorType &b, const PreconditionerType &preconditioner)
SolverMinRes(SolverControl &cn, VectorMemory< VectorType > &mem, const AdditionalData &data=AdditionalData())
SymmetricTensor< 2, dim, Number > e(const Tensor< 2, dim, Number > &F)
#define AssertThrow(cond, exc)
void swap(BlockIndices &u, BlockIndices &v)
Stop iteration, goal reached.
#define Assert(cond, exc)
#define DeclException0(Exception0)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
virtual double criterion()
virtual ~SolverMinRes()=default
static ::ExceptionBase & ExcPreconditionerNotDefinite()
virtual void print_vectors(const unsigned int step, const VectorType &x, const VectorType &r, const VectorType &d) const