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-------------------------------------------------------------------------------
10License
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
35namespace Foam
36{
37namespace functionObjects
38{
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 {
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// ************************************************************************* //
#define Log
Definition: PDRblock.C:35
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
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
Class to handle errors and exceptions in a simple, consistent stream-based manner.
Definition: error.H:77
Abstract base-class for Time/database function objects.
Computes local, global and cumulative continuity errors for a flux field.
virtual void writeFileHeader(Ostream &os)
Output file header information.
virtual bool execute()
Execute, currently does nothing.
virtual bool write()
Write the continuityError.
virtual bool read(const dictionary &)
Read the field min/max data.
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Computes the magnitude of an input field.
Definition: mag.H:153
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 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
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
engineTime & runTime
OBJstream os(runTime.globalPath()/outputName)
Calculate the divergence of the given field.
#define WarningInFunction
Report a warning using Foam::Warning.
tmp< GeometricField< Type, fvPatchField, volMesh > > div(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition: fvcDiv.C:49
Namespace for OpenFOAM.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:598
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
constexpr char tab
The tab '\t' character(0x09)
Definition: Ostream.H:52
dictionary dict