Change valid-digits to min-timestep#1788
Conversation
BenjaminRodenberg
left a comment
There was a problem hiding this comment.
Nice that this PR resolves so many problems 👍 What's missing in my opinion:
- Can you write a test that reproduces the error you describe in #1776? If I understand everything correctly, the test should trigger the assertion mentioned in #1776, if you use develop and it should succeed, if you use this branch. This also helps us to not run into the same problem again in the future.
- Please add corresponding documentation (changelog entry and porting guide)
|
Yes, I also have to check that the errors raised in 1751 are actual precice errors with error messages. I should also at some point also add some documentation with the recomended value for min-timestep tag. For time adaptive solvers one would want to exchange the line "currentDt = dt > maxDt ? maxDt : dt" with "currentDt = dt > maxDt-minTimestep ? maxDt : dt" to avoid that the last time window is smaller than minTimestep. |
76c3ae5 to
cb572ea
Compare
|
@NiklasKotarsky Status-quo here is still that you trigger me once I should have a look, right? Or should I have a look now already? |
It might be ready for a first review. It is in a state where the bugs in #1751 and #1776 now emit proper preCICE errors with a recommendation of how to change the solvers to aviod them. I am still trying to figure out where to place the tag min-time-step-size in the config file, since it should only occur once in the whole file. The implementation also currently forces all solvers to hit the end of the time window within numerical accuracy. The problem is that if a solver stops before reaching the end of the time window then the Bspline algorithm would need to extrapolate the remaining part of the time window, which is currently not supported. The simple fix would be to only return the last value, but fixing this here feels a little bit out of scope for this pull request. |
There was a problem hiding this comment.
Implementation looks good, also the configuration. Appreciated 👍 (and sorry for my slow reply)
But, the implemented behavior now is different than what we had previously and not 100% what we need I am afraid of.
- Previously: Participant can do do smaller time step sizes than eps, but preCICE does never return a next max time step size smaller than eps. If the remainder in the window is smaller than eps, preCICE simply rounds up to the window end (hence the term valid digits we used before).
- Currently in this PR: Participant is simply not allowed to hand over a time step size smaller than eps. I am not sure if this is what we want. The motivation is to prevent participants from doing to small time step sizes (which could lead to stability problems sometimes). The current behavior one could also implement directly in the solver.
Fixing this should not be too complicated.
- Could you then please add an integration test that uses a
min-time-step-sizelarger than 1e-14?
I can change it such that participant can do do smaller time step sizes than eps I also had a very hard time coming up with a situation where one would need to use eps and not fixing it on the solver side. The only valid use case I could come up with is some solvers use 16-bit floating point arithmetic and some solvers use 32 bit floating point arithmetic. I have no idea if this is a realistic use case? |
This should be the way to go in my opinion.
Imagine you have a solver that has issues with too small time step sizes. Say you don't want a dt smaller than 1e-10. Now, it could happen that preCICE tells you that the last time step within a time window needs to be smaller than 1e-12. What do you do then. Of course, you could throw an error on the side of the solver, but that is no solution. |
2be3946 to
22e03d2
Compare
I don't think that we correctly handle this case in the coupling logic. precice/src/cplscheme/BaseCouplingScheme.cpp Lines 411 to 414 in e1e20f9 We advance precice/src/cplscheme/BaseCouplingScheme.cpp Line 343 in e1e20f9 precice/src/cplscheme/BaseCouplingScheme.cpp Line 360 in e1e20f9 This leads to a desync of the time across participants. |
Couldn't we have a test representing this case? I think the use-case of the feature is still hard to understand and if I search for Writing a test also helps to more clearly define what we actually want here. |
6fc2d35 to
e7fd30f
Compare
|
Nice catch @fsimonis, it should be possible to fix the coupling logic by adjusting the time in BaseCouplingScheme and moving the last sample to the end of the time window. However as far as I under stand it I do not have write access to the samples and stamples directly in baseCouplingScheme, which means I should not be able to move the samples directly. Therefore I would propose to just adding the last sample to the end of the time window as well, which should ensure that we do not have to extrapolate. The concern I have with this solution is that it introduces a time integration error, since preCICE is moving time steps around, which is not apparent or easily understandable from the user side. The proper way to avoid this integration error is to adjust the last time step that the solver takes and force it to hit the end of the time window exactly meaning to make the last timestep 10e-12 bigger, but I can also see the argument that this feature would be a nice convenience when that is difficult to achieve. |
Yes, that's what I am suggesting above.
We cannot do this as this is already in the past. The solver only tells preCICE about the time step size it used after it did the time step. |
|
I have implemented a test case now documenting the effects of a large min time step on the waveform iteration https://github.com/precice/precice/pull/1788/files#diff-0a12f7d580510ad191bb2b2d985a1ddc12bae9ef5f7b87c6187afeb6b1cd5164. The test currently fails on develop, whit the error ´PRECICE_ASSERT(math::equals(timesAscending(nTimeSteps - 1), time::Storage::WINDOW_END))´. I am still struggling a bit with accuracy of the interpolation, since it seems to me that the interpolation no longer conserves polynomials, but this might be a coding error in the feature. |
|
Regarding #1788 (comment) The problem is not that the CouplingScheme controls the time, it's how the time is controlled, when, and why. I still strongly suggest to keep time consistent. There is also no reason not to return more information in struct TimeStepInfo {
double userTimeStep;
double adjustedTimeStep;
bool hasBeenAdjusted;
bool atEndOfTimeWindow;
};
No matter the decision, we need to clean this up before the release of v3 along the remaining coupling-related topics. |
|
I would also like to point out that no one has answered the question "Is this even necessary?" in my previous comment #1788 (comment) |
The only use case which I can come up with where it is necessary would be mixed precision, where one solver has a lower precision than the other. Other than that this would be more of a nice to have feature when the time step is difficult to change or if the solver itself does not really have a time step. For example a controller which has a fixed time step that interfaces to some FSI simulation.
If I understand this correctly then we have to modify the time in addComputedTime() in order to keep the time consistent? I am a little bit unsure of how to proceed here. I could spend some time to move everything to advance in ParticipantIMPL and addComputedTime in order to make it more robust. The tricky part for me is that this feature will have unintended consequences especially for multicoupling with different time window lengths. |
Yes, but it will not be a widely-used feature.
The whole discussion goes a bit into a fundamental direction: "What is black-box coupling?" Typically, solvers have methods like
True, but an important effect of the feature is also to save computational time. The most expensive part is the I would suggest we merge here and if necessary continue discussion in #1832 after v3.0. |
&
If it is a hard criterion or the time step cannot be changed, then why wouldn't the solver prescribe the time window size using a serial scheme? The current implementation artificially extends the time step, which is completely intransparent for the adapter and coupled solver. Let's say that this repeats every time window, then this time shift can build up. |
Using participant first might be a good idea for some systems and setups, but it only works in serial coupling. Meaning that we need to provide something else for the parallel and multicoupling case. The min-time-step tag is more meant to be used to avoid round up errors that could arise when doing integer time steps or as a quick fix when the time step in the solver is difficult to modify.
We are assuming that deltaCorrection << deltaT. Using this feature we are going to make an additional time integration error that scales with deltaCorrection, which in most cases will be smaller than the time integration error. Therefore we should be able to just ignore this error completely on both the user and coupling side. There might be a case for an api function in preCICE that returns the current time, since we might run into different round of errors in the solver and preCICE resulting in a time difference between preCICE and the solver. This would also cover the problems this feature might cause for the solver, but this is out of scope for the current pull request. |
|
After the extensive discussion here, I think the rationale for the implementation is sufficiently documented. @NiklasKotarsky are there any more changes you would like to do? |
No, this is ready to be merged. |
|
I'll deal with the conflicts and merge the PR. |
…tDigitToSmallestTimeStep
Main changes of this PR
Changes the tag valid-digits tag to a min-timestep tag. Also ensures that the same tolerance is used to check for the end of the time window in Storage, Bspline and BaseCouplingScheme.
Motivation and additional information
Resolves: #1712, #1751, #1776
Author's checklist
pre-commithook to prevent dirty commits and usedpre-commit run --allto format old commits.make changelogif there are user-observable changes since the last release.Reviewers' checklist