labelledTriI.H
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 OpenFOAM Foundation
9  Copyright (C) 2016-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 "IOstreams.H"
30 
31 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32 
33 template<class ListType>
34 inline void Foam::labelledTri::assignList(const ListType& list)
35 {
36  const label len = list.size();
37 
38  // checkSize
39  if (len < 3 || len > 4)
40  {
42  << "size " << len << " != (3 or 4)"
43  << abort(FatalError);
44  }
45 
46  auto iter = list.begin();
47 
48  for (label i=0; i<3; ++i)
49  {
50  this->operator[](i) = *iter;
51  ++iter;
52  }
53 
54  index_ = (len == 4) ? *iter : 0;
55 }
56 
57 
58 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
59 
61 :
62  triFace(),
63  index_(-1)
64 {}
65 
66 
68 (
69  const triFace& tri,
70  const label region
71 )
72 :
73  triFace(tri),
74  index_(region)
75 {}
76 
77 
79 (
80  const label p0,
81  const label p1,
82  const label p2,
83  const label region
84 )
85 :
86  triFace(p0, p1, p2),
87  index_(region)
88 {}
89 
90 
92 :
94  index_(0)
95 {
96  assignList(list);
97 }
98 
99 
100 inline Foam::labelledTri::labelledTri(std::initializer_list<label> list)
101 :
102  triFace(),
103  index_(0)
104 {
105  assignList(list);
106 }
107 
108 
110 (
111  const labelUList& list,
112  const FixedList<label, 3>& triIndices,
113  const label region
114 )
115 :
116  triFace(list, triIndices),
117  index_(region)
118 {}
119 
120 
122 (
123  const labelUList& list,
124  const labelledTri& triIndices
125 )
126 :
127  triFace(list, triIndices),
128  index_(triIndices.region())
129 {}
130 
131 
133 {
134  operator>>(is, *this);
135 }
136 
137 
138 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
139 
140 inline Foam::Istream& Foam::operator>>(Istream& is, labelledTri& t)
141 {
142  if (is.format() == IOstreamOption::BINARY)
143  {
144  Detail::readContiguous<labelledTri>
145  (
146  is,
147  reinterpret_cast<char*>(&t),
148  sizeof(labelledTri)
149  );
150  }
151  else
152  {
153  is.readBegin("labelledTri");
154 
155  is >> static_cast<triFace&>(t) >> t.index();
156 
157  is.readEnd("labelledTri");
158  }
159 
160  is.check(FUNCTION_NAME);
161  return is;
162 }
163 
164 
165 inline Foam::Ostream& Foam::operator<<(Ostream& os, const labelledTri& t)
166 {
168  {
169  os.write
170  (
171  reinterpret_cast<const char*>(&t),
172  sizeof(labelledTri)
173  );
174  }
175  else
176  {
178  << static_cast<const triFace&>(t) << token::SPACE << t.index()
179  << token::END_LIST;
180  }
181 
183  return os;
184 }
185 
186 
187 // ************************************************************************* //
virtual Ostream & write(const char c) override
Write character.
Definition: OBJstream.C:69
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
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:45
bool readBegin(const char *funcName)
Begin read of data chunk, starts with &#39;(&#39;.
Definition: Istream.C:134
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Begin list [isseparator].
Definition: token.H:161
labelledTri()
Default construct, with invalid point labels and region (-1).
Definition: labelledTriI.H:53
label & operator[](const label i)
Return element of FixedList.
Definition: FixedListI.H:403
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
A triangular face using a FixedList of labels corresponding to mesh vertices.
Definition: triFace.H:65
Istream & operator>>(Istream &, directionInfo &)
face triFace(3)
Space [isspace].
Definition: token.H:131
End list [isseparator].
Definition: token.H:162
A triFace with additional (region) index.
Definition: labelledTri.H:53
errorManip< error > abort(error &err)
Definition: errorManip.H:139
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 & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
streamFormat format() const noexcept
Get the current stream format.
const volScalarField & p0
Definition: EEqn.H:36