Skip to content
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
8 changes: 4 additions & 4 deletions .github/workflows/gui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
9 changes: 7 additions & 2 deletions src/algebra/Integrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<double, Eigen::Dynamic, 1>(size);
ydot_am = Eigen::Matrix<double, Eigen::Dynamic, 1>(size);
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/algebra/Integrator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/solve/SimulationParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
3 changes: 3 additions & 0 deletions src/solve/SimulationParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/solve/Solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<State>();
Expand Down
3 changes: 2 additions & 1 deletion tests/cases/chamber_sphere.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down
Loading