Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
coala_interface.hpp File Reference

COALA dust coagulation helpers for a DG \(k=0\) (piecewise-constant) basis. More...

#include "shambase/aliases_int.hpp"
#include "shambase/assert.hpp"
#include "shambase/mdspan_concepts.hpp"
#include <experimental/mdspan>
#include <concepts>
#include <vector>
Include dependency graph for coala_interface.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  shamphys::TabfluxCoagK0Sparse< T, Tidx >
 Sparse storage of tensor_tabflux_coag ( \(k=0\)). More...
struct  shamphys::TabfluxCoagK0SparseView< T, Tidx >
 Device view of a TabfluxCoagK0Sparse (see its documentation for the layout). More...
struct  shamphys::TabfluxCoagK0SparseView< T, Tidx >::PairEntries

Functions

template<class T>
requires requires(decltype(rho_dust) rd, int j) { { rd(j) } -> std::same_as<T>; }
void shamphys::compute_gij_k0 (auto &&rho_dust, T rho_eps, shambase::is_mdspan_rank< 1 > auto massgrid, shambase::is_mdspan_rank< 1 > auto gij)
 Build \(g_j\) coefficients on the piecewise-constant DG basis ( \(k=0\)).
template<class Func>
requires requires(Func f, int a, int b) { { f(a, b) }; }
void shamphys::compute_flux_coag_k0_kdv (int nbins, shambase::is_mdspan_rank< 1 > auto gij, shambase::is_mdspan_rank< 3 > auto tensor_tabflux_coag, Func &&dv, shambase::is_mdspan_rank< 1 > auto flux)
 Coagulation flux at bin right edges for a ballistic kernel ( \(k=0\)).
template<class T, class Tidx = u32>
TabfluxCoagK0Sparse< T, Tidx > shamphys::make_tabflux_coag_k0_sparse (int nbins, shambase::is_mdspan_rank< 3 > auto tensor_tabflux_coag)
 Build the TabfluxCoagK0Sparse form of tensor_tabflux_coag.
template<class T, class Tidx, class Func>
requires requires(Func f, int a, int b) { { f(a, b) }; }
void shamphys::compute_flux_coag_k0_kdv (int nbins, shambase::is_mdspan_rank< 1 > auto gij, TabfluxCoagK0SparseView< T, Tidx > tabflux, Func &&dv, shambase::is_mdspan_rank< 1 > auto flux)
 Same as compute_flux_coag_k0_kdv but using the TabfluxCoagK0Sparse form.
void shamphys::coala_flux_diff (shambase::is_mdspan_rank< 1 > auto flux, shambase::is_mdspan_rank< 1 > auto S_coag)
 Convert interface fluxes to a mass-bin coagulation source term.
template<class T, class FuncDv, class FuncRhoDust>
void shamphys::coala_k0_source_term (int nbins, FuncDv &&dv, FuncRhoDust &&rho_dust, T rho_eps, shambase::is_mdspan_rank< 1 > auto massgrid, auto tabflux_coag, shambase::is_mdspan_rank< 1 > auto gij, shambase::is_mdspan_rank< 1 > auto flux, shambase::is_mdspan_rank< 1 > auto S_coag)

Detailed Description

COALA dust coagulation helpers for a DG \(k=0\) (piecewise-constant) basis.

Author
Maxime Lombart (maxim.nosp@m.e.lo.nosp@m.mbart.nosp@m.@cea.nosp@m..fr)
Timothée David–Cléris (tim.s.nosp@m.hamr.nosp@m.ock@p.nosp@m.roto.nosp@m.n.me)

C++ counterparts of the COALA Python routines used to build dust coagulation source terms in the conservative form of the Smoluchowski equation (Lombart et al., 2021). The reference implementation lives in src/pylib/shamrock/external/coala/interface_coala_shamrock.py and src/pylib/shamrock/external/coala/generate_flux_intflux.py.

Only the coagulation flux with \(k=0\) approximation.

Definition in file coala_interface.hpp.

Function Documentation

◆ coala_flux_diff()

void shamphys::coala_flux_diff ( shambase::is_mdspan_rank< 1 > auto flux,
shambase::is_mdspan_rank< 1 > auto S_coag )

Convert interface fluxes to a mass-bin coagulation source term.

Applies the DG \(k=0\) divergence operator (finite difference across bin boundaries) to obtain the source term \(S_{\rm coag}\) in the conservative form of the Smoluchowski equation:

\[ S_{\rm coag}[0] = -\mathrm{flux}[0], \qquad S_{\rm coag}[j] = \mathrm{flux}[j-1] - \mathrm{flux}[j] \quad (j \ge 1) \]

Parameters
fluxRank-1 view of coagulation fluxes at bin right edges
S_coagRank-1 output view of the same length; filled in place

Definition at line 309 of file coala_interface.hpp.

◆ coala_k0_source_term()

template<class T, class FuncDv, class FuncRhoDust>
void shamphys::coala_k0_source_term ( int nbins,
FuncDv && dv,
FuncRhoDust && rho_dust,
T rho_eps,
shambase::is_mdspan_rank< 1 > auto massgrid,
auto tabflux_coag,
shambase::is_mdspan_rank< 1 > auto gij,
shambase::is_mdspan_rank< 1 > auto flux,
shambase::is_mdspan_rank< 1 > auto S_coag )

Definition at line 321 of file coala_interface.hpp.

◆ compute_flux_coag_k0_kdv() [1/2]

template<class Func>
requires requires(Func f, int a, int b) { { f(a, b) }; }
void shamphys::compute_flux_coag_k0_kdv ( int nbins,
shambase::is_mdspan_rank< 1 > auto gij,
shambase::is_mdspan_rank< 3 > auto tensor_tabflux_coag,
Func && dv,
shambase::is_mdspan_rank< 1 > auto flux )
inline

Coagulation flux at bin right edges for a ballistic kernel ( \(k=0\)).

Evaluates the flux approximation at the right boundary of each mass bin, \(\mathrm{flux}[j] \approx F(m_{j+1/2})\), by summing over all bin pairs \((l, m)\):

\[ \mathrm{flux}[j] = \sum_{l,m} \mathrm{tensor\_tabflux\_coag}[j,l,m]\, \mathrm{dv}(l,m)\, g_l\, g_m \]

Equivalent to the NumPy contraction einsum("jlm,lm,l,m->j", tensor_tabflux_coag, dv, gij, gij).

gij, tensor_tabflux_coag and flux are expected to share the same scalar element type.

Template Parameters
FuncCallable invoked as dv(l, m) returning the differential velocity between bins \(l\) and \(m\) (e.g. \(|\mathbf{v}_m - \mathbf{v}_l|\))
Parameters
nbinsNumber of dust mass bins
gijRank-1 std::mdspan (shambase::is_mdspan_rank<1>) of DG coefficients \(g_l\); extent nbins
tensor_tabflux_coagRank-3 std::mdspan (shambase::is_mdspan_rank<3>) of precomputed coagulation flux entries; extents nbins (\times) nbins (\times) nbins
dvPair-wise differential-velocity callable
fluxRank-1 std::mdspan (shambase::is_mdspan_rank<1>) of output fluxes; extent nbins, written in place

Definition at line 109 of file coala_interface.hpp.

◆ compute_flux_coag_k0_kdv() [2/2]

template<class T, class Tidx, class Func>
requires requires(Func f, int a, int b) { { f(a, b) }; }
void shamphys::compute_flux_coag_k0_kdv ( int nbins,
shambase::is_mdspan_rank< 1 > auto gij,
TabfluxCoagK0SparseView< T, Tidx > tabflux,
Func && dv,
shambase::is_mdspan_rank< 1 > auto flux )
inline

Same as compute_flux_coag_k0_kdv but using the TabfluxCoagK0Sparse form.

Pairs \((l,m)\) without any non-zero entry are skipped before evaluating \(\mathrm{dv}(l,m)\).

Parameters
nbinsNumber of dust mass bins
gijRank-1 std::mdspan of DG coefficients \(g_l\); extent nbins
tabfluxView of the TabfluxCoagK0Sparse tensor
dvPair-wise differential-velocity callable, invoked as dv(l, m)
fluxRank-1 std::mdspan of output fluxes; extent nbins, written in place

Definition at line 262 of file coala_interface.hpp.

Here is the call graph for this function:

◆ compute_gij_k0()

template<class T>
requires requires(decltype(rho_dust) rd, int j) { { rd(j) } -> std::same_as<T>; }
void shamphys::compute_gij_k0 ( auto && rho_dust,
T rho_eps,
shambase::is_mdspan_rank< 1 > auto massgrid,
shambase::is_mdspan_rank< 1 > auto gij )
inline

Build \(g_j\) coefficients on the piecewise-constant DG basis ( \(k=0\)).

For each mass bin \(j\), converts the dust density to the polynomial coefficient \(g_j = \rho_{\rm d,j} / \Delta m_j\) when \(\rho_{\rm d,j} > \rho_{\rm eps}\), and sets \(g_j = 0\) otherwise, with \Delta m_j = massgrid[j+1] - massgrid[j] the bin width from consecutive mass-grid edges.

Template Parameters
TFloating-point scalar type; rho_dust must satisfy rho_dust(j) -> T, and massgrid / gij must be rank-1 std::mdspan with element type T
Parameters
rho_dustCallable invoked as rho_dust(j) returning dust density in bin \(j\)
rho_epsDensity threshold below which \(g_j\) is set to zero
massgridRank-1 std::mdspan (shambase::is_mdspan_rank<1>) of bin-edge masses; extent must be gij.extent(0) + 1
gijRank-1 std::mdspan (shambase::is_mdspan_rank<1>) of DG coefficients; one entry per bin, written in place

Definition at line 56 of file coala_interface.hpp.

◆ make_tabflux_coag_k0_sparse()

template<class T, class Tidx = u32>
TabfluxCoagK0Sparse< T, Tidx > shamphys::make_tabflux_coag_k0_sparse ( int nbins,
shambase::is_mdspan_rank< 3 > auto tensor_tabflux_coag )
inline

Build the TabfluxCoagK0Sparse form of tensor_tabflux_coag.

Parameters
nbinsNumber of dust mass bins
tensor_tabflux_coagRank-3 std::mdspan of the dense tensor; extents nbins (\times) nbins (\times) nbins

Definition at line 210 of file coala_interface.hpp.