13#ifndef dealii_solver_bicgstab_h
14#define dealii_solver_bicgstab_h
76template <
typename VectorType = Vector<
double>>
101 const bool exact_residual =
true,
102 const double breakdown =
103 std::numeric_limits<typename VectorType::value_type>::min())
104 : exact_residual(exact_residual)
105 , breakdown(breakdown)
139 template <
typename MatrixType,
typename PreconditionerType>
143 void solve(const MatrixType &A,
146 const PreconditionerType &preconditioner);
152 template <typename MatrixType>
154 criterion(const MatrixType &A,
165 print_vectors(const
unsigned int step,
168 const VectorType &d) const;
189 const unsigned int last_step,
190 const double last_residual);
197 template <
typename MatrixType,
typename PreconditionerType>
202 const PreconditionerType &preconditioner,
203 const unsigned int step);
213template <
typename VectorType>
216 const bool breakdown,
218 const unsigned int last_step,
219 const double last_residual)
220 : breakdown(breakdown)
222 , last_step(last_step)
223 , last_residual(last_residual)
228template <
typename VectorType>
232 const AdditionalData &
data)
234 , additional_data(
data)
239template <
typename VectorType>
242 const AdditionalData &
data)
244 , additional_data(
data)
249template <
typename VectorType>
251template <
typename MatrixType>
258 return std::sqrt(t.add_and_dot(-1.0, b, t));
263template <
typename VectorType>
268 const VectorType &)
const
273template <
typename VectorType>
275template <
typename MatrixType,
typename PreconditionerType>
280 const PreconditionerType &preconditioner,
281 const unsigned int last_step)
302 rbar.reinit(x,
true);
309 using value_type =
typename VectorType::value_type;
316 unsigned int step = last_step;
320 return IterationResult(
false, state, step, res);
332 const value_type rhobar = (step == 1 + last_step) ? res * res : r * rbar;
334 if (std::fabs(rhobar) < additional_data.breakdown)
336 return IterationResult(
true, state, step, res);
339 const value_type beta = rhobar * alpha / (rho * omega);
341 if (step == last_step + 1)
348 p.add(-beta * omega, v);
351 preconditioner.vmult(y, p);
354 if (std::fabs(rbar_dot_v) < additional_data.breakdown)
356 return IterationResult(
true, state, step, res);
359 alpha = rho / rbar_dot_v;
361 res =
std::sqrt(real_type(r.add_and_dot(-alpha, v, r)));
372 print_vectors(step, x, r, y);
376 preconditioner.vmult(z, r);
379 const real_type t_squared = t * t;
380 if (t_squared < additional_data.breakdown)
382 return IterationResult(
true, state, step, res);
384 omega = t_dot_r / t_squared;
385 x.add(alpha, y, omega, z);
387 if (additional_data.exact_residual)
390 res = criterion(A, x, b, t);
393 res =
std::sqrt(real_type(r.add_and_dot(-omega, t, r)));
395 state = this->iteration_status(step, res, x);
396 print_vectors(step, x, r, y);
400 return IterationResult(
false, state, step, res);
405template <
typename VectorType>
407template <
typename MatrixType,
typename PreconditionerType>
414 const PreconditionerType &preconditioner)
421 state = iterate(A, x, b, preconditioner, state.last_step);
428 state.last_residual));
double criterion(const MatrixType &A, const VectorType &x, const VectorType &b, VectorType &t)
virtual void print_vectors(const unsigned int step, const VectorType &x, const VectorType &r, const VectorType &d) const
virtual ~SolverBicgstab() override=default
SolverBicgstab(SolverControl &cn, VectorMemory< VectorType > &mem, const AdditionalData &data=AdditionalData())
SolverBicgstab(SolverControl &cn, const AdditionalData &data=AdditionalData())
IterationResult iterate(const MatrixType &A, VectorType &x, const VectorType &b, const PreconditionerType &preconditioner, const unsigned int step)
void solve(const MatrixType &A, VectorType &x, const VectorType &b, const PreconditionerType &preconditioner)
@ iterate
Continue iteration.
@ success
Stop iteration, goal reached.
@ failure
Stop iteration, goal not reached.
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_CXX20_REQUIRES(condition)
#define DEAL_II_NAMESPACE_CLOSE
#define AssertThrow(cond, exc)
std::vector< index_type > data
Tpetra::Vector< Number, LO, GO, NodeType< MemorySpace > > VectorType
::VectorizedArray< Number, width > sqrt(const ::VectorizedArray< Number, width > &)
AdditionalData(const bool exact_residual=true, const double breakdown=std::numeric_limits< typename VectorType::value_type >::min())
SolverControl::State state
IterationResult(const bool breakdown, const SolverControl::State state, const unsigned int last_step, const double last_residual)