2 #include <fmt/format.h>
18 return fmt::format(
"CollapseNewAttributeStrategy[{}]", m_handle.name());
26 default: [[fallthrough]];
28 if constexpr (std::is_same_v<T, double> || std::is_same_v<T, Rational>) {
35 if (!bs[1] && bs[0]) {
43 if (!bs[0] && bs[1]) {
52 return (a + b) / T(2);
62 throw std::runtime_error(
"Collapse should have a new attribute");
74 default: [[fallthrough]];
79 if (!bs[1] && bs[0]) {
87 if (!bs[0] && bs[1]) {
106 throw std::runtime_error(
"Collapse should have a new attribute");
114 template <
typename T>
118 , m_collapse_op(nullptr)
120 assert(h.
holds<T>());
131 std::make_unique<edge_mesh::CollapseNewAttributeTopoInfo>(
static_cast<EdgeMesh&
>(
mesh));
134 std::make_unique<tri_mesh::CollapseNewAttributeTopoInfo>(
static_cast<TriMesh&
>(
mesh));
137 std::make_unique<tet_mesh::CollapseNewAttributeTopoInfo>(
static_cast<TetMesh&
>(
mesh));
139 throw std::runtime_error(
"Invalid mesh");
143 template <
typename T>
149 if (!
bool(m_collapse_op)) {
152 assert(!mesh().is_free());
154 if (op_datas.find(&mesh()) == op_datas.end())
return;
155 assert(&mesh() == &m);
156 const std::vector<std::tuple<simplex::NavigatableSimplex, Tuple>>& tuple_pairs =
157 op_datas.at(&mesh());
162 for (
const auto& tuple_pair : tuple_pairs) {
164 const Tuple& output_tuple = std::get<1>(tuple_pair);
167 const auto& return_data_variant = data.get_variant(mesh(), input_simplex);
172 m_topo_info->merged_simplices(return_data_variant, input_simplex.
tuple(), pt);
173 auto new_simps = m_topo_info->new_simplices(return_data_variant, output_tuple, pt);
176 assert(merged_simps.size() == new_simps.size());
178 for (
size_t s = 0; s < merged_simps.size(); ++s) {
179 assign_collapsed(acc, merged_simps[s], new_simps[s]);
186 template <
typename T>
189 const std::array<Tuple, 2>& input_simplices,
190 const Tuple& final_simplex)
const
192 if (!
bool(m_collapse_op)) {
196 auto old_values = m_handle.mesh().parent_scope([&]() {
197 return std::make_tuple(
202 const auto old_pred = this->evaluate_predicate(acc.
primitive_type(), input_simplices);
205 std::tie(a, b) = old_values;
209 new_value = m_collapse_op(a, b, old_pred);
213 template <
typename T>
216 m_collapse_op = std::move(f);
217 m_will_throw =
false;
219 template <
typename T>
222 set_strategy(standard_collapse_strategy(optype));
227 template <
typename T>
230 return m_handle.mesh();
232 template <
typename T>
235 return m_handle.primitive_type();
237 template <
typename T>
242 template <
typename T>
246 return handle == m_handle;
attribute::Accessor< T, Mesh, D > create_accessor(const attribute::MeshAttributeHandle &handle)
PrimitiveType top_simplex_type() const
A CachingAccessor that uses tuples for accessing attributes instead of indices.
MapResult< D > vector_attribute(const ArgType &t)
PrimitiveType primitive_type() const
ConstMapResult< D > const_vector_attribute(const ArgType &t) const
wmtk::multimesh::operations::OperationInOutData OperationInOutData
wmtk::multimesh::operations::CollapseReturnData ReturnData
CollapseNewAttributeStrategy(const wmtk::attribute::MeshAttributeHandle &h)
std::string name() const final override
void update(Mesh &m, const ReturnData &ret_data, const OperationInOutData &tuples) const override
bool matches_attribute(const attribute::MeshAttributeHandle &) const override
std::unique_ptr< CollapseNewAttributeTopoInfo > m_topo_info
static CollapseFuncType standard_collapse_strategy(CollapseBasicStrategy optype)
wmtk::attribute::MeshAttributeHandle m_handle
void update_handle_mesh(Mesh &m) override
std::function< VecType(const VecType &, const VecType &, const std::bitset< 2 > &)> CollapseFuncType
bool invalid_state() const final override
PrimitiveType primitive_type() const override
void set_strategy(CollapseFuncType &&f)
void assign_collapsed(wmtk::attribute::Accessor< T > &acc, const std::array< Tuple, 2 > &input_simplices, const Tuple &final_simplex) const
const Tuple & tuple() const