8#include <kernel/geometry/refinement_types.hpp> 
    9#include <kernel/shape.hpp> 
   10#include <kernel/geometry/template_builder.hpp> 
   11#include <kernel/geometry/subdivision_levels.hpp> 
   12#include <kernel/geometry/intern/refinement_field.hpp> 
   18    template<
typename Templates_, 
typename MeshType_>
 
   19    static RefinementField<std::uint64_t>
 
   20    make_standard_refinement_field(
const MeshType_& mesh, Templates_& templates, 
const Geometry::SubdivisionLevels& sdls)
 
   22      using ShapeType = 
typename MeshType_::ShapeType;
 
   23      static const constexpr int dim = MeshType_::shape_dim;
 
   24      static const constexpr int num_vertices = Shape::FaceTraits<ShapeType, 0>::count;
 
   28      RefinementField<std::uint64_t> result(sdls.size());
 
   29      for(
Index i(0); i < sdls.size(); ++i)
 
   46      const auto& v_at_c = mesh.template get_index_set<dim, 0>();
 
   54      std::vector<bool> worklist(mesh.get_num_elements(), 
true);
 
   59        auto it = std::find(worklist.begin(), worklist.end(), 
true);
 
   62        if(it == worklist.end())
 
   67        Index cell = std::distance(worklist.begin(), it);
 
   69        RefinementFieldTuple<std::uint64_t, num_vertices> levels =
 
   70          result.get_tuple(v_at_c[cell]);
 
   72        StandardRefinementType<ShapeType> type(levels);
 
   77          while(!type.is_zero_refinement() && templates.template has_template<dim>(type))
 
   80            for(
Index i(0); i < num_vertices; i++)
 
   82              levels[i] = levels[i] > 0 ? levels[i] - 1 : 0;
 
   84            type = StandardRefinementType<ShapeType>(levels);
 
   87          if(type.is_zero_refinement())
 
   90            worklist[cell] = 
false;
 
   95          auto& adjustment = templates.template type_adjustment<dim>(type.to_number());
 
   96          for(
int i(0); i < num_vertices; i++)
 
   98            result[v_at_c[cell][i]] += adjustment[i];
 
   99            levels[i] += adjustment[i];
 
  101          type = StandardRefinementType<ShapeType>(levels);
 
  112          for(
Index idx = 0; idx < mesh.get_num_elements(); idx++)
 
  114            worklist[idx] = 
true;
 
  122    template<
typename Templates_, 
typename MeshType_>
 
  123    static RefinementField<IsolatedPointVertexMarking>
 
  124    make_isolated_point_refinement_field(
const MeshType_& mesh, Templates_& templates, 
const Geometry::SubdivisionLevels& sdls)
 
  126      using ShapeType = 
typename MeshType_::ShapeType;
 
  127      static const constexpr int dim = MeshType_::shape_dim;
 
  128      static const constexpr int num_vertices = Shape::FaceTraits<ShapeType, 0>::count;
 
  133      RefinementField<IsolatedPointVertexMarking> result(sdls.size());
 
  134      for(
Index i(0); i < sdls.size(); ++i)
 
  136        result[i] = IsolatedPointVertexMarking{sdls[i], sdls[i] > 0};
 
  151      const auto& v_at_c = mesh.template get_index_set<dim, 0>();
 
  159      std::vector<bool> worklist(mesh.get_num_elements(), 
true);
 
  162      auto determine_isolation = [&]()
 
  166        for(
Index cell = 0; cell < mesh.get_num_elements(); cell++)
 
  168          Index num_marked = 0;
 
  169          for(
int vertex(0); vertex < v_at_c.num_indices; vertex++)
 
  171            num_marked += result[v_at_c(cell, vertex)].level > 0 ? 1 : 0;
 
  176            for(
int vertex(0); vertex < v_at_c.num_indices; vertex++)
 
  178              result[v_at_c(cell, vertex)].is_isolated = 
false;
 
  189        determine_isolation();
 
  191        auto it = std::find(worklist.begin(), worklist.end(), 
true);
 
  194        if(it == worklist.end())
 
  199        Index cell = std::distance(worklist.begin(), it);
 
  201        RefinementFieldTuple<IsolatedPointVertexMarking, num_vertices> levels =
 
  202          result.get_tuple(v_at_c[cell]);
 
  204        IsolatedPointRefinementType<ShapeType> type(levels);
 
  209          while(!type.is_zero_refinement() && templates.template has_template<dim>(type))
 
  212            for(
Index i(0); i < num_vertices; i++)
 
  214              levels[i].level = levels[i].level > 0 ? levels[i].level - 1 : 0;
 
  216            type = IsolatedPointRefinementType<ShapeType>(levels);
 
  219          if(type.is_zero_refinement())
 
  222            worklist[cell] = 
false;
 
  238          auto& adjustment = templates.template type_adjustment<dim>(type.to_number());
 
  239          for(
int i(0); i < num_vertices; i++)
 
  241            result[v_at_c[cell][i]].level += adjustment[i];
 
  242            levels[i].level += adjustment[i];
 
  244          type = IsolatedPointRefinementType<ShapeType>(levels);
 
  248          for(
Index idx = 0; idx < mesh.get_num_elements(); idx++)
 
  250            worklist[idx] = 
true;
 
  265    template<
typename Shape_>
 
  267    spread_refinement_field(
 
  268        const EntityReference& ref,
 
  269        const Geometry::Intern::RefinementFieldTuple<std::uint64_t, Shape::FaceTraits<Shape_, 0>::count>& markings)
 
  276          std::uint64_t 
min = markings[0];
 
  277          for(
Index i(1); i < markings.size; ++i)
 
  279            min = std::min(min, markings[i]);
 
  281          return min > 0 ? 
min - 1 : 0;
 
  285          if constexpr (Shape_::dimension >= 2)
 
  287            using Mapping = Intern::FaceIndexMapping<Shape_, 1, 0>;
 
  289            int face = ref.entity;
 
  291            std::uint64_t 
min = markings[Mapping::map(face, 0)];
 
  292            for(
int i(1); i < 2; ++i)
 
  294              min = std::min(min, markings[Mapping::map(face, i)]);
 
  296            return min > 0 ? 
min - 1 : 0;
 
  302          if constexpr (Shape_::dimension >= 3)
 
  304            using Mapping = Intern::FaceIndexMapping<Shape_, 2, 0>;
 
  306            int face = ref.entity;
 
  308            std::uint64_t 
min = markings[Mapping::map(face, 0)];
 
  309            for(
int i(1); i < 4; ++i)
 
  311              min = std::min(min, markings[Mapping::map(face, i)]);
 
  313            return min > 0 ? 
min - 1 : 0;
 
  322    template<
typename Shape_>
 
  323    IsolatedPointVertexMarking
 
  324    spread_refinement_field(
 
  325        const EntityReference& ref,
 
  326        const Geometry::Intern::RefinementFieldTuple<IsolatedPointVertexMarking, Shape::FaceTraits<Shape_, 0>::count>& markings)
 
  331          markings[ref.index].level > 0 ? markings[ref.index].level - 1 : 0,
 
  332          markings[ref.index].is_isolated
 
  336          std::uint64_t 
min = markings[0].level;
 
  337          for(
Index i(1); i < markings.size; ++i)
 
  339            min = std::min(min, markings[i].level);
 
  341          return {
min > 0 ? 
min - 1 : 0, 
false};
 
  345          if constexpr (Shape_::dimension >= 2)
 
  347            using Mapping = Intern::FaceIndexMapping<Shape_, 1, 0>;
 
  349            int face = ref.entity;
 
  351            std::uint64_t 
min = markings[Mapping::map(face, 0)].level;
 
  352            for(
int i(1); i < 2; ++i)
 
  354              min = std::min(min, markings[Mapping::map(face, i)].level);
 
  356            return {
min > 0 ? 
min - 1 : 0, 
false};
 
  362          if constexpr (Shape_::dimension >= 3)
 
  364            using Mapping = Intern::FaceIndexMapping<Shape_, 2, 0>;
 
  366            int face = ref.entity;
 
  368            std::uint64_t 
min = markings[Mapping::map(face, 0)].level;
 
  369            for(
int i(1); i < 4; ++i)
 
  371              min = std::min(min, markings[Mapping::map(face, i)].level);
 
  373            return {
min > 0 ? 
min - 1 : 0, 
false};
 
  393  template<
typename RawData_>
 
  398    using MaxShape = 
typename RawData_::MaxShape;
 
  400    using VertexMarkerType = std::uint64_t;
 
  405    template<
typename Shape_>
 
  415    template<
typename Shape_>
 
  418      return RawData_::template is_shape_compatible<Shape_>();
 
  423      _templates().
stats();
 
  432    template<
int template_dim_, 
int child_dim_>
 
  435      return RawData_::template max_children<template_dim_, child_dim_>();
 
  446    template<
typename Mesh_>
 
  449      return Intern::make_standard_refinement_field(mesh, _templates, sdls);
 
  452    template<
typename Shape_>
 
  453    static VertexMarkerType spread_refinement_field(
 
  457      return Intern::spread_refinement_field<Shape_>(ref, levels);
 
  460    template<
typename Shape_>
 
  461    static const RefinementTemplate<Shape_>& get_template(StandardRefinementType<Shape_> type)
 
  463      return _templates.template get_template<Shape_::dimension>(type);
 
  466    template<
typename Shape_>
 
  467    static bool has_template(StandardRefinementType<Shape_> type)
 
  469      return _templates.template has_template<Shape_::dimension>(type);
 
  472    template<
typename Shape_, 
int dim_>
 
  473    static std::pair<Index, int> correct_for_orientation(StandardRefinementType<Shape_> type, 
int orientation, 
Index idx)
 
  475      return _templates.template correct_for_orientation<Shape_::dimension, dim_>(type, orientation, idx);
 
  491    template<
int template_dim_, 
int child_dim_>
 
  494      return _templates.template get_template<template_dim_>(type).template num_entities<child_dim_>();
 
  508  template<
typename RawData_>
 
  511    using MaxShape = 
typename RawData_::MaxShape;
 
  518    template<
typename Shape_>
 
  528    template<
typename Shape_>
 
  531      return RawData_::template is_shape_compatible<Shape_>();
 
  536      _templates().
stats();
 
  545    template<
int template_dim_, 
int child_dim_>
 
  548      return RawData_::template max_children<template_dim_, child_dim_>();
 
  559    template<
typename Mesh_>
 
  562      return Intern::make_isolated_point_refinement_field(mesh, _templates(), sdls);
 
  565    template<
typename Shape_>
 
  566    static VertexMarkerType spread_refinement_field(
 
  570      return Intern::spread_refinement_field<Shape_>(ref, levels);
 
  573    template<
typename Shape_>
 
  574    static const RefinementTemplate<Shape_>& get_template(IsolatedPointRefinementType<Shape_> type)
 
  576      return _templates().template get_template<Shape_::dimension>(type);
 
  579    template<
typename Shape_>
 
  580    static bool has_template(StandardRefinementType<Shape_> type)
 
  582      return _templates().template has_template<Shape_::dimension>(type);
 
  585    template<
typename Shape_, 
int dim_>
 
  586    static std::pair<Index, int> correct_for_orientation(IsolatedPointRefinementType<Shape_> type, 
int orientation, 
Index idx)
 
  588      return _templates().template correct_for_orientation<Shape_::dimension, dim_>(type, orientation, idx);
 
  604    template<
int template_dim_, 
int child_dim_>
 
  607      return _templates().template get_template<template_dim_>(type).template num_entities<child_dim_>();
 
  614      return _static_templates;
 
Schneiders template set for adaptive mesh refinement.
static Intern::RefinementField< IsolatedPointVertexMarking > make_refinement_field(const Mesh_ &mesh, Geometry::SubdivisionLevels &sdls)
Adjusts SubdivisionLevels to match TemplateSet requirements.
static constexpr bool is_shape_compatible()
Shape compatability test.
static constexpr int max_children()
Returns maximum number of children a template produces.
static Index num_children(IsolatedPointRefinementType< typename Shape::FaceTraits< MaxShape, template_dim_ >::ShapeType > type)
Returns number of children a specific template produces.
Schneiders template set for adaptive mesh refinement.
static constexpr bool is_shape_compatible()
Shape compatability test.
static Index num_children(StandardRefinementType< typename Shape::FaceTraits< MaxShape, template_dim_ >::ShapeType > type)
Returns number of children a specific template produces.
static Intern::RefinementField< std::uint64_t > make_refinement_field(const Mesh_ &mesh, Geometry::SubdivisionLevels &sdls)
Adjusts SubdivisionLevels to match TemplateSet requirements.
static constexpr int max_children()
Returns maximum number of children a template produces.
Subdivision level markings for meshes.
Constructs RefinementTemplates from RawTemplates.
void stats()
print some stats about maximum children in the raw data
@ BoundaryEdge
Entity is part of a boundary edge, i.e. a child of one of the parents edges.
@ ParentTopology
Entity is part of the parents topology.
@ BoundaryFace
Entity is part of a boundary face, i.e. a child of one of the parents faces.
@ Sibling
Entity is a sibling in the refinement tree.
T_ min(T_ a, T_ b)
Returns the minimum of two values.
std::uint64_t Index
Index data type.
Reference to another local mesh entity.
Face traits tag struct template.