Skip to content

Tabulated optically thin radiative cooling module with Townsend integration#349

Open
dutta-alankar wants to merge 23 commits into
idefix-code:masterfrom
dutta-alankar:master
Open

Tabulated optically thin radiative cooling module with Townsend integration#349
dutta-alankar wants to merge 23 commits into
idefix-code:masterfrom
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.

@dutta-alankar

dutta-alankar commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

@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.

No worries. I myself, had been occupied with many other stuffs and this got to the back burner for a long while. I have fixed the linting from the pre-commit report.

@glesur

glesur commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

@dutta-alankar: you should target the develop branch as this is not a hotfix.

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

This PR introduces an optically thin radiative cooling capability to the Hydro module (tabulated cooling with Townsend integration), along with a dedicated test case, documentation, and a few build/logging quality-of-life improvements to support the new module and runtime outputs.

Changes:

  • Add a new Hydro submodule for tabulated optically thin radiative cooling with Townsend integration and a configurable temperature floor.
  • Add a CoolBox test setup (ini + setup/analysis) and new module documentation pages wired into the Sphinx docs.
  • Improve runtime logging behavior (log directory handling) and update CMake logic for CUDA librt and HDF5 detection/parallel validation.

Reviewed changes

Copilot reviewed 19 out of 21 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
test/HD/CoolBox/setup.cpp Adds a cooling validation analysis that writes temperature and inferred cooling rates over time.
test/HD/CoolBox/idefix.ini Defines a small uniform-domain run configured to use the new Tabulated/Townsend cooling entry.
test/HD/CoolBox/definitions.hpp Declares a basic 3D Cartesian test configuration.
src/input.hpp Adds state to control log enabling and track executable directory for log fallback.
src/input.cpp Determines an executable directory and enables log files after parsing input/CLI options.
src/global.hpp Extends the logging API to accept an optional log directory.
src/global.cpp Implements log-directory creation and explicit erroring on log open failure.
src/fluid/showConfig.hpp Fixes an Ohmic typo and prints cooling configuration when enabled.
src/fluid/fluid.hpp Plumbs cooling into Fluid: adds RadCooling ownership and initialization.
src/fluid/fluid_defs.hpp Adds a cooling-related function typedef (currently unused in the diff).
src/fluid/cooling/cooling.hpp Declares the new RadCooling class and parses [Hydro]:Cooling options.
src/fluid/cooling/cooling.cpp Implements Townsend integration and computes per-cell energy source terms.
src/fluid/cooling/CMakeLists.txt Adds cooling sources/includes to the build.
src/fluid/CMakeLists.txt Wires the cooling subdirectory into the fluid build.
src/fluid/addSourceTerms.hpp Applies cooling energy deltas during source-term application.
doc/source/programmingguide.rst Fixes a small typo in idefix_for/idefix_reduce examples (iengiend).
doc/source/modules/radCooling.rst Adds module documentation for radiative cooling and its input parameters.
doc/source/modules.rst Adds the new cooling module page to the modules index.
CMakeLists.txt Adds CUDA librt workaround and improves HDF5 target selection + parallel HDF5 checks.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +57 to +63
#include "fluid.hpp"

template<typename Phys>
RadCooling::RadCooling(Input &input, Grid &grid, Fluid<Phys> *hydroin):
Vc(hydroin->Vc),
Vs(hydroin->Vs) {
idfx::pushRegion("RadCooling::RadCooling");
Comment on lines +11 to +12
#include <string>

Comment on lines +207 to 209
if (coolingOn) {
Uc(ENG,k,j,i) += delta_eng_cool(k,j,i); // energy per unit volume
}
Comment on lines +167 to +170
else {
del_prs = ZERO_F;
delta_eng(k,j,i) = ZERO_F;
}
Comment thread test/HD/CoolBox/setup.cpp
Comment on lines +82 to +85
void MakeAnalysis(DataBlock & data) {
// Mirror data on host for analysis reductions.
DataBlockHost d(data);
d.SyncFromDevice();
Comment on lines +9 to +13
The ``RadiativeCooling`` module implements the computation of the loss of internal thermal energy
due radiation in an optically thin medium. Physically, it solves for :math:`\dot_{e}=\mathcal{L}`,
where we have used :math:`\mathcal{L}=-n_H^2 \Lambda (T)` (where :math:`T` is the gas temperature,
:math:`n_H=\rho X_H/m_p` is the total hydrogen number density, and :math:`\Lambda(T)`) is the
radiative cooling rate computed seperately from quantum mechanical calculations
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.

4 participants