Skip to content

[GeoMechanicsApplication] Fix bug in time step mechanism C++ workflow#14184

Merged
rfaasse merged 20 commits intomasterfrom
geo/fix-bug-in-time-step-mechanism-c-workflow
Feb 9, 2026
Merged

[GeoMechanicsApplication] Fix bug in time step mechanism C++ workflow#14184
rfaasse merged 20 commits intomasterfrom
geo/fix-bug-in-time-step-mechanism-c-workflow

Conversation

@rfaasse
Copy link
Contributor

@rfaasse rfaasse commented Feb 6, 2026

📝 Description
In the time stepping scheme in the C++ workflow, avoiding a small step was not done for the very first time-step, which resulted in an error for cases where the first increment of a stage would result in a very small subsequent step to get to the end-time.

This PR adds the same upscaling functionality that was there for subsequent steps also in the constructor, to check the very first step of a stage.

Changelog:

  • The first time step is now checked for avoiding a small last step
  • An integration test for the C++ workflow is added
  • Unit tests are added

@rfaasse rfaasse added Bugfix GeoMechanics Issues related to the GeoMechanicsApplication labels Feb 6, 2026
@rfaasse rfaasse linked an issue Feb 6, 2026 that may be closed by this pull request
@rfaasse rfaasse changed the title [GeoMechanicsApplication] Fix bug in time step mechanism c++ workflow [GeoMechanicsApplication] Fix bug in time step mechanism C++ workflow Feb 6, 2026
mReductionFactor(ReductionFactor),
mIncreaseFactor(IncreaseFactor),
mUserMinDeltaTime(std::move(UserMinDeltaTime)),
mUserMinDeltaTime(UserMinDeltaTime),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Clang-tidy mentioned the move of a std::optional was not necessary

KRATOS_ERROR_IF(MaxTimeStepFactor < 1.0)
<< "Max_delta_time_factor must be greater than or equal to 1, but got " << MaxTimeStepFactor;

CorrectDeltaTimeToEndTime(StartTime);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the actual fix, we need to check at construction to make sure the first increment is correct

return mUserMinDeltaTime.value_or(default_min_delta_time);
}

void AdaptiveTimeIncrementor::CorrectDeltaTimeToEndTime(double StartOfIncrement)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm struggling with the name of this function. What it does is if the deltatime would result in either a very small next step (difference smaller than min delta time) or if it would result in going beyond the end time, it corrects it to be the end time. If you have any suggestions for a better name, let me know

Copy link
Contributor

@WPK4FEM WPK4FEM Feb 6, 2026

Choose a reason for hiding this comment

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

CorrectDeltaTimeToReachEndTime or AdaptDeltaTimeToAvoidSmallNextIncrement

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are both better than the current name, but they don't capture the 'preventing overshooting the end time' part of the function, so I'm still wondering if there's an even better name somewhere

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that it's very hard to put the exact checks in words without ending up with extremely long function names. What about AdaptDeltaTimeIfNeeded? It doesn't spell out when it's needed, just that the time increment may or may not be modified after doing some checks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that's a good idea (since I don't see a way to capture both reasons in the function name). I did add a comment within the function to explain what it's doing. Hope that helps

auto previous_state = TimeStepEndState{};
previous_state.convergence_state = TimeStepEndState::ConvergenceState::converged;

time_incrementor.PostTimeStepExecution(previous_state);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing this line makes sure we don't do the correction that's in PostTimeStepExecution, to make sure a first step is also corrected

Comment on lines 128 to 129
KratosGeoMechanicsAvoidSmallTimeStepPythonRoute,
KratosGeoMechanicsAvoidSmallTimeStepCppRoute,
Copy link
Contributor

Choose a reason for hiding this comment

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

I find the SmallEndStep more descriptive than SmallTimeStep

@rfaasse rfaasse requested review from avdg81 and markelov208 February 6, 2026 09:45
@rfaasse rfaasse marked this pull request as ready for review February 6, 2026 09:45
@rfaasse rfaasse requested a review from a team as a code owner February 6, 2026 09:45
Copy link
Contributor

@avdg81 avdg81 left a comment

Choose a reason for hiding this comment

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

Dear @rfaasse and @WPK4FEM,
Thanks a lot for preparing this bug fix. The changes were clear, and are well-covered by the new unit tests and integration test. I only have a few minor comments, none of them being blocking. I feel this PR is almost ready to go 👍

CheckMinimumDeltaTime(mDeltaTime);
}

void AdaptiveTimeIncrementor::CheckMinimumDeltaTime(double DeltaTime) const
Copy link
Contributor

Choose a reason for hiding this comment

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

As far as I can see, this member function is always called given the data member mDeltaTime. Since it has access to this data directly, we don't really need to pass it through the argument list. Since it's a private member function, client code won't be able to call it directly. Would it be cleaner to have an empty argument list and fetch the required data directly inside the function body?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, done!

return mUserMinDeltaTime.value_or(default_min_delta_time);
}

void AdaptiveTimeIncrementor::CorrectDeltaTimeToEndTime(double StartOfIncrement)
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that it's very hard to put the exact checks in words without ending up with extremely long function names. What about AdaptDeltaTimeIfNeeded? It doesn't spell out when it's needed, just that the time increment may or may not be modified after doing some checks.

auto previous_state = TimeStepEndState{};
previous_state.convergence_state = TimeStepEndState::ConvergenceState::non_converged;
previous_state.time = 8.0;
previous_state.time = 0.0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch!

Copy link
Contributor

@avdg81 avdg81 left a comment

Choose a reason for hiding this comment

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

Thanks a lot for processing the review suggestions. To me, this PR looks good to go.

Comment on lines +121 to +124
// If the delta time would result in
// a. the next step exceeding the end time or
// b. having too small a remaining time step
// then the delta time is chosen such that the next step ends exactly at the end time.
Copy link
Contributor

Choose a reason for hiding this comment

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

Very clear, thank you.

Copy link
Contributor

@markelov208 markelov208 left a comment

Choose a reason for hiding this comment

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

Hi Richard, thank you for fixing this bug and adding unit and integration tests. The PR looks very good for me.

@rfaasse rfaasse merged commit 7882485 into master Feb 9, 2026
10 checks passed
@rfaasse rfaasse deleted the geo/fix-bug-in-time-step-mechanism-c-workflow branch February 9, 2026 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bugfix GeoMechanics Issues related to the GeoMechanicsApplication

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[GeoMechanicsApplication] Bug in time step mechanism C++ workflow

4 participants