13 #if !defined(KRATOS_DENSE_HOUSEHOLDER_QR_H_INCLUDED)
14 #define KRATOS_DENSE_HOUSEHOLDER_QR_H_INCLUDED
17 #include "amgcl/detail/qr.hpp"
43 template <
class TDenseSpaceType>
54 using DataType =
typename TDenseSpaceType::DataType;
83 return "dense_householder_qr_decomposition";
98 const std::size_t
m = rInputMatrix.size1();
99 const std::size_t
n = rInputMatrix.size2();
102 mHouseholderQR.compute(
m,
n, p_0_0);
122 const std::size_t
m = rInputMatrix.size1();
123 const std::size_t
n = rInputMatrix.size2();
126 mHouseholderQR.factorize(
m,
n, p_0_0);
129 if (rMatrixQ.size1() !=
m || rMatrixQ.size2() !=
n) {
130 rMatrixQ.resize(
m,
n,
false);
132 for (std::size_t
i = 0;
i <
m; ++
i) {
133 for (std::size_t
j = 0;
j <
n; ++
j) {
134 rMatrixQ(
i,
j) = mHouseholderQR.Q(
i,
j);
153 KRATOS_ERROR_IF(!mpA) <<
"QR decomposition not computed yet. Please call 'Compute' before 'Solve'." << std::endl;
157 const std::size_t
m = mpA->size1();
158 const std::size_t
n = mpA->size2();
161 const std::size_t
l = rB.size2();
162 if (rX.size1() !=
n || rX.size2() !=
l) {
163 rX.resize(
n,
l,
false);
169 const bool qr_computed =
true;
170 auto storage_order = amgcl::detail::storage_order::row_major;
171 for (std::size_t i_col = 0; i_col <
l; ++i_col) {
172 TDenseSpaceType::GetColumn(i_col, rB, aux_B_col);
173 TDenseSpaceType::GetColumn(i_col, rX, aux_X_col);
176 const_cast<AMGCLQRType&
>(mHouseholderQR).
solve(
m,
n, p_A_0_0, p_b_0, p_x_0, storage_order, qr_computed);
177 TDenseSpaceType::SetColumn(i_col, rX, aux_X_col);
192 KRATOS_ERROR_IF(!mpA) <<
"QR decomposition not computed yet. Please call 'Compute' before 'Solve'." << std::endl;
198 const std::size_t
m = mpA->size1();
199 const std::size_t
n = mpA->size2();
202 if (rX.size() !=
n) {
207 const bool qr_computed =
true;
208 auto storage_order = amgcl::detail::storage_order::row_major;
209 const_cast<AMGCLQRType&
>(mHouseholderQR).
solve(
m,
n, p_A_0_0, p_b_0, p_x_0, storage_order, qr_computed);
221 KRATOS_ERROR <<
"This method is not implemented. Please use the 'Compute' interface with Q and R return." << std::endl;
232 KRATOS_ERROR_IF(!mpA) <<
"QR decomposition not computed yet. Please call 'Compute' before 'MatrixR'." << std::endl;
235 const std::size_t
n = mpA->size2();
236 if (rMatrixR.size1() !=
n || rMatrixR.size2() !=
n) {
237 rMatrixR.resize(
n,
n,
false);
241 for (std::size_t
i = 0;
i <
n; ++
i) {
242 for (std::size_t
j = 0;
j <
n; ++
j) {
243 rMatrixR(
i,
j) = mHouseholderQR.R(
i,
j);
255 KRATOS_ERROR <<
"Householder QR decomposition does not implement the P matrix return" << std::endl;
263 std::size_t
Rank()
const override
265 KRATOS_ERROR <<
"Householder QR decomposition is not rank revealing." << std::endl;
275 rOStream <<
"Decomposition <" <<
Name() <<
"> finished.";
Definition: dense_householder_qr_decomposition.h:45
typename TDenseSpaceType::MatrixType MatrixType
Definition: dense_householder_qr_decomposition.h:56
void MatrixR(MatrixType &rMatrixR) const override
Upper triangular matrix getter If computed, this method sets the upper triangular matrix in the provi...
Definition: dense_householder_qr_decomposition.h:229
typename TDenseSpaceType::VectorType VectorType
Definition: dense_householder_qr_decomposition.h:55
void Solve(const VectorType &rB, VectorType &rX) const override
Solves the problem Ax=b Being A the input matrix, this method solves the problem Ax = b.
Definition: dense_householder_qr_decomposition.h:187
DenseHouseholderQRDecomposition()=default
void MatrixP(MatrixType &rMatrixP) const override
Pivoting matrix getter If computed, this method sets the pivoting matrix.
Definition: dense_householder_qr_decomposition.h:253
KRATOS_CLASS_POINTER_DEFINITION(DenseHouseholderQRDecomposition)
Definition of the shared pointer of the class.
static std::string Name()
Name of the QR Returns a string containing the name of the current QR decomposition.
Definition: dense_householder_qr_decomposition.h:81
virtual ~DenseHouseholderQRDecomposition()=default
void PrintInfo(std::ostream &rOStream) const override
QR information Outputs the QR class information.
Definition: dense_householder_qr_decomposition.h:273
void Compute(MatrixType &rInputMatrix) override
Compute the QR Computes the QR Decomposition (QR) of the given imput matrix Note that the input matri...
Definition: dense_householder_qr_decomposition.h:92
std::size_t Rank() const override
Rank of the provided array Calculates and returns the rank of the array decomposed with the QR.
Definition: dense_householder_qr_decomposition.h:263
void Solve(MatrixType &rB, MatrixType &rX) const override
Solves the problem Ax=b Being A the input matrix, this method solves the problem Ax = b.
Definition: dense_householder_qr_decomposition.h:148
typename TDenseSpaceType::DataType DataType
Definition: dense_householder_qr_decomposition.h:54
void Compute(MatrixType &rInputMatrix, MatrixType &rMatrixQ, MatrixType &rMatrixR) override
Compute the QR Computes the QR (QR) of the given input matrix Note that the input matrix is modidifed...
Definition: dense_householder_qr_decomposition.h:113
amgcl::detail::QR< DataType > AMGCLQRType
Definition: dense_householder_qr_decomposition.h:57
void MatrixQ(MatrixType &rMatrixQ) const override
Unitary matrix getter If computed, this method sets the unitary matrix in the provided array.
Definition: dense_householder_qr_decomposition.h:217
Definition: dense_qr_decomposition.h:44
#define KRATOS_ERROR
Definition: exception.h:161
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
def solve(A, rhs)
Definition: ode_solve.py:303
int n
manufactured solution and derivatives (u=0 at z=0 dudz=0 at z=domain_height)
Definition: ode_solve.py:402
int j
Definition: quadrature.py:648
int m
Definition: run_marine_rain_substepping.py:8
integer i
Definition: TensorModule.f:17
integer l
Definition: TensorModule.f:17