5#include <initializer_list>
24#include "attribute/AttributeScopeHandle.hpp"
38#if defined(__cpp_concepts) && defined(__cpp_lib_ranges)
49class AttributeManager;
50template <
typename T,
typename MeshType,
int Dim>
58class EdgeOperationData;
63class UpdateEdgeOperationMultiMeshMapFunctor;
71template <
int64_t cell_dimension,
typename NodeFunctor>
73template <
typename NodeFunctor>
75template <
typename Visitor>
77template <
typename Visitor>
98 template <
typename T,
int Dim>
100 template <
typename T,
typename MeshType,
int Dim>
107 template <
int64_t cell_dimension,
typename NodeFunctor>
109 template <
typename Visitor>
111 template <
typename NodeFunctor>
114 template <
typename Visitor>
131 std::map<std::string, const wmtk::utils::Hashable*>
child_hashables()
const override;
132 std::map<std::string, std::size_t>
child_hashes()
const override;
136 Mesh(
const int64_t& dimension);
138 Mesh(
const int64_t& dimension,
const int64_t& max_primitive_type_id,
PrimitiveType hash_type);
173 virtual std::tuple<std::vector<std::vector<int64_t>>, std::vector<std::vector<int64_t>>>
185 std::vector<attribute::MeshAttributeHandle::HandleVariant>
builtin_attributes()
const;
186 std::vector<attribute::MeshAttributeHandle::HandleVariant>
custom_attributes()
const;
190 template <
typename T>
192 const std::string& name,
195 bool replace =
false,
196 T default_value = T(0));
199 template <
typename T>
201 const std::string& name,
204 bool replace =
false,
205 T default_value = T(0));
209 template <
typename T>
211 const std::string& name,
214 template <
typename T>
216 const std::string& name,
219 template <
typename T>
221 const std::string& name,
225 template <
typename T,
int D = Eigen::Dynamic>
229 template <
typename T,
int D = Eigen::Dynamic>
233 template <
typename T,
int D = Eigen::Dynamic>
236 template <
typename T,
int D = Eigen::Dynamic>
240 template <
typename T>
243 template <
typename T>
246 template <
typename T>
258 const std::vector<attribute::MeshAttributeHandle::HandleVariant>& keep_attributes);
260 void clear_attributes(
const std::vector<attribute::MeshAttributeHandle>& keep_attributes);
277 template <
typename Functor,
typename... Args>
278 decltype(
auto)
parent_scope(Functor&& f, Args&&... args)
const;
307 const std::vector<std::vector<simplex::Simplex>>& simplices)
const;
358#if defined(__cpp_concepts) && defined(__cpp_lib_ranges)
359 template <std::ranges::forward_range ContainerType>
361 template <
typename ContainerType>
369#if defined(__cpp_concepts) && defined(__cpp_lib_ranges)
370 template <std::ranges::forward_range ContainerType>
372 template <
typename ContainerType>
378 const std::initializer_list<PrimitiveType>& op_sequence)
const;
513 const std::shared_ptr<Mesh>& child_mesh_ptr,
514 const std::vector<std::array<Tuple, 2>>&
map_tuples);
561 std::vector<simplex::Simplex>
map(
562 const Mesh& other_mesh,
563 const std::vector<simplex::Simplex>& my_simplices)
const;
576 std::vector<simplex::Simplex>
lub_map(
577 const Mesh& other_mesh,
590 std::vector<simplex::Simplex>
lub_map(
591 const Mesh& other_mesh,
592 const std::vector<simplex::Simplex>& my_simplices)
const;
628 const Mesh& child_mesh,
660 const Mesh& other_mesh,
662 const std::vector<Tuple>& my_simplices)
const;
689 const Mesh& other_mesh,
691 const std::vector<Tuple>& my_simplices)
const;
730 const Mesh& child_mesh,
808 template <
typename T,
typename MeshType>
813 template <
typename T,
typename MeshType>
866 const bool include_deleted)
const;
870template <
typename T,
int D>
876template <
typename T,
int D>
883template <
typename T,
int D>
887 assert(&handle.mesh() ==
this);
888 assert(handle.holds<T>());
889 return create_accessor<T, D>(handle.as<T>());
893template <
typename T,
int D>
897 assert(&handle.mesh() ==
this);
898 assert(handle.holds<T>());
899 return create_const_accessor<T, D>(handle.as<T>());
904 const std::string& name,
908 *
const_cast<Mesh*
>(
this),
909 get_attribute_handle_typed<T>(name, ptype));
914 const std::string& name,
940template <
typename Functor,
typename... Args>
945 return std::invoke(std::forward<Functor>(f), std::forward<Args>(args)...);
948#if defined(__cpp_concepts) && defined(__cpp_lib_ranges)
949template <std::ranges::forward_range ContainerType>
951template <
typename ContainerType>
955 static_assert(std::is_same_v<typename ContainerType::value_type, PrimitiveType>);
964 if (primitive == top_type &&
is_boundary(boundary_pt, r)) {
985 assert(dimension >= 0);
986 assert(dimension < 4);
991#if defined(__cpp_concepts) && defined(__cpp_lib_ranges)
992template <std::ranges::forward_range ContainerType>
994template <
typename ContainerType>
998 static_assert(std::is_same_v<typename ContainerType::value_type, PrimitiveType>);
void set_capacities(std::vector< int64_t > capacities)
Tuple switch_tuples_unsafe(const Tuple &tuple, const ContainerType &op_sequence) const
int64_t id(const simplex::IdSimplex &s) const
void update_vertex_operation_hashes(const Tuple &vertex, attribute::Accessor< int64_t > &hash_accessor)
wrapper function to update hashes (for parent mesh *this and its child meshes) after vertex operation...
int64_t id(const simplex::NavigatableSimplex &s) const
Mesh(const Mesh &other)=delete
attribute::Accessor< T, Mesh, D > create_accessor(const TypedAttributeHandle< T > &handle)
simplex::Simplex get_simplex(const simplex::IdSimplex &s) const
Convert an IdSimplex into a Simplex.
std::vector< attribute::MeshAttributeHandle::HandleVariant > builtin_attributes() const
std::vector< attribute::MeshAttributeHandle::HandleVariant > custom_attributes() const
static auto & get_index_access(attribute::Accessor< T, MeshType > &attr)
std::vector< int64_t > absolute_multi_mesh_id() const
returns a unique identifier for this mesh within a single multimesh structure
virtual bool is_boundary(PrimitiveType, const Tuple &tuple) const =0
check if a simplex (encoded as a tuple/primitive pair) lies on a boundary or not
attribute::MeshAttributeHandle register_attribute(const std::string &name, PrimitiveType type, int64_t size, bool replace=false, T default_value=T(0))
void serialize(MeshWriter &writer, const Mesh *local_root=nullptr) const
attribute::MeshAttributeHandle get_attribute_handle(const std::string &name, const PrimitiveType ptype) const
std::vector< std::vector< int64_t > > simplices_to_gids(const std::vector< std::vector< simplex::Simplex > > &simplices) const
const attribute::Accessor< T, Mesh, D > create_const_accessor(const attribute::MeshAttributeHandle &handle) const
int64_t capacity(PrimitiveType type) const
read in the m_capacities return the upper bound for the number of entities of the given dimension
attribute::TypedAttributeHandle< T > register_attribute_typed(const std::string &name, PrimitiveType type, int64_t size, bool replace=false, T default_value=T(0))
std::vector< simplex::Simplex > lub_map(const Mesh &other_mesh, const simplex::Simplex &my_simplex) const
maps a simplex from this mesh to any other mesh using LUB mesh as root
std::vector< TypedAttributeHandle< char > > m_flag_handles
0x1 == true = simplex is active (simplex exists) all flag default to 0
void guarantee_more_attributes(PrimitiveType type, int64_t size)
std::map< std::string, std::size_t > child_hashes() const override
void reserve_more_attributes(PrimitiveType type, int64_t size)
simplex::NavigatableSimplex simplex_from_id(const PrimitiveType type, const int64_t gid) const
void update_child_handles()
Update the child handles after clearing attributes.
Mesh & get_multi_mesh_child_mesh(const std::vector< int64_t > &relative_id)
int64_t get_attribute_dimension(const TypedAttributeHandle< T > &handle) const
Tuple map_to_root_tuple(const simplex::Simplex &my_simplex) const
maps a simplex from this mesh to the root mesh
attribute::TypedAttributeHandle< T > get_attribute_handle_typed(const std::string &name, const PrimitiveType ptype) const
virtual bool is_ccw(const Tuple &tuple) const =0
TODO this needs dimension?
int64_t id(const Tuple &tuple, PrimitiveType type) const
return the global id of the Tuple of the given dimension
bool is_boundary(const simplex::Simplex &tuple) const
check if a simplex lies on a boundary or not
void guarantee_at_least_attributes(PrimitiveType type, int64_t size)
attribute::Accessor< T, Mesh, D > create_accessor(const attribute::MeshAttributeHandle &handle)
virtual Tuple tuple_from_id(const PrimitiveType type, const int64_t gid) const =0
internal function that returns the tuple of requested type, and has the global index cid
void assert_capacity_valid() const
std::vector< std::shared_ptr< Mesh > > get_all_child_meshes() const
returns all multimesh child meshes
std::vector< Tuple > get_all(PrimitiveType type) const
Generate a vector of Tuples from global vertex/edge/triangle/tetrahedron index.
virtual int64_t id_virtual(const Tuple &tuple, PrimitiveType type) const =0
Internal utility to allow id to be virtual with a non-virtual overload in derived -Mesh classes.
multimesh::MultiMeshManager m_multi_mesh_manager
multimesh::attribute::AttributeScopeHandle create_scope()
std::vector< simplex::IdSimplex > get_all_id_simplex(PrimitiveType type) const
Tuple switch_tuples(const Tuple &tuple, const ContainerType &op_sequence) const
std::vector< Tuple > map_tuples(const Mesh &other_mesh, const simplex::Simplex &my_simplex) const
maps a simplex from this mesh to any other mesh
Mesh & operator=(const Mesh &other)=delete
bool has_attribute(const std::string &name, const PrimitiveType ptype) const
bool is_hash_valid(const Tuple &tuple) const
std::map< std::string, const wmtk::utils::Hashable * > child_hashables() const override
void register_child_mesh(const std::shared_ptr< Mesh > &child_mesh_ptr, const std::vector< std::array< Tuple, 2 > > &map_tuples)
register a mesh as the child of this mesh
virtual bool is_valid(const Tuple &tuple) const
check validity of tuple including its hash
void set_capacities_from_flags()
virtual int64_t id(const simplex::Simplex &s) const =0
Forwarding version of id on simplices that does id caching.
const attribute::Accessor< T, Mesh, D > create_const_accessor(const TypedAttributeHandle< T > &handle) const
bool is_multi_mesh_root() const
return true if this mesh is the root of a multimesh tree
int64_t top_cell_dimension() const
bool operator==(const Mesh &other) const
virtual Tuple switch_tuple(const Tuple &tuple, PrimitiveType type) const =0
switch the orientation of the Tuple of the given dimension
Tuple map_to_parent_tuple(const simplex::Simplex &my_simplex) const
optimized map from a simplex from this mesh to its direct parent
void reserve_attributes_to_fit()
reserve space for all attributes data types for all dimensional simplices
attribute::AttributeScopeHandle create_single_mesh_scope()
std::string get_attribute_name(const TypedAttributeHandle< T > &handle) const
simplex::Simplex map_to_root(const simplex::Simplex &my_simplex) const
maps a simplex from this mesh to the root mesh
virtual std::vector< std::vector< TypedAttributeHandle< int64_t > > > connectivity_attributes() const =0
Returns a vector of vectors of attribute handles.
Mesh & get_multi_mesh_root()
returns a reference to the root of a multimesh tree
bool is_hash_valid(const Tuple &tuple, const attribute::Accessor< int64_t > &hash_accessor) const
simplex::IdSimplex get_id_simplex(const Tuple &tuple, PrimitiveType pt) const
Retrieve the IdSimplex that is represented by the tuple and primitive type.
friend class tests::DEBUG_Mesh
void delete_attribute(const attribute::MeshAttributeHandle &to_delete)
int64_t m_top_cell_dimension
virtual std::vector< Tuple > orient_vertices(const Tuple &t) const =0
std::vector< std::shared_ptr< const Mesh > > get_all_meshes() const
returns all meshes in multimesh
PrimitiveType top_simplex_type() const
virtual std::tuple< std::vector< std::vector< int64_t > >, std::vector< std::vector< int64_t > > > consolidate()
Consolidate the attributes, moving all valid simplexes at the beginning of the corresponding vector.
simplex::Simplex map_to_parent(const simplex::Simplex &my_simplex) const
optimized map from a simplex from this mesh to its direct parent
Tuple get_tuple_from_id_simplex(const simplex::IdSimplex &s) const
std::vector< simplex::Simplex > map(const Mesh &other_mesh, const simplex::Simplex &my_simplex) const
maps a simplex from this mesh to any other mesh
virtual bool is_connectivity_valid() const =0
std::vector< int64_t > request_simplex_indices(PrimitiveType type, int64_t count)
Mesh & get_multi_mesh_mesh(const std::vector< int64_t > &absolute_id)
TypedAttributeHandle< int64_t > m_cell_hash_handle
decltype(auto) parent_scope(Functor &&f, Args &&... args) const
Evaluate the passed in function inside the parent scope.
bool can_map(const Mesh &other_mesh, const simplex::Simplex &my_simplex) const
const attribute::FlagAccessor< Mesh > get_const_flag_accessor(PrimitiveType type) const
bool is_from_same_multi_mesh_structure(const Mesh &other) const
void deregister_child_mesh(const std::shared_ptr< Mesh > &child_mesh_ptr)
Deregister a child mesh.
bool has_child_mesh() const
bool is_removed(const Tuple &tuple) const
std::vector< Tuple > map_to_child_tuples(const Mesh &child_mesh, const simplex::Simplex &my_simplex) const
optimized map fromsimplex from this mesh to one of its direct children
const attribute::FlagAccessor< Mesh > get_flag_accessor(PrimitiveType type) const
std::vector< simplex::Simplex > map_to_child(const Mesh &child_mesh, const simplex::Simplex &my_simplex) const
optimized map fromsimplex from this mesh to one of its direct children
std::vector< std::shared_ptr< Mesh > > get_child_meshes() const
returns the direct multimesh child meshes for the current mesh
void reserve_attributes(PrimitiveType type, int64_t size)
attribute::AttributeManager m_attribute_manager
bool has_child_mesh_in_dimension(int64_t dimension) const
returns if the mesh has a child mesh in the given dimension
const T & get_attribute_default_value(const TypedAttributeHandle< T > &handle) const
std::vector< Tuple > lub_map_tuples(const Mesh &other_mesh, const simplex::Simplex &my_simplex) const
maps a simplex from this mesh to any other mesh using LUB mesh as root
static auto & get_index_access(const attribute::Accessor< T, MeshType > &attr)
void reserve_attributes(int64_t dimension, int64_t size)
The Tuple is the basic navigation tool in our mesh data structure.
A CachingAccessor that uses tuples for accessing attributes instead of indices.
CachingBaseType & index_access()
int64_t get_attribute_dimension(const TypedAttributeHandle< T > &handle) const
std::vector< MeshAttributes< T > > & get()
std::string get_name(const TypedAttributeHandle< T > &attr) const
This handle is a wrapper for the MeshManager scope funtions.
std::variant< TypedAttributeHandle< char >, TypedAttributeHandle< int64_t >, TypedAttributeHandle< double >, TypedAttributeHandle< wmtk::Rational > > HandleVariant
Handle that represents attributes for some mesh.
wmtk::attribute::AttributeHandle m_base_handle
wmtk::PrimitiveType m_primitive_type
Implementation details for how the Mesh class implements multiple meshes.
bool has_child_mesh_in_dimension(int64_t dimension) const
bool has_child_mesh() const
TupleTag is a util helper class for tagging edges in a triangle mesh.