From 58b84b06d9271cac12a708b07e69c0d47bd66ae5 Mon Sep 17 00:00:00 2001 From: Emily Sandford Date: Mon, 11 May 2026 23:36:35 +0200 Subject: [PATCH 1/3] fixed incorrect metal mass fraction array for Freedman lowT opacity tables (#993) Co-authored-by: Emily Sandford Louis Siebenaler (cc'd) and I noticed a problem with the preprocessing & evaluation of the Freedman11 low-temperature opacity tables. Specifically, the "Z" values associated with each table, as e.g. enumerated in $MESA_DIR/kap/public/kap_def.f90, num_kap_lowT_Zs(i) = 7 kap_lowT_Zs(1:num_kap_lowT_Zs(i), i) = [ 0.01d0, 0.02d0, 0.04d0, 0.100d0, 0.200d0, 0.63d0, 1.00d0 ] are not metal mass fractions. Rather, they are related to number fractions; for example, a Freedman [M/H] value of -0.3 corresponds to a metal number fraction of 10**(-0.3)solar = 0.5solar; [M/H]=0 corresponds to a solar number fraction, etc. It appears that there was a decision made to equate the solar metal number fraction with a metal mass fraction of 0.02 and scale the other values in the array accordingly. The metal mass fraction array should instead look something like this (with small variations possible depending on which protosolar abundance table you work with; the below values are based on Lodders 2003 table 2): [M/H] = [-0.3, 0.0, 0.3, 0.7, 1.0, 1.5, 1.7] Z = [0.0075, 0.0148, 0.029, 0.0698, 0.1303, 0.3215, 0.4288] --- kap/preprocessor/src/freedman.f90 | 14 +++++++------- kap/public/kap_def.f90 | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/kap/preprocessor/src/freedman.f90 b/kap/preprocessor/src/freedman.f90 index 338e67a73..82b2b9d79 100644 --- a/kap/preprocessor/src/freedman.f90 +++ b/kap/preprocessor/src/freedman.f90 @@ -43,19 +43,19 @@ subroutine get_Freedman_fname(data_dir, Z, fname) integer :: iz iz = floor(Z*1d5 + 0.1d0) select case (iz) - case (1000) + case (700) fname = trim(data_dir)//'/m0.3.txt' - case (2000) + case (1500) fname = trim(data_dir)//'/p0.0.txt' - case (4000) + case (2900) fname = trim(data_dir)//'/p0.3.txt' - case (10000) + case (7000) fname = trim(data_dir)//'/p0.7.txt' - case (20000) + case (13000) fname = trim(data_dir)//'/p1.0.txt' - case (63000) + case (32100) fname = trim(data_dir)//'/p1.5.txt' - case (100000) + case (42900) fname = trim(data_dir)//'/p1.7.txt' case default write (*, *) 'get_Freedman_fname: unexpected Z value for Freedman data', Z diff --git a/kap/public/kap_def.f90 b/kap/public/kap_def.f90 index 3eaeb69a9..66ae19f19 100644 --- a/kap/public/kap_def.f90 +++ b/kap/public/kap_def.f90 @@ -618,7 +618,7 @@ subroutine kap_def_init(kap_cache_dir_in) kap_lowT_Xs(1:num_kap_lowT_Xs(i), i) = [ 0.00d0 ] num_kap_lowT_Zs(i) = 7 kap_lowT_Zs(1:num_kap_lowT_Zs(i), i) = & - [ 0.01d0, 0.02d0, 0.04d0, 0.100d0, 0.200d0, 0.63d0, 1.00d0 ] + [ 0.007d0, 0.015d0, 0.029d0, 0.07d0, 0.13d0, 0.321d0, 0.429d0 ] num_kap_lowT_Xs_for_this_Z(1:num_kap_lowT_Zs(i), i) = num_kap_lowT_Xs(i) case DEFAULT num_kap_lowT_Xs(i) = 10 @@ -831,4 +831,4 @@ end subroutine free_co_table end subroutine do_Free_Kap_Tables -end module kap_def +end module kap_def \ No newline at end of file From 5161c5caa3bb123b8b49170ac5d4dc831d9c81d1 Mon Sep 17 00:00:00 2001 From: Ebraheem Farag <63124736+Debraheem@users.noreply.github.com> Date: Mon, 11 May 2026 20:22:07 -0400 Subject: [PATCH 2/3] add more sig figs, regenerate kap_data using dev_requirments python version, add known_bugs/changelog docs, fix kap preprocessor typos and missing kap file build call introduced by 0030af617 ("kap: port preprocessor to new build system", update atm test output). --- atm/test/test_output | 8 ++++---- docs/source/changelog.rst | 2 ++ docs/source/known_bugs.rst | 21 +++++++++++++++++++++ kap/AESOPUS_AGSS09.h5 | 4 ++-- kap/kap_data.tar.xz | 4 ++-- kap/preprocessor/Makefile | 19 ++++++++++--------- kap/preprocessor/build_data_and_export | 11 +++++++++++ kap/preprocessor/src/freedman.f90 | 16 ++++++++-------- kap/public/kap_def.f90 | 5 +++-- 9 files changed, 63 insertions(+), 27 deletions(-) create mode 100755 kap/preprocessor/build_data_and_export diff --git a/atm/test/test_output b/atm/test/test_output index 8718566aa..efc3e464c 100644 --- a/atm/test/test_output +++ b/atm/test/test_output @@ -85,17 +85,17 @@ test_irradiated - test_grey_irradiated: kap 4.3649748642304882D-03 + test_grey_irradiated: kap 4.7498368201485917D-03 M/M_jupiter 1.4999999999999998D+00 R/R_jupiter 1.5743735095633800D+00 R/Rsun 1.6178684913857289D-01 kap_v 4.0000000000000001D-03 P 1.0000000000000000D+06 - tau 2.9101126947637423D+00 + tau 3.1669763036977079D+00 Teff 5.7759999999999891D+03 T_eq 1.0000000000000000D+03 T_int 9.0000000000000000D+02 - T 1.2929349604416070D+03 - logT 3.1115766787614829D+00 + T 1.3124222808279656D+03 + logT 3.1180735947393834D+00 diff --git a/docs/source/changelog.rst b/docs/source/changelog.rst index 34fc942a7..8e656d5ff 100644 --- a/docs/source/changelog.rst +++ b/docs/source/changelog.rst @@ -35,6 +35,8 @@ MESA no longer stops when reactions for which special rates are set are not in t Bug Fixes --------- +Important bug fix for ``r26.4.1`` identified by Emily Sandford and Louis Siebenaler: the ``lowT_Freedman11`` opacity option used ``[M/H]`` labels as the metal mass fraction when interpolating in ``Z``, resulting in incorrect opacities. We recommend users who use these low-temperature opacities, such as in planet models, update to the latest MESA version or employ the fixes in :ref:`the known bugs entry ` and `gh-993 `_. + The parameter ``report_max_infall_inside_fe_core`` was ignored in versions r25.12.1 and r26.4.1 and always had it's default value. See `gh-981 https://github.com/MESAHub/mesa/pull/981`_. ``fe_core_infall_limit`` now obeys ``when_to_stop_rtol`` and ``when_to_stop_atol`` again (broken since r11532). diff --git a/docs/source/known_bugs.rst b/docs/source/known_bugs.rst index 64abefa1b..4349d809b 100644 --- a/docs/source/known_bugs.rst +++ b/docs/source/known_bugs.rst @@ -13,6 +13,27 @@ issue, but it may not be complete. r26.4.1 ======= +.. _freedman_lowt_z_bug: + +Kap: ``lowT_Freedman11`` used ``[M/H]`` labels as ``Z`` +------------------------------------------------------- + +The ``lowT_Freedman11`` opacity option used the Freedman table labels +``0.01``, ``0.02``, ``0.04``, ``0.10``, ``0.20``, ``0.63``, and ``1.00`` as +metal mass fractions. These labels correspond to ``[M/H]`` not +MESA's metal mass fraction ``Z``. The opacity routines incorrectly interpolated in ``Z``, +using the ``[M/H]`` labels as the interpolation grid. + +This has been fixed in the main branch after ``r26.4.1``. The fix updates the +``lowT_Freedman11`` ``Z`` grid to use the correct corresponding metal mass fractions. +See `gh-993 `_. + +If applying these fixes to an existing checkout, rerun the opacity preprocessor +to regenerate the tables; this is not done by a normal MESA install:: + + cd $MESA_DIR/kap/preprocessor + ./build_data_and_export + .. _report_max_infall_inside_fe_core_bug: Controls: ``report_max_infall_inside_fe_core`` is ignored diff --git a/kap/AESOPUS_AGSS09.h5 b/kap/AESOPUS_AGSS09.h5 index ad41c3d80..fec1a67bd 100644 --- a/kap/AESOPUS_AGSS09.h5 +++ b/kap/AESOPUS_AGSS09.h5 @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ec345f74715752d4884afc1fbcb824f2b29c1c483630b647183ba531ddc146d9 -size 35605321 +oid sha256:e6d0733d381ef38bd7a836bdf13ff082cda9d4332fd39aaf19443dc9448c3264 +size 35095968 diff --git a/kap/kap_data.tar.xz b/kap/kap_data.tar.xz index 5783cad12..cab1d1ad3 100644 --- a/kap/kap_data.tar.xz +++ b/kap/kap_data.tar.xz @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:05d43caa14cadc43eedd4d26e5182acc416cae7434dd4ba8a0a55e8eedd5129c -size 95406276 +oid sha256:e195100180a32c7bccf506c85d506b497ed78a5bb01abbfdadd96f6026054a65 +size 113517544 diff --git a/kap/preprocessor/Makefile b/kap/preprocessor/Makefile index bc99445bd..0542eb2b8 100644 --- a/kap/preprocessor/Makefile +++ b/kap/preprocessor/Makefile @@ -59,6 +59,7 @@ $(call kap,$1,0.1000,-1) endef define kap-co-enhanced +$(call kap,$1,0.000,-1) $(call kap,$1,0.001,-1) $(call kap,$1,0.004,-1) $(call kap,$1,0.010,-1) @@ -69,13 +70,13 @@ $(call kap,$1,0.100,-1) endef define kap-freedman -$(call kap,$1,0.01,0) -$(call kap,$1,0.02,0) -$(call kap,$1,0.04,0) -$(call kap,$1,0.10,0) -$(call kap,$1,0.20,0) -$(call kap,$1,0.63,0) -$(call kap,$1,1.00,0) +$(call kap,$1,0.007452,0) +$(call kap,$1,0.014760,0) +$(call kap,$1,0.029024,0) +$(call kap,$1,0.069840,0) +$(call kap,$1,0.130292,0) +$(call kap,$1,0.321456,0) +$(call kap,$1,0.428844,0) endef define kap-oplib @@ -131,10 +132,10 @@ build-data: $(BUILD_DIR_MODULE)/kap_input_data/ logT_points $(OBJ_OUT) | $(BUILD $(call kap-fixed-metal,inlist_lowT_fa05_mb22) cp -r $(BUILD_DIR_MODULE)/kap_input_data/wichita/AAG21_lowT_MESA_tables/* $(BUILD_DIR_MODULE)/data/kap_data/ - cp condtable.data $(BUILD_DIR_MODULE)/data/kap_data/ + cp condtabl.data $(BUILD_DIR_MODULE)/data/kap_data/ $(BUILD_DIR_MODULE)/AESOPUS_AGSS09.h5: $(BUILD_DIR_MODULE)/ags09/ - cd $(BUILD_DIR_MODULE); python $(CURDIR)/AESOPUS/aesopus.py $(CURDIR)/AESOPUS/AGSS09.yaml + cd $(BUILD_DIR_MODULE); python $(CURDIR)/AESOPUS/aesopus.py $(CURDIR)/AESOPUS/AGSS09.yml build-aesopus: $(BUILD_DIR_MODULE)/AESOPUS_AGSS09.h5 diff --git a/kap/preprocessor/build_data_and_export b/kap/preprocessor/build_data_and_export new file mode 100755 index 000000000..941412eaf --- /dev/null +++ b/kap/preprocessor/build_data_and_export @@ -0,0 +1,11 @@ +#!/bin/bash + +set -e + +cd "$(dirname "$0")" + +kap_data_dir="../../build/kap-preprocessor/data/kap_data" + +rm -rf "$kap_data_dir" +mkdir -p "$kap_data_dir" +make build-data build-aesopus export-data diff --git a/kap/preprocessor/src/freedman.f90 b/kap/preprocessor/src/freedman.f90 index 82b2b9d79..db674cf41 100644 --- a/kap/preprocessor/src/freedman.f90 +++ b/kap/preprocessor/src/freedman.f90 @@ -41,21 +41,21 @@ subroutine get_Freedman_fname(data_dir, Z, fname) character(len=*), intent(in) :: data_dir character(len=*), intent(out) :: fname integer :: iz - iz = floor(Z*1d5 + 0.1d0) + iz = nint(Z*1d6) select case (iz) - case (700) + case (7452) fname = trim(data_dir)//'/m0.3.txt' - case (1500) + case (14760) fname = trim(data_dir)//'/p0.0.txt' - case (2900) + case (29024) fname = trim(data_dir)//'/p0.3.txt' - case (7000) + case (69840) fname = trim(data_dir)//'/p0.7.txt' - case (13000) + case (130292) fname = trim(data_dir)//'/p1.0.txt' - case (32100) + case (321456) fname = trim(data_dir)//'/p1.5.txt' - case (42900) + case (428844) fname = trim(data_dir)//'/p1.7.txt' case default write (*, *) 'get_Freedman_fname: unexpected Z value for Freedman data', Z diff --git a/kap/public/kap_def.f90 b/kap/public/kap_def.f90 index 66ae19f19..0b68f2b39 100644 --- a/kap/public/kap_def.f90 +++ b/kap/public/kap_def.f90 @@ -618,7 +618,8 @@ subroutine kap_def_init(kap_cache_dir_in) kap_lowT_Xs(1:num_kap_lowT_Xs(i), i) = [ 0.00d0 ] num_kap_lowT_Zs(i) = 7 kap_lowT_Zs(1:num_kap_lowT_Zs(i), i) = & - [ 0.007d0, 0.015d0, 0.029d0, 0.07d0, 0.13d0, 0.321d0, 0.429d0 ] + [ 0.007452d0, 0.014760d0, 0.029024d0, 0.069840d0, & + 0.130292d0, 0.321456d0, 0.428844d0 ] num_kap_lowT_Xs_for_this_Z(1:num_kap_lowT_Zs(i), i) = num_kap_lowT_Xs(i) case DEFAULT num_kap_lowT_Xs(i) = 10 @@ -831,4 +832,4 @@ end subroutine free_co_table end subroutine do_Free_Kap_Tables -end module kap_def \ No newline at end of file +end module kap_def From f3132bb6586598caacfd1eb71aa2dcf1b72874a8 Mon Sep 17 00:00:00 2001 From: Debraheem Date: Wed, 27 May 2026 10:01:04 -0400 Subject: [PATCH 3/3] [ci skip] update Freedman lowT opacity documentation --- docs/source/kap/overview.rst | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/docs/source/kap/overview.rst b/docs/source/kap/overview.rst index d6d549330..0a310f70c 100644 --- a/docs/source/kap/overview.rst +++ b/docs/source/kap/overview.rst @@ -109,13 +109,19 @@ Tables based on the work of |Fergusson| include the effects of molecules and grains and cover the range :math:`2.7 \le \log T \le 4.5` and :math:`-8 \le \log R \le 1`. -Tables based on the work of |Freedman| include the effects of -molecules and cover the range :math:`1.88 \le \log T \le 4.5` and -:math:`-8 \le \log R \le 9`. The table set was privately communicated -by R. S. Freedman in 2011. Unlike other opacity sources, this is a 1D -sequence of tables in :math:`Z` as opposed to a 2D grid of -:math:`(X,Z)` values. (The assumed H/He abundances scale with -:math:`Z`.) +Tables based on the work of |Freedman08| and |Freedman14| include the +effects of molecules. The MESA ``lowT_Freedman11`` tables cover the +range :math:`1.88 \le \log T \le 4.5` and +:math:`-8 \le \log R \le 9` after preprocessing. The raw opacity data +used to build these tables stop near :math:`T = 4000\,\rm K`, +corresponding to :math:`\log T \simeq 3.60`; the higher temperature +part of the MESA table is generated during preprocessing so the table +can be used on the same grid as the other low temperature opacity +tables. The table set was privately communicated by R. S. Freedman in +2011 and corresponds to the expanded opacity data later described by +|Freedman14|. Unlike other opacity sources, this is a 1D sequence of +tables in :math:`Z` as opposed to a 2D grid of :math:`(X,Z)` values. +(The assumed H/He abundances scale with :math:`Z`.) Tables from ÆSOPUS (|AESOPUS|) include variation factors for the CNO @@ -182,7 +188,9 @@ degeneracy, the additional correction formulae of |B20| are applied. .. |Fergusson| replace:: `Ferguson et al. (2005) `__ -.. |Freedman| replace:: `Freedman et al. (2008) `__ +.. |Freedman08| replace:: `Freedman et al. (2008) `__ + +.. |Freedman14| replace:: `Freedman et al. (2014) `__ .. |AESOPUS| replace:: `Marigo & Aringer 2009 `__ @@ -193,4 +201,3 @@ degeneracy, the additional correction formulae of |B20| are applied. .. |OPLIB| replace:: `Colgan 2016 `__ .. |Cassisi| replace:: `Cassisi et al. (2007) `__ -