13#ifndef dealii_solver_idr_h
14#define dealii_solver_idr_h
44 namespace SolverIDRImplementation
50 template <
typename VectorType>
78 operator()(
const unsigned int i,
const VectorType &temp);
89 std::vector<typename VectorMemory<VectorType>::Pointer>
data;
116template <
typename VectorType = Vector<
double>>
133 const unsigned int s;
158 template <
typename MatrixType,
typename PreconditionerType>
162 void solve(const MatrixType &A,
165 const PreconditionerType &preconditioner);
174 print_vectors(const
unsigned int step,
177 const VectorType &d) const;
194 namespace SolverIDRImplementation
196 template <
typename VectorType>
205 template <
typename VectorType>
217 template <
typename VectorType>
220 const VectorType &temp)
223 if (
data[i] ==
nullptr)
226 data[i]->reinit(temp,
true);
233 template <
typename VectorType,
234 std::enable_if_t<!IsBlockVector<VectorType>::value, VectorType>
237 n_blocks(
const VectorType &)
244 template <
typename VectorType,
245 std::enable_if_t<IsBlockVector<VectorType>::value, VectorType> * =
248 n_blocks(
const VectorType &vector)
250 return vector.n_blocks();
255 template <
typename VectorType,
256 std::enable_if_t<!IsBlockVector<VectorType>::value, VectorType>
259 block(VectorType &vector,
const unsigned int b)
267 template <
typename VectorType,
268 std::enable_if_t<IsBlockVector<VectorType>::value, VectorType> * =
270 typename VectorType::BlockType &
271 block(VectorType &vector,
const unsigned int b)
273 return vector.block(b);
281template <
typename VectorType>
285 const AdditionalData &
data)
287 , additional_data(
data)
292template <
typename VectorType>
296 , additional_data(
data)
301template <
typename VectorType>
306 const VectorType &)
const
311template <
typename VectorType>
313template <
typename MatrixType,
typename PreconditionerType>
320 const PreconditionerType &preconditioner)
325 unsigned int step = 0;
327 const unsigned int s = additional_data.
s;
340 uhat.reinit(x,
true);
344 r.sadd(-1.0, 1.0, b);
346 using value_type =
typename VectorType::value_type;
350 real_type res = r.l2_norm();
351 iteration_state = this->iteration_status(step, res, x);
364 std::normal_distribution<> normal_distribution(0.0, 1.0);
365 for (
unsigned int i = 0; i < s; ++i)
379 for (
unsigned int b = 0;
380 b < internal::SolverIDRImplementation::n_blocks(tmp_q);
382 for (
auto index :
internal::SolverIDRImplementation::block(tmp_q,
b)
383 .locally_owned_elements())
385 normal_distribution(rng);
391 for (
unsigned int j = 0; j < i; ++j)
394 v *= (v * tmp_q) / (tmp_q * tmp_q);
399 tmp_q *= 1.0 / tmp_q.l2_norm();
406 bool early_exit =
false;
415 for (
unsigned int i = 0; i < s; ++i)
419 for (
unsigned int k = 0; k < s; ++k)
426 std::vector<unsigned int> indices;
428 for (
unsigned int i = k; i < s; ++i, ++j)
430 indices.push_back(i);
433 Mk.extract_submatrix_from(M, indices, indices);
437 Mk_inv.vmult(gamma, phik);
444 for (
unsigned int i = k, j = 0; i < s; ++i, ++j)
445 v.add(-
gamma(j), G[i]);
448 preconditioner.vmult(uhat, v);
452 uhat.sadd(omega,
gamma(0), U[k]);
453 for (
unsigned int i = k + 1, j = 1; i < s; ++i, ++j)
454 uhat.add(
gamma(j), U[i]);
466 for (
unsigned int i = 1; i < k; ++i)
469 alpha = G[k].add_and_dot(-alpha, G[i - 1], Q[i]) / M(i, i);
473 uhat.add(-alpha_old, U[i - 1], -alpha, U[i]);
475 M(k, k) = G[k].add_and_dot(-alpha, G[k - 1], Q[k]);
477 uhat.add(-alpha, U[k - 1]);
480 M(k, k) = G[k] * Q[k];
485 for (
unsigned int i = k + 1; i < s; ++i)
486 M(i, k) = Q[i] * G[k];
494 print_vectors(step, x, r, U[k]);
500 iteration_state = this->iteration_status(step, res, x);
510 for (
unsigned int i = 0; i < k + 1; ++i)
512 for (
unsigned int i = k + 1; i < s; ++i)
513 phi(i) -= beta * M(i, k);
517 if (early_exit ==
true)
521 preconditioner.vmult(uhat, r);
524 omega = (v * r) / (v * v);
526 res =
std::sqrt(r.add_and_dot(-1.0 * omega, v, r));
529 print_vectors(step, x, r, uhat);
532 iteration_state = this->iteration_status(step, res, x);
@ iterate
Continue iteration.
@ success
Stop iteration, goal reached.
virtual void print_vectors(const unsigned int step, const VectorType &x, const VectorType &r, const VectorType &d) const
SolverIDR(SolverControl &cn, const AdditionalData &data=AdditionalData())
void solve(const MatrixType &A, VectorType &x, const VectorType &b, const PreconditionerType &preconditioner)
SolverIDR(SolverControl &cn, VectorMemory< VectorType > &mem, const AdditionalData &data=AdditionalData())
virtual ~SolverIDR() override=default
TmpVectors(const unsigned int s_param, VectorMemory< VectorType > &vmem)
VectorType & operator()(const unsigned int i, const VectorType &temp)
VectorType & operator[](const unsigned int i) const
VectorMemory< VectorType > & mem
std::vector< typename VectorMemory< VectorType >::Pointer > data
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_CXX20_REQUIRES(condition)
#define DEAL_II_NAMESPACE_CLOSE
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcNotInitialized()
#define AssertThrow(cond, exc)
std::vector< index_type > data
Tpetra::Vector< Number, LO, GO, NodeType< MemorySpace > > VectorType
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
long double gamma(const unsigned int n)
::VectorizedArray< Number, width > sqrt(const ::VectorizedArray< Number, width > &)
AdditionalData(const unsigned int s=2)