solutionControl.H 7.54 KB
Newer Older
andy's avatar
andy committed
1
2
3
4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
OpenFOAM bot's avatar
OpenFOAM bot committed
5
    \\  /    A nd           | www.openfoam.com
OpenFOAM bot's avatar
OpenFOAM bot committed
6
7
     \\/     M anipulation  |
-------------------------------------------------------------------------------
OpenFOAM bot's avatar
OpenFOAM bot committed
8
9
    Copyright (C) 2011-2015 OpenFOAM Foundation
    Copyright (C) 2017 OpenCFD Ltd.
andy's avatar
andy committed
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
-------------------------------------------------------------------------------
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 <http://www.gnu.org/licenses/>.

Class
    Foam::solutionControl

Description
    Base class for solution control classes

\*---------------------------------------------------------------------------*/

#ifndef solutionControl_H
#define solutionControl_H

#include "fvMesh.H"
39
#include "Pair.H"
andy's avatar
andy committed
40
41
42
43
44
45
46

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{

/*---------------------------------------------------------------------------*\
47
                       Class solutionControl Declaration
andy's avatar
andy committed
48
49
50
\*---------------------------------------------------------------------------*/

class solutionControl
51
:
52
    public regIOobject
andy's avatar
andy committed
53
54
55
{
public:

56
    //- Simple convenient storage of field residuals
andy's avatar
andy committed
57
58
59
60
61
62
63
64
65
    struct fieldData
    {
        wordRe name;
        scalar absTol;
        scalar relTol;
        scalar initialResidual;
    };


66
67
68
69
70
71
72
73
74
75
76
77
78
79
    // Static Member Functions

        //- Extract maximum residual for the solver performance entry,
        //- provided the corresponding volume field is available on the mesh.
        //
        //  \return initial residual as first member, the final residual
        //      as the second (or last) member
        static Pair<scalar> maxResidual
        (
            const fvMesh& fvmesh,
            const entry& dataDictEntry
        );


andy's avatar
andy committed
80
81
82
83
84
85
86
87
88
89
90
protected:

    // Protected data

        //- Reference to the mesh database
        fvMesh& mesh_;

        //- List of residual data per field
        List<fieldData> residualControl_;

        //- The dictionary name, e.g. SIMPLE, PIMPLE
andy's avatar
andy committed
91
        const word algorithmName_;
andy's avatar
andy committed
92
93
94
95
96
97
98
99
100
101


        // Solution controls

            //- Maximum number of non-orthogonal correctors
            label nNonOrthCorr_;

            //- Flag to indicate to solve for momentum
            bool momentumPredictor_;

102
            //- Flag to indicate to solve using transonic algorithm
andy's avatar
andy committed
103
104
            bool transonic_;

105
106
107
108
            //- Flag to indicate to relax pressure using the
            //  "consistent" approach of SIMPLEC
            bool consistent_;

109
110
111
112
            //- Flag to indicate that the flow system of equations should not
            //  be evolved
            bool frozenFlow_;

andy's avatar
andy committed
113

114
115
116
117
118
119
120
121
122
        // Evolution

            //- Current corrector loop index
            label corr_;

            //- Current non-orthogonal corrector loop index
            label corrNonOrtho_;


andy's avatar
andy committed
123
124
    // Protected Member Functions

125
        //- Read controls from fvSolution dictionary
126
        virtual bool read(const bool absTolOnly);
andy's avatar
andy committed
127

128
        //- Read controls from fvSolution dictionary
129
        virtual bool read();
130

andy's avatar
andy committed
131
        //- Return index of field in residualControl_ if present
132
133
134
135
136
        virtual label applyToField
        (
            const word& fieldName,
            const bool useRegEx = true
        ) const;
andy's avatar
andy committed
137

138
        //- Return true if all convergence checks are satisfied
andy's avatar
andy committed
139
140
        virtual bool criteriaSatisfied() = 0;

141
142
143
144
145
146
147
        //- Store previous iteration fields
        virtual void storePrevIterFields() const;

        //- Store previous iteration field for vol<Type>Fields
        template<class Type>
        void storePrevIter() const;

148
149
150
151
152
153
        //- Initial and final residual of the specified field-name,
        //- provided that the corresponding volume field is available
        //- on the fvMesh.
        //
        //  Populate residuals with initial residual as first member and
        //  the final residual as second (last) member.
154
        template<class Type>
155
        static bool maxTypeResidual
156
        (
157
158
159
160
            const fvMesh& fvmesh,
            const entry& solverPerfDictEntry,
            Pair<scalar>& residuals
        );
161

162
163
164
165
166
        //- Extract the maximum residual for the specified field
        //
        //  \return initial residual as first member, the final residual
        //      as second (last) member
        Pair<scalar> maxResidual(const entry& solverPerfDictEntry) const;
167

168
169
170
171
172
173
174
        //- Set the firstIteration flag on the mesh data dictionary
        virtual void setFirstIterFlag
        (
            const bool check = true,
            const bool force = false
        );

175
176
177
        //- Dummy write for regIOobject
        virtual bool writeData(Ostream&) const;

178
179
180

private:

181
        //- No copy construct
182
        solutionControl(const solutionControl&) = delete;
andy's avatar
andy committed
183

184
        //- No copy assignment
185
        void operator=(const solutionControl&) = delete;
andy's avatar
andy committed
186
187
188
189
190
191
192
193
194
195
196
197
198
199


public:


    // Static Data Members

        //- Run-time type information
        TypeName("solutionControl");


    // Constructors

        //- Construct from mesh
andy's avatar
andy committed
200
        solutionControl(fvMesh& mesh, const word& algorithmName);
andy's avatar
andy committed
201
202
203


    //- Destructor
204
    virtual ~solutionControl() = default;
andy's avatar
andy committed
205
206
207
208
209
210
211


    // Member Functions

        // Access

            //- Return the solution dictionary
212
            virtual const dictionary dict() const;
andy's avatar
andy committed
213

214
215
216
217
218
219
            //- Current corrector loop index
            inline label corr() const;

            //- Current non-orthogonal corrector index
            inline label corrNonOrtho() const;

andy's avatar
andy committed
220
221
222
223
224
225

        // Solution control

            //- Maximum number of non-orthogonal correctors
            inline label nNonOrthCorr() const;

226
227
228
            //- Helper function to identify final non-orthogonal iteration
            inline bool finalNonOrthogonalIter() const;

andy's avatar
andy committed
229
230
231
            //- Flag to indicate to solve for momentum
            inline bool momentumPredictor() const;

232
            //- Flag to indicate to solve using transonic algorithm
andy's avatar
andy committed
233
            inline bool transonic() const;
234

235
236
237
238
            //- Flag to indicate to relax pressure using the
            //  "consistent" approach of SIMPLEC
            inline bool consistent() const;

239
240
241
242
            //- Flag to indicate that the flow system of equations should not
            //  be evolved
            inline bool frozenFlow() const;

243
244
245
246
247
248
249
250

        // Evolution

            //- Main control loop
            virtual bool loop() = 0;

            //- Non-orthogonal corrector loop
            inline bool correctNonOrthogonal();
andy's avatar
andy committed
251
252
253
254
255
256
257
258
259
};


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

260
261
262
263
264
265
#ifdef NoRepository
    #include "solutionControlTemplates.C"
#endif

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

andy's avatar
andy committed
266
267
268
269
270
271
272
#include "solutionControlI.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif

// ************************************************************************* //