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 
39 
41 Foam::blockMesh::strategyNames_
42 ({
43  { mergeStrategy::MERGE_TOPOLOGY, "topology" },
44  { mergeStrategy::MERGE_POINTS, "points" },
45 });
46 
47 
48 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49 
50 Foam::blockMesh::blockMesh
51 (
52  const IOdictionary& dict,
53  const word& regionName,
54  mergeStrategy strategy
55 )
56 :
57  meshDict_(dict),
58  verboseOutput(meshDict_.getOrDefault("verbose", true)),
59  checkFaceCorrespondence_
60  (
61  meshDict_.getOrDefault("checkFaceCorrespondence", true)
62  ),
63  geometry_
64  (
65  IOobject
66  (
67  "geometry", // dummy name
68  meshDict_.time().constant(), // instance
69  "geometry", // local
70  meshDict_.time(), // registry
71  IOobject::MUST_READ,
72  IOobject::NO_WRITE
73  ),
74  meshDict_.found("geometry")
75  ? meshDict_.subDict("geometry")
76  : dictionary(),
77  true
78  ),
79  scaleFactor_(1),
80  blockVertices_
81  (
82  meshDict_.lookup("vertices"),
83  blockVertex::iNew(meshDict_, geometry_)
84  ),
85  vertices_(Foam::vertices(blockVertices_)),
86  topologyPtr_(createTopology(meshDict_, regionName))
87 {
88  // Command-line option has precedence over dictionary setting
89 
90  if (strategy == mergeStrategy::DEFAULT_MERGE)
91  {
92  strategyNames_.readIfPresent("mergeType", meshDict_, strategy);
93 
94  // Warn about fairly obscure old "fastMerge" option?
95  }
96 
97  if (strategy == mergeStrategy::MERGE_POINTS)
98  {
99  // MERGE_POINTS
100  calcGeometricalMerge();
101  }
102  else
103  {
104  // MERGE_TOPOLOGY
105  calcTopologicalMerge();
106  }
107 }
108 
109 
110 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
111 
113 {
114  return bool(topologyPtr_);
115 }
116 
117 
118 void Foam::blockMesh::verbose(const bool on)
119 {
120  verboseOutput = on;
121 }
122 
123 
125 {
126  return vertices_;
127 }
128 
129 
131 {
132  if (!topologyPtr_)
133  {
135  << "topologyPtr_ not allocated"
136  << exit(FatalError);
137  }
138 
139  return *topologyPtr_;
140 }
141 
142 
144 {
145  const polyPatchList& patchTopologies = topology().boundaryMesh();
146 
147  PtrList<dictionary> patchDicts(patchTopologies.size());
148 
149  forAll(patchTopologies, patchi)
150  {
151  OStringStream os;
152  patchTopologies[patchi].write(os);
153  IStringStream is(os.str());
154  patchDicts.set(patchi, new dictionary(is));
155  }
156  return patchDicts;
157 }
158 
159 
160 Foam::scalar Foam::blockMesh::scaleFactor() const
161 {
162  return scaleFactor_;
163 }
164 
165 
167 {
168  if (points_.empty())
169  {
170  createPoints();
171  }
172 
173  return points_;
174 }
175 
176 
178 {
179  if (cells_.empty())
180  {
181  createCells();
182  }
183 
184  return cells_;
185 }
186 
187 
189 {
190  if (patches_.empty())
191  {
192  createPatches();
193  }
194 
195  return patches_;
196 }
197 
198 
200 {
201  return topology().boundaryMesh().names();
202 }
203 
204 
205 //Foam::wordList Foam::blockMesh::patchTypes() const
206 //{
207 // return topology().boundaryMesh().types();
208 //}
209 //
210 //
211 //Foam::wordList Foam::blockMesh::patchPhysicalTypes() const
212 //{
213 // return topology().boundaryMesh().physicalTypes();
214 //}
215 
216 
218 {
219  const blockList& blocks = *this;
220 
221  label count = 0;
222 
223  for (const block& blk : blocks)
224  {
225  if (blk.zoneName().size())
226  {
227  ++count;
228  }
229  }
230 
231  return count;
232 }
233 
234 
236 {
237  for (const point& p : topology().points())
238  {
239  os << "v " << p.x() << ' ' << p.y() << ' ' << p.z() << nl;
240  }
241 
242  for (const edge& e : topology().edges())
243  {
244  os << "l " << e.start() + 1 << ' ' << e.end() + 1 << nl;
245  }
246 }
247 
248 // ************************************************************************* //
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:143
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
p
volScalarField & p
Definition: createFieldRefs.H:8
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:188
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:156
Foam::edge
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:63
blockMesh.H
Foam::blockMesh::topology
const polyMesh & topology() const
Return the blockMesh topology as a polyMesh.
Definition: blockMesh.C:130
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::blockMesh::verbose
void verbose(const bool on=true)
Enable/disable verbose information about the progress.
Definition: blockMesh.C:118
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
patchDicts
PtrList< dictionary > patchDicts
Definition: readKivaGrid.H:532
Foam::blockMesh::writeTopology
void writeTopology(Ostream &) const
Writes edges of blockMesh in OBJ format.
Definition: blockMesh.C:235
regionName
Foam::word regionName
Definition: createNamedDynamicFvMesh.H:1
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:124
Foam::PtrList< Foam::dictionary >
Foam::blockMesh::scaleFactor
scalar scaleFactor() const
The scaling factor used to convert to metres.
Definition: blockMesh.C:160
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::blockMesh::valid
bool valid() const
True if the blockMesh topology exists.
Definition: blockMesh.C:112
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:372
Foam::blockMesh::numZonedBlocks
label numZonedBlocks() const
Number of blocks with specified zones.
Definition: blockMesh.C:217
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::blockMesh::points
const pointField & points() const
The points for the entire mesh.
Definition: blockMesh.C:166
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:74
Foam::Vector< scalar >
Foam::List< cellShape >
Foam::blockMesh::patchNames
wordList patchNames() const
Return patch names.
Definition: blockMesh.C:199
Foam::OStringStream
Output to string buffer, using a OSstream.
Definition: StringStream.H:196
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::constant::electromagnetic::e
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
bool
bool
Definition: EEqn.H:20
Foam::blockVertex::iNew
Class used for the read-construction of.
Definition: blockVertex.H:95
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::blockMesh::cells
const cellShapeList & cells() const
Return cell shapes list.
Definition: blockMesh.C:177