XGC1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
f_source.cpp File Reference
#include <Kokkos_Core.hpp>
#include "timer_macro.hpp"
#include "space_settings.hpp"
#include "globals.hpp"
#include "sml.hpp"
#include "plasma.hpp"
#include "domain_decomposition.hpp"
#include "distribution.hpp"
#include "velocity_grid.hpp"
#include "collisions.hpp"
#include "update_ptl_weights.hpp"
#include "update_f0.hpp"
#include "update_analytic_f0_old.hpp"
#include "update_analytic_f0.hpp"
#include "distribute_f0g.hpp"
#include "resampling.hpp"
#include "pseudo_inverse.hpp"
#include "checkpoint.hpp"
#include "vgrid_distribution.hpp"
#include "diffusion.hpp"
#include "toroidal_average.hpp"
#include "moments.hpp"
#include "f_source.hpp"
#include "current_drive.hpp"
#include "diag_f0.hpp"
#include "diag_3d_f0_f.hpp"
#include "diagnostics.hpp"
#include "pellet.hpp"
#include "heat_torque.hpp"
#include "neutrals.hpp"
#include "set_nans_to_zero.hpp"
#include "get_total_f.hpp"
Include dependency graph for f_source.cpp:

Functions

void f_nan_check (double *f0_f)
 
int get_resamp_tile_size ()
 
void f0_upsampling_set_params ()
 
void f0_upsampling_restore_params ()
 
int do_f0_upsampling ()
 
void f_source (const Simulation< DeviceType > &sml, const Grid< DeviceType > &grid, const MagneticField< DeviceType > &magnetic_field, ElectricField< DeviceType > &electric_field, DomainDecomposition< DeviceType > &pol_decomp, const VelocityGrid &vgrid, const Charges &charges, Plasma &plasma, Smoothing &smoothing, PerturbedBField< DeviceType > &perturbed_B_field, const Neutrals< DeviceType > &neutrals, Sources &sources, DMWrapper &pseudo_inv_dm, Diagnostics &diagnostics)
 Applies multiple non-Hamiltonian source terms (collisions, neutrals, heat/torque, diffusion, radiative cooling, etc.) that modify the distribution function. More...
 

Function Documentation

int do_f0_upsampling ( )

Here is the caller graph for this function:

void f0_upsampling_restore_params ( )

Here is the caller graph for this function:

void f0_upsampling_set_params ( )

Here is the caller graph for this function:

void f_nan_check ( double *  f0_f)
void f_source ( const Simulation< DeviceType > &  sml,
const Grid< DeviceType > &  grid,
const MagneticField< DeviceType > &  magnetic_field,
ElectricField< DeviceType > &  electric_field,
DomainDecomposition< DeviceType > &  pol_decomp,
const VelocityGrid vgrid,
const Charges charges,
Plasma plasma,
Smoothing smoothing,
PerturbedBField< DeviceType > &  perturbed_B_field,
const Neutrals< DeviceType > &  neutrals,
Sources sources,
DMWrapper pseudo_inv_dm,
Diagnostics diagnostics 
)

Applies multiple non-Hamiltonian source terms (collisions, neutrals, heat/torque, diffusion, radiative cooling, etc.) that modify the distribution function.

The function orchestrates the entire "source" step in the kinetic equation, including:

  • Checking if sources should be triggered at the current simulation step
  • Optionally upsampling the particle set (if enabled) before performing particle-mesh interpolation and grid-based operations
  • Transfering a fraction of the particle weights to the background distribution and updating particle weights (based on analytic or numerical background updates)
  • Computing or retrieving the total distribution f0_f
  • Applying each source routine sequentially (collisions, neutrals, heat and torque, anomalous diffusion, radiative cooling, pellets, current drive, etc.)
  • Recording the incremental distribution-function changes in f0_df0g and accumulating them in f0_df0g_cumul
  • Distributing the cumulative changes to particles to keep the grid and particle representations consistent
  • Calling relevant diagnostic routines as needed

If sources are not triggered, the function simply updates particle weights.

Key steps and notes:

  1. Upsampling (optional): If f0 upsampling is enabled, the particle set is resampled to reduce the error of mesh-particle interpolation.
  2. Particle-Weight Updates: Particle weights may be recalculated based on updated analytic background information or to ensure correct f0 matching.
  3. Collision Handling: For non-linear collisions, particle and distribution-function data are copied to/from the host if needed, since collisions can be memory-intensive.
  4. Moment Calculations: The function computes distribution-function moments (density, flow, temperature) on the grid, used by certain source routines.
  5. Incremental Changes: Each source routine (diffusion, collisions, neutrals, etc.) writes its changes into an incremental array (f0_df0g). These changes are then accumulated (in f0_df0g_cumul) and zeroed out (in f0_df0g) via accumulate_df0g_and_reset_to_zero.
  6. Diagnostics: Several diagnostics can be triggered, e.g., writing out f0, df, or monitoring the distribution-function changes at each stage.
  7. Performance & Parallelism: This routine relies on Kokkos parallel loops and GPTL timers for efficient execution and detailed performance measurement.
Template Parameters
DeviceTypeThe device (execution space) on which the simulation primarily runs.
Parameters
[in]smlTop-level simulation parameters and flags (time step, step count, upsampling flags, etc.).
[in]gridThe spatial grid object containing geometry, number of planes, and mapping information.
[in]magnetic_fieldAccess to magnetic-field geometry, used by certain sources and moment calculations.
[in,out]electric_fieldElectric field object, which can be modified by routines such as current-drive sources.
[in,out]pol_decompDomain decomposition information for poloidal planes (may be used in parallel loops or moment calculations).
[in]vgridVelocity-space grid (including resolution, bounds, and pseudo-inverse setup flags).
[in]chargesContains charge/mass information for different species.
[in,out]plasmaMain plasma container for all species; holds distribution functions, particle data, and moments.
[in,out]perturbed_B_fieldOptional container for perturbed magnetic fields used in certain advanced calculations (e.g., 3D modes).
[in]neutralsData structure holding neutral densities and reaction rates for neutral-particle recycling or atomic physics processes.
[in,out]sourcesControls which source terms (collisions, diffusion, neutral recycling, pellet injection, etc.) are active, along with their parameters.
[in,out]pseudo_inv_dmData manager for pseudo-inverse velocity mapping, needed for distributing f0 changes to particles correctly.
[in,out]diagnosticsManages diagnostic output for f0, df, distribution function moments, and other user-defined checks.
Returns
This function does not return a value; instead, it modifies the plasma state, updates diagnostic data, and manages distribution-function changes internally.
Note
  • Collisions (if enabled and executed on the device) trigger moving the particle data from the device to the host before execution due to high memory requirements.
  • The incremental distribution changes f0_df0g are always accumulated into f0_df0g_cumul before being distributed to the particle representation.
  • When sources are not triggered, only a minimal update (e.g., particle weights) is performed to remain consistent with potential background changes.

Here is the call graph for this function:

int get_resamp_tile_size ( )

Here is the caller graph for this function: