blockMeshApp.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 | Copyright (C) 2011-2015 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  blockMesh
26 
27 Description
28  A multi-block mesh generator.
29 
30  Uses the block mesh description found in
31  \a system/blockMeshDict
32  or \a system/<region>/blockMeshDict
33  or \a constant/polyMesh/blockMeshDict
34  or \a constant/<region>/polyMesh/blockMeshDict
35 
36 Usage
37 
38  - blockMesh [OPTION]
39 
40  \param -blockTopology \n
41  Write the topology as a set of edges in OBJ format.
42 
43  \param -region <name> \n
44  Specify an alternative mesh region.
45 
46  \param -dict <filename> \n
47  Specify alternative dictionary for the block mesh description.
48 
49 \*---------------------------------------------------------------------------*/
50 
51 #include "Time.H"
52 #include "IOdictionary.H"
53 #include "IOPtrList.H"
54 
55 #include "blockMesh.H"
56 #include "attachPolyTopoChanger.H"
57 #include "emptyPolyPatch.H"
58 #include "cellSet.H"
59 
60 #include "argList.H"
61 #include "OSspecific.H"
62 #include "OFstream.H"
63 
64 #include "Pair.H"
65 #include "slidingInterface.H"
66 
67 using namespace Foam;
68 
69 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
70 
71 int main(int argc, char *argv[])
72 {
75  (
76  "blockTopology",
77  "write block edges and centres as .obj files"
78  );
80  (
81  "dict",
82  "file",
83  "specify alternative dictionary for the blockMesh description"
84  );
85 
86  #include "addRegionOption.H"
87  #include "setRootCase.H"
88  #include "createTime.H"
89 
90  const word dictName("blockMeshDict");
91 
93  word regionPath;
94 
95  // Check if the region is specified otherwise mesh the default region
97  {
98  Info<< nl << "Generating mesh for region " << regionName << endl;
99  regionPath = regionName;
100  }
101 
102  // Search for the appropriate blockMesh dictionary....
103 
105 
106  // Check if the dictionary is specified on the command-line
107  if (args.optionFound("dict"))
108  {
109  dictPath = args["dict"];
110 
111  dictPath =
112  (
113  isDir(dictPath)
115  : dictPath
116  );
117  }
118  // Check if dictionary is present in the constant directory
119  else if
120  (
121  exists
122  (
123  runTime.path()/runTime.constant()
124  /regionPath/polyMesh::meshSubDir/dictName
125  )
126  )
127  {
128  dictPath =
129  runTime.constant()
130  /regionPath/polyMesh::meshSubDir/dictName;
131  }
132  // Otherwise assume the dictionary is present in the system directory
133  else
134  {
135  dictPath = runTime.system()/regionPath/dictName;
136  }
137 
138  IOobject meshDictIO
139  (
140  dictPath,
141  runTime,
144  false
145  );
146 
147  if (!meshDictIO.headerOk())
148  {
150  << meshDictIO.objectPath()
151  << nl
152  << exit(FatalError);
153  }
154 
155  Info<< "Creating block mesh from\n "
156  << meshDictIO.objectPath() << endl;
157 
158  blockMesh::verbose(true);
159 
160  IOdictionary meshDict(meshDictIO);
161  blockMesh blocks(meshDict, regionName);
162 
163 
164  if (args.optionFound("blockTopology"))
165  {
166  // Write mesh as edges.
167  {
168  fileName objMeshFile("blockTopology.obj");
169 
170  OFstream str(runTime.path()/objMeshFile);
171 
172  Info<< nl << "Dumping block structure as Lightwave obj format"
173  << " to " << objMeshFile << endl;
174 
175  blocks.writeTopology(str);
176  }
177 
178  // Write centres of blocks
179  {
180  fileName objCcFile("blockCentres.obj");
181 
182  OFstream str(runTime.path()/objCcFile);
183 
184  Info<< nl << "Dumping block centres as Lightwave obj format"
185  << " to " << objCcFile << endl;
186 
187  const polyMesh& topo = blocks.topology();
188 
189  const pointField& cellCentres = topo.cellCentres();
190 
191  forAll(cellCentres, cellI)
192  {
193  //point cc = b.blockShape().centre(b.points());
194  const point& cc = cellCentres[cellI];
195 
196  str << "v " << cc.x() << ' ' << cc.y() << ' ' << cc.z() << nl;
197  }
198  }
199 
200  Info<< nl << "end" << endl;
201 
202  return 0;
203  }
204 
205 
206  Info<< nl << "Creating polyMesh from blockMesh" << endl;
207 
208  word defaultFacesName = "defaultFaces";
209  word defaultFacesType = emptyPolyPatch::typeName;
210  polyMesh mesh
211  (
212  IOobject
213  (
214  regionName,
215  runTime.constant(),
216  runTime
217  ),
218  xferCopy(blocks.points()), // could we re-use space?
219  blocks.cells(),
220  blocks.patches(),
221  blocks.patchNames(),
222  blocks.patchDicts(),
225  );
226 
227 
228  // Read in a list of dictionaries for the merge patch pairs
229  if (meshDict.found("mergePatchPairs"))
230  {
231  List<Pair<word> > mergePatchPairs
232  (
233  meshDict.lookup("mergePatchPairs")
234  );
235 
236  #include "mergePatchPairs.H"
237  }
238  else
239  {
240  Info<< nl << "There are no merge patch pairs edges" << endl;
241  }
242 
243 
244  // Set any cellZones (note: cell labelling unaffected by above
245  // mergePatchPairs)
246 
247  label nZones = blocks.numZonedBlocks();
248 
249  if (nZones > 0)
250  {
251  Info<< nl << "Adding cell zones" << endl;
252 
253  // Map from zoneName to cellZone index
254  HashTable<label> zoneMap(nZones);
255 
256  // Cells per zone.
257  List<DynamicList<label> > zoneCells(nZones);
258 
259  // Running cell counter
260  label cellI = 0;
261 
262  // Largest zone so far
263  label freeZoneI = 0;
264 
265  forAll(blocks, blockI)
266  {
267  const block& b = blocks[blockI];
268  const labelListList& blockCells = b.cells();
269  const word& zoneName = b.blockDef().zoneName();
270 
271  if (zoneName.size())
272  {
273  HashTable<label>::const_iterator iter = zoneMap.find(zoneName);
274 
275  label zoneI;
276 
277  if (iter == zoneMap.end())
278  {
279  zoneI = freeZoneI++;
280 
281  Info<< " " << zoneI << '\t' << zoneName << endl;
282 
283  zoneMap.insert(zoneName, zoneI);
284  }
285  else
286  {
287  zoneI = iter();
288  }
289 
290  forAll(blockCells, i)
291  {
292  zoneCells[zoneI].append(cellI++);
293  }
294  }
295  else
296  {
297  cellI += b.cells().size();
298  }
299  }
300 
301 
302  List<cellZone*> cz(zoneMap.size());
303 
304  Info<< nl << "Writing cell zones as cellSets" << endl;
305 
306  forAllConstIter(HashTable<label>, zoneMap, iter)
307  {
308  label zoneI = iter();
309 
310  cz[zoneI] = new cellZone
311  (
312  iter.key(),
313  zoneCells[zoneI].shrink(),
314  zoneI,
315  mesh.cellZones()
316  );
317 
318  // Write as cellSet for ease of processing
319  cellSet cset(mesh, iter.key(), zoneCells[zoneI].shrink());
320  cset.write();
321  }
322 
323  mesh.pointZones().setSize(0);
324  mesh.faceZones().setSize(0);
325  mesh.cellZones().setSize(0);
327  }
328 
329  // Set the precision of the points data to 10
331 
332  Info<< nl << "Writing polyMesh" << endl;
333  mesh.removeFiles();
334  if (!mesh.write())
335  {
337  << "Failed writing polyMesh."
338  << exit(FatalError);
339  }
340 
341 
342  //
343  // write some information
344  //
345  {
347 
348  Info<< "----------------" << nl
349  << "Mesh Information" << nl
350  << "----------------" << nl
351  << " " << "boundingBox: " << boundBox(mesh.points()) << nl
352  << " " << "nPoints: " << mesh.nPoints() << nl
353  << " " << "nCells: " << mesh.nCells() << nl
354  << " " << "nFaces: " << mesh.nFaces() << nl
355  << " " << "nInternalFaces: " << mesh.nInternalFaces() << nl;
356 
357  Info<< "----------------" << nl
358  << "Patches" << nl
359  << "----------------" << nl;
360 
361  forAll(patches, patchI)
362  {
363  const polyPatch& p = patches[patchI];
364 
365  Info<< " " << "patch " << patchI
366  << " (start: " << p.start()
367  << " size: " << p.size()
368  << ") name: " << p.name()
369  << nl;
370  }
371  }
372 
373  Info<< "\nEnd\n" << endl;
374 
375  return 0;
376 }
377 
378 
379 // ************************************************************************* //
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
Foam::polyMesh::points
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:979
Foam::blockMesh::patchDicts
PtrList< dictionary > patchDicts() const
Get patch information from the topology mesh.
Definition: blockMesh.C:95
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::block
Creates a single block of cells from point coordinates, numbers of cells in each direction and an exp...
Definition: block.H:63
OSspecific.H
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Foam::blockMesh::patches
const faceListList & patches() const
Return the patch face lists.
Definition: blockMesh.C:140
p
p
Definition: pEqn.H:62
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::exists
bool exists(const fileName &, const bool checkGzip=true)
Does the name exist (as DIRECTORY or FILE) in the file system?
Definition: POSIX.C:608
Foam::argList::addOption
static void addOption(const word &opt, const string &param="", const string &usage="")
Add to an option to validOptions with usage information.
Definition: argList.C:108
Foam::polyMesh::defaultRegion
static word defaultRegion
Return the default region name.
Definition: polyMesh.H:306
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
mergePatchPairs.H
Foam::polyMesh::meshSubDir
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Definition: polyMesh.H:309
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
Foam::argList::addBoolOption
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
Definition: argList.C:98
Foam::HashTable::insert
bool insert(const Key &, const T &newElmt)
Insert a new hashedEntry.
Definition: HashTableI.H:80
Foam::polyMesh::cellZones
const cellZoneMesh & cellZones() const
Return cell zone mesh.
Definition: polyMesh.H:469
main
int main(int argc, char *argv[])
Definition: blockMeshApp.C:68
Foam::regIOobject::write
virtual bool write() const
Write using setting from DB.
Definition: regIOobjectWrite.C:126
Foam::IOobject::MUST_READ
@ MUST_READ
Definition: IOobject.H:108
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:421
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Pair.H
blockMesh.H
defaultFacesType
word defaultFacesType
Definition: readKivaGrid.H:461
Foam::blockMesh::topology
const polyMesh & topology() const
Return the blockMesh topology as a polyMesh.
Definition: blockMesh.C:82
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::IOobject::NO_WRITE
@ NO_WRITE
Definition: IOobject.H:118
Foam::blockMesh::verbose
static void verbose(const bool on=true)
Enable/disable verbose information about the progress.
Definition: blockMesh.C:70
Foam::cellZone
A subset of mesh cells.
Definition: cellZone.H:61
forAllConstIter
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
OFstream.H
Foam::polyMesh::faceZones
const faceZoneMesh & faceZones() const
Return face zone mesh.
Definition: polyMesh.H:463
Foam::IOobject::objectPath
fileName objectPath() const
Return complete path + object name.
Definition: IOobject.H:376
Foam::primitiveMesh::nCells
label nCells() const
Definition: primitiveMeshI.H:64
Foam::fvMesh::write
virtual bool write() const
Write mesh using IO settings from time.
Definition: fvMesh.C:873
Foam::IOobject::headerOk
bool headerOk()
Read and check header info.
Definition: IOobject.C:439
dictName
const word dictName("particleTrackDict")
Foam::blockMesh::writeTopology
void writeTopology(Ostream &) const
Writes edges of blockMesh in OBJ format.
Definition: blockMesh.C:185
regionName
Foam::word regionName
Definition: createNamedDynamicFvMesh.H:1
Foam::primitiveMesh::nPoints
label nPoints() const
Definition: primitiveMeshI.H:35
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::dictionary::found
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:304
Foam::constant::physicoChemical::b
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:28
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::List::append
void append(const T &)
Append an element at the end of the list.
IOPtrList.H
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Foam::polyMesh::pointZones
const pointZoneMesh & pointZones() const
Return point zone mesh.
Definition: polyMesh.H:457
Foam::polyMesh::removeFiles
void removeFiles(const fileName &instanceDir) const
Remove all files from mesh instance.
Definition: polyMesh.C:1173
argList.H
addRegionOption.H
Foam::PtrList
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:61
Foam::Vector::x
const Cmpt & x() const
Definition: VectorI.H:65
Foam::FatalError
error FatalError
Foam::HashTable::size
label size() const
Return number of elements in table.
Definition: HashTableI.H:65
Foam::primitiveMesh::nInternalFaces
label nInternalFaces() const
Definition: primitiveMeshI.H:52
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::Vector::z
const Cmpt & z() const
Definition: VectorI.H:77
Foam::isDir
bool isDir(const fileName &)
Does the name exist as a DIRECTORY in the file system?
Definition: POSIX.C:615
Foam::cellSet
A collection of cell labels.
Definition: cellSet.H:48
Foam::HashTable::find
iterator find(const Key &)
Find and return an iterator set at the hashedEntry.
emptyPolyPatch.H
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::OFstream
Output to file stream.
Definition: OFstream.H:81
Foam::HashTable< label >
Foam::max
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
IOdictionary.H
setRootCase.H
Foam::primitiveMesh::cellCentres
const vectorField & cellCentres() const
Definition: primitiveMeshCellCentresAndVols.C:211
attachPolyTopoChanger.H
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::blockMesh::numZonedBlocks
label numZonedBlocks() const
Number of blocks with specified zones.
Definition: blockMesh.C:169
Foam::primitiveMesh::nFaces
label nFaces() const
Definition: primitiveMeshI.H:58
slidingInterface.H
Foam::blockMesh::points
const pointField & points() const
The points for the entire mesh.
Definition: blockMesh.C:118
defaultFacesName
word defaultFacesName
Definition: readKivaGrid.H:460
Foam::IOstream::defaultPrecision
static unsigned int defaultPrecision()
Return the default precision.
Definition: IOstream.H:461
Foam::xferCopy
Xfer< T > xferCopy(const T &)
Construct by copying the contents of the arg.
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::blockMesh::patchNames
wordList patchNames() const
Return patch names.
Definition: blockMesh.C:151
createTime.H
Foam::argList::optionFound
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:108
Foam::boundBox
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:55
patches
patches[0]
Definition: createSingleCellMesh.H:36
Foam::Vector::y
const Cmpt & y() const
Definition: VectorI.H:71
cellSet.H
Foam::argList::noParallel
static void noParallel()
Remove the parallel options.
Definition: argList.C:161
Foam::blockMesh::cells
const cellShapeList & cells() const
Return cell shapes list.
Definition: blockMesh.C:129
args
Foam::argList args(argc, argv)
dictPath
fileName dictPath
Definition: setConstantMeshDictionaryIO.H:5
Foam::argList::optionReadIfPresent
bool optionReadIfPresent(const word &opt, T &) const
Read a value from the named option if present.
Definition: argListI.H:198
Foam::polyMesh::addZones
void addZones(const List< pointZone * > &pz, const List< faceZone * > &fz, const List< cellZone * > &cz)
Add mesh zones.
Definition: polyMesh.C:922
Foam::blockMesh
A multi-block mesh generator.
Definition: blockMesh.H:58