Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: change return type of some function to keep expressions #68

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
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
4 changes: 1 addition & 3 deletions ponio/examples/belousov_zhabotinsky_pirock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,7 @@ main( int argc, char** argv )

auto pb = ponio::make_imex_operator_problem( fd, fr, fr_t );

auto pirock = ponio::runge_kutta::pirock::pirock<1>( ponio::runge_kutta::pirock::beta_0<double>(),
eigmax_computer,
ponio::shampine_trick::shampine_trick<decltype( u_ini )>() );
auto pirock = ponio::runge_kutta::pirock::pirock<1>( ponio::runge_kutta::pirock::beta_0<double>(), eigmax_computer );

// time loop -------------------------------------------------------------
auto sol_range = ponio::make_solver_range( pb, pirock, u_ini, t_span, dt );
Expand Down
2 changes: 1 addition & 1 deletion ponio/examples/heat_rock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ main()
} );

auto pb_heat = heat_model( dx, xmin, xmax );
auto eigmax_computer = [=]( heat_model&, double, std::valarray<double>&, double )
auto eigmax_computer = [=]( auto&, double, std::valarray<double>&, double )
{
return 4. / ( dx * dx );
};
Expand Down
10 changes: 5 additions & 5 deletions ponio/examples/heat_samurai.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
name = "heat_samurai"
data_dir = name+"_data"

# make = subprocess.Popen(["make", name])
# make.wait()
make = subprocess.Popen(["make", name])
make.wait()

# args = [os.path.join(".", name)]
# process = subprocess.Popen(args)
# process.wait()
args = [os.path.join(".", name)]
process = subprocess.Popen(args)
process.wait()


def read_file(filename: str):
Expand Down
9 changes: 8 additions & 1 deletion ponio/examples/lorenz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
#include <ponio/solver.hpp>
#include <ponio/time_span.hpp>

template <std::size_t I, typename array_coeff_t>
auto
f( std::valarray<double> const& x, std::valarray<double> const& y, double const& a, array_coeff_t const& coeff )
{
return x + a * coeff * y;
}

int
main( int, char** )
{
Expand All @@ -24,7 +31,7 @@ main( int, char** )
double const rho = 28.;
double const beta = 8. / 3.;

auto lorenz = [=]( double, state_t const& u ) -> state_t
auto lorenz = [=]( double, auto const& u ) -> state_t
{
auto du1 = sigma * ( u[1] - u[0] );
auto du2 = rho * u[0] - u[1] - u[0] * u[2];
Expand Down
10 changes: 5 additions & 5 deletions ponio/include/ponio/detail.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ namespace detail

/* tpl_inner_product */
template <typename state_t, typename value_t, typename ArrayA_t, typename ArrayB_t, std::size_t... Is>
constexpr state_t
inline constexpr auto
tpl_inner_product_impl( ArrayA_t const& a,
ArrayB_t const& b,
state_t const& init,
[[maybe_unused]] value_t mul_coeff,
[[maybe_unused]] value_t const& mul_coeff,
std::index_sequence<Is...> )
{
return ( init + ... + ( mul_coeff * a[Is] * b[Is] ) );
return ( init + ... + ( mul_coeff * ( a[Is] * b[Is] ) ) );
}

/**
Expand All @@ -86,8 +86,8 @@ namespace detail
* @details This function compute \f$\texttt{init} + \sum_{i=0}^N \texttt{mul_coeff}a_ib_i\f$ without loop thanks to template.
*/
template <std::size_t N, typename state_t, typename value_t, typename ArrayA_t, typename ArrayB_t>
constexpr state_t
tpl_inner_product( ArrayA_t const& a, ArrayB_t const& b, state_t const& init, value_t mul_coeff = value_t{ 1.0 } )
inline constexpr auto
tpl_inner_product( ArrayA_t const& a, ArrayB_t const& b, state_t const& init, value_t const& mul_coeff )
{
return tpl_inner_product_impl( a, b, init, mul_coeff, std::make_index_sequence<N>() );
}
Expand Down
10 changes: 5 additions & 5 deletions ponio/include/ponio/method.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace ponio
*/
method( Algorithm_t const& alg_, state_t const& shadow_of_u0 )
: alg( alg_ )
, kis( ::detail::init_fill_array<std::tuple_size<step_storage_t>::value>( shadow_of_u0 ) )
, kis( ::detail::init_fill_array<std::tuple_size_v<step_storage_t>>( shadow_of_u0 ) )
{
}

Expand Down Expand Up @@ -128,7 +128,7 @@ namespace ponio
std::tuple<value_t, state_t, value_t>
_return( value_t tn, [[maybe_unused]] state_t const& un, value_t dt )
{
return std::make_tuple( tn + dt, kis.back(), dt );
return std::forward_as_tuple( tn + dt, kis.back(), dt );
}

template <typename value_t, typename Algo_t = Algorithm_t>
Expand All @@ -144,11 +144,11 @@ namespace ponio
if ( alg.info.error > alg.info.tolerance )
{
alg.info.success = false;
return std::make_tuple( tn, un, new_dt );
return std::forward_as_tuple( tn, un, new_dt );
}

alg.info.success = true;
return std::make_tuple( tn + dt, kis[Algorithm_t::N_stages], new_dt );
return std::forward_as_tuple( tn + dt, kis[Algorithm_t::N_stages], new_dt );
}

/**
Expand Down Expand Up @@ -207,7 +207,7 @@ namespace ponio

method( Algorithm_t const& alg_, state_t const& shadow_of_u0 )
: alg( alg_ )
, kis( ::detail::init_fill_array<std::tuple_size<step_storage_t>::value>( shadow_of_u0 ) )
, kis( ::detail::init_fill_array<std::tuple_size_v<step_storage_t>>( shadow_of_u0 ) )
{
}

Expand Down
48 changes: 24 additions & 24 deletions ponio/include/ponio/problem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ namespace ponio
simple_problem( Callable_t&& f_ );

template <typename state_t, typename value_t>
state_t
auto
operator()( value_t t, state_t&& u );

template <typename state_t, typename value_t>
state_t
auto
operator()( value_t t, state_t& u );
};

Expand All @@ -52,15 +52,15 @@ namespace ponio
*/
template <typename Callable_t>
template <typename state_t, typename value_t>
inline state_t
inline auto
simple_problem<Callable_t>::operator()( value_t t, state_t&& u )
{
return f( t, std::forward<state_t>( u ) );
}

template <typename Callable_t>
template <typename state_t, typename value_t>
inline state_t
inline auto
simple_problem<Callable_t>::operator()( value_t t, state_t& u )
{
return f( t, u );
Expand Down Expand Up @@ -175,14 +175,14 @@ namespace ponio
imex_problem( Callable_explicit_t&& f_explicit, Implicit_problem_t&& pb_implicit );

template <typename state_t, typename value_t>
state_t
auto
operator()( value_t t, state_t&& u )
{
return explicit_part( t, std::forward<state_t>( u ) ) + implicit_part( t, std::forward<state_t>( u ) );
}

template <typename state_t, typename value_t>
state_t
auto
operator()( value_t t, state_t& u )
{
return explicit_part( t, u ) + implicit_part( t, u );
Expand Down Expand Up @@ -254,7 +254,7 @@ namespace ponio
lawson_problem( Linear_t&& l_, Nonlinear_t&& n_ );

template <typename state_t, typename value_t>
state_t
auto
operator()( value_t t, state_t&& u );
};

Expand All @@ -278,7 +278,7 @@ namespace ponio
*/
template <typename Linear_t, typename Nonlinear_t>
template <typename state_t, typename value_t>
state_t
auto
lawson_problem<Linear_t, Nonlinear_t>::operator()( value_t t, state_t&& u )
{
return l * u + n( t, std::forward<state_t>( u ) );
Expand Down Expand Up @@ -311,35 +311,35 @@ namespace ponio
problem( Callables_t... args );

template <typename value_t, typename state_t, std::size_t... Is>
state_t
auto
_sum_components_impl( value_t t, state_t&& u, std::index_sequence<Is...> );

template <typename value_t, typename state_t, std::size_t... Is>
state_t
auto
_sum_components_impl( value_t t, state_t& u, std::index_sequence<Is...> );

template <typename value_t, typename state_t>
state_t
auto
operator()( value_t t, state_t&& u );

template <typename value_t, typename state_t>
state_t
auto
operator()( value_t t, state_t& u );

template <std::size_t I, typename value_t, typename state_t>
state_t
auto
operator()( std::integral_constant<std::size_t, I>, value_t t, state_t&& u );

template <std::size_t I, typename value_t, typename state_t>
state_t
auto
operator()( std::integral_constant<std::size_t, I>, value_t t, state_t& u );

template <std::size_t Index, typename value_t, typename state_t>
state_t
auto
call( value_t t, state_t&& u );

template <std::size_t Index, typename value_t, typename state_t>
state_t
auto
call( value_t t, state_t& u );
};

Expand All @@ -362,15 +362,15 @@ namespace ponio
*/
template <typename... Callables_t>
template <typename value_t, typename state_t, std::size_t... Is>
inline state_t
inline auto
problem<Callables_t...>::_sum_components_impl( value_t t, state_t&& u, std::index_sequence<Is...> )
{
return ( call<Is>( t, std::forward<state_t>( u ) ) + ... );
}

template <typename... Callables_t>
template <typename value_t, typename state_t, std::size_t... Is>
inline state_t
inline auto
problem<Callables_t...>::_sum_components_impl( value_t t, state_t& u, std::index_sequence<Is...> )
{
return ( call<Is>( t, u ) + ... );
Expand All @@ -384,15 +384,15 @@ namespace ponio
*/
template <typename... Callables_t>
template <typename value_t, typename state_t>
inline state_t
inline auto
problem<Callables_t...>::operator()( value_t t, state_t&& u )
{
return _sum_components_impl( t, std::forward<state_t>( u ), std::make_index_sequence<size>{} );
}

template <typename... Callables_t>
template <typename value_t, typename state_t>
inline state_t
inline auto
problem<Callables_t...>::operator()( value_t t, state_t& u )
{
return _sum_components_impl( t, u, std::make_index_sequence<size>{} );
Expand All @@ -408,15 +408,15 @@ namespace ponio
*/
template <typename... Callables_t>
template <std::size_t I, typename value_t, typename state_t>
inline state_t
inline auto
problem<Callables_t...>::operator()( std::integral_constant<std::size_t, I>, value_t t, state_t&& u )
{
return call<I>( t, std::forward<state_t>( u ) );
}

template <typename... Callables_t>
template <std::size_t I, typename value_t, typename state_t>
inline state_t
inline auto
problem<Callables_t...>::operator()( std::integral_constant<std::size_t, I>, value_t t, state_t& u )
{
return call<I>( t, u );
Expand All @@ -431,15 +431,15 @@ namespace ponio
*/
template <typename... Callables_t>
template <std::size_t Index, typename value_t, typename state_t>
inline state_t
inline auto
problem<Callables_t...>::call( value_t t, state_t&& u )
{
return std::get<Index>( system )( t, std::forward<state_t>( u ) );
}

template <typename... Callables_t>
template <std::size_t Index, typename value_t, typename state_t>
inline state_t
inline auto
problem<Callables_t...>::call( value_t t, state_t& u )
{
return std::get<Index>( system )( t, u );
Expand Down
16 changes: 8 additions & 8 deletions ponio/include/ponio/runge_kutta/dirk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ namespace ponio::runge_kutta::diagonal_implicit_runge_kutta

template <typename problem_t, typename state_t, typename array_ki_t, std::size_t I>
requires detail::problem_operator<problem_t, value_t>
state_t
stage( Stage<I>, problem_t& pb, value_t tn, state_t& un, array_ki_t const& Ki, value_t dt )
auto
stage( Stage<I>, problem_t& pb, value_t const& tn, state_t& un, array_ki_t const& Ki, value_t const& dt )
{
if constexpr ( I == 0 )
{
Expand All @@ -135,8 +135,8 @@ namespace ponio::runge_kutta::diagonal_implicit_runge_kutta

template <typename problem_t, typename state_t, typename array_ki_t, std::size_t I>
requires detail::problem_jacobian<problem_t, value_t, state_t>
state_t
stage( Stage<I>, problem_t& pb, value_t tn, state_t& un, array_ki_t const& Ki, value_t dt )
auto
stage( Stage<I>, problem_t& pb, value_t const& tn, state_t& un, array_ki_t const& Ki, value_t const& dt )
{
if constexpr ( I == 0 )
{
Expand Down Expand Up @@ -204,8 +204,8 @@ namespace ponio::runge_kutta::diagonal_implicit_runge_kutta
}

template <typename problem_t, typename state_t, typename array_ki_t>
state_t
stage( Stage<N_stages>, problem_t&, value_t, state_t& un, array_ki_t const& Ki, value_t dt )
auto
stage( Stage<N_stages>, problem_t&, value_t const&, state_t& un, array_ki_t const& Ki, value_t const& dt )
{
// last stage is always explicit and just equals to:
// $$
Expand All @@ -216,8 +216,8 @@ namespace ponio::runge_kutta::diagonal_implicit_runge_kutta

template <typename problem_t, typename state_t, typename array_ki_t, typename tab_t = tableau_t>
requires std::same_as<tab_t, tableau_t> && is_embedded
state_t
stage( Stage<N_stages + 1>, problem_t&, value_t, state_t& un, array_ki_t const& Ki, value_t dt )
auto
stage( Stage<N_stages + 1>, problem_t&, value_t const&, state_t& un, array_ki_t const& Ki, value_t const& dt )
{
return ::detail::tpl_inner_product<N_stages>( butcher.b2, Ki, un, dt );
}
Expand Down
12 changes: 6 additions & 6 deletions ponio/include/ponio/runge_kutta/erk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,23 @@ namespace ponio::runge_kutta::explicit_runge_kutta
}

template <typename problem_t, typename state_t, typename array_ki_t, std::size_t I>
state_t
stage( Stage<I>, problem_t& f, value_t tn, state_t& un, array_ki_t const& Ki, value_t dt )
auto
stage( Stage<I>, problem_t& f, value_t const& tn, state_t& un, array_ki_t const& Ki, value_t const& dt )
{
return f( tn + butcher.c[I] * dt, ::detail::tpl_inner_product<I>( butcher.A[I], Ki, un, dt ) );
}

template <typename problem_t, typename state_t, typename array_ki_t>
state_t
stage( Stage<N_stages>, problem_t&, value_t, state_t& un, array_ki_t const& Ki, value_t dt )
auto
stage( Stage<N_stages>, problem_t&, value_t const&, state_t& un, array_ki_t const& Ki, value_t const& dt )
{
return ::detail::tpl_inner_product<N_stages>( butcher.b, Ki, un, dt );
}

template <typename problem_t, typename state_t, typename array_ki_t, typename tab_t = tableau_t>
requires std::same_as<tab_t, tableau_t> && is_embedded
state_t
stage( Stage<N_stages + 1>, problem_t&, value_t, state_t& un, array_ki_t const& Ki, value_t dt )
auto
stage( Stage<N_stages + 1>, problem_t&, value_t const&, state_t& un, array_ki_t const& Ki, value_t const& dt )
{
return ::detail::tpl_inner_product<N_stages>( butcher.b2, Ki, un, dt );
}
Expand Down
Loading
Loading