Loading...
Searching...
No Matches
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-2024 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{
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
91
93 (
94 "no-clean",
95 "Do not remove polyMesh/ directory or files"
96 );
97 argList::addOptionCompat("no-clean", {"noClean", -2006});
98
100 (
101 "no-outer",
102 "Create without any other region"
103 );
105 (
106 "print-dict",
107 "Print blockMeshDict equivalent and exit"
108 );
110 (
111 "write-dict",
112 "Write system/blockMeshDict.PDRblockMesh and exit"
113 );
114
115 argList::addOption("dict", "file", "Alternative PDRblockMeshDict");
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
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
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 // More precision (for points data)
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...
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
@ NO_REGISTER
Do not request registration (bool: false).
@ NO_READ
Nothing to be read.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
static unsigned int minPrecision(unsigned int prec) noexcept
Set the minimum default precision.
Definition IOstream.H:459
A single block x-y-z rectilinear mesh addressable as i,j,k with simplified creation....
Definition PDRblock.H:152
static void noFunctionObjects(bool addWithOption=false)
Remove '-noFunctionObjects' option and ignore any occurrences.
Definition argList.C:562
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
Definition argList.C:389
static void noParallel()
Remove the parallel options.
Definition argList.C:599
static void addOption(const word &optName, const string &param="", const string &usage="", bool advanced=false)
Add an option to validOptions with usage information.
Definition argList.C:400
static void addNote(const string &note)
Add extra notes for the usage information.
Definition argList.C:477
static void addOptionCompat(const word &optName, std::pair< const char *, int > compat)
Specify an alias for the option name.
Definition argList.C:433
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
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:79
static word defaultRegion
Return the default region name.
Definition polyMesh.H:406
A class for handling words, derived from Foam::string.
Definition word.H:66
dynamicFvMesh & mesh
engineTime & runTime
Foam::autoPtr< Foam::dynamicFvMesh > meshPtr
Foam::word regionName(args.getOrDefault< word >("region", Foam::polyMesh::defaultRegion))
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
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:519
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
IOobject dictIO
Foam::argList args(argc, argv)