coded_zoneGenerator.H
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) 2026 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 Class
25  Foam::zoneGenerators::coded
26 
27 Description
28  Coded zoneGenerator
29 
30  The code provided should set \c pointIndices and/or \c cellIndices
31  and/or \c faceIndices and optionally \c faceMap. These index lists
32  are automatically converted into the corresponding zones in the \c zoneSet
33  which is returned by the \c zoneGenerator.
34 
35  The entries are:
36  \plaintable
37  code | Code to set pointIndices, cellIndices, faceIndices
38  codeInclude | Include files
39  codeOptions | Include paths; inserted into EXE_INC in Make/options
40  codeLibs | Link line; inserted into LIB_LIBS in Make/options
41  \endplaintable
42 
43  Example of a zoneGenerators::coded which creates a \c cellZone of the cells
44  in which the value of the turbulent kinetic energy is within the highest
45  10%:
46  \verbatim
47  cellZone
48  {
49  type coded;
50 
51  // Regenerate cellZone for every evaluation
52  regenerate yes;
53 
54  code
55  #{
56  // Lookup field from the objectRegistry, e.g. k
57  const volScalarField& k = mesh().lookupObject<volScalarField>("k");
58 
59  // Calculate the minimum and maximum k values
60  const scalar mink = min(k).value();
61  const scalar maxk = max(k).value();
62 
63  // Fraction of the range of k
64  const scalar f = 0.1;
65 
66  // Lowest k in selection
67  const scalar lowk = f*mink + (1.0 - f)*maxk;
68 
69  cellIndices = selectIndices
70  (
71  k,
72  [&](const scalar k)
73  {
74  return k > lowk;
75  }
76  );
77  #};
78  }
79  \endverbatim
80 
81 See also
82  Foam::zoneGenerator
83  Foam::codedBase
84 
85 SourceFiles
86  coded_zoneGenerator.C
87 
88 \*---------------------------------------------------------------------------*/
89 
90 #ifndef coded_zoneGenerator_H
91 #define coded_zoneGenerator_H
92 
93 #include "zoneGenerator.H"
94 #include "codedBase.H"
95 
96 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
97 
98 namespace Foam
99 {
100 namespace zoneGenerators
101 {
102 
103 /*---------------------------------------------------------------------------*\
104  Class coded Declaration
105 \*---------------------------------------------------------------------------*/
106 
107 class coded
108 :
109  public zoneGenerator,
110  public codedBase
111 {
112  // Private Data
113 
114  //- Keywords associated with source code
115  static const wordList codeKeys;
116 
117  //- Name of the dictionary variables in the source code
118  static const wordList codeDictVars;
119 
120  // Name of the code options template file
121  static const word codeOptions;
122 
123  // Names of the source files to compile
124  static const wordList compileFiles;
125 
126  // Names of the source files to copy (header files)
127  static const wordList copyFiles;
128 
129  //- The dynamically generated zoneGenerator pointer
130  mutable autoPtr<zoneGenerator> redirectZoneGeneratorPtr_;
131 
132 
133 public:
134 
135  //- Runtime type information
136  TypeName("coded");
137 
138 
139  // Constructors
140 
141  //- Construct from name, polyMesh and dictionary
142  coded
143  (
144  const word& name,
145  const polyMesh& mesh,
146  const dictionary& dict
147  );
148 
149  //- Disallow default bitwise copy construction
150  coded(const coded&) = delete;
151 
152 
153  //- Destructor
154  virtual ~coded();
155 
156 
157  // Member Functions
158 
159  //- Generate and return the zoneSet
160  virtual zoneSet generate() const;
161 
162 
163  // Member Operators
164 
165  //- Disallow default bitwise assignment
166  void operator=(const coded&) = delete;
167 };
168 
169 
170 //- Helper struct to enable the zone type for the corresponding list of indices
171 // which allows for the generation of empty zones
172 struct enabledLabelList
173 :
174  public labelList
175 {
176  bool enabled_;
177 
179  :
180  enabled_(false)
181  {}
182 
183  void operator=(const labelList& indices)
184  {
185  labelList::operator=(indices);
186  enabled_ = true;
187  }
188 
189  bool enabled() const
190  {
191  return enabled_ || size();
192  }
193 };
194 
195 
196 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
197 
198 } // End namespace zoneGenerators
199 } // End namespace Foam
200 
201 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
202 
203 #endif
204 
205 // ************************************************************************* //
label size() const
Return the number of elements in the UList.
Definition: ListI.H:171
void operator=(const UList< label > &)
Assignment to UList operator. Takes linear time.
Definition: List.C:376
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:78
A class for handling words, derived from string.
Definition: word.H:63
const word & name() const
Return the zoneGenerator name.
const polyMesh & mesh() const
Return reference to the polyMesh.
virtual zoneSet generate() const
Generate and return the zoneSet.
TypeName("coded")
Runtime type information.
void operator=(const coded &)=delete
Disallow default bitwise assignment.
coded(const word &name, const polyMesh &mesh, const dictionary &dict)
Construct from name, polyMesh and dictionary.
Zone container returned by zoneGenerator::generate.
Definition: zoneSet.H:94
Namespace for OpenFOAM.
List< word > wordList
A List of words.
Definition: fileName.H:54
dictionary dict
Helper struct to enable the zone type for the corresponding list of indices.
void operator=(const labelList &indices)