Tabulated optically thin radiative cooling module with Townsend integration#349
Tabulated optically thin radiative cooling module with Townsend integration#349dutta-alankar wants to merge 40 commits into
Conversation
|
@glesur I noticed that use of CGS quantities has now been incorporated into |
Updated energy calculation in addSourceTerms.hpp to use energy per unit volume instead of specific energy.
|
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 |
|
Hi @dutta-alankar |
@neutrinoceros I understand. Apologies for my lack of knowledge on the latest developments and dynamics in the Idefix development team. |
|
No worries |
|
@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. |
[FIX] `pre-commit` linting
| // 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"); |
There was a problem hiding this comment.
It might be okay to let it pass.
Fix to not have radiative cooling in isothermal setup Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
@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. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
| explicit Fluid_AddSourceTermsFunctor(Fluid<Phys> *hydro, real dt): | ||
| hydroin(hydro) { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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>
@glesur I think now you can trigger the CI/CD workflow from your end. |
|
@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.
|
@glesur Looks like the code can now clear the CI/CD tests. |
|
@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
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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|
|
||
| # 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)) |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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.
| sslogFileName << "idefix." << idfx::prank << ".log"; | ||
|
|
||
| std::string logFileName(sslogFileName.str()); | ||
| std::string logFileName; |
There was a problem hiding this comment.
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.
| 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) | ||
|
|
There was a problem hiding this comment.
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 ?
| ) | ||
| find_package(HDF5 REQUIRED) | ||
| target_link_libraries(idefix "${HDF5_LIBRARIES}") | ||
| # Prefer imported targets (matches older working behavior), then fall back. |
There was a problem hiding this comment.
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.
|
@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:
|
|
note: for the log file, we already have #270, so no need to duplicate it. |
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
Cloudygenerated 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
.rstdocumentation 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):
