surfZoneIOList.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "surfZoneIOList.H"
27 
28 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
29 
30 namespace Foam
31 {
32 defineTypeNameAndDebug(surfZoneIOList, 0);
33 }
34 
35 
36 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
37 
39 (
40  const IOobject& io
41 )
42 :
43  surfZoneList(),
44  regIOobject(io)
45 {
47  "surfZoneIOList::surfZoneIOList"
48  "(const IOobject& io)";
49 
50 
51  if
52  (
53  readOpt() == IOobject::MUST_READ
54  || readOpt() == IOobject::MUST_READ_IF_MODIFIED
55  )
56  {
57  surfZoneList& zones = *this;
58 
59  Istream& is = readStream(typeName);
60 
61  PtrList<entry> dictEntries(is);
62  zones.setSize(dictEntries.size());
63 
64  label facei = 0;
65  forAll(zones, zoneI)
66  {
67  const dictionary& dict = dictEntries[zoneI].dict();
68 
69  label zoneSize = dict.lookup<label>("nFaces");
70  label startFacei = dict.lookup<label>("startFace");
71 
72  zones[zoneI] = surfZone
73  (
74  dictEntries[zoneI].keyword(),
75  zoneSize,
76  startFacei,
77  zoneI
78  );
79 
80  word geoType;
81  if (dict.readIfPresent("geometricType", geoType))
82  {
83  zones[zoneI].geometricType() = geoType;
84  }
85 
86  if (startFacei != facei)
87  {
89  << "surfZones are not ordered. Start of zone " << zoneI
90  << " does not correspond to sum of preceding zones." << nl
91  << "while reading " << objectPath() << endl
92  << exit(FatalError);
93  }
94 
95  facei += zoneSize;
96  }
97 
98  // Check state of IOstream
99  is.check(functionName.c_str());
100 
101  close();
102  }
103 }
104 
105 
107 (
108  const IOobject& io,
109  const surfZoneList& zones
110 )
111 :
112  surfZoneList(zones),
113  regIOobject(io)
114 {}
115 
116 
118 (
119  const IOobject& io,
120  surfZoneList&& zones
121 )
122 :
123  surfZoneList(move(zones)),
124  regIOobject(io)
125 {}
126 
127 
128 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
129 
131 {}
132 
133 
134 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
135 
136 
137 // writeData member function required by regIOobject
139 {
140  os << *this;
141  return os.good();
142 }
143 
144 
145 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
146 
148 {
149  os << L.size() << nl << token::BEGIN_LIST << incrIndent << nl;
150 
151  forAll(L, i)
152  {
153  L[i].writeDict(os);
154  }
155 
156  os << decrIndent << token::END_LIST;
157 
158  return os;
159 }
160 
161 
162 // ************************************************************************* //
dictionary dict
bool writeData(Ostream &) const
writeData member function required by regIOobject
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
A surface zone on a MeshedSurface.
Definition: surfZone.H:62
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
~surfZoneIOList()
Destructor.
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:330
A functionName is a word starting with &#39;#&#39;.
Definition: functionName.H:57
A class for handling words, derived from string.
Definition: word.H:59
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
surfZoneIOList(const IOobject &)
Construct from IOobject.
IOobject for a surfZoneList.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
static const char nl
Definition: Ostream.H:260
defineTypeNameAndDebug(combustionModel, 0)
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:235
List< surfZone > surfZoneList
Definition: surfZoneList.H:45
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
void setSize(const label)
Reset size of List.
Definition: List.C:281
Ostream & operator<<(Ostream &, const ensightPart &)
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:52
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:228
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:98
A class for handling character strings derived from std::string.
Definition: string.H:76
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:864