multiRegion.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) 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 "multiRegion.H"
29#include "fvMesh.H"
32
33// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34
35namespace Foam
36{
37namespace functionObjects
38{
40
42 (
46 );
47}
48}
49
50
51// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
52
54(
55 const word& name,
56 const Time& runTime,
57 const dictionary& dict
58)
59:
61{
62 read(dict);
63}
64
65
66// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
67
69{
71 {
72 Info<< type() << ' ' << name() << ':' << nl;
73
74 wordRes regionMatcher;
75
76 const bool matchAny =
77 !dict.readIfPresent<wordRes>("regions", regionMatcher);
78
79 const dictionary& functionDict = dict.subDict("function");
80
81 const wordList allRegions(time_.sortedNames<fvMesh>());
82 functions_.resize(allRegions.size());
83
84 const bool needsTimeControl = timeControl::entriesPresent(functionDict);
85
86 label functioni = 0;
87 for (const word& regionName : allRegions)
88 {
89 if (matchAny || regionMatcher.match(regionName))
90 {
91 const word localName(IOobject::scopedName(name(), regionName));
92
93 dictionary regionDict(functionDict);
94 regionDict.add("region", regionName);
95
96 if (needsTimeControl)
97 {
98 functions_.set
99 (
100 functioni,
101 new timeControl(localName, time_, regionDict)
102 );
103 }
104 else
105 {
106 functions_.set
107 (
108 functioni,
109 functionObject::New(localName, time_, regionDict)
110 );
111 }
112
113 ++functioni;
114 }
115 }
116
117 functions_.resize(functioni);
118
119 if (functions_.empty())
120 {
122 << "No regions applied"
123 << endl;
124
125 return false;
126 }
127
128 Info<< " Spawned additional object(s):" << nl;
129 for (const auto& f : functions_)
130 {
131 Info<< " " << f.name() << nl;
132 }
133
134 Info<< endl;
135
136 return true;
137 }
138
139 return false;
140}
141
142
144{
145 bool result = true;
146
147 for (auto& f : functions_)
148 {
149 result = f.execute() && result;
150 }
151
152 return result;
153}
154
155
157{
158 bool result = true;
159
160 for (auto& f : functions_)
161 {
162 result = f.write() && result;
163 }
164
165 return result;
166}
167
168
169// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
static word scopedName(const std::string &scope, const word &name)
Create scope:name or scope_name string.
Definition: IOobjectI.H:47
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
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
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
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:640
Abstract base-class for Time/database function objects.
Wrapper that clones the supplied function object for each region.
Definition: multiRegion.H:126
virtual bool read(const dictionary &dict)
Read the controls.
Definition: multiRegion.C:68
virtual bool execute()
Execute, currently does nothing.
Definition: multiRegion.C:143
virtual bool write()
Write the multiRegion.
Definition: multiRegion.C:156
Wrapper around functionObjects to add time control.
static bool entriesPresent(const dictionary &dict)
Helper function to identify if a timeControl object is present.
Virtual base class for function objects with a reference to Time.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:54
bool match(const std::string &text, bool literal=false) const
Smart match as literal or regex, stopping on the first match.
Definition: wordResI.H:91
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
Foam::word regionName(Foam::polyMesh::defaultRegion)
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
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
labelList f(nPoints)
dictionary dict