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 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 
40 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
41 
42 Foam::blockMesh::blockMesh(const IOdictionary& dict, const word& regionName)
43 :
44  meshDict_(dict),
45  verboseOutput(meshDict_.lookupOrDefault("verbose", true)),
46  checkFaceCorrespondence_
47  (
48  meshDict_.lookupOrDefault("checkFaceCorrespondence", true)
49  ),
50  geometry_
51  (
52  IOobject
53  (
54  "geometry", // dummy name
55  meshDict_.time().constant(), // instance
56  "geometry", // local
57  meshDict_.time(), // registry
58  IOobject::MUST_READ,
59  IOobject::NO_WRITE
60  ),
61  meshDict_.found("geometry")
62  ? meshDict_.subDict("geometry")
63  : dictionary(),
64  true
65  ),
66  scaleFactor_(1.0),
67  blockVertices_
68  (
69  meshDict_.lookup("vertices"),
70  blockVertex::iNew(meshDict_, geometry_)
71  ),
72  vertices_(Foam::vertices(blockVertices_)),
73  topologyPtr_(createTopology(meshDict_, regionName))
74 {
75  if (meshDict_.lookupOrDefault("fastMerge", false))
76  {
77  calcMergeInfoFast();
78  }
79  else
80  {
81  calcMergeInfo();
82  }
83 }
84 
85 
86 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
87 
89 {
90  return topologyPtr_.valid();
91 }
92 
93 
94 void Foam::blockMesh::verbose(const bool on)
95 {
96  verboseOutput = on;
97 }
98 
99 
101 {
102  return vertices_;
103 }
104 
105 
107 {
108  if (!topologyPtr_)
109  {
111  << "topologyPtr_ not allocated"
112  << exit(FatalError);
113  }
114 
115  return *topologyPtr_;
116 }
117 
118 
120 {
121  const polyPatchList& patchTopologies = topology().boundaryMesh();
122 
123  PtrList<dictionary> patchDicts(patchTopologies.size());
124 
125  forAll(patchTopologies, patchi)
126  {
127  OStringStream os;
128  patchTopologies[patchi].write(os);
129  IStringStream is(os.str());
130  patchDicts.set(patchi, new dictionary(is));
131  }
132  return patchDicts;
133 }
134 
135 
136 Foam::scalar Foam::blockMesh::scaleFactor() const
137 {
138  return scaleFactor_;
139 }
140 
141 
143 {
144  if (points_.empty())
145  {
146  createPoints();
147  }
148 
149  return points_;
150 }
151 
152 
154 {
155  if (cells_.empty())
156  {
157  createCells();
158  }
159 
160  return cells_;
161 }
162 
163 
165 {
166  if (patches_.empty())
167  {
168  createPatches();
169  }
170 
171  return patches_;
172 }
173 
174 
176 {
177  return topology().boundaryMesh().names();
178 }
179 
180 
181 //Foam::wordList Foam::blockMesh::patchTypes() const
182 //{
183 // return topology().boundaryMesh().types();
184 //}
185 //
186 //
187 //Foam::wordList Foam::blockMesh::patchPhysicalTypes() const
188 //{
189 // return topology().boundaryMesh().physicalTypes();
190 //}
191 
192 
194 {
195  const blockList& blocks = *this;
196 
197  label count = 0;
198 
199  for (const block& blk : blocks)
200  {
201  if (blk.zoneName().size())
202  {
203  ++count;
204  }
205  }
206 
207  return count;
208 }
209 
210 
212 {
213  const pointField& pts = topology().points();
214 
215  for (const point& pt : pts)
216  {
217  os << "v " << pt.x() << ' ' << pt.y() << ' ' << pt.z() << endl;
218  }
219 
220  const edgeList& edges = topology().edges();
221 
222  for (const edge& e : edges)
223  {
224  os << "l " << e.start() + 1 << ' ' << e.end() + 1 << endl;
225  }
226 }
227 
228 // ************************************************************************* //
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:119
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::patches
const faceListList & patches() const
Return the patch face lists.
Definition: blockMesh.C:164
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::edge
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:63
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::dictionary::lookupOrDefault
T lookupOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionary.H:1241
blockMesh.H
Foam::blockMesh::topology
const polyMesh & topology() const
Return the blockMesh topology as a polyMesh.
Definition: blockMesh.C:106
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:94
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
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:211
regionName
Foam::word regionName
Definition: createNamedDynamicFvMesh.H:1
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:62
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:100
Foam::PtrList< Foam::dictionary >
Foam::blockVertex
Define a block vertex.
Definition: blockVertex.H:51
Foam::radiation::lookup
Lookup type of boundary radiation properties.
Definition: lookup.H:63
Foam::blockMesh::scaleFactor
scalar scaleFactor() const
The scaling factor used to convert to metres.
Definition: blockMesh.C:136
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::blockMesh::valid
bool valid() const
True if the blockMesh topology exists.
Definition: blockMesh.C:88
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:112
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
found
bool found
Definition: TABSMDCalcMethod2.H:32
Foam::Detail::StringStreamAllocator::str
Foam::string str() const
Get the string - as Foam::string rather than std::string.
Definition: StringStream.H:92
Time.H
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
Foam::blockMesh::numZonedBlocks
label numZonedBlocks() const
Number of blocks with specified zones.
Definition: blockMesh.C:193
Foam::blockMesh::points
const pointField & points() const
The points for the entire mesh.
Definition: blockMesh.C:142
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:175
Foam::OStringStream
Output to string buffer, using a OSstream.
Definition: StringStream.H:189
Foam::constant::electromagnetic::e
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
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:153
constant
constant condensation/saturation model.