initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / triSurface / triSurface / surfacePatch / surfacePatchIOList.C
blobd7389299387b067283ea89942cb7c571be03c97a
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "surfacePatchIOList.H"
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 defineTypeNameAndDebug(Foam::surfacePatchIOList, 0);
34 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
36 // Construct from IOObject
37 Foam::surfacePatchIOList::surfacePatchIOList
39     const IOobject& io
42     surfacePatchList(),
43     regIOobject(io)
45     Foam::string functionName =
46         "surfacePatchIOList::surfacePatchIOList"
47         "(const IOobject& io)";
50     if (readOpt() == IOobject::MUST_READ)
51     {
52         surfacePatchList& patches = *this;
54         // read polyPatchList
55         Istream& is = readStream(typeName);
57         PtrList<entry> patchEntries(is);
58         patches.setSize(patchEntries.size());
60         label faceI = 0;
62         forAll(patches, patchI)
63         {
64             const dictionary& dict = patchEntries[patchI].dict();
66             label patchSize = readLabel(dict.lookup("nFaces"));
67             label startFaceI = readLabel(dict.lookup("startFace"));
69             patches[patchI] = 
70                 surfacePatch
71                 (
72                     word(dict.lookup("geometricType")),
73                     patchEntries[patchI].keyword(),
74                     patchSize,
75                     startFaceI,
76                     patchI
77                 );
80             if (startFaceI != faceI)
81             {
82                 FatalErrorIn(functionName)
83                     << "Patches are not ordered. Start of patch " << patchI
84                     << " does not correspond to sum of preceding patches."
85                     << endl
86                     << "while reading " << io.objectPath()
87                     << exit(FatalError);
88             }
90             faceI += patchSize;
91         }
93         // Check state of IOstream
94         is.check(functionName.c_str());
96         close();
97     }
100 // Construct from IOObject
101 Foam::surfacePatchIOList::surfacePatchIOList
103     const IOobject& io,
104     const surfacePatchList& patches    
107     surfacePatchList(patches),
108     regIOobject(io)
112 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
114 Foam::surfacePatchIOList::~surfacePatchIOList()
118 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
121 // writeData member function required by regIOobject
122 bool Foam::surfacePatchIOList::writeData(Ostream& os) const
124     os << *this;
125     return os.good();
129 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
131 Foam::Ostream& Foam::operator<<(Ostream& os, const surfacePatchIOList& patches)
133     os  << patches.size() << nl << token::BEGIN_LIST;
135     forAll(patches, patchI)
136     {
137         patches[patchI].writeDict(os);
138     }
140     os  << token::END_LIST;
142     return os;
146 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
149 // * * * * * * * * * * * * * * * Friend Functions  * * * * * * * * * * * * * //
151 // ************************************************************************* //