PDRblockMesh.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2019-2022 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26Application
27 PDRblockMesh
28
29Group
30 grpMeshGenerationUtilities
31
32Description
33 A specialized single-block mesh generator for a rectilinear mesh
34 in x-y-z.
35
36 Uses the mesh description found in
37 - \c system/PDRblockMeshDict
38
39Usage
40 \b PDRblockMesh [OPTION]
41
42 Options:
43 - \par -dict <filename>
44 Alternative dictionary for the mesh description.
45
46 - \par -no-clean
47 Do not remove polyMesh/ directory or files
48
49 - \par -time
50 Write resulting mesh to a time directory (instead of constant)
51
52\*---------------------------------------------------------------------------*/
53
54#include "argList.H"
55#include "polyMesh.H"
56#include "PDRblock.H"
57#include "Time.H"
58#include "IOdictionary.H"
59#include "OSspecific.H"
60
61using namespace Foam;
62
63// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
64
65int main(int argc, char *argv[])
66{
67 argList::addNote
68 (
69 "A block mesh generator for a rectilinear mesh in x-y-z.\n"
70 " The ordering of vertex and face labels within a block as shown "
71 "below.\n"
72 " For the local vertex numbering in the sequence 0 to 7:\n"
73 " Faces 0, 1 == x-min, x-max.\n"
74 " Faces 2, 3 == y-min, y-max.\n"
75 " Faces 4, 5 == z-min, z-max.\n"
76 "\n"
77 " 7 ---- 6\n"
78 " f5 |\\ |\\ f3\n"
79 " | | 4 ---- 5 \\\n"
80 " | 3 |--- 2 | \\\n"
81 " | \\| \\| f2\n"
82 " f4 0 ---- 1\n"
83 " Y Z\n"
84 " \\ | f0 ------ f1\n"
85 " \\|\n"
86 " O--- X\n"
87 );
88
89 argList::noParallel();
90 argList::noFunctionObjects();
91
92 argList::addBoolOption
93 (
94 "no-clean",
95 "Do not remove polyMesh/ directory or files"
96 );
97 argList::addOptionCompat("no-clean", {"noClean", -2006});
98
99 argList::addBoolOption
100 (
101 "no-outer",
102 "Create without any other region"
103 );
104 argList::addBoolOption
105 (
106 "print-dict",
107 "Print blockMeshDict equivalent and exit"
108 );
109 argList::addBoolOption
110 (
111 "write-dict",
112 "Write system/blockMeshDict.PDRblockMesh and exit"
113 );
114
115 argList::addOption("dict", "file", "Alternative PDRblockMeshDict");
116 argList::addOption
117 (
118 "time",
119 "time",
120 "Specify a time to write mesh to (default: constant)"
121 );
122
123 #include "setRootCase.H"
124 #include "createTime.H"
125
126 // Remove old files, unless disabled
127 const bool removeOldFiles = !args.found("no-clean");
128
129 // Suppress creation of the outer region
130 const bool noOuterRegion = args.found("no-outer");
131
132 const word regionName(polyMesh::defaultRegion);
133
134
135 // Instance for resulting mesh
136 bool useTime = false;
137 word meshInstance(runTime.constant());
138
139 if
140 (
141 args.readIfPresent("time", meshInstance)
142 && runTime.constant() != meshInstance
143 )
144 {
145 // Verify that the value is actually good
146 scalar timeValue;
147
148 useTime = readScalar(meshInstance, timeValue);
149 if (!useTime)
150 {
152 << "Bad input value: " << meshInstance
153 << "Should be a scalar or 'constant'"
154 << nl << endl
155 << exit(FatalError);
156 }
157 }
158
159
160 // Locate appropriate PDRblockMeshDict
161 const word dictName("PDRblockMeshDict");
163
165
166 Info<< "Creating PDRblockMesh from "
167 << dictIO.objectRelPath() << endl;
168
169 // Always start from a PDRblock
170 PDRblock blkMesh(meshDict, true);
171
172 if (args.found("print-dict"))
173 {
174 Info<< nl << "Equivalent blockMeshDict" << nl << nl;
175
176 blkMesh.blockMeshDict(Info, true);
177
178 Info<< "\nEnd\n" << endl;
179 return 0;
180 }
181
182 if (args.found("write-dict"))
183 {
184 // Generate system/blockMeshDict and exit
185 blkMesh.writeBlockMeshDict
186 (
188 (
189 "blockMeshDict.PDRblockMesh",
190 runTime.system(), // instance
191 runTime, // registry
192 IOobject::NO_READ,
193 IOobject::NO_WRITE,
194 false // Do not register
195 )
196 );
197
198 Info<< "\nEnd\n" << endl;
199 return 0;
200 }
201
202 // Instance for resulting mesh
203 if (useTime)
204 {
205 Info<< "Writing polyMesh to " << meshInstance << nl << endl;
206
207 // Make sure that the time is seen to be the current time.
208 // This is the logic inside regIOobject that resets the instance
209 // to the current time before writing
210 runTime.setTime(instant(meshInstance), 0);
211 }
212
213 if (removeOldFiles)
214 {
215 #include "cleanMeshDirectory.H"
216 }
217
218
219 Info<< nl << "Creating polyMesh from PDRblockMesh" << endl;
220 if (noOuterRegion)
221 {
222 Info<< "Outer region disabled, using ijk generation" << nl;
223 }
224
226 (
227 args.found("no-outer")
228 ? blkMesh.innerMesh(IOobject(regionName, meshInstance, runTime))
229 : blkMesh.mesh(IOobject(regionName, meshInstance, runTime))
230 );
231
233
234 // Set the precision of the points data to 10
235 IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision()));
236
237 Info<< nl << "Writing polyMesh with "
238 << mesh.cellZones().size() << " cellZones" << endl;
239
240 mesh.removeFiles();
241 if (!mesh.write())
242 {
244 << "Failed writing polyMesh."
245 << exit(FatalError);
246 }
247
248 #include "printMeshSummary.H"
249
250 Info<< "\nEnd\n" << endl;
251
252 return 0;
253}
254
255
256// ************************************************************************* //
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Y[inertIndex] max(0.0)
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:57
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
A single block x-y-z rectilinear mesh addressable as i,j,k with simplified creation....
Definition: PDRblock.H:156
bool found(const word &optName) const
Return true if the named option is found.
Definition: argListI.H:178
bool readIfPresent(const word &optName, T &val) const
Read a value from the named option if present.
Definition: argListI.H:323
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
An instant of time. Contains the time value and name. Uses Foam::Time when formatting the name.
Definition: instant.H:56
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
A class for handling words, derived from Foam::string.
Definition: word.H:68
dynamicFvMesh & mesh
engineTime & runTime
Foam::autoPtr< Foam::dynamicFvMesh > meshPtr
Foam::word regionName(Foam::polyMesh::defaultRegion)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
const IOdictionary & meshDict
const word dictName("faMeshDefinition")
Namespace for OpenFOAM.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
IOobject dictIO
Foam::argList args(argc, argv)