FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
voxel_coloring.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/adjacency/graph.hpp>
10
11#include <vector>
12namespace FEAT
13{
14 namespace VoxelAssembly
15 {
16 template<typename Shape_>
18 {
19 static constexpr int dim = Shape_::dimension;
20
21 static std::vector<int> create_coloring(int lvl)
22 {
23 int num_per_row = 1 << lvl;
24 // std::cout << num_per_row << "\n";
25 std::vector<int> vec;
26 if constexpr(dim == 3)
27 {
28 vec.resize(std::size_t(num_per_row * num_per_row * num_per_row));
29 for(int j = 0; j < num_per_row * num_per_row * num_per_row; ++j)
30 {
31 vec[std::size_t(j)] = j % 8;
32
33 // std::cout << "\n";
34 }
35 }
36 else
37 {
38 vec.resize(std::size_t(num_per_row * num_per_row));
39 for(int j = 0; j < num_per_row * num_per_row; ++j)
40 {
41 vec[std::size_t(j)] = j % 4;
42
43 // std::cout << "\n";
44 }
45 }
46
47 return vec;
48 }
49
50 static std::vector<int> naive_coloring(int lvl)
51 {
52 int num_per_row = 1 << lvl;
53 std::vector<int> vec(std::size_t(num_per_row * num_per_row));
54 for(int j = 0; j < num_per_row * num_per_row; ++j)
55 {
56 vec[std::size_t(j)] = j;
57 // std::cout << "\n";
58 }
59 return vec;
60 }
61 };
62
63
64 template<typename Mesh_>
65 bool test_coloring(const Mesh_& mesh, const std::vector<int>& coloring)
66 {
67 auto& cell_to_vert = mesh.template get_index_set<Mesh_::world_dim, 0>();
68 Adjacency::Graph vert_to_cell(Adjacency::RenderType::transpose, cell_to_vert);
69 Adjacency::Graph cell_neighbours(Adjacency::RenderType::injectify, cell_to_vert, vert_to_cell);
70
71 for(Index i = 0; i < cell_neighbours.get_num_nodes_domain(); ++i)
72 {
73 for(auto ptr = cell_neighbours.image_begin(i); ptr != cell_neighbours.image_end(i); ++ptr)
74 {
75 if(*ptr != i)
76 {
77 if(coloring.at(*ptr) == coloring.at(i))
78 {
79 std::cout << "Same color for neighbour!";
80 return false;
81 }
82 }
83 }
84 }
85 return true;
86
87 }
88 }
89}
FEAT Kernel base header.
Adjacency Graph implementation.
Definition: graph.hpp:34
@ transpose
Render-Transpose mode.
@ injectify
Render-Injectified mode.
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.