| XGC1
    | 
#include <Kokkos_Core.hpp>#include "space_settings.hpp"#include "sml.hpp"#include "plasma.hpp"#include "DM_wrapper.hpp"#include <petscversion.h>#include <petscsys.h>#include <petscdmplex.h>#include <petscds.h>#include "petscdmswarm.h"#include "petscksp.h"

Go to the source code of this file.
| Classes | |
| struct | PseudoInversePetscObjects | 
| class | Pseudo_inverse< Device > | 
| For description see source file.  More... | |
| Functions | |
| 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, 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, const PetscInt order, Kokkos::View< PetscReal *, Kokkos::LayoutRight, Kokkos::HostSpace > particle_weights, int &ksp_num_its, bool &ksp_converged) | 
| 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) | 
| For description see source file.  More... | |
| 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, const std::string &msg, Kokkos::View< bool **, Kokkos::LayoutRight, DeviceType > vgrid_filled) | 
| template<class Device > | |
| KOKKOS_INLINE_FUNCTION bool | pseudo_inv_do_node (const Pseudo_inverse< Device > &pseudo_inv, int isp_non_ad, int node) | 
| bool | pseudo_inv_do_node_h (Pseudo_inverse< DeviceType > &pseudo_inv, int isp_non_ad, int node) | 
@Version 1.0 @Authors A. Mollen, M. Adams, M. Knepley @Date Last update Oct 2023
Header file to pseudo_inverse.cpp. Also contains the Pseudo_inverse class which stores arrays to perform the pseudo-inverse mapping.
| 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 | ||
| ) | 
For description see source file.
Update pseudo-inverse full weights (not alpha weights) of all non-adiabatic species.
| [in] | sml | contains simulation control parameters | 
| [in] | grid | spatial grid object | 
| [in] | magnetic_field | magnetic field object | 
| [in] | plasma | plasma object | 
| [in] | vgrid | contains the velocity grid dimensions | 
| [in] | pol_decomp | contains poloidal decomposition info | 
| [in] | pseudo_inv_dm | pseudo-inverse mesh object | 
| [in,out] | pseudo_inv | pseudo-inverse object (contains pseudo-inverse arrays) | 


| 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, | ||
| const std::string & | msg, | ||
| Kokkos::View< bool **, Kokkos::LayoutRight, DeviceType > | vgrid_filled | ||
| ) | 
Obtain maximum number of particles (for any non-adiabatic species) on any 3D real-space mesh node in each plane, and which of the nodes are filled in velocity space (i.e. all velocity cells have enough particles) for all non-adiabatic species (used for the pseudo-inverse allocation and calculation). A node is filled for element order Q (= 0 for nearest neighbor, = 1 for linear, = 2 for quadratic, = 3 for cubic, ...) if all QxQ velocity cells have at least Q^2 particles and the corner cells at least Q*(Q + 1) particles.
| [in] | sml | contains simulation control parameters | 
| [in] | grid | spatial grid object | 
| [in] | magnetic_field | magnetic field object | 
| [in] | plasma | plasma object | 
| [in] | vgrid | contains the velocity grid dimensions | 
| [in] | pol_decomp | contains poloidal decomposition info | 
| [in] | msg | message printed to the log in combination with statistics | 
| [in,out] | vgrid_filled | empty velocity cells array (non-adiabatic species, node) | 


| 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
For description see source file
Set up and allocate pseudo-inverse object.
| [in] | sml | contains simulation control parameters | 
| [in] | grid | spatial grid object | 
| [in] | magnetic_field | magnetic field object | 
| [in] | plasma | plasma object | 
| [in] | vgrid | contains the velocity grid dimensions | 
| [in] | pol_decomp | contains poloidal decomposition info | 
| [in,out] | pseudo_inv | pseudo-inverse object (contains pseudo-inverse arrays) | 


| 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.
| [in] | dm | PETSc DM velocity grid object. | 
| [in] | sw | PETSc DM Swarm object. | 
| [in] | thread_id | ID of thread if using OpenMP. | 
| [in] | target_id | ID of thread for visualization if using OpenMP (normally not used, needs PETSc input flags). | 
| [in] | particle_coords | 2*Nparticles-sized array containing the particle coordinates. | 
| [in] | particle_weights | Nparticles-sized array containing the particle weights. | 
| [in] | Nparticles | Number of particles being interpolated. | 
| [out] | rho | PETSc helper vector. | 
| [out] | Mp_out | PETSc projection matrix created. | 

| 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.
| [in] | dm | PETSc DM velocity grid object. | 
| [out] | sw | PETSc DM Swarm object created. | 

| KOKKOS_INLINE_FUNCTION bool pseudo_inv_do_node | ( | const Pseudo_inverse< Device > & | pseudo_inv, | 
| int | isp_non_ad, | ||
| int | node | ||
| ) | 

| 
 | inline | 

| 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, | ||
| const PetscInt | order, | ||
| Kokkos::View< PetscReal *, Kokkos::LayoutRight, Kokkos::HostSpace > | particle_weights, | ||
| int & | ksp_num_its, | ||
| bool & | ksp_converged | ||
| ) | 
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.
| [in] | dm | PETSc DM velocity grid object. | 
| [in] | sw | PETSc DM Swarm object. | 
| [in] | rhs | PETSc right-hand side vector. | 
| [in] | M_p | PETSc projection matrix. | 
| [in] | PM_p | PETSc preconditioner matrix. | 
| [in] | Ngrid | Number of velocity grid points. | 
| [in] | Nparticles | Number of particles being interpolated. | 
| [in] | order | The interpolation order (>= 0). (dm already contains the order but used in check of nonsingular matrix.) | 
| [out] | particle_weights | Nparticles-sized array containing the particle weights. | 
| [out] | ksp_num_its | Number of iterations for linear solver in PETSc. | 
| [out] | ksp_converged | true if the pseudo-inverse calculation converged, otherwise false. | 


| 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.
| [in] | dm | PETSc DM velocity grid object. | 
| [in] | MM | PETSc mass matrix velocity grid object. | 
| [in] | grid_weights | Ngrid-sized array containing the new velocity grid weights. | 
| [in] | Ngrid | Number of velocity grid points. | 
| [out] | rho | PETSc helper vector. | 
| [out] | rhs | PETSc right-hand side vector. | 

| 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, | ||
| 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.
| [in] | dm | is the PETSc DM object containing the velocity grid coordinates and the element (interpolation) order (created by initialize_pseudo_inverse_interpolation). | 
| [in] | particle_coords | is a 2*Nparticles-sized array containing the particle coordinates. | 
| [in] | particle_weights | is a Nparticles-sized array containing the particle weights. | 
| [in] | Nparticles | is the number of particles being interpolated. | 
| [in] | Nspecies | is the number of species being interpolated, typically 1. | 
| [in,out] | grid_coords | is a 2*NGridPoints-sized array containing the velocity grid coordinates. | 
| [in,out] | grid_weights | is a NGridPoints-sized array containing the velocity grid weights. | 

