[Mesa-users] [EXT] custom write photos
Amadeusz Miszuda
amiszuda.astro at gmail.com
Fri Nov 7 08:23:54 UTC 2025
Hi Neev,
Thanks for that, it helped!
For the devs: It’d be nice to have an easier way of doing this, implemented directly in MESA.
Best,
Amadeusz
> On 5 Nov 2025, at 23:47, Shah, Neev - (neevshah) <neevshah at arizona.edu> wrote:
>
> Hi Amadeusz,
>
> Mathieu and I did this a while back and copied some functions from the MESA source code. There is probably a neater way to do it, but this is what I have in my run_binary_extras which seems to work -
>
>
> subroutine do_saves_for_binary(b, ierr)
> type(binary_info), pointer :: b
> integer, intent(out) :: ierr
> integer :: iounit, id
> character (len = strlen) :: str_photo, filename, iomsg, report_str
>
> call string_for_model_number('x', b% model_number, b% photo_digits, str_photo)
>
> filename = trim(trim(b% photo_directory) // '/b_' // str_photo)
> report_str = trim('save ' // filename)
> open(newunit = iounit, file = trim(filename), action = 'write', &
> status = 'replace', iostat = ierr, iomsg = iomsg, form = 'unformatted')
> if (ierr /= 0) then
> write(*, *) 'failed in do_saves_for_binary', trim(filename)
> return
> end if
> call binary_photo_write(b% binary_id, iounit)
> close(iounit)
>
> if (b% have_star_1) then
> filename = trim(trim(b% s1% photo_directory) // '/1_' // str_photo)
> call star_save_for_restart(b% s1% id, filename, ierr)
> report_str = trim(trim(report_str) // ', ' // filename)
> end if
> if (b% have_star_2) then
> filename = trim(trim(b% s2% photo_directory) // '/2_' // str_photo)
> call star_save_for_restart(b% s2% id, filename, ierr)
> report_str = trim(trim(report_str) // ', ' // filename)
> end if
> if (ierr /= 0) then
> write(*, *) 'failed in do_saves_for_binary'
> return
> end if
>
> write(*, *) trim(trim(report_str) // ' for model'), b% model_number
>
> end subroutine do_saves_for_binary
>
> subroutine binary_photo_write(binary_id, iounit)
> integer, intent(in) :: binary_id, iounit
> type(binary_info), pointer :: b
>
> integer :: ierr, k, len_history_col_spec
>
> ierr = 0
> call binary_ptr(binary_id, b, ierr)
> if (ierr /= 0) then
> write(*, *) 'failed in binary_ptr'
> return
> end if
>
> write(iounit) star_def_version
>
> write(iounit, iostat = ierr) &
> b% binary_age, b% binary_age_old, &
> b% model_number, b% model_number_old, &
> b% mtransfer_rate, b% mtransfer_rate_old, &
> b% angular_momentum_j, b% angular_momentum_j_old, &
> b% separation, b% separation_old, &
> b% eccentricity, b% eccentricity_old, &
> b% rl_relative_gap(1), b% rl_relative_gap_old(1), &
> b% rl_relative_gap(2), b% rl_relative_gap_old(2), &
> b% r(1), b% r_old(1), &
> b% r(2), b% r_old(2), &
> b% rl(1), b% rl_old(1), &
> b% rl(2), b% rl_old(2), &
> b% m(1), b% m_old(1), &
> b% m(2), b% m_old(2), &
> b% dt, b% dt_old, &
> b% env(1), b% env_old(1), &
> b% env(2), b% env_old(2), &
> b% eq_initial_bh_mass, &
> b% period, b% period_old, &
> b% max_timestep, b% max_timestep_old, &
> b% change_factor, b% change_factor_old, &
> b% min_binary_separation, &
> b% using_jdot_mb(1), b% using_jdot_mb_old(1), &
> b% using_jdot_mb(2), b% using_jdot_mb_old(2), &
> b% d_i, b% d_i_old, b% a_i, b% a_i_old, &
> b% point_mass_i, b% point_mass_i_old, &
> b% ignore_rlof_flag, b% ignore_rlof_flag_old, &
> b% model_twins_flag, b% model_twins_flag_old, &
> b% dt_why_reason, b% dt_why_reason_old, &
> b% have_star_1, b% have_star_2, &
> b% CE_flag, b% CE_flag_old, &
> b% CE_init, b% CE_init_old, &
> b% CE_nz, b% CE_initial_radius, b% CE_initial_separation, b% CE_initial_Mdonor, &
> b% CE_initial_Maccretor, b% CE_initial_age, b% CE_initial_model_number, &
> b% CE_b_initial_age, b% CE_b_initial_model_number, &
> b% CE_num1, b% CE_num1_old, &
> b% CE_num2, b% CE_num2_old, &
> b% CE_lambda1, b% CE_lambda1_old, &
> b% CE_lambda2, b% CE_lambda2_old, &
> b% CE_Ebind1, b% CE_Ebind1_old, &
> b% CE_Ebind2, b% CE_Ebind2_old, &
> b% ixtra(:), b% ixtra_old(:), &
> b% xtra(:), b% xtra_old(:), &
> b% lxtra(:), b% lxtra_old(:)
>
> if (associated(b% binary_history_column_spec)) then
> len_history_col_spec = size(b% binary_history_column_spec)
> write(iounit) len_history_col_spec
> write(iounit) b% binary_history_column_spec(1:len_history_col_spec)
> else
> write(iounit) 0 ! len_log_col_spec
> end if
> write(iounit) &
> b% number_of_binary_history_columns, b% model_number_of_binary_history_values, &
> b% need_to_set_binary_history_names_etc
> if (b% number_of_binary_history_columns > 0) then
> write(iounit) b% binary_history_value_is_integer(1:b% number_of_binary_history_columns)
> do k = 1, b% number_of_binary_history_columns
> write(iounit) b% binary_history_names(k)
> end do
> end if
>
> if (b% CE_init) then
> write(iounit, iostat = ierr) &
> b% CE_m(:), b% CE_entropy(:), b% CE_U_in(:), b% CE_U_out(:), b% CE_Omega_in(:), b% CE_Omega_out(:)
> end if
>
> call b% other_binary_photo_write(binary_id, iounit)
>
> if (ierr /= 0) stop "error in binary_photo_write"
>
> end subroutine binary_photo_write
> With these two subroutines, I think
> call do_saves_for_binary(b, ierr)
> should save a binary photo.
>
> Best,
> Neev
> From: Mesa-users <mesa-users-bounces at lists.mesastar.org> on behalf of Amadeusz Miszuda via Mesa-users <mesa-users at lists.mesastar.org>
> Sent: 05 November 2025 15:00
> To: Renzo, Mathieu - (mrenzo) <mrenzo at arizona.edu>
> Cc: mesa-users at lists.mesastar.org <mesa-users at lists.mesastar.org>
> Subject: Re: [Mesa-users] [EXT] custom write photos
>
> Hi Mathieu,
>
> I have not, but I believe it won't get me the binary run photo, right?
>
> Amadeusz
>
>> On 5 Nov 2025, at 18:40, Mathieu Renzo via Mesa-users <mesa-users at lists.mesastar.org> wrote:
>>
>> Hi Amadeusz,
>>
>> Have you tried calling the function `star_write_photo` defined in `$MESA_DIR/star/public/star_lib.def`?
>> That should be straightforward from run_star/binary_extras.f90, and I have used it in the past (but can't find a snippet at the moment)
>>
>> Mathieu
>> On 11/5/25 09:18, Amadeusz Miszuda via Mesa-users wrote:
>>> External Email
>>>
>>> Hi All,
>>>
>>> I am trying to force MESA to write additional photos at specific moments of evolution from the run_binary_extras. Since I don’t see any controls, I have tried several options, including will_do_photo = .true. or calling the do_saves_for_binary subroutine, but they all fail, sometimes due to some compilation reasons, as:
>>> Undefined symbols for architecture arm64:
>>> "_do_saves_for_binary_", referenced from:
>>> ___run_binary_extras_MOD_extras_binary_finish_step in run_binary_extras.o
>>> ld: symbol(s) not found for architecture arm64
>>> collect2: error: ld returned 1 exit status
>>> make: *** [binary] Error 1
>>>
>>> FAILED
>>>
>>> Does anyone know a simple way to achieve that? Any help would be appreciated.
>>>
>>> Thanks!
>>> Amadeusz
>>>
>>>
>>>
>>>
>>> ——————————————————
>>> Dr Amadeusz Miszuda
>>> Postdoctoral Researcher
>>> Nicolaus Copernicus Astronomical Centre
>>> Polish Academy of Sciences,
>>> Warsaw, Poland
>>>
>>>
>>> _______________________________________________
>>> mesa-users at lists.mesastar.org <mailto:mesa-users at lists.mesastar.org>
>>> https://lists.mesastar.org/mailman/listinfo/mesa-users
>>>
>> --
>> Mathieu Renzo <https://www.as.arizona.edu/~mrenzo/>
>> Assistant Professor
>> University of Arizona - Steward Observatory
>> _______________________________________________
>> mesa-users at lists.mesastar.org
>> https://lists.mesastar.org/mailman/listinfo/mesa-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.mesastar.org/pipermail/mesa-users/attachments/20251107/d1f79180/attachment.htm>
More information about the Mesa-users
mailing list