blockMesh.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) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2018-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "blockMesh.H"
30 #include "Time.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineDebugSwitch(blockMesh, 0);
37 }
38 
40 
41 
43 Foam::blockMesh::strategyNames_
44 ({
45  { mergeStrategy::MERGE_TOPOLOGY, "topology" },
46  { mergeStrategy::MERGE_POINTS, "points" },
47 });
48 
49 
50 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
51 
52 Foam::blockMesh::blockMesh
53 (
54  const IOdictionary& dict,
55  const word& regionName,
56  mergeStrategy strategy
57 )
58 :
59  meshDict_(dict),
60  verbose_(meshDict_.getOrDefault("verbose", verboseOutput)),
61  checkFaceCorrespondence_
62  (
63  meshDict_.getOrDefault("checkFaceCorrespondence", true)
64  ),
65  geometry_
66  (
67  IOobject
68  (
69  "geometry", // dummy name
70  meshDict_.time().constant(), // instance
71  "geometry", // local
72  meshDict_.time(), // registry
73  IOobject::MUST_READ,
74  IOobject::NO_WRITE
75  ),
76  meshDict_.found("geometry")
77  ? meshDict_.subDict("geometry")
78  : dictionary(),
79  true
80  ),
81  scaleFactor_(1),
82  blockVertices_
83  (
84  meshDict_.lookup("vertices"),
85  blockVertex::iNew(meshDict_, geometry_)
86  ),
87  vertices_(Foam::vertices(blockVertices_)),
88  topologyPtr_(createTopology(meshDict_, regionName))
89 {
90  // Command-line option has precedence over dictionary setting
91 
92  if (strategy == mergeStrategy::DEFAULT_MERGE)
93  {
94  strategyNames_.readIfPresent("mergeType", meshDict_, strategy);
95 
96  // Warn about fairly obscure old "fastMerge" option?
97  }
98 
99  if (strategy == mergeStrategy::MERGE_POINTS)
100  {
101  // MERGE_POINTS
102  calcGeometricalMerge();
103  }
104  else
105  {
106  // MERGE_TOPOLOGY
107  calcTopologicalMerge();
108  }
109 }
110 
111 
112 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
113 
114 bool Foam::blockMesh::valid() const noexcept
115 {
116  return bool(topologyPtr_);
117 }
118 
119 
120 bool Foam::blockMesh::verbose() const noexcept
121 {
122  return verbose_;
123 }
124 
125 
126 bool Foam::blockMesh::verbose(const bool on) noexcept
127 {
128  bool old(verbose_);
129  verbose_ = on;
130  return old;
131 }
132 
133 
135 {
136  return vertices_;
137 }
138 
139 
141 {
142  if (!topologyPtr_)
143  {
145  << "topologyPtr_ not allocated"
146  << exit(FatalError);
147  }
148 
149  return *topologyPtr_;
150 }
151 
152 
154 {
155  const polyPatchList& patchTopologies = topology().boundaryMesh();
156 
157  PtrList<dictionary> patchDicts(patchTopologies.size());
158 
159  forAll(patchTopologies, patchi)
160  {
161  OStringStream os;
162  patchTopologies[patchi].write(os);
163  IStringStream is(os.str());
164  patchDicts.set(patchi, new dictionary(is));
165  }
166  return patchDicts;
167 }
168 
169 
170 Foam::scalar Foam::blockMesh::scaleFactor() const
171 {
172  return scaleFactor_;
173 }
174 
175 
177 {
178  if (points_.empty())
179  {
180  createPoints();
181  }
182 
183  return points_;
184 }
185 
186 
188 {
189  if (cells_.empty())
190  {
191  createCells();
192  }
193 
194  return cells_;
195 }
196 
197 
199 {
200  if (patches_.empty())
201  {
202  createPatches();
203  }
204 
205  return patches_;
206 }
207 
208 
210 {
211  return topology().boundaryMesh().names();
212 }
213 
214 
215 //Foam::wordList Foam::blockMesh::patchTypes() const
216 //{
217 // return topology().boundaryMesh().types();
218 //}
219 //
220 //
221 //Foam::wordList Foam::blockMesh::patchPhysicalTypes() const
222 //{
223 // return topology().boundaryMesh().physicalTypes();
224 //}
225 
226 
228 {
229  const blockList& blocks = *this;
230 
231  label count = 0;
232 
233  for (const block& blk : blocks)
234  {
235  if (blk.zoneName().size())
236  {
237  ++count;
238  }
239  }
240 
241  return count;
242 }
243 
244 
245 // ************************************************************************* //
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:54
Foam::blockMesh::patchDicts
PtrList< dictionary > patchDicts() const
Get patch information from the topology mesh.
Definition: blockMesh.C:153
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::block
Creates a single block of cells from point coordinates, numbers of cells in each direction and an exp...
Definition: block.H:58
Foam::blockMesh::valid
bool valid() const noexcept
True if the blockMesh topology exists.
Definition: blockMesh.C:114
Foam::Enum
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: IOstreamOption.H:57
Foam::blockMesh::patches
const faceListList & patches() const
Return the patch face lists.
Definition: blockMesh.C:198
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::blockMesh::mergeStrategy
mergeStrategy
The block merging strategy.
Definition: blockMesh.H:163
blockMesh.H
Foam::blockMesh::topology
const polyMesh & topology() const
Return the blockMesh topology as a polyMesh.
Definition: blockMesh.C:140
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
patchDicts
PtrList< dictionary > patchDicts
Definition: readKivaGrid.H:532
regionName
Foam::word regionName
Definition: createNamedDynamicFvMesh.H:1
Foam::blockMesh::verbose
bool verbose() const noexcept
Verbose output.
Definition: blockMesh.C:120
Foam::Field< vector >
Foam::defineDebugSwitch
defineDebugSwitch(blockMesh, 0)
Foam::blockMesh::vertices
const pointField & vertices() const
Reference to point field defining the blockMesh.
Definition: blockMesh.C:134
Foam::PtrList< Foam::dictionary >
Foam::blockMesh::scaleFactor
scalar scaleFactor() const
The scaling factor used to convert to metres.
Definition: blockMesh.C:170
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::vertices
pointField vertices(const blockVertexList &bvl)
Definition: blockVertexList.H:49
Foam::IStringStream
Input from string buffer, using a ISstream.
Definition: StringStream.H:111
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::Detail::StringStreamAllocator::str
Foam::string str() const
Get the string - as Foam::string rather than std::string.
Definition: StringStream.H:91
Time.H
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
Foam::blockMesh::numZonedBlocks
label numZonedBlocks() const
Number of blocks with specified zones.
Definition: blockMesh.C:227
Foam::blockMesh::points
const pointField & points() const
The points for the entire mesh.
Definition: blockMesh.C:176
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:77
Foam::List< cellShape >
Foam::blockMesh::patchNames
wordList patchNames() const
Return patch names.
Definition: blockMesh.C:209
Foam::OStringStream
Output to string buffer, using a OSstream.
Definition: StringStream.H:196
bool
bool
Definition: EEqn.H:20
Foam::blockVertex::iNew
Class used for the read-construction of.
Definition: blockVertex.H:95
Foam::blockMesh::cells
const cellShapeList & cells() const
Return cell shapes list.
Definition: blockMesh.C:187
Foam::blockMesh::verboseOutput
static bool verboseOutput
The default verbosity (true)
Definition: blockMesh.H:295