Skip to content

Commit bd2e000

Browse files
authored
Merge pull request #845 from mtao/mtao/flag_accessor
Flag Accessor
2 parents 22b78e8 + 42d5ab0 commit bd2e000

26 files changed

+306
-124
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ endif()
4444
project(WildMeshingToolkit DESCRIPTION "A mesh optimization toolkit" LANGUAGES C CXX)
4545

4646
# ###############################################################################
47+
option(WMTK_ENABLE_APPLICATIONS "Enable applications (required for any applications to build)" ${WILDMESHING_TOOLKIT_TOPLEVEL_PROJECT})
4748
option(WMTK_BUILD_DOCS "Build doxygen" OFF)
4849
option (BUILD_SHARED_LIBS "Build Shared Libraries" OFF) # we globally want to disable this option due to use of TBB
4950

@@ -207,5 +208,7 @@ endif()
207208
# Compile extras only if this is a top-level project
208209
if(WILDMESHING_TOOLKIT_TOPLEVEL_PROJECT)
209210
add_subdirectory(tests)
211+
endif()
212+
if(WMTK_ENABLE_APPLICATIONS)
210213
add_subdirectory(applications)
211214
endif()

src/wmtk/EdgeMesh.cpp

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <numeric>
66
#include <wmtk/utils/Logger.hpp>
77
namespace wmtk {
8-
EdgeMesh::~EdgeMesh() = default;
8+
EdgeMesh::~EdgeMesh() = default;
99
EdgeMesh::EdgeMesh()
1010
: MeshCRTP<EdgeMesh>(1)
1111
, m_ve_handle(register_attribute_typed<int64_t>("m_ve", PrimitiveType::Vertex, 1, false, -1))
@@ -111,21 +111,21 @@ void EdgeMesh::initialize(
111111
attribute::Accessor<int64_t> ee_accessor = create_accessor<int64_t>(m_ee_handle);
112112
attribute::Accessor<int64_t> ve_accessor = create_accessor<int64_t>(m_ve_handle);
113113

114-
attribute::Accessor<char> v_flag_accessor = get_flag_accessor(PrimitiveType::Vertex);
115-
attribute::Accessor<char> e_flag_accessor = get_flag_accessor(PrimitiveType::Edge);
114+
attribute::FlagAccessor<EdgeMesh> v_flag_accessor = get_flag_accessor(PrimitiveType::Vertex);
115+
attribute::FlagAccessor<EdgeMesh> e_flag_accessor = get_flag_accessor(PrimitiveType::Edge);
116116

117117
// iterate over the matrices and fill attributes
118118

119119
for (int64_t i = 0; i < capacity(PrimitiveType::Edge); ++i) {
120120
ev_accessor.index_access().vector_attribute<2>(i) = EV.row(i).transpose();
121121
ee_accessor.index_access().vector_attribute<2>(i) = EE.row(i).transpose();
122122

123-
e_flag_accessor.index_access().scalar_attribute(i) |= 0x1;
123+
e_flag_accessor.index_access().activate(i);
124124
}
125125
// m_ve
126126
for (int64_t i = 0; i < capacity(PrimitiveType::Vertex); ++i) {
127127
ve_accessor.index_access().scalar_attribute(i) = VE(i);
128-
v_flag_accessor.index_access().scalar_attribute(i) |= 0x1;
128+
v_flag_accessor.index_access().activate(i);
129129
}
130130
}
131131

@@ -239,31 +239,38 @@ bool EdgeMesh::is_connectivity_valid() const
239239
const attribute::Accessor<int64_t> ev_accessor = create_const_accessor<int64_t>(m_ev_handle);
240240
const attribute::Accessor<int64_t> ee_accessor = create_const_accessor<int64_t>(m_ee_handle);
241241
const attribute::Accessor<int64_t> ve_accessor = create_const_accessor<int64_t>(m_ve_handle);
242-
const attribute::Accessor<char> v_flag_accessor = get_flag_accessor(PrimitiveType::Vertex);
243-
const attribute::Accessor<char> e_flag_accessor = get_flag_accessor(PrimitiveType::Edge);
242+
const attribute::FlagAccessor<EdgeMesh> v_flag_accessor =
243+
get_flag_accessor(PrimitiveType::Vertex);
244+
const attribute::FlagAccessor<EdgeMesh> e_flag_accessor =
245+
get_flag_accessor(PrimitiveType::Edge);
244246

245247
// VE and EV
246248
for (int64_t i = 0; i < capacity(PrimitiveType::Vertex); ++i) {
247-
if (v_flag_accessor.index_access().const_scalar_attribute(i) == 0) {
248-
wmtk::logger().debug("Vertex {} is deleted", i);
249+
if (!v_flag_accessor.index_access().is_active(i)) {
249250
continue;
250251
}
251252
int cnt = 0;
252253
for (int64_t j = 0; j < 2; ++j) {
253254
if (ev_accessor.index_access().const_vector_attribute<2>(
254-
ve_accessor.index_access().const_scalar_attribute(i))[j] == i) {
255+
ve_accessor.index_access().const_scalar_attribute(i))(j) == i) {
255256
cnt++;
256257
}
257258
}
258259
if (cnt == 0) {
260+
int64_t idx = ve_accessor.index_access().const_scalar_attribute(i);
261+
wmtk::logger().error(
262+
"EV[VE[{}]={},:]] ({}) = doesn't contain {}",
263+
i,
264+
idx,
265+
fmt::join(ev_accessor.index_access().const_vector_attribute<2>(idx), ","),
266+
i);
259267
return false;
260268
}
261269
}
262270

263271
// EV and EE
264272
for (int64_t i = 0; i < capacity(PrimitiveType::Edge); ++i) {
265-
if (e_flag_accessor.index_access().const_scalar_attribute(i) == 0) {
266-
wmtk::logger().debug("Edge {} is deleted", i);
273+
if (!e_flag_accessor.index_access().is_active(i)) {
267274
continue;
268275
}
269276
// TODO: need to handle cornor case (self-loop)

src/wmtk/EdgeMeshOperationExecutor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void EdgeMesh::EdgeMeshOperationExecutor::delete_simplices()
3838
{
3939
for (size_t d = 0; d < simplex_ids_to_delete.size(); ++d) {
4040
for (const int64_t id : simplex_ids_to_delete[d]) {
41-
flag_accessors[d].index_access().scalar_attribute(id) = 0;
41+
flag_accessors[d].index_access().deactivate(id) ;
4242
}
4343
}
4444
}

src/wmtk/EdgeMeshOperationExecutor.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class EdgeMesh::EdgeMeshOperationExecutor : public operations::edge_mesh::EdgeOp
1111
void delete_simplices();
1212
void update_cell_hash();
1313

14-
std::array<attribute::Accessor<char>, 2> flag_accessors;
14+
std::array<attribute::FlagAccessor<EdgeMesh>, 2> flag_accessors;
1515
attribute::Accessor<int64_t, EdgeMesh> ee_accessor;
1616
attribute::Accessor<int64_t, EdgeMesh> ev_accessor;
1717
attribute::Accessor<int64_t, EdgeMesh> ve_accessor;

src/wmtk/Mesh.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ std::vector<simplex::IdSimplex> Mesh::get_all_id_simplex(
5656

5757
const int64_t cap = capacity(type);
5858

59-
const attribute::Accessor<char> flag_accessor = get_flag_accessor(type);
60-
const attribute::CachingAccessor<char>& flag_accessor_indices = flag_accessor.index_access();
59+
const attribute::FlagAccessor<> flag_accessor = get_flag_accessor(type);
60+
const attribute::IndexFlagAccessor<>& flag_accessor_indices = flag_accessor.index_access();
6161
ret.reserve(cap);
6262
for (size_t index = 0; index < cap; ++index) {
63-
if (flag_accessor_indices.const_scalar_attribute(index) & 1)
63+
if (flag_accessor_indices.is_active(index))
6464
ret.emplace_back(simplex::IdSimplex(type, index));
6565
else if (include_deleted)
6666
ret.emplace_back();
@@ -77,14 +77,15 @@ std::vector<Tuple> Mesh::get_all(PrimitiveType type, const bool include_deleted)
7777

7878
const int64_t cap = capacity(type);
7979

80-
const attribute::Accessor<char> flag_accessor = get_flag_accessor(type);
81-
const attribute::CachingAccessor<char>& flag_accessor_indices = flag_accessor.index_access();
80+
const attribute::FlagAccessor<> flag_accessor = get_flag_accessor(type);
81+
const attribute::IndexFlagAccessor<>& flag_accessor_indices = flag_accessor.index_access();
8282
ret.reserve(cap);
8383
for (size_t index = 0; index < cap; ++index) {
84-
if (flag_accessor_indices.const_scalar_attribute(index) & 1)
84+
if (flag_accessor_indices.is_active(index)) {
8585
ret.emplace_back(tuple_from_id(type, index));
86-
else if (include_deleted)
86+
} else if (include_deleted) {
8787
ret.emplace_back();
88+
}
8889
}
8990
return ret;
9091
}
@@ -137,7 +138,7 @@ bool Mesh::is_removed(int64_t index) const
137138
bool Mesh::is_removed(int64_t index, PrimitiveType pt) const
138139
{
139140
const auto& flag_accessor = get_const_flag_accessor(pt);
140-
return !(flag_accessor.index_access().const_scalar_attribute(index) & 0x1);
141+
return !flag_accessor.index_access().is_active(index);
141142
}
142143

143144
bool Mesh::is_valid(const simplex::Simplex& s) const
@@ -155,17 +156,19 @@ bool Mesh::is_valid(const simplex::Simplex& s) const
155156
}
156157

157158

158-
const attribute::Accessor<char> Mesh::get_flag_accessor(PrimitiveType type) const
159+
const attribute::FlagAccessor<Mesh> Mesh::get_flag_accessor(PrimitiveType type) const
159160
{
160161
return get_const_flag_accessor(type);
161162
}
162-
const attribute::Accessor<char> Mesh::get_const_flag_accessor(PrimitiveType type) const
163+
const attribute::FlagAccessor<Mesh> Mesh::get_const_flag_accessor(PrimitiveType type) const
163164
{
164-
return create_const_accessor(m_flag_handles.at(get_primitive_type_id(type)));
165+
return attribute::FlagAccessor<Mesh>(
166+
create_const_accessor(m_flag_handles.at(get_primitive_type_id(type))));
165167
}
166-
attribute::Accessor<char> Mesh::get_flag_accessor(PrimitiveType type)
168+
attribute::FlagAccessor<Mesh> Mesh::get_flag_accessor(PrimitiveType type)
167169
{
168-
return create_accessor(m_flag_handles.at(get_primitive_type_id(type)));
170+
return attribute::FlagAccessor<Mesh>(
171+
create_accessor(m_flag_handles.at(get_primitive_type_id(type))));
169172
}
170173

171174

src/wmtk/Mesh.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "attribute/AttributeScopeHandle.hpp"
2525
#include "attribute/MeshAttributeHandle.hpp"
2626
#include "attribute/MeshAttributes.hpp"
27+
#include "attribute/FlagAccessor.hpp"
2728
#include "multimesh/attribute/AttributeScopeHandle.hpp"
2829

2930
#include "multimesh/attribute/UseParentScopeRAII.hpp"
@@ -295,8 +296,8 @@ class Mesh : public std::enable_shared_from_this<Mesh>, public wmtk::utils::Merk
295296
decltype(auto) parent_scope(Functor&& f, Args&&... args) const;
296297

297298

298-
const attribute::Accessor<char> get_flag_accessor(PrimitiveType type) const;
299-
const attribute::Accessor<char> get_const_flag_accessor(PrimitiveType type) const;
299+
const attribute::FlagAccessor<Mesh> get_flag_accessor(PrimitiveType type) const;
300+
const attribute::FlagAccessor<Mesh> get_const_flag_accessor(PrimitiveType type) const;
300301

301302

302303
bool operator==(const Mesh& other) const;
@@ -307,7 +308,7 @@ class Mesh : public std::enable_shared_from_this<Mesh>, public wmtk::utils::Merk
307308
virtual std::vector<Tuple> orient_vertices(const Tuple& t) const = 0;
308309

309310
protected: // member functions
310-
attribute::Accessor<char> get_flag_accessor(PrimitiveType type);
311+
attribute::FlagAccessor<> get_flag_accessor(PrimitiveType type);
311312

312313

313314
protected:

src/wmtk/Mesh_attributes.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ std::vector<int64_t> Mesh::request_simplex_indices(PrimitiveType type, int64_t c
4747
int64_t current_capacity = capacity(type);
4848

4949
// enable newly requested simplices
50-
attribute::Accessor<char> flag_accessor = get_flag_accessor(type);
51-
int64_t max_size = flag_accessor.reserved_size();
50+
attribute::FlagAccessor<Mesh> flag_accessor = get_flag_accessor(type);
51+
int64_t max_size = flag_accessor.base_accessor().reserved_size();
5252

5353
if (current_capacity + count > max_size) {
5454
logger().warn(
@@ -71,11 +71,11 @@ std::vector<int64_t> Mesh::request_simplex_indices(PrimitiveType type, int64_t c
7171

7272
m_attribute_manager.m_capacities[primitive_id] = new_capacity;
7373

74-
attribute::CachingAccessor<char>& flag_accessor_indices = flag_accessor.index_access();
74+
attribute::IndexFlagAccessor<Mesh>& flag_accessor_indices = flag_accessor.index_access();
7575

7676
for (const int64_t simplex_index : ret) {
7777
// wmtk::logger().trace("Activating {}-simplex {}", primitive_id, simplex_index);
78-
flag_accessor_indices.scalar_attribute(simplex_index) |= 0x1;
78+
flag_accessor_indices.activate(simplex_index);
7979
}
8080

8181
return ret;
@@ -218,10 +218,10 @@ std::tuple<std::vector<std::vector<int64_t>>, std::vector<std::vector<int64_t>>>
218218

219219
// Initialize both maps
220220
for (int64_t d = 0; d < tcp; d++) {
221-
attribute::Accessor<char> flag_accessor =
221+
attribute::FlagAccessor<Mesh> flag_accessor =
222222
get_flag_accessor(wmtk::get_primitive_type_from_id(d));
223223
for (int64_t i = 0; i < capacity(wmtk::get_primitive_type_from_id(d)); ++i) {
224-
if (flag_accessor.index_access().scalar_attribute(i) & 1) {
224+
if (flag_accessor.index_access().is_active(i)) {
225225
old2new[d].push_back(new2old[d].size());
226226
new2old[d].push_back(old2new[d].size() - 1); // -1 since we just pushed into it
227227
} else {

src/wmtk/PointMesh.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ void PointMesh::initialize(int64_t count)
5252
{
5353
set_capacities({count});
5454
reserve_attributes_to_fit();
55-
attribute::Accessor<char> v_flag_accessor = get_flag_accessor(PrimitiveType::Vertex);
55+
attribute::FlagAccessor<PointMesh> v_flag_accessor = get_flag_accessor(PrimitiveType::Vertex);
5656
for (int64_t i = 0; i < capacity(PrimitiveType::Vertex); ++i) {
57-
v_flag_accessor.index_access().scalar_attribute(i) |= 0x1;
57+
v_flag_accessor.index_access().activate(i);
5858
}
5959
}
6060

0 commit comments

Comments
 (0)