lookup.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 "lookup.H"
27 #include "polyMesh.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34  namespace zoneGenerators
35  {
38  }
39 }
40 
41 
42 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
43 
44 template<class ZoneListType>
45 const typename ZoneListType::zoneType& Foam::zoneGenerators::lookup::lookupZone
46 (
47  const ZoneListType& zones,
48  const word& zoneName
49 ) const
50 {
51  typedef typename ZoneListType::zoneType ZoneType;
52 
53  const ZoneType* zonePtr = zones.lookupPtr(zoneName_);
54 
55  if (zonePtr == nullptr)
56  {
58  << "Cannot find " << ZoneType::typeName << " " << zoneName_ << nl;
59 
60  if (mesh_.pointZones().lookupPtr(zoneName_) != nullptr)
61  {
62  FatalIOError << " Found pointZone " << zoneName << nl;
63  }
64 
65  if (mesh_.cellZones().lookupPtr(zoneName_) != nullptr)
66  {
67  FatalIOError << " Found cellZone " << zoneName << nl;
68  }
69 
70  if (mesh_.faceZones().lookupPtr(zoneName_) != nullptr)
71  {
72  FatalIOError << " Found faceZone " << zoneName << nl;
73  }
74 
76  << " Available " << ZoneType::typeName << "s: "
77  << zones.sortedToc()
78  << exit(FatalIOError);
79  }
80 
81  return *zonePtr;
82 }
83 
84 
85 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
86 
88 (
89  const word& name,
90  const polyMesh& mesh,
91  const dictionary& dict
92 )
93 :
95  zoneType_
96  (
97  zoneTypesAllNames.lookupOrDefault("zoneType", dict, zoneTypesAll::all)
98  )
99 {}
100 
101 
102 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
103 
105 {}
106 
107 
108 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
109 
111 {
112  switch (zoneType_)
113  {
114  case zoneTypesAll::point:
115  {
116  const pointZone& pZone = lookupZone(mesh_.pointZones(), zoneName_);
117  moveUpdate_ = moveUpdate_ || pZone.moveUpdate();
118  return zoneSet(pZone);
119  }
120 
121  case zoneTypesAll::cell:
122  {
123  const cellZone& cZone = lookupZone(mesh_.cellZones(), zoneName_);
124  moveUpdate_ = moveUpdate_ || cZone.moveUpdate();
125  return zoneSet(cZone);
126  }
127 
128  case zoneTypesAll::face:
129  {
130  const faceZone& fZone = lookupZone(mesh_.faceZones(), zoneName_);
131  moveUpdate_ = moveUpdate_ || fZone.moveUpdate();
132  return zoneSet(fZone);
133  }
134 
135  case zoneTypesAll::all:
136  {
137  if (zoneName_ == "all")
138  {
140  << "zoneType not specified or set to all for zone all"
141  << exit(FatalIOError);
142  }
143 
144  zoneSet zs;
145  bool found = false;
146 
147  if (mesh_.pointZones().found(zoneName_))
148  {
149  zs = mesh_.pointZones()[zoneName_];
150  found = true;
151  moveUpdate_ = moveUpdate_ || zs.pZone().moveUpdate();
152  }
153 
154  if (mesh_.cellZones().found(zoneName_))
155  {
156  zs = mesh_.cellZones()[zoneName_];
157  found = true;
158  moveUpdate_ = moveUpdate_ || zs.cZone().moveUpdate();
159  }
160 
161  if (mesh_.faceZones().found(zoneName_))
162  {
163  zs = mesh_.faceZones()[zoneName_];
164  found = true;
165  moveUpdate_ = moveUpdate_ || zs.fZone().moveUpdate();
166  }
167 
168  if (!found)
169  {
171  << "Cannot find zone " << zoneName_ << exit(FatalIOError);
172  }
173 
174  return zs;
175  }
176  }
177 
178  return zoneSet();
179 }
180 
181 
182 // ************************************************************************* //
bool found
Macros for easy insertion into run-time selection tables.
const ZoneType * lookupPtr(const word &name) const
Return const reference to ZoneType by name.
Definition: ZoneList.C:142
bool moveUpdate() const
Flag indicating the zone is updated by the generator.
Definition: Zone.H:187
Named list of cell indices representing a sub-set of the mesh.
Definition: cellZone.H:61
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Named list of face indices representing a sub-set of the mesh faces.
Definition: faceZone.H:66
Named list of point indices representing a sub-set of the mesh faces.
Definition: pointZone.H:60
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
const pointZoneList & pointZones() const
Return point zones.
Definition: polyMesh.H:437
const cellZoneList & cellZones() const
Return cell zones.
Definition: polyMesh.H:449
const faceZoneList & faceZones() const
Return face zones.
Definition: polyMesh.H:443
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
const word zoneName_
Name of the zone (defaults to the name of the generator)
Definition: zoneGenerator.H:69
const word & zoneName() const
const dictionary dict_
Dictionary cached for error context.
Definition: zoneGenerator.H:66
const polyMesh & mesh_
Reference to the polyMesh.
Definition: zoneGenerator.H:72
A zoneGenerator which looks-up and returns a zoneSet containing point, and/or cell and/or faces zones...
Definition: lookup.H:139
virtual zoneSet generate() const
Generate and return the zoneSet.
Definition: lookup.C:110
virtual ~lookup()
Destructor.
Definition: lookup.C:104
lookup(const word &name, const polyMesh &mesh, const dictionary &dict)
Construct from dictionary.
Definition: lookup.C:88
Zone container returned by zoneGenerator::generate.
Definition: zoneSet.H:94
const faceZone & fZone() const
Return a reference to the faceZone if allocated.
Definition: zoneSetI.H:230
const cellZone & cZone() const
Return a reference to the cellZone if allocated.
Definition: zoneSetI.H:223
const pointZone & pZone() const
Return a reference to the pointZone if allocated.
Definition: zoneSetI.H:216
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
defineTypeNameAndDebug(cylinderHeadPoints, 0)
addToRunTimeSelectionTable(zoneGenerator, cylinderHeadPoints, dictionary)
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
zoneTypesAll
Enumeration defining the zone types with an option for all the types.
Definition: zoneSet.H:77
IOerror FatalIOError
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
static const char nl
Definition: Ostream.H:267
const NamedEnum< zoneTypesAll, 4 > zoneTypesAllNames
Named enumeration defining the zone type names.
Definition: zoneSet.C:43
dictionary dict