Skip to content

Tabulated optically thin radiative cooling module with Townsend integration#349

Open
dutta-alankar wants to merge 40 commits into
idefix-code:developfrom
dutta-alankar:master
Open

Tabulated optically thin radiative cooling module with Townsend integration#349
dutta-alankar wants to merge 40 commits into
idefix-code:developfrom
dutta-alankar:master

Conversation

@dutta-alankar

@dutta-alankar dutta-alankar commented Sep 6, 2025

Copy link
Copy Markdown
Contributor

I have implemented optically thin radiative cooling module for Idefix. I have tested this for by allowing cooling of a collection of cells (initially at $2\times 10^6 \ \rm K$) in a uniform domain (and calculating temperature and $-\dot{e}/n_H^2$ from the code over time) which seems to exactly reproduce the cooling rate as supplied by the table read during runtime by the code (screenshot attached). The setup and analysis code is attached here for reference and further testing. I have also put in a sample Cloudy generated equilibrium cooling rate table for plasma at solar metallicity in presence of HM12 UV photo-ionizing background at redshift 0.

The integration method follows the Townsend algorithm (https://ui.adsabs.harvard.edu/abs/2009ApJS..181..391T/abstract), which is quite efficient in calculating the pressure drop due to radiative cooling. There is also a way to set a floor that switches off cooling below some temperature, as required by many popular setups. I have also included a small .rst documentation for this module.

Let me know if this is something worth integrating to the main repo and if something additional needs to be done.

Test setup:
cooling-test.tar.gz

Test result (purple: supplied table; green: code result):
image

@dutta-alankar

dutta-alankar commented Oct 20, 2025

Copy link
Copy Markdown
Contributor Author

@glesur I noticed that use of CGS quantities has now been incorporated into Idefix. If this radiative cooling module with Townsend integration is something you/developer community thinks worth being integrated into Idefix, then I would be happy to change the code to utilize the CGS units capability. Let me know.

Comment thread src/fluid/addSourceTerms.hpp Outdated
Comment thread src/fluid/fluid.hpp
@dutta-alankar

dutta-alankar commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

I have now updated the Townsend radiative cooling module to utilize the code units to CGS units conversion as a runtime parameter from the ini file and the documentation has been updated accordingly along with the addition of a test problem of an advecting uniform box undergoing cooling in test/HD/CoolBox. @glesur @neutrinoceros Please let me know if you would like to have this feature in Idefix. I have been using this modified version of Idefix in simulating turbulent radiatively cooling mixing layers and also plan to use this in upcoming cloud-crushing simulations.

@neutrinoceros

Copy link
Copy Markdown
Collaborator

Hi @dutta-alankar
For the record, I have no say in what goes into idefix and it's not part of my job to work on it anymore.

@dutta-alankar

Copy link
Copy Markdown
Contributor Author

Hi @dutta-alankar For the record, I have no say in what goes into idefix and it's not part of my job to work on it anymore.

@neutrinoceros I understand. Apologies for my lack of knowledge on the latest developments and dynamics in the Idefix development team.

@neutrinoceros

Copy link
Copy Markdown
Collaborator

No worries

@glesur

glesur commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

@dutta-alankar thanks for the heads up and the additional test. I owe you an applogy for the delay in working on your PR...

I'll submit a review shortly, but in the meantime, I think you can probably start with fixing the pre-commit issues.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 22 out of 24 changed files in this pull request and generated 6 comments.

Comment thread src/fluid/fluid.hpp
Comment thread src/fluid/cooling/cooling.cpp Outdated
Comment on lines +100 to +104
// tabulated data does not enclose the temperature value
printf("RadCooling::TownsendIntegration Temperature out of range: T=%e, "
"valid range=[%e, %e]\n",
temperature, temperature_min_data, temperature_max_data);
Kokkos::abort("RadCooling::TownsendIntegration Temperature out of range");

@dutta-alankar dutta-alankar Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It might be okay to let it pass.

Comment thread src/global.cpp
Comment thread src/fluid/cooling/coolingConstructor.hpp Outdated
Comment thread doc/source/modules/radCooling.rst
Fix to not have radiative cooling in isothermal setup

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 22 out of 24 changed files in this pull request and generated 6 comments.

Comment thread src/fluid/cooling/cooling.cpp Outdated
Comment thread src/global.cpp
Comment thread doc/source/modules/radCooling.rst Outdated
Comment thread doc/source/modules/radCooling.rst Outdated
Comment thread test/HD/CoolBox/idefix.ini
Comment thread src/fluid/cooling/coolingConstructor.hpp Outdated
@glesur

glesur commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

@dutta-alankar : good idea for the CIs. Drop me a message when you think this is ready so that I can trigger the workflow on our side.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 26 out of 28 changed files in this pull request and generated 5 comments.

Comment thread src/fluid/cooling/cooling.cpp Outdated
Comment thread src/fluid/cooling/cooling.cpp Outdated
Comment thread doc/source/modules/radCooling.rst
Comment on lines +22 to +23
explicit Fluid_AddSourceTermsFunctor(Fluid<Phys> *hydro, real dt):
hydroin(hydro) {

@dutta-alankar dutta-alankar Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not related to my PR and I leave it to @glesur to consider this or not.

IdefixArray3D<real> csIsoArr;
IdefixArray3D<real> delta_eng_cool;

Fluid<Phys> *hydroin;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Again not related to this PR and left to @glesur to decide

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@dutta-alankar

dutta-alankar commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

@dutta-alankar : good idea for the CIs. Drop me a message when you think this is ready so that I can trigger the workflow on our side.

@glesur I think now you can trigger the CI/CD workflow from your end.

@dutta-alankar

Copy link
Copy Markdown
Contributor Author

@glesur In case you missed my previous comment. I think that this PR is now at a good state when you can trigger a CI/CD workflow.

The test runner introduced on develop (idfx_test_run.py) parses every
testme.json during pytest collection and validates that the 'namings' list
covers all parameters that vary across variants. The CoolBox testme.json
predates the finalized schema: its variants vary 'mpi' while namings only
listed 'ini', so collection raised

  Fail to generate tests from HD/CoolBox/testme.json :
  Naming parameter list not match the auto-detectection [...]

Since one malformed testme.json aborts the whole collection, every CI test
step of every job failed at its first test, regardless of -subdir.

Two changes:

* Rewrite the file following the canonical schema (cf. HD/FargoPlanet):
  shared settings move to a 'default' block (dec as integers), and the two
  runs are expressed as a single variant with mpi: [false, true] under
  namings "ini,mpi". Generates the same two configurations as intended.

* Drop the check_file_produced entry: the runner evaluates it with a bare
  filename after restoring the repo-root cwd, so the check cannot see files
  written in the problem directory. The standard test (python/testidefix.py)
  already loads and validates analysis-time-temperature.dat, which covers
  the intent of the check.
@dutta-alankar

Copy link
Copy Markdown
Contributor Author

@glesur Looks like the code can now clear the CI/CD tests.

@dutta-alankar

Copy link
Copy Markdown
Contributor Author

@glesur I am now happy that all the tests passed. Although the test is classified in the Parabolic test group, I think this is a minor misclassification.

@svalat svalat left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hi @dutta-alankar,
we took some time to review your PR. Following some remarks and questions.

As said in the following comments, there are several goals here, if some can move in dedicated PRs it would be very nice to ease the tracking in the git history.

data file

The data file ./src/fuild/cooling/cooltable.dat is redundant with the one in the test case. As the one in the src is not used it would be nice the remove it.


.. code-block:: ini

Cooling Tabulated cooltable.dat Townsend TcoolFloor 1.0e+04

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

As we might need to extend those arguments in the future and they have different meanings I would create a new section and set the parameters as distinct keys and enable when the section is present via input.CheckBlock().

An example (to adapt to what you think is better):

[Cooling]
mode=tabulated
table=cooltable.dat
integration=Townsend
# maybe 0 to disable as it is in K ?
t_cool_floor=1.0e+04

Comment thread pytools/idfx_test.py

# transform all arguments from args into attributes of this instance
self.__dict__.update(vars(args))
idefix_dir = os.path.realpath(os.path.abspath(self.idefixDir))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is this patch required here ? I see no effect on the rest of the PR with those variables ?

If I well understand it is to call testme.py from anywhere by using abs paths ?

If it is that, can you make a dedicated PR for that as we need to look on side effects ?

// delta_eng(k,j,i) = eos.GetInternalEnergy(del_prs, Vc(RHO,k,j,i));
}
else {
while (T_indx_lo<=T_indx_hi) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why not using the interpolation of the LookupTable class you included ?

As it looks redundant with what does LookupTable.

Is it because you want to interpolate with log ? But in this case it can probably be done by putting the table in log and using the linear interpolation of LookupTable ? Or I miss-understood something ?

this->data = hydroin->data;
this->eos = *(hydroin->eos.get());

const int nCoolingParams = input.CheckEntry("Hydro","Cooling");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

As said in the doc part, in term of API it would be better to put the options in a [Cooling] section and use keys for the arguments as they have different semantics and will probably evolve.

Comment thread src/global.cpp
sslogFileName << "idefix." << idfx::prank << ".log";

std::string logFileName(sslogFileName.str());
std::string logFileName;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The patch into this file as a different goal than this PR, can you make it in another PR or is it already what is in #270 ?

By the way, we should avoid rush on all MPI ranks to create the directory and make it only in master rank. This is done in your other PR if I well understood.

Same remark for the changes in the 3 next files which are related.

Comment thread CMakeLists.txt
set(Kokkos_ENABLE_CUDA_LAMBDA ON CACHE BOOL "Idefix requires lambdas on Cuda" FORCE)
# CUDA_MALLOC_ASYNC disbaled by default in Kokkos 4.5, so not required here
#set(Kokkos_ENABLE_IMPL_CUDA_MALLOC_ASYNC OFF CACHE BOOL "Disable Async malloc to avoid bugs on PSM2" FORCE)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This part of the PR target another goal, is it possible to make it in a dedicated PR ?

Also I would ask two questions here which might be good to give in the dedicated PR :

  • Is this a warning or a failure ?
  • What is the OS / lib conditions to reproduce ?

Comment thread CMakeLists.txt
)
find_package(HDF5 REQUIRED)
target_link_libraries(idefix "${HDF5_LIBRARIES}")
# Prefer imported targets (matches older working behavior), then fall back.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same remark here, it targets another goal than the current PR, would it be possible to make it in a dedicated PR ?

Also if you remember the HDF5 version and OS version on which you had the issue it would be very nice.

@dutta-alankar

dutta-alankar commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

@svalat I agree that multiple file changes happened over time (~1 yr) as I not only developed this module but also tried improving/fixing parts of the code on the way. This unfortunately resulted in code changes that do not exactly fit the main goal of this PR. I apologize for this and appreciate your effort in sorting through this. I will, over the next few days, issue separate PRs with separate branches for:

  • Cooling related implementation
    • Separate Cooling block in ini
    • Usage of built-in interpolation table (with log10 space interpolation)
    • Perhaps extend the lookup table module to also parse column arranged data
  • log file directory creation
  • Addressing compile failure due to Cuda linking on CMake
  • Detection and linking of serial/parallel hdf5
  • Minor testme patch

@glesur

glesur commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

note: for the log file, we already have #270, so no need to duplicate it.

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.

5 participants