Skip to content

[SPH] Add Ormel variant of COALA source term#1830

Open
mlombart wants to merge 4 commits into
Shamrock-code:mainfrom
mlombart:extend-run-coala
Open

[SPH] Add Ormel variant of COALA source term#1830
mlombart wants to merge 4 commits into
Shamrock-code:mainfrom
mlombart:extend-run-coala

Conversation

@mlombart
Copy link
Copy Markdown
Collaborator

No description provided.

@github-actions
Copy link
Copy Markdown
Contributor

Thanks @mlombart for opening this PR!

You can do multiple things directly here:
1 - Comment pre-commit.ci run to run pre-commit checks.
2 - Comment pre-commit.ci autofix to apply fixes.
3 - Add label autofix.ci to fix authorship & pre-commit for every commit made.
4 - Add label light-ci to only trigger a reduced & faster version of the CI (need the full one before merge).
5 - Add label trigger-ci to create an empty commit to trigger the CI.

Once the workflow completes a message will appear displaying informations related to the run.

Also the PR gets automatically reviewed by gemini, you can:
1 - Comment /gemini review to trigger a review
2 - Comment /gemini summary for a summary
3 - Tag it using @gemini-code-assist either in the PR or in review comments on files

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds a new source file reference to the CMake configuration and includes a macro undefinition in the NodeEvolveDustCOALASourceTerm.hpp header. A critical issue was identified: the newly referenced source file, NodeEvolveDustCOALASourceTermOrmel.cpp, is missing from the pull request, which will result in a build failure.

Comment thread src/shammodels/sph/CMakeLists.txt
@tdavidcl
Copy link
Copy Markdown
Member

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces the NodeEvolveDustCOALASourceTermOrmel module, implementing the Ormel model for differential velocities within the dust coagulation source term. Feedback identifies a critical correctness bug where stopping times are accessed without particle offsets, alongside performance concerns regarding redundant calculations in the kernel and inefficient buffer management. Additionally, the reviewer highlighted a potential division-by-zero risk and requested a refactor of the LaTeX documentation logic to address inaccuracies and code duplication.

Comment on lines +148 to +149
Tscal ts_i = ts[i];
Tscal ts_j = ts[j];
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.

critical

The stopping time ts is an IFieldSpan, which contains per-particle per-bin data. Accessing it as ts[i] and ts[j] without the particle offset id_a_d (which is id_a * nbins) will incorrectly use the stopping times of the first few particles in the patch for every particle in the simulation. This is a critical correctness bug.

                        Tscal ts_i = ts[id_a_d + i];
                        Tscal ts_j = ts[id_a_d + j];

Comment on lines +161 to +164
Tscal t_L = cs_a / a_ext_a;
Tscal nh = rho_gas_a / (mu * mh);
Tscal Re = 62e6 * sycl::sqrt(nh / 1e5) * sycl::sqrt(T_a / 10.);
Tscal t_eta = t_L / sycl::sqrt(Re);
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.

high

These variables (t_L, nh, Re, t_eta) are independent of the bin indices i and j. Calculating them inside the dv lambda results in $O(N_{bins}^3)$ redundant calculations per particle. Moving these calculations outside the lambda will significantly improve performance.


Tscal eps_diff = 1e-16;

Tscal t_L = cs_a / a_ext_a;
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.

high

If a_ext_a (the magnitude of external acceleration) is zero, this will result in a division by zero, setting t_L to infinity and potentially causing NaNs in subsequent calculations (e.g., in St or x_St). A safety guard or a small epsilon should be added.

                        Tscal t_L   = cs_a / (a_ext_a + 1e-20);

Comment on lines +255 to +259
sham::DeviceBuffer<Tscal> massgrid_buf(nbins + 1, dev_sched);
massgrid_buf.copy_from_stdvec(massgrid);

sham::DeviceBuffer<Tscal> tensor_tabflux_coag_buf(nbins * nbins * nbins, dev_sched);
tensor_tabflux_coag_buf.copy_from_stdvec(tensor_tabflux_coag);
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.

high

Allocating and copying massgrid_buf and tensor_tabflux_coag_buf every time _impl_evaluate_internal is called (i.e., every timestep) is highly inefficient, especially for the $O(N_{bins}^3)$ tensor. These buffers should be managed as persistent members of the class or cached to avoid redundant allocations and host-to-device transfers.

Comment on lines +297 to +327
auto rhodust_eps = get_ro_edge_base(0).get_tex_symbol();
auto massgrid = get_ro_edge_base(1).get_tex_symbol();
auto tensor_tabflux_coag = get_ro_edge_base(2).get_tex_symbol();
auto part_counts = get_ro_edge_base(3).get_tex_symbol();
auto s_j = get_ro_edge_base(5).get_tex_symbol();
auto delta_v_j = get_ro_edge_base(6).get_tex_symbol();
auto S_coag = get_rw_edge_base(0).get_tex_symbol();

std::string tex = R"tex(
COALA dust coagulation source term, DG $k=0$ (Lombart et al., 2021)

Per gas particle $a$ and mass bin $j$ (monofluid: $\rho_{{\rm d},j,a}} = {s_j}_{j,a}^2$):

\begin{align}
\rho_{{\rm d},j,a} &= {s_j}_{j,a}^2 \\
\Delta m_j &= {massgrid}_{j+1} - {massgrid}_j \\
g_{j,a} &= \begin{cases}
\rho_{{\rm d},j,a} / \Delta m_j & \rho_{{\rm d},j,a} > \rho_{\rm eps} \\
0 & \text{otherwise}
\end{cases} \\
\mathrm{dv}_{l,m,a} &= \left| {delta_v_j}_{m,a} - {delta_v_j}_{l,a} \right| \\
\mathrm{flux}_{j,a} &= \sum_{l,m}
{tensor_tabflux_coag}_{j,l,m}\,
\mathrm{dv}_{l,m,a}\, g_{l,a}\, g_{m,a} \\
{S_coag}_{0,a} &= -\mathrm{flux}_{0,a}, \quad
{S_coag}_{j,a} = \mathrm{flux}_{j-1,a} - \mathrm{flux}_{j,a}
\quad (j \ge 1) \\
a &\in [0, {part_counts}), \quad j,l,m \in [0, N_{\rm bins}) \\
\rho_{\rm eps} &= {rhodust_eps}, \quad N_{\rm bins} = {nbins}
\end{align}
)tex";
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.

high

The _impl_get_tex implementation appears to be a copy-paste from NodeEvolveDustCOALASourceTerm and contains several errors (incorrect indices, missing edges, outdated formulas). Refactor this duplicated logic into a helper function or lambda to improve readability and maintainability, as per repository guidelines.

References
  1. Refactor duplicated logic into a helper function or lambda to improve readability and maintainability.

@github-actions
Copy link
Copy Markdown
Contributor

Workflow report

workflow report corresponding to commit 7017bb7
Commiter email is timothee.davidcleris@proton.me

Pre-commit check report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants