createZones.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 Application
25  createZones
26 
27 Description
28  Executes the zoneGenerators specified and writes the zones generated
29 
30 Usage
31  \b createZones [OPTION]
32 
33  Options:
34  - \par -region <name>
35  Specify an alternative mesh region.
36 
37  - \par -mesh <name>
38  Specify an alternative mesh.
39 
40  - \par -fvMesh
41  Construct an fvMesh rather than a polyMesh
42  to allow the generation and writing of zones associated with
43  fvMesh movers
44 
45  - \par -dict <filename>
46  Specify alternative dictionary for the zoneGenerators,
47  defaults to system/createZonesDict
48 
49  - \par -zonesGenerator
50  Generate the zones from the constant/zonesGenerator file
51  during fvMesh construction instead of from createZonesDict
52 
53  - \par -clear
54  Clear all registered zones before generating new zones from
55  the createZonesDict file.
56  Not applicable to the zonesGenerator option.
57 
58 \*---------------------------------------------------------------------------*/
59 
60 #include "argList.H"
61 #include "Time.H"
62 #include "fvMesh.H"
63 #include "zoneGeneratorList.H"
64 #include "zonesGenerator.H"
65 #include "systemDict.H"
66 
67 using namespace Foam;
68 
69 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
70 
71 int main(int argc, char *argv[])
72 {
73  #include "addDictOption.H"
74  #include "addMeshOption.H"
75  #include "addRegionOption.H"
77  (
78  "clear",
79  "clear all existing zones"
80  );
82  (
83  "zonesGenerator",
84  "execute the zonesGenerator on construction"
85  );
87  (
88  "fvMesh",
89  "construct an fvMesh rather than a polyMesh"
90  );
91 
92  #include "setRootCase.H"
93  #include "createTime.H"
94 
95  #include "setMeshPath.H"
96  #include "setRegionName.H"
97 
98  const bool zonesGenerator = args.optionFound("zonesGenerator");
99  const bool constructFvMesh = args.optionFound("fvMesh") || zonesGenerator;
100 
102 
103  if (constructFvMesh)
104  {
105  fvMesh *fvMeshPtr = new fvMesh
106  (
107  IOobject
108  (
109  regionName,
110  runTime.name(),
111  meshPath,
112  runTime,
114  ),
115  false
116  );
117 
118  fvMeshPtr->postConstruct
119  (
120  true,
123  );
124 
125  meshPtr = fvMeshPtr;
126  }
127  else
128  {
129  meshPtr = new polyMesh
130  (
131  IOobject
132  (
133  regionName,
134  runTime.name(),
135  meshPath,
136  runTime,
138  )
139  );
140  }
141 
142  polyMesh& mesh = meshPtr();
143 
144  if (!zonesGenerator)
145  {
146  if (args.optionFound("clear"))
147  {
148  mesh.pointZones().clear();
149  mesh.cellZones().clear();
150  mesh.faceZones().clear();
151  }
152 
153  const dictionary zoneGeneratorsDict
154  (
155  systemDict("createZonesDict", args, mesh)
156  );
157 
158  zoneGeneratorList zoneGenerators(mesh, zoneGeneratorsDict, true);
159 
160  // Generate and register the zones
161  zoneGenerators.generate();
162  }
163 
164  // Write the zone lists that are not empty
165  mesh.pointZones().write();
166  mesh.cellZones().write();
167  mesh.faceZones().write();
168 
169  Info<< "End\n" << endl;
170 
171  return 0;
172 }
173 
174 
175 // ************************************************************************* //
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
void clear()
Clear the zones.
Definition: ZoneList.C:282
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
Definition: argList.C:118
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:114
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 data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:96
void postConstruct(const bool changers, const bool zones, const stitchType stitch)
Complete construction of the mesh.
Definition: fvMesh.C:634
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
virtual bool write(const bool write=true) const
Write using setting from DB.
List of zoneGenerators.
MeshObject zoneGeneratorList instantiated by polyMesh.
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
int main(int argc, char *argv[])
Definition: financialFoam.C:44
static fvMesh * meshPtr
Definition: globalFoam.H:52
Namespace for OpenFOAM.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:258
const word & regionName(const solver &region)
Definition: solver.H:218
messageStream Info
IOdictionary systemDict(const word &dictName, const argList &args, const objectRegistry &ob, const word &regionName=polyMesh::defaultRegion, const fileName &path=fileName::null)
Definition: systemDict.C:93
word meshPath
Definition: setMeshPath.H:1
Foam::argList args(argc, argv)