12 const std::string& name,
20 register_attribute_typed<T>(name, ptype, size, replace, default_value));
26 const std::string& name,
47 int64_t current_capacity =
capacity(type);
53 if (current_capacity + count > max_size) {
55 "Requested more {} simplices than available (have {}, wanted {}, can only have at most "
64 std::vector<int64_t> ret(count);
65 std::iota(ret.begin(), ret.end(), current_capacity);
68 int64_t new_capacity = current_capacity + ret.size();
69 assert(ret.back() + 1 == current_capacity + ret.size());
76 for (
const int64_t simplex_index : ret) {
78 flag_accessor_indices.
activate(simplex_index);
111 for (int64_t j = 0; j < sizes.size(); ++j) {
122 for (int64_t j = 0; j < sizes.size(); ++j) {
133 for (int64_t j = 0; j < sizes.size(); ++j) {
139 std::vector<attribute::MeshAttributeHandle::HandleVariant> variant_diff(
140 std::vector<attribute::MeshAttributeHandle::HandleVariant>& a,
141 std::vector<attribute::MeshAttributeHandle::HandleVariant>& b)
143 std::vector<attribute::MeshAttributeHandle::HandleVariant> ret;
144 std::sort(a.begin(), a.end());
146 std::sort(b.begin(), b.end());
148 std::set_difference(a.begin(), a.end(), b.begin(), b.end(), std::inserter(ret, ret.begin()));
157 return variant_diff(all, builtins);
171 const std::vector<attribute::MeshAttributeHandle::HandleVariant>& keep_attributes)
174 auto b = keep_attributes;
180 std::map<Mesh*, std::vector<attribute::MeshAttributeHandle::HandleVariant>> keeps_t;
181 for (
const auto& attr : keep_attributes) {
182 keeps_t[
const_cast<Mesh*
>(&attr.mesh())].emplace_back(attr.handle());
184 for (
auto& [mptr, handles] : keeps_t) {
185 mptr->clear_attributes(handles);
190 assert(
this == &to_delete.
mesh());
209 std::tuple<std::vector<std::vector<int64_t>>, std::vector<std::vector<int64_t>>>
Mesh::consolidate()
215 std::vector<std::vector<int64_t>> new2old(tcp);
217 std::vector<std::vector<int64_t>> old2new(tcp);
220 for (int64_t d = 0; d < tcp; d++) {
225 old2new[d].push_back(new2old[d].size());
226 new2old[d].push_back(old2new[d].size() - 1);
228 old2new[d].push_back(-1);
234 auto run = [&](
auto&& mesh_attrs) {
235 for (int64_t d = 0; d < mesh_attrs.size(); ++d) {
236 auto& ma = mesh_attrs[d];
237 const auto& n2o = new2old[d];
238 ma.reserve(n2o.size());
240 for (
auto& h : ma.active_attributes()) {
241 ma.attribute(h).consolidate(n2o);
253 for (int64_t d = 0; d < tcp; d++) {
258 std::vector<std::vector<TypedAttributeHandle<int64_t>>> handle_indices =
261 for (int64_t d = 0; d < tcp; d++) {
262 for (int64_t i = 0; i < handle_indices[d].size(); ++i) {
264 accessor.
attribute().index_remap(old2new[d]);
269 constexpr
static int64_t TUPLE_SIZE = multimesh::utils::TUPLE_SIZE;
270 constexpr
static int64_t GLOBAL_ID_INDEX = multimesh::utils::GLOBAL_ID_INDEX;
271 const static std::vector<Eigen::Index> image_map_offsets{
272 Eigen::Index(TUPLE_SIZE + GLOBAL_ID_INDEX)};
273 const static std::vector<Eigen::Index> domain_map_offsets{Eigen::Index(GLOBAL_ID_INDEX)};
275 const auto& top_map = old2new[dim];
279 const auto& child_data = parent_ptr->m_multi_mesh_manager.m_children[child_id];
280 const auto handle = child_data.map_handle;
281 auto acc = parent_ptr->create_accessor(handle);
282 auto& attr = acc.attribute();
283 attr.index_remap(top_map, image_map_offsets);
289 auto& attr = acc.attribute();
290 attr.index_remap(top_map, domain_map_offsets);
296 const auto handle = child_data.map_handle;
298 auto& attr = acc.attribute();
299 attr.index_remap(top_map, domain_map_offsets);
302 const auto handle = child_data.mesh->m_multi_mesh_manager.map_to_parent_handle;
303 auto acc = child_data.mesh->create_accessor(handle);
304 auto& attr = acc.attribute();
305 attr.index_remap(top_map, image_map_offsets);
311 return {new2old, old2new};
315 std::vector<attribute::MeshAttributeHandle::HandleVariant> data;
317 std::copy(vec.begin(), vec.end(), std::back_inserter(data));
324 std::copy(mm_handles.begin(), mm_handles.end(), std::back_inserter(data));
330 Mesh::register_attribute<char>(
const std::string&,
PrimitiveType, int64_t,
bool,
char);
332 Mesh::register_attribute<int64_t>(
const std::string&,
PrimitiveType, int64_t,
bool, int64_t);
334 Mesh::register_attribute<double>(
const std::string&,
PrimitiveType, int64_t,
bool,
double);
void set_capacities(std::vector< int64_t > capacities)
std::vector< attribute::MeshAttributeHandle::HandleVariant > builtin_attributes() const
std::vector< attribute::MeshAttributeHandle::HandleVariant > custom_attributes() const
attribute::MeshAttributeHandle register_attribute(const std::string &name, PrimitiveType type, int64_t size, bool replace=false, T default_value=T(0))
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< 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)
void reserve_more_attributes(PrimitiveType type, int64_t size)
void update_child_handles()
Update the child handles after clearing attributes.
void guarantee_at_least_attributes(PrimitiveType type, int64_t size)
multimesh::MultiMeshManager m_multi_mesh_manager
multimesh::attribute::AttributeScopeHandle create_scope()
int64_t top_cell_dimension() const
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
attribute::Accessor< T, Mesh, D > create_accessor(const attribute::MeshAttributeHandle &handle)
virtual std::vector< std::vector< TypedAttributeHandle< int64_t > > > connectivity_attributes() const =0
Returns a vector of vectors of attribute handles.
void delete_attribute(const attribute::MeshAttributeHandle &to_delete)
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.
std::vector< int64_t > request_simplex_indices(PrimitiveType type, int64_t count)
TypedAttributeHandle< int64_t > m_cell_hash_handle
const attribute::FlagAccessor< Mesh > get_flag_accessor(PrimitiveType type) const
void reserve_attributes(PrimitiveType type, int64_t size)
attribute::AttributeManager m_attribute_manager
const T & get_attribute_default_value(const TypedAttributeHandle< T > &handle) const
Attribute< T > & attribute()
int64_t reserved_size() const
std::vector< MeshAttributes< double > > m_double_attributes
AttributeScopeHandle create_scope(Mesh &m)
std::vector< MeshAttributes< char > > m_char_attributes
void set_capacities(std::vector< int64_t > capacities)
void guarantee_at_least_attributes(int64_t dimension, int64_t size)
const T & get_attribute_default_value(const TypedAttributeHandle< T > &handle) const
std::vector< int64_t > m_capacities
std::vector< MeshAttributes< Rational > > m_rational_attributes
void clear_attributes(const std::vector< attribute::MeshAttributeHandle::HandleVariant > &custom_attributes)
Remove all custom attributes besides the one passed in.
void guarantee_more_attributes(int64_t dimension, int64_t size)
std::vector< MeshAttributeHandle::HandleVariant > get_all_attributes() const
void reserve_more_attributes(int64_t dimension, int64_t size)
std::string get_name(const TypedAttributeHandle< T > &attr) const
TypedAttributeHandle< T > register_attribute(const std::string &name, PrimitiveType type, int64_t size, bool replace, T default_value)
void delete_attribute(const attribute::MeshAttributeHandle::HandleVariant &to_delete)
void reserve_attributes(int64_t dimension, int64_t size)
std::vector< MeshAttributes< int64_t > > m_long_attributes
This handle is a wrapper for the MeshManager scope funtions.
const IndexBaseType & index_access() const
BaseAccessor & base_accessor()
bool is_active(int64_t t) const
std::variant< TypedAttributeHandle< char >, TypedAttributeHandle< int64_t >, TypedAttributeHandle< double >, TypedAttributeHandle< wmtk::Rational > > HandleVariant
Handle that represents attributes for some mesh.
std::vector< ChildData > m_children
TypedAttributeHandle< int64_t > map_to_parent_handle
std::vector< TypedAttributeHandle< int64_t > > map_handles() const
std::string_view primitive_type_name(PrimitiveType t)
constexpr PrimitiveType get_primitive_type_from_id(int8_t id)
Get the primitive type corresponding to its unique integer id.
constexpr int8_t get_primitive_type_id(PrimitiveType t)
Get a unique integer id corresponding to each primitive type.
spdlog::logger & logger()
Retrieves the current logger.