zoneGenerator.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 "zoneGenerator.H"
27 #include "dlLibraryTable.H"
28 #include "lookup.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
36 }
37 
38 
39 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40 
42 (
43  const word& name,
44  const polyMesh& mesh,
45  const dictionary& dict
46 )
47 :
48  name_(name),
49  dict_(dict),
50  zoneName_(dict.lookupOrDefault("name", name)),
51  mesh_(mesh),
52  moveUpdate_(dict.lookupOrDefault("moveUpdate", false))
53 {}
54 
55 
56 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
57 
59 {}
60 
61 
62 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
63 
66 (
67  const word& name,
68  const polyMesh& mesh,
69  const dictionary& dict
70 )
71 {
72  const word type(dict.lookup("type"));
73 
74  if (debug)
75  {
77  << "Constructing " << typeName
78  << " " << name << " of type " << type << endl;
79  }
80 
81  if
82  (
83  !dictionaryConstructorTablePtr_
84  || dictionaryConstructorTablePtr_->find(type)
85  == dictionaryConstructorTablePtr_->end()
86  )
87  {
88  if
89  (
90  !libs.open
91  (
92  dict,
93  "libs",
94  dictionaryConstructorTablePtr_
95  )
96  )
97  {
98  libs.open("lib" + type.remove(':') + ".so", false);
99  }
100 
101  if (!dictionaryConstructorTablePtr_)
102  {
104  << "Unknown " << typeName << " type "
105  << type << nl << nl
106  << "Table of " << typeName << " is empty"
107  << exit(FatalError);
108  }
109  }
110 
111  dictionaryConstructorTable::iterator cstrIter =
112  dictionaryConstructorTablePtr_->find(type);
113 
114  if (cstrIter == dictionaryConstructorTablePtr_->end())
115  {
117  (
118  dict
119  ) << "Unknown " << typeName << " type "
120  << type << nl << nl
121  << "Valid " << typeName << " types are:" << nl
122  << dictionaryConstructorTablePtr_->sortedToc()
123  << exit(FatalIOError);
124  }
125 
126  return autoPtr<zoneGenerator>(cstrIter()(name, mesh, dict));
127 }
128 
129 
132 (
133  const word& name,
134  const zoneTypes& zoneType,
135  const polyMesh& mesh,
136  const dictionary& dict
137 )
138 {
139  return New
140  (
141  name,
142  mesh,
143  // Copy the dictionary and add the zoneType entry
144  dictionary
145  (
146  dict,
148  (
150  (
151  "zoneType",
152  zoneTypesNames[zoneType],
154  )
155  )
156  )
157  );
158 }
159 
160 
163 (
164  const polyMesh& mesh,
165  const dictionary& dict
166 )
167 {
168  if (debug)
169  {
171  << "Constructing " << typeName << endl;
172  }
173 
175  {
176  const word& name = iter().keyword();
177 
178  if (iter().isDict())
179  {
180  if (iter().dict().found("type"))
181  {
182  return zoneGenerator::New(name, mesh, iter().dict());
183  }
184  else
185  {
186  // If an empty keyword is present assume it is a zone name
187  // and add a zone lookup
189  (
190  new zoneGenerators::lookup(name, mesh, iter().dict())
191  );
192  }
193  }
194  else if (!iter().stream().size())
195  {
196  // If an empty keyword is present assume it is a zone name
197  // and add a zone lookup
199  (
201  (
202  name,
203  mesh,
204  dictionary
205  (
206  name,
207  dict,
209  (
211  (
212  "type",
213  zoneGenerators::lookup::typeName,
214  iter().startLineNumber()
215  )
216  )
217  )
218  )
219  );
220  }
221  }
222 
224  << "Cannot find valid " << typeName
225  << " entry in dictionary " << dict << exit(FatalIOError);
226 
227  return autoPtr<zoneGenerator>(nullptr);
228 }
229 
230 
231 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
232 
234 {
235  label nSelected = 0;
236  forAll(selected, i)
237  {
238  if (selected[i])
239  {
240  nSelected++;
241  }
242  }
243 
244  labelList selectedIndices(nSelected);
245 
246  label ui = 0;
247  forAll(selected, i)
248  {
249  if (selected[i])
250  {
251  selectedIndices[ui++] = i;
252  }
253  }
254 
255  return selectedIndices;
256 }
257 
258 
260 {
261  if (moveUpdate_)
262  {
263  return generate();
264  }
265  else
266  {
267  return zoneSet();
268  }
269 }
270 
271 
272 // ************************************************************************* //
bool found
#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
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:740
virtual label endLineNumber() const
Return line number of last token in dictionary.
Definition: dictionary.C:485
static std::tuple< const Entries &... > entries(const Entries &...)
Construct an entries tuple from which to make a dictionary.
bool open(const fileName &libName, const bool verbose=true)
Open the named library, optionally with warnings if problems occur.
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
Abstract base class for all zoneGenerators, providing runtime selection.
Definition: zoneGenerator.H:57
virtual ~zoneGenerator()
Destructor.
Definition: zoneGenerator.C:58
static labelList indices(const boolList &selected)
Return the list of selected indices.
virtual zoneSet movePoints() const
Regenerate the zoneSet following mesh point motion.
static autoPtr< zoneGenerator > New(const word &name, const polyMesh &mesh, const dictionary &dict)
Select constructed from name, mesh and dictionary.
Definition: zoneGenerator.C:66
zoneGenerator(const word &name, const polyMesh &mesh, const dictionary &dict)
Construct from name, polyMesh and dictionary.
Definition: zoneGenerator.C:42
A zoneGenerator which looks-up and returns a zoneSet containing point, and/or cell and/or faces zones...
Definition: lookup.H:139
Zone container returned by zoneGenerator::generate.
Definition: zoneSet.H:94
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
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
#define InfoInFunction
Report an information message using Foam::Info.
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
dlLibraryTable libs
Table of loaded dynamic libraries.
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:258
defineTypeNameAndDebug(combustionModel, 0)
IOerror FatalIOError
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
error FatalError
zoneTypes
Enumeration defining the zone types.
Definition: zoneSet.H:66
tmp< DimensionedField< TypeR, GeoMesh, Field > > New(const tmp< DimensionedField< TypeR, GeoMesh, Field >> &tdf1, const word &name, const dimensionSet &dimensions)
static const char nl
Definition: Ostream.H:267
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
const NamedEnum< zoneTypes, 3 > zoneTypesNames
Named enumeration defining the zone type names.
Definition: zoneSet.C:35
dictionary dict