Debian Codegraph @

include/deal.II/grid/tria_objects_orientations.h

raw
1 // ------------------------------------------------------------------------
2 //
3 // SPDX-License-Identifier: LGPL-2.1-or-later
4 // Copyright (C) 2023 - 2025 by the deal.II authors
5 //
6 // This file is part of the deal.II library.
7 //
8 // Part of the source code is dual licensed under Apache-2.0 WITH
9 // LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10 // governing the source code and code contributions can be found in
11 // LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12 //
13 // ------------------------------------------------------------------------
14
15 #ifndef dealii_tria_objects_orientations_h
16 #define dealii_tria_objects_orientations_h
17
18 #include <deal.II/base/config.h>
19
20 #include <deal.II/base/exceptions.h>
21 #include <deal.II/base/memory_consumption.h>
22 #include <deal.II/base/utilities.h>
23
24 #include <deal.II/grid/reference_cell.h>
25
26 #include <vector>
27
28 DEAL_II_NAMESPACE_OPEN
29
30 namespace internal
31 {
32 namespace TriangulationImplementation
33 {
34 /**
35 * Class storing orientation information for various objects in a
36 * Triangulation.
37 *
38 * @ingroup reordering
39 */
40 class TriaObjectsOrientations
41 {
42 public:
43 /**
44 * Constructor.
45 */
46 TriaObjectsOrientations();
47
48 /**
49 * Constructor. Sets up objects in the default orientation (orientation
50 * = `true`).
51 */
52 TriaObjectsOrientations(const unsigned int n_objects);
53
54 /**
55 * Return number of geometric objects stored by this class.
56 */
57 unsigned int
58 n_objects() const;
59
60 /**
61 * Reset the object to a default state.
62 */
63 void
64 reinit(const unsigned int n_objects);
65
66 /**
67 * Change the number of stored objects. New objects are constructed in
68 * the default orientation (true, false, false).
69 */
70 void
71 resize(const unsigned int n_objects);
72
73 /**
74 * Return the size of objects of this kind.
75 */
76 std::size_t
77 memory_consumption() const;
78
79 /**
80 * Get the combined orientation of the object, as described in the class
81 * documentation.
82 */
83 types::geometric_orientation
84 get_combined_orientation(const unsigned int object) const;
85
86 /**
87 * Get the orientation bit of the object.
88 */
89 bool
90 get_orientation(const unsigned int object) const;
91
92 /**
93 * Get the rotation bit of the object.
94 */
95 bool
96 get_rotation(const unsigned int object) const;
97
98 /**
99 * Get the flip bit of the object.
100 */
101 bool
102 get_flip(const unsigned int object) const;
103
104 /**
105 * Set the combined orientation of the object, as described in the class
106 * documentation.
107 */
108 void
109 set_combined_orientation(const unsigned int object,
110 const types::geometric_orientation value);
111
112 /**
113 * Read or write the data of this object to or from a stream for the
114 * purpose of serialization using the [BOOST serialization
115 * library](https://www.boost.org/doc/libs/1_74_0/libs/serialization/doc/index.html).
116 */
117 template <class Archive>
118 void
119 serialize(Archive &ar, const unsigned int version);
120
121 private:
122 /**
123 * Number of objects.
124 */
125 unsigned int n_stored_objects;
126
127 /**
128 * Orientations.
129 */
130 std::vector<types::geometric_orientation> object_orientations;
131 };
132
133 //----------------------------------------------------------------------//
134
135 inline TriaObjectsOrientations::TriaObjectsOrientations()
136 {
137 reinit(0);
138 }
139
140
141
142 inline TriaObjectsOrientations::TriaObjectsOrientations(
143 const unsigned int n_objects)
144 {
145 reinit(n_objects);
146 }
147
148
149
150 inline void
151 TriaObjectsOrientations::reinit(const unsigned int n_objects)
152 {
153 n_stored_objects = n_objects;
154 object_orientations.assign(n_objects,
155 numbers::default_geometric_orientation);
156 }
157
158
159
160 inline void
161 TriaObjectsOrientations::resize(const unsigned int n_objects)
162 {
163 object_orientations.resize(n_objects,
164 numbers::default_geometric_orientation);
165 n_stored_objects = n_objects;
166 }
167
168
169
170 inline std::size_t
171 TriaObjectsOrientations::memory_consumption() const
172 {
173 return MemoryConsumption::memory_consumption(n_stored_objects) +
174 MemoryConsumption::memory_consumption(object_orientations);
175 }
176
177
178
179 inline unsigned int
180 TriaObjectsOrientations::n_objects() const
181 {
182 return n_stored_objects;
183 }
184
185
186
187 inline types::geometric_orientation
188 TriaObjectsOrientations::get_combined_orientation(
189 const unsigned int object) const
190 {
191 AssertIndexRange(object, n_stored_objects);
192 return object_orientations[object];
193 }
194
195
196
197 inline bool
198 TriaObjectsOrientations::get_orientation(const unsigned int object) const
199 {
200 AssertIndexRange(object, n_stored_objects);
201 return !Utilities::get_bit(object_orientations[object], 0);
202 }
203
204
205
206 inline bool
207 TriaObjectsOrientations::get_rotation(const unsigned int object) const
208 {
209 AssertIndexRange(object, n_stored_objects);
210 return Utilities::get_bit(object_orientations[object], 1);
211 }
212
213
214
215 inline bool
216 TriaObjectsOrientations::get_flip(const unsigned int object) const
217 {
218 AssertIndexRange(object, n_stored_objects);
219 return Utilities::get_bit(object_orientations[object], 2);
220 }
221
222
223
224 inline void
225 TriaObjectsOrientations::set_combined_orientation(
226 const unsigned int object,
227 const types::geometric_orientation value)
228 {
229 AssertIndexRange(object, n_stored_objects);
230 object_orientations[object] = value;
231 }
232
233
234
235 template <class Archive>
236 void
237 TriaObjectsOrientations::serialize(Archive &ar, const unsigned int)
238 {
239 ar &n_stored_objects &object_orientations;
240 }
241 } // namespace TriangulationImplementation
242 } // namespace internal
243
244 DEAL_II_NAMESPACE_CLOSE
245
246 #endif