53#ifndef Foam_LduMatrix_H
54#define Foam_LduMatrix_H
73template<
class Type,
class DType,
class LUType>
class LduMatrix;
75template<
class Type,
class DType,
class LUType>
87template<
class Type,
class DType,
class LUType>
96 std::unique_ptr<Field<DType>> diagPtr_;
99 std::unique_ptr<Field<LUType>> upperPtr_;
102 std::unique_ptr<Field<LUType>> lowerPtr_;
105 std::unique_ptr<Field<Type>> sourcePtr_;
167 dict.readIfPresent(key, val);
174 virtual const word&
type()
const = 0;
299 virtual const word&
type()
const = 0;
397 virtual const word&
type()
const = 0;
411 (sol, preconditionerDict)
423 (sol, preconditionerDict)
524 return lduMesh_.lduAddr();
530 return lduMesh_.lduAddr().patchSchedule();
563 return interfacesUpper_;
568 return interfacesLower_;
573 return interfacesUpper_;
578 return interfacesLower_;
595 return (diagPtr_ && !lowerPtr_ && !upperPtr_);
601 return (diagPtr_ && !lowerPtr_ && upperPtr_);
607 return (diagPtr_ && lowerPtr_ && upperPtr_);
651 const label startRequest
695#define makeLduMatrix(Type, DType, LUType) \
697typedef Foam::LduMatrix<Type, DType, LUType> \
698 ldu##Type##DType##LUType##Matrix; \
700defineNamedTemplateTypeNameAndDebug(ldu##Type##DType##LUType##Matrix, 0); \
703typedef LduMatrix<Type, DType, LUType>::smoother \
704 ldu##Type##DType##LUType##Smoother; \
706defineTemplateRunTimeSelectionTable \
708 ldu##Type##DType##LUType##Smoother, \
712defineTemplateRunTimeSelectionTable \
714 ldu##Type##DType##LUType##Smoother, \
719typedef LduMatrix<Type, DType, LUType>::preconditioner \
720 ldu##Type##DType##LUType##Preconditioner; \
722defineTemplateRunTimeSelectionTable \
724 ldu##Type##DType##LUType##Preconditioner, \
728defineTemplateRunTimeSelectionTable \
730 ldu##Type##DType##LUType##Preconditioner, \
735typedef LduMatrix<Type, DType, LUType>::solver \
736 ldu##Type##DType##LUType##Solver; \
738defineTemplateRunTimeSelectionTable \
740 ldu##Type##DType##LUType##Solver, \
744defineTemplateRunTimeSelectionTable \
746 ldu##Type##DType##LUType##Solver, \
751#define makeLduPreconditioner(Precon, Type, DType, LUType) \
753typedef Precon<Type, DType, LUType> \
754 Precon##Type##DType##LUType##Preconditioner; \
755defineNamedTemplateTypeNameAndDebug \
757 Precon##Type##DType##LUType##Preconditioner, \
761#define makeLduSymPreconditioner(Precon, Type, DType, LUType) \
763LduMatrix<Type, DType, LUType>::preconditioner:: \
764addsymMatrixConstructorToTable<Precon##Type##DType##LUType##Preconditioner> \
765add##Precon##Type##DType##LUType##PreconditionerSymMatrixConstructorToTable_;
767#define makeLduAsymPreconditioner(Precon, Type, DType, LUType) \
769LduMatrix<Type, DType, LUType>::preconditioner:: \
770addasymMatrixConstructorToTable<Precon##Type##DType##LUType##Preconditioner> \
771add##Precon##Type##DType##LUType##PreconditionerAsymMatrixConstructorToTable_;
774#define makeLduSmoother(Smoother, Type, DType, LUType) \
776typedef Smoother<Type, DType, LUType> \
777 Smoother##Type##DType##LUType##Smoother; \
779defineNamedTemplateTypeNameAndDebug \
781 Smoother##Type##DType##LUType##Smoother, \
785#define makeLduSymSmoother(Smoother, Type, DType, LUType) \
787LduMatrix<Type, DType, LUType>::smoother:: \
788 addsymMatrixConstructorToTable<Smoother##Type##DType##LUType##Smoother> \
789 add##Smoother##Type##DType##LUType##SymMatrixConstructorToTable_;
791#define makeLduAsymSmoother(Smoother, Type, DType, LUType) \
793LduMatrix<Type, DType, LUType>::smoother:: \
794 addasymMatrixConstructorToTable<Smoother##Type##DType##LUType##Smoother> \
795 add##Smoother##Type##DType##LUType##AsymMatrixConstructorToTable_;
798#define makeLduSolver(Solver, Type, DType, LUType) \
800typedef Solver<Type, DType, LUType> \
801 Solver##Type##DType##LUType##Solver; \
803defineNamedTemplateTypeNameAndDebug \
805 Solver##Type##DType##LUType##Solver, \
809#define makeLduSymSolver(Solver, Type, DType, LUType) \
811LduMatrix<Type, DType, LUType>::solver:: \
812 addsymMatrixConstructorToTable<Solver##Type##DType##LUType##Solver> \
813 add##Solver##Type##DType##LUType##SymMatrixConstructorToTable_;
815#define makeLduAsymSolver(Solver, Type, DType, LUType) \
817LduMatrix<Type, DType, LUType>::solver:: \
818 addasymMatrixConstructorToTable<Solver##Type##DType##LUType##Solver> \
819 add##Solver##Type##DType##LUType##AsymMatrixConstructorToTable_;
List of coupled interface fields to be used in coupling.
A field of fields is a PtrList of fields with reference counting.
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Abstract base-class for LduMatrix preconditioners.
const solver & solver_
Reference to the base-solver this preconditioner is used with.
preconditioner(const solver &sol)
Construct for given solver.
declareRunTimeSelectionTable(autoPtr, preconditioner, symMatrix,(const solver &sol, const dictionary &preconditionerDict),(sol, preconditionerDict))
static autoPtr< preconditioner > New(const solver &sol, const dictionary &preconditionerDict)
Return a new preconditioner.
declareRunTimeSelectionTable(autoPtr, preconditioner, asymMatrix,(const solver &sol, const dictionary &preconditionerDict),(sol, preconditionerDict))
virtual void read(const dictionary &)
Read and reset the preconditioner parameters from the given dictionary.
virtual void preconditionT(Field< Type > &wT, const Field< Type > &rT) const
Return wT the transpose-matrix preconditioned form of residual rT.
virtual void precondition(Field< Type > &wA, const Field< Type > &rA) const =0
Return wA the preconditioned form of residual rA.
virtual const word & type() const =0
Runtime type information.
virtual ~preconditioner()=default
Destructor.
Abstract base-class for LduMatrix smoothers.
declareRunTimeSelectionTable(autoPtr, smoother, symMatrix,(const word &fieldName, const LduMatrix< Type, DType, LUType > &matrix),(fieldName, matrix))
smoother(const word &fieldName, const LduMatrix< Type, DType, LUType > &matrix)
Construct for given field name and matrix.
const LduMatrix< Type, DType, LUType > & matrix() const noexcept
virtual ~smoother()=default
Destructor.
declareRunTimeSelectionTable(autoPtr, smoother, asymMatrix,(const word &fieldName, const LduMatrix< Type, DType, LUType > &matrix),(fieldName, matrix))
const LduMatrix< Type, DType, LUType > & matrix_
virtual void smooth(Field< Type > &psi, const label nSweeps) const =0
Smooth the solution for a given number of sweeps.
virtual const word & type() const =0
Runtime type information.
const word & fieldName() const noexcept
static autoPtr< smoother > New(const word &fieldName, const LduMatrix< Type, DType, LUType > &matrix, const dictionary &smootherDict)
Return a new smoother.
Abstract base-class for LduMatrix solvers.
label maxIter_
Maximum number of iterations in the solver.
solver(const word &fieldName, const LduMatrix< Type, DType, LUType > &matrix, const dictionary &solverDict)
Construct for given field name, matrix and controls.
const LduMatrix< Type, DType, LUType > & matrix() const noexcept
Type relTol_
Convergence tolerance relative to the initial.
void readControl(const dictionary &dict, T &val, const word &key)
Deprecated(2021-09) Read control parameter from dictionary.
virtual SolverPerformance< Type > solve(Field< Type > &psi) const =0
Type normFactor(const Field< Type > &psi, const Field< Type > &Apsi, Field< Type > &tmpField, const lduMatrix::normTypes normType) const
Return the matrix norm using the specified norm method.
Type normFactor(const Field< Type > &psi, const Field< Type > &Apsi, Field< Type > &tmpField) const
Return the matrix norm used to normalise the residual for the stopping criterion.
label minIter_
Minimum number of iterations in the solver.
Type tolerance_
Final convergence tolerance.
declareRunTimeSelectionTable(autoPtr, solver, asymMatrix,(const word &fieldName, const LduMatrix< Type, DType, LUType > &matrix, const dictionary &solverDict),(fieldName, matrix, solverDict))
lduMatrix::normTypes normType_
The matrix normalisation type.
int log_
Verbosity level for solver output statements.
virtual ~solver()=default
Destructor.
virtual void readControls()
Read the control parameters from controlDict_.
const LduMatrix< Type, DType, LUType > & matrix_
declareRunTimeSelectionTable(autoPtr, solver, symMatrix,(const word &fieldName, const LduMatrix< Type, DType, LUType > &matrix, const dictionary &solverDict),(fieldName, matrix, solverDict))
static autoPtr< solver > New(const word &fieldName, const LduMatrix< Type, DType, LUType > &matrix, const dictionary &solverDict)
Return a new solver.
virtual void read(const dictionary &)
Read and reset the solver parameters from the given dictionary.
dictionary controlDict_
Dictionary of solution controls.
virtual const word & type() const =0
Runtime type information.
const word & fieldName() const noexcept
LduMatrix is a general matrix class in which the coefficients are stored as three arrays,...
void Amul(Field< Type > &, const tmp< Field< Type > > &) const
Matrix multiplication.
bool hasUpper() const noexcept
LduMatrix(const LduMatrix< Type, DType, LUType > &)
Copy construct.
const Field< LUType > & upper() const
const FieldField< Field, LUType > & interfacesUpper() const noexcept
void sumA(Field< Type > &) const
Sum the coefficients on each row of the matrix.
tmp< Field< Type > > faceH(const tmp< Field< Type > > &) const
const lduAddressing & lduAddr() const
Return the LDU addressing.
const Field< Type > & source() const
bool asymmetric() const noexcept
Matrix is asymmetric (ie, full).
FieldField< Field, LUType > & interfacesUpper() noexcept
tmp< Field< Type > > H(const Field< Type > &) const
void updateMatrixInterfaces(const bool add, const FieldField< Field, LUType > &interfaceCoeffs, const Field< Type > &psiif, Field< Type > &result, const label startRequest) const
Update interfaced interfaces for matrix operations.
Field< LUType > & upper()
tmp< Field< Type > > residual(const Field< Type > &psi) const
LduMatrix(LduMatrix< Type, DType, LUType > &, bool reuse)
Construct as copy or re-use as specified.
bool symmetric() const noexcept
Matrix is symmetric.
const Field< DType > & diag() const
void operator+=(const LduMatrix< Type, DType, LUType > &)
const LduInterfaceFieldPtrsList< Type > & interfaces() const noexcept
Const access to the interfaces.
const lduSchedule & patchSchedule() const
Return the patch evaluation schedule.
LduMatrix(LduMatrix< Type, DType, LUType > &&)
Move construct.
const FieldField< Field, LUType > & interfacesLower() const noexcept
void operator=(const LduMatrix< Type, DType, LUType > &)
Copy assignment.
void operator*=(const scalarField &)
bool diagonal() const noexcept
Matrix has diagonal only.
void sumMagOffDiag(Field< LUType > &sumOff) const
LduMatrix(const lduMesh &mesh)
Construct given an LDU addressed mesh.
FieldField< Field, LUType > & interfacesLower() noexcept
void residual(Field< Type > &rA, const Field< Type > &psi) const
bool hasLower() const noexcept
tmp< Field< Type > > faceH(const Field< Type > &) const
void initMatrixInterfaces(const bool add, const FieldField< Field, LUType > &interfaceCoeffs, const Field< Type > &psiif, Field< Type > &result) const
Initialise the update of interfaced interfaces.
~LduMatrix()=default
Destructor.
const lduMesh & mesh() const noexcept
void operator-=(const LduMatrix< Type, DType, LUType > &)
void operator=(LduMatrix< Type, DType, LUType > &&)
Move assignment.
bool hasSource() const noexcept
word matrixTypeName() const
The matrix type (empty, diagonal, symmetric, ...).
tmp< Field< Type > > H(const tmp< Field< Type > > &) const
bool hasDiag() const noexcept
LduMatrix(const lduMesh &mesh, Istream &is)
Construct given an LDU addressed mesh and an Istream from which the coefficients are read.
void Tmul(Field< Type > &, const tmp< Field< Type > > &) const
Matrix transpose multiplication.
Field< LUType > & lower()
const Field< LUType > & lower() const
LduInterfaceFieldPtrsList< Type > & interfaces() noexcept
Non-const access to the interfaces.
friend Ostream & operator(Ostream &, const LduMatrix< Type, DType, LUType > &)
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
The class contains the addressing required by the lduMatrix: upper, lower and losort.
normTypes
Enumerated matrix normalisation types.
Abstract base class for meshes which provide LDU addressing for the construction of lduMatrix and LDU...
A class for managing temporary objects.
A class for handling words, derived from Foam::string.
#define ClassName(TypeNameString)
Add typeName information from argument TypeNameString to a class.
const volScalarField & psi
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
List< lduScheduleEntry > lduSchedule
A List of lduSchedule entries.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
void add(DimensionedField< scalar, GeoMesh > &result, const dimensioned< scalar > &dt1, const DimensionedField< scalar, GeoMesh > &f2)
UPtrList< const LduInterfaceField< Type > > LduInterfaceFieldPtrsList
Store lists of LduInterfaceField as a UPtrList.
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Macros to ease declaration of run-time selection tables.
#define declareRunTimeSelectionTable(ptrWrapper, baseType, argNames, argList, parList)
Declare a run-time selection (variables and adder classes).
Basic run-time type information using word as the type's name. Used to enhance the standard RTTI to c...