Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/cmc-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
types: [opened]
paths:
- 'src/cosmic/evolve.py'
- 'src/cosmic/consts.py'
- 'src/cosmic/data/cosmic-settings.json'
- 'src/cosmic/src/ran3.f'

Expand Down
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
- Code cleanup
- Function signature for kick() and evolv2() in the fortran changed to remove ``bkick`` entirely
- Also removed ``kick_info_out``. Both of these can be reconstructed from ``kick_info``
- [Just for developers] Created ``consts.py`` which ``evolve.py`` now draws from, loops over GROUPED_SETTINGS instead of giant chunk of assignments

- Bug fixes: c
- Bug fixes:
- corrected mass sign in bjorklund wind routine in SSE_mlwind.f
- fixed bug in ``bhspinmag`` assignment in ``assign_remnant.f``

Expand Down
29 changes: 10 additions & 19 deletions docs/pages/develop/new-settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ This page guides you through adding an entirely new setting to COSMIC. If you ju

- ``src/cosmic/src/const_bse.h``: Initialise a new variable and add it to the relevant common block
- ``src/cosmic/data/cosmic-settings.json``: Add the setting to the JSON file, with a description and default value
- ``src/cosmic/evolve.py``
- Add variable to ``INITIAL_CONDITIONS_BSE_COLUMNS``
- Add variable in ``_evolve_single_system()`` list
- ``src/cosmic/consts.py`` - Add settings to correct group in ``GROUPED_SETTINGS`` dict
- ``src/cosmic/tests/data``: Update initC files and params.ini with new setting
- ``src/cosmic/tests/data/initial_conditions_for_testing.hdf5``
- ``src/cosmic/tests/data/kick_initial_conditions.h5``
Expand All @@ -25,7 +23,7 @@ This page guides you through adding an entirely new setting to COSMIC. If you ju

Adding a new setting to ``COSMIC`` is a little more involved than just adding an options. Settings are stored in common blocks in the Fortran code so that they can be accessed anywhere in the code. Let's do it step by step.

Throughout this example, let's say we want to add a new setting called ``lbv_flag`` that sets the prescription for luminous blue variable mass loss.
Throughout this example, let's say we want to add a new setting called ``LBV_flag`` that sets the prescription for luminous blue variable mass loss.

Add new setting to a common block
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -55,7 +53,7 @@ In ``src/cosmic/data/cosmic-settings.json``, we add a new entry for our setting:

.. code-block:: json

"name": "lbv_flag",
"name": "LBV_flag",
"description": "Flag for luminous blue variable wind mass loss prescription.",
"type": "dropdown",
"options-preface": "",
Expand Down Expand Up @@ -83,22 +81,15 @@ In ``src/cosmic/data/cosmic-settings.json``, we add a new entry for our setting:
Pass the setting from evolve() to the Fortran code
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Now we need to pass the setting from the Python code in ``evolve.py`` to the Fortran code. This is done in the ``_evolve_single_system()`` function in ``src/cosmic/evolve.py``. But first, we need to add the new setting to the list of columns in the initial binary table. This is done by adding it to the ``INITIAL_CONDITIONS_BSE_COLUMNS`` list at the top of ``src/cosmic/evolve.py``:
Now we need to pass the setting from the Python code in ``evolve.py`` to the Fortran code. This is actually handled in ``src/cosmic/consts.py``, where we have a dictionary called ``GROUPED_SETTINGS`` that groups settings by the common block they belong to. We need to add our new setting to the correct group in this dictionary:

.. code-block:: python

# dots are representing the existing columns
INITIAL_CONDITIONS_BSE_COLUMNS = [..., 'lbv_flag']

Now we change the ``_evolve_single_system()`` function to pass the new setting to the Fortran code. In the list of flags that is passed to the Fortran code, we add our new setting:

.. code-block:: python

_evolvebin.windvars.lbv_flag = f["lbv_flag"]

.. warning::

Make sure you use the right common block here (``windvars`` in this case) otherwise the setting won't get properly passed but will also not throw an error which can be very confusing to debug! (I have made this mistake before and it was not fun to figure out what was going wrong)
GROUPED_SETTINGS = {
...,
"windvars": [..., "LBV_flag"],
...
}

Use the new setting in the Fortran code
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -135,6 +126,6 @@ For the params.ini file, add a new entry for the new setting with a reasonable d
with open("src/cosmic/tests/data/Params.ini", "a") as f:
f.write(f"\n\n{setting_name} = {setting_value}\n\n")

add_setting_to_test_files("lbv_flag", 1)
add_setting_to_test_files("LBV_flag", 1)

And that's it! You've added a new setting to COSMIC. Now you should absolutely run the tests to make sure everything is working properly! Better yet, add more tests that specifically test the new setting to make sure it's working as expected.
66 changes: 66 additions & 0 deletions src/cosmic/consts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
__all__ = ['ALL_COLUMNS', 'INTEGER_COLUMNS', 'BPP_COLUMNS', 'BCM_COLUMNS', 'KICK_COLUMNS', 'GROUPED_SETTINGS']

# Make this match the ordering of all_cols in bpp_array.f
ALL_COLUMNS = ['tphys', 'mass_1', 'mass_2', 'kstar_1', 'kstar_2', 'sep', 'porb',
'ecc', 'RRLO_1', 'RRLO_2', 'evol_type', 'aj_1', 'aj_2', 'tms_1',
'tms_2', 'massc_he_layer_1', 'massc_he_layer_2', 'massc_co_layer_1', 'massc_co_layer_2',
'rad_1', 'rad_2', 'mass0_1',
'mass0_2', 'lum_1', 'lum_2', 'teff_1', 'teff_2', 'radc_1',
'radc_2', 'menv_1', 'menv_2', 'renv_1', 'renv_2', 'omega_spin_1',
'omega_spin_2', 'B_1', 'B_2', 'bacc_1', 'bacc_2', 'tacc_1',
'tacc_2', 'epoch_1', 'epoch_2', 'bhspin_1', 'bhspin_2',
'deltam_1', 'deltam_2', 'SN_1', 'SN_2', 'bin_state', 'merger_type', 'metallicity']

INTEGER_COLUMNS = ["bin_state", "bin_num", "kstar_1", "kstar_2", "SN_1", "SN_2", "evol_type"]

BPP_COLUMNS = ['tphys', 'mass_1', 'mass_2', 'kstar_1', 'kstar_2',
'sep', 'porb', 'ecc', 'RRLO_1', 'RRLO_2', 'evol_type',
'aj_1', 'aj_2', 'tms_1', 'tms_2',
'massc_he_layer_1', 'massc_he_layer_2', 'massc_co_layer_1', 'massc_co_layer_2', 'rad_1', 'rad_2',
'mass0_1', 'mass0_2', 'lum_1', 'lum_2', 'teff_1', 'teff_2',
'radc_1', 'radc_2', 'menv_1', 'menv_2', 'renv_1', 'renv_2',
'omega_spin_1', 'omega_spin_2', 'B_1', 'B_2', 'bacc_1', 'bacc_2',
'tacc_1', 'tacc_2', 'epoch_1', 'epoch_2',
'bhspin_1', 'bhspin_2']

BCM_COLUMNS = ['tphys', 'kstar_1', 'mass0_1', 'mass_1', 'lum_1', 'rad_1',
'teff_1', 'massc_he_layer_1', 'massc_co_layer_1', 'radc_1', 'menv_1', 'renv_1', 'epoch_1',
'omega_spin_1', 'deltam_1', 'RRLO_1', 'kstar_2', 'mass0_2', 'mass_2',
'lum_2', 'rad_2', 'teff_2', 'massc_he_layer_2', 'massc_co_layer_2', 'radc_2', 'menv_2',
'renv_2', 'epoch_2', 'omega_spin_2', 'deltam_2', 'RRLO_2',
'porb', 'sep', 'ecc', 'B_1', 'B_2',
'SN_1', 'SN_2', 'bin_state', 'merger_type']

KICK_COLUMNS = ['star', 'disrupted', 'natal_kick', 'phi', 'theta', 'mean_anomaly',
'delta_vsysx_1', 'delta_vsysy_1', 'delta_vsysz_1', 'vsys_1_total',
'delta_vsysx_2', 'delta_vsysy_2', 'delta_vsysz_2', 'vsys_2_total',
'theta_euler', 'phi_euler', 'psi_euler', 'randomseed', 'tphys', 'bin_num']

GROUPED_SETTINGS = {
"windvars": [
"neta", "bwind", "hewind", "beta", "xi", "acc2",
"epsnov", "eddfac", "gamma", "LBV_flag",
],
"cevars": ["alpha1", "lambdaf", "qcrit_array"],
"ceflags": ["ceflag", "cekickflag", "cemergeflag", "cehestarflag", "ussn"],
"flags": [
"tflag", "ifflag", "wdflag", "rtmsflag", "bhflag", "remnantflag",
"maltsev_mode", "grflag", "bhms_coll_flag", "wd_mass_lim", "aic",
"bdecayfac", "windflag", "qcflag", "eddlimflag", "bhspinflag",
"rejuvflag", "htpmb", "ST_cr", "ST_tide",
],
"snvars": [
"pisn", "ppi_co_shift", "ppi_extra_ml", "maltsev_fallback",
"maltsev_pf_prob", "fryer_mass_limit", "mxns", "fryer_fmix",
"fryer_mcrit_nsbh", "ecsn", "ecsn_mlow", "sigma", "sigmadiv",
"bhsigmafrac", "polar_kick_angle", "natal_kick_array", "bhspinmag",
"rembar_massloss", "kickflag", "mm_mu_ns", "mm_mu_bh",
],
"points": ["pts1", "pts2", "pts3"],
"mtvars": ["don_lim", "acc_lim", "smt_periastron_check"],
"magvars": ["bconst", "ck"],
"tidalvars": ["fprimc_array"],
"mixvars": ["rejuv_fac"],
"metvars": ["zsun"],
"rand1": ["randomseed"]
}
Loading
Loading