Loading...
Searching...
No Matches
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"
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");
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
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:28
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:59
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
Class to handle errors and exceptions in a simple, consistent stream-based manner.
Definition error.H:74
Abstract base-class for Time/database function objects.
virtual bool read(const dictionary &dict)
Read and set the function object if its data have changed.
Computes local, global and cumulative continuity errors for a flux field.
virtual bool read(const dictionary &dict)
Read the function-object dictionary.
continuityError(const word &name, const Time &runTime, const dictionary &dict)
Construct from name, Time and dictionary.
virtual void writeFileHeader(Ostream &os)
Output file header information.
virtual bool execute()
Execute the function-object operations.
virtual bool write()
Write the function-object results.
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
const fvMesh & mesh_
Reference to the fvMesh.
fvMeshFunctionObject(const fvMeshFunctionObject &)=delete
No copy construct.
void setResult(const word &entryName, const Type &value)
Add result.
void setProperty(const word &entryName, const Type &value)
Add generic property.
Type getProperty(const word &entryName, const Type &defaultValue=Type(Zero)) const
Retrieve generic property.
Base class for writing single files from the function objects.
Definition writeFile.H:113
writeFile(const objectRegistry &obr, const fileName &prefix, const word &name="undefined", const bool writeToFile=true, const string &ext=".dat")
Construct from objectRegistry, prefix, fileName.
Definition writeFile.C:200
virtual void writeHeader(Ostream &os, const string &str) const
Write a commented header to stream.
Definition writeFile.C:344
virtual bool read(const dictionary &dict)
Read.
Definition writeFile.C:240
virtual OFstream & file()
Return access to the file (if only 1).
Definition writeFile.C:270
virtual void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
Definition writeFile.C:318
virtual void writeCurrentTime(Ostream &os) const
Write the current time to stream.
Definition writeFile.C:354
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
bool local
Definition EEqn.H:20
engineTime & runTime
OBJstream os(runTime.globalPath()/outputName)
Calculate the divergence of the given field.
auto & name
#define WarningInFunction
Report a warning using Foam::Warning.
Function objects are OpenFOAM utilities to ease workflow configurations and enhance workflows.
tmp< GeometricField< Type, fvPatchField, volMesh > > div(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition fvcDiv.C:42
Namespace for OpenFOAM.
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Type weightedAverage(const UList< scalar > &weights, const UList< Type > &fld)
The local weighted average of a field, using the mag() of the weights.
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition POSIX.C:801
const word GlobalIOList< Tuple2< scalar, vector > >::typeName("scalarVectorTable")
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
constexpr char tab
The tab '\t' character(0x09).
Definition Ostream.H:49
dictionary dict