Skip to content

1570 Allow setting tolerance for last timestep in SystemIntegrator manually#1574

Open
annawendler wants to merge 1 commit into
mainfrom
1570-allow-setting-eps-in-systemintegrator-manually
Open

1570 Allow setting tolerance for last timestep in SystemIntegrator manually#1574
annawendler wants to merge 1 commit into
mainfrom
1570-allow-setting-eps-in-systemintegrator-manually

Conversation

@annawendler

@annawendler annawendler commented Jun 1, 2026

Copy link
Copy Markdown
Member

Changes and Information

  • Add setter and getter for last_step_tolerance that determines if an additional time step is made to reach tmax

Merge Request - Guideline Checklist

Please check our git workflow. Use the draft feature if the Pull Request is not yet ready to review.

Checks by code author

  • Every addressed issue is linked (use the "Closes #ISSUE" keyword below).
  • New code adheres to coding guidelines.
  • No large data files have been added (files should in sum not exceed 100 KB, avoid PDFs, Word docs, etc.).
  • Tests are added for new functionality and a local test run was successful (with and without OpenMP).
  • Appropriate documentation within the code (Doxygen) for new functionality has been added in the code.
  • Appropriate external documentation (ReadTheDocs) for new functionality has been added to the online documentation and checked in the preview.
  • Proper attention to licenses, especially no new third-party software with conflicting license has been added.
  • (For ABM development) Checked benchmark results and ran and posted a local test above from before and after development to ensure performance is monitored.

Checks by code reviewer(s)

  • Corresponding issue(s) is/are linked and addressed.
  • Code is clean of development artifacts (no deactivated or commented code lines, no debugging printouts, etc.).
  • Appropriate unit tests have been added, CI passes, code coverage and performance is acceptable (did not decrease).
  • No large data files added in the whole history of commits(files should in sum not exceed 100 KB, avoid PDFs, Word docs, etc.).
  • On merge, add 2-5 lines with the changes (main added features, changed items, or corrected bugs) to the merge-commit-message. This can be taken from the briefly-list-the-changes above (best case) or the separate commit messages (worst case).

Closes #1570

@annawendler annawendler linked an issue Jun 1, 2026 that may be closed by this pull request
2 tasks
@annawendler annawendler self-assigned this Jun 1, 2026
@codecov

codecov Bot commented Jun 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.46%. Comparing base (8851d5b) to head (3215278).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1574      +/-   ##
==========================================
- Coverage   97.47%   97.46%   -0.02%     
==========================================
  Files         190      190              
  Lines       15966    16037      +71     
==========================================
+ Hits        15563    15630      +67     
- Misses        403      407       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@annawendler annawendler changed the title 1570 Add setter and getter for last_step_tolerance 1570 Allow setting tolerance for last timestep in SystemIntegrator manually Jun 1, 2026

@reneSchm reneSchm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice addition, though I'd like some changes.

Comment on lines +171 to +174
FP& get_last_step_tolerance()
{
return m_integrator.get_last_step_tolerance();
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mashes two design philosophies. Either make a read-only getter (i.e. const FP& or simply FP) and a setter, or a read-write getter (without a setter). For integral types, which we can treat FP as, a read-write should be enough, as the setter won't do much.

Comment on lines +276 to +299
/**
* @brief Change the tolerance for the last time step.
* @param last_step_tolerance The new last_step_tolerance.
*/
void set_last_step_tolerance(FP last_step_tolerance)
{
m_last_step_tolerance = last_step_tolerance;
}

/**
* @brief Access the tolerance for the last time step.
* @return A reference to the last_step_tolerance.
* @{
*/
FP& get_last_step_tolerance()
{
return m_last_step_tolerance;
}

const FP& get_last_step_tolerance() const
{
return m_last_step_tolerance;
}
/** @} */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above

Comment on lines +101 to +102
sim.set_last_step_tolerance(new_tol);
EXPECT_EQ(sim.get_last_step_tolerance(), new_tol);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A more meaningful test would be to reproduce the issue you want to solve here.

A simplified set up should work too, e.g. make the simulation take a 0.8 step until 1.0, once with a 0.25 tolerance, and once with the default. Such that the first one stops at 0.8, the second at 1.0.

}
}

TEST(TestOdeIntegrator, integratorLastStepTolerance)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think running essentially the same test twice has little benefit, right? The other test should cover this sufficiently

FP t = t0;

for (size_t i = results.get_num_time_points() - 1; fabs((tmax - t) / (tmax - t0)) > eps; ++i) {
for (size_t i = results.get_num_time_points() - 1; fabs((tmax - t) / (tmax - t0)) > m_last_step_tolerance;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have (tmax - t) / (tmax - t0) <= 1 and (tmax - t) / (tmax - t0) --> 0.
So we should add a requirement that m_last_step_tolerance > FP{0.0}. I'd suggest an assert here as well as documentation on the getter.

@reneSchm reneSchm Jun 10, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is, for m_last_step_tolerance <= 0 we get an infinite loop, for m_last_step_tolerance >= 1, we simply don't do anything. So the valid range is (0, 1), though >=1 is less problematic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow setting tolerance for last timestep in SystemIntegrator manually

2 participants