mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: support LLTMatrix, QRMatrix solve of indirect lists (#1220)
This commit is contained in:
committed by
Andrew Heather
parent
96d0a8f2af
commit
4f93bc3b5e
@ -91,10 +91,11 @@ void Foam::LLTMatrix<Type>::decompose(const SquareMatrix<Type>& mat)
|
|||||||
|
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
void Foam::LLTMatrix<Type>::solve
|
template<template<typename> class ListContainer>
|
||||||
|
void Foam::LLTMatrix<Type>::solveImpl
|
||||||
(
|
(
|
||||||
List<Type>& x,
|
List<Type>& x,
|
||||||
const UList<Type>& source
|
const ListContainer<Type>& source
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
// If x and source are different, copy initialize x = source
|
// If x and source are different, copy initialize x = source
|
||||||
@ -132,6 +133,28 @@ void Foam::LLTMatrix<Type>::solve
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
void Foam::LLTMatrix<Type>::solve
|
||||||
|
(
|
||||||
|
List<Type>& x,
|
||||||
|
const UList<Type>& source
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
solveImpl(x, source);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
template<class Addr>
|
||||||
|
void Foam::LLTMatrix<Type>::solve
|
||||||
|
(
|
||||||
|
List<Type>& x,
|
||||||
|
const IndirectListBase<Type, Addr>& source
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
solveImpl(x, source);
|
||||||
|
}
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
Foam::tmp<Foam::Field<Type>> Foam::LLTMatrix<Type>::solve
|
Foam::tmp<Foam::Field<Type>> Foam::LLTMatrix<Type>::solve
|
||||||
(
|
(
|
||||||
@ -146,4 +169,19 @@ Foam::tmp<Foam::Field<Type>> Foam::LLTMatrix<Type>::solve
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
template<class Addr>
|
||||||
|
Foam::tmp<Foam::Field<Type>> Foam::LLTMatrix<Type>::solve
|
||||||
|
(
|
||||||
|
const IndirectListBase<Type, Addr>& source
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
auto tresult(tmp<Field<Type>>::New(source.size()));
|
||||||
|
|
||||||
|
solve(tresult.ref(), source);
|
||||||
|
|
||||||
|
return tresult;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -58,6 +58,20 @@ class LLTMatrix
|
|||||||
:
|
:
|
||||||
public SquareMatrix<Type>
|
public SquareMatrix<Type>
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// 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<template<typename> class ListContainer>
|
||||||
|
void solveImpl
|
||||||
|
(
|
||||||
|
List<Type>& x,
|
||||||
|
const ListContainer<Type>& source
|
||||||
|
) const;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
@ -75,13 +89,38 @@ public:
|
|||||||
void decompose(const SquareMatrix<Type>& mat);
|
void decompose(const SquareMatrix<Type>& mat);
|
||||||
|
|
||||||
//- Solve the linear system with the given source
|
//- 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.
|
// This function may be called with the same field for x and source.
|
||||||
void solve(List<Type>& x, const UList<Type>& source) const;
|
void solve
|
||||||
|
(
|
||||||
|
List<Type>& x,
|
||||||
|
const UList<Type>& source
|
||||||
|
) const;
|
||||||
|
|
||||||
//- Solve the linear system with the given source
|
//- Solve the linear system with the given source
|
||||||
//- returning the solution
|
//- and return the solution in the argument x.
|
||||||
tmp<Field<Type>> solve(const UList<Type>& source) const;
|
// This function may be called with the same field for x and source.
|
||||||
|
template<class Addr>
|
||||||
|
void solve
|
||||||
|
(
|
||||||
|
List<Type>& x,
|
||||||
|
const IndirectListBase<Type, Addr>& source
|
||||||
|
) const;
|
||||||
|
|
||||||
|
//- Solve the linear system with the given source
|
||||||
|
//- return the solution
|
||||||
|
tmp<Field<Type>> solve
|
||||||
|
(
|
||||||
|
const UList<Type>& source
|
||||||
|
) const;
|
||||||
|
|
||||||
|
//- Solve the linear system with the given source
|
||||||
|
//- return the solution
|
||||||
|
template<class Addr>
|
||||||
|
tmp<Field<Type>> solve
|
||||||
|
(
|
||||||
|
const IndirectListBase<Type, Addr>& source
|
||||||
|
) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -326,10 +326,7 @@ public:
|
|||||||
Form T() const;
|
Form T() const;
|
||||||
|
|
||||||
//- Multiply matrix with vector (A * x)
|
//- Multiply matrix with vector (A * x)
|
||||||
inline tmp<Field<Type>> Amul
|
inline tmp<Field<Type>> Amul(const UList<Type>& x) const;
|
||||||
(
|
|
||||||
const UList<Type>& x
|
|
||||||
) const;
|
|
||||||
|
|
||||||
//- Multiply matrix with vector (A * x)
|
//- Multiply matrix with vector (A * x)
|
||||||
template<class Addr>
|
template<class Addr>
|
||||||
|
|||||||
@ -188,10 +188,11 @@ void Foam::QRMatrix<MatrixType>::solvex
|
|||||||
|
|
||||||
|
|
||||||
template<class MatrixType>
|
template<class MatrixType>
|
||||||
void Foam::QRMatrix<MatrixType>::solve
|
template<template<typename> class ListContainer>
|
||||||
|
void Foam::QRMatrix<MatrixType>::solveImpl
|
||||||
(
|
(
|
||||||
List<cmptType>& x,
|
List<cmptType>& x,
|
||||||
const UList<cmptType>& source
|
const ListContainer<cmptType>& source
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
// Assert (&x != &source) ?
|
// Assert (&x != &source) ?
|
||||||
@ -211,6 +212,29 @@ void Foam::QRMatrix<MatrixType>::solve
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class MatrixType>
|
||||||
|
void Foam::QRMatrix<MatrixType>::solve
|
||||||
|
(
|
||||||
|
List<cmptType>& x,
|
||||||
|
const UList<cmptType>& source
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
solveImpl(x, source);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class MatrixType>
|
||||||
|
template<class Addr>
|
||||||
|
void Foam::QRMatrix<MatrixType>::solve
|
||||||
|
(
|
||||||
|
List<cmptType>& x,
|
||||||
|
const IndirectListBase<cmptType, Addr>& source
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
solveImpl(x, source);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class MatrixType>
|
template<class MatrixType>
|
||||||
Foam::tmp<Foam::Field<typename MatrixType::cmptType>>
|
Foam::tmp<Foam::Field<typename MatrixType::cmptType>>
|
||||||
Foam::QRMatrix<MatrixType>::solve
|
Foam::QRMatrix<MatrixType>::solve
|
||||||
@ -218,9 +242,25 @@ Foam::QRMatrix<MatrixType>::solve
|
|||||||
const UList<cmptType>& source
|
const UList<cmptType>& source
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
auto tresult(tmp<Field<cmptType>>::New(Q_.m()));
|
auto tresult(Q_.Tmul(source));
|
||||||
|
|
||||||
solve(tresult.ref(), source);
|
solvex(tresult.ref());
|
||||||
|
|
||||||
|
return tresult;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class MatrixType>
|
||||||
|
template<class Addr>
|
||||||
|
Foam::tmp<Foam::Field<typename MatrixType::cmptType>>
|
||||||
|
Foam::QRMatrix<MatrixType>::solve
|
||||||
|
(
|
||||||
|
const IndirectListBase<cmptType, Addr>& source
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
auto tresult(Q_.Tmul(source));
|
||||||
|
|
||||||
|
solvex(tresult.ref());
|
||||||
|
|
||||||
return tresult;
|
return tresult;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -79,6 +79,15 @@ private:
|
|||||||
template<template<typename> class ListContainer>
|
template<template<typename> class ListContainer>
|
||||||
void solvex(ListContainer<cmptType>& x) const;
|
void solvex(ListContainer<cmptType>& x) const;
|
||||||
|
|
||||||
|
//- Solve the linear system with the given source
|
||||||
|
//- and return the solution in x
|
||||||
|
template<template<typename> class ListContainer>
|
||||||
|
void solveImpl
|
||||||
|
(
|
||||||
|
List<cmptType>& x,
|
||||||
|
const ListContainer<cmptType>& source
|
||||||
|
) const;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -103,12 +112,36 @@ public:
|
|||||||
void decompose(const MatrixType& M);
|
void decompose(const MatrixType& M);
|
||||||
|
|
||||||
//- Solve the linear system with the given source
|
//- Solve the linear system with the given source
|
||||||
//- and return the solution in the Field argument x
|
//- and return the solution in the argument x
|
||||||
void solve(List<cmptType>& x, const UList<cmptType>& source) const;
|
void solve
|
||||||
|
(
|
||||||
|
List<cmptType>& x,
|
||||||
|
const UList<cmptType>& source
|
||||||
|
) const;
|
||||||
|
|
||||||
|
//- Solve the linear system with the given source
|
||||||
|
//- and return the solution in the argument x
|
||||||
|
template<class Addr>
|
||||||
|
void solve
|
||||||
|
(
|
||||||
|
List<cmptType>& x,
|
||||||
|
const IndirectListBase<cmptType, Addr>& source
|
||||||
|
) const;
|
||||||
|
|
||||||
//- Solve the linear system with the given source
|
//- Solve the linear system with the given source
|
||||||
//- and return the solution
|
//- and return the solution
|
||||||
tmp<Field<cmptType>> solve(const UList<cmptType>& source) const;
|
tmp<Field<cmptType>> solve
|
||||||
|
(
|
||||||
|
const UList<cmptType>& source
|
||||||
|
) const;
|
||||||
|
|
||||||
|
//- Solve the linear system with the given source
|
||||||
|
//- and return the solution
|
||||||
|
template<class Addr>
|
||||||
|
tmp<Field<cmptType>> solve
|
||||||
|
(
|
||||||
|
const IndirectListBase<cmptType, Addr>& source
|
||||||
|
) const;
|
||||||
|
|
||||||
//- Return the inverse of (Q*R), so that solving x = (Q*R).inv()*source
|
//- Return the inverse of (Q*R), so that solving x = (Q*R).inv()*source
|
||||||
QMatrixType inv() const;
|
QMatrixType inv() const;
|
||||||
|
|||||||
Reference in New Issue
Block a user