lduMatrixSolver.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2017 OpenFOAM Foundation
9 Copyright (C) 2016-2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include "lduMatrix.H"
30#include "diagonalSolver.H"
31#include "PrecisionAdaptor.H"
32
33// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34
35namespace Foam
36{
39}
40
41
42// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43
45(
46 const word& fieldName,
47 const lduMatrix& matrix,
48 const FieldField<Field, scalar>& interfaceBouCoeffs,
49 const FieldField<Field, scalar>& interfaceIntCoeffs,
50 const lduInterfaceFieldPtrsList& interfaces,
51 const dictionary& solverControls
52)
53{
54 const word name(solverControls.get<word>("solver"));
55
56 if (matrix.diagonal())
57 {
59 (
61 (
63 matrix,
67 solverControls
68 )
69 );
70 }
71 else if (matrix.symmetric())
72 {
73 auto* ctorPtr = symMatrixConstructorTable(name);
74
75 if (!ctorPtr)
76 {
78 (
79 solverControls,
80 "symmetric matrix solver",
81 name,
82 *symMatrixConstructorTablePtr_
83 ) << exit(FatalIOError);
84 }
85
87 (
88 ctorPtr
89 (
91 matrix,
95 solverControls
96 )
97 );
98 }
99 else if (matrix.asymmetric())
100 {
101 auto* ctorPtr = asymMatrixConstructorTable(name);
102
103 if (!ctorPtr)
104 {
106 (
107 solverControls,
108 "asymmetric matrix solver",
109 name,
110 *asymMatrixConstructorTablePtr_
111 ) << exit(FatalIOError);
112 }
113
115 (
116 ctorPtr
117 (
118 fieldName,
119 matrix,
123 solverControls
124 )
125 );
126 }
127
128 FatalIOErrorInFunction(solverControls)
129 << "cannot solve incomplete matrix, "
130 "no diagonal or off-diagonal coefficient"
131 << exit(FatalIOError);
132
133 return nullptr;
134}
135
136
137// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
138
140(
141 const word& fieldName,
142 const lduMatrix& matrix,
143 const FieldField<Field, scalar>& interfaceBouCoeffs,
144 const FieldField<Field, scalar>& interfaceIntCoeffs,
145 const lduInterfaceFieldPtrsList& interfaces,
146 const dictionary& solverControls
147)
148:
149 fieldName_(fieldName),
150 matrix_(matrix),
151 interfaceBouCoeffs_(interfaceBouCoeffs),
152 interfaceIntCoeffs_(interfaceIntCoeffs),
153 interfaces_(interfaces),
154 controlDict_(solverControls),
155 profiling_("lduMatrix::solver." + fieldName)
156{
157 readControls();
158}
159
160
161// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
162
164{
165 log_ = controlDict_.getOrDefault<int>("log", 1);
166 minIter_ = controlDict_.getOrDefault<label>("minIter", 0);
167 maxIter_ = controlDict_.getOrDefault<label>("maxIter", defaultMaxIter_);
168 tolerance_ = controlDict_.getOrDefault<scalar>("tolerance", 1e-6);
169 relTol_ = controlDict_.getOrDefault<scalar>("relTol", 0);
170}
171
172
173void Foam::lduMatrix::solver::read(const dictionary& solverControls)
174{
175 controlDict_ = solverControls;
176 readControls();
177}
178
179
181(
183 const solveScalarField& source,
184 const direction cmpt
185) const
186{
188 return solve
189 (
190 tpsi_s.ref(),
192 cmpt
193 );
194}
195
196
198(
199 const solveScalarField& psi,
200 const solveScalarField& source,
201 const solveScalarField& Apsi,
202 solveScalarField& tmpField
203) const
204{
205 // --- Calculate A dot reference value of psi
206 matrix_.sumA(tmpField, interfaceBouCoeffs_, interfaces_);
207
208 tmpField *= gAverage(psi, matrix_.mesh().comm());
209
210 return
211 gSum
212 (
213 (mag(Apsi - tmpField) + mag(source - tmpField))(),
214 matrix_.mesh().comm()
215 )
217
218 // At convergence this simpler method is equivalent to the above
219 // return 2*gSumMag(source) + solverPerformance::small_;
220}
221
222
223// ************************************************************************* //
A const Field/List wrapper with possible data conversion.
const Mesh & mesh() const
Return mesh.
A field of fields is a PtrList of fields with reference counting.
Definition: FieldField.H:80
A non-const Field/List wrapper with possible data conversion.
virtual bool read()
Re-read model coefficients if they have changed.
SolverPerformance is the class returned by the LduMatrix solver containing performance statistics.
static const scalar small_
Small Type for the use in solvers.
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
Foam::diagonalSolver.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:66
label comm() const noexcept
Return communicator used for parallel communication.
Definition: faMeshI.H:44
Abstract base-class for lduMatrix solvers.
Definition: lduMatrix.H:99
const FieldField< Field, scalar > & interfaceIntCoeffs() const noexcept
Definition: lduMatrix.H:243
const lduInterfaceFieldPtrsList & interfaces() const noexcept
Definition: lduMatrix.H:248
const lduMatrix & matrix() const noexcept
Definition: lduMatrix.H:233
solveScalarField::cmptType normFactor(const solveScalarField &psi, const solveScalarField &source, const solveScalarField &Apsi, solveScalarField &tmpField) const
virtual solverPerformance scalarSolve(solveScalarField &psi, const solveScalarField &source, const direction cmpt=0) const
Solve with given field and rhs (in solveScalar precision).
virtual void readControls()
Read the control parameters from the controlDict_.
const FieldField< Field, scalar > & interfaceBouCoeffs() const noexcept
Definition: lduMatrix.H:238
const word & fieldName() const noexcept
Definition: lduMatrix.H:228
lduMatrix is a general matrix class in which the coefficients are stored as three arrays,...
Definition: lduMatrix.H:84
bool symmetric() const
Definition: lduMatrix.H:628
bool diagonal() const
Definition: lduMatrix.H:623
bool asymmetric() const
Definition: lduMatrix.H:633
T & ref() const
Definition: refPtrI.H:203
A class for handling words, derived from Foam::string.
Definition: word.H:68
const volScalarField & psi
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
Definition: error.H:478
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
Namespace for OpenFOAM.
Type gSum(const FieldField< Field, Type > &f)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
uint8_t direction
Definition: direction.H:56
IOerror FatalIOError
Type gAverage(const FieldField< Field, Type > &f)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
#define defineRunTimeSelectionTable(baseType, argNames)
Define run-time selection table.
CEqn solve()
volScalarField & e
Definition: createFields.H:11