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-2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
33template<class ListType>
34inline 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 a,
81 const label b,
82 const label c,
83 const label region
84)
85:
86 triFace(a, b, c),
87 index_(region)
88{}
89
90
92:
93 triFace(),
94 index_(0)
95{
96 assignList(list);
97}
98
99
100inline 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
141{
142 if (is.format() == IOstream::ASCII)
143 {
144 is.readBegin("labelledTri");
145
146 is >> static_cast<triFace&>(t) >> t.index();
147
148 is.readEnd("labelledTri");
149 }
150 else
151 {
152 Detail::readContiguous<labelledTri>
153 (
154 is,
155 reinterpret_cast<char*>(&t),
156 sizeof(labelledTri)
157 );
158 }
159
161 return is;
162}
163
164
166{
167 if (os.format() == IOstream::ASCII)
168 {
170 << static_cast<const triFace&>(t) << token::SPACE << t.index()
172 }
173 else
174 {
175 os.write
176 (
177 reinterpret_cast<const char*>(&t),
178 sizeof(labelledTri)
179 );
180 }
181
183 return os;
184}
185
186
187// ************************************************************************* //
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
A 1D vector of objects of type <T> with a fixed length <N>.
Definition: FixedList.H:81
label & operator[](const label i)
Return element of FixedList.
Definition: FixedListI.H:412
streamFormat format() const noexcept
Get the current stream format.
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:58
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
bool readEnd(const char *funcName)
End read of data chunk, ends with ')'.
Definition: Istream.C:129
bool readBegin(const char *funcName)
Begin read of data chunk, starts with '('.
Definition: Istream.C:111
virtual Ostream & write(const char c)
Write character.
Definition: OBJstream.C:78
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
A triFace with additional (region) index.
Definition: labelledTri.H:60
labelledTri()
Default construct, with invalid point labels and region (-1).
Definition: labelledTriI.H:60
label index() const noexcept
Return the index (eg, the region)
Definition: labelledTri.H:129
@ BEGIN_LIST
Begin list [isseparator].
Definition: token.H:155
@ END_LIST
End list [isseparator].
Definition: token.H:156
@ SPACE
Space [isspace].
Definition: token.H:125
A triangular face using a FixedList of labels corresponding to mesh vertices.
Definition: triFace.H:72
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
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:83
Istream & operator>>(Istream &, directionInfo &)
errorManip< error > abort(error &err)
Definition: errorManip.H:144
error FatalError
volScalarField & b
Definition: createFields.H:27