1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
26 \*---------------------------------------------------------------------------*/
28 #include "eBoundaryMesh.H"
30 #include "primitiveMesh.H"
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
39 defineTypeNameAndDebug(eBoundaryMesh, 0);
42 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
45 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
47 // Construct from dictionary
48 eBoundaryMesh::eBoundaryMesh
60 (readOpt() == IOobject::MUST_READ) ||
61 (readOpt() == IOobject::READ_IF_PRESENT && headerOk())
64 readFromInputStream();
69 // Construct given size. Patches will be set later
70 eBoundaryMesh::eBoundaryMesh
83 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
85 //- Read from input stream
86 void eBoundaryMesh::readFromInputStream()
88 ePatchList& patches = *this;
91 Istream& is = readStream(typeName);
93 PtrList<entry> patchEntries(is);
94 patches.setSize(patchEntries.size());
96 forAll(patches, patchI)
103 patchEntries[patchI].keyword(),
104 patchEntries[patchI].dict(),
111 // Check state of IOstream
114 "eBoundaryMesh::eBoundaryMesh"
115 "(const IOobject&, const faMesh&)"
121 // Return the mesh reference
122 const eMesh& eBoundaryMesh::mesh() const
128 // Return a list of patch types
129 wordList eBoundaryMesh::types() const
131 const ePatchList& patches = *this;
133 wordList t(patches.size());
135 forAll (patches, patchI)
137 t[patchI] = patches[patchI].type();
144 // Return a list of patch names
145 wordList eBoundaryMesh::names() const
147 const ePatchList& patches = *this;
149 wordList t(patches.size());
151 forAll (patches, patchI)
153 t[patchI] = patches[patchI].name();
160 // Return a list of patch sizes
161 labelList eBoundaryMesh::patchSizes() const
163 const ePatchList& patches = *this;
165 labelList t(patches.size());
167 forAll (patches, patchI)
169 t[patchI] = patches[patchI].size();
176 // Return a list of patch starts
177 labelList eBoundaryMesh::patchStarts() const
179 const ePatchList& patches = *this;
181 labelList t(patches.size());
183 forAll (patches, patchI)
185 t[patchI] = patches[patchI].start();
192 //- Return patch index for a given edge label
193 label eBoundaryMesh::whichPatch(const label edgeIndex) const
195 // Find out which patch the current edge belongs to by comparing label
196 // with patch start labels.
197 // If the face is internal, return -1;
198 // if it is off the end of the list, abort
199 if (edgeIndex >= mesh().nEdges())
203 "eBoundaryMesh::whichPatch(const label edgeIndex) const"
204 ) << "given label greater than the number of geometric edges"
205 << abort(FatalError);
208 if (edgeIndex < mesh().nInternalEdges())
213 forAll (*this, patchI)
215 const ePatch& bp = operator[](patchI);
219 edgeIndex >= bp.start()
220 && edgeIndex < bp.start() + bp.size()
227 // If not in any of above, it is trouble!
230 "label eBoundaryMesh::whichPatch(const label edgeIndex) const"
231 ) << "Cannot find edge " << edgeIndex << " in any of the patches "
233 << "It seems your patches are not consistent with the mesh :"
234 << " internalEdges:" << mesh().nInternalEdges()
235 << " total number of edges:" << mesh().nEdges()
236 << abort(FatalError);
242 label eBoundaryMesh::findPatchID(const word& patchName) const
244 const ePatchList& patches = *this;
246 forAll (patches, patchI)
248 if (patches[patchI].name() == patchName)
259 // writeData member function required by regIOobject
260 bool eBoundaryMesh::writeData(Ostream& os) const
262 const ePatchList& patches = *this;
264 os << patches.size() << nl << token::BEGIN_LIST << incrIndent << nl;
266 forAll(patches, patchi)
268 os << indent << patches[patchi].name() << nl
269 << indent << token::BEGIN_BLOCK << nl
270 << incrIndent << patches[patchi] << decrIndent
271 << indent << token::END_BLOCK << endl;
274 os << decrIndent << token::END_LIST;
276 // Check state of IOstream
277 os.check("eBoundaryMesh::writeData(Ostream& os) const");
283 Ostream& operator<<(Ostream& os, const eBoundaryMesh& bm)
290 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
292 } // End namespace Foam
294 // ************************************************************************* //