XGCa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Classes | Functions
velocity_interpolate.cpp File Reference
#include "gptl.h"
#include <Kokkos_Core.hpp>
#include "timer_macro.hpp"
#include "space_settings.hpp"
#include "globals.hpp"
#include "sml.hpp"
#include "plasma.hpp"
#include "grid.hpp"
#include "domain_decomposition.hpp"
#include "distribution.hpp"
#include "velocity_grid.hpp"
#include "quadratic_weights.hpp"
#include <petscversion.h>
#include <petscsys.h>
#include <petscdmplex.h>
#include <petscds.h>
#include "petscdmswarm.h"
#include "petscksp.h"
#include "velocity_interpolate.hpp"
Include dependency graph for velocity_interpolate.cpp:

Classes

struct  MatShellCtx
 

Functions

int force_pseudo_inv ()
 
int pseudo_inv_particles_to_grid_petsc ()
 
int pseudo_inv_delta_grid ()
 
static PetscErrorCode crd_func (PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nf_dummy, PetscScalar *u, void *actx)
 
PetscErrorCode MatMultMtM_SeqAIJ (Mat MtM, Vec xx, Vec yy)
 
PetscErrorCode MatMultAddMtM_SeqAIJ (Mat MtM, Vec xx, Vec yy, Vec zz)
 
PetscInt pseudo_inverse_interpolate_particles_to_velocity_grid (const DM &dm, Kokkos::View< PetscReal *, Kokkos::LayoutRight, Kokkos::HostSpace > particle_coords, Kokkos::View< PetscReal *, Kokkos::LayoutRight, Kokkos::HostSpace > particle_weights, const PetscInt Nparticles, PetscInt order, const PetscInt Nspecies, Kokkos::View< PetscReal *, Kokkos::LayoutRight, Kokkos::HostSpace > grid_coords, Kokkos::View< PetscReal *, Kokkos::LayoutRight, Kokkos::HostSpace > grid_weights)
 For description see source file. More...
 
PetscErrorCode pseudo_inv_create_Swarm (const DM dm, DM *sw)
 For description see source file. More...
 
PetscErrorCode pseudo_inv_create_projection (const DM dm, DM sw, const PetscInt thread_id, const PetscInt target_id, Kokkos::View< PetscReal *, Kokkos::LayoutRight, Kokkos::HostSpace > particle_coords, Kokkos::View< PetscReal *, Kokkos::LayoutRight, Kokkos::HostSpace > particle_weights, const PetscInt Nparticles, Vec rho, Mat *Mp_out)
 For description see source file. More...
 
PetscErrorCode pseudo_inv_set_rhs (const DM dm, Mat MM, Kokkos::View< PetscReal *, Kokkos::LayoutRight, Kokkos::HostSpace > grid_weights, const PetscInt Ngrid, Vec rho, Vec rhs)
 For description see source file. More...
 
PetscErrorCode pseudo_inv_grid_to_particles (const DM dm, DM sw, Vec rhs, Mat M_p, Mat PM_p, const PetscInt Ngrid, const PetscInt Nparticles, Kokkos::View< PetscReal *, Kokkos::LayoutRight, Kokkos::HostSpace > particle_weights, bool &ksp_converged)
 For description see source file. More...
 
void pseudo_inv_allocate (const Simulation< DeviceType > &sml, const Grid< DeviceType > &grid, const MagneticField< DeviceType > &magnetic_field, Plasma &plasma, const VelocityGrid &vgrid, const DomainDecomposition< DeviceType > &pol_decomp, Pseudo_inverse< DeviceType > &pseudo_inv)
 For description see source file. More...
 
void all_species_update_pseudo_inv_weights (const Simulation< DeviceType > &sml, const Grid< DeviceType > &grid, const MagneticField< DeviceType > &magnetic_field, Plasma &plasma, const VelocityGrid &vgrid, const DomainDecomposition< DeviceType > &pol_decomp, DMWrapper &pseudo_inv_dm, Pseudo_inverse< DeviceType > &pseudo_inv)
 
int max_n_ptl_on_node_and_vgrid_filled (const Simulation< DeviceType > &sml, const Grid< DeviceType > &grid, const MagneticField< DeviceType > &magnetic_field, Plasma &plasma, const VelocityGrid &vgrid, const DomainDecomposition< DeviceType > &pol_decomp, int n_non_adi_species, Kokkos::View< bool **, Kokkos::LayoutRight, DeviceType > vgrid_filled)
 < For description see source file More...
 

Detailed Description

1.0 A. Mollen, M. Adams, M. Knepley Apr 2022

DESCRIPTION

C++ functions for performing the particles -> velocity grid and velocity grid -> particles interpolation using a pseudo-inverse. This functionality needs PETSc 3.14 or above.

Function Documentation

void all_species_update_pseudo_inv_weights ( const Simulation< DeviceType > &  sml,
const Grid< DeviceType > &  grid,
const MagneticField< DeviceType > &  magnetic_field,
Plasma plasma,
const VelocityGrid vgrid,
const DomainDecomposition< DeviceType > &  pol_decomp,
DMWrapper pseudo_inv_dm,
Pseudo_inverse< DeviceType > &  pseudo_inv 
)

Update pseudo-inverse full weights (not alpha weights) of all non-adiabatic species.

Parameters
[in]smlcontains simulation control parameters
[in]gridspatial grid object
[in]magnetic_fieldmagnetic field object
[in]plasmaplasma object
[in]vgridcontains the velocity grid dimensions
[in]pol_decompcontains poloidal decomposition info
[in]pseudo_inv_dmpseudo-inverse mesh object
[in,out]pseudo_invpseudo-inverse object (contains pseudo-inverse arrays)
Returns
void

Here is the call graph for this function:

Here is the caller graph for this function:

static PetscErrorCode crd_func ( PetscInt  dim,
PetscReal  time,
const PetscReal  x[],
PetscInt  Nf_dummy,
PetscScalar *  u,
void *  actx 
)
static

Helper function for coordinates in PETSc.

Parameters
[in]dimDimension.
[in]timeTime.
[in]xInput vector.
[in]Nf_dummyDummy.
[out]uOutput vector.
[out]actx
Returns
PetscErrorCode

Here is the caller graph for this function:

int force_pseudo_inv ( )

Here is the caller graph for this function:

PetscErrorCode MatMultAddMtM_SeqAIJ ( Mat  MtM,
Vec  xx,
Vec  yy,
Vec  zz 
)

Helper function for pseudo_inv_grid_to_particles.

Parameters
[in]MtMPETSc shell matrix.
[in]xxPETSc vector.
[in]yyPETSc vector.
[out]zzPETSc vector.
Returns
PetscErrorCode

Here is the caller graph for this function:

PetscErrorCode MatMultMtM_SeqAIJ ( Mat  MtM,
Vec  xx,
Vec  yy 
)

Helper function for pseudo_inv_grid_to_particles.

Parameters
[in]MtMPETSc shell matrix.
[in]xxPETSc vector.
[out]yyPETSc vector.
Returns
PetscErrorCode

Here is the caller graph for this function:

int max_n_ptl_on_node_and_vgrid_filled ( const Simulation< DeviceType > &  sml,
const Grid< DeviceType > &  grid,
const MagneticField< DeviceType > &  magnetic_field,
Plasma plasma,
const VelocityGrid vgrid,
const DomainDecomposition< DeviceType > &  pol_decomp,
int  n_non_adi_species,
Kokkos::View< bool **, Kokkos::LayoutRight, DeviceType vgrid_filled 
)

< For description see source file

Obtain maximum number of particles on any mesh node for any non-adiabatic species and which nodes are filled in velocity space for all non-adiabatic species (used for pseudo-inverse memory allocation).

Parameters
[in]smlcontains simulation control parameters
[in]gridspatial grid object
[in]magnetic_fieldmagnetic field object
[in]plasmaplasma object
[in]vgridcontains the velocity grid dimensions
[in]pol_decompcontains poloidal decomposition info
[in]n_non_adi_speciesnumber of non-adiabatic species
[in,out]vgrid_filledempty velocity cells array (non-adiabatic species, node)
Returns
maximum number of particles on any mesh node for any non-adiabatic species

Here is the call graph for this function:

Here is the caller graph for this function:

void pseudo_inv_allocate ( const Simulation< DeviceType > &  sml,
const Grid< DeviceType > &  grid,
const MagneticField< DeviceType > &  magnetic_field,
Plasma plasma,
const VelocityGrid vgrid,
const DomainDecomposition< DeviceType > &  pol_decomp,
Pseudo_inverse< DeviceType > &  pseudo_inv 
)

For description see source file.

Set up and allocate pseudo-inverse object.

Parameters
[in]smlcontains simulation control parameters
[in]gridspatial grid object
[in]magnetic_fieldmagnetic field object
[in]plasmaplasma object
[in]vgridcontains the velocity grid dimensions
[in]pol_decompcontains poloidal decomposition info
[in,out]pseudo_invpseudo-inverse object (contains pseudo-inverse arrays)
Returns
void

Here is the call graph for this function:

Here is the caller graph for this function:

PetscErrorCode pseudo_inv_create_projection ( const DM  dm,
DM  sw,
const PetscInt  thread_id,
const PetscInt  target_id,
Kokkos::View< PetscReal *, Kokkos::LayoutRight, Kokkos::HostSpace >  particle_coords,
Kokkos::View< PetscReal *, Kokkos::LayoutRight, Kokkos::HostSpace >  particle_weights,
const PetscInt  Nparticles,
Vec  rho,
Mat *  Mp_out 
)

For description see source file.

Creates a PETSc projection matrix used for the pseudo-inverse velocity interpolation from particle coordinates and weights, based on the PETSc DM velocity grid object containing the velocity grid coordinates and the element (interpolation) order.

Parameters
[in]dmPETSc DM velocity grid object.
[in]swPETSc DM Swarm object.
[in]thread_idID of thread if using OpenMP.
[in]target_idID of thread for visualization if using OpenMP (normally not used, needs PETSc input flags).
[in]particle_coords2*Nparticles-sized array containing the particle coordinates.
[in]particle_weightsNparticles-sized array containing the particle weights.
[in]NparticlesNumber of particles being interpolated.
[out]rhoPETSc helper vector.
[out]Mp_outPETSc projection matrix created.
Returns
PetscErrorCode

Here is the caller graph for this function:

PetscErrorCode pseudo_inv_create_Swarm ( const DM  dm,
DM *  sw 
)

For description see source file.

Creates a PETSc DM Swarm object used for the pseudo-inverse velocity interpolation, based on the PETSc DM velocity grid object containing the velocity grid coordinates and the element (interpolation) order.

Parameters
[in]dmPETSc DM velocity grid object.
[out]swPETSc DM Swarm object created.
Returns
PetscErrorCode

Here is the caller graph for this function:

int pseudo_inv_delta_grid ( )

Here is the caller graph for this function:

PetscErrorCode pseudo_inv_grid_to_particles ( const DM  dm,
DM  sw,
Vec  rhs,
Mat  M_p,
Mat  PM_p,
const PetscInt  Ngrid,
const PetscInt  Nparticles,
Kokkos::View< PetscReal *, Kokkos::LayoutRight, Kokkos::HostSpace >  particle_weights,
bool &  ksp_converged 
)

For description see source file.

Performs the velocity grid -> particles interpolation by solving the linear system containing the pseudo-inverse and gives the updated particle weights, based on the PETSc DM velocity grid object containing the velocity grid coordinates and the element (interpolation) order.

Parameters
[in]dmPETSc DM velocity grid object.
[in]swPETSc DM Swarm object.
[in]rhsPETSc right-hand side vector.
[in]M_pPETSc projection matrix.
[in]PM_pPETSc preconditioner matrix.
[in]NgridNumber of velocity grid points.
[in]NparticlesNumber of particles being interpolated.
[out]particle_weightsNparticles-sized array containing the particle weights.
[out]ksp_convergedtrue if the pseudo-inverse calculation converged, otherwise false.
Returns
PetscErrorCode

Here is the call graph for this function:

Here is the caller graph for this function:

int pseudo_inv_particles_to_grid_petsc ( )

Here is the caller graph for this function:

PetscErrorCode pseudo_inv_set_rhs ( const DM  dm,
Mat  MM,
Kokkos::View< PetscReal *, Kokkos::LayoutRight, Kokkos::HostSpace >  grid_weights,
const PetscInt  Ngrid,
Vec  rho,
Vec  rhs 
)

For description see source file.

Sets the right-hand side used for the pseudo-inverse velocity interpolation from new grid weights, based on the PETSc DM velocity grid object containing the velocity grid coordinates and the element (interpolation) order.

Parameters
[in]dmPETSc DM velocity grid object.
[in]MMPETSc mass matrix velocity grid object.
[in]grid_weightsNgrid-sized array containing the new velocity grid weights.
[in]NgridNumber of velocity grid points.
[out]rhoPETSc helper vector.
[out]rhsPETSc right-hand side vector.
Returns
PetscErrorCode

Here is the caller graph for this function:

PetscInt pseudo_inverse_interpolate_particles_to_velocity_grid ( const DM &  dm,
Kokkos::View< PetscReal *, Kokkos::LayoutRight, Kokkos::HostSpace >  particle_coords,
Kokkos::View< PetscReal *, Kokkos::LayoutRight, Kokkos::HostSpace >  particle_weights,
const PetscInt  Nparticles,
PetscInt  order,
const PetscInt  Nspecies,
Kokkos::View< PetscReal *, Kokkos::LayoutRight, Kokkos::HostSpace >  grid_coords,
Kokkos::View< PetscReal *, Kokkos::LayoutRight, Kokkos::HostSpace >  grid_weights 
)

For description see source file.

Performs the particles -> velocity grid interpolation of marker particle weights to 2D velocity grid weights.

Parameters
[in]dmis the PETSc DM object created by initialize_pseudo_inverse_interpolation.
[in]particle_coordsis a 2*Nparticles-sized array containing the particle coordinates.
[in]particle_weightsis a Nparticles-sized array containing the particle weights.
[in]Nparticlesis the number of particles being interpolated.
[in]orderis the interpolation order (1 = linear), (2 = quadratic).
[in]Nspeciesis the number of species being interpolated, typically 1.
[in,out]grid_coordsis a 2*NGridPoints-sized array containing the velocity grid coordinates.
[in,out]grid_weightsis a NGridPoints-sized array containing the velocity grid weights.
Returns
the number of grid points.

Here is the call graph for this function:

Here is the caller graph for this function: