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 -------------------------------------------------------------------------------
11 License
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 
34 namespace Foam
35 {
36 namespace functionObjects
37 {
38  defineTypeNameAndDebug(solverInfo, 0);
39  addToRunTimeSelectionTable(functionObject, solverInfo, dictionary);
40 }
41 }
42 
43 
44 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
45 
47 {
49  {
50  return;
51  }
52 
53  if (writtenHeader_)
54  {
55  writeBreak(file());
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 =
97  new IOField<scalar>
98  (
99  IOobject
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  (
209  IOobject
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 // ************************************************************************* //
Foam::IOobject::NO_WRITE
Definition: IOobject.H:195
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::functionObjects::solverFieldSelection::updateSelection
virtual bool updateSelection()
Update the selection using current contents of obr_.
Definition: solverFieldSelection.C:54
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
solverInfo.H
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::functionObjects::solverInfo::read
virtual bool read(const dictionary &)
Read solverInfo settings.
Definition: solverInfo.C:139
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::functionObjects::writeFile::file
virtual OFstream & file()
Return access to the file (if only 1)
Definition: writeFile.C:236
Foam::IOField
A primitive field of type <T> with automated input and output.
Definition: foamVtkLagrangianWriter.H:61
Foam::functionObjects::writeFile::writtenHeader_
bool writtenHeader_
Flag to identify whether the header has been written.
Definition: writeFile.H:148
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::functionObjects::fieldSelection::selectionNames
wordHashSet selectionNames() const
Return the current field selection.
Definition: fieldSelectionI.H:50
Foam::functionObjects::fvMeshFunctionObject
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Definition: fvMeshFunctionObject.H:64
Foam::zeroGradientFvPatchField
This boundary condition applies a zero-gradient condition from the patch internal field onto the patc...
Definition: zeroGradientFvPatchField.H:64
Foam::functionObjects::writeFile::writeHeader
virtual void writeHeader(Ostream &os, const string &str) const
Write a commented header to stream.
Definition: writeFile.C:298
Foam::functionObjects::writeFile::writeBreak
virtual void writeBreak(Ostream &os) const
Write a break marker to the stream.
Definition: writeFile.C:321
Foam::functionObjects::solverInfo::execute
virtual bool execute()
Execute solverInfo.
Definition: solverInfo.C:158
Foam::Field< scalar >
Foam::dimensionedScalar
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Definition: dimensionedScalarFwd.H:42
Foam::functionObjects::solverInfo::solverInfo
solverInfo(const solverInfo &)=delete
No copy construct.
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::functionObjects::regionFunctionObject::read
virtual bool read(const dictionary &dict)
Read optional controls.
Definition: regionFunctionObject.C:173
os
OBJstream os(runTime.globalPath()/outputName)
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::GeometricField::primitiveFieldRef
Internal::FieldType & primitiveFieldRef(const bool updateAccessTime=true)
Return a reference to the internal field.
Definition: GeometricField.C:766
Foam::functionObjects::writeFile::writeCommented
virtual void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
Definition: writeFile.C:272
Foam::functionObjects::solverInfo::writeFileHeader
void writeFileHeader(Ostream &os)
Output file header information.
Definition: solverInfo.C:46
Foam::functionObjects::addToRunTimeSelectionTable
addToRunTimeSelectionTable(functionObject, ObukhovLength, dictionary)
Foam::functionObjects::solverInfo::write
virtual bool write()
Write solverInfo results.
Definition: solverInfo.C:198
Foam::functionObjects::solverInfo::fieldSet_
solverFieldSelection fieldSet_
Names of operand fields.
Definition: solverInfo.H:178
Foam::functionObjects::defineTypeNameAndDebug
defineTypeNameAndDebug(ObukhovLength, 0)
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::functionObjects::writeFile
Base class for writing single files from the function objects.
Definition: writeFile.H:119
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::IOobject::scopedName
static word scopedName(const std::string &scope, const word &name)
Create scope:name or scope_name string.
Definition: IOobjectI.H:47
Foam::GeometricField< scalar, fvPatchField, volMesh >
Foam::IOobject::NO_READ
Definition: IOobject.H:188
Foam::functionObjects::solverInfo::createResidualField
void createResidualField(const word &fieldName)
Create and store a residual field on the mesh database.
Definition: solverInfo.C:80
Foam::dimless
const dimensionSet dimless
Dimensionless.
Definition: dimensionSets.C:189