diff --git a/src/OpenFOAM/matrices/LLTMatrix/LLTMatrix.C b/src/OpenFOAM/matrices/LLTMatrix/LLTMatrix.C index 9208048b28..9f0422ca43 100644 --- a/src/OpenFOAM/matrices/LLTMatrix/LLTMatrix.C +++ b/src/OpenFOAM/matrices/LLTMatrix/LLTMatrix.C @@ -91,10 +91,11 @@ void Foam::LLTMatrix::decompose(const SquareMatrix& mat) template -void Foam::LLTMatrix::solve +template class ListContainer> +void Foam::LLTMatrix::solveImpl ( List& x, - const UList& source + const ListContainer& source ) const { // If x and source are different, copy initialize x = source @@ -132,6 +133,28 @@ void Foam::LLTMatrix::solve } +template +void Foam::LLTMatrix::solve +( + List& x, + const UList& source +) const +{ + solveImpl(x, source); +} + + +template +template +void Foam::LLTMatrix::solve +( + List& x, + const IndirectListBase& source +) const +{ + solveImpl(x, source); +} + template Foam::tmp> Foam::LLTMatrix::solve ( @@ -146,4 +169,19 @@ Foam::tmp> Foam::LLTMatrix::solve } +template +template +Foam::tmp> Foam::LLTMatrix::solve +( + const IndirectListBase& source +) const +{ + auto tresult(tmp>::New(source.size())); + + solve(tresult.ref(), source); + + return tresult; +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/matrices/LLTMatrix/LLTMatrix.H b/src/OpenFOAM/matrices/LLTMatrix/LLTMatrix.H index a9f853e41c..ac7753ddd6 100644 --- a/src/OpenFOAM/matrices/LLTMatrix/LLTMatrix.H +++ b/src/OpenFOAM/matrices/LLTMatrix/LLTMatrix.H @@ -58,6 +58,20 @@ class LLTMatrix : public SquareMatrix { + + // Private Member Functions + + //- Solve the linear system with the given source + //- and return the solution in x + // This function may be called with the same field for x and source. + template class ListContainer> + void solveImpl + ( + List& x, + const ListContainer& source + ) const; + + public: // Constructors @@ -75,13 +89,38 @@ public: void decompose(const SquareMatrix& mat); //- Solve the linear system with the given source - //- and returning the solution in the Field argument x. + //- and return the solution in the argument x. // This function may be called with the same field for x and source. - void solve(List& x, const UList& source) const; + void solve + ( + List& x, + const UList& source + ) const; //- Solve the linear system with the given source - //- returning the solution - tmp> solve(const UList& source) const; + //- and return the solution in the argument x. + // This function may be called with the same field for x and source. + template + void solve + ( + List& x, + const IndirectListBase& source + ) const; + + //- Solve the linear system with the given source + //- return the solution + tmp> solve + ( + const UList& source + ) const; + + //- Solve the linear system with the given source + //- return the solution + template + tmp> solve + ( + const IndirectListBase& source + ) const; }; diff --git a/src/OpenFOAM/matrices/Matrix/Matrix.H b/src/OpenFOAM/matrices/Matrix/Matrix.H index 6024d21c18..bfe1c4e51f 100644 --- a/src/OpenFOAM/matrices/Matrix/Matrix.H +++ b/src/OpenFOAM/matrices/Matrix/Matrix.H @@ -326,10 +326,7 @@ public: Form T() const; //- Multiply matrix with vector (A * x) - inline tmp> Amul - ( - const UList& x - ) const; + inline tmp> Amul(const UList& x) const; //- Multiply matrix with vector (A * x) template diff --git a/src/OpenFOAM/matrices/QRMatrix/QRMatrix.C b/src/OpenFOAM/matrices/QRMatrix/QRMatrix.C index 6c1ad97928..ea3c437a86 100644 --- a/src/OpenFOAM/matrices/QRMatrix/QRMatrix.C +++ b/src/OpenFOAM/matrices/QRMatrix/QRMatrix.C @@ -188,10 +188,11 @@ void Foam::QRMatrix::solvex template -void Foam::QRMatrix::solve +template class ListContainer> +void Foam::QRMatrix::solveImpl ( List& x, - const UList& source + const ListContainer& source ) const { // Assert (&x != &source) ? @@ -211,6 +212,29 @@ void Foam::QRMatrix::solve } +template +void Foam::QRMatrix::solve +( + List& x, + const UList& source +) const +{ + solveImpl(x, source); +} + + +template +template +void Foam::QRMatrix::solve +( + List& x, + const IndirectListBase& source +) const +{ + solveImpl(x, source); +} + + template Foam::tmp> Foam::QRMatrix::solve @@ -218,9 +242,25 @@ Foam::QRMatrix::solve const UList& source ) const { - auto tresult(tmp>::New(Q_.m())); + auto tresult(Q_.Tmul(source)); - solve(tresult.ref(), source); + solvex(tresult.ref()); + + return tresult; +} + + +template +template +Foam::tmp> +Foam::QRMatrix::solve +( + const IndirectListBase& source +) const +{ + auto tresult(Q_.Tmul(source)); + + solvex(tresult.ref()); return tresult; } diff --git a/src/OpenFOAM/matrices/QRMatrix/QRMatrix.H b/src/OpenFOAM/matrices/QRMatrix/QRMatrix.H index b716cd1954..0dc739ce93 100644 --- a/src/OpenFOAM/matrices/QRMatrix/QRMatrix.H +++ b/src/OpenFOAM/matrices/QRMatrix/QRMatrix.H @@ -79,6 +79,15 @@ private: template class ListContainer> void solvex(ListContainer& x) const; + //- Solve the linear system with the given source + //- and return the solution in x + template class ListContainer> + void solveImpl + ( + List& x, + const ListContainer& source + ) const; + public: @@ -103,12 +112,36 @@ public: void decompose(const MatrixType& M); //- Solve the linear system with the given source - //- and return the solution in the Field argument x - void solve(List& x, const UList& source) const; + //- and return the solution in the argument x + void solve + ( + List& x, + const UList& source + ) const; + + //- Solve the linear system with the given source + //- and return the solution in the argument x + template + void solve + ( + List& x, + const IndirectListBase& source + ) const; //- Solve the linear system with the given source //- and return the solution - tmp> solve(const UList& source) const; + tmp> solve + ( + const UList& source + ) const; + + //- Solve the linear system with the given source + //- and return the solution + template + tmp> solve + ( + const IndirectListBase& source + ) const; //- Return the inverse of (Q*R), so that solving x = (Q*R).inv()*source QMatrixType inv() const;