/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 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 .
Class
Foam::fvMatrix
Description
A special matrix type and solver, designed for finite volume
solutions of scalar equations.
Face addressing is used to make all matrix assembly
and solution loops vectorise.
SourceFiles
fvMatrix.C
fvMatrixSolve.C
fvScalarMatrix.C
\*---------------------------------------------------------------------------*/
#ifndef fvMatrix_H
#define fvMatrix_H
#include "volFields.H"
#include "surfaceFields.H"
#include "lduMatrix.H"
#include "tmp.H"
#include "autoPtr.H"
#include "dimensionedTypes.H"
#include "zero.H"
#include "className.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of friend functions and operators
template
class fvMatrix;
template
tmp> operator&
(
const fvMatrix&,
const DimensionedField&
);
template
tmp> operator&
(
const fvMatrix&,
const tmp>&
);
template
tmp> operator&
(
const fvMatrix&,
const tmp>&
);
template
tmp> operator&
(
const tmp>&,
const DimensionedField&
);
template
tmp> operator&
(
const tmp>&,
const tmp>&
);
template
tmp> operator&
(
const tmp>&,
const tmp>&
);
template
Ostream& operator<<(Ostream&, const fvMatrix&);
template class UIndirectList;
/*---------------------------------------------------------------------------*\
Class fvMatrix Declaration
\*---------------------------------------------------------------------------*/
template
class fvMatrix
:
public tmp>::refCount,
public lduMatrix
{
// Private data
//- Const reference to GeometricField
// Converted into a non-const reference at the point of solution.
const GeometricField& psi_;
//- Dimension set
dimensionSet dimensions_;
//- Source term
Field source_;
//- Boundary scalar field containing pseudo-matrix coeffs
// for internal cells
FieldField internalCoeffs_;
//- Boundary scalar field containing pseudo-matrix coeffs
// for boundary cells
FieldField boundaryCoeffs_;
//- Face flux field for non-orthogonal correction
mutable GeometricField
*faceFluxCorrectionPtr_;
protected:
//- Declare friendship with the fvSolver class
friend class fvSolver;
// Protected Member Functions
//- Add patch contribution to internal field
template
void addToInternalField
(
const labelUList& addr,
const Field& pf,
Field& intf
) const;
template
void addToInternalField
(
const labelUList& addr,
const tmp>& tpf,
Field& intf
) const;
//- Subtract patch contribution from internal field
template
void subtractFromInternalField
(
const labelUList& addr,
const Field& pf,
Field& intf
) const;
template
void subtractFromInternalField
(
const labelUList& addr,
const tmp>& tpf,
Field& intf
) const;
// Matrix completion functionality
void addBoundaryDiag
(
scalarField& diag,
const direction cmpt
) const;
void addCmptAvBoundaryDiag(scalarField& diag) const;
void addBoundarySource
(
Field& source,
const bool couples=true
) const;
// Matrix manipulation functionality
//- Set solution in given cells to the specified values
template class ListType>
void setValuesFromList
(
const labelUList& cells,
const ListType& values
);
public:
//- Solver class returned by the solver function
// used for systems in which it is useful to cache the solver for reuse
// e.g. if the solver is potentially expensive to construct (AMG) and can
// be used several times (PISO)
class fvSolver
{
fvMatrix& fvMat_;
autoPtr solver_;
public:
// Constructors
fvSolver(fvMatrix& fvMat, autoPtr sol)
:
fvMat_(fvMat),
solver_(sol)
{}
// Member functions
//- Solve returning the solution statistics.
// Use the given solver controls
SolverPerformance solve(const dictionary&);
//- Solve returning the solution statistics.
// Solver controls read from fvSolution
SolverPerformance solve();
};
ClassName("fvMatrix");
// Constructors
//- Construct given a field to solve for
fvMatrix
(
const GeometricField&,
const dimensionSet&
);
//- Construct as copy
fvMatrix(const fvMatrix&);
//- Construct as copy of tmp> deleting argument
#ifndef NoConstructFromTmp
fvMatrix(const tmp>&);
#endif
//- Construct from Istream given field to solve for
fvMatrix(const GeometricField&, Istream&);
//- Clone
tmp> clone() const;
//- Destructor
virtual ~fvMatrix();
// Member functions
// Access
const GeometricField& psi() const
{
return psi_;
}
const dimensionSet& dimensions() const
{
return dimensions_;
}
Field& source()
{
return source_;
}
const Field& source() const
{
return source_;
}
//- fvBoundary scalar field containing pseudo-matrix coeffs
// for internal cells
FieldField& internalCoeffs()
{
return internalCoeffs_;
}
//- fvBoundary scalar field containing pseudo-matrix coeffs
// for boundary cells
FieldField& boundaryCoeffs()
{
return boundaryCoeffs_;
}
//- Declare return type of the faceFluxCorrectionPtr() function
typedef GeometricField
*surfaceTypeFieldPtr;
//- Return pointer to face-flux non-orthogonal correction field
surfaceTypeFieldPtr& faceFluxCorrectionPtr()
{
return faceFluxCorrectionPtr_;
}
// Operations
//- Set solution in given cells to the specified values
// and eliminate the corresponding equations from the matrix.
void setValues
(
const labelUList& cells,
const UList& values
);
//- Set solution in given cells to the specified values
// and eliminate the corresponding equations from the matrix.
void setValues
(
const labelUList& cells,
const UIndirectList& values
);
//- Set reference level for solution
void setReference
(
const label celli,
const Type& value,
const bool forceReference = false
);
//- Set reference level for a component of the solution
// on a given patch face
void setComponentReference
(
const label patchi,
const label facei,
const direction cmpt,
const scalar value
);
//- Relax matrix (for steady-state solution).
// alpha = 1 : diagonally equal
// alpha < 1 : diagonally dominant
// alpha = 0 : do nothing
// Note: Requires positive diagonal.
void relax(const scalar alpha);
//- Relax matrix (for steady-state solution).
// alpha is read from controlDict
void relax();
//- Manipulate based on a boundary field
void boundaryManipulate
(
typename GeometricField::
Boundary& values
);
//- Construct and return the solver
// Use the given solver controls
autoPtr solver(const dictionary&);
//- Construct and return the solver
// Solver controls read from fvSolution
autoPtr solver();
//- Solve segregated or coupled returning the solution statistics.
// Use the given solver controls
SolverPerformance solve(const dictionary&);
//- Solve segregated returning the solution statistics.
// Use the given solver controls
SolverPerformance solveSegregated(const dictionary&);
//- Solve coupled returning the solution statistics.
// Use the given solver controls
SolverPerformance solveCoupled(const dictionary&);
//- Solve returning the solution statistics.
// Solver controls read from fvSolution
SolverPerformance solve();
//- Return the matrix residual
tmp> residual() const;
//- Return the matrix scalar diagonal
tmp D() const;
//- Return the matrix Type diagonal
tmp> DD() const;
//- Return the central coefficient
tmp A() const;
//- Return the H operation source
tmp> H() const;
//- Return H(1)
tmp H1() const;
//- Return the face-flux field from the matrix
tmp>
flux() const;
// Member operators
void operator=(const fvMatrix&);
void operator=(const tmp>&);
void negate();
void operator+=(const fvMatrix&);
void operator+=(const tmp>&);
void operator-=(const fvMatrix&);
void operator-=(const tmp>&);
void operator+=
(
const DimensionedField&
);
void operator+=
(
const tmp>&
);
void operator+=
(
const tmp>&
);
void operator-=
(
const DimensionedField&
);
void operator-=
(
const tmp>&
);
void operator-=
(
const tmp>&
);
void operator+=(const dimensioned&);
void operator-=(const dimensioned&);
void operator+=(const zero&);
void operator-=(const zero&);
void operator*=(const volScalarField::Internal&);
void operator*=(const tmp&);
void operator*=(const tmp&);
void operator*=(const dimensioned&);
// Friend operators
friend tmp>
operator&
(
const fvMatrix&,
const DimensionedField&
);
friend tmp>
operator&
(
const fvMatrix&,
const tmp>&
);
friend tmp>
operator&
(
const tmp>&,
const DimensionedField&
);
friend tmp>
operator&
(
const tmp>&,
const tmp>&
);
// Ostream operator
friend Ostream& operator<<
(
Ostream&,
const fvMatrix&
);
};
// * * * * * * * * * * * * * * * Global functions * * * * * * * * * * * * * //
template
void checkMethod
(
const fvMatrix&,
const fvMatrix&,
const char*
);
template
void checkMethod
(
const fvMatrix&,
const DimensionedField&,
const char*
);
template
void checkMethod
(
const fvMatrix&,
const dimensioned&,
const char*
);
//- Solve returning the solution statistics given convergence tolerance
// Use the given solver controls
template
SolverPerformance solve(fvMatrix&, const dictionary&);
//- Solve returning the solution statistics given convergence tolerance,
// deleting temporary matrix after solution.
// Use the given solver controls
template
SolverPerformance solve
(
const tmp>&,
const dictionary&
);
//- Solve returning the solution statistics given convergence tolerance
// Solver controls read fvSolution
template
SolverPerformance solve(fvMatrix&);
//- Solve returning the solution statistics given convergence tolerance,
// deleting temporary matrix after solution.
// Solver controls read fvSolution
template
SolverPerformance solve(const tmp>&);
//- Return the correction form of the given matrix
// by subtracting the matrix multiplied by the current field
template
tmp> correction(const fvMatrix&);
//- Return the correction form of the given temporary matrix
// by subtracting the matrix multiplied by the current field
template
tmp> correction(const tmp>&);
// * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * //
template
tmp> operator==
(
const fvMatrix&,
const fvMatrix&
);
template
tmp> operator==
(
const tmp>&,
const fvMatrix&
);
template
tmp> operator==
(
const fvMatrix&,
const tmp>&
);
template
tmp> operator==
(
const tmp>&,
const tmp>&
);
template
tmp> operator==
(
const fvMatrix&,
const DimensionedField&
);
template
tmp> operator==
(
const fvMatrix&,
const tmp>&
);
template
tmp> operator==
(
const fvMatrix&,
const tmp>&
);
template
tmp> operator==
(
const tmp>&,
const DimensionedField&
);
template
tmp> operator==
(
const tmp>&,
const tmp>&
);
template
tmp> operator==
(
const tmp>&,
const tmp>&
);
template
tmp> operator==
(
const fvMatrix&,
const dimensioned&
);
template
tmp> operator==
(
const tmp>&,
const dimensioned&
);
template
tmp> operator==
(
const fvMatrix&,
const zero&
);
template
tmp> operator==
(
const tmp>&,
const zero&
);
template
tmp> operator-
(
const fvMatrix&
);
template
tmp> operator-
(
const tmp>&
);
template
tmp> operator+
(
const fvMatrix&,
const fvMatrix&
);
template
tmp> operator+
(
const tmp>&,
const fvMatrix&
);
template
tmp> operator+
(
const fvMatrix&,
const tmp>&
);
template
tmp> operator+
(
const tmp>&,
const tmp>&
);
template
tmp> operator+
(
const fvMatrix&,
const DimensionedField&
);
template
tmp> operator+
(
const fvMatrix&,
const tmp>&
);
template
tmp> operator+
(
const fvMatrix&,
const tmp>&
);
template
tmp> operator+
(
const tmp>&,
const DimensionedField&
);
template
tmp> operator+
(
const tmp>&,
const tmp>&
);
template
tmp> operator+
(
const tmp>&,
const tmp>&
);
template
tmp> operator+
(
const DimensionedField&,
const fvMatrix&
);
template
tmp> operator+
(
const tmp>&,
const fvMatrix