22#ifndef INCLUDE_EXADG_FLUID_STRUCTURE_INTERACTION_ACCELERATION_SCHEMES_LINEAR_ALGEBRA_H_
23#define INCLUDE_EXADG_FLUID_STRUCTURE_INTERACTION_ACCELERATION_SCHEMES_LINEAR_ALGEBRA_H_
29#include <deal.II/base/exceptions.h>
38template<
typename Number>
43 Matrix(
unsigned int const size) : M(size)
53 for(
unsigned int i = 0; i < M; ++i)
54 for(
unsigned int j = 0; j < M; ++j)
55 data[i * M + j] = Number(0.0);
59 get(
unsigned int const i,
unsigned int const j)
const
61 AssertThrow(i < M and j < M, dealii::ExcMessage(
"Index exceeds matrix dimensions."));
63 return data[i * M + j];
67 set(Number
const value,
unsigned int const i,
unsigned int const j)
69 AssertThrow(i < M and j < M, dealii::ExcMessage(
"Index exceeds matrix dimensions."));
71 data[i * M + j] = value;
77 std::vector<Number> data;
80template<
typename VectorType,
typename Number>
82compute_QR_decomposition(std::vector<VectorType> & Q,
Matrix<Number> & R, Number
const eps = 1.e-2)
84 for(
unsigned int i = 0; i < Q.size(); ++i)
86 Number
const norm_initial = Number(Q[i].l2_norm());
89 for(
unsigned int j = 0; j < i; ++j)
91 Number r_ji = Q[j] * Q[i];
93 Q[i].add(-r_ji, Q[j]);
97 Number r_ii = Number(Q[i].l2_norm());
98 if(r_ii < eps * norm_initial)
101 for(
unsigned int j = 0; j < i; ++j)
116template<
typename Number>
119 std::vector<Number> & dst,
120 std::vector<Number>
const & rhs)
122 int const n = dst.size();
124 for(
int i = n - 1; i >= 0; --i)
126 double value = rhs[i];
127 for(
int j = i + 1; j < n; ++j)
129 value -= matrix.get(i, j) * dst[j];
132 dst[i] = value / matrix.get(i, i);
136template<
typename Number,
typename VectorType>
139 std::vector<VectorType> & dst,
140 std::vector<VectorType>
const & rhs)
142 int const n = dst.size();
144 for(
int i = n - 1; i >= 0; --i)
146 VectorType value = rhs[i];
147 for(
int j = i + 1; j < n; ++j)
149 value.add(-matrix.get(i, j), dst[j]);
152 dst[i].equ(1.0 / matrix.get(i, i), value);
156template<
typename VectorType>
158inv_jacobian_times_residual(VectorType & b,
159 std::vector<std::shared_ptr<std::vector<VectorType>>>
const & D_history,
160 std::vector<std::shared_ptr<std::vector<VectorType>>>
const & R_history,
161 std::vector<std::shared_ptr<std::vector<VectorType>>>
const & Z_history,
162 VectorType
const & residual)
164 VectorType a = residual;
169 for(
int idx = Z_history.size() - 1; idx >= 0; --idx)
171 std::shared_ptr<std::vector<VectorType>> D = D_history[idx];
172 std::shared_ptr<std::vector<VectorType>> R = R_history[idx];
173 std::shared_ptr<std::vector<VectorType>> Z = Z_history[idx];
175 int const k = Z->size();
176 std::vector<double> Z_times_a(k, 0.0);
177 for(
int i = 0; i < k; ++i)
178 Z_times_a[i] = (*Z)[i] * a;
181 for(
int i = 0; i < k; ++i)
182 b.add(Z_times_a[i], (*D)[i]);
185 for(
int i = 0; i < k; ++i)
186 a.add(-Z_times_a[i], (*R)[i]);
Definition linear_algebra.h:40