Skip to content

Commit

Permalink
feat: add cell_in in functionBC (hpc-maths#121)
Browse files Browse the repository at this point in the history
- modify template parameter of a Cell
- add the cell inside the domain in the method which computes the values
in FunctionBC
  • Loading branch information
gouarin authored and pmatalon committed Sep 5, 2023
1 parent 8d91300 commit ec7dc80
Show file tree
Hide file tree
Showing 26 changed files with 225 additions and 226 deletions.
2 changes: 1 addition & 1 deletion demos/FiniteVolume/level_set_from_scratch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ bool update_mesh(Field& f, Field_u& u, Tag& tag)
samurai::for_each_interval(mesh[SimpleID::cells],
[&](std::size_t level, const auto& interval, const auto& index_yz)
{
auto itag = static_cast<std::size_t>(interval.start + interval.index);
auto itag = interval.start + interval.index;
for (int i = interval.start; i < interval.end; ++i)
{
if (tag[itag] & static_cast<int>(samurai::CellFlag::refine))
Expand Down
12 changes: 6 additions & 6 deletions demos/FiniteVolume/stokes_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ int main(int argc, char* argv[])

// Boundary conditions
samurai::make_bc<samurai::Dirichlet>(velocity,
[](const auto& coord)
[](const auto&, const auto& coord)
{
const auto& x = coord[0];
const auto& y = coord[1];
Expand All @@ -243,7 +243,7 @@ int main(int argc, char* argv[])
});

samurai::make_bc<samurai::Neumann>(pressure,
[](const auto& coord)
[](const auto&, const auto& coord)
{
const auto& x = coord[0];
const auto& y = coord[1];
Expand Down Expand Up @@ -396,12 +396,12 @@ int main(int argc, char* argv[])

// Boundary conditions
samurai::make_bc<samurai::Dirichlet>(velocity_np1,
[&](const auto& coord)
[&](const auto&, const auto& coord)
{
return exact_velocity(0, coord);
});
samurai::make_bc<samurai::Neumann>(pressure_np1,
[&](const auto& coord)
[&](const auto&, const auto& coord)
{
return exact_normal_grad_pressure(0, coord);
});
Expand Down Expand Up @@ -483,13 +483,13 @@ int main(int argc, char* argv[])
// Boundary conditions
velocity_np1.get_bc().clear();
samurai::make_bc<samurai::Dirichlet>(velocity_np1,
[&](const auto& coord)
[&](const auto&, const auto& coord)
{
return exact_velocity(t_np1, coord);
});
pressure_np1.get_bc().clear();
samurai::make_bc<samurai::Neumann>(pressure_np1,
[&](const auto& coord)
[&](const auto&, const auto& coord)
{
return exact_normal_grad_pressure(t_np1, coord);
});
Expand Down
2 changes: 1 addition & 1 deletion demos/highorder/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ int main(int argc, char* argv[])

auto u = samurai::make_field<double, 1>("u", mesh);
samurai::make_bc<samurai::Dirichlet>(u,
[](const auto& coord)
[](const auto&, const auto& coord)
{
const auto& x = coord[0];
const auto& y = coord[1];
Expand Down
27 changes: 16 additions & 11 deletions demos/multigrid/test_cases.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ class TestCase
public:

static constexpr std::size_t dim = Field::dim;
using coords = xt::xtensor_fixed<double, xt::xshape<dim>>;
using cell_t = typename Field::cell_t;
using coords_t = typename cell_t::coords_t;

using field_value_t = typename samurai::detail::return_type<double, Field::size>::type;
using field_function_t = typename samurai::FunctionBc<dim, double, Field::size>::function_t;
using boundary_cond_t = field_function_t;
using boundary_cond_t = typename samurai::FunctionBc<Field>::function_t;
using field_value_t = typename samurai::FunctionBc<Field>::value_t;
using field_function_t = std::function<field_value_t(const coords_t&)>;

virtual bool solution_is_known()
{
Expand Down Expand Up @@ -41,9 +42,12 @@ class TestCase
{
if (solution_is_known())
{
return solution();
return [&](const auto&, const auto& coords)
{
return solution()(coords);
};
}
return [](const coords&)
return [](const cell_t&, const coords_t&)
{
if constexpr (Field::size == 1)
{
Expand Down Expand Up @@ -80,7 +84,8 @@ class PolynomialTestCase : public TestCase<Field>
using field_value_t = typename TestCase<Field>::field_value_t;
using field_function_t = typename TestCase<Field>::field_function_t;
using boundary_cond_t = typename TestCase<Field>::boundary_cond_t;
using coords = typename TestCase<Field>::coords;
using coords_t = typename TestCase<Field>::coords_t;
using cell_t = typename TestCase<Field>::cell_t;

bool solution_is_known() override
{
Expand Down Expand Up @@ -145,7 +150,7 @@ class PolynomialTestCase : public TestCase<Field>

boundary_cond_t dirichlet() override
{
return [](const coords&)
return [](const cell_t&, const coords_t&)
{
if constexpr (Field::size == 1)
{
Expand All @@ -164,7 +169,7 @@ class PolynomialTestCase : public TestCase<Field>
{
if constexpr (dim == 1)
{
return [](const coords& coord)
return [](const auto&, const coords_t& coord)
{
const auto& x = coord[0];
if (x == 0 || x == 1)
Expand All @@ -180,11 +185,11 @@ class PolynomialTestCase : public TestCase<Field>
}
else if constexpr (dim == 2)
{
return [](const auto& coord)
return [](const auto&, const auto& coord)
{
const auto& x = coord[0];
const auto& y = coord[1];
double value;
double value = 0.;
if (x == 0 || x == 1)
{
value = y * (y - 1);
Expand Down
4 changes: 2 additions & 2 deletions demos/p4est/simple_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void refine_1(mesh_t& mesh, std::size_t max_level)
samurai::for_each_interval(mesh,
[&](std::size_t level, const auto& interval, const auto& index_yz)
{
auto itag = static_cast<std::size_t>(interval.start + interval.index);
auto itag = interval.start + interval.index;
for (coord_index_t i = interval.start; i < interval.end; ++i)
{
if (cell_tag[itag])
Expand Down Expand Up @@ -165,7 +165,7 @@ void refine_2(mesh_t& mesh, std::size_t max_level)
samurai::for_each_interval(mesh[mesh_id_t::cells],
[&](std::size_t level, const auto& interval, const auto& index_yz)
{
auto itag = static_cast<std::size_t>(interval.start + interval.index);
auto itag = interval.start + interval.index;
for (coord_index_t i = interval.start; i < interval.end; ++i)
{
if (cell_tag[itag])
Expand Down
2 changes: 1 addition & 1 deletion demos/pablo/bubble_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void update_mesh(Mesh& mesh,
samurai::for_each_interval(mesh,
[&](std::size_t level, const auto& interval, const auto& index_yz)
{
auto itag = static_cast<std::size_t>(interval.start + interval.index);
auto itag = interval.start + interval.index;
for (int i = interval.start; i < interval.end; ++i)
{
if (tag[itag] & static_cast<int>(samurai::CellFlag::refine))
Expand Down
2 changes: 1 addition & 1 deletion demos/tutorial/AMR_1D_Burgers/step_4/update_field.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void update_field(Field& f, const Tag& tag, Mesh& new_mesh)
samurai::for_each_interval(mesh[mesh_id_t::cells],
[&](std::size_t level, const auto& interval, const auto&)
{
auto itag = static_cast<std::size_t>(interval.start + interval.index);
auto itag = interval.start + interval.index;
for (coord_index_t i = interval.start; i < interval.end; ++i)
{
if (tag[itag] & static_cast<int>(samurai::CellFlag::refine))
Expand Down
2 changes: 1 addition & 1 deletion demos/tutorial/AMR_1D_Burgers/step_4/update_mesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ bool update_mesh(Field& f, const Tag& tag)
samurai::for_each_interval(mesh[mesh_id_t::cells],
[&](std::size_t level, const auto& interval, const auto&)
{
auto itag = static_cast<std::size_t>(interval.start + interval.index);
auto itag = interval.start + interval.index;
for (int i = interval.start; i < interval.end; ++i)
{
if (tag[itag] & static_cast<int>(samurai::CellFlag::refine))
Expand Down
2 changes: 1 addition & 1 deletion demos/tutorial/graduation_case_3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ int main(int argc, char* argv[])
[&](std::size_t level, const auto& interval, const auto& index)
{
auto j = index[0];
auto itag = static_cast<std::size_t>(interval.start + interval.index);
auto itag = interval.start + interval.index;
for (int i = interval.start; i < interval.end; ++i)
{
if (tag[itag] && level < max_level)
Expand Down
29 changes: 15 additions & 14 deletions include/samurai/algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,9 @@ namespace samurai
template <std::size_t dim, class TInterval, class Func>
inline void for_each_cell(const LevelCellArray<dim, TInterval>& lca, Func&& f)
{
using coord_index_t = typename TInterval::coord_index_t;
xt::xtensor_fixed<coord_index_t, xt::xshape<dim>> index;
using cell_t = Cell<dim, TInterval>;
using index_value_t = typename cell_t::value_t;
typename cell_t::indices_t index;

for (auto it = lca.cbegin(); it != lca.cend(); ++it)
{
Expand All @@ -169,10 +170,10 @@ namespace samurai
index[d + 1] = it.index()[d];
}

for (coord_index_t i = it->start; i < it->end; ++i)
for (index_value_t i = it->start; i < it->end; ++i)
{
index[0] = i;
Cell<coord_index_t, dim> cell{lca.level(), index, static_cast<std::size_t>(it->index + i)};
cell_t cell{lca.level(), index, it->index + i};
f(cell);
}
}
Expand All @@ -181,21 +182,20 @@ namespace samurai
template <std::size_t dim, class TInterval, class Func, class F, class... CT>
inline void for_each_cell(const LevelCellArray<dim, TInterval>& lca, subset_operator<F, CT...> set, Func&& f)
{
using set_t = subset_operator<F, CT...>;
using coord_index_t = typename set_t::coord_index_t;

xt::xtensor_fixed<coord_index_t, xt::xshape<dim>> index;
using cell_t = Cell<dim, TInterval>;
using index_value_t = typename cell_t::value_t;
typename cell_t::indices_t index;

set(
[&](const auto& interval, const auto& index_yz)
{
index[0] = interval.start;
auto cell_index = lca.get_index(index);
xt::view(index, xt::range(1, _)) = index_yz;
for (coord_index_t i = interval.start; i < interval.end; ++i)
for (index_value_t i = interval.start; i < interval.end; ++i)
{
index[0] = i;
Cell<coord_index_t, dim> cell{set.level(), index, cell_index++};
cell_t cell{set.level(), index, cell_index++};
f(cell);
}
});
Expand Down Expand Up @@ -223,18 +223,19 @@ namespace samurai
template <class Mesh, class coord_type, class Func>
inline void for_each_cell(const Mesh& mesh, std::size_t level, const typename Mesh::interval_t& i, const coord_type& index, Func&& f)
{
using coord_index_t = typename Mesh::interval_t::coord_index_t;
static constexpr std::size_t dim = Mesh::dim;
using cell_t = Cell<dim, typename Mesh::interval_t>;
using index_value_t = typename cell_t::value_t;
typename cell_t::indices_t coord;

xt::xtensor_fixed<coord_index_t, xt::xshape<dim>> coord;
coord[0] = i.start;
for (std::size_t d = 0; d < dim - 1; ++d)
{
coord[d + 1] = index[d];
}
auto cell_index = mesh.get_index(level, coord);
Cell<coord_index_t, dim> cell{level, coord, cell_index};
for (coord_index_t ii = 0; ii < static_cast<coord_index_t>(i.size()); ++ii)
cell_t cell{level, coord, cell_index};
for (index_value_t ii = 0; ii < static_cast<index_value_t>(i.size()); ++ii)
{
f(cell);
cell.indices[0]++; // increment x coordinate
Expand Down
4 changes: 2 additions & 2 deletions include/samurai/algorithm/update.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ namespace samurai
for_each_interval(mesh[mesh_id_t::cells],
[&](std::size_t level, const auto& interval, const auto& index)
{
auto itag = static_cast<std::size_t>(interval.start + interval.index);
auto itag = interval.start + interval.index;
for (auto i = interval.start; i < interval.end; ++i)
{
if (tag[itag] & static_cast<int>(CellFlag::refine))
Expand Down Expand Up @@ -555,7 +555,7 @@ namespace samurai
for_each_interval(mesh[mesh_id_t::cells],
[&](std::size_t level, const auto& interval, const auto& index)
{
auto itag = static_cast<std::size_t>(interval.start + interval.index);
auto itag = interval.start + interval.index;
for (value_t i = interval.start; i < interval.end; ++i)
{
if (tag[itag] & static_cast<int>(CellFlag::refine))
Expand Down
Loading

0 comments on commit ec7dc80

Please sign in to comment.