15#ifndef dealii_solver_idr_h
16#define dealii_solver_idr_h
52 template <
typename VectorType>
80 operator()(
const unsigned int i,
const VectorType &temp);
91 std::vector<typename VectorMemory<VectorType>::Pointer>
data;
118template <
typename VectorType = Vector<
double>>
135 const unsigned int s;
160 template <
typename MatrixType,
typename PreconditionerType>
167 const PreconditionerType &preconditioner);
179 const VectorType &d) const;
196 namespace SolverIDRImplementation
198 template <
typename VectorType>
207 template <
typename VectorType>
219 template <
typename VectorType>
222 const VectorType &temp)
225 if (data[i] ==
nullptr)
228 data[i]->reinit(temp,
true);
235 template <
typename VectorType,
236 std::enable_if_t<!IsBlockVector<VectorType>::value, VectorType>
239 n_blocks(
const VectorType &)
246 template <
typename VectorType,
247 std::enable_if_t<IsBlockVector<VectorType>::value, VectorType> * =
250 n_blocks(
const VectorType &vector)
252 return vector.n_blocks();
257 template <
typename VectorType,
258 std::enable_if_t<!IsBlockVector<VectorType>::value, VectorType>
261 block(VectorType &vector,
const unsigned int b)
269 template <
typename VectorType,
270 std::enable_if_t<IsBlockVector<VectorType>::value, VectorType> * =
272 typename VectorType::BlockType &
273 block(VectorType &vector,
const unsigned int b)
275 return vector.block(b);
283template <
typename VectorType>
287 const AdditionalData &data)
289 , additional_data(data)
294template <
typename VectorType>
298 , additional_data(data)
303template <
typename VectorType>
308 const VectorType &)
const
313template <
typename VectorType>
315template <
typename MatrixType,
typename PreconditionerType>
322 const PreconditionerType &preconditioner)
327 unsigned int step = 0;
329 const unsigned int s = additional_data.
s;
336 VectorType &r = *r_pointer;
337 VectorType &v = *v_pointer;
338 VectorType &uhat = *uhat_pointer;
342 uhat.reinit(x,
true);
346 r.sadd(-1.0, 1.0, b);
348 using value_type =
typename VectorType::value_type;
352 real_type res = r.l2_norm();
353 iteration_state = this->iteration_status(step, res, x);
366 std::normal_distribution<> normal_distribution(0.0, 1.0);
367 for (
unsigned int i = 0; i < s; ++i)
378 VectorType &tmp_q = Q(i, x);
381 for (
unsigned int b = 0;
382 b < internal::SolverIDRImplementation::n_blocks(tmp_q);
384 for (
auto indx : internal::SolverIDRImplementation::block(tmp_q, b)
385 .locally_owned_elements())
386 internal::SolverIDRImplementation::block(tmp_q, b)(indx) =
387 normal_distribution(rng);
393 for (
unsigned int j = 0; j < i; ++j)
396 v *= (v * tmp_q) / (tmp_q * tmp_q);
401 tmp_q *= 1.0 / tmp_q.l2_norm();
406 value_type omega = 1.;
408 bool early_exit =
false;
417 for (
unsigned int i = 0; i < s; ++i)
421 for (
unsigned int k = 0; k < s; ++k)
428 std::vector<unsigned int> indices;
430 for (
unsigned int i = k; i < s; ++i, ++j)
432 indices.push_back(i);
435 Mk.extract_submatrix_from(M, indices, indices);
439 Mk_inv.vmult(gamma, phik);
446 for (
unsigned int i = k, j = 0; i < s; ++i, ++j)
447 v.add(-
gamma(j), G[i]);
450 preconditioner.vmult(uhat, v);
454 uhat.sadd(omega,
gamma(0), U[k]);
455 for (
unsigned int i = k + 1, j = 1; i < s; ++i, ++j)
456 uhat.add(
gamma(j), U[i]);
467 value_type alpha = Q[0] * G[k] / M(0, 0);
468 for (
unsigned int i = 1; i < k; ++i)
470 const value_type alpha_old = alpha;
471 alpha = G[k].add_and_dot(-alpha, G[i - 1], Q[i]) / M(i, i);
475 uhat.add(-alpha_old, U[i - 1], -alpha, U[i]);
477 M(k, k) = G[k].add_and_dot(-alpha, G[k - 1], Q[k]);
479 uhat.add(-alpha, U[k - 1]);
482 M(k, k) = G[k] * Q[k];
487 for (
unsigned int i = k + 1; i < s; ++i)
488 M(i, k) = Q[i] * G[k];
492 const value_type beta = phi(k) / M(k, k);
496 print_vectors(step, x, r, U[k]);
502 iteration_state = this->iteration_status(step, res, x);
512 for (
unsigned int i = 0; i < k + 1; ++i)
514 for (
unsigned int i = k + 1; i < s; ++i)
515 phi(i) -= beta * M(i, k);
519 if (early_exit ==
true)
523 preconditioner.vmult(uhat, r);
526 omega = (v * r) / (v * v);
528 res =
std::sqrt(r.add_and_dot(-1.0 * omega, v, r));
531 print_vectors(step, x, r, uhat);
534 iteration_state = this->iteration_status(step, res, x);
SolverBase(SolverControl &solver_control, VectorMemory< VectorType > &vector_memory)
@ 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())
AdditionalData additional_data
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)
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)