[Mesa-users] NaN values when getting zones' opacity (in run_star_extras.f90)

Pablo Marchant pamarca at gmail.com
Wed Jul 31 13:58:18 EDT 2019


Hi Matheus,

now I realize that it was not as simple. Just a quick explainer, within the
various things that are done at the beginning of a step, the order of some
of these operations is as follows (other things happen in-between these
steps as well)
1) adjust mesh
2) set mdot
3) adjust mass (essentially reduce mass of the model by dt*mdot)
4) call set_vars

now, the call to the set_vars subroutine assumes some stuff is set from the
adjust mass step. Since you are calling it before that, it fails. If you
want to know how I tracked the reason for failure, did the following

1) see $MESA_DIR/public/star_lib.f90 to check the subroutine star_set_vars
that I recommended calling. You'll see its just a wrapper for "set_vars" in
the module hydro_vars
2) In the module hydro_vars, go through the code for the subroutine
hydro_vars (which has various calls to different functions). Within all
that code, I looked for a place where the code was doing a "return" before
completing anything, to understand why the opacity was not set. This led me
to the see that the subroutine "unpack" runs into an issue and sets ierr (a
variable meant to indicate something did not went well). I generally do
this in a dirty way by putting write statements directly in the source code
and rerunning my simulation.
3) Within the subroutine unpack, I noticed that the offending lines where
these
                         s% dlnd_dt_const_q(k) = &
                            (s% xh(i_lnd,k) - s%
lnd_for_d_dt_const_q(k))*dt_inv
                         if (is_bad(s% dlnd_dt_const_q(k))) then
this is part of the code that computes the time derivatives used in stellar
structure equations. The issue here is that variables like
lnd_for_d_dt_const_q(k) are set after adjust mass, and before that can
contain NaNs.
4) So to "solve" it, in run_star_extras, just after the call to set_vars I
set all these variables to zero. This just prevents set_vars from running
into trouble, set_vars ends up being called again after mass is adjusted
and sets those variables correctly.

The attached run_star_extras does this. It is not the most elegant of
solutions, but it serves it's purpose. One reason why it's not ideal to
call set_vars in here is because there will be many unnecessary double
calls that will reduce performance.

Just going through this in detail so you understand the reason for the
problem, and can potentially find a better solution. One thing I could
recommend, would be to evaluate your wind at the end of each step (or just
evaluate the bits that depend on opacities), where all variables are
properly set. This can be done in extras_finish_step. You can store the
result in s% xtra1. These "xtra" variables are meant to be used to store
different variables in the model that will be properly restored if you're
model retries a step or does a backup. You can then just read this value
directly in your wind routine.

One further recommendation, you're implementing a super Eddington wind
boost as an instantaneous boost by a factor of 3 on the normal mass loss
rate. These discontinuous changes on the mass loss rate can often lead to
problems in the simulation, and you might need to find a better way to
continuously turn on this boost rather than having it as a discontinuous
change.

On Wed, Jul 31, 2019 at 10:32 AM Matheus Bernini <matheus.b.peron at gmail.com>
wrote:

> Thanks for the answer!
>
> So, a few more questions:
> (1) If the opacities are calculated after the mass adjustment, how can I
> get (if there is a way to) the values used in previous steps?
> (2) So, can I access the cells' opacities (even if they are from the
> previous step) with the xh(:,:) ! (nvar, nz)? If so, where can I find the
> index corresponding to the opacities?
> (3) I called the subroutine you mentioned but it still giving NaN results.
> Probably I didn't do this the right way, since my knowledge in Fortran is
> not very advanced.
>
>
>
> Em ter, 30 de jul de 2019 às 18:20, Pablo Marchant <pamarca at gmail.com>
> escreveu:
>
>> Hi Matheus,
>>
>> different variables are set at different points during a step in the
>> evolution. You're trying to implement a new wind routine, there are
>> guidelines on how to implement new wind physics under
>> $MESA_DIR/star/other/other_wind.f90, and in particular there you'll find
>> that
>>
>>            ! NOTE: surface is outermost cell. not necessarily at
>> photosphere.
>>            ! NOTE: don't assume that vars are set at this point.
>>            ! so if you want values other than those given as args,
>>            ! you should use values from s% xh(:,:) and s% xa(:,:) only.
>>            ! rather than things like s% Teff or s% lnT(:) which have not
>> been set yet.
>>
>> so you cannot directly access things like opacity at this point, it is
>> computed further ahead in the code. In particular, all those variables are
>> set after mass is adjusted. Perhaps one way you can work around this is by
>> calling the function star_set_vars which is part of star_lib (look in
>> $MESA_DIR/star/public/star_lib.f90 to see what arguments the function
>> receives). That will set many structure variables including opacity.
>>
>> Cheers
>>
>> On Tue, Jul 30, 2019 at 2:24 PM Matheus Bernini via Mesa-users <
>> mesa-users at lists.mesastar.org> wrote:
>>
>>> I've forgotten some files :)
>>>
>>> Em ter, 30 de jul de 2019 às 16:19, Matheus Bernini <
>>> matheus.b.peron at gmail.com> escreveu:
>>>
>>>> Hello everyone.
>>>>
>>>> I'm having a problem to get the opacity in the star zones in
>>>> run_star_extras, using the pointer star_info during the evolution of the
>>>> model.
>>>>
>>>> Basically, when the model starts, before it relax the initial rotation,
>>>> the opacities(:) have real values, but after the rotation relaxation, the
>>>> returned opacities become NaN, and I can't figure out why this happens.
>>>>
>>>> Cheers
>>>>
>>>> [image: image.png]
>>>>
>>> _______________________________________________
>>> mesa-users at lists.mesastar.org
>>> https://lists.mesastar.org/mailman/listinfo/mesa-users
>>>
>>>
>>
>> --
>> Pablo Marchant Campos
>> M.Sc on Astrophysics, Universidad Católica de Chile
>> PhD on Astrophysics, Argelander-Institut für Astronomie, Universität Bonn
>>
>

-- 
Pablo Marchant Campos
M.Sc on Astrophysics, Universidad Católica de Chile
PhD on Astrophysics, Argelander-Institut für Astronomie, Universität Bonn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.mesastar.org/pipermail/mesa-users/attachments/20190731/835a2a1a/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 120534 bytes
Desc: not available
URL: <https://lists.mesastar.org/pipermail/mesa-users/attachments/20190731/835a2a1a/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: run_star_extras.f
Type: text/x-fortran
Size: 17816 bytes
Desc: not available
URL: <https://lists.mesastar.org/pipermail/mesa-users/attachments/20190731/835a2a1a/attachment-0001.bin>


More information about the Mesa-users mailing list