zoneGeneratorList.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2025 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "zoneGeneratorList.H"
27 #include "lookup.H"
28 #include "polyMesh.H"
29 
30 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
31 
33 (
34  const dictionary& dict,
35  const bool topLevel
36 )
37 {
38  setSize(dict.size());
39 
40  label i = 0;
41 
43  {
44  const word& name = iter().keyword();
45 
46  if (iter().isDict())
47  {
48  if (iter().dict().found("type"))
49  {
50  this->set
51  (
52  i,
53  name,
54  zoneGenerator::New(name, mesh_, iter().dict())
55  );
56  }
57  else
58  {
59  if (topLevel)
60  {
61  // If the type is not specified
62  // assume the zoneGenerator type is the same as the name
63  this->set
64  (
65  i,
66  name,
68  (
69  name,
70  mesh_,
72  (
73  iter().dict(),
75  (
77  (
78  "type",
79  name,
80  iter().startLineNumber()
81  )
82  )
83  )
84  )
85  );
86  }
87  else
88  {
89  // If the type is not specified assume the it is a lookup
90  this->set
91  (
92  i,
93  name,
94  new zoneGenerators::lookup(name, mesh_, iter().dict())
95  );
96  }
97  }
98 
99  i++;
100  }
101  else if (!iter().stream().size())
102  {
103  if (topLevel)
104  {
105  // If an empty keyword is present assume it is a
106  // zoneGenerator type and add to the list
107  this->set
108  (
109  i,
110  name,
112  (
113  name,
114  mesh_,
115  dictionary
116  (
117  name,
118  dict,
120  (
122  (
123  "type",
124  name,
125  iter().startLineNumber()
126  )
127  )
128  )
129  )
130  );
131  }
132  else
133  {
134  // If an empty keyword is present assume it is a zone name
135  // and add a zone lookup
136  this->set
137  (
138  i,
139  name,
141  (
142  name,
143  mesh_,
144  dictionary
145  (
146  name,
147  dict,
149  (
151  (
152  "type",
153  zoneGenerators::lookup::typeName,
154  iter().startLineNumber()
155  )
156  )
157  )
158  )
159  );
160  }
161 
162  i++;
163  }
164  }
165 
166  setSize(i);
167 }
168 
169 
170 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
171 
173 :
175  mesh_(mesh)
176 {}
177 
178 
180 (
181  const polyMesh& mesh,
182  const dictionary& dict,
183  const bool topLevel
184 )
185 :
187 {
188  read(dict, topLevel);
189 }
190 
191 
193 (
194  const polyMesh& mesh,
195  const dictionary& dict,
196  const word& zoneName,
197  const word& zonesName
198 )
199 :
201 {
202  if (dict.found(zoneName) && dict.found(zonesName))
203  {
205  << "Both " << zoneName << " and " << zonesName << " specified"
206  << exit(FatalIOError);
207  }
208 
209  if (dict.found(zoneName))
210  {
211  if (dict.isDict(zoneName))
212  {
213  append
214  (
215  zoneName,
216  zoneGenerator::New(zoneName, mesh_, dict.subDict(zoneName))
217  );
218  }
219  else
220  {
221  ITstream& zoneStream(dict.lookup(zoneName));
222  const word name(zoneStream);
223  append
224  (
225  name,
227  (
228  name,
229  mesh,
230  dictionary
231  (
232  name,
233  dict,
235  (
237  (
238  "type",
239  zoneGenerators::lookup::typeName,
240  zoneStream.lineNumber()
241  )
242  )
243  )
244  )
245  );
246  }
247  }
248  else if (dict.found(zonesName))
249  {
250  read(dict.subDict(zonesName));
251  }
252 }
253 
254 
255 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
256 
258 {
259  const PtrListDictionary<zoneGenerator>& zgList(*this);
260 
261  forAll(zgList, i)
262  {
263  if (zgList[i].moveUpdate_)
264  {
265  return true;
266  }
267  }
268 
269  return false;
270 }
271 
272 
274 {
275  PtrListDictionary<zoneGenerator>& zgList(*this);
276 
277  forAll(zgList, i)
278  {
279  zgList[i].generate().store();
280  }
281 }
282 
283 
285 {
286  PtrListDictionary<zoneGenerator>& zgList(*this);
287 
288  forAll(zgList, i)
289  {
290  zgList[i].movePoints().store();
291  }
292 }
293 
294 
295 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:433
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:476
bool found(const word &) const
Search DictionaryBase for given keyword.
label lineNumber() const
Return current stream line number.
Definition: IOstream.H:450
Input token stream.
Definition: ITstream.H:53
Template dictionary class which manages the storage associated with it.
void append(const word &key, zoneGenerator *)
Append an element at the end of the list.
autoPtr< zoneGenerator > set(const label, const word &key, zoneGenerator *)
Set element to pointer provided and return old element.
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
static std::tuple< const Entries &... > entries(const Entries &...)
Construct an entries tuple from which to make a dictionary.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
A keyword and a list of tokens is a 'primitiveEntry'. An primitiveEntry can be read,...
A class for handling words, derived from string.
Definition: word.H:62
List of zoneGenerators.
void read(const dictionary &dict, const bool topLevel=false)
void generate()
Generate and register the zones.
void movePoints()
Update the zones following mesh point movement.
zoneGeneratorList(const polyMesh &mesh)
Construct from mesh.
const polyMesh & mesh_
Reference to the polyMesh.
bool moveUpdate() const
Return true if any of the zoneGenerators updates any of the zones.
Abstract base class for all zoneGenerators, providing runtime selection.
Definition: zoneGenerator.H:57
static autoPtr< zoneGenerator > New(const word &name, const polyMesh &mesh, const dictionary &dict)
Select constructed from name, mesh and dictionary.
Definition: zoneGenerator.C:66
A zoneGenerator which looks-up and returns a zoneSet containing point, and/or cell and/or faces zones...
Definition: lookup.H:139
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
IOerror FatalIOError
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
points setSize(newPointi)
dictionary dict