XGC1
Functions/Subroutines
petsc_solver_module Module Reference

Functions/Subroutines

subroutine petsc_get_sizes (grid, bc, n_equation, n_boundary, xgc_petsc, petsc_xgc_bd)
 Calculate (i) the number of equations (vertices) of the solver, (ii) the number of XGC boundary vertices included in the solver, (iii) (preliminary) mapping from XGC vertices to PETSc equations, (iv) mapping from XGC vertices to PETSc boundary conditions, all based the XGC boundary object passed as input. More...
 
subroutine petsc_get_bd_map (grid, bc, n_boundary, petsc_xgc_bd, petsc_bd_xgc)
 Generate mapping from PETSc boundary conditions to XGC vertices. This requires the results of petsc_get_sizes because the number of boundary conditions is not known a priori. More...
 
subroutine getnnz (grid, nloc, low, high, d_nnz, o_nnz, xgc_petsc, nglobal, ierr)
 Computes the number of non-zero entries nnz per row in the rank-local rows. More...
 
subroutine petsc_get_partitioning (grid, bc, b_factors, comm, num_pe, n_eq_tot_in, set_diffusion_matrix, xgc_petsc, petsc_xgc_bd, n_eq_loc, xgc_proc_out, proc_eq, ierr)
 Generates a domain partitioning of part of the XGC mesh used by a solver (as defined by the boundary conditions bc) using Parmetis and generates a mapping between PETSc equation index and XGC MPI ranks (those in the communicator comm used by the solver). More...
 
subroutine petsc_get_mapping (nnode, bc, comm, num_pe, n_eq_tot, n_eq_loc, xgc_proc, proc_eq, xgc_petsc, petsc_xgc, petscloc_xgc)
 Based on the Parmetis partition of the XGC domain, updates the mappings between XGC vertices and PETSc equations. More...
 
subroutine petsc_get_template_mat (grid, comm, n_eq_tot, n_eq_loc, xgc_petsc, solver_template_mat, ierr)
 Uses pre-computed (petsc_get_partitioning) local matrix sizes and XGC vertex to PETSc equation mapping to set up a blank template matrix with sufficient pre-allocated memory. More...
 
subroutine petsc_get_scatter_multi_block (nnode, ksp, mat_all_blocks, mat_one_block, blocksize, varnames, n_eq_tot, n_eq_loc, petscloc_xgc, petsc_xgc, iss, to_petsc, from_petsc, ierr)
 Sets up a PETSc scatter object for a (2D) multi-block field-split solver. More...
 
subroutine petsc_to_xgc (nnode, blocksize, from_petsc, field_petsc, field_xgc, ierr)
 This routine scatters values from the distributed vector compatible with the block-matrix of the 2D diffusion model to local variables on the XGC solver grid. More...
 
subroutine xgc_to_petsc (nnode, blocksize, to_petsc, field_petsc, field_xgc, ierr)
 This routine scatters values from local variable on the XGC solver grid to the distributed vector compatible with the block-matrix of the 2D diffusion model. More...
 
subroutine diffusion_matrix_init (diffusion_ts, grid, bc, solver_template_mat, ierr)
 Set up a template matrix for XGC's anomalous diffusion time integrator. This is currently a system of either 4 (adiabatic electrons) or 7 (kinetic electrons) equations. Impurities are not supported yet. More...
 

Function/Subroutine Documentation

◆ diffusion_matrix_init()

subroutine petsc_solver_module::diffusion_matrix_init ( type(xgc_ts diffusion_ts,
type(grid_type), intent(in)  grid,
integer, dimension(grid%nnode), intent(in)  bc,
intent(out)  solver_template_mat,
  ierr 
)

Set up a template matrix for XGC's anomalous diffusion time integrator. This is currently a system of either 4 (adiabatic electrons) or 7 (kinetic electrons) equations. Impurities are not supported yet.

Parameters
[in,out]diffusion_tsPETSc time integrator object (TS) for the diffusion solver
[in]gridXGC grid object, type(grid_type)
[in]bcSolver boundary mask, 1 if not in boundary vertex list
[out]solver_template_matPETSc matrix with the template for the anomalous diffusion solver
[out]ierrPETSc error code.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getnnz()

subroutine petsc_solver_module::getnnz ( type(grid_type), intent(in)  grid,
  nloc,
  low,
  high,
  d_nnz,
  o_nnz,
dimension(grid%nnode), intent(in)  xgc_petsc,
  nglobal,
  ierr 
)

Computes the number of non-zero entries nnz per row in the rank-local rows.

Parameters
[in]gridXGC grid object, type(grid_type)
[in]nlocNumber of equations on this rank, PetscInt
[in]lowGlobal index of the first equation on this rank, PetscInt
[in]highGlobal index of the last equation on this rank, PetscInt
[out]d_nnzNumber of non-zero entries in "diagonal" local part of the matrix
[out]o_nnzNumber of non-zero entries in the "off-diagnonal" local part of the matrix.
[in]xgc_petscMapping between XGC grid vertices and PETSc equations
[in]nglobalTotal number of equations, PetscInt
[in]ierrPETSc error code
Here is the caller graph for this function:

◆ petsc_get_bd_map()

subroutine petsc_solver_module::petsc_get_bd_map ( type(grid_type), intent(in)  grid,
integer, dimension(grid%nnode), intent(in)  bc,
intent(in)  n_boundary,
dimension(grid%nnode), intent(in)  petsc_xgc_bd,
dimension(n_boundary), intent(out)  petsc_bd_xgc 
)

Generate mapping from PETSc boundary conditions to XGC vertices. This requires the results of petsc_get_sizes because the number of boundary conditions is not known a priori.

Parameters
[in]gridXGC solver mesh, type(grid_type)
[in]bcSolver boundary mask, 1 if not in boundary vertex list
[in]n_boundaryNumber of boundary values, PetscInt
[in]petsc_xgc_bdMapping from XGC vertices to PETSc boundary conditions
[out]petsc_bd_xgcMapping fron PETSc boundary conditions to XGC vertices
Here is the caller graph for this function:

◆ petsc_get_mapping()

subroutine petsc_solver_module::petsc_get_mapping ( integer, intent(in)  nnode,
integer, dimension(nnode), intent(in)  bc,
integer, intent(in)  comm,
integer, intent(in)  num_pe,
intent(in)  n_eq_tot,
intent(in)  n_eq_loc,
dimension(n_eq_tot), intent(in)  xgc_proc,
dimension(0:num_pe), intent(inout)  proc_eq,
dimension(nnode), intent(out)  xgc_petsc,
dimension(n_eq_tot), intent(out)  petsc_xgc,
dimension(n_eq_loc), intent(out)  petscloc_xgc 
)

Based on the Parmetis partition of the XGC domain, updates the mappings between XGC vertices and PETSc equations.

Parameters
[in]nnodeNumber of XGC vertices, integer
[in]bcSolver boundary mask, 1 if not in boundary vertex list
[in]commMPI comunicator for distributed matrix solver, MPI_comm
[in]n_eq_totTotal number of PETSc equations, PetscInt
[in]n_eq_locLocal number of equations on the current rank, PetscInt
[in]xgc_procMapping from equation index to XGC rank, PetscInt
[in]proc_eqMapping from XGC process to PETSc equation, integer
[out]xgc_petscMapping from XGC vertices to PETSc equation, integer
[out]petsc_xgcMapping from PETSc equation index to XGC vertices, integer
[out]petscloc_xgcMapping from local PETSc eq. to XGC vertices, integer
Here is the caller graph for this function:

◆ petsc_get_partitioning()

subroutine petsc_solver_module::petsc_get_partitioning ( type(grid_type), intent(in)  grid,
integer, dimension(grid%nnode), intent(in)  bc,
real(kind=8), dimension(grid%ntriangle, 6), intent(in)  b_factors,
integer, intent(in)  comm,
integer, intent(in)  num_pe,
intent(in)  n_eq_tot_in,
logical, intent(in)  set_diffusion_matrix,
dimension(grid%nnode), intent(in)  xgc_petsc,
dimension(grid%nnode), intent(in)  petsc_xgc_bd,
intent(out)  n_eq_loc,
dimension(n_eq_tot_in), intent(out)  xgc_proc_out,
dimension(0:num_pe), intent(out)  proc_eq,
intent(out)  ierr 
)

Generates a domain partitioning of part of the XGC mesh used by a solver (as defined by the boundary conditions bc) using Parmetis and generates a mapping between PETSc equation index and XGC MPI ranks (those in the communicator comm used by the solver).

Parameters
[in]gridXGC solver mesh, type(grid_type)
[in]bcSolver boundary mask, 1 if not in boundary vertex list
[in]commMPI communicator used by the solver, integer
[in]num_peNumber of MPI ranks in communicator comm, integer
[in]n_eq_tot_inTotal number of equations (i.e. number of vertices in the solver), PetscInt
[in]set_diffusion_matrixWhether to set diffusion or Poisson/Ampere matrix
[out]n_eq_locNumber of equations on the current rank, PetscInt
[out]xgc_procMapping from PETSc equation to XGC rank, PetscInt
[out]proc_eqMapping from XGC_process to PETSc equation number (in form of the boundaries of the domain partitioning)
[out]ierrError code
Here is the call graph for this function:
Here is the caller graph for this function:

◆ petsc_get_scatter_multi_block()

subroutine petsc_solver_module::petsc_get_scatter_multi_block ( integer, intent(in)  nnode,
intent(in)  ksp,
  mat_all_blocks,
  mat_one_block,
intent(in)  blocksize,
character(*), dimension(0:blocksize-1), intent(in)  varnames,
intent(in)  n_eq_tot,
intent(in)  n_eq_loc,
dimension(n_eq_loc), intent(in)  petscloc_xgc,
dimension(n_eq_tot), intent(in)  petsc_xgc,
  iss,
  to_petsc,
  from_petsc,
intent(out)  ierr 
)

Sets up a PETSc scatter object for a (2D) multi-block field-split solver.

Parameters
[in]nnodeNumber of XGC mesh vertices
[in]kspPETSc Krylov sub-space solver object, KSP
[in]mat_all_blocksGlobal matrix with all solver blocks, Mat
[in]mat_one_blockMatrix of one single block, Mat
[in]blocksizeNumber of blocks, PetscInt
[in]varnamesNames of the variables represented by each block, char
[in]n_eq_totNumber of equations in one block, PetscInt
[in]n_eq_locNumber of local equations in one block, PetscInt
[in]petscloc_xgcRank-local mapping from PETSc equations to XGC vertices, PetscInt
[in]petsc_xgcGlobal mapping from PETSc equations to XGC vertices, PetscInt
[out]issIndex sets for mapping single blocks into the global matrix, IS
[out]from_petscVecScatter object for scattering PETSc results to an XGC field, VecScatter
[out]to_petscVecScatter object for scattering XGC vectors into the global PETSc block matrix
[out]ierrPETSc error code, PetscErrorCode
Here is the caller graph for this function:

◆ petsc_get_sizes()

subroutine petsc_solver_module::petsc_get_sizes ( type(grid_type), intent(in)  grid,
integer, dimension(grid%nnode), intent(in)  bc,
intent(out)  n_equation,
intent(out)  n_boundary,
dimension(grid%nnode), intent(out)  xgc_petsc,
dimension(grid%nnode), intent(out)  petsc_xgc_bd 
)

Calculate (i) the number of equations (vertices) of the solver, (ii) the number of XGC boundary vertices included in the solver, (iii) (preliminary) mapping from XGC vertices to PETSc equations, (iv) mapping from XGC vertices to PETSc boundary conditions, all based the XGC boundary object passed as input.

Parameters
[in]gridXGC solver mesh, type(grid_type)
[in]bcSolver boundary mask, 1 if not in boundary vertex list
[out]n_equationNumber of PETSc equations (matrix rows), integer
[out]n_boundaryNumber of boundary conditions/vertices, integer
[out]xgc_petsc(Preliminary) mapping from XGC vertices to PETSc equations
[out]petsc_xgc_bdMapping from XGC vertices to PETSc boundary conditions
Here is the caller graph for this function:

◆ petsc_get_template_mat()

subroutine petsc_solver_module::petsc_get_template_mat ( type(grid_type), intent(in)  grid,
integer, intent(in)  comm,
intent(in)  n_eq_tot,
intent(in)  n_eq_loc,
dimension(grid%nnode), intent(in)  xgc_petsc,
intent(out)  solver_template_mat,
  ierr 
)

Uses pre-computed (petsc_get_partitioning) local matrix sizes and XGC vertex to PETSc equation mapping to set up a blank template matrix with sufficient pre-allocated memory.

Parameters
[in]gridXGC grid object, type(grid_type)
[in]commMPI communicator for template matrix, MPI_comm
[in]n_eq_totTotal number of equations, PetscInt
[in]n_eq_locNumber of local equations on the current rank, PetscInt
[in]xgc_petscMapping from XGC vertices to PETSc equation index
[out]solver_template_matTemplate matrix with the desired partitioning and sufficient preallocated memory.
[out]ierrError code
Here is the call graph for this function:
Here is the caller graph for this function:

◆ petsc_to_xgc()

subroutine petsc_solver_module::petsc_to_xgc ( intent(in)  nnode,
intent(in)  blocksize,
dimension(0:blocksize-1), intent(in)  from_petsc,
intent(in)  field_petsc,
real (kind=8), dimension(nnode,blocksize), intent(inout)  field_xgc,
intent(out)  ierr 
)

This routine scatters values from the distributed vector compatible with the block-matrix of the 2D diffusion model to local variables on the XGC solver grid.

Parameters
[in]nnodeNumber of vertices per plane in XGC mesh, PetscInt
[in]blocksizeNumber of equations, PetscInt
[in]from_petscVecScatter object for moving data from PETSc Vec to XGC mesh data, VecScatter
[in]field_petscPETSc vector with the data to be scattered, PETSc Vec
[in,out]field_xgcXGC mesh array to which data is scattered, real8
[out]ierrError code, PetscErrorCode
Here is the caller graph for this function:

◆ xgc_to_petsc()

subroutine petsc_solver_module::xgc_to_petsc ( intent(in)  nnode,
intent(in)  blocksize,
dimension(0:blocksize-1), intent(in)  to_petsc,
  field_petsc,
real (kind=8), dimension(nnode,blocksize), intent(in)  field_xgc,
intent(out)  ierr 
)

This routine scatters values from local variable on the XGC solver grid to the distributed vector compatible with the block-matrix of the 2D diffusion model.

Parameters
[in]nnodeNumber of vertices per plane in XGC mesh, PetscInt
[in]blocksizeNumber of equations, PetscInt
[in]from_petscVecScatter object for moving data from PETSc Vec to XGC mesh data, VecScatter
[in]field_petscPETSc vector with the data to be scattered, PETSc Vec
[in,out]field_xgcXGC mesh array to which data is scattered, real8
[out]ierrError code, PetscErrorCode
Here is the caller graph for this function: