Loading...
Searching...
No Matches
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"
33// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
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:
60 timeFunctionObject(name, runTime)
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 {
99 (
100 functioni,
101 new timeControl(localName, time_, regionDict)
102 );
103 }
104 else
105 {
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:50
const T * set(const label i) const
Return const pointer to element (can be nullptr), or nullptr for out-of-range access (ie,...
Definition PtrList.H:171
void resize(const label newLen)
Adjust size of PtrList.
Definition PtrList.C:124
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
Definition dictionary.C:625
Abstract base-class for Time/database function objects.
const word & name() const noexcept
Return the name of this functionObject.
virtual bool read(const dictionary &dict)
Read and set the function object if its data have changed.
virtual const word & type() const =0
Runtime type information.
static autoPtr< functionObject > New(const word &name, const Time &runTime, const dictionary &dict)
Select from dictionary, based on its "type" entry.
Wrapper that clones the supplied function object for each region.
multiRegion(const multiRegion &)=delete
No copy construct.
PtrList< functionObject > functions_
List of cloned objects (1 per region).
virtual bool read(const dictionary &dict)
Read the function-object dictionary.
Definition multiRegion.C:61
virtual bool execute()
Execute the function-object operations (no-op).
virtual bool write()
Write the function-object results.
Wrapper around functionObjects to add time control.
static bool entriesPresent(const dictionary &dict)
Helper function to identify if a timeControl object is present.
const Time & time_
Reference to the time database.
timeFunctionObject(const timeFunctionObject &)=delete
No copy construct.
Mesh data needed to do the Finite Volume discretisation.
Definition fvMesh.H:85
wordList sortedNames() const
The sorted names of all objects.
A List of wordRe with additional matching capabilities.
Definition wordRes.H:56
static bool match(const UList< wordRe > &selectors, const std::string &text, bool literal=false)
Test for a match of any selectors against the text.
Definition wordResI.H:47
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
engineTime & runTime
Foam::word regionName(args.getOrDefault< word >("region", Foam::polyMesh::defaultRegion))
auto & name
#define WarningInFunction
Report a warning using Foam::Warning.
Function objects are OpenFOAM utilities to ease workflow configurations and enhance workflows.
Namespace for OpenFOAM.
List< word > wordList
List of word.
Definition fileName.H:60
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 POSIX.C:801
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
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
labelList f(nPoints)
dictionary dict