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