Skip to content

Commit

Permalink
Remove const
Browse files Browse the repository at this point in the history
  • Loading branch information
pmatalon committed Jan 29, 2025
1 parent f52e44b commit c144e23
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 30 deletions.
4 changes: 2 additions & 2 deletions include/samurai/petsc/block_assembly.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ namespace samurai

explicit BlockAssemblyBase(const block_operator_t& block_op)
: m_block_operator(block_op)
, m_assembly_ops(transform(block_op.operators(),
[](const auto& op)
, m_assembly_ops(transform(m_block_operator.operators(),
[](auto& op)
{
return make_assembly(op);
}))
Expand Down
7 changes: 6 additions & 1 deletion include/samurai/petsc/fv/FV_scheme_assembly.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ namespace samurai
this->set_name(scheme.name());
}

auto& scheme() const
auto& scheme()
{
return m_scheme;
}

const auto& scheme() const
{
return m_scheme;
}
Expand Down
11 changes: 8 additions & 3 deletions include/samurai/petsc/fv/operator_sum_assembly.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ namespace samurai

private:

const scheme_t* m_sum_scheme;
scheme_t* m_sum_scheme;

std::tuple<Assembly<Operators>...> m_assembly_ops;

public:

explicit Assembly(const scheme_t& sum_scheme)
explicit Assembly(scheme_t& sum_scheme)
: m_sum_scheme(&sum_scheme)
, m_assembly_ops(transform(sum_scheme.operators(),
[](const auto& op)
[](auto& op)
{
return make_assembly(op);
}))
Expand Down Expand Up @@ -67,6 +67,11 @@ namespace samurai
});
}

auto& scheme()
{
return *m_sum_scheme;
}

auto& scheme() const
{
return *m_sum_scheme;
Expand Down
2 changes: 1 addition & 1 deletion include/samurai/petsc/linear_block_solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace samurai

static constexpr bool is_monolithic = monolithic;

explicit LinearBlockSolver(const block_operator_t& block_op)
explicit LinearBlockSolver(block_operator_t& block_op)
: base_class(block_op)
{
_configure_solver();
Expand Down
4 changes: 2 additions & 2 deletions include/samurai/petsc/linear_solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace samurai

public:

explicit LinearSolverBase(const scheme_t& scheme)
explicit LinearSolverBase(scheme_t& scheme)
: m_assembly(scheme)
{
_configure_solver();
Expand Down Expand Up @@ -252,7 +252,7 @@ namespace samurai

public:

explicit LinearSolver(const scheme_t& scheme)
explicit LinearSolver(scheme_t& scheme)
: base_class(scheme)
{
_configure_solver();
Expand Down
4 changes: 2 additions & 2 deletions include/samurai/petsc/matrix_assembly.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,11 @@ namespace samurai
};

template <class Scheme>
auto make_assembly(const Scheme& s)
auto make_assembly(Scheme& s)
{
if constexpr (std::is_base_of_v<MatrixAssembly, Scheme>)
{
return *reinterpret_cast<const Assembly<Scheme>*>(&s);
return *reinterpret_cast<Assembly<Scheme>*>(&s);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions include/samurai/petsc/nonlinear_solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace samurai

public:

explicit NonLinearSolverBase(const scheme_t& scheme)
explicit NonLinearSolverBase(scheme_t& scheme)
: m_assembly(scheme)
{
_configure_solver();
Expand Down Expand Up @@ -308,7 +308,7 @@ namespace samurai
using base_class::m_is_set_up;
using base_class::m_J;

explicit NonLinearSolver(const scheme_t& scheme)
explicit NonLinearSolver(scheme_t& scheme)
: base_class(scheme)
{
}
Expand Down
22 changes: 15 additions & 7 deletions include/samurai/petsc/solver_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,36 @@ namespace samurai

// Linear solver
template <class Scheme, std::enable_if_t<Scheme::cfg_t::scheme_type != SchemeType::NonLinear, bool> = true>
auto make_solver(const Scheme& scheme)
auto make_solver(Scheme& scheme)
{
return LinearSolver<Scheme>(scheme);
}

// Linear block solver (choice monolithic or not)
template <bool monolithic, std::size_t rows, std::size_t cols, class... Operators>
auto make_solver(const BlockOperator<rows, cols, Operators...>& block_operator)
auto make_solver(BlockOperator<rows, cols, Operators...>& block_operator)
{
return LinearBlockSolver<monolithic, rows, cols, Operators...>(block_operator);
}

// Linear block solver (monolithic)
template <std::size_t rows, std::size_t cols, class... Operators>
auto make_solver(const BlockOperator<rows, cols, Operators...>& block_operator)
auto make_solver(BlockOperator<rows, cols, Operators...>& block_operator)
{
static constexpr bool default_monolithic = true;
return make_solver<default_monolithic, rows, cols, Operators...>(block_operator);
}

// Non-linear solver
template <class Scheme, std::enable_if_t<Scheme::cfg_t::scheme_type == SchemeType::NonLinear, bool> = true>
auto make_solver(const Scheme& scheme)
auto make_solver(Scheme& scheme)
{
return NonLinearSolver<Scheme>(scheme);
}

// Non-linear local solvers
template <class cfg, class bdry_cfg, std::enable_if_t<cfg::scheme_type == SchemeType::NonLinear && cfg::stencil_size == 1, bool> = true>
auto make_solver(const CellBasedScheme<cfg, bdry_cfg>& scheme)
auto make_solver(CellBasedScheme<cfg, bdry_cfg>& scheme)
{
return NonLinearLocalSolvers<CellBasedScheme<cfg, bdry_cfg>>(scheme);
}
Expand All @@ -53,18 +53,26 @@ namespace samurai
*/

template <class Scheme>
void solve(const Scheme& scheme, typename Scheme::field_t& unknown, typename Scheme::field_t& rhs)
void solve(Scheme& scheme, typename Scheme::field_t& unknown, typename Scheme::field_t& rhs)
{
auto solver = make_solver(scheme);
solver.solve(unknown, rhs);
}

template <class Scheme, class E>
void solve(const Scheme& scheme, typename Scheme::field_t& unknown, const field_expression<E>& rhs_expression)
void solve(Scheme& scheme, typename Scheme::field_t& unknown, const field_expression<E>& rhs_expression)
{
typename Scheme::field_t rhs = rhs_expression;
solve(scheme, unknown, rhs);
}

template <class Scheme>
void solve(Scheme&& scheme, typename Scheme::field_t& unknown, typename Scheme::field_t& rhs)
{
Scheme scheme_ = std::move(scheme);
auto solver = make_solver(scheme_);
solver.solve(unknown, rhs);
}

} // end namespace petsc
} // end namespace samurai
7 changes: 6 additions & 1 deletion include/samurai/schemes/block_operator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ namespace samurai
static_assert(n_operators == rows * cols, "The number of operators must correspond to rows*cols.");
}

auto& operators() const
const auto& operators() const
{
return m_operators;
}

auto& operators()
{
return m_operators;
}
Expand Down
10 changes: 5 additions & 5 deletions include/samurai/schemes/fv/explicit_operator_sum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ namespace samurai
using size_type = typename base_class::size_type;
using base_class::scheme;

explicit Explicit(const scheme_t& sum_scheme)
explicit Explicit(scheme_t& sum_scheme)
: base_class(sum_scheme)
{
}

void apply(output_field_t& output_field, input_field_t& input_field) const override
void apply(output_field_t& output_field, input_field_t& input_field) override
{
for_each(scheme().operators(),
[&](const auto& op)
[&](auto& op)
{
op.apply(output_field, input_field);
});
}

void apply(std::size_t d, output_field_t& output_field, input_field_t& input_field) const override
void apply(std::size_t d, output_field_t& output_field, input_field_t& input_field) override
{
for_each(scheme().operators(),
[&](const auto& op)
[&](auto& op)
{
op.apply(d, output_field, input_field);
});
Expand Down
6 changes: 3 additions & 3 deletions include/samurai/schemes/fv/scheme_operators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,19 @@ namespace samurai
return ss.str();
}

auto operator()(input_field_t& input_field) const
auto operator()(input_field_t& input_field)
{
auto explicit_scheme = make_explicit(*this);
return explicit_scheme.apply_to(input_field);
}

auto operator()(std::size_t d, input_field_t& input_field) const
auto operator()(std::size_t d, input_field_t& input_field)
{
auto explicit_scheme = make_explicit(*this);
return explicit_scheme.apply_to(d, input_field);
}

void apply(output_field_t& output_field, input_field_t& input_field) const
void apply(output_field_t& output_field, input_field_t& input_field)
{
auto explicit_scheme = make_explicit(*this);
explicit_scheme.apply(output_field, input_field);
Expand Down
14 changes: 13 additions & 1 deletion include/samurai/static_algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ namespace samurai
template <typename... Ts, typename Func, size_t... Is>
auto transform_impl(const std::tuple<Ts...>& t, Func&& f, std::index_sequence<Is...>)
{
return std::tuple<std::invoke_result_t<Func, Ts>...>{f(std::get<Is>(t))...};
return std::make_tuple(f(std::get<Is>(t))...);
}

template <typename... Ts, typename Func>
Expand All @@ -160,6 +160,18 @@ namespace samurai
return transform_impl(t, std::forward<Func>(f), std::make_index_sequence<sizeof...(Ts)>{});
}

template <typename... Ts, typename Func, size_t... Is>
auto transform_impl(std::tuple<Ts...>& t, Func&& f, std::index_sequence<Is...>)
{
return std::make_tuple(f(std::get<Is>(t))...);
}

template <typename... Ts, typename Func>
auto transform(std::tuple<Ts...>& t, Func&& f)
{
return transform_impl(t, std::forward<Func>(f), std::make_index_sequence<sizeof...(Ts)>{});
}

/**
* Static for loop
*/
Expand Down

0 comments on commit c144e23

Please sign in to comment.