XGCa
|
#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 "lagrange_weights.hpp"
#include <petscversion.h>
#include <petscsys.h>
#include <petscdmplex.h>
#include <petscds.h>
#include "petscdmswarm.h"
#include "petscksp.h"
#include "pseudo_inverse.hpp"
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, 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) |
1.0 A. Mollen, M. Adams, M. Knepley Last update Oct 2023
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.
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) |
|
static |
Helper function for coordinates in PETSc.
[in] | dim | Dimension. |
[in] | time | Time. |
[in] | x | Input vector. |
[in] | Nf_dummy | Dummy. |
[out] | u | Output vector. |
[out] | actx |
int force_pseudo_inv | ( | ) |
PetscErrorCode MatMultAddMtM_SeqAIJ | ( | Mat | MtM, |
Vec | xx, | ||
Vec | yy, | ||
Vec | zz | ||
) |
Helper function for pseudo_inv_grid_to_particles.
[in] | MtM | PETSc shell matrix. |
[in] | xx | PETSc vector. |
[in] | yy | PETSc vector. |
[out] | zz | PETSc vector. |
PetscErrorCode MatMultMtM_SeqAIJ | ( | Mat | MtM, |
Vec | xx, | ||
Vec | yy | ||
) |
Helper function for pseudo_inv_grid_to_particles.
[in] | MtM | PETSc shell matrix. |
[in] | xx | PETSc vector. |
[out] | yy | PETSc vector. |
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
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. |
int pseudo_inv_delta_grid | ( | ) |
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. |
int pseudo_inv_particles_to_grid_petsc | ( | ) |
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. |