FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
data_handler.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
9#include <kernel/backend.hpp>
10#include <kernel/util/memory_pool.hpp>
11#include <kernel/voxel_assembly/voxel_assembly_common.hpp>
12#include <kernel/voxel_assembly/helper/cell_to_dof_helper.hpp>
13#include <kernel/util/tiny_algebra.hpp>
14#include <kernel/adjacency/coloring.hpp>
15#include <kernel/util/time_stamp.hpp>
16#include <kernel/util/stop_watch.hpp>
17
18#ifdef FEAT_HAVE_CUDA
19#include <kernel/util/cuda_util.hpp>
20#endif
21
22#include <vector>
23
24namespace FEAT
25{
26 namespace VoxelAssembly
27 {
28 //Warning: for now only works with Q2standard space... we should probably use this class as specialzation for lagrange based spaces...
41 template<typename Space_, typename DT_, typename IT_>
43 {
44 public:
45 typedef Space_ SpaceType;
46 typedef DT_ DataType;
47 typedef IT_ IndexType;
48
49 static constexpr int dim = SpaceType::world_dim;
50 protected:
52 IndexType* _cell_to_dof;
57
62
65 public:
66 double time_off_load_mesh, time_off_load_color;
67 double time_init_mesh, time_init_color;
68
69 public:
70 inline AssemblyMappingData<DataType, IndexType> get_assembly_field() const
71 {
73 (void*)_nodes, _nodes_size};
74 }
75
76 Index get_num_colors() const
77 {
79 }
80
81 int* get_color_map(Index k)
82 {
84 }
85
86 const int* get_color_map(Index k) const
87 {
89 }
90
91 std::vector<int*>& get_coloring_maps()
92 {
94 }
95
96 const std::vector<int*>& get_coloring_maps() const
97 {
99 }
100
101 Index get_color_map_size(Index k) const
102 {
103 return coloring_data.get_color_size(k);
104 }
105
106 std::vector<Index>& get_color_map_sizes()
107 {
108 return coloring_data.get_color_sizes();
109 }
110
111 const std::vector<Index>& get_color_map_sizes() const
112 {
113 return coloring_data.get_color_sizes();
114 }
115
116 Index get_max_color_size() const
117 {
119 }
120
121 protected:
122 //Container has to be sortable and a and b have to be sorted beforhand....
123 template<typename ITX_>
124 bool _contains_common_element(const ITX_* a, const ITX_* ae, const ITX_* b, const ITX_* be) const
125 {
126 std::vector<ITX_> intersection;
127
128 std::set<ITX_> aa { a, ae };
129 std::set<ITX_> bb { b, be };
130
131 std::set_intersection(aa.begin(), aa.end(),
132 bb.begin(), bb.end(),
133 std::inserter(intersection, intersection.end()));
134
135 return !intersection.empty();
136 }
137
138 bool _test_coloring() const
139 {
140 const auto& _coloring_maps = coloring_data.get_coloring_maps();
141 const auto& _coloring_map_sizes = coloring_data.get_color_sizes();
142 for(int i = 0; i < int(_coloring_maps.size()); ++i)
143 {
144 for(int l = 0; l < int(_coloring_map_sizes.at(std::size_t(i))); ++l)
145 {
146 int cell_a = _coloring_maps[std::size_t(i)][std::size_t(l)];
147 const IndexType* a_b = &_cell_to_dof[std::size_t(cell_a*SpaceType::DofMappingType::dof_count)];
148 const IndexType* a_e = &_cell_to_dof[std::size_t(cell_a*SpaceType::DofMappingType::dof_count)] + SpaceType::DofMappingType::dof_count;
149 for(int j = l+1; j < int(_coloring_map_sizes[std::size_t(i)]); ++j)
150 {
151 int cell_b = _coloring_maps[std::size_t(i)][std::size_t(j)];
152 const IndexType* b_b = &_cell_to_dof[std::size_t(cell_b*SpaceType::DofMappingType::dof_count)];
153 const IndexType* b_e = &_cell_to_dof[std::size_t(cell_b*SpaceType::DofMappingType::dof_count)] + SpaceType::DofMappingType::dof_count;
154
155 if(_contains_common_element(a_b, a_e, b_b, b_e))
156 {
157 std::cout << "Cell 1: ";
158 for(int r = 0; r < SpaceType::DofMappingType::dof_count; ++r)
159 {
160 std::cout << *(a_b + r) << " ";
161 }
162 std::cout << "\nCell 2: ";
163 for(int r = 0; r < SpaceType::DofMappingType::dof_count; ++r)
164 {
165 std::cout << *(b_b + r) << " ";
166 }
167 std::cout << "\n";
168 XABORTM("Intersection in color " + stringify(i) + " between cells " + stringify(cell_a) + " " + stringify(cell_b));
169 }
170 }
171 }
172
173 for(int j = i+1; j < int(_coloring_maps.size()); ++j)
174 {
175 if(_contains_common_element(_coloring_maps.at(std::size_t(i)), _coloring_maps.at(std::size_t(i))+_coloring_map_sizes.at(std::size_t(i)), _coloring_maps.at(std::size_t(j)), _coloring_maps.at(std::size_t(j))+_coloring_map_sizes.at(std::size_t(j))))
176 {
177 std::cout << "Colors contain common element!\n";
178 XABORTM("I think you have misunderstood colors.");
179 }
180 }
181 }
182
183 return true;
184
185 }
186
187 void _fill_color(const std::vector<int>& coloring, int hint)
188 {
189 TimeStamp stamp1;
190 coloring_data.fill_color(coloring, hint);
191 #ifdef DEBUG
192 _test_coloring();
193 #endif
194 TimeStamp stamp2;
195 time_init_color = stamp2.elapsed(stamp1);
196 }
197
198 void _fill_color(const Adjacency::Coloring& coloring, int hint)
199 {
200 TimeStamp stamp1;
201 coloring_data.fill_color(coloring, hint);
202 #ifdef DEBUG
203 _test_coloring();
204 #endif
205 TimeStamp stamp2;
206 time_init_color = stamp2.elapsed(stamp1);
207 }
208
209 public:
210 explicit LagrangeDataHandler() = default;
211
212 template<typename ColoringType_>
213 explicit LagrangeDataHandler(const SpaceType& space, const ColoringType_& coloring, int hint = -1) :
214 _cell_to_dof(nullptr),
215 _cell_to_dof_sorter(nullptr),
217 _nodes(nullptr),
218 _nodes_size(Index(0)),
219 time_off_load_mesh(0.),
220 time_off_load_color(0.),
221 time_init_mesh(0.),
222 time_init_color(0.)
223 {
224 TimeStamp stamp1;
225 if constexpr(std::is_same<ColoringType_, Adjacency::Coloring>::value)
226 {
227 ASSERTM(space.get_mesh().get_num_entities(dim) == coloring.get_num_nodes(), "Coloring and space do not fit!");
228 }
229 else
230 {
231 ASSERTM(space.get_mesh().get_num_entities(dim) == coloring.size(), "Coloring and space do not fit!");
232 }
233 _nodes_size = space.get_mesh().get_vertex_set().get_num_vertices();
234 _nodes = MemoryPool::allocate_memory<Tiny::Vector<DataType, dim>>(_nodes_size);
235 // copy the internal nodes array
236 const auto* vertex_begin = (const typename SpaceType::MeshType::VertexSetType::CoordType*)space.get_mesh().get_vertex_set().begin();
237 std::transform(vertex_begin, vertex_begin + _nodes_size*Index(dim), (DataType*)_nodes, [](const auto& a) ->DataType {return DataType(a);});
238
239 // define our _cell_to_dof
240 _cell_to_dof_size = space.get_mesh().get_num_entities(dim) * SpaceType::DofMappingType::dof_count;
241 _cell_to_dof = MemoryPool::allocate_memory<IndexType>(_cell_to_dof_size);
242 _cell_to_dof_sorter = MemoryPool::allocate_memory<IndexType>(_cell_to_dof_size);
243 // for this iterate through our target_sets and parse them in
245 VoxelAssembly::fill_sorter(_cell_to_dof_sorter, _cell_to_dof, space);
246 TimeStamp stamp2;
247 time_init_mesh = stamp2.elapsed(stamp1);
248
249 // for(int cell = 0; cell < space.get_mesh().get_num_elements(); ++cell)
250 // {
251 // std::cout << "For cell " << cell << ": \n";
252 // IndexType* ctd = _cell_to_dof.data() + cell * SpaceType::DofMappingType::dof_count;
253 // for(int i = 0; i < SpaceType::DofMappingType::dof_count; ++i)
254 // {
255 // std::cout << ctd[i] << " ";
256 // }
257 // std::cout << "\n";
258 // }
259
260 _fill_color(coloring, hint);
261
262 }
263
264 LagrangeDataHandler(const LagrangeDataHandler&) = delete;
265
266 LagrangeDataHandler& operator=(const LagrangeDataHandler&) = delete;
267
268 LagrangeDataHandler(LagrangeDataHandler&& other) noexcept :
269 _cell_to_dof(other._cell_to_dof),
270 _cell_to_dof_sorter(other._cell_to_dof_sorter),
271 _cell_to_dof_size(other._cell_to_dof_size),
272 _nodes(other._nodes),
273 _nodes_size(other._nodes_size),
274 coloring_data(std::move(other.coloring_data)),
275 time_off_load_mesh(other.time_off_load_mesh),
276 time_off_load_color(other.time_off_load_color),
277 time_init_mesh(other.time_init_mesh),
278 time_init_color(other.time_init_color)
279 {
283 }
284
285 LagrangeDataHandler& operator=(LagrangeDataHandler&& other) noexcept
286 {
287 if(this == &other)
288 return *this;
289 time_off_load_mesh = other.time_off_load_mesh;
290 time_off_load_color = other.time_off_load_color;
291 time_init_mesh = other.time_init_mesh;
292 time_init_color = other.time_init_color;
293 coloring_data = std::move(other.coloring_data);
297 _cell_to_dof = other._cell_to_dof;
298 _cell_to_dof_sorter = other._cell_to_dof_sorter;
299 _cell_to_dof_size = other._cell_to_dof_size;
300 _nodes = other._nodes;
301 _nodes_size = other._nodes_size;
305 return *this;
306 }
307
308 ~LagrangeDataHandler()
309 {
313 }
314 }; //class GPUDataHandler
315 }
316}
#define XABORTM(msg)
Abortion macro definition with custom message.
Definition: assertion.hpp:192
#define ASSERTM(expr, msg)
Debug-Assertion macro definition with custom message.
Definition: assertion.hpp:230
FEAT Kernel base header.
Datahandler for inverse coloring data.
Definition: coloring.hpp:253
Index get_max_color_size() const
Get max size of all colors.
Definition: coloring.hpp:358
Index get_num_colors() const
Returns the number of colors.
Definition: coloring.hpp:313
int * get_color_map(Index k)
Get the k-th color map.
Definition: coloring.hpp:334
void fill_color(const std::vector< int > &coloring, int hint=-1)
Fill in the coloring array.
Definition: coloring.hpp:370
std::vector< int * > & get_coloring_maps()
Retrieve the color maps.
Definition: coloring.hpp:346
static void release_memory(void *address)
release memory or decrease reference counter
static void increase_memory(void *address)
increase memory counter
Tiny Vector class template.
Data handler for Lagrange based FE spaces.
Index _cell_to_dof_size
Size of cell to dof array.
Index _nodes_size
Size of node array.
Adjacency::ColoringDataHandler coloring_data
Datahanlder for the coloring data.
IndexType * _cell_to_dof
Array mapping each cell index to ALL its local dofs in correct numbering.
Tiny::Vector< DataType, dim > * _nodes
Array of node coordinates.
IndexType * _cell_to_dof_sorter
Array mapping each _cell_to_dof entry to it locally sorted position.
@ other
generic/other permutation strategy
void fill_cell_to_dof(IT_ *ctd, const Space_ &space, IT_ offset=0)
Computes a sequentialized dof mapping for the given space.
FEAT namespace.
Definition: adjactor.hpp:12
String stringify(const T_ &item)
Converts an item into a String.
Definition: string.hpp:944
std::uint64_t Index
Index data type.
A data field for all necessary values that define the dof mapping for assembly.