Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demos/FiniteVolume/AMR_Burgers_Hat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion demos/FiniteVolume/level_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 7 additions & 1 deletion demos/FiniteVolume/level_set_from_scratch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>;
using mesh_id_t = SimpleID;
Expand Down Expand Up @@ -86,6 +87,11 @@ class AMRMesh : public samurai::Mesh_base<AMRMesh<Config>, 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)
{
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions include/samurai/algorithm/graduation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,9 @@ namespace samurai
} // end for
}

template <std::size_t dim, class TInterval, class MeshType, size_t max_size>
template <std::size_t dim, class TInterval, size_t max_size, class Subdomains>
size_t make_graduation(CellArray<dim, TInterval, max_size>& ca,
[[maybe_unused]] const std::vector<MPI_Subdomain<MeshType>>& mpi_neighbourhood,
[[maybe_unused]] const Subdomains& mpi_neighbourhood,
const std::array<bool, dim>& is_periodic,
const std::array<int, dim>& nb_cells_finest_level,
const size_t grad_width = 1)
Expand Down
71 changes: 0 additions & 71 deletions include/samurai/algorithm/update.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -746,77 +746,6 @@ namespace samurai
}
}

template <class Tag, class... Fields>
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<size_type>(interval.start + interval.index);
for (auto i = interval.start; i < interval.end; ++i)
{
if (tag[itag] & static_cast<int>(CellFlag::refine))
{
if (level < mesh.max_level())
{
static_nested_loop<dim - 1, 0, 2>(
[&](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<int>(CellFlag::keep))
{
cl[level][index].add_point(i);
}
else if (tag[itag] & static_cast<int>(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 <class Tag, class Field, class... Fields>
bool update_field_mr(const Tag& tag, Field& field, Fields&... other_fields)
{
Expand Down
8 changes: 4 additions & 4 deletions include/samurai/mesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool, dim>& periodicity() const;
const auto& periodicity() const;
// std::vector<int>& neighbouring_ranks();
std::vector<mpi_subdomain_t>& mpi_neighbourhood();
const auto& mpi_neighbourhood() const;

void swap(Mesh_base& mesh) noexcept;

Expand Down Expand Up @@ -565,13 +565,13 @@ namespace samurai
}

template <class D, class Config>
inline auto Mesh_base<D, Config>::periodicity() const -> const std::array<bool, dim>&
inline const auto& Mesh_base<D, Config>::periodicity() const
{
return m_periodic;
}

template <class D, class Config>
inline auto Mesh_base<D, Config>::mpi_neighbourhood() -> std::vector<mpi_subdomain_t>&
inline const auto& Mesh_base<D, Config>::mpi_neighbourhood() const
{
return m_mpi_neighbourhood;
}
Expand Down
33 changes: 1 addition & 32 deletions include/samurai/mr/adapt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, mesh_t::dim> 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 <class... TFields>
Expand Down
Loading