20 #define WMTK_MESH_VISITOR_ONLY_SUPPORTS_NONCONST_REFERENCE
25 template <
typename MMVisitor>
26 class MultiMeshSimplexVisitorExecutor;
28 template <
int64_t cell_dimension_,
typename NodeFunctor_>
37 !wmtk::utils::metaprogramming::
38 all_return_void_v<NodeFunctor, MeshVariantTraits, simplex::Simplex>;
51 #if defined(WMTK_MESH_VISITOR_ONLY_SUPPORTS_NONCONST_REFERENCE)
52 template <
typename MeshType>
54 template <
typename MeshType>
57 template <
bool IsConst,
typename MeshType>
58 using GetReturnType_t =
typename TypeHelper::template ReturnType<IsConst, MeshType>;
59 template <
bool IsConst,
typename MeshType>
60 constexpr
static bool HasReturnValue_v = !std::is_void_v<GetReturnType_t<IsConst, MeshType>>;
81 template <
typename MMVisitor_>
93 template <
typename MeshType>
97 !std::is_same_v<std::decay_t<MeshType>,
Mesh>,
98 "Don't pass in a mesh, use variant/visitor to get its derived type");
100 exec.
execute(std::forward<MeshType>(mesh), simplex);
125 std::visit([&](
auto&& root) {
execute_mesh(root.get(), root_simplex); }, mesh_root_variant);
138 conditional_t<HasReturnCache, typename ReturnDataType::KeyType, std::tuple<const Mesh*>>;
146 template <
typename MMVisitor>
153 template <
typename T>
164 !wmtk::utils::metaprogramming::
165 all_return_void_v<NodeFunctor, MeshVariantTraits, simplex::Simplex>;
174 conditional_t<HasReturnCache, typename ReturnDataType::KeyType, std::tuple<const Mesh*>>;
186 template <
typename MeshType>
189 static_assert(std::is_base_of_v<
Mesh, std::decay_t<MeshType>>);
190 run(std::forward<MeshType>(mesh), simplex);
199 template <
typename MeshType_>
202 assert(current_mesh.is_valid(simplex.
tuple()));
203 using MeshType = std::decay_t<MeshType_>;
207 constexpr
static int64_t MeshDim = wmtk::utils::metaprogramming::cell_dimension_v<MeshType>;
211 #if defined(WMTK_MESH_VISITOR_ONLY_SUPPORTS_NONCONST_REFERENCE)
214 constexpr
static bool CurIsConst = std::is_const_v<MeshType>;
218 constexpr
static bool CurHasReturn = !std::is_void_v<CurReturnType>;
222 auto& child_datas = current_mesh.m_multi_mesh_manager.children();
223 std::vector<std::vector<simplex::NavigatableSimplex>> mapped_child_simplices;
224 mapped_child_simplices.reserve(child_datas.size());
233 std::back_inserter(mapped_child_simplices),
234 [&](
const auto& child_data) {
235 Mesh& child_mesh = *child_data.mesh;
237 const std::vector<simplex::Simplex> _r =
238 current_mesh.map_to_child(child_mesh, simplex);
239 std::vector<simplex::NavigatableSimplex> r;
243 std::back_inserter(r),
244 [&](const simplex::Simplex& s) {
245 return simplex::NavigatableSimplex(child_mesh, s);
248 for (
const auto& s : r) {
249 assert(child_mesh.is_valid(s.tuple()));
259 for (
size_t child_index = 0; child_index < child_datas.size(); ++child_index) {
260 auto&& child_data = child_datas[child_index];
261 auto&& simplices = mapped_child_simplices[child_index];
262 Mesh& child_mesh_base = *child_data.mesh;
265 for (
const auto& s : simplices) {
266 assert(child_mesh_base.
is_valid(s.tuple()));
270 auto child_mesh_variant =
273 [&](
auto&& child_mesh_) noexcept {
274 auto&& child_mesh = child_mesh_.get();
275 using ChildType = std::decay_t<decltype(child_mesh)>;
276 #if defined(WMTK_MESH_VISITOR_ONLY_SUPPORTS_NONCONST_REFERENCE)
277 using ChildReturnType = GetReturnType_t<ChildType>;
279 constexpr
static bool ChildIsConst = std::is_const_v<ChildType>;
280 using ChildReturnType = GetReturnType_t<ChildIsConst, ChildType>;
283 constexpr
static bool ChildHasReturn = !std::is_void_v<ChildReturnType>;
284 constexpr
static int64_t ChildDim =
285 wmtk::utils::metaprogramming::cell_dimension_v<ChildType>;
293 assert(MeshDim >= ChildDim);
295 if constexpr (MeshDim >= ChildDim) {
297 assert(child_mesh.is_valid(child_simplex.tuple()));
299 run(child_mesh, child_simplex);
302 auto parent_id =
m_return_data.get_id(current_mesh, simplex);
303 auto child_id =
m_return_data.get_id(child_mesh, child_simplex);
322 if constexpr (CurHasReturn) {
323 auto current_return =
visitor.m_node_functor(current_mesh, simplex);
325 m_return_data.add(std::move(current_return), current_mesh, simplex);
327 visitor.m_node_functor(current_mesh, simplex);
333 template <
int64_t cell_dimension,
typename NodeFunctor>
337 template <
typename NodeFunctor>
virtual bool is_valid(const Tuple &tuple) const
check validity of tuple including its hash
simplex::Simplex map_to_root(const simplex::Simplex &my_simplex) const
maps a simplex from this mesh to the root mesh
Mesh & get_multi_mesh_root()
returns a reference to the root of a multimesh tree
std::conditional_t< HasReturnCache, typename ReturnDataType::KeyType, std::tuple< const Mesh * > > KeyType
constexpr static int64_t cell_dimension
MultiMeshSimplexVisitorExecutor(const MMVisitor &v)
const MMVisitor & visitor
void run(MeshType_ &¤t_mesh, const simplex::NavigatableSimplex &simplex)
void execute(MeshType &&mesh, const simplex::NavigatableSimplex &simplex)
wmtk::utils::metaprogramming::MeshVariantTraits MeshVariantTraits
typename MMVisitor::template GetReturnType_t< T > GetReturnType_t
wmtk::utils::metaprogramming::ReferenceWrappedFunctorReturnCacheCustomComparator< NodeFunctor, MeshVariantTraits, wmtk::simplex::utils::MeshSimplexComparator, simplex::NavigatableSimplex > ReturnDataType
constexpr static bool HasReturnCache
ReturnDataType m_return_data
typename MMVisitor::NodeFunctor NodeFunctor
std::vector< std::tuple< KeyType, KeyType > > edge_events
void execute_from_root(Mesh &mesh, const simplex::NavigatableSimplex &simplex)
const auto & edge_events() const
std::vector< std::tuple< KeyType, KeyType > > m_edge_events
constexpr static bool HasReturnCache
void execute_mesh(MeshType &&mesh, const simplex::NavigatableSimplex &simplex)
typename TypeHelper::template ReturnType< MeshType > GetReturnType_t
MultiMeshSimplexVisitor(std::integral_constant< int64_t, cell_dimension >, NodeFunctor &&f)
constexpr static bool HasReturnValue_v
wmtk::utils::metaprogramming::ReferenceWrappedFunctorReturnCacheCustomComparator< NodeFunctor, MeshVariantTraits, wmtk::simplex::utils::MeshSimplexComparator, simplex::NavigatableSimplex > ReturnDataType
constexpr static int64_t cell_dimension
wmtk::utils::metaprogramming::MeshVariantTraits MeshVariantTraits
NodeFunctor m_node_functor
const CacheType & cache() const
MultiMeshSimplexVisitor(NodeFunctor &&f)
std::conditional_t< HasReturnCache, typename ReturnDataType::KeyType, std::tuple< const Mesh * > > KeyType
const Tuple & tuple() const
const Tuple & tuple() const
MultiMeshSimplexVisitor(NodeFunctor &&) -> MultiMeshSimplexVisitor< 0, NodeFunctor >