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) 2019-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
32// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33
34template<class Type, class DType, class LUType>
37(
38 const word& fieldName,
40 const dictionary& solverDict
41)
42{
43 const word solverName(solverDict.get<word>("solver"));
44
45 if (matrix.diagonal())
46 {
48 (
50 (
52 matrix,
53 solverDict
54 )
55 );
56 }
57 else if (matrix.symmetric())
58 {
59 auto* ctorPtr = symMatrixConstructorTable(solverName);
60
61 if (!ctorPtr)
62 {
64 (
65 solverDict,
66 "symmetric matrix solver",
67 solverName,
68 *symMatrixConstructorTablePtr_
69 ) << exit(FatalIOError);
70 }
71
73 (
74 ctorPtr
75 (
77 matrix,
78 solverDict
79 )
80 );
81 }
82 else if (matrix.asymmetric())
83 {
84 auto* ctorPtr = asymMatrixConstructorTable(solverName);
85
86 if (!ctorPtr)
87 {
89 (
90 solverDict,
91 "asymmetric matrix solver",
92 solverName,
93 *asymMatrixConstructorTablePtr_
94 ) << exit(FatalIOError);
95 }
96
98 (
99 ctorPtr
100 (
101 fieldName,
102 matrix,
103 solverDict
104 )
105 );
106 }
107
108 FatalIOErrorInFunction(solverDict)
109 << "cannot solve incomplete matrix, "
110 "no diagonal or off-diagonal coefficient"
111 << exit(FatalIOError);
112
113 return nullptr;
114}
115
116
117// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
118
119template<class Type, class DType, class LUType>
121(
122 const word& fieldName,
123 const LduMatrix<Type, DType, LUType>& matrix,
124 const dictionary& solverDict
125)
126:
127 fieldName_(fieldName),
128 matrix_(matrix),
129
130 controlDict_(solverDict),
131
132 log_(1),
133 minIter_(0),
134 maxIter_(defaultMaxIter_),
135 tolerance_(1e-6*pTraits<Type>::one),
136 relTol_(Zero)
137{
138 readControls();
139}
140
141
142// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
143
144template<class Type, class DType, class LUType>
146{
147 controlDict_.readIfPresent("log", log_);
148 controlDict_.readIfPresent("minIter", minIter_);
149 controlDict_.readIfPresent("maxIter", maxIter_);
150 controlDict_.readIfPresent("tolerance", tolerance_);
151 controlDict_.readIfPresent("relTol", relTol_);
152}
153
154
155template<class Type, class DType, class LUType>
157(
158 const dictionary& solverDict
159)
160{
161 controlDict_ = solverDict;
162 readControls();
163}
164
165
166template<class Type, class DType, class LUType>
168(
169 const Field<Type>& psi,
170 const Field<Type>& Apsi,
171 Field<Type>& tmpField
172) const
173{
174 // --- Calculate A dot reference value of psi
175 matrix_.sumA(tmpField);
176 cmptMultiply(tmpField, tmpField, gAverage(psi));
177
178 return stabilise
179 (
180 gSum(cmptMag(Apsi - tmpField) + cmptMag(matrix_.source() - tmpField)),
182 );
183
184 // At convergence this simpler method is equivalent to the above
185 // return stabilise(2*gSumCmptMag(matrix_.source()), matrix_.small_);
186}
187
188
189// ************************************************************************* //
Foam::DiagonalSolver.
Generic templated field type.
Definition: Field.H:82
const LduMatrix< Type, DType, LUType > & matrix() const noexcept
Definition: LduMatrix.H:239
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.
virtual void readControls()
Read the control parameters from the controlDict_.
const word & fieldName() const noexcept
Definition: LduMatrix.H:234
LduMatrix is a general matrix class in which the coefficients are stored as three arrays,...
Definition: LduMatrix.H:88
virtual bool read()
Re-read model coefficients if they have changed.
SolverPerformance is the class returned by the LduMatrix solver containing performance statistics.
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
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
Abstract base-class for lduMatrix solvers.
Definition: lduMatrix.H:99
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
Definition: one.H:62
A traits class, which is primarily used for primitives.
Definition: pTraits.H:59
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
Type gSum(const FieldField< Field, Type > &f)
IOerror FatalIOError
dimensionedScalar stabilise(const dimensionedScalar &x, const dimensionedScalar &y)
Type gAverage(const FieldField< Field, Type > &f)
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
void cmptMag(FieldField< Field, Type > &cf, const FieldField< Field, Type > &f)
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
volScalarField & e
Definition: createFields.H:11