FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
subdivision_levels.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
7
8// includes, FEAT
10#include <kernel/geometry/index_set.hpp>
11#include <kernel/shape.hpp>
13
14// includes, system
15#include <functional>
16
17namespace FEAT::Geometry
18{
26 template<int size_>
28 {
29 static_assert(size_ > 0, "invalid number of indices");
30
32 static constexpr int size = size_;
33
35 std::array<std::uint64_t, size_> levels;
36
39 {
40 ASSERT(idx < size);
41 return levels[idx];
42 }
43
45 const Index& operator[](Index idx) const
46 {
47 ASSERT(idx < size);
48 return levels[idx];
49 }
50
57 {
59 for(int i = 0; i < size; i++)
60 {
61 result[i] = levels[i] > 0 ? levels[i] - 1 : 0;
62 }
63 return result;
64 }
65 };
66
75 {
77 friend std::ostream& operator<<(std::ostream& /*unused*/, const SubdivisionLevels& /*unused*/);
78
79 public:
85 explicit SubdivisionLevels(Index num_vertices) : _levels(num_vertices)
86 {
87 }
88
95 SubdivisionLevels(Index num_vertices, std::uint64_t default_level) : _levels(num_vertices, default_level)
96 {
97 }
98
101 _levels(std::forward<std::vector<std::uint64_t>>(other._levels))
102 {
103 }
104
107 {
108 // avoid self-move
109 if(this == &other)
110 {
111 return *this;
112 }
113
114 _levels = std::forward<std::vector<std::uint64_t>>(other._levels);
115
116 return *this;
117 }
118
123
126
128 std::uint64_t& operator[](Index idx)
129 {
130 ASSERT(idx < _levels.size());
131 return _levels[idx];
132 }
133
135 const std::uint64_t& operator[](Index idx) const
136 {
137 ASSERT(idx < _levels.size());
138 return _levels[idx];
139 }
140
144 std::uint64_t maximum_level()
145 {
146 std::uint64_t result = 0;
147 for(auto level : _levels)
148 {
149 result = std::max(result, level);
150 }
151 return result;
152 }
153
154 std::size_t size() const
155 {
156 return _levels.size();
157 }
158
172 template<typename MeshType>
173 void set_per_element(const MeshType& mesh, std::function<std::uint64_t(Index)> f)
174 {
175 constexpr int cell_dim = MeshType::shape_dim;
176
177 Index num_verts = mesh.get_num_entities(0);
178 Index num_cells = mesh.get_num_entities(cell_dim);
179
180 // Initialize levels to correct size
181 _levels = std::vector<std::uint64_t>(num_verts, 0);
182
183 for(Index cell(0); cell < num_cells; ++cell)
184 {
185 std::uint64_t cell_level = f(cell);
186 set_level_for_element(mesh, cell, cell_level);
187 }
188 }
189
199 template<typename MeshType>
200 void set_level_for_element(const MeshType& mesh, Index element, std::uint64_t element_level)
201 {
202 constexpr int cell_dim = MeshType::shape_dim;
204
205 auto& v_at_c = mesh.template get_index_set<cell_dim, 0>();
206 for(Index vert(0); vert < verts_per_cell; ++vert)
207 {
208 Index vert_idx = v_at_c(element, vert);
209 _levels[vert_idx] = std::max(_levels[vert_idx], element_level);
210 }
211 }
212
217 {
218 Index len = std::max(_levels.size(), other._levels.size());
219 for(Index i(0); i < len; ++i)
220 {
221 _levels[i] += other._levels[i];
222 }
223 }
224
230 template<int n>
232 {
233 SubdivisionLevelTuple<n> result = {};
234 for(int i = 0; i < indices.num_indices; i++)
235 {
236 result[i] = _levels[indices[i]];
237 }
238 return result;
239 }
240
241 private:
243 std::vector<std::uint64_t> _levels;
244 };
245
247 inline std::ostream& operator<<(std::ostream& os, const SubdivisionLevels& sdls)
248 {
249 os << "SDLs {" << "\n";
250 for(auto sdl : sdls._levels)
251 {
252 os << "\t" << sdl << ",\n";
253 }
254 os << "}\n";
255 return os;
256 }
257} // namespace FEAT::Geometry
#define ASSERT(expr)
Debug-Assertion macro definition.
Definition: assertion.hpp:229
FEAT Kernel base header.
Subdivision level markings for meshes.
SubdivisionLevels(Index num_vertices, std::uint64_t default_level)
Constructor.
std::vector< std::uint64_t > _levels
Level markings.
const std::uint64_t & operator[](Index idx) const
access operator
void set_level_for_element(const MeshType &mesh, Index element, std::uint64_t element_level)
Set subdivision level for a mesh element.
SubdivisionLevels(const SubdivisionLevels &other)=delete
deleted copy-constructor
SubdivisionLevels & operator=(const SubdivisionLevels &other)=delete
deleted copy-assign operator
SubdivisionLevels & operator=(SubdivisionLevels &&other) noexcept
move-assign operator
~SubdivisionLevels()=default
destructor
SubdivisionLevels(Index num_vertices)
Constructor.
SubdivisionLevelTuple< n > get_levels(const IndexTuple< n > &indices) const
Retrieve SubdivisionLevelTuple.
void merge(const SubdivisionLevels &other)
Adds up two SubdivisionLevels.
friend std::ostream & operator<<(std::ostream &, const SubdivisionLevels &)
Debug output operator.
std::uint64_t & operator[](Index idx)
access operator
SubdivisionLevels(SubdivisionLevels &&other) noexcept
move-constructor
void set_per_element(const MeshType &mesh, std::function< std::uint64_t(Index)> f)
Sets subdivision levels for each cell of the given mesh.
std::uint64_t maximum_level()
Returns the maximum refinement level assigned to any vertex.
Geometry namespace.
@ other
generic/other permutation strategy
std::uint64_t Index
Index data type.
Index Tuple class template.
Definition: index_set.hpp:35
static constexpr int num_indices
number of indices per tuple
Definition: index_set.hpp:39
Tuple-type for SubdivisionLevels.
const Index & operator[](Index idx) const
access operator
SubdivisionLevelTuple< size > decrement() const
Decrement levels.
static constexpr int size
Tuple size.
std::array< std::uint64_t, size_ > levels
Tuple values.
Index & operator[](Index idx)
access operator
Face traits tag struct template.
Definition: shape.hpp:106