continuityError.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) 2019-2020 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "continuityError.H"
29 #include "volFields.H"
30 #include "fvcDiv.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 namespace functionObjects
38 {
39  defineTypeNameAndDebug(continuityError, 0);
40  addToRunTimeSelectionTable(functionObject, continuityError, dictionary);
41 }
42 }
43 
44 
45 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
46 
48 {
49  writeHeader(os, "Continuity error");
50 
51  writeCommented(os, "Time");
52  writeCommented(os, "Local");
53  writeCommented(os, "Global");
54  writeCommented(os, "Cumulative");
55 
56  os << endl;
57 }
58 
59 
60 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
61 
63 (
64  const word& name,
65  const Time& runTime,
66  const dictionary& dict
67 )
68 :
70  writeFile(mesh_, name, typeName, dict),
71  phiName_("phi"),
72  cumulative_(getProperty<scalar>("cumulative"))
73 {
74  if (read(dict))
75  {
76  writeFileHeader(file());
77  }
78 }
79 
80 
81 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
82 
84 {
86  {
87  dict.readIfPresent("phi", phiName_);
88 
89  return true;
90  }
91 
92  return false;
93 }
94 
95 
97 {
98  return true;
99 }
100 
101 
103 {
104  const auto* phiPtr = mesh_.cfindObject<surfaceScalarField>(phiName_);
105 
106  if (!phiPtr)
107  {
109  << "Unable to find flux field " << phiName_
110  << endl;
111 
112  return false;
113  }
114 
115  const volScalarField error(fvc::div(*phiPtr));
116  const scalar deltaT = mesh_.time().deltaTValue();
117 
118  const scalar local = deltaT*mag(error)().weightedAverage(mesh_.V()).value();
119  const scalar global = deltaT*error.weightedAverage(mesh_.V()).value();
120  cumulative_ += global;
121 
122  Ostream& os = file();
123 
124  writeCurrentTime(os);
125 
126  os << local << tab
127  << global << tab
128  << cumulative_ << endl;
129 
130  Log << type() << " " << name() << " write:" << nl
131  << " local = " << local << nl
132  << " global = " << global << nl
133  << " cumulative = " << cumulative_ << nl
134  << endl;
135 
136  setResult("local", local);
137  setResult("global", global);
138  setResult("cumulative", cumulative_);
139 
140  setProperty<scalar>("cumulative", cumulative_);
141 
142  return true;
143 }
144 
145 
146 // ************************************************************************* //
volFields.H
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Log
#define Log
Definition: PDRblock.C:35
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
fvcDiv.H
Calculate the divergence of the given field.
Foam::fvc::div
tmp< GeometricField< Type, fvPatchField, volMesh > > div(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition: fvcDiv.C:49
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::functionObjects::fvMeshFunctionObject
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Definition: fvMeshFunctionObject.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::read
virtual bool read(const dictionary &dict)
Read.
Definition: writeFile.C:213
Foam::functionObjects::continuityError::write
virtual bool write()
Write the continuityError.
Definition: continuityError.C:102
Foam::functionObjects::continuityError::execute
virtual bool execute()
Execute, currently does nothing.
Definition: continuityError.C:96
Foam::functionObjects::continuityError::continuityError
continuityError(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
Definition: continuityError.C:63
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::functionObjects::continuityError::read
virtual bool read(const dictionary &)
Read the field min/max data.
Definition: continuityError.C:83
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::functionObjects::writeFile::writeCommented
virtual void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
Definition: writeFile.C:272
Foam::tab
constexpr char tab
Definition: Ostream.H:403
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::functionObjects::addToRunTimeSelectionTable
addToRunTimeSelectionTable(functionObject, ObukhovLength, dictionary)
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
Foam::functionObjects::continuityError::writeFileHeader
virtual void writeFileHeader(Ostream &os)
Output file header information.
Definition: continuityError.C:47
Foam::functionObjects::defineTypeNameAndDebug
defineTypeNameAndDebug(ObukhovLength, 0)
continuityError.H
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::GeometricField< scalar, fvsPatchField, surfaceMesh >
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:328
Foam::error
Class to handle errors and exceptions in a simple, consistent stream-based manner.
Definition: error.H:73