Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 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
cc3f6a0
Restore the collisionless kernels, comments and remove maxima coding …
Antoinehoff May 15, 2026
e030549
use `float(expan(` instead of `float(fullratsimp(`
Antoinehoff May 15, 2026
65380b2
remove personal path
Antoinehoff May 15, 2026
a5bd672
revert changes for collisionless terms
Antoinehoff May 15, 2026
cc9491b
revert modification outside of the scope of the PR
Antoinehoff May 15, 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
8 changes: 5 additions & 3 deletions maxima/g0/gk-sheath/ms-gk-sheath.mac
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ load("gk-sheath/sheath-3x2v");

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

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

/* Serendipity basis. */
minPolyOrder_Ser : 1$
maxPolyOrder_Ser : 1$
Expand Down Expand Up @@ -43,7 +45,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 @@ -69,7 +71,7 @@ for bInd : 1 thru length(bName) do (


/* 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_util.h>~%")$
Expand All @@ -94,7 +96,7 @@ 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 q2Dm, const double *phi, const double *phiWall, const double *vcut_fact, const double *f, double *fRefl); ~%", edge[sI], cdim, vDims[cdim][vI], bName[bInd], polyOrder)

)
)
Expand Down
2 changes: 1 addition & 1 deletion maxima/g0/gk-sheath/sheath-1x1v.mac
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ 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),
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 *vcut_fact, 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. */
Expand Down
84 changes: 41 additions & 43 deletions maxima/g0/gk-sheath/sheath-1x2v.mac
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ genGkSheathKer1x2v(fh, cdim, vdim, basisFun, polyOrder) := block(
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,vparLo_e,vparUp_e,fReflSurfMu_e,j,nodeIdx,fSurfMu_c,fSurfMu_e,intLims,fReflSurfMu_c,
xBar_v,xSqBar_v,fReflSurf_c,fReflSurf_e,fRefl_c],
xBar_v,xSqBar_v,fReflSurf_c,fReflSurf_e,fRefl_c,
vcutFact_e,vcutFact_vpar0_e,vcutFact_q,vcutFactVpar_e,nodesVparMu,vcutFact_c,tempVars1,tempVars2],

pdim : cdim+vdim,

Expand All @@ -35,12 +36,12 @@ genGkSheathKer1x2v(fh, cdim, vdim, basisFun, polyOrder) := block(
bSurf : basisFromVars("gkhyb",surfVars,polyOrder),
bV : basisFromVars("gkhyb",[vpar,mu],polyOrder),
bVpar : basisFromVars("gkhyb",[vpar],polyOrder),
bMu : basisFromVars("gkhyb",[mu],polyOrder)
bMu : basisFromVars("ser",[mu],polyOrder)
) else (
bSurf : basisFromVars(basisFun,surfVars,polyOrder),
bV : basisFromVars(basisFun,[vpar,mu],polyOrder),
bVpar : basisFromVars(basisFun,[vpar],polyOrder),
bMu : basisFromVars(basisFun,[mu],polyOrder)
bMu : basisFromVars("ser",[mu],polyOrder)
),
numBsurf : length(bSurf),

Expand All @@ -62,6 +63,12 @@ genGkSheathKer1x2v(fh, cdim, vdim, basisFun, polyOrder) := block(

/* Expand input distribution function f on phase-space basis using input coeffs. */
f_e : doExpand1(f, bP),

/* Expand vcut_fact on mu basis (bMu). */
vcutFactVpar_e : doExpand1(vcut_fact, bMu),

/* Evaluate vcut_fact at (mu_j) */
vcutFact_q : evAtNodes(vcutFactVpar_e, nodesMu, zvSurfVars),

/* Generate separate kernels for lower/upper boundaries. */
edge : ["lower", "upper"],
Expand All @@ -70,18 +77,17 @@ genGkSheathKer1x2v(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),
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 *vcut_fact, 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. */
/* Evaluate base potential difference: deltaPhi = phiSheath - phiWall. */
deltaPhi_q : deltaPhi_e,
vcutSq_q : gcfac(float(fullratsimp(-q2Dm*deltaPhi_q))),


/* Evaluate f at the z surface. */
fSurf_c : calcInnerProdList(surfVars, 1, bSurf, subst(surfPerpVar=surfPerpVal[sI], f_e)),
fSurf_e : doExpand(fSurf_c, bSurf),
Expand All @@ -94,7 +100,7 @@ genGkSheathKer1x2v(fh, cdim, vdim, basisFun, polyOrder) := block(
printf(fh, " double vcutSq;~%"),
printf(fh, " double fReflSurf[~a] = {0.}; ~%", length(bV)),
printf(fh, "~%"),

vparLo_e : subst(vpar=-1, vmap_e[1]),
vparUp_e : subst(vpar=1, vmap_e[1]),
printf(fh, " double vparLo = ~a;~%", float(expand(vparLo_e))),
Expand All @@ -105,54 +111,46 @@ genGkSheathKer1x2v(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),
printf(fh, "~%"),

/* If vcut^2 at this node is below all vpar^2 in this cell, BC at this node should be absorbing
Comment thread
Antoinehoff marked this conversation as resolved.
so set coefficients of fRefl to 0 (no reflection from this node). */
printf(fh, " if (vcutSq <= 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, "~%"),

/* Project f onto vpar,mu basis (bV). */
fSurf_c : gcfac(fullratsimp(calcInnerProdList(varsV, 1, bV, fSurf_e))),
/* Full reflection: set fRefl coefficients to f coefficients. */
writeCExprsNoExpand1(fReflSurf, fSurf_c),
printf(fh, "~%"),

/* If vcut^2 at this node is in this cell, BC at this node is partial reflection. */
printf(fh, " } else { // partial reflection ~%"),
printf(fh, "~%"),

/* Reflected f at (mu)_j nodes. */
fReflSurfMu_e : makelist(0,j,1,numNodesMu),

printf(fh, " double wv = ~a;~%", float(fullratsimp((vparUp + vparLo)/2))),
printf(fh, " double dv = ~a;~%", float(fullratsimp(vparUp - vparLo))),
printf(fh, " double wv = ~a;~%", float(expand((vparUp + vparLo)/2))),
printf(fh, " double dv = ~a;~%", float(expand(vparUp - vparLo))),
printf(fh, "~%"),

printf(fh, " double xBar, xSqBar;~%"),
printf(fh, " double fReflSurfMu[~a][~a] = {0.}; ~%", numNodesMu, length(bVpar)),
printf(fh, " double xBar, xSqBar;~%"),
printf(fh, " double fReflSurfMu[~a][~a] = {0.}; ~%", numNodesMu, length(bVpar)),
printf(fh, "~%"),

/* Loop over (mu)_j nodes. */
for j : 1 thru numNodesMu do (
printf(fh, " // node (mu)_~a ~%", j-1),
printf(fh, " // node (mu)_~a ~%", j-1),

nodeIdx : sublist_indices(nodesMu, lambda([x], x[1]=nodesMu[j][1]))[1],

/* Project f at this (mu)_j node onto vpar basis (bVpar). */
fSurfMu_c : gcfac(fullratsimp(calcInnerProdList([vpar], 1, bVpar, fSurfMu_q[nodeIdx]))),
fSurfMu_e : doExpand(fSurfMu_c, bVpar),

/* Compute vcut^2 at this mu node: vcutSq = alpha(mu) * q2Dm * deltaPhi. */
printf(fh, " vcutSq = ~a; ~%", gcfac(float(expand(-vcutFact_q[nodeIdx]*q2Dm*deltaPhi_q)))),
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 at this (x,y)_i node to 0 (no reflection from this node). */
printf(fh, " if (vcutSq <= vparAbsSqLo) { // absorb (no reflection) ~%"),
printf(fh, "~%"),
writeCExprsWithZeros1(fReflSurfMu[j-1], makelist(0,i,1,length(bVpar))),
printf(fh, "~%"),

printf(fh, " } else if (vcutSq > vparAbsSqUp) { // full reflection ~%"),
printf(fh, "~%"),
writeCExprsNoExpand1(fReflSurfMu[j-1], fSurfMu_c),
printf(fh, "~%"),

printf(fh, " } else { // partial reflection ~%"),
printf(fh, "~%"),

printf(fh, " if (wv > 0.) {~%"),
printf(fh, " // vcut in logical space.~%"),
printf(fh, " double vcut_l = 2.*(sqrt(vcutSq)-wv)/dv;~%"),
Expand Down Expand Up @@ -193,6 +191,9 @@ genGkSheathKer1x2v(fh, cdim, vdim, basisFun, polyOrder) := block(
printf(fh, " }~%"),
printf(fh, "~%"),

printf(fh, " }~%"), /* End of partial reflection. */
printf(fh, "~%"),

/* Expand vpar coefficients in vpar basis at this (mu)_j node. */
fReflSurfMu_e[j] : doExpand1(fReflSurfMu[j-1], bVpar)

Expand All @@ -208,9 +209,6 @@ genGkSheathKer1x2v(fh, cdim, vdim, basisFun, polyOrder) := block(
writeCExprsNoExpand1(fReflSurf, fReflSurf_c),
printf(fh, "~%"),

printf(fh, " }~%"), /* End of partial reflection else. */
printf(fh, "~%"),

/* Expansion in vpar,mu of fReflSurf. */
fReflSurf_e : doExpand1(fReflSurf, bV),

Expand Down
Loading