Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
157 commits
Select commit Hold shift + click to select a range
fb01668
new argument in the gk sheath bc updater to introduce the mu dependen…
Antoinehoff Feb 24, 2026
08dceb1
Merge remote-tracking branch 'origin/new_gk_bc_sheath_unit_test' into…
Antoinehoff Feb 24, 2026
9a0d39d
This setup includes alpha_mu in the kernel and returns the same resul…
Antoinehoff Feb 24, 2026
abb84ee
Had to define a specific basis for the alpha_mu coeff in bc_sheath ob…
Antoinehoff Feb 25, 2026
0c163dd
the sheath bc test is now adapted to check mu-dependent vcut. We avoi…
Antoinehoff Feb 26, 2026
f7ffb5d
We remove the function pointer interface to set the alpha_mu array. T…
Antoinehoff Feb 26, 2026
b251b92
restore the twist shift unit test (mixed up with the bc sheath one)
Antoinehoff Feb 27, 2026
4503727
update the sheath bc unit test, we can now pass a curve to make vcut …
Antoinehoff Feb 27, 2026
7bf4723
naming refactor, alpha_mu is now vcut_fact
Antoinehoff Feb 27, 2026
2e8ada7
start of a vcut_fact(x,y,mu) version
Antoinehoff Feb 27, 2026
681f76f
New dimensionality for the vcut factor array. It is now a combinaison…
Antoinehoff Mar 2, 2026
13854cf
reduce debug lines and comment print statement
Antoinehoff Mar 2, 2026
fe9d6d1
add a new bool to decide if we use the surrogate in bc_sheath updater
Antoinehoff Mar 4, 2026
aeee19d
Add new kernels to update the vcut factor and connections to the surr…
Antoinehoff Mar 4, 2026
a4207d5
switch commented section, the test of non zero cell avg in fully refl…
Antoinehoff Mar 5, 2026
6409f28
add an assert to forbid the use of the surrogate in 1v case
Antoinehoff Mar 5, 2026
f4814fd
made the switch statement more robust
Antoinehoff Mar 5, 2026
d990730
add an example of surrogate model
Antoinehoff Mar 5, 2026
31a9cff
add method to choose the surrogate kernel
Antoinehoff Mar 5, 2026
1a8a0e0
reorganize the surrogate kernel choice logic
Antoinehoff Mar 5, 2026
8082dc8
the sheath unit test is now in mksa units and can also test the surro…
Antoinehoff Mar 5, 2026
6f0951d
fix pointer to function logic
Antoinehoff Mar 5, 2026
fc54201
The surrogate interface works as expected 🥳Commit details:
Antoinehoff Mar 6, 2026
4c1a5e3
The species can now call the surrogate model for sheath physics, we d…
Antoinehoff Mar 16, 2026
b7b85cb
Merge remote-tracking branch 'origin/main' into gk_ai_sheath
Antoinehoff Mar 16, 2026
1ddd30d
Add missing EXTERN_C_END to the gkyl_bc_sheath_gyrokinetic_gyraze_sur…
Antoinehoff Mar 16, 2026
bd04693
add the commit ID that generated the sheath ai model interface
Antoinehoff Mar 16, 2026
b4fc78d
adapt the surrogate interface for GPU application
Antoinehoff Mar 16, 2026
022fea5
try another way to write the surrogate model to make it work on GPU
Antoinehoff Mar 16, 2026
43dabaa
The ctest passes on GPUs without surrogate, it is valgrind clean. One…
Antoinehoff Mar 17, 2026
f3fcb86
uncomment tests and remove write fields
Antoinehoff Mar 17, 2026
85b8eae
the surrogate eval is GPU compatible, also replace M_PI by GKYL_PI
Antoinehoff Mar 18, 2026
6a6d506
the sheath AI surrogate is now ready for GPU, also remove q and m fro…
Antoinehoff Mar 18, 2026
91ed92d
The sheath unit test passes with surrogate now for both cpu and gpu. …
Antoinehoff Mar 18, 2026
4541300
Add the impact angle of the magnetic field with the xy plane and use …
Antoinehoff Mar 19, 2026
095be63
We can now call the projector to project the sheath surrogate eval pa…
Antoinehoff Mar 19, 2026
5b21f89
create a regression test that uses the sheath surrogate.
Antoinehoff Mar 19, 2026
21e6d40
forgot to remove a debugging print statement
Antoinehoff Mar 23, 2026
85aa760
forgot to uncomment some tests
Antoinehoff Mar 23, 2026
c0b643e
Merge remote-tracking branch 'origin/main' into gk_ai_sheath
Antoinehoff Mar 23, 2026
0bfea45
Merge remote-tracking branch 'origin/main' into gk_ai_sheath
Antoinehoff Mar 23, 2026
400a606
use surrogate only when GYRAZE is expected to converge
Antoinehoff Mar 31, 2026
cfaff40
correct the impact angle calculation
Antoinehoff Mar 31, 2026
a2c6588
bug fix: bring back the former version of the impact angle
Antoinehoff Mar 31, 2026
ae6d6b2
this commit is not working, it's a transfer
Antoinehoff Mar 31, 2026
98f2ce8
Addition of a input parameter to decide if we check convergence befor…
Antoinehoff Apr 1, 2026
7b821d2
Merge remote-tracking branch 'origin/righthanded_checks' into gk_ai_s…
Antoinehoff Apr 1, 2026
c48e248
adapt the rt_gk sheath surrogate to the new geom
Antoinehoff Apr 1, 2026
ec39170
Revert "adapt the rt_gk sheath surrogate to the new geom"
Antoinehoff Apr 1, 2026
3452558
Now use a model of GYRAZE that does the projection internally in the …
Antoinehoff Apr 15, 2026
7d31b27
forgot to update the cuda kernel to choose if we ue the convergence c…
Antoinehoff Apr 15, 2026
921d794
Merge branch 'gk_ai_sheath' of https://github.com/ammarhakim/gkeyll i…
Antoinehoff Apr 15, 2026
dc9c63b
Merge remote-tracking branch 'origin/main' into gk_ai_sheath
Antoinehoff Apr 15, 2026
9a699b5
Merge branch 'gk_ai_sheath' of https://github.com/ammarhakim/gkeyll i…
Antoinehoff Apr 15, 2026
257828a
update the TCV sheath surrogate regression test with the new geom
Antoinehoff Apr 15, 2026
e7afe36
add a regression test for the helical 3x2v case
Antoinehoff Apr 15, 2026
d152dd4
Merge branch 'gk_ai_sheath' of https://github.com/ammarhakim/gkeyll i…
Antoinehoff Apr 15, 2026
3e3ec03
the branch is now valgrind clean:
Antoinehoff Apr 15, 2026
a611330
use the sheath surrogate in the helical regression test
Antoinehoff Apr 15, 2026
ceb7188
use the input table to fix the valgrind uninitialised value error ins…
Antoinehoff Apr 16, 2026
e1860a2
use the full_MPE NN model
Antoinehoff Apr 29, 2026
39b3cc6
replace magic number with GKYL_PHI_THRESHOLD and set it to 2
Antoinehoff May 1, 2026
1af9179
Merge remote-tracking branch 'origin/main' into gk_ai_sheath
Antoinehoff May 2, 2026
6cfc940
update the sheath surrogate model with the one trained on the GYRAZE …
Antoinehoff May 4, 2026
2784e6c
Merge branch 'gk_ai_sheath' of https://github.com/ammarhakim/gkeyll i…
Antoinehoff May 4, 2026
bfd9820
Merge remote-tracking branch 'origin/main' into gk_ai_sheath
Antoinehoff May 4, 2026
ce17eb5
set the threshold to very small, we don't want to use it anymore
Antoinehoff May 6, 2026
5a557d3
Merge remote-tracking branch 'origin/main' into gk_ai_sheath
Antoinehoff May 11, 2026
8d82697
Merge remote-tracking branch 'origin/nccl-reorg-periodic-bcs' into gk…
Antoinehoff May 11, 2026
c61aecf
use the local density and not the polarization density for gamma_gyraze
Antoinehoff May 13, 2026
a829836
add a fmax to ensure non negative vcut factor
Antoinehoff May 13, 2026
3972220
Remove unused surrogate routines and the conv_check option
Antoinehoff May 13, 2026
04d8aff
use sheath surrogate in the regression test
Antoinehoff May 13, 2026
0ecd079
add a method to test the kann surrogate in the unit test. I guess we'…
Antoinehoff May 14, 2026
82efe9b
Update the kernels with `float(expand(` instead of `float(fullratsimp…
Antoinehoff May 15, 2026
6025a4e
add temp variable for vcut_fact dimensions and rename acquisition fun…
Antoinehoff May 15, 2026
cb0234c
try to reduce the size of the interface between kann and the bc sheat…
Antoinehoff May 15, 2026
2a0a198
Merge remote-tracking branch 'origin/main' into gk_sheath_vcut_mu_dep
Antoinehoff May 15, 2026
4d8fb31
The GPU implementation was done on the sheath_ai branch but not on th…
Antoinehoff May 15, 2026
b65b451
define and use vcut_fact_dim instead of cdim
Antoinehoff May 15, 2026
a161441
Merge remote-tracking branch 'origin/gk_sheath_vcut_mu_dep' into gk_a…
Antoinehoff May 19, 2026
e141508
Merge remote-tracking branch 'origin/main' into gk_ai_sheath
Antoinehoff May 28, 2026
0dec7e5
Merge remote-tracking branch 'origin/bimpactangle_surf' into gk_ai_sh…
Antoinehoff May 28, 2026
0ca9a04
remove the interior B impact angle from mirror geom
Antoinehoff May 28, 2026
025e8e2
use now the surface representation of bimpactangle
Antoinehoff May 28, 2026
4778327
remove print statement
Antoinehoff May 28, 2026
da49cb2
Merge pull request #1034 from ammarhakim/gk_ai_sheath-surf_bimpactangle
Antoinehoff May 28, 2026
80879f7
Merge remote-tracking branch 'origin/kann-hack' into gk_ai_sheath_kann
Antoinehoff Jun 2, 2026
03cbc8e
Merge remote-tracking branch 'origin/gk_ai_sheath' into gk_ai_sheath_…
Antoinehoff Jun 2, 2026
9e289bb
Merge remote-tracking branch 'origin/main' into gk_ai_sheath_kann
Antoinehoff Jun 2, 2026
2373817
small merge issue fix
Antoinehoff Jun 2, 2026
b81caae
We now pass the pointer to the KANN model to evaluate the BC. This wo…
Antoinehoff Jun 2, 2026
57d0c01
Fix a maxima bug that was not projecting properly the vcut along mu. …
Antoinehoff Jun 2, 2026
9fcc3ba
Merge remote-tracking branch 'origin/main' into gk_ai_sheath
Antoinehoff Jun 2, 2026
fdae289
revert residual issue of interior impact angle on dev
Antoinehoff Jun 2, 2026
f6abdbf
The CPU surrogate sheath BC program flow now uses the gkyl_kann layer…
Antoinehoff Jun 3, 2026
1f1fd94
a bit of renaming and fix the choosing kernels for GPU, we have to mo…
Antoinehoff Jun 3, 2026
4bae969
The interface looks to work well on CPU now with the kernels filling …
Antoinehoff Jun 3, 2026
4dc395e
Big reorg of the handling of sheath BC. The main change is that we do…
Antoinehoff Jun 5, 2026
e2a64f0
The GPU code looks clean for sheath ai KANN bc. Are we done?
Antoinehoff Jun 5, 2026
828fd8f
Remove the direct kann interface (everything goes through gkyl_kann),…
Antoinehoff Jun 12, 2026
69a0af5
compute gamma with fabs(0.0,density) instead of the density alone, si…
Antoinehoff Jun 12, 2026
2fd33c9
Good bye hardcoded NN, you will be remembered 🫡
Antoinehoff Jun 12, 2026
17d6f5f
forgot to move gkyl_const to have access to electron mass and others …
Antoinehoff Jun 12, 2026
918f8d1
add the neural model for the sheath bc
Antoinehoff Jun 12, 2026
7978dc5
Merge remote-tracking branch 'origin/gk_ai_sheath_kann' into gk_ai_sh…
Antoinehoff Jun 15, 2026
e888c27
remove the special tcv 2x2v sheath surrogate regression test because …
Antoinehoff Jun 15, 2026
be250bc
refactor: rename surrogate variable and function references consisten…
Antoinehoff Jun 15, 2026
41e8f44
remove unused arguments in sheath advance method.
Antoinehoff Jun 15, 2026
b6c22ec
adapt the sheath unit test to work with kann. Since it's monday, noth…
Antoinehoff Jun 15, 2026
712aa03
add the surrogate model path to the regression test that use the surr…
Antoinehoff Jun 16, 2026
dd5de27
Merge remote-tracking branch 'origin/main' into gk_ai_sheath, need to…
Antoinehoff Jun 16, 2026
0ebec35
Merge remote-tracking branch 'origin/main' into gk_ai_sheath
Antoinehoff Jun 16, 2026
e59911d
Restablish the bc_sheath updater new routine call to pass the surroga…
Antoinehoff Jun 16, 2026
5e211c0
Put back a chunk of code that got lost during the merge 😰
Antoinehoff Jun 16, 2026
618a309
add a 2x2v helical reg test with sheath BC
Antoinehoff Jun 16, 2026
1c0ec60
The ai sheath branch is ready I think. The unit test passes on GPU an…
Antoinehoff Jun 16, 2026
c9d4dbf
add an assert to make sure that kperpSq parameter is >0 (it was just …
Antoinehoff Jun 18, 2026
28a4a90
put io diag in a more consistent way
Antoinehoff Jun 18, 2026
7fafe76
fix right hand of LTX reg test in 1x2v, the y term in the definition …
Antoinehoff Jun 18, 2026
0903288
add diagnostics for the source in ltx reg test
Antoinehoff Jun 18, 2026
6525d44
Fix an error in the mapping of the surface bimpact angle and the inde…
Antoinehoff Jun 19, 2026
802424d
add the 1x2v version of TCV iwl adapt source stup
Antoinehoff Jun 19, 2026
141d64c
Merge remote-tracking branch 'origin/hot-fix-frame-metadata-bug' into…
Antoinehoff Jun 19, 2026
9985ec8
Add a diagnostic for the cutting velocity of the sheath surrogate BC
Antoinehoff Jun 20, 2026
26dc576
add the call to surrogate in the 1x2v reg test
Antoinehoff Jun 20, 2026
028d91c
fix a indexation bug in the 1x2v sheath kernel
Antoinehoff Jun 20, 2026
4b0a570
add 1x2v version of helical sim and reduce rt tcv iwl 1x2v resolution
Antoinehoff Jun 22, 2026
5cf654a
Merge remote-tracking branch 'origin/dg_binop_sig_change' into aishea…
Antoinehoff Jun 23, 2026
350798f
change app->io_meta_grid to app->io_meta_dg
Antoinehoff Jun 23, 2026
6c36045
add new setups for helical simulation using adapt sources
Antoinehoff Jun 23, 2026
bffd4e2
reduce the total number of particles to match ~ the one obtain in the…
Antoinehoff Jun 23, 2026
d4d5e88
put non uniform velocity grid
Antoinehoff Jun 23, 2026
939ba3d
replace the ref density from 7e18*10 to 7e19 (the 10 factor comes fro…
Antoinehoff Jun 23, 2026
424413c
apply a hand made scaling of the total density so that it matches the…
Antoinehoff Jun 24, 2026
e392780
Merge remote-tracking branch 'origin/dg_binop_sig_change-differentiat…
Antoinehoff Jun 24, 2026
42d97bb
we now integrate the grid associated to the cutting velocity output b…
Antoinehoff Jun 24, 2026
33e19bf
cosmetic changes
Antoinehoff Jun 24, 2026
fdc3085
delete the adapt src 1x2v tcv regression test because this dimensiona…
Antoinehoff Jun 30, 2026
2c73a03
simplify 1x2v TCV reg test
Antoinehoff Jul 2, 2026
6272373
Merge remote-tracking branch 'origin/main' into gk_ai_sheath
Antoinehoff Jul 8, 2026
af8670a
correct a erroneous comment
Antoinehoff Jul 8, 2026
065483d
clamp the potential to positive value for the surrogate evaluation. T…
Antoinehoff Jul 16, 2026
8889819
remove the adaptive source in helical 1x2x setup because we cannot ha…
Antoinehoff Jul 16, 2026
f726bcf
Merge remote-tracking branch 'origin/main' into gk_ai_sheath
Antoinehoff Jul 22, 2026
8f82ab1
change num_cell_ into N and final_time into t_end
Antoinehoff Jul 22, 2026
2c4f470
split GKYL_BC_GK_SPECIES_SHEATH bc type into GKYL_BC_GK_SPECIES_SHEAT…
Antoinehoff Jul 22, 2026
a66169f
add a few regression tests to ignore because they don't pass
Antoinehoff Jul 22, 2026
a741b13
Change the enum type GKYL_BC_GK_SPECIES_SHEATH_CONDUCTING in the regr…
Antoinehoff Jul 23, 2026
1ea32fd
fix some logic isssue with the enum change. Had also to divide by the…
Antoinehoff Jul 23, 2026
dcd4369
add a readme for the .kann NN model.
Antoinehoff Jul 23, 2026
bc93810
update vcutsq output file naming
Antoinehoff Jul 23, 2026
472d95d
forgot to remove an obsolete bolean and adapt the release of the kann…
Antoinehoff Jul 23, 2026
630e1f0
change the naming of the vcutsq diag. The code is leak check clean an…
Antoinehoff Jul 23, 2026
3f223b7
Merge remote-tracking branch 'origin/main' into gk_ai_sheath
Antoinehoff Jul 23, 2026
1c07f44
Merge remote-tracking branch 'origin/main' into gk_ai_sheath
Antoinehoff Aug 4, 2026
7b67a9d
Merge remote-tracking branch 'origin/main' into gk_ai_sheath
Antoinehoff Aug 25, 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
4 changes: 2 additions & 2 deletions core/zero/gkyl_array_average.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ typedef struct gkyl_array_average_inp gkyl_array_average_inp;
* @param local Full range of the input array, covering all dimensions of the total basis.
* @param local_avg Reduced range of the output array, covering only the non-averaged dimensions.
* @param local_avg_ext Extended reduced range of the output array, used only to define the integrated weight.
* @param weight Pointer to the array containing weight for the averaging process. (set it to NULL for integral)
* @param weight Pointer to the array containing weight for the averaging process.
* @param avg_dim Flag array to set which dimension is averaged
* @param use_gpu Boolean flag indicating whether the computation should be performed on a GPU.
*/
Expand Down Expand Up @@ -78,7 +78,7 @@ gkyl_array_average_inew(const struct gkyl_array_average_inp *inp);
* @param local Full range of the input array, covering all dimensions of the total basis.
* @param local_avg Reduced range of the output array, covering only the non-averaged dimensions.
* @param local_avg_ext Extended reduced range of the output array, used only to define the integrated weight.
* @param weight Pointer to the array containing weight for the averaging process. (set it to NULL for integral)
* @param weight Pointer to the array containing weight for the averaging process.
* @param avg_dim Flag array to set which dimension is averaged
* @param use_gpu Boolean flag indicating whether the computation should be performed on a GPU.
*/
Expand Down
1 change: 1 addition & 0 deletions gyrokinetic/apps/gk_field_1x.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ gk_field_fem_new_1x(struct gkyl_gyrokinetic_app *app, struct gk_field *f)
polarization_weight += s->info.polarization_density*s->info.mass/pow(polarization_bmag,2);
}
// Need to set weight to kperpsq*polarizationWeight for use in potential smoothing.
assert(f->info.kperpSq > 0.0);
gkyl_array_copy(f->epsilon, app->gk_geom->geo_int.jacobgeo);
gkyl_array_scale(f->epsilon, polarization_weight);
gkyl_array_scale(f->epsilon, f->info.kperpSq);
Expand Down
121 changes: 105 additions & 16 deletions gyrokinetic/apps/gk_species.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <gkyl_dg_interpolate.h>
#include <gkyl_translate_dim.h>
#include <gkyl_proj_on_basis.h>
#include <gkyl_gk_maxwellian_moments.h>

#include <assert.h>
#include <time.h>
Expand Down Expand Up @@ -197,7 +198,7 @@ gk_species_rhs_implicit_static(gkyl_gyrokinetic_app *app, struct gk_species *spe
}

static void
gk_species_apply_bc_dynamic(gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gkyl_array *f)
gk_species_apply_bc_dynamic(gkyl_gyrokinetic_app *app, struct gk_species *species, struct gkyl_array *f)
{
struct timespec wst = gkyl_wall_clock();

Expand All @@ -209,9 +210,18 @@ gk_species_apply_bc_dynamic(gkyl_gyrokinetic_app *app, const struct gk_species *
if (species->bc_is_np[d]) {

switch (species->lower_bc[d].type) {
case GKYL_BC_GK_SPECIES_SHEATH:
case GKYL_BC_GK_SPECIES_SHEATH_CONDUCTING:
gkyl_bc_sheath_gyrokinetic_advance(species->bc_sheath_lo, app->field->phi_smooth,
app->field->phi_wall_lo, f, &app->local);
app->field->phi_wall_lo, NULL, NULL, NULL, NULL, f, &app->local);
break;
case GKYL_BC_GK_SPECIES_SHEATH_SURROGATE:
gk_species_moment_calc(&species->sheath_moms, species->local, app->local, f);
gk_species_moment_diag_jacobgeo_div(app, &species->sheath_moms, species->sheath_moms.marr, species->sheath_moms.marr);
gkyl_array_set_offset_range(species->dens_sheath, 1.0, species->sheath_moms.marr, 0, &app->local);
gkyl_array_set_offset_range(species->temp_sheath, species->info.mass, species->sheath_moms.marr, 2*app->basis.num_basis, &app->local);
gkyl_bc_sheath_gyrokinetic_advance(species->bc_sheath_lo, app->field->phi_smooth,
app->field->phi_wall_lo, species->dens_sheath, species->temp_sheath,
app->gk_geom->geo_int.bmag, app->gk_geom->geo_surf[d].bimpactangle, f, &app->local);
break;
case GKYL_BC_GK_SPECIES_TWISTSHIFT:
gkyl_bc_twistshift_advance(species->bc_ts_lo, f, f);
Expand All @@ -231,9 +241,18 @@ gk_species_apply_bc_dynamic(gkyl_gyrokinetic_app *app, const struct gk_species *
}

switch (species->upper_bc[d].type) {
case GKYL_BC_GK_SPECIES_SHEATH:
case GKYL_BC_GK_SPECIES_SHEATH_CONDUCTING:
gkyl_bc_sheath_gyrokinetic_advance(species->bc_sheath_up, app->field->phi_smooth,
app->field->phi_wall_up, f, &app->local);
app->field->phi_wall_up, NULL, NULL, NULL, NULL, f, &app->local);
break;
case GKYL_BC_GK_SPECIES_SHEATH_SURROGATE:
gk_species_moment_calc(&species->sheath_moms, species->local, app->local, f);
gk_species_moment_diag_jacobgeo_div(app, &species->sheath_moms, species->sheath_moms.marr, species->sheath_moms.marr);
gkyl_array_set_offset_range(species->dens_sheath, 1.0, species->sheath_moms.marr, 0, &app->local);
gkyl_array_set_offset_range(species->temp_sheath, species->info.mass, species->sheath_moms.marr, 2*app->basis.num_basis, &app->local);
gkyl_bc_sheath_gyrokinetic_advance(species->bc_sheath_up, app->field->phi_smooth,
app->field->phi_wall_up, species->dens_sheath, species->temp_sheath,
app->gk_geom->geo_int.bmag, app->gk_geom->geo_surf[d].bimpactangle, f, &app->local);
break;
case GKYL_BC_GK_SPECIES_TWISTSHIFT:
gkyl_bc_twistshift_advance(species->bc_ts_up, f, f);
Expand Down Expand Up @@ -266,7 +285,7 @@ gk_species_apply_bc_dynamic(gkyl_gyrokinetic_app *app, const struct gk_species *
}

static void
gk_species_apply_bc_static(gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gkyl_array *f)
gk_species_apply_bc_static(gkyl_gyrokinetic_app *app, struct gk_species *species, struct gkyl_array *f)
{
// do nothing
}
Expand Down Expand Up @@ -316,6 +335,39 @@ gk_species_copy_range_static(struct gkyl_array *out,
// do nothing
}

// Write out the sheath BC velocity cutoff (vcutsq) at one boundary.
static void
gk_species_write_vcutsq(gkyl_gyrokinetic_app* app, struct gk_species *gks,
struct gkyl_bc_sheath_gyrokinetic *bc_sheath, const char *dir_str, const char *edge_str, double tm, int frame)
{
struct timespec wst = gkyl_wall_clock();

// Package metadata (time/frame + DG basis info).
gkyl_msgpack_map_elem_set_double(app->io_meta_dg_len, app->io_meta_dg, "time", tm);
gkyl_msgpack_map_elem_set_uint(app->io_meta_dg_len, app->io_meta_dg, "frame", frame);
Comment on lines +346 to +347

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think but i'm not 100% that this should use io_meta_basic instead of io_meta_dg, because the latter has the conf-space basis and poly order, which is not what you want here.

@Antoinehoff Antoinehoff Jul 22, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

the vcut_sq is stored in a DG modal representation on a p=1 3D (x,y,mu) serendipity basis. It does not use the gk hybrid one so I think this works like that. I checked the resulting .gkyl output and it matches with what should the cutting velocity look like.

struct gkyl_msgpack_map_elem mpe_vcutsq[] = {
{ .key = "poly_order", .elem_type = GKYL_MP_UNSIGNED_INT, .uval = app->basis.poly_order },
{ .key = "basis_type", .elem_type = GKYL_MP_STRING, .cval = "serendipity" },
{ .key = "Description", .elem_type = GKYL_MP_STRING,
.cval = "Square of the velocity cutoff used in the gyrokinetic sheath BC." }
};
int mpe_vcutsq_len = sizeof(mpe_vcutsq)/sizeof(mpe_vcutsq[0]);
int io_meta_len[] = {app->io_meta_dg_len, mpe_vcutsq_len};
const struct gkyl_msgpack_map_elem* io_meta[] = {app->io_meta_dg, mpe_vcutsq};
struct gkyl_msgpack_data *mt = gkyl_msgpack_create_union(sizeof(io_meta_len)/sizeof(int), io_meta_len, io_meta);

const char *fmt = "%s-%s_bc_%s%s_vcutsq_%d.gkyl";
int sz = gkyl_calc_strlen(fmt, app->name, gks->info.name, dir_str, edge_str, frame);
char fileNm[sz+1]; // ensures no buffer overflow
snprintf(fileNm, sizeof fileNm, fmt, app->name, gks->info.name, dir_str, edge_str, frame);

gkyl_bc_sheath_gyrokinetic_write_vcutsq(bc_sheath, mt, fileNm);

gkyl_msgpack_data_release(mt);
app->stat.species_diag_io_tm += gkyl_time_diff_now_sec(wst);
app->stat.n_diag_io += 1;
}

static void
gk_species_write_dynamic(gkyl_gyrokinetic_app* app, struct gk_species *gks, double tm, int frame)
{
Expand Down Expand Up @@ -348,6 +400,13 @@ gk_species_write_dynamic(gkyl_gyrokinetic_app* app, struct gk_species *gks, doub

app->stat.species_io_tm += gkyl_time_diff_now_sec(wst);
app->stat.n_io += 1;

// Write out the sheath BC velocity cutoff (vcutsq).
int par_dir = app->cdim-1; // Sheath BC acts in the parallel direction.
if (gks->lower_bc[par_dir].type == GKYL_BC_GK_SPECIES_SHEATH_SURROGATE || gks->lower_bc[par_dir].type == GKYL_BC_GK_SPECIES_SHEATH_CONDUCTING)
gk_species_write_vcutsq(app, gks, gks->bc_sheath_lo,"z","lower", tm, frame);
if (gks->upper_bc[par_dir].type == GKYL_BC_GK_SPECIES_SHEATH_SURROGATE || gks->upper_bc[par_dir].type == GKYL_BC_GK_SPECIES_SHEATH_CONDUCTING)
gk_species_write_vcutsq(app, gks, gks->bc_sheath_up, "z", "upper", tm, frame);
}

static void
Expand Down Expand Up @@ -674,9 +733,14 @@ gk_species_release_dynamic(const gkyl_gyrokinetic_app* app, const struct gk_spec
}

// Copy BCs are allocated by default. Need to free.
bool release_surr_aux_var = false;
for (int d=0; d<app->cdim; ++d) {
if (s->lower_bc[d].type == GKYL_BC_GK_SPECIES_SHEATH) {
if (s->lower_bc[d].type == GKYL_BC_GK_SPECIES_SHEATH_CONDUCTING) {
gkyl_bc_sheath_gyrokinetic_release(s->bc_sheath_lo);
}
else if (s->lower_bc[d].type == GKYL_BC_GK_SPECIES_SHEATH_SURROGATE) {
gkyl_bc_sheath_gyrokinetic_release(s->bc_sheath_lo);
release_surr_aux_var = true;
}
else if (s->lower_bc[d].type == GKYL_BC_GK_SPECIES_TWISTSHIFT) {
gkyl_bc_twistshift_release(s->bc_ts_lo);
Expand All @@ -688,9 +752,13 @@ gk_species_release_dynamic(const gkyl_gyrokinetic_app* app, const struct gk_spec
gkyl_bc_basic_gyrokinetic_release(s->bc_lo[d]);
}

if (s->upper_bc[d].type == GKYL_BC_GK_SPECIES_SHEATH) {
if (s->upper_bc[d].type == GKYL_BC_GK_SPECIES_SHEATH_CONDUCTING) {
gkyl_bc_sheath_gyrokinetic_release(s->bc_sheath_up);
}
else if (s->upper_bc[d].type == GKYL_BC_GK_SPECIES_SHEATH_SURROGATE) {
gkyl_bc_sheath_gyrokinetic_release(s->bc_sheath_up);
release_surr_aux_var = true;
}
else if (s->upper_bc[d].type == GKYL_BC_GK_SPECIES_TWISTSHIFT) {
gkyl_bc_twistshift_release(s->bc_ts_up);
}
Expand All @@ -700,6 +768,11 @@ gk_species_release_dynamic(const gkyl_gyrokinetic_app* app, const struct gk_spec
(s->upper_bc[d].type == GKYL_BC_GK_SPECIES_FIXED_FUNC) ) {
gkyl_bc_basic_gyrokinetic_release(s->bc_up[d]);
}
if (release_surr_aux_var) {
gk_species_moment_release(app, &s->sheath_moms);
gkyl_array_release(s->dens_sheath);
gkyl_array_release(s->temp_sheath);
}
}

if (app->gk_geom->has_LCFS && app->cdim == 3) {
Expand Down Expand Up @@ -872,11 +945,14 @@ gk_species_init_dynamic(struct gkyl_gk *gk_app_inp, struct gkyl_gyrokinetic_app

for (int d=0; d<cdim; ++d) {
// Lower BC.
if (gks->lower_bc[d].type == GKYL_BC_GK_SPECIES_SHEATH) {
if (gks->lower_bc[d].type == GKYL_BC_GK_SPECIES_SHEATH_CONDUCTING ||
gks->lower_bc[d].type == GKYL_BC_GK_SPECIES_SHEATH_SURROGATE) {
struct gkyl_range *sol_skin = gk_app_inp->geometry.has_LCFS? &gks->local_lower_skin_par_sol : &gks->local_lower_skin[d];
struct gkyl_range *sol_ghost = gk_app_inp->geometry.has_LCFS? &gks->local_lower_ghost_par_sol : &gks->local_lower_ghost[d];
gks->bc_sheath_lo = gkyl_bc_sheath_gyrokinetic_new(d, GKYL_LOWER_EDGE, gks->basis_on_dev,
sol_skin, sol_ghost, gks->vel_map, cdim, 2.0*(gks->info.charge/gks->info.mass), app->use_gpu);
gks->bc_sheath_lo = gkyl_bc_sheath_gyrokinetic_new(d, GKYL_LOWER_EDGE, gks->basis_on_dev,
sol_skin, sol_ghost, gks->vel_map, cdim, 2.0*(gks->info.charge/gks->info.mass),
gks->lower_bc[d].type, gks->lower_bc[d].aux_str,
&gks->grid, &gks->local, gks->basis.poly_order, app->use_gpu);
}
else if (gks->lower_bc[d].type == GKYL_BC_GK_SPECIES_TWISTSHIFT) {
assert(cdim == 3);
Expand Down Expand Up @@ -932,11 +1008,14 @@ gk_species_init_dynamic(struct gkyl_gk *gk_app_inp, struct gkyl_gyrokinetic_app
}

// Upper BC.
if (gks->upper_bc[d].type == GKYL_BC_GK_SPECIES_SHEATH) {
if (gks->upper_bc[d].type == GKYL_BC_GK_SPECIES_SHEATH_CONDUCTING ||
gks->upper_bc[d].type == GKYL_BC_GK_SPECIES_SHEATH_SURROGATE) {
struct gkyl_range *sol_skin = gk_app_inp->geometry.has_LCFS? &gks->local_upper_skin_par_sol : &gks->local_upper_skin[d];
struct gkyl_range *sol_ghost = gk_app_inp->geometry.has_LCFS? &gks->local_upper_ghost_par_sol : &gks->local_upper_ghost[d];
gks->bc_sheath_up = gkyl_bc_sheath_gyrokinetic_new(d, GKYL_UPPER_EDGE, gks->basis_on_dev,
sol_skin, sol_ghost, gks->vel_map, cdim, 2.0*(gks->info.charge/gks->info.mass), app->use_gpu);
gks->bc_sheath_up = gkyl_bc_sheath_gyrokinetic_new(d, GKYL_UPPER_EDGE, gks->basis_on_dev,
sol_skin, sol_ghost, gks->vel_map, cdim, 2.0*(gks->info.charge/gks->info.mass),
gks->upper_bc[d].type, gks->upper_bc[d].aux_str,
&gks->grid, &gks->local, gks->basis.poly_order, app->use_gpu);
}
else if (gks->upper_bc[d].type == GKYL_BC_GK_SPECIES_TWISTSHIFT) {
assert(cdim == 3);
Expand Down Expand Up @@ -983,7 +1062,7 @@ gk_species_init_dynamic(struct gkyl_gk *gk_app_inp, struct gkyl_gyrokinetic_app
gks->f->ncomp, app->cdim, app->use_gpu);
gkyl_bc_basic_gyrokinetic_advance(gfss_bc_op, gks->bc_buffer_up_fixed, gks->f1);
gkyl_bc_basic_gyrokinetic_release(gfss_bc_op);
// Copy ghost range into buffer.
// Copy ghost range into buffer.
gkyl_bc_basic_gyrokinetic_buffer_fixed_func(gks->bc_up[d], gks->bc_buffer_up_fixed, gks->f1);
gkyl_array_clear(gks->f1, 0.0);
gk_species_projection_release(app, &gk_proj_bc_up);
Expand Down Expand Up @@ -1034,6 +1113,16 @@ gk_species_init_dynamic(struct gkyl_gk *gk_app_inp, struct gkyl_gyrokinetic_app
gks->bc_ts_up = gkyl_bc_twistshift_new(&tsinp_up);
}

bool alloc_surr_aux_var = false;
for (int d=0; d<2*app->cdim; ++d)
alloc_surr_aux_var = alloc_surr_aux_var || gks->info.bcs[d].type == GKYL_BC_GK_SPECIES_SHEATH_SURROGATE;

if (alloc_surr_aux_var) {
gk_species_moment_init(app, gks, &gks->sheath_moms, GKYL_F_MOMENT_MAXWELLIAN, false);
gks->dens_sheath = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume);
gks->temp_sheath = mkarr(app->use_gpu, app->basis.num_basis, app->local_ext.volume);
}

// Set function pointers.
gks->rhs_func = gk_species_rhs_dynamic;
gks->rhs_implicit_func = gk_species_rhs_implicit_dynamic;
Expand Down Expand Up @@ -1935,7 +2024,7 @@ gk_species_copy_range(struct gk_species *species, struct gkyl_array *out,
}

void
gk_species_apply_bc(gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gkyl_array *f)
gk_species_apply_bc(gkyl_gyrokinetic_app *app, struct gk_species *species, struct gkyl_array *f)
{
species->bc_func(app, species, f);
}
Expand Down
4 changes: 3 additions & 1 deletion gyrokinetic/apps/gk_species_source.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ gk_species_source_write_integrated_mom_enabled(gkyl_gyrokinetic_app* app, struct
}
}
gkyl_dynvec_clear(gks->src.integ_diag);
app->stat.n_diag_io += 1;

if (gks->src.num_adapt_sources > 0) {
if (rank == 0) {
Expand All @@ -230,6 +231,7 @@ gk_species_source_write_integrated_mom_enabled(gkyl_gyrokinetic_app* app, struct
}
}
gkyl_dynvec_clear(gks->src.part_diag);
app->stat.n_diag_io += 1;

if (rank == 0) {
// Write out temperature diagnostics for adaptive sources.
Expand All @@ -255,11 +257,11 @@ gk_species_source_write_integrated_mom_enabled(gkyl_gyrokinetic_app* app, struct
}
}
gkyl_dynvec_clear(gks->src.temp_diag);
app->stat.n_diag_io += 1;
gks->src.is_first_integ_write_call_adapt = false;
}

app->stat.species_diag_io_tm += gkyl_time_diff_now_sec(wst);
app->stat.n_diag_io += 1;
}


Expand Down
1 change: 1 addition & 0 deletions gyrokinetic/apps/gkyl_gyrokinetic.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ struct gkyl_gyrokinetic_bc {
struct gkyl_gyrokinetic_emission_inp emission;
bool write_diagnostics; // Whether to output diagnostics.
int bidx; // Block index (for multiblock solver).
char aux_str[128]; // Auxiliary string (e.g. path to surrogate model for sheath BCs).
};

struct gkyl_gyrokinetic_geometry {
Expand Down
10 changes: 7 additions & 3 deletions gyrokinetic/apps/gkyl_gyrokinetic_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,11 @@ struct gk_species {
struct gkyl_array *f_host; // Host copy for IO and initialization.

struct gkyl_array *gyro_phi; // Gyroaveraged electrostatic potential.


struct gk_species_moment sheath_moms; // Maxwellian moment array to get temperature and density for sheath BCs.
struct gkyl_array *dens_sheath; // Zeroth maxwellian moment, at the sheath used for surrogate BCs.
struct gkyl_array *temp_sheath; // Third maxwellian moment times mass, at the sheath used for surrogate BCs.

struct gk_species_moment m0; // Computes charge density.
struct gk_species_moment integ_moms; // Integrated moments.
struct gk_species_moment *moms; // Diagnostic moments
Expand Down Expand Up @@ -1126,7 +1130,7 @@ struct gk_species {
const struct gkyl_array *fin, struct gkyl_array *rhs, struct gkyl_array **bflux_moms);
double (*rhs_implicit_func)(gkyl_gyrokinetic_app *app, struct gk_species *species,
const struct gkyl_array *fin, struct gkyl_array *rhs, struct gkyl_array **bflux_moms, double dt);
void (*bc_func)(gkyl_gyrokinetic_app *app, const struct gk_species *species,
void (*bc_func)(gkyl_gyrokinetic_app *app, struct gk_species *species,
struct gkyl_array *f);
void (*release_func)(const gkyl_gyrokinetic_app* app, const struct gk_species *s);
void (*step_f_func)(struct gkyl_array* out, double dt, const struct gkyl_array* inp);
Expand Down Expand Up @@ -3246,7 +3250,7 @@ void gk_species_apply_pos_shift(gkyl_gyrokinetic_app* app, struct gk_species *gk
* @param species Pointer to species.
* @param f Field to apply BCs.
*/
void gk_species_apply_bc(gkyl_gyrokinetic_app *app, const struct gk_species *species, struct gkyl_array *f);
void gk_species_apply_bc(gkyl_gyrokinetic_app *app, struct gk_species *species, struct gkyl_array *f);

/**
* Fill stat object in app with collision timers.
Expand Down
3 changes: 2 additions & 1 deletion gyrokinetic/apps/gyrokinetic_lw.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ static const struct gkyl_str_int_pair gk_bcs[] = {
{ "speciesFunc", GKYL_BC_GK_SPECIES_FUNC }, // Fill ghost cell using a user-function.
{ "speciesFixedFunc", GKYL_BC_GK_SPECIES_FIXED_FUNC }, // Fixed function, time-independent.
{ "speciesZeroFlux", GKYL_BC_GK_SPECIES_ZERO_FLUX }, // Zero flux.
{ "speciesSheath", GKYL_BC_GK_SPECIES_SHEATH }, // Sheath.
{ "speciesSheathConducting", GKYL_BC_GK_SPECIES_SHEATH_CONDUCTING }, // Sheath.
{ "speciesSheathSurrogate", GKYL_BC_GK_SPECIES_SHEATH_SURROGATE }, // Sheath.
{ "speciesRecycle", GKYL_BC_GK_SPECIES_RECYCLE }, // Recycling.
{ "speciesPeriodic", GKYL_BC_GK_SPECIES_PERIODIC }, // Periodic.
{ "speciesTwistshift", GKYL_BC_GK_SPECIES_TWISTSHIFT }, // Twist-shift.
Expand Down
5 changes: 5 additions & 0 deletions gyrokinetic/creg/ignore_c_tests.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ return {
"rt_gk_bgk_periodic_sodshock_1x2v_p1", -- crashes compareFiles (C assertion in gkyl_aligned_free_)
"rt_gk_bgk_im_periodic_sodshock_1x2v_p1", -- crashes compareFiles (C assertion in gkyl_aligned_free_)
"rt_gk_wham_1xIC_2x2v_p1", -- crashes compareFiles (C assertion in gkyl_aligned_free_)
"rt_gk_multib_tcv_x21_3x2v_p1", -- Not ready yet.
"rt_gk_cbc_2x2v_p1", -- The setup is not ready yet.
"rt_gk_tcv_iwl_adapt_source_3x2v_p1", -- The shift function is too large and makes it crash.
"rt_gk_neut_step_2x3v_p1",
"rt_gk_multib_asdex_solonly_3x2v_p1", -- eqdisk reading problem.
},
gpu = {
},
Expand Down
Loading
Loading