PrincetonUniversity / athena

Athena++ radiation GRMHD code and adaptive mesh refinement (AMR) framework
https://www.athena-astro.app
BSD 3-Clause "New" or "Revised" License
226 stars 122 forks source link

Apply output time cadence changes even if no input file is provided during restarts #454

Closed felker closed 2 years ago

felker commented 2 years ago

Makes command line changes equivalent to input file changes. Closes #451. Can you check @EdwinChan ? I just removed the if (iarg_flag == 1) check for the Forward/RollbackNextTime() calls in main.cpp, which I am pretty sure is safe in all cases but not 100% positive.

Also closes #310, by skipping the initial condition output if next_time > start_time. This was one of two suggested changes; see discussion in #311. The alternative is to stop overriding next_time when the IC is outputted, in other words "keep next_time after the initial output."


451 had many other comments and suggestions, which should be opened as separate issues if we want to pursue any of them:

The suggestion is that "the output should happen as soon as possible ..., because that would give us an easy way to make a debug dump right at the point of restart", i.e. next_time_new = pm->time like an initial condition output for the restarted simulation, which does seem useful.

Regardless of the choice, we should explicitly document it in the Wiki if it isnt already documented.

EdwinChan commented 2 years ago

Thanks, @felker, for the patch. The four tests in the original post of #451 have been redone with commit 08a002a0f057a390d320e3205d1615889f187d46; only the third test produces different results, and the new results are identical to the second test. That is to say, the specific problem I raised seems to be fixed. I'll let the maintainers contemplate the wider ramifications, if any.

I second the idea of documenting in the wiki the behavior when next_time < pm->time (as C++ programmers I'm sure we all hate undefined behavior…). Better yet, Athena++ can simply terminate on invalid input. As a bonus, we can teach the readers how to read the time in the restart file (see, e.g., https://github.com/PrincetonUniversity/athena/issues/451#issuecomment-1232344719) and set output#/next_time to that.

felker commented 2 years ago

Thanks for checking @EdwinChani. Can you draft an edit to the Wiki, and I will apply it?

felker commented 2 years ago

Any suggested edit to the Wiki, @EdwinChan ?

EdwinChan commented 2 years ago

I felt like I'm being gaslighted by GitHub… I was away during the long weekend and I can clearly remember replying to this thread after I came back to the office last Wednesday, but that post just disappeared. It's giving me serious trust issues…

Anyway, here's my suggested edit to the wiki:

Some notes:

felker commented 2 years ago

https://github.com/PrincetonUniversity/athena/wiki/The-Input-File

how does this look?

EdwinChan commented 2 years ago

The only quibble I have is that the phrase "to write the initial condition" implies that any other value of next_time would prevent writing of the initial condition, but in fact the initial condition is written unconditionally (pun?):

https://github.com/PrincetonUniversity/athena/blob/15bd136cd5237980965ce774d3ce4c5f1531980c/src/main.cpp#L399

I'd suggest removing that phrase.

felker commented 2 years ago

Not anymore: https://github.com/PrincetonUniversity/athena/commit/13ebdb9cf3ce23e64a7cae11f5540de7c52d3c33

https://github.com/PrincetonUniversity/athena/blob/15bd136cd5237980965ce774d3ce4c5f1531980c/src/outputs/outputs.cpp#L778-L790

felker commented 2 years ago

maybe good to add a comment in main.cp since the name of the function call is misleading

EdwinChan commented 2 years ago

For what it's worth, setting next_time to the time in the restart file means the next output will happen at next_time + dt, necessitating "exceed" in the description. Immediate output after restart is possible if next_time + dt is slightly later than the restart time.

felker commented 2 years ago

Are you suggesting I modify this?

  • next_time (optional) : earliest time the simulation must reach (or exceed) before the next output is written; the behavior is undefined if next_time is earlier than either 1) time/start_time for an initial, non-restart run 2) or the time stored in the restart file for a restart run (default = time/start_time to write the initial condition for a non-restart run)
EdwinChan commented 2 years ago

Not really; the way you wrote it is loose enough to cover the situation I described. But someone years later might have Googled this page when trying to figure out why there is no output even though start_time is after the restart time, and I thought it might be worthwhile to mention it here.