Skip to content

Add fdot_abs_integrated_moms diagnostic - #1098

Open
Maxwell-Rosen wants to merge 7 commits into
mainfrom
fdot-abs-integrated-moms
Open

Add fdot_abs_integrated_moms diagnostic#1098
Maxwell-Rosen wants to merge 7 commits into
mainfrom
fdot-abs-integrated-moms

Conversation

@Maxwell-Rosen

@Maxwell-Rosen Maxwell-Rosen commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

Greg and I have been interested in the diagnostic of integral |fdot| dv dz in the mirror simulations. This is helpful for the L2 norm of the change in the distribution function. Here is an example of it being used.

image

The diagnostic is added to the time_rate_diagnostics flag, so it will show both fdot and fdot_abs integrated diagnostics.

A new sum abs function was added, with a unit test, as this is necessary for |fdot| to be computed.

I also had GPT sol refactor the fdot diagnostics to take an enum table, specifying which of the fdot diagnostics the user wants. This also provides the fdot, RHS vector directly, which is a phase space array.

- Implement gkyl_array_reduce_range_sum_abs for CPU.
- Implement gkyl_array_reduce_range_sum_abs_cu for CUDA.
- Update tests to include absolute value reduction cases.
- Modify gk_species to use absolute value reduction for diagnostics.
Comment thread core/zero/array_reduce.c Outdated
long start = gkyl_range_idx(range, iter.idx);
const double *d = gkyl_array_cfetch(arr, start);
for (long i=0; i<n; ++i)
res[i] += fabs(d[i]);

@Antoinehoff Antoinehoff Aug 27, 2026

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 am a bit confused about how $\sum |f_{dot}|$ is computed component wise like

$$v^{k} = \sum_{i=0}^{N} |f_i^{(k)}|$$

What's the meaning of this quantity? when $k\neq 0$ ?

@Maxwell-Rosen Maxwell-Rosen Aug 27, 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.

I believe this sums over all the components, which is also what the reduce operation for the regular sum does as well. In your notation, does i represent "cell" and k is the component? It sums over all cells and components here.

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.

Yeah sorry my question was not clear and I think I misunderstood something. We agree that the start is used to take only the 0th coefficient to sum over the absolute value of the cell average ?

- Updated the time rate diagnostics configuration in various files to support two diagnostic types:
  - GKYL_GK_TIME_RATE_DIAGNOSTIC_FDOT_INTEGRATED_MOMENTS
  - GKYL_GK_TIME_RATE_DIAGNOSTIC_FDOT_ABS_INTEGRATED_MOMENTS
- Replaced the previous boolean flag for time rate diagnostics with a structured approach that includes the number of diagnostics and their specific types.
- This change improves the diagnostic capabilities of the gyrokinetic simulations, allowing for more detailed analysis of the integrated moments over time.
… a seperate function rather than putting it

  inside gkyl_array_reduce_range as an option for GKYL_SUM_ABS. The existing implementation is correct, so refactor
  this to use the gkyl_array_reduce_range method
…add diagnostics that write the moments of fdot and fdot_abs that are

  computed from

  Implemented FdotMoments and FdotAbsMoments diagnostics.

  - Reuses the existing RK-computed moment arrays without recalculation.
  - Writes P0 configuration-space files named *_fdot_<moment>_<frame>.gkyl and *_fdot_abs_<moment>_<frame>.gkyl.
  - Added C enums and Lua bindings in gyrokinetic/apps/gkyl_gyrokinetic.h:103 and gyrokinetic/apps/gyrokinetic_lw.c:83.
  - CPU regression verified absolute values and agreement with both integrated diagnostics.
  - Library compiled and linked successfully. The final build step only failed when copying shared data outside the writable workspace.

Avoid if statements in time loops

  - Time-loop fdot calculation now uses preselected enabled/no-op function pointers.
  - Signed, absolute, combined, and disabled writers are selected during initialization.
  - All new conditionals are limited to initialization/release.
  - Enabled/disabled regressions and Valgrind passed.
  - Library compiled and linked; only the sandboxed post-build data copy failed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants