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-2022 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 {
36 }
37 
38 
39 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40 
42 (
43  const IOobject& io
44 )
45 :
46  regIOobject(io),
47  surfZoneList()
48 {
49  if (isReadRequired())
50  {
51  surfZoneList& zones = *this;
52 
53  Istream& is = readStream(typeName);
54 
55  PtrList<entry> dictEntries(is);
56  zones.resize(dictEntries.size());
57 
58  label facei = 0;
59  forAll(zones, zonei)
60  {
61  zones[zonei] = surfZone
62  (
63  dictEntries[zonei].keyword(),
64  dictEntries[zonei].dict(),
65  zonei
66  );
67 
68  if (zones[zonei].start() != facei)
69  {
71  << "surfZones are not ordered. Start of zone " << zonei
72  << " does not correspond to sum of preceding zones." << nl
73  << "while reading " << io.objectPath() << endl
74  << exit(FatalError);
75  }
76 
77  facei += zones[zonei].size();
78  }
79 
81  close();
82  }
83 }
84 
85 
87 (
88  const IOobject& io,
89  const UList<surfZone>& content
90 )
91 :
92  regIOobject(io),
93  surfZoneList(content)
94 {}
95 
96 
98 (
99  const IOobject& io,
100  surfZoneList&& content
101 )
102 :
104  surfZoneList(std::move(content))
105 {}
106 
107 
108 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
109 
111 {
112  const surfZoneList& zones = *this;
113  const label sz = zones.size();
114 
115  if (sz)
116  {
117  os << sz << nl << token::BEGIN_LIST << incrIndent << nl;
118 
119  for (const surfZone& zn : zones)
120  {
121  zn.write(os);
122  }
123 
125  }
126  else
127  {
129  }
131  return os.good();
132 }
133 
134 
135 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
136 
138 {
140 }
141 
142 
143 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
144 
145 Foam::Ostream& Foam::operator<<(Ostream& os, const surfZoneIOList& zones)
146 {
147  zones.writeData(os);
148 
149  return os;
150 }
151 
152 
153 // ************************************************************************* //
dictionary dict
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:118
surfZoneIOList(const IOobject &io)
Construct from IOobject.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:132
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:578
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:45
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:52
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:49
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
Begin list [isseparator].
Definition: token.H:158
void operator=(const UList< surfZone > &a)
Assignment to UList operator. Takes linear time.
Definition: List.C:472
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:413
defineTypeName(manifoldCellsMeshObject)
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
void close()
Close Istream.
End list [isseparator].
Definition: token.H:159
IOobject for a surfZoneList.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:55
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:467
bool isReadRequired() const noexcept
True if (MUST_READ | MUST_READ_IF_MODIFIED) bits are set.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:76
bool good() const noexcept
True if next operation might succeed.
Definition: IOstream.H:274
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:69
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:458
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:166
bool writeData(Ostream &os) const
The writeData function - required by regIOobject.
Namespace for OpenFOAM.
void operator=(const surfZoneIOList &rhs)
Copy assignment of entries.