Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
2eab822
add kernel generation for EM. The kernels are empty for now.
Antoinehoff Oct 23, 2025
598b7a0
change the path to a generic path
Antoinehoff Oct 23, 2025
ea126b3
reorganize the em scripts and code. The em kernels are still empty
Antoinehoff Oct 23, 2025
a789c8f
restore electrostatic files
Antoinehoff Oct 23, 2025
90d8dd8
this commit is able to create all the add em kernels (empty) and the …
Antoinehoff Oct 23, 2025
fc855f8
New way of handling the EM kernels. We now generate two types of EM k…
Antoinehoff Nov 4, 2025
78e8603
The scripts are still containing commented parts to keep the possibil…
Antoinehoff Nov 6, 2025
6ecbf54
clean and make the script write es and em kernels for fluxes
Antoinehoff Nov 6, 2025
eff6a16
Ensure that all local variables are put in the bracket scope of the b…
Antoinehoff Nov 7, 2025
ee37a0c
fix an error were apardot was expanded on bP instead of bC
Antoinehoff Nov 7, 2025
ef2671c
Fix the apardot volume contribution, a 1/vmap was missing.
Antoinehoff Nov 7, 2025
7faac8e
remove dot operator with doExpand and fix a wrong expansion of Apar a…
Antoinehoff Nov 7, 2025
3ed347a
update kernel signature of add_aprdot to include vmap.
Antoinehoff Nov 7, 2025
99d2daf
correct a 1/J factor and define the apar and apardot quantities in co…
Antoinehoff Nov 11, 2025
5a22333
clean unused routines
Antoinehoff Dec 3, 2025
9bce6d8
conserve former naming for electrostatic limit and add 'em_' prefix f…
Antoinehoff Feb 10, 2026
b4dea01
add a configurable output directory variable
Antoinehoff Feb 10, 2026
ab0ea6d
add configurable output directory variable
Antoinehoff Feb 10, 2026
c4df9f7
remove unused lines
Antoinehoff Feb 10, 2026
a51a16c
caught a typo but it's just in a comment -_-
Antoinehoff Feb 10, 2026
064ca54
Improve the em flux kernel generation scripts to be less redundant an…
Antoinehoff Feb 12, 2026
25399c6
kernels related to the get_em_back_full_upwind branch in Gkeyll
Antoinehoff Feb 17, 2026
2d170be
remove unused scripts
Antoinehoff Feb 17, 2026
dea3b48
remove unused function
Antoinehoff Feb 17, 2026
8631b9a
remove the EM in the surface flux routines since it's the only one now.
Antoinehoff Feb 17, 2026
bf20d44
add error detection for the advection scheme
Antoinehoff Feb 17, 2026
03fdd36
remove unused variables and streamline error handling for p>1
Antoinehoff Feb 19, 2026
0d518e1
add apar_c to local variable list
Antoinehoff Feb 19, 2026
79fa5a5
Refactor a major part of the volume and conf flux kernels. We reuse a…
Antoinehoff Feb 23, 2026
984a83c
update scripts to be compatible with latest commit.
Antoinehoff Feb 23, 2026
651e967
🐛it almost works but it seems that an error in indexation is present
Antoinehoff Feb 25, 2026
bd5e5d7
also update the header of the other functions
Antoinehoff Feb 25, 2026
4763487
🔥🐛🔥 the 1x2v kernel works fine now
Antoinehoff Feb 25, 2026
9693824
not all local variables were declared
Antoinehoff Feb 25, 2026
93bebbc
unify coding style with 1x2v
Antoinehoff Feb 26, 2026
72e9677
little cleaning
Antoinehoff Feb 26, 2026
742bf9d
refactor alpha_mu name to vcut_fact
Antoinehoff Feb 27, 2026
29bb010
The vcut factor is now defined on the perpendicular conf dims and mu
Antoinehoff Mar 2, 2026
558caeb
add the sheath surrogate kernels
Antoinehoff Mar 5, 2026
6c32acf
use q2Dm directly in the kernel
Antoinehoff Mar 16, 2026
910aed4
Add kernels that use the convergence check before using the surrogate
Antoinehoff Apr 1, 2026
d6af53b
restore collisionless kernel to main, EM sneaked in
Antoinehoff May 28, 2026
f7ce0fa
restore collisionless kernel to main, EM sneaked in
Antoinehoff May 28, 2026
7fdc7a0
remove the converged surrogate kernels
Antoinehoff May 28, 2026
f46be80
adapt the kernels to use the surface representation of bimpact angle
Antoinehoff May 28, 2026
fa3a949
Merge pull request #99 from ammarhakim/gk_ai_sheath-bimpactangle_surf
Antoinehoff May 28, 2026
537b353
Split the kernels for surrogate sheath BC in two, one infer and get t…
Antoinehoff Jun 3, 2026
3603e30
Include the stride as input and change the double to float arrays
Antoinehoff Jun 3, 2026
ee81922
The reflection kernels expect vcut as an input now. New kernels are c…
Antoinehoff Jun 5, 2026
d87192d
add fmax to cap density non negative for sqrt eval
Antoinehoff Jun 12, 2026
8a3950e
fix the node selection in 1x2v
Antoinehoff Jun 20, 2026
858f8f7
renam functions from srgz to surr and fix a indexation bug in the 1x2…
Antoinehoff Jun 20, 2026
5b30d7a
adapt the surrogate kernel interface to have handle the grid integration
Antoinehoff Jun 24, 2026
1df7ec3
add a comment about possible extension of the input parameters
Antoinehoff Jun 25, 2026
fbb63ca
cap density and potential drop to positive numbers to avoid evaluatin…
Antoinehoff Jul 22, 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
88 changes: 84 additions & 4 deletions maxima/g0/gk-sheath/ms-gk-sheath.mac
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ load("gk-sheath/sheath-1x1v");
load("gk-sheath/sheath-1x2v");
load("gk-sheath/sheath-2x2v");
load("gk-sheath/sheath-3x2v");
load("gk-sheath/sheath_surrogate-1x2v");
load("gk-sheath/sheath_surrogate-2x2v");
load("gk-sheath/sheath_surrogate-3x2v");

/* ...... USER INPUTS........ */

outDir : "~/max-out"$ /* Output directory */

/* Serendipity basis. */
minPolyOrder_Ser : 1$
maxPolyOrder_Ser : 1$
Expand Down Expand Up @@ -43,7 +48,7 @@ for bInd : 1 thru length(bName) do (
minPolyOrderB : minPolyOrder[bInd],
maxPolyOrderB : maxPolyOrder[bInd],
for polyOrder : minPolyOrderB thru maxPolyOrderB do (
fname : sconcat("~/max-out/bc_sheath_gyrokinetic_",bName[bInd],"_p",polyOrder,".c"),
fname : sconcat(outDir,"/bc_sheath_gyrokinetic_",bName[bInd],"_p",polyOrder,".c"),
fh : openw(fname),

printf(fh, "#include <gkyl_bc_sheath_gyrokinetic_kernels.h> ~%"),
Expand All @@ -63,15 +68,45 @@ for bInd : 1 thru length(bName) do (
)
)
),

for useSurrogate : 0 thru 1 do (
for cdim : minDim[bInd] thru maxDim[bInd] do (
print(sconcat("Creating vcut kernels for serendipity basis, surrogate = ", useSurrogate, " for ", cdim, "x2v, p", polyOrder)),
if (polyOrder = 1) then (
if cdim=1 then (
genGkSheathVcutCalcKer1x2v(fh, cdim, 2, bName[bInd], polyOrder, useSurrogate)
) else if cdim=2 then (
genGkSheathVcutCalcKer2x2v(fh, cdim, 2, bName[bInd], polyOrder, useSurrogate)
) else if cdim=3 then (
genGkSheathVcutCalcKer3x2v(fh, cdim, 2, bName[bInd], polyOrder, useSurrogate)
)
)
)
),

for cdim : minDim[bInd] thru maxDim[bInd] do (
print(sconcat("Creating input builder kernels for serendipity basis for ", cdim, "x2v, p", polyOrder)),
if (polyOrder = 1) then (
if cdim=1 then (
genGkSheathInputKer1x2v(fh, cdim, 2, bName[bInd], polyOrder)
) else if cdim=2 then (
genGkSheathInputKer2x2v(fh, cdim, 2, bName[bInd], polyOrder)
) else if cdim=3 then (
genGkSheathInputKer3x2v(fh, cdim, 2, bName[bInd], polyOrder)
)
)
),
close(fh)
)
)$


/* Create a header file for sheath kernels. */
fh : openw("~/max-out/gkyl_bc_sheath_gyrokinetic_kernels.h")$
fh : openw(sconcat(outDir,"/gkyl_bc_sheath_gyrokinetic_kernels.h"))$
printf(fh, "#pragma once~%")$
printf(fh, "~%")$
printf(fh, "#include <gkyl_const.h>~%")$
printf(fh, "#include <gkyl_kann_net.h>~%")$
printf(fh, "#include <gkyl_util.h>~%")$
printf(fh, "#include <math.h>~%")$
printf(fh, "~%")$
Expand All @@ -83,7 +118,31 @@ printf(fh, " // from Kroger ~%")$
printf(fh, " return (3.*x-x*x*x*(6. + x*x - 2.*x*x*x*x)/5.)/(1.-x*x); ~%")$
printf(fh, "}~%")$
printf(fh, "~%")$


printf(fh, "// Linear interpolation of the surrogate output vcut[ng] (defined on the mu-grid~%")$
printf(fh, "// mu_grid[ng], which the surrogate model supplies as the second half of each~%")$
printf(fh, "// node's output block) onto mu_new[n], normalising mu by mu_ref (= T/B). Results~%")$
printf(fh, "// are written into out[n]; clamps at the grid boundaries.~%")$
printf(fh, "GKYL_CU_DH~%")$
printf(fh, "static inline void~%")$
printf(fh, "bc_sheath_gyrokinetic_surr_interpf(const float *vcut, const float *mu_grid, int ng, const double *mu_new, int n, double mu_ref, double *out)~%")$
printf(fh, "{~%")$
printf(fh, " for (int i = 0; i < n; i++) {~%")$
printf(fh, " double mu = mu_new[i]/mu_ref;~%")$
printf(fh, " if (mu <= mu_grid[0]) { out[i] = vcut[0]; continue; }~%")$
printf(fh, " if (mu >= mu_grid[ng - 1]) { out[i] = vcut[ng - 1]; continue; }~%")$
printf(fh, " // binary search for the bracketing interval~%")$
printf(fh, " int lo = 0, hi = ng - 1;~%")$
printf(fh, " while (hi - lo > 1) {~%")$
printf(fh, " int mid = (lo + hi) >> 1;~%")$
printf(fh, " if (mu_grid[mid] <= mu) lo = mid; else hi = mid;~%")$
printf(fh, " }~%")$
printf(fh, " double t = (mu - mu_grid[lo]) / (mu_grid[hi] - mu_grid[lo]);~%")$
printf(fh, " out[i] = vcut[lo] + t * (vcut[hi] - vcut[lo]);~%")$
printf(fh, " }~%")$
printf(fh, "}~%")$
printf(fh, "~%")$

printf(fh, "EXTERN_C_BEG~%")$
printf(fh, "~%")$

Expand All @@ -94,14 +153,35 @@ for bInd : 1 thru length(bName) do (
for vI : 1 thru length(vDims[cdim]) do (
for sI : 1 thru length(edge) do (

printf(fh, "GKYL_CU_DH void bc_sheath_gyrokinetic_reflectedf_~a_~ax~av_~a_p~a(const double *vmap, const double q2Dm, const double *phi, const double *phiWall, const double *f, double *fRefl); ~%", edge[sI], cdim, vDims[cdim][vI], bName[bInd], polyOrder)
printf(fh, "GKYL_CU_DH void bc_sheath_gyrokinetic_reflectedf_~a_~ax~av_~a_p~a(const double *vmap, const double *vcutsq, const double *f, double *fRefl); ~%", edge[sI], cdim, vDims[cdim][vI], bName[bInd], polyOrder)

)
)
)
)
)$

/* Eval vcutconst kernels. */
for cdim : minDim_Ser thru maxDim_Ser do (
for sI : 1 thru length(edge) do (
printf(fh, "GKYL_CU_DH void bc_sheath_gyrokinetic_vcutsq_const_~a_~ax2v_ser_p1(const double *phi, const double *phi_wall, double q2Dm, double *vcutSq_n) ; ~%", edge[sI], cdim)
)
)$

/* Eval vcutsq surrogate kernels. */
for cdim : minDim_Ser thru maxDim_Ser do (
for sI : 1 thru length(edge) do (
printf(fh, "GKYL_CU_DH void bc_sheath_gyrokinetic_vcutsq_surr_~a_~ax2v_ser_p1(const double *vmap, const float *nn_out, int n_out, const double *temperature, const double *bmag, double *vcutsq_out) ; ~%", edge[sI], cdim)
)
)$

/* input builder kernels. */
for cdim : minDim_Ser thru maxDim_Ser do (
for sI : 1 thru length(edge) do (
printf(fh, "GKYL_CU_DH void bc_sheath_gyrokinetic_build_input_~a_~ax2v_ser_p1(const double *phi, const double *phi_wall, const double *density, const double *temperature, const double *bmag, const double *bimpact_angle, int n_inp, float *nn_inp_out) ; ~%", edge[sI], cdim)
)
)$

printf(fh, "~%")$
printf(fh, "EXTERN_C_END~%")$
printf(fh, "~%")$
Expand Down
29 changes: 9 additions & 20 deletions maxima/g0/gk-sheath/sheath-1x1v.mac
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fpprec : 24$
genGkSheathKer1x1v(fh, cdim, vdim, basisFun, polyOrder) := block(
[pdim,varsC,bC,varsP,bP,vSub,NP,varsV,vmap_e,vmapSq_e,vmap_prime_e,vparLo_e,vparUp_e,surfPerpVar,
surfVars,surfVarsC,bSurf,bV,bVpar,bMu,numBsurf,zvSurfVars,nodesMu,numNodesMu,bNMu,f_e,edge,
surfPerpVal,sI,phiSheath_e,phiWall_e,deltaPhi_e,deltaPhi_q,vcutSq_q,fSurf_c,fSurf_e,fSurfMu_q,
surfPerpVal,sI,phiSheath_e,phiWall_e,deltaPhi_e,deltaPhi_q,vcutsq_q,fSurf_c,fSurf_e,fSurfMu_q,
fReflSurfMu_e,j,nodeIdx,fSurfMu_c,fSurfMu_e,intLims,fReflSurfMu_c,
xBar_v,xSqBar_v,fReflSurf_c,fReflSurf_e,fRefl_c],

Expand Down Expand Up @@ -54,24 +54,13 @@ genGkSheathKer1x1v(fh, cdim, vdim, basisFun, polyOrder) := block(
for sI : 1 thru length(edge) do (

printf(fh, "~%"),
printf(fh, "GKYL_CU_DH void bc_sheath_gyrokinetic_reflectedf_~a_~ax~av_~a_p~a(const double *vmap, const double q2Dm, const double *phi, const double *phiWall, const double *f, double *fRefl) ~%{ ~%", edge[sI], cdim, vdim, basisFun, polyOrder),

/* Calculate expansion for deltaPhi = phiSheath - phiWall, evaluated at z=zVal,
where zVal=-1 or 1 depending on if we're on the left or right edge of the global domain, respectively. */
phiSheath_e : subst(surfPerpVar=surfPerpVal[sI],doExpand1(phi, bC)),
phiWall_e : subst(surfPerpVar=surfPerpVal[sI],doExpand1(phiWall, bC)),
deltaPhi_e : phiSheath_e - phiWall_e,

/* Evaluate vcutSqQ = vcut^2. q2Dm = q*2/m. */
deltaPhi_q : deltaPhi_e,
vcutSq_q : gcfac(float(fullratsimp(-q2Dm*deltaPhi_q))),

printf(fh, "GKYL_CU_DH void bc_sheath_gyrokinetic_reflectedf_~a_~ax~av_~a_p~a(const double *vmap, const double *vcutsq, const double *f, double *fRefl) ~%{ ~%", edge[sI], cdim, vdim, basisFun, polyOrder),

/* Evaluate f at the z surface. */
fSurf_c : calcInnerProdList(surfVars, 1, bSurf, subst(surfPerpVar=surfPerpVal[sI], f_e)),
fSurf_e : doExpand(fSurf_c, bSurf),

/* Variable declarations/allocations. */
printf(fh, " double vcutSq;~%"),
printf(fh, " double fReflSurf[~a] = {0.}; ~%", length(bV)),
printf(fh, "~%"),

Expand All @@ -85,21 +74,21 @@ genGkSheathKer1x1v(fh, cdim, vdim, basisFun, polyOrder) := block(
printf(fh, " double vparAbsSqUp = vmap[0]>0.? vparUp*vparUp : vparLo*vparLo;~%"),
printf(fh, "~%"),

/* Write vcut^2 at boundary. */
printf(fh, " vcutSq = ~a; ~%", vcutSq_q),
/* vcutsq is passed as a pre-computed DG field; read the single surface value. */
printf(fh, " double vcutsq_n = vcutsq[0]; ~%"),
printf(fh, "~%"),

/* If vcut^2 at this node is below all vpar^2 in this cell, BC at this node should be absorbing
so set coefficients of fRefl to 0 (no reflection from this node). */
printf(fh, " if (vcutSq <= vparAbsSqLo) { // absorb (no reflection) ~%"),
printf(fh, " if (vcutsq_n <= vparAbsSqLo) { // absorb (no reflection) ~%"),
printf(fh, "~%"),

writeCExprsWithZeros1(fReflSurf, makelist(0.,j,1,length(bV))),
printf(fh, "~%"),

/* If vcut^2 at this node is above all vpar^2 in this cell, BC at this node should be full reflection. */
/* So set coefficients of fRefl to coefficients of f. */
printf(fh, " } else if (vcutSq > vparAbsSqUp) { // full reflection ~%"),
printf(fh, " } else if (vcutsq_n > vparAbsSqUp) { // full reflection ~%"),
printf(fh, "~%"),

/* Project f onto vpar basis (bV). */
Expand All @@ -124,7 +113,7 @@ genGkSheathKer1x1v(fh, cdim, vdim, basisFun, polyOrder) := block(

printf(fh, " if (wv > 0.) {~%"),
printf(fh, " // vcut in logical space.~%"),
printf(fh, " double vcut_l = 2.*(sqrt(vcutSq)-wv)/dv;~%"),
printf(fh, " double vcut_l = 2.*(sqrt(vcutsq_n)-wv)/dv;~%"),
printf(fh, "~%"),

intLims : [[-1,vcut_l]],
Expand All @@ -135,7 +124,7 @@ genGkSheathKer1x1v(fh, cdim, vdim, basisFun, polyOrder) := block(

printf(fh, " } else {~%"),
printf(fh, " // vcut in logical space.~%"),
printf(fh, " double vcut_l = 2.*(-sqrt(vcutSq)-wv)/dv;~%"),
printf(fh, " double vcut_l = 2.*(-sqrt(vcutsq_n)-wv)/dv;~%"),
printf(fh, "~%"),

intLims : [[vcut_l,1]],
Expand Down
Loading