Wildmeshing Toolkit
Mesh.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <Eigen/Core>
4 
5 #include <initializer_list>
6 
7 #include <memory>
8 #include <tuple>
9 // just includes function prorotypes to befriend
10 //#include <wmtk/multimesh/utils/extract_child_mesh_from_tag.hpp>
11 
12 
13 // need to return this header
14 #include "attribute/Accessor.hpp"
15 
16 // is a member of the Mesh class
17 #include "MultiMeshManager.hpp"
18 
19 // basic data for the class
20 #include <wmtk/simplex/Simplex.hpp>
21 #include "Tuple.hpp"
22 #include "Types.hpp"
24 #include "attribute/AttributeScopeHandle.hpp"
28 
30 
31 #include "simplex/IdSimplex.hpp"
33 #include "simplex/Simplex.hpp"
34 
35 
36 // if we have concepts then switch_tuples uses forward_iterator concept
37 #if defined(__cpp_concepts) && defined(__cpp_lib_ranges)
38 #include <ranges>
39 #endif
40 
41 
42 namespace wmtk {
43 namespace tests {
44 class DEBUG_Mesh;
45 namespace tools {
46 
47 class TestTools;
48 
49 }
50 } // namespace tests
51 // thread management tool that we will PImpl
52 namespace attribute {
53 class AttributeManager;
54 template <typename T, typename MeshType, int Dim>
55 class Accessor;
56 
57 } // namespace attribute
58 namespace operations {
59 class Operation;
60 class EdgeCollapse;
61 class EdgeSplit;
62 class EdgeOperationData;
63 namespace internal {
65 }
66 namespace utils {
67 class UpdateEdgeOperationMultiMeshMapFunctor;
68 }
69 } // namespace operations
70 
71 namespace simplex {
72 class RawSimplex;
73 namespace utils {
74 class SimplexComparisons;
75 }
76 } // namespace simplex
77 
78 namespace io {
79 class ParaviewWriter;
80 }
81 namespace multimesh {
82 template <int64_t cell_dimension, typename NodeFunctor>
84 template <typename NodeFunctor>
85 class MultiMeshVisitor;
86 template <typename Visitor>
88 template <typename Visitor>
90 
91 namespace utils {
92  class MapValidator;
93 namespace internal {
94 class TupleTag;
95 }
96 } // namespace utils
97 } // namespace multimesh
98 
99 
100 // NOTE: the implementation of this class is split into several files to improve clang-format
101 // performance
102 // * Mesh.cpp
103 // * Mesh_attributes.cpp
104 // * Mesh_construction.cpp
105 class Mesh : public std::enable_shared_from_this<Mesh>, public wmtk::utils::MerkleTreeInteriorNode
106 {
107 public:
109  friend class tests::DEBUG_Mesh;
110  template <typename T, int Dim>
112  template <typename T, typename MeshType, int Dim>
113  friend class attribute::Accessor;
114  friend class io::ParaviewWriter;
115  friend class HDF5Reader;
119  template <int64_t cell_dimension, typename NodeFunctor>
121  template <typename Visitor>
123  template <typename NodeFunctor>
126  template <typename Visitor>
131  friend class simplex::RawSimplex;
132  friend class simplex::Simplex;
133  friend class simplex::IdSimplex;
136  friend class operations::Operation;
138  friend class operations::EdgeSplit;
141 
142 
143  int64_t top_cell_dimension() const;
145  bool is_free() const;
146 
147  // attribute directly hashes its "children" components so it overrides "child_hashes"
148  std::map<std::string, const wmtk::utils::Hashable*> child_hashables() const override;
149  std::map<std::string, std::size_t> child_hashes() const override;
150 
151  // dimension is the dimension of the top level simplex in this mesh
152  // That is, a TriMesh is a 2, a TetMesh is a 3
153  Mesh(const int64_t& dimension);
154  // maximum primitive type id for supported attribute primitive locations
155  Mesh(const int64_t& dimension, const int64_t& max_primitive_type_id, PrimitiveType hash_type);
156  Mesh(Mesh&& other);
157  Mesh(const Mesh& other) = delete;
158  Mesh& operator=(const Mesh& other) = delete;
159  Mesh& operator=(Mesh&& other);
160  virtual ~Mesh();
161 
162  void serialize(MeshWriter& writer, const Mesh* local_root = nullptr) const;
163 
169  std::vector<Tuple> get_all(PrimitiveType type) const;
170 
171  std::vector<simplex::IdSimplex> get_all_id_simplex(PrimitiveType type) const;
175  simplex::IdSimplex get_id_simplex(const Tuple& tuple, PrimitiveType pt) const;
176 
178 
183 
185 
190  virtual std::tuple<std::vector<std::vector<int64_t>>, std::vector<std::vector<int64_t>>>
191  consolidate();
192 
198  virtual std::vector<std::vector<TypedAttributeHandle<int64_t>>> connectivity_attributes()
199  const = 0;
200 
201 
202  std::vector<attribute::MeshAttributeHandle::HandleVariant> builtin_attributes() const;
203  std::vector<attribute::MeshAttributeHandle::HandleVariant> custom_attributes() const;
204 
205 
206  /* @brief registers an attribute without assuming the mesh exists */
207  template <typename T>
209  const std::string& name,
210  PrimitiveType type,
211  int64_t size,
212  bool replace = false,
213  T default_value = T(0));
214 
215  /* @brief registers an attribute without assuming the mesh exists, returns a typed attribute */
216  template <typename T>
218  const std::string& name,
219  PrimitiveType type,
220  int64_t size,
221  bool replace = false,
222  T default_value = T(0));
223 
224 
225 public:
226  template <typename T>
227  bool has_attribute(
228  const std::string& name,
229  const PrimitiveType ptype) const; // block standard topology tools
230 
231  template <typename T>
233  const std::string& name,
234  const PrimitiveType ptype) const; // block standard topology tools
235 
236  template <typename T>
238  const std::string& name,
239  const PrimitiveType ptype) const; // block standard topology tools
240 
241 
242  template <typename T, int D = Eigen::Dynamic>
244 
245 
246  template <typename T, int D = Eigen::Dynamic>
248  const attribute::MeshAttributeHandle& handle) const;
249 
250  template <typename T, int D = Eigen::Dynamic>
252 
253  template <typename T, int D = Eigen::Dynamic>
255  const TypedAttributeHandle<T>& handle) const;
256 
257  template <typename T>
258  int64_t get_attribute_dimension(const TypedAttributeHandle<T>& handle) const;
259 
260  template <typename T>
261  const T& get_attribute_default_value(const TypedAttributeHandle<T>& handle) const;
262 
263  template <typename T>
264  std::string get_attribute_name(const TypedAttributeHandle<T>& handle) const;
265 
266  std::string get_attribute_name(
268 
274  void clear_attributes(
275  const std::vector<attribute::MeshAttributeHandle::HandleVariant>& keep_attributes);
276  void clear_attributes();
277  void clear_attributes(const std::vector<attribute::MeshAttributeHandle>& keep_attributes);
278  void delete_attribute(const attribute::MeshAttributeHandle& to_delete);
280 
281 
282  // creates a scope as int64_t as the AttributeScopeHandle exists
284 
285 
294  template <typename Functor, typename... Args>
295  decltype(auto) parent_scope(Functor&& f, Args&&... args) const;
296 
297 
298  const attribute::Accessor<char> get_flag_accessor(PrimitiveType type) const;
299  const attribute::Accessor<char> get_const_flag_accessor(PrimitiveType type) const;
300 
301 
302  bool operator==(const Mesh& other) const;
303 
304  void assert_capacity_valid() const;
305  virtual bool is_connectivity_valid() const = 0;
306 
307  virtual std::vector<Tuple> orient_vertices(const Tuple& t) const = 0;
308 
309 protected: // member functions
310  attribute::Accessor<char> get_flag_accessor(PrimitiveType type);
311 
312 
313 protected:
321  virtual Tuple tuple_from_id(const PrimitiveType type, const int64_t gid) const = 0;
322  simplex::NavigatableSimplex simplex_from_id(const PrimitiveType type, const int64_t gid) const;
323  std::vector<std::vector<int64_t>> simplices_to_gids(
324  const std::vector<std::vector<simplex::Simplex>>& simplices) const;
331  void reserve_attributes(PrimitiveType type, int64_t size);
332  void reserve_attributes(int64_t dimension, int64_t size);
333 
334 
335  // specifies the number of simplices of each type and resizes attributes appropritely
336  void set_capacities(std::vector<int64_t> capacities);
337 
338  // reserves extra attributes than necessary right now
339  void reserve_more_attributes(PrimitiveType type, int64_t size);
340  // reserves extra attributes than necessary right now, does not pay attention
341  void reserve_more_attributes(const std::vector<int64_t>& sizes);
342 
343  // makes sure that there are at least `size` simples of type `type` avialable
344  void guarantee_more_attributes(PrimitiveType type, int64_t size);
345  // makes sure that there are at least `size` simplices avialable at every dimension
346  void guarantee_more_attributes(const std::vector<int64_t>& sizes);
347 
348  // makes sure that there are at least `size` simples of type `type` avialable
349  void guarantee_at_least_attributes(PrimitiveType type, int64_t size);
350  // makes sure that there are at least `size` simplices avialable at every dimension
351  void guarantee_at_least_attributes(const std::vector<int64_t>& sizes);
352 
353  // provides new simplices - should ONLY be called in our atomic topological operations
354  // all returned simplices are active (i.e their flags say they exist)
355  [[nodiscard]] std::vector<int64_t> request_simplex_indices(PrimitiveType type, int64_t count);
356 
357 public:
368  virtual Tuple switch_tuple(const Tuple& tuple, PrimitiveType type) const = 0;
369 
370  // NOTE: adding per-simplex utility functions here is _wrong_ and will be removed
371 
372 
373  // Performs a sequence of switch_tuple operations in the order specified in op_sequence.
374  // in debug mode this will assert a failure, in release this will return a null tuple
375 #if defined(__cpp_concepts) && defined(__cpp_lib_ranges)
376  template <std::ranges::forward_range ContainerType>
377 #else
378  template <typename ContainerType>
379 #endif
380  Tuple switch_tuples(const Tuple& tuple, const ContainerType& op_sequence) const;
381  // annoying initializer list prototype to catch switch_tuples(t, {PV,PE})
382  Tuple switch_tuples(const Tuple& tuple, const std::initializer_list<PrimitiveType>& op_sequence)
383  const;
384 
385  // Performs a sequence of switch_tuple operations in the order specified in op_sequence.
386 #if defined(__cpp_concepts) && defined(__cpp_lib_ranges)
387  template <std::ranges::forward_range ContainerType>
388 #else
389  template <typename ContainerType>
390 #endif
391  Tuple switch_tuples_unsafe(const Tuple& tuple, const ContainerType& op_sequence) const;
392  // annoying initializer list prototype to catch switch_tuples(t, {PV,PE})
394  const Tuple& tuple,
395  const std::initializer_list<PrimitiveType>& op_sequence) const;
396 
405  int64_t capacity(PrimitiveType type) const;
406 
414  virtual bool is_ccw(const Tuple& tuple) const = 0;
415 
423  bool is_boundary(const simplex::Simplex& tuple) const;
431  virtual bool is_boundary(PrimitiveType, const Tuple& tuple) const = 0;
432 
433 
434  bool is_hash_valid(const Tuple& tuple, const attribute::Accessor<int64_t>& hash_accessor) const;
435  bool is_hash_valid(const Tuple& tuple) const;
436 
446  virtual bool is_valid(const Tuple& tuple) const;
447 
448  // whether the tuple refers to a removed / invalid dart in the mesh
449  bool is_removed(const Tuple& tuple) const;
450  // whether the tuple refers to a removed / invalid simplex in the mesh
451  bool is_removed(const Tuple& tuple, PrimitiveType pt) const;
452 
453 protected:
454  // whether the tuple refers to a removed / invalid facet
455  bool is_removed(int64_t index) const;
456  // whether the tuple refers to a removed / invalid simplex
457  bool is_removed(int64_t index, PrimitiveType pt) const;
458 
459 public:
463  bool is_valid(const simplex::Simplex& s) const;
464 
465 
466  //============================
467  // MultiMesh interface
468  //============================
469  //
473  bool is_multi_mesh_root() const;
481  const Mesh& get_multi_mesh_root() const;
482 
483  Mesh& get_multi_mesh_mesh(const std::vector<int64_t>& absolute_id);
484  const Mesh& get_multi_mesh_mesh(const std::vector<int64_t>& absolute_id) const;
485 
486 
487  Mesh& get_multi_mesh_child_mesh(const std::vector<int64_t>& relative_id);
488  const Mesh& get_multi_mesh_child_mesh(const std::vector<int64_t>& relative_id) const;
489 
493  std::vector<std::shared_ptr<Mesh>> get_child_meshes() const;
494 
498  std::vector<std::shared_ptr<Mesh>> get_all_child_meshes() const;
499 
503  std::vector<std::shared_ptr<const Mesh>> get_all_meshes() const;
504 
505 
514  std::vector<int64_t> absolute_multi_mesh_id() const;
515 
516 
529  void register_child_mesh(
530  const std::shared_ptr<Mesh>& child_mesh_ptr,
531  const std::vector<std::array<Tuple, 2>>& map_tuples);
532 
540  void deregister_child_mesh(const std::shared_ptr<Mesh>& child_mesh_ptr);
541 
542 
543 private:
547  void update_child_handles();
548 
549 public:
567  std::vector<simplex::Simplex> map(const Mesh& other_mesh, const simplex::Simplex& my_simplex)
568  const;
569 
570 
571  /*
572  * @brief map a collection of simplices to another mesh
573  *
574  * @param mesh the mesh the simplices should be mapped to
575  * @param simplices the simplices being mapped to the child mesh
576  * @returns every simplex that corresponds to the passed simplices
577  * */
578  std::vector<simplex::Simplex> map(
579  const Mesh& other_mesh,
580  const std::vector<simplex::Simplex>& my_simplices) const;
581 
593  std::vector<simplex::Simplex> lub_map(
594  const Mesh& other_mesh,
595  const simplex::Simplex& my_simplex) const;
596 
597 
598  /*
599  * @brief maps a collection of simplices from this mesh to any other mesh using LUB mesh as root
600  *
601  * Satisfies the same properties of standard map, but uses a the LUB as the root
602  *
603  * @param mesh the mesh the simplices should be mapped to
604  * @param simplices the simplices being mapped to the child mesh
605  * @returns every simplex that corresponds to the passed simplices
606  * */
607  std::vector<simplex::Simplex> lub_map(
608  const Mesh& other_mesh,
609  const std::vector<simplex::Simplex>& my_simplices) const;
610 
623  simplex::Simplex map_to_parent(const simplex::Simplex& my_simplex) const;
624 
633  simplex::Simplex map_to_root(const simplex::Simplex& my_simplex) const;
634 
644  std::vector<simplex::Simplex> map_to_child(
645  const Mesh& child_mesh,
646  const simplex::Simplex& my_simplex) const;
647 
648 
666  std::vector<Tuple> map_tuples(const Mesh& other_mesh, const simplex::Simplex& my_simplex) const;
667 
668  /*
669  * @brief map a collection of homogeneous simplices to another mesh
670  *
671  * @param mesh the mesh the simplices should be mapped to
672  * @param primitive_type the type of primitive the simplices are
673  * @param tuples the tuples used to represent the simplices
674  * @returns every simplex that corresponds to the passed simplices
675  * */
676  std::vector<Tuple> map_tuples(
677  const Mesh& other_mesh,
678  PrimitiveType pt,
679  const std::vector<Tuple>& my_simplices) const;
680 
692  std::vector<Tuple> lub_map_tuples(const Mesh& other_mesh, const simplex::Simplex& my_simplex)
693  const;
694 
695 
696  /*
697  * @brief maps a collection of simplices from this mesh to any other mesh using LUB mesh as root
698  *
699  * Satisfies the same properties of standard map_tuples, but uses a the LUB as the root
700  *
701  * @param mesh the mesh the simplices should be mapped to
702  * @param simplices the simplices being mapped to the child mesh
703  * @returns every simplex that corresponds to the passed simplices
704  * */
705  std::vector<Tuple> lub_map_tuples(
706  const Mesh& other_mesh,
707  PrimitiveType pt,
708  const std::vector<Tuple>& my_simplices) const;
709 
723  Tuple map_to_parent_tuple(const simplex::Simplex& my_simplex) const;
724 
734  Tuple map_to_root_tuple(const simplex::Simplex& my_simplex) const;
735 
746  std::vector<Tuple> map_to_child_tuples(
747  const Mesh& child_mesh,
748  const simplex::Simplex& my_simplex) const;
749 
750 
751  /*
752  * @brief identifies if this simplex can be mapped to another mesh
753  *
754  * This tries to map a simplex to another mesh and wil return true if a simplex is found.
755  * Note that the cost of this is almost hte same as mapping, so it is more efficient to map and
756  * check if the returned vector is empty rather than call this function.
757  */
758  bool can_map(const Mesh& other_mesh, const simplex::Simplex& my_simplex) const;
759 
768  const Tuple& vertex,
769  attribute::Accessor<int64_t>& hash_accessor);
770 
771 
779  bool has_child_mesh_in_dimension(int64_t dimension) const
780  {
782  }
783 
785 
786  /*
787  * @brief returns if the other mesh is part of the same multi-mesh structure
788  * @param other the other being mesh being checked
789  * @returns true if they are part of the same structure
790  **/
791  bool is_from_same_multi_mesh_structure(const Mesh& other) const;
792 
793 protected:
794  // creates a scope as int64_t as the AttributeScopeHandle exists
796 
797 protected:
810  int64_t id(const Tuple& tuple, PrimitiveType type) const;
811 
812  int64_t id(const simplex::NavigatableSimplex& s) const { return s.index(); }
813  int64_t id(const simplex::IdSimplex& s) const { return s.index(); }
815  virtual int64_t id(const simplex::Simplex& s) const = 0;
819  virtual int64_t id_virtual(const Tuple& tuple, PrimitiveType type) const = 0;
820 
821 
822  template <typename T, typename MeshType>
824  {
825  return attr.index_access();
826  }
827  template <typename T, typename MeshType>
829  {
830  return attr.index_access();
831  }
832 
833 
834  // std::shared_ptr<AccessorCache> request_accesor_cache();
835  //[[nodiscard]] AccessorScopeHandle push_accesor_scope();
836 
837 protected: // THese are protected so unit tests can access - do not use manually in other derived
838  // classes?
840 
842 
843  int64_t m_top_cell_dimension = -1;
844 
845  // assumes no adjacency data exists
846  bool m_is_free = false;
847 
848 private:
849  // PImpl'd manager of per-thread update stacks
850  // Every time a new access scope is requested the manager creates another level of indirection
851  // for updates
852  // std::unique_ptr<AttributeScopeManager> m_attribute_scope_manager;
853 
854  //=========================================================
855  // simplex::Simplex Attribute
856  //=========================================================
857 
858 
864  std::vector<TypedAttributeHandle<char>> m_flag_handles;
865 
866  // hashes for top level simplices (i.e cells) to identify whether tuples
867  // are invalid or not
869 
870 
877  std::vector<Tuple> get_all(PrimitiveType type, const bool include_deleted) const;
878  std::vector<simplex::IdSimplex> get_all_id_simplex(
879  PrimitiveType type,
880  const bool include_deleted) const;
881 };
882 
883 
884 template <typename T, int D>
887 {
888  return attribute::Accessor<T, Mesh, D>(*this, handle);
889 }
890 template <typename T, int D>
891 inline auto Mesh::create_const_accessor(const TypedAttributeHandle<T>& handle) const
893 {
894  return attribute::Accessor<T, Mesh, D>(*this, handle);
895 }
896 
897 template <typename T, int D>
900 {
901  assert(&handle.mesh() == this);
902  assert(handle.holds<T>());
903  return create_accessor<T, D>(handle.as<T>());
904 }
905 
906 
907 template <typename T, int D>
910 {
911  assert(&handle.mesh() == this);
912  assert(handle.holds<T>());
913  return create_const_accessor<T, D>(handle.as<T>());
914 }
915 
916 template <typename T>
918  const std::string& name,
919  const PrimitiveType ptype) const
920 {
922  *const_cast<Mesh*>(this),
923  get_attribute_handle_typed<T>(name, ptype));
924 }
925 
926 template <typename T>
928  const std::string& name,
929  const PrimitiveType ptype) const
930 {
932  h.m_base_handle = m_attribute_manager.get<T>(ptype).attribute_handle(name);
933  h.m_primitive_type = ptype;
934  return h;
935 }
936 template <typename T>
937 inline bool Mesh::has_attribute(const std::string& name, const PrimitiveType ptype) const
938 {
939  return m_attribute_manager.get<T>(ptype).has_attribute(name);
940 }
941 
942 template <typename T>
943 inline int64_t Mesh::get_attribute_dimension(const TypedAttributeHandle<T>& handle) const
944 {
946 }
947 
948 template <typename T>
949 inline std::string Mesh::get_attribute_name(const TypedAttributeHandle<T>& handle) const
950 {
951  return m_attribute_manager.get_name(handle);
952 }
953 
954 template <typename Functor, typename... Args>
955 inline decltype(auto) Mesh::parent_scope(Functor&& f, Args&&... args) const
956 {
957  multimesh::attribute::UseParentScopeRAII raii(const_cast<Mesh&>(*this));
958 
959  return std::invoke(std::forward<Functor>(f), std::forward<Args>(args)...);
960 }
961 
962 #if defined(__cpp_concepts) && defined(__cpp_lib_ranges)
963 template <std::ranges::forward_range ContainerType>
964 #else
965 template <typename ContainerType>
966 #endif
967 inline Tuple Mesh::switch_tuples(const Tuple& tuple, const ContainerType& sequence) const
968 {
969  static_assert(std::is_same_v<typename ContainerType::value_type, PrimitiveType>);
970  Tuple r = tuple;
971  const PrimitiveType top_type = top_simplex_type();
972 
973  const int64_t boundary_dim = top_cell_dimension() - 1;
974  const PrimitiveType boundary_pt = static_cast<PrimitiveType>(boundary_dim);
975 
976  for (const PrimitiveType primitive : sequence) {
977  // for top level simplices we cannot navigate across boundaries
978  if (primitive == top_type && is_boundary(boundary_pt, r)) {
979  assert(!is_boundary(boundary_pt, r));
980  r = {};
981  return r;
982  }
983  r = switch_tuple(r, primitive);
984  }
985  return r;
986 }
987 inline bool Mesh::is_free() const
988 {
989  return m_is_free;
990 }
991 
992 inline int64_t Mesh::top_cell_dimension() const
993 {
994  return m_top_cell_dimension;
995 }
997 {
998  int64_t dimension = top_cell_dimension();
999  assert(dimension >= 0);
1000  assert(dimension < 4);
1001  return static_cast<PrimitiveType>(dimension);
1002 }
1003 
1004 
1005 #if defined(__cpp_concepts) && defined(__cpp_lib_ranges)
1006 template <std::ranges::forward_range ContainerType>
1007 #else
1008 template <typename ContainerType>
1009 #endif
1010 inline Tuple Mesh::switch_tuples_unsafe(const Tuple& tuple, const ContainerType& sequence) const
1011 {
1012  static_assert(std::is_same_v<typename ContainerType::value_type, PrimitiveType>);
1013  Tuple r = tuple;
1014  for (const PrimitiveType primitive : sequence) {
1015  r = switch_tuple(r, primitive);
1016  }
1017  return r;
1018 }
1019 
1020 inline int64_t Mesh::id(const Tuple& tuple, PrimitiveType type) const
1021 {
1022  return id_virtual(tuple, type);
1023 }
1024 } // namespace wmtk
bool m_is_free
Definition: Mesh.hpp:846
void set_capacities(std::vector< int64_t > capacities)
Tuple switch_tuples_unsafe(const Tuple &tuple, const ContainerType &op_sequence) const
Definition: Mesh.hpp:1010
Mesh(const int64_t &dimension)
int64_t id(const simplex::IdSimplex &s) const
Definition: Mesh.hpp:813
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...
void clear_attributes()
virtual std::vector< Tuple > orient_vertices(const Tuple &t) const =0
int64_t id(const simplex::NavigatableSimplex &s) const
Definition: Mesh.hpp:812
Mesh(const Mesh &other)=delete
simplex::Simplex get_simplex(const simplex::IdSimplex &s) const
Convert an IdSimplex into a Simplex.
Definition: Mesh.cpp:38
std::vector< attribute::MeshAttributeHandle::HandleVariant > builtin_attributes() const
std::vector< attribute::MeshAttributeHandle::HandleVariant > custom_attributes() const
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))
static auto & get_index_access(const attribute::Accessor< T, MeshType > &attr)
Definition: Mesh.hpp:828
void serialize(MeshWriter &writer, const Mesh *local_root=nullptr) const
Definition: Mesh.cpp:92
attribute::MeshAttributeHandle get_attribute_handle(const std::string &name, const PrimitiveType ptype) const
Definition: Mesh.hpp:917
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
Definition: Mesh.hpp:864
void guarantee_more_attributes(PrimitiveType type, int64_t size)
std::map< std::string, std::size_t > child_hashes() const override
Definition: Mesh_hash.cpp:12
void reserve_more_attributes(PrimitiveType type, int64_t size)
simplex::NavigatableSimplex simplex_from_id(const PrimitiveType type, const int64_t gid) const
Definition: Mesh.cpp:129
const attribute::Accessor< T, Mesh, D > create_const_accessor(const attribute::MeshAttributeHandle &handle) 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
Definition: Mesh.hpp:943
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
Definition: Mesh.hpp:927
bool is_free() const
Definition: Mesh.hpp:987
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
Definition: Mesh.hpp:1020
bool is_boundary(const simplex::Simplex &tuple) const
check if a simplex lies on a boundary or not
Definition: Mesh.cpp:106
void guarantee_at_least_attributes(PrimitiveType type, int64_t size)
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
Definition: Mesh.cpp:217
std::vector< std::shared_ptr< Mesh > > get_all_child_meshes() const
returns all multimesh child meshes
static auto & get_index_access(attribute::Accessor< T, MeshType > &attr)
Definition: Mesh.hpp:823
std::vector< Tuple > get_all(PrimitiveType type) const
Generate a vector of Tuples from global vertex/edge/triangle/tetrahedron index.
Definition: Mesh.cpp:18
const attribute::Accessor< char > get_const_flag_accessor(PrimitiveType type) const
Definition: Mesh.cpp:162
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
Definition: Mesh.hpp:841
multimesh::attribute::AttributeScopeHandle create_scope()
std::vector< std::vector< int64_t > > simplices_to_gids(const std::vector< std::vector< simplex::Simplex >> &simplices) const
Definition: Mesh.cpp:186
std::vector< simplex::IdSimplex > get_all_id_simplex(PrimitiveType type) const
Definition: Mesh.cpp:23
Tuple switch_tuples(const Tuple &tuple, const ContainerType &op_sequence) const
Definition: Mesh.hpp:967
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
bool has_attribute(const std::string &name, const PrimitiveType ptype) const
Definition: Mesh.hpp:937
bool is_hash_valid(const Tuple &tuple) const
std::map< std::string, const wmtk::utils::Hashable * > child_hashables() const override
Definition: Mesh_hash.cpp:5
virtual bool is_valid(const Tuple &tuple) const
check validity of tuple including its hash
Definition: Mesh.cpp:112
void set_capacities_from_flags()
Definition: Mesh.cpp:172
virtual int64_t id(const simplex::Simplex &s) const =0
Forwarding version of id on simplices that does id caching.
bool is_multi_mesh_root() const
return true if this mesh is the root of a multimesh tree
int64_t top_cell_dimension() const
Definition: Mesh.hpp:992
Mesh & operator=(const Mesh &other)=delete
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
Definition: Mesh.hpp:949
simplex::Simplex map_to_root(const simplex::Simplex &my_simplex) const
maps a simplex from this mesh to the root mesh
attribute::Accessor< T, Mesh, D > create_accessor(const attribute::MeshAttributeHandle &handle)
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.
Definition: Mesh.cpp:28
virtual std::vector< std::vector< TypedAttributeHandle< int64_t > > > connectivity_attributes() const =0
Returns a vector of vectors of attribute handles.
friend class tests::DEBUG_Mesh
Definition: Mesh.hpp:109
void delete_attribute(const attribute::MeshAttributeHandle &to_delete)
int64_t m_top_cell_dimension
Definition: Mesh.hpp:843
std::vector< std::shared_ptr< const Mesh > > get_all_meshes() const
returns all meshes in multimesh
PrimitiveType top_simplex_type() const
Definition: Mesh.hpp:996
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
Definition: Mesh.cpp:44
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
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
Definition: Mesh.hpp:868
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
bool is_from_same_multi_mesh_structure(const Mesh &other) const
const attribute::Accessor< T, Mesh, D > create_const_accessor(const TypedAttributeHandle< T > &handle) const
void deregister_child_mesh(const std::shared_ptr< Mesh > &child_mesh_ptr)
Deregister a child mesh.
bool has_child_mesh() const
Definition: Mesh.hpp:784
bool is_removed(const Tuple &tuple) const
Definition: Mesh.cpp:117
const attribute::Accessor< char > get_flag_accessor(PrimitiveType type) const
Definition: Mesh.cpp:158
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
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
friend class tests::tools::TestTools
Definition: Mesh.hpp:108
void reserve_attributes(PrimitiveType type, int64_t size)
attribute::AttributeManager m_attribute_manager
Definition: Mesh.hpp:839
bool has_child_mesh_in_dimension(int64_t dimension) const
returns if the mesh has a child mesh in the given dimension
Definition: Mesh.hpp:779
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
attribute::Accessor< T, Mesh, D > create_accessor(const TypedAttributeHandle< T > &handle)
A CachingAccessor that uses tuples for accessing attributes instead of indices.
Definition: Accessor.hpp:25
CachingBaseType & index_access()
Definition: Accessor.hpp:95
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
Implementation details for how the Mesh class implements multiple meshes.
bool has_child_mesh_in_dimension(int64_t dimension) const
TupleTag is a util helper class for tagging edges in a triangle mesh.
Definition: TupleTag.hpp:17
int64_t index() const
Definition: IdSimplex.hpp:32
A meshless implementation of the simplex that just stores an array of ids.
Definition: RawSimplex.hpp:20
Definition: autodiff.h:995
std::pair< std::shared_ptr< Mesh >, std::shared_ptr< Mesh > > multimesh(const MultiMeshType &type, Mesh &parent, std::shared_ptr< Mesh > child, const attribute::MeshAttributeHandle parent_position_handle, const std::string &tag_name, const int64_t tag_value, const int64_t primitive)
Definition: multimesh.cpp:15
Definition: Accessor.hpp:6