Skip to content

- changed some asserts to throw - #4566

Closed
hnil wants to merge 1 commit into
OPM:masterfrom
hnil:changed_asserts_to_throw
Closed

- changed some asserts to throw#4566
hnil wants to merge 1 commit into
OPM:masterfrom
hnil:changed_asserts_to_throw

Conversation

@hnil

@hnil hnil commented Mar 29, 2023

Copy link
Copy Markdown
Member
  • changing asserts which may happen due to input to throw.

@akva2 akva2 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.

Looks fine but I would prefer more explicit conditionals.

resultDelta = gridView.comm().sum(resultDelta);
resultDenom = gridView.comm().sum(resultDenom);

if (!(std::isfinite(resultDelta) && std::isfinite(resultDenom))) {

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.

! || ! is more readable imo.

++current_step_;
current_time_ += dt_;
assert(dt_ > 0);
if(!(dt_ > 0)){

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.

<= 0 is more readable.

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.

<= 0 is more readable.

Arguably yes, but it's not completely equivalent. If, through some unexpected calculation, dt_ happens to be NaN, then <= 0 is false while ! (dt_ > 0) is true. There's also the general advice of avoiding equality comparisons for floating-point numbers if possible.

// apply max time step if it was set
dt_ = std::min( dt_estimate, max_time_step_ );
assert(dt_ > 0);
if(!(dt_ > 0)){

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.

<= 0 is more readable.

dt_ = 0.5 * remaining;
}
assert(dt_ > 0);
if(!(dt_ > 0)){

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.

<= 0 is more readable.

if( 1.5 * dt_ > remaining ) {
dt_ = 0.5 * remaining;
assert(dt_ > 0);
if(!(dt_ > 0)){

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.

<= 0 is more readable.

substepTimer.simulationTimeElapsed());

assert(dtEstimate > 0);
if(!(dtEstimate > 0)){

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.

<= 0 is more readable.

// limit the growth of the timestep size by the growth factor
dtEstimate = std::min(dtEstimate, double(maxGrowth_ * dt));
assert(dtEstimate > 0);
if(!(dtEstimate > 0)){

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.

<= 0 is more readable.

}
assert(dtEstimate > 0);

if(!(dtEstimate > 0)){

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.

<= 0 is more readable.

// make sure growth factor is something reasonable
assert(growthFactor_ >= 1.0);

if(!(growthFactor_ >= 1.0)){

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.

< 1.0 is more readable.

double SimulatorTimer::stepLengthTaken() const
{
assert(current_step_ > 0);
if(!(current_step_ > 0)){

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.

<= 0 is more readable.

@blattms

blattms commented Mar 29, 2023

Copy link
Copy Markdown
Member

Please, pretty please, with lots of sugar on top, use meaningful error messages that help people to see where the problem is. Those used here are 100% correct, but also 100% unable to tell the user in which part of the simulator the problem is.

@hnil

hnil commented Jul 29, 2026

Copy link
Copy Markdown
Member Author

Closing: the patch targets BlackoilModelEbos.hpp and AdaptiveTimeSteppingEbos.hpp, which no longer exist after the Ebos rename.

The underlying issue is still live, so recording it rather than losing it: there are currently 140 assert( calls in opm/simulators/wells/*.cpp. Asserts compile out under NDEBUG, so in a release build those are not checks at all. This is worth revisiting as a fresh change against current master, particularly if opm-common #3427 (WITH_NDEBUG ON by default in release) is ever taken.

@hnil hnil closed this Jul 29, 2026
@hnil hnil reopened this Jul 29, 2026
@hnil
hnil marked this pull request as draft July 29, 2026 11:43
@hnil

hnil commented Jul 29, 2026

Copy link
Copy Markdown
Member Author

Reopening as a draft to keep the issue alive.

The patch itself is dead -- BlackoilModelEbos.hpp and AdaptiveTimeSteppingEbos.hpp no longer exist -- but the problem is not: there are currently 140 assert( calls in opm/simulators/wells/*.cpp, and asserts compile out under NDEBUG, so in a release build they are not checks at all. Related to opm-common #3427, which would turn NDEBUG on for release builds; if that lands, converting the load-bearing asserts becomes more urgent.

@hnil

hnil commented Aug 24, 2026

Copy link
Copy Markdown
Member Author

Superseded by #7355, which reapplies this to today's files - this branch predates the ebos rename and no longer merges. The asserts it targeted are all still on master, so the point stood; it just needed re-siting.

@hnil hnil closed this Aug 24, 2026
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.

5 participants