Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
159 commits
Select commit Hold shift + click to select a range
72244f8
Added new branch with collisionless TC from develop
vreville Dec 3, 2024
cb3bea8
Fixed undeclared CL arrays (GPU compiling)
vreville Dec 12, 2024
6ec6d0d
collisionless tc as an option of bragTDiffusion
Dec 14, 2024
9ac6698
idefix error includes collisionless status
vreville Dec 16, 2024
94a71d2
Added a saturation option for collisionless formulation
vreville Dec 20, 2024
e2f7a9a
add a column Density example
glesur Jan 12, 2025
26ffc60
add some documentation
glesur Jan 12, 2025
a1e6e67
add it to the tests
glesur Jan 12, 2025
9c58596
imrove documentation
glesur Jan 12, 2025
6283fd5
add doc link for column density
glesur Jan 12, 2025
8277ed0
missing testme file
glesur Jan 12, 2025
31ae1b8
add a 3D interface for column density computation
glesur Jan 14, 2025
d656036
Upwind scheme for cless TC with limiters + tests
Jan 15, 2025
7c10ec0
fix dimensions for alias
glesur Jan 15, 2025
79e70cf
updated ShowConfig functions from braginskii tc and viscosity to disp…
jeankpf Jan 16, 2025
c1cd824
Merge pull request #1 from jeankpf/collisionlessTC
vreville Jan 16, 2025
4286299
Merge pull request #316 from idefix-code/V2.2.00
glesur Jan 18, 2025
d0f348a
Génération automatique de plots de performance dans la doc
Jan 17, 2025
a61eb61
Updated doc for Collisionless TC
vreville Jan 20, 2025
7bef7a9
Corrected doc typo
vreville Jan 20, 2025
8f48bc2
Corrected typo
vreville Jan 21, 2025
1f891c7
add global routines to dump Idefix arrays (useful for debugging or
glesur Jan 21, 2025
afc3e4d
add missing header
glesur Jan 21, 2025
e840e2f
revert back to old reference commit sha to avoid merge conflicts
glesur Jan 21, 2025
ac10470
go back to last reference before fork
glesur Jan 22, 2025
76e399a
Récupération des derniers benchmarks sur JeanZay
Jan 24, 2025
49a56ee
Récupération de benchs pour H100; ajout de labels aux axes
Jan 24, 2025
0cb52ea
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Jan 24, 2025
0c07a8e
Use a std::vector of IdefixArray as input for the userdef braginskii …
vreville Jan 29, 2025
250610a
corrected typo
vreville Jan 29, 2025
2f54bb5
Merge pull request #308 from idefix-code/addColumnDensityExample
glesur Feb 9, 2025
898fcf3
add some doc
glesur Feb 9, 2025
241c69c
refactor DumpArray
glesur Feb 10, 2025
ab340ed
implements a 1st order IMEX1 solver for polydisperse dust species
glesur Feb 10, 2025
c0fbc84
switch for std.vector.at() in userdef TD tests
vreville Feb 11, 2025
22eaf5b
refactor dust drag law
glesur Feb 11, 2025
cbcc63f
clean up
glesur Feb 11, 2025
05ca488
change signature of userdef drag function
glesur Feb 11, 2025
6fbd722
add the dustyShock test from Benitez-Llambay 2019
glesur Feb 11, 2025
60740e7
add back dump files for reference
glesur Feb 11, 2025
4b8e277
update reference files for new dusyShock
glesur Feb 11, 2025
e844bc1
add documentation for implicit dust module
glesur Feb 11, 2025
78fae02
use proper update variables istead of pre-stage ones
glesur Feb 13, 2025
59a91d3
switch off heating terms when feedback is disabled (feedback assumes
glesur Feb 13, 2025
f1141ee
typo
glesur Feb 13, 2025
9b2afc5
restore energy conservation in implicit scheme with feedback
glesur Feb 13, 2025
e8d34bb
fix label of dust tracers with non-isothermal equation of state
glesur Feb 13, 2025
f87b698
Merge pull request #317 from vreville/CollisionlessTC
glesur Feb 17, 2025
34d9366
fix a bug that could lead to Nans when using the RKL scheme on grids
glesur Feb 19, 2025
cb7b999
change the way polar singularities are handled
glesur Feb 19, 2025
2874fda
-refactor curvature terms without using a small number on all Areas
glesur Feb 19, 2025
461ae58
fix typo
glesur Feb 20, 2025
a4ed690
fix capture on Cuda
glesur Feb 20, 2025
b3481f5
do not make an exception when Area=0, as this artificiallykills off one
glesur Feb 20, 2025
af6b3b7
update reference test
glesur Feb 20, 2025
9ea85b0
do not perform implicit capture
glesur Feb 20, 2025
ff459c0
remove reference to useless feedback
glesur Feb 20, 2025
3c9f26d
update signature of fargo+planet+dust drag function
glesur Feb 21, 2025
630836b
Merge pull request #321 from idefix-code/implicitDrag
glesur Feb 21, 2025
59dc0d6
Merge pull request #318 from idefix-code/addDumpArray
glesur Feb 21, 2025
ecb9d2d
Merge pull request #323 from idefix-code/fixRKLSmallGridSpacing
glesur Feb 21, 2025
902c003
add the job to the test suite
glesur Feb 21, 2025
24a62e4
update reference commit #
glesur Feb 21, 2025
c34b819
clean up test
glesur Feb 21, 2025
6f3bedd
too much cleaning
glesur Feb 22, 2025
dbdd28d
final cleanup
glesur Feb 22, 2025
2bc09a0
Merge pull request #324 from idefix-code/addCollionslessTCTest
glesur Feb 22, 2025
da27024
check coarsening inside ghost zone, and detect Nan.
glesur Mar 3, 2025
8bed32b
fix loop unrolling
glesur Mar 3, 2025
3d96f41
add back axis flux tube test
glesur Mar 3, 2025
f283f78
remove analysis from axisfluxtube
glesur Mar 4, 2025
4c9985f
add environement to gitignore
glesur Mar 4, 2025
3fb2236
final improvement to error message on grid coarsening levels
glesur Mar 4, 2025
1d9d101
use one single plot
glesur Mar 4, 2025
282cd12
Merge pull request #329 from idefix-code/checkCoarseningLevels
glesur Mar 4, 2025
4771bde
Update Adastra Mi250 to lock Rocm version
glesur Mar 6, 2025
b2168df
add benchmark data
glesur Mar 10, 2025
eccab2d
Merge pull request #319 from lih/marc-bench-plots
glesur Mar 11, 2025
d59ecf0
attempt at fixing Kokkos SYCL loop configuration (a proper benchmark
glesur Mar 11, 2025
ca9c8b0
tabs
glesur Mar 11, 2025
dd702ab
add a static_assert so that the error observed on syscl doesn't go
glesur Mar 12, 2025
9d7c589
do this for all loops
glesur Mar 12, 2025
217a812
catch misbehaved loops earlier (fix cuda!), and be more explicit.
glesur Mar 12, 2025
e58f724
cleaning up
glesur Mar 12, 2025
4c8ccb8
Merge pull request #331 from idefix-code/fixSyclConfig
glesur Mar 12, 2025
939f0cd
fix axis current regularisation along the south pole
glesur Mar 31, 2025
8e0481e
make divB check diemsionless
glesur Apr 14, 2025
bfc1aca
Merge pull request #334 from idefix-code/improveDivB
glesur Apr 15, 2025
1c33a03
Merge pull request #333 from idefix-code/fixJaxis
glesur Apr 16, 2025
d894627
use one single extra parameter for dump time output
glesur Apr 16, 2025
83986d0
add doc for wallclock dump outputs
glesur Apr 16, 2025
2529e80
Improve Wallclock dump outputs
glesur Apr 16, 2025
28ff697
Merge branch 'master' into develop
glesur Apr 16, 2025
1be4115
Add units (#338)
glesur Apr 25, 2025
e4b5a83
add Kokkos::fence at the beginning of profiling regions to fix profil…
glesur May 16, 2025
b22cd25
fix the energetic of ShearingBox+Fargo (#346)
glesur Jun 12, 2025
81f9143
Fix axis and reflective boundary conditions (#345)
glesur Jun 16, 2025
bea1c7b
fix "size" drag force with adiabatic equation of state (sound speed w…
glesur Oct 18, 2025
cde3a14
Doc updates (#354)
glesur Oct 18, 2025
18a22f7
Merge branch 'master' into develop
glesur Nov 5, 2025
7ff2f42
Fix axis regularisation (#356)
glesur Nov 27, 2025
3a8e37b
Fix BXs consistency accross mpi decomposition (#357)
glesur Dec 15, 2025
0880026
update changelog
glesur Dec 15, 2025
e289365
fix #358 (#359)
glesur Dec 18, 2025
3c5586e
typo
glesur Dec 27, 2025
52b6c97
[FIX] compatibility with compiling on AMD Instinct MI300A APU (#360)
dutta-alankar Jan 16, 2026
e53bc20
Add vector potentiel to pydefix (#361)
glesur Jan 20, 2026
de7ee54
Merge branch 'develop' of github.com:idefix-code/idefix into develop
glesur Jan 20, 2026
d83d694
fix incorrect subviews when using vector_potential in 2.5D (#362)
glesur Jan 21, 2026
56189c9
Usage of ccache in the test suite (#364)
svalat Mar 2, 2026
8300404
fix UCT HLLD when using DIMENSIONS<COMPONENTS (#363)
glesur Mar 10, 2026
df60d14
Fix div(B) check (#369)
glesur Mar 26, 2026
8171c32
Reorganise tests (#367)
glesur Mar 26, 2026
4f625af
MNT: upgrade inifix pre-commit hook (#372)
neutrinoceros Apr 4, 2026
24a3c3d
update pydefix for people using venv
glesur Apr 21, 2026
3b26652
update changelog in prep for release 2.2.1
glesur Apr 21, 2026
a6eebd1
Test launcher based on pytest (#366)
svalat Apr 21, 2026
3c69e45
update version number
glesur Apr 21, 2026
080557f
Merge branch 'develop' of github.com:idefix-code/idefix into develop
glesur Apr 21, 2026
326e7e0
Merge branch 'master' into develop
glesur Apr 21, 2026
5be7d71
fix security in ci-jobs
glesur Apr 21, 2026
62c3256
add pytest PR to changelog
glesur Apr 22, 2026
b6bdd5a
bump up sphinx package requirements for readthedocs
glesur Apr 22, 2026
8077957
Merge branch 'master' into develop
glesur Apr 22, 2026
0ef3886
test: add "default" semantic to testme.json files (#378)
svalat Jun 4, 2026
273abf1
Bump up to Kokkos 5.1 (#375)
glesur Jun 4, 2026
b3c330b
Revert "Bump up to Kokkos 5.1 (#375)"
glesur Jun 4, 2026
e589979
Bump up to Kokkos 5.1 (#384)
glesur Jun 4, 2026
cd56506
ci: run the test via the new way (test.py && **/testme.json) (#377)
svalat Jun 5, 2026
70f5318
fix segfault when using UCT_HLL with dimensions <3 (#386)
glesur Jul 2, 2026
39ff467
refactor: use the Buffer and BoundingBox types to perform the communi…
svalat Jul 8, 2026
85004d8
restore ctrl-c in pydefix (#388)
glesur Jul 8, 2026
3a12a5c
MNT: migrate inifix-pre-commit hooks (#383)
neutrinoceros Jul 9, 2026
a103389
do not show warning for balance issues on cpus (#387)
glesur Jul 10, 2026
4f0ff74
MNT: upgrade ruff pre-commit hook, move its configuration out of pre-…
neutrinoceros Jul 15, 2026
0822bdf
update python req to 3.10 consistently (#390)
glesur Jul 15, 2026
392d89d
STY: setup python formatting with ruff (#392)
neutrinoceros Jul 16, 2026
86f46ff
Bug: Coarsening+Viscosity (#397)
glesur Aug 17, 2026
1e23562
test: Fix missing propagation of return status when calling pytest in…
svalat Aug 18, 2026
b6136e4
TST/DEP: update minimal Python requirements (#393)
neutrinoceros Aug 19, 2026
f604897
Fixing issues related to linking parallel hdf5 on cmake (#391)
dutta-alankar Aug 19, 2026
8d8508a
github: update the action version dependencies to fix some warnings a…
svalat Aug 19, 2026
73255b0
Fix: Kokkos 5 performances on AMD (#402)
glesur Aug 26, 2026
9344820
MPI gpu-direct: make it optional and have fallback solution with devi…
svalat Aug 27, 2026
fa22d20
fix: typo in documentation + issue in pytest configuration (#404)
svalat Aug 28, 2026
3903fba
Enable parsing of 1D column data and interpolation in functional spac…
dutta-alankar Aug 31, 2026
289197c
doc: add documentation for pydefix in virtualenv (#365)
glesur Aug 31, 2026
110ab02
TST: require inifile to be Pluto/Idefix valid (#394)
neutrinoceros Aug 31, 2026
ec7751b
test: add usage of jsonschema to validate testme.json files and get m…
svalat Sep 2, 2026
e982729
Move CheckNan to end of loop on stages in timeIntegrator (#403)
nscepi Sep 3, 2026
5787cac
Add conservation test to OT and OT3D (#407)
glesur Sep 3, 2026
6ef3da0
Keep Inter-cell flux (#337)
glesur Sep 8, 2026
8e4f8db
ensure shearing box test also analyse B (#412)
glesur Sep 18, 2026
c46e497
fix spelling error (#411)
ScatteredComet Sep 18, 2026
f0403bb
copyrights: update copyright headers in all files of the project (#410)
svalat Sep 23, 2026
c136040
Merge branch 'master' into develop
glesur Sep 24, 2026
959f9d7
tests: fix test suite runner not to require anymore the user to set P…
svalat Oct 6, 2026
ed53262
fix non-deterministic axis regularisation algorithm (#413)
glesur Oct 6, 2026
0d36d40
First commit of test CoagBox
Oct 9, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 59 additions & 28 deletions src/fluid/boundary/axis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,25 @@ void Axis::SymmetrizeEx1Side(int jref, IdefixArray3D<real> Ex1) {

auto Ex1Avg = this->Ex1Avg.deviceView();

idefix_for("Ex1_ini",0,data->np_tot[IDIR],
KOKKOS_LAMBDA(int i) {
Ex1Avg(i) = ZERO_F;
});

idefix_for("Ex1_Symmetrize",data->beg[KDIR],data->end[KDIR],0,data->np_tot[IDIR],
KOKKOS_LAMBDA(int k,int i) {
Kokkos::atomic_add(&Ex1Avg(i), Ex1(k,jref,i));
// Deterministic reduction: one thread per i, fixed k loop order

const int kbeg = data->beg[KDIR];
const int kend = data->end[KDIR];

idefix_for("Ex1_SymmetrizeDet", 0, data->np_tot[IDIR],
KOKKOS_LAMBDA(int i) {
real sum = ZERO_F;
real c = ZERO_F; // Kahan compensation
for(int k = kbeg; k < kend; k++) {
real y = Ex1(k, jref, i) - c;
real t = sum + y;
c = (t - sum) - y;
sum = t;
}
Ex1Avg(i) = sum;
});


if(needMPIExchange) {
#ifdef WITH_MPI
Kokkos::fence();
Expand Down Expand Up @@ -105,14 +115,20 @@ void Axis::RegularizeCurrentSide(int side) {
IdefixArray1D<real> dx3 = data->dx[KDIR];
IdefixArray1D<real> dx2 = data->dx[JDIR];

idefix_for("B_ini",0,data->np_tot[IDIR],
KOKKOS_LAMBDA(int i) {
BAvg(i) = ZERO_F;
});
idefix_for("Compute_Bcirculation",data->beg[KDIR],data->end[KDIR],0,data->np_tot[IDIR],
KOKKOS_LAMBDA(int k,int i) {
Kokkos::atomic_add(&BAvg(i), Vs(BX3s,k,jc,i)*dx3(k) ); // Compute the circulation of
// Bphi around the pole
const int kbeg = data->beg[KDIR];
const int kend = data->end[KDIR];
idefix_for("Compute_BcirculationDet", 0, data->np_tot[IDIR],
KOKKOS_LAMBDA(int i) {
real sum = ZERO_F;
real c = ZERO_F; // Kahan compensation
for(int k = kbeg; k < kend; k++) {
real term = Vs(BX3s, k, jc, i) * dx3(k);
real y = term - c;
real t = sum + y;
c = (t - sum) - y;
sum = t;
}
BAvg(i) = sum;
});

if(needMPIExchange) {
Expand Down Expand Up @@ -202,19 +218,34 @@ void Axis::FixBx2sAxis(int side) {
sign = -1;
}

idefix_for("B_ini",0,data->np_tot[IDIR],0,2,
KOKKOS_LAMBDA(int i, int n) {
BAvg(i,n) = ZERO_F;
});
idefix_for("BHorizontal_compute",data->beg[KDIR],data->end[KDIR],0,data->np_tot[IDIR],
KOKKOS_LAMBDA(int k,int i) {
real Bthmid = sign*HALF_F*(Vs(BX2s,k,jaxe-1,i) + Vs(BX2s,k,jaxe+1,i));
real Bphimid = HALF_F*(Vs(BX3s,k,jin,i) + Vs(BX3s,k,jout,i));
//Bthmid = 0.0;
//Bphimid = 0.0;
const int kbeg = data->beg[KDIR];
const int kend = data->end[KDIR];
idefix_for("BHorizontal_computeDet", 0, data->np_tot[IDIR],
KOKKOS_LAMBDA(int i) {
real sumX = ZERO_F;
real cX = ZERO_F; // Kahan compensation for X
real sumY = ZERO_F;
real cY = ZERO_F; // Kahan compensation for Y

for(int k = kbeg; k < kend ; k++) {
real Bthmid = sign*HALF_F*(Vs(BX2s,k,jaxe-1,i) + Vs(BX2s,k,jaxe+1,i));
real Bphimid = HALF_F*(Vs(BX3s,k,jin,i) + Vs(BX3s,k,jout,i));

real termX = Bthmid * cos(phi(k)) - Bphimid * sin(phi(k));
real yX = termX - cX;
real tX = sumX + yX;
cX = (tX - sumX) - yX;
sumX = tX;

real termY = Bthmid * sin(phi(k)) + Bphimid * cos(phi(k));
real yY = termY - cY;
real tY = sumY + yY;
cY = (tY - sumY) - yY;
sumY = tY;
}

Kokkos::atomic_add(&BAvg(i,IDIR), Bthmid * cos(phi(k)) - Bphimid * sin(phi(k)));
Kokkos::atomic_add(&BAvg(i,JDIR), Bthmid * sin(phi(k)) + Bphimid * cos(phi(k)));
BAvg(i,IDIR) = sumX;
BAvg(i,JDIR) = sumY;
});
if(needMPIExchange) {
Kokkos::fence();
Expand Down
6 changes: 6 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
sys.path.append(source_dir)
from pytools.idfx_test_run import IdexPytestRunner

# export it for sub-commands accessing ./pytools module
if "PYTHONPATH" in os.environ:
os.environ["PYTHONPATH"] = source_dir + ":" + os.environ["PYTHONPATH"]
else:
os.environ["PYTHONPATH"] = source_dir

# should be global so it remember state (last build) and avoids
# to build for each run if we just changed the ini file and run options.
gblIdefixPytestRunner = IdexPytestRunner(__file__)
Expand Down
3 changes: 3 additions & 0 deletions test/Dust/CoagBox/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
enable_idefix_property(Idefix_PYTHON)
add_idefix_source(coagulation.cpp)
add_idefix_source(coagulation.hpp)
47 changes: 47 additions & 0 deletions test/Dust/CoagBox/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Testing coagulation in Idefix

## Introduction

We solve the coagulation of dust grains using the code COALA (see details in [Lombart & Laibe, 2021, MNRAS](https://ui.adsabs.harvard.edu/abs/2021MNRAS.501.4298L/abstract)). The code is a high-order scheme based on Discontinuous Galerkin (DG) method to solve the Smoluchowski coagulation equation in its conservative form. In practice, the coagulation corresponds to a source term in Idefix that updates the dust densities (and not the momentum for the moment). In this source term, COALA provides a table that only depends on the mass grid (not on the time), thanks to the method used in COALA. The table contains the needed weights to evolve coagulation in time. Hence, we generate the table only once, before the simulation starts, then it is read during the run in the coagulation source term.

## Requierments

Make sure you have python>=3.10 (relative to COALA and these tests) and pybind11>=2.12 (relative to pydefix that is used here, see [Pydefix doc](https://idefix.readthedocs.io/latest/modules/pydefix.html)). You can create a virtual environement with the packages in `requirements.txt`, which is the one I am using right now.

## The tests explained

### Coagulation kernels

We can use COALA with 4 different coagulation kernels, which define the nature of the interaction between grains. The precalculation table generated by COALA depends on the kernel used. The *constant kernel* and the *additive kernel* are the only with exact solutions. The *brownian kernel* and the *collision kernel* derive from the ballistic kernel and are known as the "physical kernels". The ballistic kernel depends on the cross-section of the collision and the differential velocity between grains. In the brownian kernel case, the analytical expression of the differential velocity from Brownian motion is used, in order to obtain a reference solution. In the collision kernel case, only the cross-section is used for precalculation, and the differential velocities have to be given by the hydro part, Idefix.

### Description of the tests and the files

We prepare 4 input files for each coagulation kernel. The precalculation table is already written are and ready to be called by Idefix. The corresponding COALA solutions are also already computed for comparison. Hence the tests can be done without using COALA. We give here a brief description of the files:

- `idefix-XXXKernel.ini`: The input files. Parameters needed for coagulation are `nSpecies`in the *dust* block and all the parameters in the *Coala* block. Do not change them!
- `coagulation.hpp` and `coagulation.cpp`: the source files concerning the coagulation. This is where the precalculation tables are loaded, and where the coagulation source term is written.
- `setup.cpp`: the setup, calling the coagulation files. It also contains a function that check mass conservation.
- `myInit.py`: To initialize the flow.
- `testidefix.py`: To compute the standard tests (the plots and the errors), comparing Idefix to COALA's solutions.
- `testme.json`: To compute the reference tests, given a space of parameters to test.
- `utils.py`: Common functions and classes, called by the `.py` files.
- `computeCoalaTable.py`: To generate the precalculation table. Depends on `nSpecies`, `Q`, `kernel`, `kpol`, `massmin` and `massmax`.
- `coala_coag.py`: The file calling COALA to generate the solution for comparison.

The output files are stored in the `./data` directory.

>[!NOTE]
> If you want to change any parameter, you need COALA to compute the new precalculation table and the solution for comparison (so don't do it!).

>[!NOTE]
> To use `testidefix.py` (but also `computeCoalaTable.py`, and `coala_coag.py`), you need to give the argument `-ini idefix-XXXKernel.ini` (replace by the input file you want to test).

## How do you test ?
### Standard tests
- First, initialise the IDEFIX_DIR environement to the root of the idefix directory, with `export IDEFIX_DIR=/path_to_idefix_root`;
- Second, configure the code with `cmake $IDEFIX_DIR` and compile the code with `make -j`;
- Thrid, do `export PYTHONPATH=/$MY_VIRTUAL_ENV/lib/python3.XX/site-packages:$PYTHONPATH` (replace XX by the python version in your $MY_VIRTUAL_ENV) and launch the code with `./idefix -i idefix-XXXKernel.ini`(replace `idefix-XXXKernel.ini` by the input file you want to test);
- Finally, use `python testidefix.py -ini idefix-XXXKernel.ini` to test the run.

### Reference tests
- In the root of the idefix directory, use `./test.py -subdir /path_to_the_coagulation_test -v -x` (-v to enable verbose mode, -x to stop the test if one error is detected)
176 changes: 176 additions & 0 deletions test/Dust/CoagBox/coagulation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
#include "idefix.hpp"
#include "coagulation.hpp"
#include "npy.hpp"

Coagulation *CoagulationGlob;

Coagulation::Coagulation(DataBlock &data, int kernel, real eps, real coagCFL) {
this->kernel = kernel;
this->eps = eps;
this->coagCFL = coagCFL;

//==============================================//
//==============================================//
// In this part, we load the coagulation tables //
//==============================================//
//==============================================//
const int nSpecies = data.dust.size();
//===== Load the mass grid =====//
std::string filename_massgrid = "data/test-massgrid-kernel-"+std::to_string(kernel)+".npy";
std::vector<uint64_t> shape_massgrid;
bool fortran_order_massgrid;
std::vector<double> massgrid;
npy::LoadArrayFromNumpy(filename_massgrid, shape_massgrid, fortran_order_massgrid, massgrid);
//===== verification =====//
if(massgrid.size() != static_cast<size_t>(nSpecies+1)) {
IDEFIX_ERROR("Mass grid has an unexpected size");
}
//========================//

this->binWidth = IdefixArray1D<real>("binWidth", nSpecies);
IdefixHostArray1D<real> binWidthHost = Kokkos::create_mirror_view(this->binWidth);
for(int n = 0; n <nSpecies; n++) {
binWidthHost(n) = massgrid[n+1] - massgrid[n];
}
Kokkos::deep_copy(this->binWidth, binWidthHost);

//===== Loading the Flux Table =====//
std::string filename_coagTabFlux = "data/test-coagTabFlux-kernel-"+std::to_string(kernel)+".npy";
std::vector<uint64_t> shape_coagTabFlux;
bool fortran_order_coagTabFlux;
std::vector<double> coagTabFlux;
npy::LoadArrayFromNumpy(filename_coagTabFlux, shape_coagTabFlux, fortran_order_coagTabFlux, coagTabFlux);
//===== verification =====//
const size_t expectedSize = static_cast<size_t>(nSpecies)*static_cast<size_t>(nSpecies)*static_cast<size_t>(nSpecies);
if(coagTabFlux.size() != expectedSize) {
IDEFIX_ERROR("Coagulation flux table has an unexpected size");
}
//========================//

this->coagTabFlux = IdefixArray3D<real>("coagTabFlux", nSpecies, nSpecies, nSpecies);
IdefixHostArray3D<real> coagTabFluxHost = Kokkos::create_mirror_view(this->coagTabFlux);
for(int i=0; i<nSpecies; i++) {
for(int j=0; j<nSpecies; j++) {
for(int k=0; k<nSpecies; k++) {
int index = i*nSpecies*nSpecies + j*nSpecies + k;
coagTabFluxHost(i,j,k) = coagTabFlux[index];
}
}
}
Kokkos::deep_copy(this->coagTabFlux, coagTabFluxHost);
}

void CoagSourceTerm(DataBlock &dataRef, const real t, const real dtin) {
//==============================================//
/*
Coagulation source term : compute the coagulation product to finally upload the dust densities.
This function is implemented via operator splitting : coagulation is integrated in a step.
Hence, enroll the function with `data.EnrollUserStepFirst(&CoagSourceTerm);`.
This version does not preserve bins momentum yet.
This version does not work on GPU yet.
*/
//==============================================//
DataBlock *data = &dataRef;
data->PrimToCons();
IdefixArray1D<real> h = CoagulationGlob->binWidth;
IdefixArray3D<real> coagTabFlux = CoagulationGlob->coagTabFlux;
const int nSpecies = data->dust.size();
const int test_size = 20; // Because we can't give nSpecies in the KOKKOS_LAMBDA

const real eps = CoagulationGlob->eps;
const real coagCFL = CoagulationGlob->coagCFL;
const bool physicalKernel = (CoagulationGlob->kernel==3);

idefix_for("CoagSourceTerm",0,data->np_tot[KDIR],0,data->np_tot[JDIR],0,data->np_tot[IDIR],
KOKKOS_LAMBDA (int k, int j, int i) {
real rho[test_size];
real g0[test_size];
real vx1[test_size];
real vx2[test_size];
real vx3[test_size];
real deltaV[test_size][test_size];
real Flux[test_size+1];

// Initial State
for(int n=0; n<nSpecies; n++) {
rho[n] = data->dust[n]->Uc(RHO,k,j,i);
vx1[n] = data->dust[n]->Uc(MX1,k,j,i)/rho[n];
vx2[n] = data->dust[n]->Uc(MX2,k,j,i)/rho[n];
vx3[n] = data->dust[n]->Uc(MX3,k,j,i)/rho[n];

/*
// To have a constant drift velocity that does not evolve in sub-cycling
// WARNING: dirty here! check that it corresponds to Compute_test_velocity in utils.py
real vx = 1e-2 + (1e-1 - 1e-2)*n/(nSpecies - 1);
real vy = 1.3*vx;
real vz = 1.7*vx;
vx1[n] = vx;
vx2[n] = vy;
vx3[n] = vz;
*/
}

// Relative velocity
if(physicalKernel) {
for(int lp=0; lp<nSpecies; lp++) {
for(int l=0; l<nSpecies; l++) {
real dvx = vx1[lp] - vx1[l];
real dvy = vx2[lp] - vx2[l];
real dvz = vx3[lp] - vx3[l];
deltaV[lp][l] = sqrt(dvx*dvx + dvy*dvy + dvz*dvz);
}
}
}

//===== COAGULATION SUBCYCLING =====//
real time = 0.0;
while(time<dtin) {
Flux[0] = 0.0; // No mass flux crossing the left boundary of the distribution
for(int n=0; n<nSpecies; n++) {
g0[n] = rho[n]/h(n);
}
//===== FLUX CALCULATION =====//
for(int n=0; n<nSpecies; n++) {
real flux = 0.0;
for(int lp=0; lp <= n; lp++) {
real g0_lp = g0[lp];
for(int l=0; l<nSpecies; l++) {
real g0_l = g0[l];
real delta_v = physicalKernel ? deltaV[lp][l] : 1.0;
flux += g0_lp*g0_l*coagTabFlux(n,lp,l)*delta_v;
}
}
Flux[n+1] = flux;
}
//===== CFL CALCULATION =====//
real dt_sub = std::numeric_limits<double>::max();
for(int n=0; n<nSpecies; n++) {
real dflux = Flux[n+1] - Flux[n];
if(std::abs(dflux)>0.0 && rho[n]>eps*h(n)) {
dt_sub = std::min(dt_sub, std::abs(rho[n]/dflux));
}
}
real dt_coag = dt_sub*coagCFL;
dt_coag = std::min(dt_coag, dtin-time); // Last substep
if(dt_coag<=0.0) {
IDEFIX_ERROR("Coagulation time step is non-positive");
}
//===== EULER UPDATE =====//
for(int n=0; n<nSpecies; n++) {
rho[n] = std::max(rho[n] - dt_coag*(Flux[n+1] - Flux[n]), eps*h(n));
}
time += dt_coag;
}
//===== UPDATE THE FINAL DENSITIES =====//
for(int n=0; n<nSpecies; n++) {
data->dust[n]->Uc(RHO,k,j,i) = rho[n];

// To keep a constant velocity, just for the test with kernel = 3
data->dust[n]->Uc(MX1,k,j,i) = rho[n]*vx1[n];
data->dust[n]->Uc(MX2,k,j,i) = rho[n]*vx2[n];
data->dust[n]->Uc(MX3,k,j,i) = rho[n]*vx3[n];
}
}
);
data->ConsToPrim();
}
20 changes: 20 additions & 0 deletions test/Dust/CoagBox/coagulation.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "idefix.hpp"
#include "dataBlock/dataBlock.hpp"
#include "fluid/fluid.hpp"

class Coagulation {
public:
// Constructor: allocate and load all coagulation tables
Coagulation(DataBlock &data, int kernel, real eps, real coagCFL);

IdefixArray1D<real> binWidth;
IdefixArray3D<real> coagTabFlux;

int kernel;
real eps;
real coagCFL;
};

extern Coagulation *CoagulationGlob;

void CoagSourceTerm(DataBlock &data, const real t, const real dtin);
Loading