*xtra variables not saved in photos?
mathren opened this issue · 3 comments
Describe the bug
According to $MESA_DIR/star_data/public/star_data_step_work.inc
(lines ~947 onwards in r24.03.1
) it should be possible to use ixtra
, lxtra
, and xtra
arrays for applications in the run_star_extras.f90
which have a state which should work across restarts and retries. Specifically there is a comment saying:
! more extras -- for run_star_extras applications with state.
! if your extra state info is all held in the following variables,
! restarts and retries will work without doing anything special.
I've been trying to use these to save checkpoints (mod file, profile, and photo) if and only if a certain condition (e.g., O depletion) has been reached, and flip lxtra(1)
to .true.
when I save it. The idea is that once lxtra(1) .eqv. .true.
, MESA will not over-write these checkpoints anymore. I've added in my extras_startup
lines like the following:
if (restart .eqv. .false.) then
print *, "NOT RESTARTING: SET TO FALSE"
s% lxtra(1) = .false.
else
print *, "RESTART: READ s%lxtra_old(1)"
s% lxtra(1) = s% lxtra_old(1)
end if
print *, s%lxtra(1)
However, this does not seem to work as expected: regardless of from where I restart (from a photo) lxtra(1)
is always initialize to .false.
(even if I expected lxtra_old(1)
to be .true.
after the checkpoint), and therefore if I restart from after the desired checkpoint, the first timestep will always overwrite my checkpoint.
I suppose this is because the information is not saved in the photos. This is maybe a niche need, but at the very least I find the comments above confusing.
To Reproduce
The attached zip file contains a simple minimal work example where lxtra(1)
is flipped at model number 5 and that saves a photo for each timestep. I would expect that restarting from photos x001, x002, x003, x004
lxtra(1)
would be set .false.
in extras_startup
, while restarting from photos x005
onwards it would be set to .true.
Instead it appears to always be set to .false.
I could find another way to "protect" saved checkpoints, e.g. checking if the file exists -- but ideally I would like to have MESA overwrite or not the checkpoints saved depending on whether I restart from before or after said checkpoint.
I suppose this is because the information is not saved in the photos.
in r24.03.1 the arrays ixtra, lxtra, and xtra are written to a photo file at lines 144-146 in $MESA_DIR/star/private/photo_out.f90. they are read from a photo file at lines 240-245 in $MESA_DIR/star/private/photo_in.f90.
a question to answer then is if these arrays are being re-initialized after a photo file is read.
I think the _old
variable is misleading here. These variables have a different purpose of saving the starting state of the model in case we need to fall back to that in the course of evolution.
The lxtra
variable itself should have a value that persists through restarts, so you shouldn't actually need to do any assignment upon restart at all. Does that resolve your issue?
I have fallen in this trap indeed and over-complicated things! It seems that removing completely that if
from extras_start_step
works as expected.
So old
refers to at the beginning of the step, not to the previous timestep? This is a bit confusing, maybe a renaming of the variables to *_init_step
or something like that would have prevented me from confusing myself -- but totally my bad.
Another option would be to rephrase the comments/documentation to make this clearer. Happy to do a PR for that if you think this would be useful to others as well.