solverInfo.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) 2015-2016 OpenFOAM Foundation
9 Copyright (C) 2015-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 "solverInfo.H"
31
32// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33
34namespace Foam
35{
36namespace functionObjects
37{
40}
41}
42
43
44// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
45
47{
49 {
50 return;
51 }
52
54 {
56 }
57 else
58 {
59 writeHeader(os, "Solver information");
60 }
61
62 writeCommented(os, "Time");
63
64 for (const word& fieldName : fieldSet_.selectionNames())
65 {
66 writeFileHeader<scalar>(os, fieldName);
67 writeFileHeader<vector>(os, fieldName);
68 writeFileHeader<sphericalTensor>(os, fieldName);
69 writeFileHeader<symmTensor>(os, fieldName);
70 writeFileHeader<tensor>(os, fieldName);
71 }
72
73 os << endl;
74
75 writtenHeader_ = true;
76}
77
78
80(
81 const word& fieldName
82)
83{
84 if (!writeResidualFields_)
85 {
86 return;
87 }
88
89 const word residualName
90 (
91 IOobject::scopedName("initialResidual", fieldName)
92 );
93
94 if (!mesh_.foundObject<IOField<scalar>>(residualName))
95 {
96 auto* fieldPtr =
98 (
100 (
101 residualName,
102 mesh_.time().timeName(),
103 mesh_,
106 ),
107 Field<scalar>(mesh_.nCells(), Zero)
108 );
109
110 fieldPtr->store();
111
112 residualFieldNames_.insert(residualName);
113 }
114}
115
116
117// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
118
120(
121 const word& name,
122 const Time& runTime,
123 const dictionary& dict
124)
125:
127 writeFile(obr_, name, typeName, dict),
128 fieldSet_(mesh_),
129 residualFieldNames_(),
130 writeResidualFields_(false),
131 initialised_(false)
132{
133 read(dict);
134}
135
136
137// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
138
140{
142 {
143 initialised_ = false;
144
145 fieldSet_.read(dict);
146
147 writeResidualFields_ = dict.getOrDefault("writeResidualFields", false);
148
149 residualFieldNames_.clear();
150
151 return true;
152 }
153
154 return false;
155}
156
157
159{
160 // Note: delaying initialisation until after first iteration so that
161 // we can find wildcard fields
162 if (!initialised_)
163 {
164 writeFileHeader(file());
165
166 if (writeResidualFields_)
167 {
168 for (const word& fieldName : fieldSet_.selectionNames())
169 {
170 initialiseResidualField<scalar>(fieldName);
171 initialiseResidualField<vector>(fieldName);
172 initialiseResidualField<sphericalTensor>(fieldName);
173 initialiseResidualField<symmTensor>(fieldName);
174 initialiseResidualField<tensor>(fieldName);
175 }
176 }
177
178 initialised_ = true;
179 }
180
181 writeCurrentTime(file());
182
183 for (const word& fieldName : fieldSet_.selectionNames())
184 {
185 updateSolverInfo<scalar>(fieldName);
186 updateSolverInfo<vector>(fieldName);
187 updateSolverInfo<sphericalTensor>(fieldName);
188 updateSolverInfo<symmTensor>(fieldName);
189 updateSolverInfo<tensor>(fieldName);
190 }
191
192 file() << endl;
193
194 return true;
195}
196
197
199{
200 for (const word& residualName : residualFieldNames_)
201 {
202 const auto* residualPtr =
203 mesh_.findObject<IOField<scalar>>(residualName);
204
205 if (residualPtr)
206 {
207 volScalarField residual
208 (
210 (
211 residualName,
212 mesh_.time().timeName(),
213 mesh_,
216 false
217 ),
218 mesh_,
221 );
222
223 residual.primitiveFieldRef() = *residualPtr;
224 residual.correctBoundaryConditions();
225
226 residual.write();
227 }
228 }
229
230 return true;
231}
232
233
234// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
Generic templated field type.
Definition: Field.H:82
Internal::FieldType & primitiveFieldRef(const bool updateAccessTime=true)
Return a reference to the internal field.
void correctBoundaryConditions()
Correct boundary field.
A primitive field of type <T> with automated input and output.
Definition: IOField.H:58
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
static word scopedName(const std::string &scope, const word &name)
Create scope:name or scope_name string.
Definition: IOobjectI.H:47
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
virtual bool read()
Re-read model coefficients if they have changed.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Abstract base-class for Time/database function objects.
wordHashSet selectionNames() const
Return the current field selection.
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
virtual bool updateSelection()
Update the selection using current contents of obr_.
Writes solver information for a list of user-specified fields.
Definition: solverInfo.H:172
void createResidualField(const word &fieldName)
Create and store a residual field on the mesh database.
Definition: solverInfo.C:80
void writeFileHeader(Ostream &os)
Output file header information.
Definition: solverInfo.C:46
virtual bool execute()
Execute solverInfo.
Definition: solverInfo.C:158
virtual bool write()
Write solverInfo results.
Definition: solverInfo.C:198
solverFieldSelection fieldSet_
Names of operand fields.
Definition: solverInfo.H:178
virtual bool read(const dictionary &)
Read solverInfo settings.
Definition: solverInfo.C:139
Base class for writing single files from the function objects.
Definition: writeFile.H:120
virtual void writeHeader(Ostream &os, const string &str) const
Write a commented header to stream.
Definition: writeFile.C:295
virtual void writeBreak(Ostream &os) const
Write a break marker to the stream.
Definition: writeFile.C:318
bool writtenHeader_
Flag to identify whether the header has been written.
Definition: writeFile.H:148
virtual OFstream & file()
Return access to the file (if only 1)
Definition: writeFile.C:233
virtual void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
Definition: writeFile.C:269
virtual bool write(const bool valid=true) const
Write using setting from DB.
A class for handling words, derived from Foam::string.
Definition: word.H:68
This boundary condition applies a zero-gradient condition from the patch internal field onto the patc...
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
engineTime & runTime
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
const dimensionSet dimless
Dimensionless.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
dictionary dict