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 -------------------------------------------------------------------------------
10 License
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 
26 Application
27  PDRblockMesh
28 
29 Group
30  grpMeshGenerationUtilities
31 
32 Description
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 
39 Usage
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 
61 using namespace Foam;
62 
63 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
64 
65 int 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  (
187  IOobject
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 
232  polyMesh& mesh = *meshPtr;
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 // ************************************************************************* //
const IOdictionary & meshDict
static void noFunctionObjects(bool addWithOption=false)
Remove &#39;-noFunctionObjects&#39; option and ignore any occurrences.
Definition: argList.C:547
static void addNote(const string &note)
Add extra notes for the usage information.
Definition: argList.C:462
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:608
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
const word dictName("faMeshDefinition")
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
Definition: argList.C:374
static void noParallel()
Remove the parallel options.
Definition: argList.C:584
static void addOptionCompat(const word &optName, std::pair< const char *, int > compat)
Specify an alias for the option name.
Definition: argList.C:418
Ignore writing from objectRegistry::writeObject()
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:50
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
dynamicFvMesh & mesh
void removeFiles(const fileName &instanceDir) const
Remove all files from mesh instance.
Definition: polyMesh.C:1329
Foam::autoPtr< Foam::dynamicFvMesh > meshPtr
A class for handling words, derived from Foam::string.
Definition: word.H:63
static word defaultRegion
Return the default region name.
Definition: polyMesh.H:406
label size() const noexcept
The number of entries in the list.
Definition: UPtrListI.H:106
const word & system() const noexcept
Return system name.
Definition: TimePathsI.H:118
A single block x-y-z rectilinear mesh addressable as i,j,k with simplified creation. Some of the input is similar to blockMeshDict, but since this specialization is for a single-block that is aligned with the x-y-z directions, it provides a different means of specifying the mesh.
Definition: PDRblock.H:149
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:385
virtual void setTime(const Time &t)
Reset the time and time-index to those of the given time.
Definition: Time.C:902
static unsigned int minPrecision(unsigned int prec) noexcept
Set the minimum default precision.
Definition: IOstream.H:440
virtual bool write(const bool writeOnProc=true) const
Write mesh using IO settings from time.
Definition: fvMesh.C:1113
const word & constant() const noexcept
Return constant name.
Definition: TimePathsI.H:112
An instant of time. Contains the time value and name. Uses Foam::Time when formatting the name...
Definition: instant.H:53
Foam::word regionName(args.getOrDefault< word >("region", Foam::polyMesh::defaultRegion))
Nothing to be read.
const cellZoneMesh & cellZones() const noexcept
Return cell zone mesh.
Definition: polyMesh.H:679
fileName objectRelPath() const
The object path relative to the root.
Definition: IOobject.C:524
messageStream Info
Information stream (stdout output on master, null elsewhere)
IOobject dictIO
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:75
bool readIfPresent(const word &optName, T &val) const
Read a value from the named option if present.
Definition: argListI.H:316
Foam::argList args(argc, argv)
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:180
Do not request registration (bool: false)
bool found(const word &optName) const
Return true if the named option is found.
Definition: argListI.H:171
Namespace for OpenFOAM.