9#include <kernel/backend.hpp>
10#include <kernel/voxel_assembly/voxel_assembly_common.hpp>
11#include <kernel/voxel_assembly/helper/cell_to_dof_helper.hpp>
12#include <kernel/util/tiny_algebra.hpp>
13#include <kernel/adjacency/coloring_data_handler.hpp>
14#include <kernel/util/time_stamp.hpp>
15#include <kernel/util/stop_watch.hpp>
18#include <kernel/util/cuda_util.hpp>
25 namespace VoxelAssembly
40 template<
typename Space_,
typename DT_,
typename IT_>
44 typedef Space_ SpaceType;
46 typedef IT_ IndexType;
48 static constexpr int dim = SpaceType::world_dim;
67 double time_off_load_mesh, time_off_load_color;
68 double time_init_mesh, time_init_color;
78 template<
typename ITX_>
79 bool _contains_common_element(
const ITX_* a,
const ITX_* ae,
const ITX_* b,
const ITX_* be)
const
81 std::vector<ITX_> intersection;
83 std::set<ITX_> aa { a, ae };
84 std::set<ITX_> bb { b, be };
86 std::set_intersection(aa.begin(), aa.end(),
88 std::inserter(intersection, intersection.end()));
90 return !intersection.empty();
93 bool _test_coloring()
const
98 const auto& _coloring_map_offsets =
coloring_data.get_color_offsets();
99 const auto& _coloring_map_sizes =
coloring_data.get_color_sizes();
100 for(std::size_t i = 0; i < _coloring_map_sizes.size(); ++i)
102 for(std::size_t l = 0; l < _coloring_map_sizes.at(i); ++l)
105 int cell_a = coloring_view[_coloring_map_offsets[i] + l];
106 const IndexType* a_b = &cell_to_dof_view[std::size_t(cell_a*SpaceType::DofMappingType::dof_count)];
107 const IndexType* a_e = a_b + SpaceType::DofMappingType::dof_count;
108 for(std::size_t j = l+1; j < _coloring_map_sizes[i]; ++j)
111 int cell_b = coloring_view[_coloring_map_offsets[i] + j];
112 const IndexType* b_b = &cell_to_dof_view[std::size_t(cell_b*SpaceType::DofMappingType::dof_count)];
113 const IndexType* b_e = b_b + SpaceType::DofMappingType::dof_count;
115 if(_contains_common_element(a_b, a_e, b_b, b_e))
117 std::cout <<
"Cell 1: ";
118 for(
int r = 0; r < SpaceType::DofMappingType::dof_count; ++r)
120 std::cout << *(a_b + r) <<
" ";
122 std::cout <<
"\nCell 2: ";
123 for(
int r = 0; r < SpaceType::DofMappingType::dof_count; ++r)
125 std::cout << *(b_b + r) <<
" ";
133 for(std::size_t j = i+1; j < _coloring_map_sizes.size(); ++j)
140 const int* cvi = &coloring_view.get_r()[_coloring_map_offsets[i]];
141 const int* cvj = &coloring_view.get_r()[_coloring_map_offsets[j]];
142 if(_contains_common_element(
143 cvi, cvi + _coloring_map_sizes.at(i),
144 cvj, cvj + _coloring_map_sizes.at(j)))
146 std::cout <<
"Colors contain common element!\n";
147 XABORTM(
"I think you have misunderstood colors.");
156 void _fill_color(
const std::vector<int>& coloring,
int hint)
164 time_init_color = stamp2.elapsed(stamp1);
167 void _fill_color(
const Adjacency::Coloring& coloring,
int hint)
175 time_init_color = stamp2.elapsed(stamp1);
179 explicit LagrangeDataHandler() =
default;
181 template<
typename ColoringType_>
182 explicit LagrangeDataHandler(
const SpaceType& space,
const ColoringType_& coloring,
int hint = -1) :
188 time_off_load_mesh(0.),
189 time_off_load_color(0.),
194 if constexpr(std::is_same<ColoringType_, Adjacency::Coloring>::value)
196 ASSERTM(space.get_mesh().get_num_entities(dim) == coloring.get_num_nodes(),
"Coloring and space do not fit!");
200 ASSERTM(space.get_mesh().get_num_entities(dim) == coloring.size(),
"Coloring and space do not fit!");
202 _nodes_size = space.get_mesh().get_vertex_set().get_num_vertices();
205 const auto* vertex_begin = (
const typename SpaceType::MeshType::VertexSetType::CoordType*)space.get_mesh().get_vertex_set().begin();
208 [](
const auto& a) ->DataType {return DataType(a);});
211 _cell_to_dof_size = space.get_mesh().get_num_entities(dim) * SpaceType::DofMappingType::dof_count;
219 VoxelAssembly::fill_sorter(ctdsv.get_w(), ctdv.get_r(), space);
222 time_init_mesh = stamp2.elapsed(stamp1);
235 _fill_color(coloring, hint);
239 LagrangeDataHandler(
const LagrangeDataHandler&) =
delete;
241 LagrangeDataHandler& operator=(
const LagrangeDataHandler&) =
delete;
243 LagrangeDataHandler(LagrangeDataHandler&& other) noexcept :
250 time_off_load_mesh(
other.time_off_load_mesh),
251 time_off_load_color(
other.time_off_load_color),
252 time_init_mesh(
other.time_init_mesh),
253 time_init_color(
other.time_init_color)
257 LagrangeDataHandler& operator=(LagrangeDataHandler&& other)
noexcept
261 time_off_load_mesh =
other.time_off_load_mesh;
262 time_off_load_color =
other.time_off_load_color;
263 time_init_mesh =
other.time_init_mesh;
264 time_init_color =
other.time_init_color;
274 ~LagrangeDataHandler() =
default;
#define XABORTM(msg)
Abortion macro definition with custom message.
#define ASSERTM(expr, msg)
Debug-Assertion macro definition with custom message.
Datahandler for inverse coloring data.
void fill_color(const std::vector< int > &coloring, int hint=-1)
Fill in the coloring array.
View view(Location mem_loc, Access access)
Maps a raw view to a memory block.
Data handler for Lagrange based FE spaces.
Index _cell_to_dof_size
Size of cell to dof array.
Memory::Arbiter _cell_to_dof_sorter
Array mapping each _cell_to_dof entry to it locally sorted position.
Index _nodes_size
Size of node array.
Adjacency::ColoringDataHandler coloring_data
Datahandler for the coloring data.
Memory::Arbiter _cell_to_dof
Array mapping each cell index to ALL its local dofs in correct numbering.
Memory::Arbiter _nodes
Array of node coordinates.
@ other
generic/other permutation strategy
@ write
write-only access (see attention note above)
void fill_cell_to_dof(IT_ *ctd, const Space_ &space, IT_ offset=0)
Computes a sequentialized dof mapping for the given space.
String stringify(const T_ &item)
Converts an item into a String.
std::uint64_t Index
Index data type.
A data field for all necessary values that define the dof mapping for assembly.