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 :
60  timeFunctionObject(name, runTime)
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 // ************************************************************************* //
dictionary dict
defineTypeNameAndDebug(ObukhovLength, 0)
multiRegion(const multiRegion &)=delete
No copy construct.
virtual bool read(const dictionary &dict)
Read the controls.
Definition: multiRegion.C:61
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
static bool entriesPresent(const dictionary &dict)
Helper function to identify if a timeControl object is present.
virtual bool write()
Write the multiRegion.
Definition: multiRegion.C:149
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
Wrapper around functionObjects to add time control.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
Macros for easy insertion into run-time selection tables.
const word & name() const noexcept
Return the name of this functionObject.
static word scopedName(const std::string &scope, const word &name)
Create scope:name or scope_name string.
Definition: IOobjectI.H:40
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
PtrList< functionObject > functions_
List of cloned objects (1 per region)
Definition: multiRegion.H:130
A class for handling words, derived from Foam::string.
Definition: word.H:63
wordList sortedNames() const
The sorted names of all objects.
virtual const word & type() const =0
Runtime type information.
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:53
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:159
void read(Istream &, label &val, const dictionary &)
In-place read with dictionary lookup.
addToRunTimeSelectionTable(functionObject, ObukhovLength, dictionary)
labelList f(nPoints)
void resize(const label newLen)
Adjust size of PtrList.
Definition: PtrList.C:95
bool empty() const noexcept
True if the list is empty (ie, size() is zero)
Definition: UPtrListI.H:99
#define WarningInFunction
Report a warning using Foam::Warning.
Foam::word regionName(args.getOrDefault< word >("region", Foam::polyMesh::defaultRegion))
virtual bool read(const dictionary &dict)
Read and set the function object if its data have changed.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
bool match(const std::string &text, bool literal=false) const
Smart match as literal or regex, stopping on the first match.
Definition: wordResI.H:84
messageStream Info
Information stream (stdout output on master, null elsewhere)
static autoPtr< functionObject > New(const word &name, const Time &runTime, const dictionary &dict)
Select from dictionary, based on its "type" entry.
virtual bool execute()
Execute, currently does nothing.
Definition: multiRegion.C:136
Namespace for OpenFOAM.
const Time & time_
Reference to the time database.