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-2020 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 // * * * * * * * * * * * * * * * * 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.resize(dictEntries.size());
61 
62  label facei = 0;
63  forAll(zones, zonei)
64  {
65  zones[zonei] = surfZone
66  (
67  dictEntries[zonei].keyword(),
68  dictEntries[zonei].dict(),
69  zonei
70  );
71 
72  if (zones[zonei].start() != facei)
73  {
75  << "surfZones are not ordered. Start of zone " << zonei
76  << " does not correspond to sum of preceding zones." << nl
77  << "while reading " << io.objectPath() << endl
78  << exit(FatalError);
79  }
80 
81  facei += zones[zonei].size();
82  }
83 
84  is.check(FUNCTION_NAME);
85  close();
86  }
87 }
88 
89 
91 (
92  const IOobject& io,
93  const UList<surfZone>& content
94 )
95 :
96  regIOobject(io),
97  surfZoneList(content)
98 {}
99 
100 
102 (
103  const IOobject& io,
104  surfZoneList&& content
105 )
106 :
107  regIOobject(io),
108  surfZoneList(std::move(content))
109 {}
110 
111 
112 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
113 
115 {
116  const surfZoneList& zones = *this;
117  const label sz = zones.size();
118 
119  if (sz)
120  {
121  os << sz << nl << token::BEGIN_LIST << incrIndent << nl;
122 
123  for (const surfZone& zn : zones)
124  {
125  zn.write(os);
126  }
127 
129  }
130  else
131  {
133  }
134 
135  return os.good();
136 }
137 
138 
139 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
140 
142 {
144 }
145 
146 
147 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
148 
150 {
151  zones.writeData(os);
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:169
Foam::List::resize
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::incrIndent
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:346
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::surfZoneIOList::writeData
bool writeData(Ostream &os) const
The writeData function - required by regIOobject.
Definition: surfZoneIOList.C:114
Foam::surfZoneIOList
IOobject for a surfZoneList.
Definition: surfZoneIOList.H:53
Foam::surfZoneIOList::operator=
void operator=(const surfZoneIOList &rhs)
Copy assignment of entries.
Definition: surfZoneIOList.C:141
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::defineTypeName
defineTypeName(ensightPart)
Foam::PtrList< entry >
Foam::List< surfZone >::operator=
void operator=(const UList< surfZone > &a)
Assignment to UList operator. Takes linear time.
Definition: List.C:498
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:58
Foam::FatalError
error FatalError
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::decrIndent
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:353
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:73
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::nl
constexpr char nl
Definition: Ostream.H:404
surfZoneIOList.H
Foam::List< surfZone >
Foam::surfZone
A surface zone on a MeshedSurface.
Definition: surfZone.H:56
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:295
Foam::surfZoneList
List< surfZone > surfZoneList
Definition: surfZoneList.H:47
Foam::token::END_LIST
End list [isseparator].
Definition: token.H:156
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:214
Foam::token::BEGIN_LIST
Begin list [isseparator].
Definition: token.H:155