ddt2.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) 2016-2021 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 "ddt2.H"
29#include "stringOps.H"
30#include "stringListOps.H"
31#include "volFields.H"
32#include "dictionary.H"
33#include "wordRes.H"
36
37// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38
39namespace Foam
40{
41namespace functionObjects
42{
45}
46}
47
48// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
49
50bool Foam::functionObjects::ddt2::checkFormatName
51(
52 const std::string& str
53)
54{
55 if (std::string::npos == str.find("@@"))
56 {
58 << "Bad result naming (no '@@' token found)."
59 << nl << endl;
60
61 return false;
62 }
63 else if (str == "@@")
64 {
66 << "Bad result naming (only a '@@' token found)."
67 << nl << endl;
68
69 return false;
70 }
71
72 return true;
73}
74
75
76bool Foam::functionObjects::ddt2::accept(const word& fieldName) const
77{
78 // check input vs possible result names
79 // to avoid circular calculations
80 return !denyField_.match(fieldName);
81}
82
83
84int Foam::functionObjects::ddt2::process(const word& fieldName)
85{
86 if (!accept(fieldName))
87 {
88 return -1;
89 }
90
91 int state = 0;
92
93 apply<volScalarField>(fieldName, state);
94 apply<volVectorField>(fieldName, state);
95
96 return state;
97}
98
99
100// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
101
103(
104 const word& name,
105 const Time& runTime,
106 const dictionary& dict
107)
108:
110 selectFields_(),
111 resultName_(),
112 denyField_(),
113 results_(),
114 mag_(dict.getOrDefault("mag", false))
115{
116 read(dict);
117}
118
119
120// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
121
123{
125
126 if (word(mesh_.ddtScheme("default")) == "steadyState")
127 {
129 << typeName << " function object not appropriate for steady-state"
130 << endl;
131 return false;
132 }
133
134 dict.readEntry("fields", selectFields_);
135 selectFields_.uniq();
136
137 Info<< type() << " fields: " << selectFields_ << nl;
138
139 resultName_ = dict.getOrDefault<word>
140 (
141 "result",
142 ( mag_ ? "mag(ddt(@@))" : "magSqr(ddt(@@))" )
143 );
144
145 // Expect '@@' token for result, unless a single (non-regex) source field
146 if
147 (
148 (selectFields_.size() == 1 && selectFields_.first().isLiteral())
149 || checkFormatName(resultName_)
150 )
151 {
152 denyField_.set
153 (
154 stringOps::quotemeta(resultName_, regExp::meta())
155 .replace("@@", "(.+)")
156 );
157
158 return true;
159 }
160
161 denyField_.clear();
162 return false;
163}
164
165
167{
168 results_.clear();
169
170 wordHashSet candidates(subsetStrings(selectFields_, mesh_.names()));
171 DynamicList<word> missing(selectFields_.size());
172 DynamicList<word> ignored(selectFields_.size());
173
174 // Check exact matches first
175 for (const wordRe& select : selectFields_)
176 {
177 if (select.isLiteral())
178 {
179 const word& fieldName = select;
180
181 if (!candidates.erase(fieldName))
182 {
183 missing.append(fieldName);
184 }
185 else if (process(fieldName) < 1)
186 {
187 ignored.append(fieldName);
188 }
189 }
190 }
191
192 for (const word& fieldName : candidates)
193 {
194 process(fieldName);
195 }
196
197 if (missing.size())
198 {
200 << "Missing field " << missing << endl;
201 }
202 if (ignored.size())
203 {
205 << "Unprocessed field " << ignored << endl;
206 }
207
208 return true;
209}
210
211
213{
214 if (results_.size())
215 {
216 Log << type() << ' ' << name() << " write:" << endl;
217 }
218
219 // Consistent output order
220 const wordList outputList = results_.sortedToc();
221 for (const word& fieldName : outputList)
222 {
223 if (foundObject<regIOobject>(fieldName))
224 {
225 const regIOobject& io = lookupObject<regIOobject>(fieldName);
226
227 Log << " " << fieldName << endl;
228
229 io.write();
230 }
231 }
232
233 return true;
234}
235
236
237// ************************************************************************* //
#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.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:72
void append(const T &val)
Copy append an element to the end of this list.
Definition: DynamicListI.H:503
bool erase(const iterator &iter)
Erase an entry specified by given iterator.
Definition: HashTable.C:440
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
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
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.
Computes the magnitude or magnitude squared of the Eulerian time derivative of an input volume field ...
Definition: ddt2.H:181
virtual bool execute()
Calculate the ddt2 fields.
Definition: ddt2.C:166
virtual bool write()
Write the ddt2 fields.
Definition: ddt2.C:212
virtual bool read(const dictionary &)
Read the ddt2 specification.
Definition: ddt2.C:122
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:76
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
Definition: wordRe.H:83
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
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
#define WarningInFunction
Report a warning using Foam::Warning.
StringType quotemeta(const StringType &str, const UnaryPredicate &meta, const char quote='\\')
Quote any meta-characters in given string.
Namespace for OpenFOAM.
StringListType subsetStrings(const regExp &matcher, const StringListType &input, const bool invert=false)
Extract elements of StringList when regular expression matches.
messageStream Info
Information stream (stdout output on master, null elsewhere)
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
dictionary dict
Operations on lists of strings.
Functor wrapper for testing meta-characters.
Definition: regExpCxx.H:147