surfZoneIOList.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-2016 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 "surfZoneIOList.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  defineTypeNameAndDebug(surfZoneIOList, 0);
36 }
37 
38 
39 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40 
42 (
43  const IOobject& io
44 )
45 :
46  regIOobject(io),
47  surfZoneList()
48 {
49  if
50  (
51  readOpt() == IOobject::MUST_READ
52  || readOpt() == IOobject::MUST_READ_IF_MODIFIED
53  )
54  {
55  surfZoneList& zones = *this;
56 
57  Istream& is = readStream(typeName);
58 
59  PtrList<entry> dictEntries(is);
60  zones.setSize(dictEntries.size());
61 
62  label facei = 0;
63  forAll(zones, zoneI)
64  {
65  const dictionary& dict = dictEntries[zoneI].dict();
66 
67  const label zoneSize = dict.get<label>("nFaces");
68  const label startFacei = dict.get<label>("startFace");
69 
70  zones[zoneI] = surfZone
71  (
72  dictEntries[zoneI].keyword(),
73  zoneSize,
74  startFacei,
75  zoneI
76  );
77 
78  word geoType;
79  if (dict.readIfPresent("geometricType", geoType))
80  {
81  zones[zoneI].geometricType() = geoType;
82  }
83 
84  if (startFacei != facei)
85  {
87  << "surfZones are not ordered. Start of zone " << zoneI
88  << " does not correspond to sum of preceding zones." << nl
89  << "while reading " << io.objectPath() << endl
90  << exit(FatalError);
91  }
92 
93  facei += zoneSize;
94  }
95 
96  is.check(FUNCTION_NAME);
97  close();
98  }
99 }
100 
101 
103 (
104  const IOobject& io,
105  const UList<surfZone>& content
106 )
107 :
108  regIOobject(io),
109  surfZoneList(content)
110 {}
111 
112 
114 (
115  const IOobject& io,
116  surfZoneList&& content
117 )
118 :
119  regIOobject(io),
120  surfZoneList(std::move(content))
121 {}
122 
123 
124 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
125 
127 {
128  return (os << *this).good();
129 }
130 
131 
132 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
133 
135 {
137 }
138 
139 
140 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
141 
143 {
144  os << list.size() << nl << token::BEGIN_LIST << incrIndent << nl;
145 
146  for (const surfZone& item : list)
147  {
148  item.writeDict(os);
149  }
150 
151  os << decrIndent << token::END_LIST;
152 
153  return os;
154 }
155 
156 
157 // ************************************************************************* //
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::incrIndent
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:314
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::surfZoneIOList::writeData
bool writeData(Ostream &os) const
The writeData function for regIOobject.
Definition: surfZoneIOList.C:126
Foam::surfZoneIOList
IOobject for a surfZoneList.
Definition: surfZoneIOList.H:61
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::surfZoneIOList::operator=
void operator=(const surfZoneIOList &rhs)
Copy assignment of entries.
Definition: surfZoneIOList.C:134
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::PtrList< entry >
Foam::List< surfZone >::operator=
void operator=(const UList< surfZone > &a)
Assignment to UList operator. Takes linear time.
Definition: List.C:478
Foam::surfZoneIOList::surfZoneIOList
surfZoneIOList(const IOobject &io)
Construct from IOobject.
Definition: surfZoneIOList.C:42
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:51
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
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::decrIndent
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:321
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:67
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
Foam::nl
constexpr char nl
Definition: Ostream.H:372
surfZoneIOList.H
Foam::List< surfZone >
Foam::surfZone
A surface zone on a MeshedSurface.
Definition: surfZone.H:65
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:261
Foam::surfZoneList
List< surfZone > surfZoneList
Definition: surfZoneList.H:47
Foam::token::END_LIST
End list [isseparator].
Definition: token.H:118
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::IOobject::objectPath
fileName objectPath() const
The complete path + object name.
Definition: IOobjectI.H:185
Foam::List::setSize
void setSize(const label newSize)
Alias for resize(const label)
Definition: ListI.H:146
Foam::token::BEGIN_LIST
Begin list [isseparator].
Definition: token.H:117
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &)
Definition: boundaryPatch.C:102