Skip to content

Commit

Permalink
Build fixes (#766)
Browse files Browse the repository at this point in the history
* pip fix and few name cleanups
  • Loading branch information
mkstoyanov authored Feb 21, 2025
1 parent 42f0ebe commit ea771e1
Show file tree
Hide file tree
Showing 22 changed files with 203 additions and 184 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ set (_asgard_pdes continuity diffusion elliptic sinwav two_stream
foreach (_asgexe ${_asgard_pdes})
add_executable (${_asgexe} "${CMAKE_CURRENT_SOURCE_DIR}/src/${_asgexe}.cpp")
target_link_libraries (${_asgexe} PUBLIC libasgard)
install(TARGETS ${_asgexe} EXPORT "asgard-export" RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/share/asgard/pde")
install(TARGETS ${_asgexe} EXPORT "asgard-export" RUNTIME DESTINATION "share/asgard/pde")
endforeach()

#-------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion python/pipinstall/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from skbuild.cmaker import get_cmake_version
from skbuild import setup # This line replaces 'from setuptools import setup'

asg_ver = '0.7.0a3'
asg_ver = '0.7.0a4'

# Add CMake as a build requirement if cmake is not installed or too old
setup_requires = []
Expand Down
2 changes: 1 addition & 1 deletion src/asgard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void simulate(prog_opts const &options, verbosity_level verbosity = verbosity_le
{
auto discretization = discretize<pde_class>(options, verbosity);

advance_time(discretization);
discretization.advance_time();

discretization.save_final_snapshot();
}
Expand Down
22 changes: 11 additions & 11 deletions src/asgard_discretization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,15 @@ void discretization_manager<precision>::start_cold()

{ // setting up the time-step approach
// if no method is set, defaulting to explicit time-stepping
time_advance::method sm = options.step_method.value_or(time_advance::method::rk3);
time_method sm = options.step_method.value_or(time_method::rk3);

time_data<precision> dtime; // initialize below

precision stop = options.stop_time.value_or(-1);
precision dt = options.dt.value_or(-1);
int64_t n = options.num_time_steps.value_or(-1);

if (sm == time_advance::method::steady) {
if (sm == time_method::steady) {
stop = options.stop_time.value_or(options.default_stop_time.value_or(0));
dtime = time_data<precision>(stop);
} else {
Expand Down Expand Up @@ -294,8 +294,8 @@ void discretization_manager<precision>::start_cold()
}
}

if (stepper.needed_precon() == preconditioner_opts::adi) {
terms.build_matrices(sgrid, conn, hier, preconditioner_opts::adi,
if (stepper.needed_precon() == precon_method::adi) {
terms.build_matrices(sgrid, conn, hier, precon_method::adi,
0.5 * stepper.data.dt());
} else
terms.build_matrices(sgrid, conn, hier);
Expand Down Expand Up @@ -338,10 +338,10 @@ void discretization_manager<precision>::restart_from_file()
}
}

if (stepper.needed_precon() == preconditioner_opts::adi) {
if (stepper.needed_precon() == precon_method::adi) {
precision const substep
= (options.step_method.value() == time_advance::method::cn) ? 0.5 : 1;
terms.build_matrices(sgrid, conn, hier, preconditioner_opts::adi,
= (options.step_method.value() == time_method::cn) ? 0.5 : 1;
terms.build_matrices(sgrid, conn, hier, precon_method::adi,
substep * stepper.data.dt());
} else
terms.build_matrices(sgrid, conn, hier);
Expand Down Expand Up @@ -602,21 +602,21 @@ void discretization_manager<precision>::ode_sv(imex_flag imflag,
std::vector<precision> &x) const
{
auto const &options = pde->options();
solve_opts const solver = options.solver.value();
solver_method const solver = options.solver.value();

static fk::vector<precision> sol; // used by the iterative solvers

switch (solver)
{
case solve_opts::gmres:
case solve_opts::bicgstab: {
case solver_method::gmres:
case solver_method::bicgstab: {
kronops.make(imflag, *pde, matrices, grid);
precision const tolerance = *options.isolver_tolerance;
int const restart = *options.isolver_iterations;
int const max_iter = *options.isolver_inner_iterations;
sol.resize(static_cast<int>(x.size()));
std::copy(x.begin(), x.end(), sol.begin());
if (solver == solve_opts::gmres)
if (solver == solver_method::gmres)
solvers::simple_gmres_euler<precision, resource::host>(
pde->get_dt(), imflag, kronops, sol, x, restart, max_iter, tolerance);
else
Expand Down
8 changes: 4 additions & 4 deletions src/asgard_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ void h5manager<P>::write(PDEv2<P> const &pde, int degree, sparse_grid const &gri
}

{ // solver data section
H5Easy::dump(file, "solver_method", static_cast<int>(options.solver.value_or(solve_opts::direct)));
H5Easy::dump(file, "solver_method", static_cast<int>(options.solver.value_or(solver_method::direct)));
H5Easy::dump(file, "solver_itol", options.isolver_tolerance.value_or(-1));
H5Easy::dump(file, "solver_iter", options.isolver_iterations.value_or(-1));
H5Easy::dump(file, "solver_inner", options.isolver_inner_iterations.value_or(-1));
Expand Down Expand Up @@ -377,8 +377,8 @@ void h5manager<P>::read(std::string const &filename, bool silent, PDEv2<P> &pde,
pde.options_.degree = H5Easy::load<int>(file, "degree");

{ // reading time parameters
time_advance::method sm = pde.options_.step_method.value_or(
static_cast<time_advance::method>(H5Easy::load<int>(file, std::string("dtime_smethod"))));
time_method sm = pde.options_.step_method.value_or(
static_cast<time_method>(H5Easy::load<int>(file, std::string("dtime_smethod"))));

P const stop = pde.options_.stop_time.value_or(-1);
P const dt = pde.options_.dt.value_or(-1);
Expand Down Expand Up @@ -502,7 +502,7 @@ void h5manager<P>::read(std::string const &filename, bool silent, PDEv2<P> &pde,

{ // solver data section
if (not pde.options_.solver)
pde.options_.solver = static_cast<solve_opts>(H5Easy::load<int>(file, "solver_method"));
pde.options_.solver = static_cast<solver_method>(H5Easy::load<int>(file, "solver_method"));
if (not pde.options_.isolver_tolerance) {
pde.options_.isolver_tolerance = H5Easy::load<double>(file, "solver_itol");
if (pde.options_.isolver_tolerance.value() < 0)
Expand Down
40 changes: 20 additions & 20 deletions src/asgard_program_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,25 +349,25 @@ void prog_opts::process_inputs(std::vector<std::string_view> const &argv, handle
if (not selected)
throw std::runtime_error(report_no_value());
if (*selected == "steady")
step_method = time_advance::method::steady;
step_method = time_method::steady;
else if (*selected == "forward-euler" or *selected == "fe" or *selected == "rk1")
step_method = time_advance::method::forward_euler;
step_method = time_method::forward_euler;
else if (*selected == "rk2")
step_method = time_advance::method::rk2;
step_method = time_method::rk2;
else if (*selected == "rk3")
step_method = time_advance::method::rk3;
step_method = time_method::rk3;
else if (*selected == "rk4")
step_method = time_advance::method::rk4;
step_method = time_method::rk4;
else if (*selected == "cn" or *selected == "crank-nicolson")
step_method = time_advance::method::cn;
step_method = time_method::cn;
else if (*selected == "be" or *selected == "backward-euler")
step_method = time_advance::method::back_euler;
step_method = time_method::back_euler;
else if (*selected == "expl")
step_method = time_advance::method::exp;
step_method = time_method::exp;
else if (*selected == "impl")
step_method = time_advance::method::imp;
step_method = time_method::imp;
else if (*selected == "imex")
step_method = time_advance::method::imex;
step_method = time_method::imex;
else {
throw std::runtime_error(report_wrong_value());
}
Expand Down Expand Up @@ -503,11 +503,11 @@ void prog_opts::process_inputs(std::vector<std::string_view> const &argv, handle
if (not selected)
throw std::runtime_error(report_no_value());
if (*selected == "direct")
solver = solve_opts::direct;
solver = solver_method::direct;
else if (*selected == "gmres")
solver = solve_opts::gmres;
solver = solver_method::gmres;
else if (*selected == "bicgstab")
solver = solve_opts::bicgstab;
solver = solver_method::bicgstab;
else
throw std::runtime_error(report_wrong_value());
}
Expand All @@ -518,11 +518,11 @@ void prog_opts::process_inputs(std::vector<std::string_view> const &argv, handle
if (not selected)
throw std::runtime_error(report_no_value());
if (*selected == "none")
precon = preconditioner_opts::none;
precon = precon_method::none;
else if (*selected == "jacobi")
precon = preconditioner_opts::jacobi;
precon = precon_method::jacobi;
else if (*selected == "adi")
precon = preconditioner_opts::adi;
precon = precon_method::adi;
else
throw std::runtime_error(report_wrong_value());
}
Expand Down Expand Up @@ -805,16 +805,16 @@ void prog_opts::print_options(std::ostream &os) const
if (step_method)
switch (step_method.value())
{
case time_advance::method::rk3:
case time_method::rk3:
os << " method: RK3\n";
break;
case time_advance::method::cn:
case time_method::cn:
os << " method: Crank-Nicolson\n";
break;
case time_advance::method::imex:
case time_method::imex:
os << " method: IMEX\n";
break;
case time_advance::method::imp:
case time_method::imp:
os << " method: Backward Euler\n";
break;
default:
Expand Down
27 changes: 12 additions & 15 deletions src/asgard_program_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ enum class verbosity_level
* \ingroup asgard_common_options
* \brief the available solvers for implicit time stepping
*/
enum class solve_opts
enum class solver_method
{
//! direct solve using LAPACK, slow but stable
direct,
Expand All @@ -63,7 +63,7 @@ enum class solve_opts
* \ingroup asgard_common_options
* \brief the available preconditioners for the solvers
*/
enum class preconditioner_opts
enum class precon_method
{
//! probably not a good idea for an iterative solve
none = 0,
Expand Down Expand Up @@ -175,13 +175,11 @@ enum class grid_type
mixed
};

namespace time_advance
{
/*!
* \ingroup asgard_common_options
* types of time time advance methods, declared here to be used in the program options
* types of time advance methods, declared here to be used in the program options
*/
enum class method
enum class time_method
{
//! steady state solution, not a time-stepping method
steady = 0,
Expand All @@ -204,7 +202,6 @@ enum class method
//! implicit-explicit scheme for nonlinear Vlasov-Poisson problems
imex
};
} // namespace time_advance

/*!
* \ingroup asgard_common_options
Expand Down Expand Up @@ -416,7 +413,7 @@ struct prog_opts
std::optional<adapt_norm> anorm;

//! time stepping method, explicit, implicit or imex
std::optional<time_advance::method> step_method;
std::optional<time_method> step_method;
//! final time for the integration
std::optional<double> stop_time;
//! fixed time step, if missing the default cfl condition will be used
Expand All @@ -428,9 +425,9 @@ struct prog_opts
std::optional<int> wavelet_output_freq;

//! solver for implicit or imex methods: direct, gmres, bicgstab
std::optional<solve_opts> solver;
std::optional<solver_method> solver;
//! preconditioner, used for iterative solvers
std::optional<preconditioner_opts> precon;
std::optional<precon_method> precon;
//! tolerance for the iterative solvers (gmres, bicgstab)
std::optional<double> isolver_tolerance;
//! max number of iterations (inner iterations for gmres)
Expand Down Expand Up @@ -617,14 +614,14 @@ struct prog_opts
}

//! sets the step-method but issues a warning if a method is already provided
void force_step_method(time_advance::method method)
void force_step_method(time_method method)
{
if (step_method)
std::cerr << "warning: overriding the user-requested -step-method" << std::endl;
step_method = method;
}
//! sets the step-method but issues a warning if a method is already provided
void force_solver(solve_opts method)
void force_solver(solver_method method)
{
if (solver)
std::cerr << "warning: overriding the user-requested -solver" << std::endl;
Expand All @@ -639,11 +636,11 @@ struct prog_opts
//! used in place of stop time, if stop time is not provided
std::optional<double> default_stop_time;
//! used in place of the step method, if step method is provided
std::optional<time_advance::method> default_step_method;
std::optional<time_method> default_step_method;
//! used in place of the solver type, if solver type is not provided
std::optional<solve_opts> default_solver;
std::optional<solver_method> default_solver;
//! used in place of the preconditioner type, if preconditioner is not specified
std::optional<preconditioner_opts> default_precon;
std::optional<precon_method> default_precon;
//! used in place of the tolerance, if tolerance is not specified
std::optional<double> default_isolver_tolerance;
//! max number of iterations (inner iterations for gmres)
Expand Down
42 changes: 21 additions & 21 deletions src/asgard_program_options_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,37 +39,37 @@ TEST_CASE("new program options", "[single options]")
"invalid value for -s, see exe -help");
prog_opts prog(vecstrview({"", "-s", "expl"}));
REQUIRE(prog.step_method);
REQUIRE(*prog.step_method == time_advance::method::exp);
REQUIRE(*prog.step_method == time_method::exp);
prog = prog_opts(vecstrview({"", "-s", "impl"}));
REQUIRE(prog.step_method);
REQUIRE(*prog.step_method == time_advance::method::imp);
REQUIRE(*prog.step_method == time_method::imp);
REQUIRE(prog_opts(vecstrview({"", "-s", "imex"})).step_method.value()
== time_advance::method::imex);
== time_method::imex);

prog = prog_opts(vecstrview({"", "-s", "impl"}));
std::cerr << "generating a warning about -step-method, ignore since it is part of the test\n";
prog.force_step_method(time_advance::method::imex);
prog.force_step_method(time_method::imex);
REQUIRE(prog.step_method);
REQUIRE(*prog.step_method == time_advance::method::imex);
REQUIRE(*prog.step_method == time_method::imex);

REQUIRE(prog_opts(vecstrview({"exe", "-s", "steady"})).step_method);
REQUIRE(prog_opts(vecstrview({"exe", "-s", "steady"})).step_method.value() == time_advance::method::steady);
REQUIRE(prog_opts(vecstrview({"exe", "-s", "steady"})).step_method.value() == time_method::steady);
REQUIRE(prog_opts(vecstrview({"exe", "-s", "fe"})).step_method);
REQUIRE(prog_opts(vecstrview({"exe", "-s", "fe"})).step_method.value() == time_advance::method::forward_euler);
REQUIRE(prog_opts(vecstrview({"exe", "-s", "fe"})).step_method.value() == time_method::forward_euler);
REQUIRE(prog_opts(vecstrview({"exe", "-s", "forward-euler"})).step_method);
REQUIRE(prog_opts(vecstrview({"exe", "-s", "forward-euler"})).step_method.value() == time_advance::method::forward_euler);
REQUIRE(prog_opts(vecstrview({"exe", "-s", "forward-euler"})).step_method.value() == time_method::forward_euler);
REQUIRE(prog_opts(vecstrview({"exe", "-s", "rk2"})).step_method);
REQUIRE(prog_opts(vecstrview({"exe", "-s", "rk2"})).step_method.value() == time_advance::method::rk2);
REQUIRE(prog_opts(vecstrview({"exe", "-s", "rk2"})).step_method.value() == time_method::rk2);
REQUIRE(prog_opts(vecstrview({"exe", "-s", "rk3"})).step_method);
REQUIRE(prog_opts(vecstrview({"exe", "-s", "rk3"})).step_method.value() == time_advance::method::rk3);
REQUIRE(prog_opts(vecstrview({"exe", "-s", "rk3"})).step_method.value() == time_method::rk3);
REQUIRE(prog_opts(vecstrview({"exe", "-s", "rk4"})).step_method);
REQUIRE(prog_opts(vecstrview({"exe", "-s", "rk4"})).step_method.value() == time_advance::method::rk4);
REQUIRE(prog_opts(vecstrview({"exe", "-s", "rk4"})).step_method.value() == time_method::rk4);
REQUIRE(prog_opts(vecstrview({"exe", "-s", "cn"})).step_method);
REQUIRE(prog_opts(vecstrview({"exe", "-s", "cn"})).step_method.value() == time_advance::method::cn);
REQUIRE(prog_opts(vecstrview({"exe", "-s", "crank-nicolson"})).step_method.value() == time_advance::method::cn);
REQUIRE(prog_opts(vecstrview({"exe", "-s", "cn"})).step_method.value() == time_method::cn);
REQUIRE(prog_opts(vecstrview({"exe", "-s", "crank-nicolson"})).step_method.value() == time_method::cn);
REQUIRE(prog_opts(vecstrview({"exe", "-s", "be"})).step_method);
REQUIRE(prog_opts(vecstrview({"exe", "-s", "be"})).step_method.value() == time_advance::method::back_euler);
REQUIRE(prog_opts(vecstrview({"exe", "-s", "backward-euler"})).step_method.value() == time_advance::method::back_euler);
REQUIRE(prog_opts(vecstrview({"exe", "-s", "be"})).step_method.value() == time_method::back_euler);
REQUIRE(prog_opts(vecstrview({"exe", "-s", "backward-euler"})).step_method.value() == time_method::back_euler);
}
SECTION("-adapt-norm")
{
Expand Down Expand Up @@ -208,17 +208,17 @@ TEST_CASE("new program options", "[single options]")
{
prog_opts prog(vecstrview({"", "-solver", "direct"}));
REQUIRE(prog.solver);
REQUIRE(prog.solver.value() == solve_opts::direct);
REQUIRE(prog_opts(vecstrview({"exe", "-sv", "gmres"})).solver.value() == solve_opts::gmres);
REQUIRE(prog_opts(vecstrview({"exe", "-solver", "bicgstab"})).solver.value() == solve_opts::bicgstab);
REQUIRE(prog.solver.value() == solver_method::direct);
REQUIRE(prog_opts(vecstrview({"exe", "-sv", "gmres"})).solver.value() == solver_method::gmres);
REQUIRE(prog_opts(vecstrview({"exe", "-solver", "bicgstab"})).solver.value() == solver_method::bicgstab);
REQUIRE_THROWS_WITH(prog_opts(vecstrview({"exe", "-solver", "dummy"})),
"invalid value for -solver, see exe -help");

prog = prog_opts(vecstrview({"", "-dt", "0.1"}));
REQUIRE_FALSE(prog.solver);
prog.force_solver(solve_opts::gmres);
prog.force_solver(solver_method::gmres);
REQUIRE(prog.solver);
REQUIRE(*prog.solver == solve_opts::gmres);
REQUIRE(*prog.solver == solver_method::gmres);
}
SECTION("-memory")
{
Expand Down Expand Up @@ -344,7 +344,7 @@ TEST_CASE("input file processing", "[file i/o]")
REQUIRE(prog.grid);
REQUIRE(prog.grid.value() == grid_type::dense);
REQUIRE(prog.step_method);
REQUIRE(prog.step_method.value() == time_advance::method::exp);
REQUIRE(prog.step_method.value() == time_method::exp);

REQUIRE_FALSE(prog.file_value<int>("missing"));
auto bbool = prog.file_value<bool>("bb1");
Expand Down
Loading

0 comments on commit ea771e1

Please sign in to comment.