Skip to content

Draft: Extending custom reference states to active and passive scalar fields.#586

Merged
illorenzo7 merged 18 commits into
mainfrom
cianwilson/chi-reference-states
Jul 14, 2026
Merged

Draft: Extending custom reference states to active and passive scalar fields.#586
illorenzo7 merged 18 commits into
mainfrom
cianwilson/chi-reference-states

Conversation

@cianwilson

@cianwilson cianwilson commented Apr 7, 2026

Copy link
Copy Markdown
Member

This pull request extends custom references states to active and passive scalar fields by adding a new custom reference state file type. One of these files can be set for active and passive scalar fields and each file contains the reference states for all active or passive scalar fields respectively.

These file names can be set using chi_a_custom_reference_file and chi_p_custom_reference_file for active and passive scalar fields respectively. Other new namelist parameters are:

    override_chi_a_constant, override_chi_p_constant,
    chi_a_constants, chi_p_constants,
    with_custom_chi_a_constants, with_custom_chi_p_constants,
    with_custom_chi_a_functions, with_custom_chi_p_functions

which do the equivalent of their reference state parameters but for active and passive scalar fields.

Using these files it is currently possible to set reference states for:

    constants = ['dchirefdr_scale', 'kappa_chi_scale', 'source_chi_scale', 'buoy_chi_scale']
    functions = ['dchirefdr', 'kappa_chi', 'source_chi', 'd_ln_kappa_chi', 'buoy_chi']

Note that the buoyancy constant and function will be ignored for passive scalar fields.

Within Rayleigh this also required dchiref and the source terms to be activated (they were previously turned off).

Also fixed some typos and deprecation warnings.

A test has been added in tests/chi_custom_reference that provides example input files. The test runs a case using the existing implementation in temperature and checks that the new implementation for scalar fields produces the same answer.

Documentation has been updated doc/source/User_Guide/arbitrary_scalar_fields.txt.

This is done by creating a new input file type, based on the reference state file but for scalar fields alone.

These can be set using `chi_a_custom_reference_file` and `chi_p_custom_reference_file` for active and passive scalar fields
respectively.  Other new namelist parameters are:
```
    override_chi_a_constant, override_chi_p_constant,
    chi_a_constants, chi_p_constants,
    with_custom_chi_a_constants, with_custom_chi_p_constants,
    with_custom_chi_a_functions, with_custom_chi_p_functions
```
which do the equivalent of their reference state parameters but for active and passive scalar fields.

Currently it is possible to set reference states for:
```
    constants = ['dchirefdr_scale', 'kappa_chi_scale', 'source_chi_scale', 'buoy_chi_scale']
    functions = ['dchirefdr', 'kappa_chi', 'source_chi', 'd_ln_kappa_chi', 'buoy_chi']
```
The buoyancy constant and function will be ignored for passive scalar fields.

Hooked up the dchiref in the assembly of the scalar fields as well as the source terms.

Also fixed some typos and deprecation warnings.

This is untested and undocumented so far.  More to come.
@cianwilson cianwilson self-assigned this Apr 7, 2026
The test currently compares running an augmented source T case with an augmented source chi case with and without advecting a reference state.

I haven't been able to get the same answer generated with and without advecting the reference state yet.

Implementing this test involved allowing rmin and rmax to be available always to generic input generation
(rayleigh_spectral_input.py).
@cianwilson
cianwilson marked this pull request as ready for review July 12, 2026 17:39
# )+ end of grouping
# - from http://rick.measham.id.au/paste/explain.pl
r = re.compile(r'(?:[^,; '+os.linesep+'([{]|\([^)]*\)|\[[^]]*\]|\{[^}]*\})+')
r = re.compile(r'(?:[^,; '+os.linesep+'([{]|\\([^)]*\\)|\\[[^]]*\\]|\\{[^}]*\\})+')

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a fix for a warning I came across while developing everything else here.

return m_max

def radial_extents(rmin=None, rmax=None, aspect_ratio=None, shell_depth=None):
def radial_extents(rmin=None, rmax=None, aspect_ratio=None, shell_depth=None, throw=True):

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This modification allows this function to be called regardless of whether our function depends on radius or not and therefore makes rmax and rmin available more generally. It will still throw an error if it can't make the conversion and the conversion is needed (but it won't throw if the conversion is still not needed).

Though unrelated to the PR specifically it is a necessary change for the test.

Comment thread src/Physics/PDE_Coefficients.F90 Outdated
endif
Call stdout%print('Source requires both d_3 and g_3 to be set.')
if (active) Call stdout%print('Buoyancy requires both d_4 and g_5 to be set.')
Call stdout%print('Reference dchidr requires g_1 to be set (sets d_11 to 1 if unspecified).')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be d_1 not d_11.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed now, thanks!

Comment thread src/Physics/PDE_Coefficients.F90 Outdated
Read(15) dummy ! n_chi_functions
Read(15) n_scalars
if (n_scalars .gt. n_l_scalars) then
Call stdout%print('ERROR: number of scalars in the custom reference file')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think since the code continues to try to read the file, it should be a "WARNING" (this is part of the larger warning/error issue of #423 so not unique to this part of the code). Also perhaps the print message should say what the code does in this case? It looks like it ignores n_l_scalars from main_input and just reads whatever is in the custom file...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've modified the ERROR -> WARNING and stated what will happen if you carry on.

I've also tried changing the logic underneath so that n_scalars and n_l_scalars are used appropriately. This is untested however as all the tests have nscalars == n_l_scalars.

Comment thread src/Physics/PDE_Coefficients.F90 Outdated
Read(15) ((fset(i, j), i = 1, n_chi_functions), j = 1, n_scalars)
Read(15) ((input_constants(i, j), i = 1, n_chi_constants), j = 1, n_scalars)

! Cset(i) is 1 if a constant(i) was set; it is 0 otherwise.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make this set(i,j) in comments...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, thanks!

@cianwilson
cianwilson removed the request for review from feathern July 14, 2026 20:26

@illorenzo7 illorenzo7 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just checked all this over the last few days and it looks good to me! Merging.

@illorenzo7 illorenzo7 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just checked all this over the last few days and it looks good to me! Merging.

@illorenzo7
illorenzo7 merged commit 622be93 into main Jul 14, 2026
8 checks passed
@cianwilson

Copy link
Copy Markdown
Member Author

Thanks @illorenzo7 !

@cianwilson
cianwilson deleted the cianwilson/chi-reference-states branch July 15, 2026 01:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants