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 -------------------------------------------------------------------------------
10 License
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 
35 namespace Foam
36 {
37 namespace functionObjects
38 {
39  defineTypeNameAndDebug(multiRegion, 0);
40 
42  (
43  functionObject,
44  multiRegion,
45  dictionary
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  {
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 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::objectRegistry::sortedNames
wordList sortedNames() const
The sorted names of all objects.
Definition: objectRegistry.C:153
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::functionObject::New
static autoPtr< functionObject > New(const word &name, const Time &runTime, const dictionary &dict)
Select from dictionary, based on its "type" entry.
Definition: functionObject.C:79
Foam::functionObjects::timeFunctionObject::time_
const Time & time_
Reference to the time database.
Definition: timeFunctionObject.H:65
multiRegion.H
Foam::functionObjects::timeControl
Wrapper around functionObjects to add time control.
Definition: timeControlFunctionObject.H:76
Foam::functionObjects::timeFunctionObject
Virtual base class for function objects with a reference to Time.
Definition: timeFunctionObject.H:56
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::PtrList::set
const T * set(const label i) const
Return const pointer to element (can be nullptr),.
Definition: PtrList.H:138
Foam::functionObjects::multiRegion::functions_
PtrList< functionObject > functions_
List of cloned objects (1 per region)
Definition: multiRegion.H:132
Foam::wordRes::match
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
Foam::blockMeshTools::read
void read(Istream &, label &val, const dictionary &)
In-place read with dictionary lookup.
Definition: blockMeshTools.C:57
Foam::functionObjects::multiRegion::read
virtual bool read(const dictionary &dict)
Read the controls.
Definition: multiRegion.C:68
regionName
Foam::word regionName
Definition: createNamedDynamicFvMesh.H:1
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::functionObjects::multiRegion::multiRegion
multiRegion(const multiRegion &)=delete
No copy construct.
Foam::functionObject::read
virtual bool read(const dictionary &dict)
Read and set the function object if its data have changed.
Definition: functionObject.C:163
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
fvMesh.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::PtrList::resize
void resize(const label newLen)
Adjust size of PtrList.
Definition: PtrList.C:103
Foam::functionObject::name
const word & name() const noexcept
Return the name of this functionObject.
Definition: functionObject.C:143
Foam::nl
constexpr char nl
Definition: Ostream.H:404
f
labelList f(nPoints)
Foam::functionObjects::addToRunTimeSelectionTable
addToRunTimeSelectionTable(functionObject, ObukhovLength, dictionary)
Foam::functionObject::type
virtual const word & type() const =0
Runtime type information.
Foam::List< word >
Foam::functionObjects::multiRegion::write
virtual bool write()
Write the multiRegion.
Definition: multiRegion.C:156
timeControlFunctionObject.H
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:51
Foam::functionObjects::defineTypeNameAndDebug
defineTypeNameAndDebug(ObukhovLength, 0)
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::dictionary::add
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:640
Foam::functionObjects::timeControl::entriesPresent
static bool entriesPresent(const dictionary &dict)
Helper function to identify if a timeControl object is present.
Definition: timeControlFunctionObject.C:473
Foam::IOobject::scopedName
static word scopedName(const std::string &scope, const word &name)
Create scope:name or scope_name string.
Definition: IOobjectI.H:47
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:328
Foam::functionObjects::multiRegion::execute
virtual bool execute()
Execute, currently does nothing.
Definition: multiRegion.C:143