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> 
   19#include <kernel/util/cuda_util.hpp> 
   26  namespace VoxelAssembly
 
   41    template<
typename Space_, 
typename DT_, 
typename IT_>
 
   45      typedef Space_ SpaceType;
 
   47      typedef IT_ IndexType;
 
   49      static constexpr int dim = SpaceType::world_dim;
 
   66      double time_off_load_mesh, time_off_load_color;
 
   67      double time_init_mesh, time_init_color;
 
   76      Index get_num_colors()
 const 
   81      int* get_color_map(
Index k)
 
   86      const int* get_color_map(
Index k)
 const 
   91      std::vector<int*>& get_coloring_maps()
 
   96      const std::vector<int*>& get_coloring_maps()
 const 
  106      std::vector<Index>& get_color_map_sizes()
 
  111      const std::vector<Index>& get_color_map_sizes()
 const 
  116      Index get_max_color_size()
 const 
  123      template<
typename ITX_>
 
  124      bool _contains_common_element(
const ITX_* a, 
const ITX_* ae, 
const ITX_* b, 
const ITX_* be)
 const 
  126          std::vector<ITX_> intersection;
 
  128          std::set<ITX_> aa { a, ae };
 
  129          std::set<ITX_> bb { b, be };
 
  131          std::set_intersection(aa.begin(), aa.end(),
 
  132                                bb.begin(), bb.end(),
 
  133                                std::inserter(intersection, intersection.end()));
 
  135          return !intersection.empty();
 
  138      bool _test_coloring()
 const 
  141        const auto& _coloring_map_sizes = 
coloring_data.get_color_sizes();
 
  142        for(
int i = 0; i < int(_coloring_maps.size()); ++i)
 
  144          for(
int l = 0; l < int(_coloring_map_sizes.at(std::size_t(i))); ++l)
 
  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)
 
  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;
 
  155              if(_contains_common_element(a_b, a_e, b_b, b_e))
 
  157                std::cout << 
"Cell 1: ";
 
  158                for(
int r = 0; r < SpaceType::DofMappingType::dof_count; ++r)
 
  160                  std::cout << *(a_b + r) << 
" ";
 
  162                std::cout << 
"\nCell 2: ";
 
  163                for(
int r = 0; r < SpaceType::DofMappingType::dof_count; ++r)
 
  165                  std::cout << *(b_b + r) << 
" ";
 
  173          for(
int j = i+1; j < int(_coloring_maps.size()); ++j)
 
  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))))
 
  177              std::cout << 
"Colors contain common element!\n";
 
  178              XABORTM(
"I think you have misunderstood colors.");
 
  187      void _fill_color(
const std::vector<int>& coloring, 
int hint)
 
  195        time_init_color = stamp2.elapsed(stamp1);
 
  198      void _fill_color(
const Adjacency::Coloring& coloring, 
int hint)
 
  206        time_init_color = stamp2.elapsed(stamp1);
 
  210      explicit LagrangeDataHandler() = 
default;
 
  212      template<
typename ColoringType_>
 
  213      explicit LagrangeDataHandler(
const SpaceType& space, 
const ColoringType_& coloring, 
int hint = -1) :
 
  219      time_off_load_mesh(0.),
 
  220      time_off_load_color(0.),
 
  225        if constexpr(std::is_same<ColoringType_, Adjacency::Coloring>::value)
 
  227          ASSERTM(space.get_mesh().get_num_entities(dim) == coloring.get_num_nodes(), 
"Coloring and space do not fit!");
 
  231          ASSERTM(space.get_mesh().get_num_entities(dim) == coloring.size(), 
"Coloring and space do not fit!");
 
  233        _nodes_size = space.get_mesh().get_vertex_set().get_num_vertices();
 
  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);});
 
  240        _cell_to_dof_size = space.get_mesh().get_num_entities(dim) * SpaceType::DofMappingType::dof_count;
 
  247        time_init_mesh = stamp2.elapsed(stamp1);
 
  260        _fill_color(coloring, hint);
 
  264      LagrangeDataHandler(
const LagrangeDataHandler&) = 
delete;
 
  266      LagrangeDataHandler& operator=(
const LagrangeDataHandler&) = 
delete;
 
  268      LagrangeDataHandler(LagrangeDataHandler&& other) noexcept :
 
  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)
 
  285      LagrangeDataHandler& operator=(LagrangeDataHandler&& other) 
noexcept 
  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;
 
  308      ~LagrangeDataHandler()
 
#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.
Index get_max_color_size() const
Get max size of all colors.
Index get_num_colors() const
Returns the number of colors.
int * get_color_map(Index k)
Get the k-th color map.
void fill_color(const std::vector< int > &coloring, int hint=-1)
Fill in the coloring array.
std::vector< int * > & get_coloring_maps()
Retrieve the color maps.
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.
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.