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-2020 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 -noClean
47  Do not remove any existing 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 #include "OFstream.H"
61 
62 using namespace Foam;
63 
64 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
65 
66 int main(int argc, char *argv[])
67 {
69  (
70  "A block mesh generator for a rectilinear mesh in x-y-z.\n"
71  " The ordering of vertex and face labels within a block as shown "
72  "below.\n"
73  " For the local vertex numbering in the sequence 0 to 7:\n"
74  " Faces 0, 1 == x-min, x-max.\n"
75  " Faces 2, 3 == y-min, y-max.\n"
76  " Faces 4, 5 == z-min, z-max.\n"
77  "\n"
78  " 7 ---- 6\n"
79  " f5 |\\ |\\ f3\n"
80  " | | 4 ---- 5 \\\n"
81  " | 3 |--- 2 | \\\n"
82  " | \\| \\| f2\n"
83  " f4 0 ---- 1\n"
84  " Y Z\n"
85  " \\ | f0 ------ f1\n"
86  " \\|\n"
87  " O--- X\n"
88  );
89 
92 
94  (
95  "noClean",
96  "Do not remove any existing polyMesh/ directory or files"
97  );
98  argList::addOption("dict", "file", "Alternative PDRblockMeshDict");
100  (
101  "time",
102  "time",
103  "Specify a time to write mesh to (default: constant)"
104  );
105 
106  #include "setRootCase.H"
107  #include "createTime.H"
108 
109  // Remove old files, unless disabled
110  const bool removeOldFiles = !args.found("noClean");
111 
112  // Instance for resulting mesh
113  bool useTime = false;
114  word meshInstance(runTime.constant());
115 
116  if
117  (
118  args.readIfPresent("time", meshInstance)
119  && runTime.constant() != meshInstance
120  )
121  {
122  // Verify that the value is actually good
123  scalar timeValue;
124 
125  useTime = readScalar(meshInstance, timeValue);
126  if (!useTime)
127  {
129  << "Bad input value: " << meshInstance
130  << "Should be a scalar or 'constant'"
131  << nl << endl
132  << exit(FatalError);
133  }
134  }
135 
136 
137  const word dictName("PDRblockMeshDict");
138 
140 
142 
143  Info<< "Creating PDRblockMesh from "
145 
146  PDRblock blkMesh(meshDict, true);
147 
148 
149  // Instance for resulting mesh
150  if (useTime)
151  {
152  Info<< "Writing polyMesh to " << meshInstance << nl << endl;
153 
154  // Make sure that the time is seen to be the current time.
155  // This is the logic inside regIOobject that resets the instance
156  // to the current time before writing
157  runTime.setTime(instant(meshInstance), 0);
158  }
159 
160  if (removeOldFiles)
161  {
162  const fileName polyMeshPath
163  (
164  runTime.path()/meshInstance/polyMesh::meshSubDir
165  );
166 
167  if (exists(polyMeshPath))
168  {
169  Info<< "Deleting polyMesh directory "
170  << runTime.relativePath(polyMeshPath) << endl;
171  rmDir(polyMeshPath);
172  }
173  }
174 
175 
176  Info<< nl << "Creating polyMesh from PDRblockMesh" << endl;
177 
178  auto meshPtr = blkMesh.mesh
179  (
180  IOobject
181  (
183  meshInstance,
184  runTime,
187  )
188  );
189 
190 
191  const polyMesh& mesh = *meshPtr;
192 
193  // Set the precision of the points data to 10
195 
196  Info<< nl << "Writing polyMesh with "
197  << mesh.cellZones().size() << " cellZones" << endl;
198 
199  mesh.removeFiles();
200  if (!mesh.write())
201  {
203  << "Failed writing polyMesh."
204  << exit(FatalError);
205  }
206 
207  // Mesh summary
208  {
209  Info<< "----------------" << nl
210  << "Mesh Information" << nl
211  << "----------------" << nl
212  << " " << "boundingBox: " << boundBox(mesh.points()) << nl
213  << " " << "nPoints: " << mesh.nPoints() << nl
214  << " " << "nCells: " << mesh.nCells() << nl
215  << " " << "nFaces: " << mesh.nFaces() << nl
216  << " " << "nInternalFaces: " << mesh.nInternalFaces() << nl;
217 
218  Info<< "----------------" << nl
219  << "Patches" << nl
220  << "----------------" << nl;
221 
222  for (const polyPatch& p : mesh.boundaryMesh())
223  {
224  Info<< " " << "patch " << p.index()
225  << " (start: " << p.start()
226  << " size: " << p.size()
227  << ") name: " << p.name()
228  << nl;
229  }
230  }
231 
232  Info<< "\nEnd\n" << endl;
233 
234  return 0;
235 }
236 
237 
238 // ************************************************************************* //
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:54
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::polyMesh::points
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1038
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
meshPtr
Foam::autoPtr< Foam::fvMesh > meshPtr(nullptr)
OSspecific.H
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::IOobject::AUTO_WRITE
Definition: IOobject.H:129
Foam::exists
bool exists(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist (as DIRECTORY or FILE) in the file system?
Definition: MSwindows.C:625
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::fvMesh::write
virtual bool write(const bool valid=true) const
Write mesh using IO settings from time.
Definition: fvMesh.C:895
setSystemRunTimeDictionaryIO.H
Foam::polyMesh::defaultRegion
static word defaultRegion
Return the default region name.
Definition: polyMesh.H:312
Foam::primitiveMesh::nInternalFaces
label nInternalFaces() const
Number of internal faces.
Definition: primitiveMeshI.H:78
Foam::primitiveMesh::nFaces
label nFaces() const
Number of mesh faces.
Definition: primitiveMeshI.H:90
Foam::polyMesh::meshSubDir
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Definition: polyMesh.H:315
Foam::argList::addNote
static void addNote(const string &note)
Add extra notes for the usage information.
Definition: argList.C:413
dictName
const word dictName("blockMeshDict")
Foam::polyMesh::cellZones
const cellZoneMesh & cellZones() const
Return cell zone mesh.
Definition: polyMesh.H:483
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:435
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
polyMesh.H
Foam::argList::readIfPresent
bool readIfPresent(const word &optName, T &val) const
Read a value from the named option if present.
Definition: argListI.H:302
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
OFstream.H
Foam::TimePaths::relativePath
fileName relativePath(const fileName &input, const bool caseTag=false) const
Definition: TimePathsI.H:79
Foam::argList::noFunctionObjects
static void noFunctionObjects(bool addWithOption=false)
Remove '-noFunctionObjects' option and ignore any occurrences.
Definition: argList.C:454
Foam::primitiveMesh::nCells
label nCells() const
Number of mesh cells.
Definition: primitiveMeshI.H:96
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:67
Foam::polyMesh::removeFiles
void removeFiles(const fileName &instanceDir) const
Remove all files from mesh instance.
Definition: polyMesh.C:1264
argList.H
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
PDRblock.H
Foam::FatalError
error FatalError
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
dictIO
IOobject dictIO
Definition: setConstantMeshDictionaryIO.H:1
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::PDRblock
A single block x-y-z rectilinear mesh addressable as i,j,k with simplified creation....
Definition: PDRblock.H:149
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::argList::addBoolOption
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
Definition: argList.C:325
IOdictionary.H
Time.H
setRootCase.H
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:372
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::Time::path
fileName path() const
Return path.
Definition: Time.H:358
Foam::IOstream::defaultPrecision
static unsigned int defaultPrecision()
Return the default precision.
Definition: IOstream.H:333
Foam::rmDir
bool rmDir(const fileName &directory, const bool silent=false)
Remove a directory and its contents (optionally silencing warnings)
Definition: MSwindows.C:1018
Foam::Time::setTime
virtual void setTime(const Time &t)
Reset the time and time-index to those of the given time.
Definition: Time.C:1006
Foam::primitiveMesh::nPoints
label nPoints() const
Number of mesh points.
Definition: primitiveMeshI.H:37
createTime.H
Foam::boundBox
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:63
Foam::instant
An instant of time. Contains the time value and name.
Definition: instant.H:52
Foam::argList::noParallel
static void noParallel()
Remove the parallel options.
Definition: argList.C:491
Foam::IOobject::objectPath
fileName objectPath() const
The complete path + object name.
Definition: IOobjectI.H:209
Foam::TimePaths::constant
const word & constant() const
Return constant name.
Definition: TimePathsI.H:88
Foam::IOobject::NO_READ
Definition: IOobject.H:123
Foam::argList::addOption
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:336
args
Foam::argList args(argc, argv)
meshDict
const IOdictionary & meshDict
Definition: findBlockMeshDict.H:72
Foam::argList::found
bool found(const word &optName) const
Return true if the named option is found.
Definition: argListI.H:157