/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2016-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see .
\*---------------------------------------------------------------------------*/
#include "QRMatrix.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template
Foam::QRMatrix::QRMatrix(const MatrixType& M)
{
decompose(M);
}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
template
void Foam::QRMatrix::decompose(const MatrixType& M)
{
const label m = M.m();
const label n = M.n();
// Initialise the R-matrix to M
R_ = M;
// Initialise the Q-matrix to I
Q_.setSize(m);
Q_ = I;
// Pre-allocate temporary storage for the Householder steps
QMatrixType Qk(m);
QMatrixType Rk(m);
Field uk(m);
for (label k=0; k 0)
{
alpha = -alpha;
}
// uk = column k of Rk - alpha*ek
// rSumSqrUk = 2/sum(sqr(uk))
uk[k] = R_(k, k) - alpha;
cmptType rSumSqrUk = sqr(uk[k]);
for (label bi=k+1; bi
void Foam::QRMatrix::solvex
(
Field& x
) const
{
const label n = R_.n();
for (int i=n-1; i>=0; i--)
{
cmptType sum = x[i];
for (label j=i+1; j
void Foam::QRMatrix::solve
(
Field& x,
const Field& source
) const
{
const label m = Q_.m();
// x = Q_.T()*source;
for (label i=0; i
Foam::tmp>
Foam::QRMatrix::solve
(
const Field& source
) const
{
tmp> tx(new Field(Q_.m()));
Field& x = tx.ref();
solve(x, source);
return tx;
}
template
typename Foam::QRMatrix::QMatrixType
Foam::QRMatrix::inv() const
{
const label m = Q_.m();
Field x(m);
QMatrixType inv(m);
for (label i=0; i