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-2023 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  defineTypeName(surfZoneIOList);
36 }
37 
38 
39 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
40 
41 bool Foam::surfZoneIOList::readContents()
42 {
43  if
44  (
45  this->isReadRequired()
46  )
47  {
48  surfZoneList& zones = *this;
49 
50  // Read entries
51  Istream& is = readStream(typeName);
52 
53  PtrList<entry> entries(is);
54  zones.resize(entries.size());
55 
56  // Transcribe
57  label startOffset = 0;
58  forAll(zones, zonei)
59  {
60  zones[zonei] = surfZone
61  (
62  entries[zonei].keyword(),
63  entries[zonei].dict(),
64  zonei
65  );
66 
67  if (zones[zonei].start() != startOffset)
68  {
70  << "surfZones are not ordered. Start of zone " << zonei
71  << " does not correspond to sum of preceding zones." << nl
72  << "while reading " << this->objectRelPath() << endl
73  << exit(FatalError);
74  }
75 
76  startOffset += zones[zonei].size();
77  }
78 
79  is.check(FUNCTION_NAME);
80  close();
81  return true;
82  }
83 
84  // Nothing read
85  return false;
86 }
87 
88 
89 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
90 
92 (
93  const IOobject& io
94 )
95 :
96  regIOobject(io),
98 {
99  readContents(); // allowOptionalRead = false
100 }
101 
102 
104 (
105  const IOobject& io,
106  const UList<surfZone>& content
107 )
108 :
109  regIOobject(io),
110  surfZoneList(content)
111 {}
112 
113 
115 (
116  const IOobject& io,
117  surfZoneList&& content
118 )
119 :
121  surfZoneList(std::move(content))
122 {}
123 
124 
125 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
126 
128 {
129  const surfZoneList& zones = *this;
130  const label len = zones.size();
131 
132  if (len)
133  {
134  os << len << nl << token::BEGIN_LIST << incrIndent << nl;
135 
136  for (const surfZone& zn : zones)
137  {
138  zn.write(os);
139  }
140 
142  }
143  else
144  {
145  os << len << token::BEGIN_LIST << token::END_LIST;
146  }
148  return os.good();
149 }
150 
151 
152 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
153 
155 {
157 }
158 
159 
160 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
161 
162 Foam::Ostream& Foam::operator<<(Ostream& os, const surfZoneIOList& zones)
163 {
164  zones.writeData(os);
165 
166  return os;
167 }
168 
169 
170 // ************************************************************************* //
dictionary dict
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
surfZoneIOList(const IOobject &io)
Construct from IOobject.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
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:598
A surface zone on a MeshedSurface.
Definition: surfZone.H:52
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
Begin list [isseparator].
Definition: token.H:161
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
defineTypeName(manifoldCellsMeshObject)
void operator=(const UList< surfZone > &list)
Assignment to UList operator. Takes linear time.
Definition: List.C:360
void close()
Close Istream.
End list [isseparator].
Definition: token.H:162
IOobject for a surfZoneList.
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:105
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:511
bool isReadRequired() const noexcept
True if (MUST_READ | READ_MODIFIED) bits are set.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
bool good() const noexcept
True if next operation might succeed.
Definition: IOstream.H:281
List< surfZone > surfZoneList
List of surfZone.
Definition: surfZoneList.H:32
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:66
fileName objectRelPath() const
The object path relative to the root.
Definition: IOobject.C:524
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:502
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
Istream & readStream(const word &, const bool readOnProc=true)
Return Istream and check object type against that given.
bool writeData(Ostream &os) const
The writeData function - required by regIOobject.
Namespace for OpenFOAM.
void operator=(const surfZoneIOList &rhs)
Copy assignment of entries.