XGCa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Private Attributes | List of all members
Diffusion Class Reference

Implements an anomalous transport (advection-diffusion) model for the kinetic electrons in the plasma simulation. More...

#include <diffusion.hpp>

Inheritance diagram for Diffusion:
Inheritance graph
[legend]
Collaboration diagram for Diffusion:
Collaboration graph
[legend]

Public Member Functions

bool is_triggered_update (int step) const
 Determines whether the update of the diffusion coefficients should be executed on the given step. More...
 
int trigger_count_update (int step) const
 Calculates how many times the update of the diffusion coefficient has been executed up to the given step. More...
 
 Diffusion ()
 Default constructor. Creates an uninitialized Diffusion object. More...
 
 Diffusion (NLReader::NamelistReader &nlr, const MagneticField< DeviceType > &magnetic_field, const Grid< DeviceType > &grid)
 
void init (NLReader::NamelistReader &nlr, const MagneticField< DeviceType > &magnetic_field, const Grid< DeviceType > &grid)
 Constructs a Diffusion object by reading diffusion-related parameters from the namelist. More...
 
void apply (const Simulation< DeviceType > &sml, const Grid< DeviceType > &grid, const MagneticField< DeviceType > &magnetic_field, ElectricField< DeviceType > &electric_field, const DomainDecomposition< DeviceType > &pol_decomp, const VelocityGrid &vgrid, Plasma &plasma, Smoothing &smoothing, DiagF0DF &diag_f0_df, const Moments &moments, const VGridDistribution< DeviceType > &f0_f, VGridDistribution< HostType > &f0_df0g, double dt)
 
void update (const Plasma &plasma, const DomainDecomposition< DeviceType > &pol_decomp, const Grid< DeviceType > &grid)
 Updates the diffusion coefficients from an input BP file and passes the data to a Fortran routine. More...
 
- Public Member Functions inherited from Source
bool is_triggered (int step)
 

Private Attributes

double inner_psi_bound
 Inner boundary for diffusion in terms of normalized poloidal flux. More...
 
double outer_psi_bound
 Outer boundary for diffusion in terms of normalized poloidal flux. More...
 
Boundary bndry
 Boundary object for handling domain exclusion regions; now a member variable for later reuse. More...
 
bool use_smoothing
 Whether to smooth the fluid moments before solving the transport equations. More...
 
bool update_on
 Switch for periodic updates of the diffusion coefficients. More...
 
StepTrigger step_trigger_update
 Triggers when it is time to update the diffusion coefficients. More...
 
XGC_IO_Stream diffusion_update_stream
 Adios stream used for reading the updated diffusion coefficients. More...
 

Additional Inherited Members

- Public Attributes inherited from Source
StepTrigger step_trigger
 

Detailed Description

Implements an anomalous transport (advection-diffusion) model for the kinetic electrons in the plasma simulation.

This class extends the generic Source interface, providing functionality to apply an anomalous diffusion source term during the kinetic equation update. It sets diffusion boundaries based on poloidal flux surfaces and initializes a boundary mask for the domain.

Typical usage:

  1. Construct a Diffusion object from a namelist and the necessary grid/magnetic-field data.
  2. Call apply() at each time step (or when triggered) to modify the distribution function.

Example:

Grid<DeviceType> grid(...);
Diffusion diff(nlr, magField, grid);
...
diff.apply(...);

Constructor & Destructor Documentation

Diffusion::Diffusion ( )
inline

Default constructor. Creates an uninitialized Diffusion object.

This default constructor does not set any boundary conditions or read from the namelist. It is primarily intended for creating an object that will be assigned or initialized later.

Diffusion::Diffusion ( NLReader::NamelistReader nlr,
const MagneticField< DeviceType > &  magnetic_field,
const Grid< DeviceType > &  grid 
)

Here is the call graph for this function:

Member Function Documentation

void Diffusion::apply ( const Simulation< DeviceType > &  sml,
const Grid< DeviceType > &  grid,
const MagneticField< DeviceType > &  magnetic_field,
ElectricField< DeviceType > &  electric_field,
const DomainDecomposition< DeviceType > &  pol_decomp,
const VelocityGrid vgrid,
Plasma plasma,
Smoothing smoothing,
DiagF0DF diag_f0_df,
const Moments moments_h,
const VGridDistribution< DeviceType > &  f0_f,
VGridDistribution< HostType > &  f0_df0g_h,
double  dt 
)

Calls the diffusion timestepper. The solve uses PETSc and the setup for that is still in Fortran.

Parameters
[in]smlSimulation parameters
[in]gridThe grid object
[in]magnetic_fieldThe magnetic field object
[in]electric_fieldUsed for dpot to remove adiabatic response
[in]pol_decompThe domain decomposition
[in]velocity_gridVelocity grid
[in,out]plasmaPlasma object. f0_delta_n/u/T are updated
[in]moments_hMoments
[in]f0_fThe part of the distribution function represented on the velocity grid
[in,out]f0_df0g_hThe change to the distribution function
[in]dtThe time step return View marking whether each mesh node is in bounds

Here is the call graph for this function:

Here is the caller graph for this function:

void Diffusion::init ( NLReader::NamelistReader nlr,
const MagneticField< DeviceType > &  magnetic_field,
const Grid< DeviceType > &  grid 
)

Constructs a Diffusion object by reading diffusion-related parameters from the namelist.

This constructor reads in electron settings (to verify that electrons are kinetic), boundary flux values for the diffusion model, and other solver-related parameters (e.g., start time) from the specified namelist reader. It then creates a Boundary object to handle domain exclusion regions and calls an external Fortran routine initialize_diffusion() to set up the diffusion mask.

Parameters
[in,out]nlrNamelist reader from which diffusion parameters and other simulation controls are retrieved.
[in]magnetic_fieldProvides poloidal-flux normalization factors (psi_norm) and in/out flux boundaries required for setting up the diffusion domain.
[in]gridThe spatial grid defining the geometry of the problem; includes node information needed to map boundary settings to the correct domain regions.
Note
  • If sml_electron_on is false, the constructor will terminate the code via exit_XGC(), since anomalous diffusion requires kinetic electrons.
  • The constructor uses multiple namelists: first sml_param to verify that electrons are on, then diff_param to read specific diffusion boundaries and timing parameters.
  • The boundary settings constructed here are subsequently used within initialize_diffusion() to exclude regions (e.g., near-wall, private flux).

< Outer boundary (for Poisson solver), normalized poloidal flux

< Outer boundary (for Poisson solver, 2nd private region), normalized poloidal flux

< To move the outer boundary of the Poisson solver away from the inner wall (in m)

< Start time (in time steps) for anomalous diffusion

< Switch for periodic updates of the diffusion coefficients

< Period in time steps between subsequent updates of the diffusion coefficients

Here is the call graph for this function:

Here is the caller graph for this function:

bool Diffusion::is_triggered_update ( int  step) const
inline

Determines whether the update of the diffusion coefficients should be executed on the given step.

This function checks the trigger associated with updating the diffusion coefficients.

Parameters
stepThe current step number.
Returns
True if the trigger condition is met for the given step, false otherwise.

Here is the call graph for this function:

Here is the caller graph for this function:

int Diffusion::trigger_count_update ( int  step) const
inline

Calculates how many times the update of the diffusion coefficient has been executed up to the given step.

This function calculates how many times the function updating the diffusion coefficients has been called up to the given time step, taking into account the start time and whether the update functionality is active.

Parameters
stepThe current time step index.
Returns
The number of times the diffusivity update has been triggered.

Here is the call graph for this function:

void Diffusion::update ( const Plasma plasma,
const DomainDecomposition< DeviceType > &  pol_decomp,
const Grid< DeviceType > &  grid 
)

Updates the diffusion coefficients from an input BP file and passes the data to a Fortran routine.

This function uses the C++ routine ReadSpeciesData to read updated diffusion coefficient data from the specified BP file. The data consists of a common 1D array (x) and a 3D array (y) with dimensions [4, n_species, N] corresponding to four different diffusion coefficient types for each species. The routine then calls the Fortran routine update_diffusion_eq_ftn, passing pointers to the x and y data, as well as the number of species.

Parameters
input_filenameThe name of the input BP file containing updated diffusion coefficients.
n_speciesThe number of particle species.
Exceptions
std::runtime_errorif reading the diffusion coefficient data fails.

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

Boundary Diffusion::bndry
private

Boundary object for handling domain exclusion regions; now a member variable for later reuse.

XGC_IO_Stream Diffusion::diffusion_update_stream
private

Adios stream used for reading the updated diffusion coefficients.

double Diffusion::inner_psi_bound
private

Inner boundary for diffusion in terms of normalized poloidal flux.

double Diffusion::outer_psi_bound
private

Outer boundary for diffusion in terms of normalized poloidal flux.

StepTrigger Diffusion::step_trigger_update
private

Triggers when it is time to update the diffusion coefficients.

bool Diffusion::update_on
private

Switch for periodic updates of the diffusion coefficients.

bool Diffusion::use_smoothing
private

Whether to smooth the fluid moments before solving the transport equations.


The documentation for this class was generated from the following files: