diff --git a/.github/workflows/gui.yml b/.github/workflows/gui.yml index 9309c2eb2..8a7d79f3f 100644 --- a/.github/workflows/gui.yml +++ b/.github/workflows/gui.yml @@ -14,12 +14,12 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up Node.js - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: - node-version: '20' + node-version: '22' - name: Install dependencies working-directory: tests/cypress @@ -43,7 +43,7 @@ jobs: FLASK_ENV: development - name: Run Cypress tests - uses: cypress-io/github-action@v5 + uses: cypress-io/github-action@v6 with: start: npm start working-directory: tests/cypress diff --git a/src/algebra/Integrator.cpp b/src/algebra/Integrator.cpp index ab01c100d..f1a1f8312 100644 --- a/src/algebra/Integrator.cpp +++ b/src/algebra/Integrator.cpp @@ -4,7 +4,7 @@ #include "Integrator.h" Integrator::Integrator(Model* model, double time_step_size, double rho, - double atol, int max_iter) { + double atol, int max_iter, bool max_iter_warning) { this->model = model; alpha_m = 0.5 * (3.0 - rho) / (1.0 + rho); alpha_f = 1.0 / (1.0 + rho); @@ -19,6 +19,7 @@ Integrator::Integrator(Model* model, double time_step_size, double rho, this->time_step_size = time_step_size; this->atol = atol; this->max_iter = max_iter; + this->max_iter_warning = max_iter_warning; y_af = Eigen::Matrix(size); ydot_am = Eigen::Matrix(size); @@ -82,9 +83,13 @@ State Integrator::step(const State& old_state, double time) { // Abort if maximum number of non-linear iterations is reached else if (i == max_iter - 1) { - throw std::runtime_error( + if (max_iter_warning) { + std::cout << "Warning: Maximum number of non-linear iterations reached at time " << time << std::endl; + } else { + throw std::runtime_error( "Maximum number of non-linear iterations reached at time " + std::to_string(time)); + } } // Evaluate Jacobian diff --git a/src/algebra/Integrator.h b/src/algebra/Integrator.h index 0876ff763..eca90136b 100644 --- a/src/algebra/Integrator.h +++ b/src/algebra/Integrator.h @@ -34,6 +34,7 @@ class Integrator { double y_coeff_jacobian{0.0}; double atol{0.0}; int max_iter{0}; + bool max_iter_warning{false}; int size{0}; int n_iter{0}; int n_nonlin_iter{0}; @@ -51,9 +52,11 @@ class Integrator { * @param rho Spectral radius for generalized-alpha step * @param atol Absolut tolerance for non-linear iteration termination * @param max_iter Maximum number of non-linear iterations + * @param max_iter_warning If true, print a warning instead of throwing error + * when maximum iterations is reached */ Integrator(Model* model, double time_step_size, double rho, double atol, - int max_iter); + int max_iter, bool max_iter_warning = false); /** * @brief Construct a new Integrator object diff --git a/src/solve/SimulationParameters.cpp b/src/solve/SimulationParameters.cpp index 036609994..c5cdc8a14 100644 --- a/src/solve/SimulationParameters.cpp +++ b/src/solve/SimulationParameters.cpp @@ -237,6 +237,8 @@ SimulationParameters load_simulation_params(const nlohmann::json& config) { } sim_params.sim_abs_tol = sim_config.value("absolute_tolerance", 1e-8); sim_params.sim_nliter = sim_config.value("maximum_nonlinear_iterations", 30); + sim_params.sim_max_iter_warning = + sim_config.value("max_iter_warning", false); sim_params.sim_steady_initial = sim_config.value("steady_initial", true); sim_params.sim_rho_infty = sim_config.value("rho_infty", 0.5); sim_params.output_variable_based = diff --git a/src/solve/SimulationParameters.h b/src/solve/SimulationParameters.h index b84b2845a..6999a9010 100644 --- a/src/solve/SimulationParameters.h +++ b/src/solve/SimulationParameters.h @@ -67,6 +67,9 @@ struct SimulationParameters { false}; ///< Running 0D simulation coupled with external solver double sim_external_step_size{0.0}; ///< Step size of external solver if ///< running coupled + bool sim_max_iter_warning{ + false}; ///< If true, warn instead of throwing when max nonlinear + ///< iterations is reached }; /// @brief Wrapper class for nlohmann:json with error checking diff --git a/src/solve/Solver.cpp b/src/solve/Solver.cpp index 7f9bf06a7..07317f55f 100644 --- a/src/solve/Solver.cpp +++ b/src/solve/Solver.cpp @@ -87,7 +87,8 @@ void Solver::setup_integrator() { DEBUG_MSG("Setup time integration"); integrator = Integrator(this->model.get(), simparams.sim_time_step_size, simparams.sim_rho_infty, simparams.sim_abs_tol, - simparams.sim_nliter); + simparams.sim_nliter, + simparams.sim_max_iter_warning); // Initialize loop states = std::vector(); diff --git a/tests/cases/chamber_sphere.json b/tests/cases/chamber_sphere.json index 4936ccf09..f2bb937a8 100644 --- a/tests/cases/chamber_sphere.json +++ b/tests/cases/chamber_sphere.json @@ -26,7 +26,8 @@ "steady_initial": false, "output_variable_based": true, "absolute_tolerance": 1e-9, - "output_all_cycles": true + "output_all_cycles": true, + "max_iter_warning": false }, "vessels": [ {