diff --git a/demos/FiniteVolume/AMR_Burgers_Hat.cpp b/demos/FiniteVolume/AMR_Burgers_Hat.cpp index 4d65d2391..d8a4ae043 100644 --- a/demos/FiniteVolume/AMR_Burgers_Hat.cpp +++ b/demos/FiniteVolume/AMR_Burgers_Hat.cpp @@ -274,7 +274,7 @@ int main(int argc, char* argv[]) tag.resize(); AMR_criteria(phi, tag); samurai::graduation(tag, stencil_grad); - if (samurai::update_field(tag, phi)) + if (samurai::update_field_mr(tag, phi)) { break; } diff --git a/demos/FiniteVolume/level_set.cpp b/demos/FiniteVolume/level_set.cpp index 825698eb9..8b58b6728 100644 --- a/demos/FiniteVolume/level_set.cpp +++ b/demos/FiniteVolume/level_set.cpp @@ -336,7 +336,7 @@ int main(int argc, char* argv[]) AMR_criteria(phi, tag); samurai::graduation(tag, stencil_grad); samurai::update_ghost(phi, u); - if ((samurai::update_field(tag, phi, u))) + if ((samurai::update_field_mr(tag, phi, u))) { break; } diff --git a/demos/FiniteVolume/level_set_from_scratch.cpp b/demos/FiniteVolume/level_set_from_scratch.cpp index 38ff27524..d14f13c90 100644 --- a/demos/FiniteVolume/level_set_from_scratch.cpp +++ b/demos/FiniteVolume/level_set_from_scratch.cpp @@ -58,6 +58,7 @@ struct AMRConfig static constexpr std::size_t max_refinement_level = 20; static constexpr int max_stencil_width = 2; static constexpr int ghost_width = 2; + static constexpr int graduation_width = 2; static constexpr std::size_t prediction_order = 1; using interval_t = samurai::Interval; using mesh_id_t = SimpleID; @@ -86,6 +87,11 @@ class AMRMesh : public samurai::Mesh_base, Config> { } + inline AMRMesh(const ca_type& ca, const self_type& ref_mesh) + : base_type(ca, ref_mesh) + { + } + inline AMRMesh(const cl_type& cl, std::size_t min_level, std::size_t max_level) : base_type(cl, min_level, max_level) { @@ -408,7 +414,7 @@ bool update_mesh(Field& f, Field_u& u, Tag& tag) return true; } - samurai::update_field(tag, f, u); + samurai::update_field_mr(tag, f, u); tag.mesh().swap(new_mesh); return false; diff --git a/include/samurai/algorithm/graduation.hpp b/include/samurai/algorithm/graduation.hpp index d749f3201..1c729f8bd 100644 --- a/include/samurai/algorithm/graduation.hpp +++ b/include/samurai/algorithm/graduation.hpp @@ -315,9 +315,9 @@ namespace samurai } // end for } - template + template size_t make_graduation(CellArray& ca, - [[maybe_unused]] const std::vector>& mpi_neighbourhood, + [[maybe_unused]] const Subdomains& mpi_neighbourhood, const std::array& is_periodic, const std::array& nb_cells_finest_level, const size_t grad_width = 1) diff --git a/include/samurai/algorithm/update.hpp b/include/samurai/algorithm/update.hpp index d6c6436ed..5ae2a8df5 100644 --- a/include/samurai/algorithm/update.hpp +++ b/include/samurai/algorithm/update.hpp @@ -746,77 +746,6 @@ namespace samurai } } - template - bool update_field(Tag& tag, Fields&... fields) - { - static constexpr std::size_t dim = Tag::dim; - using mesh_t = typename Tag::mesh_t; - using size_type = typename Tag::size_type; - using mesh_id_t = typename Tag::mesh_t::mesh_id_t; - using cl_type = typename Tag::mesh_t::cl_type; - - auto& mesh = tag.mesh(); - - cl_type cl; - - for_each_interval(mesh[mesh_id_t::cells], - [&](std::size_t level, const auto& interval, const auto& index) - { - auto itag = static_cast(interval.start + interval.index); - for (auto i = interval.start; i < interval.end; ++i) - { - if (tag[itag] & static_cast(CellFlag::refine)) - { - if (level < mesh.max_level()) - { - static_nested_loop( - [&](const auto& stencil) - { - auto new_index = 2 * index + stencil; - cl[level + 1][new_index].add_interval({2 * i, 2 * i + 2}); - }); - } - else - { - cl[level][index].add_point(i); - } - } - else if (tag[itag] & static_cast(CellFlag::keep)) - { - cl[level][index].add_point(i); - } - else if (tag[itag] & static_cast(CellFlag::coarsen)) - { - if (level > mesh.min_level()) - { - cl[level - 1][index >> 1].add_point(i >> 1); - } - else - { - cl[level][index].add_point(i); - } - } - itag++; - } - }); - - mesh_t new_mesh = {cl, mesh}; - -#ifdef SAMURAI_WITH_MPI - mpi::communicator world; - if (mpi::all_reduce(world, mesh == new_mesh, std::logical_and())) -#else - if (mesh == new_mesh) -#endif - { - return true; - } - - detail::update_fields(new_mesh, fields...); - tag.mesh().swap(new_mesh); - return false; - } - template bool update_field_mr(const Tag& tag, Field& field, Fields&... other_fields) { diff --git a/include/samurai/mesh.hpp b/include/samurai/mesh.hpp index cf8f74e24..0da094e48 100644 --- a/include/samurai/mesh.hpp +++ b/include/samurai/mesh.hpp @@ -105,9 +105,9 @@ namespace samurai const lca_type& subdomain() const; const ca_type& get_union() const; bool is_periodic(std::size_t d) const; - const std::array& periodicity() const; + const auto& periodicity() const; // std::vector& neighbouring_ranks(); - std::vector& mpi_neighbourhood(); + const auto& mpi_neighbourhood() const; void swap(Mesh_base& mesh) noexcept; @@ -565,13 +565,13 @@ namespace samurai } template - inline auto Mesh_base::periodicity() const -> const std::array& + inline const auto& Mesh_base::periodicity() const { return m_periodic; } template - inline auto Mesh_base::mpi_neighbourhood() -> std::vector& + inline const auto& Mesh_base::mpi_neighbourhood() const { return m_mpi_neighbourhood; } diff --git a/include/samurai/mr/adapt.hpp b/include/samurai/mr/adapt.hpp index 215a661b7..86175b592 100644 --- a/include/samurai/mr/adapt.hpp +++ b/include/samurai/mr/adapt.hpp @@ -303,39 +303,8 @@ namespace samurai keep_subset.apply_op(maximum(m_tag)); } - using ca_type = typename mesh_t::ca_type; - // return update_field_mr(m_tag, m_fields, other_fields...); - // for some reason I do not understand the above code produces the following error : - // C++ exception with description "Incompatible dimension of arrays, compile in DEBUG for more info" thrown in the test body - // on test adapt_test/2.mutliple_fields with: - // linux-mamba (clang-18, ubuntu-24.04, clang, clang-18, clang-18, clang++-18) - // while the code bellow do not. - const auto& min_indices = mesh.domain().min_indices(); - const auto& max_indices = mesh.domain().max_indices(); - - std::array nb_cells_finest_level; - - for (size_t d = 0; d != max_indices.size(); ++d) - { - nb_cells_finest_level[d] = max_indices[d] - min_indices[d]; - } - - ca_type new_ca = update_cell_array_from_tag(mesh[mesh_id_t::cells], m_tag); - make_graduation(new_ca, mesh.mpi_neighbourhood(), mesh.periodicity(), nb_cells_finest_level, mesh_t::config::graduation_width); - mesh_t new_mesh{new_ca, mesh}; -#ifdef SAMURAI_WITH_MPI - mpi::communicator world; - if (mpi::all_reduce(world, mesh == new_mesh, std::logical_and())) -#else - if (mesh == new_mesh) -#endif // SAMURAI_WITH_MPI - { - return true; - } - detail::update_fields(new_mesh, m_fields, other_fields...); - m_fields.mesh().swap(new_mesh); - return false; + return update_field_mr(m_tag, m_fields, other_fields...); } template