This is an example thorn describing how to use the TATPETSc interface to PETSc. It solves the Poisson equation for a spherical charge distribution on a uniform grid.
PETSc is a well-known library for solving elliptic equations. TATPETSc is a Cactus thorn that provides a wrapper for calling PETSc to solve elliptic equations on uniform grids. (TATPETSc currently supports neither mesh refinement nor multi-block systems.) TATPETSc can solve both linear and non-linear systems.
Here we solve the Poisson equation
where the right hand side \(\rho \) is given by
for the charge \(Q\) and the radius \(R\), with \(V=4\pi R^3/3\). We use Dirichlet boundary conditions \(\Phi (x)=0\).
PETSc supports a large number of options to choose solvers. Here we use PETSc’s default settings.
In the example parameter file, we set the parameter TATPETSc::options to select the following PETSc options:
-snes_atol 1e-8: set absolute tolerance for residual
-snes_stol 1e-8: set relative tolerance for residual
-snes_monitor: output progress information at each iteration of the non-linear solver
-ksp_monitor: output progress information at each iteration of the linear (Krylov subspace) solver
The solution (the potential \(\Phi (x)\)) is stored in the grid function potential, the residual (a measure for the error) in the grid function residual.
charge | Scope: private | REAL |
Description: Charge of uniformly charged sphere
| ||
Range | Default: 1.0 | |
*:* | ||
options | Scope: private | STRING |
Description: Options for the solver
| ||
Range | Default: (none) | |
.* | no restriction
| |
radius | Scope: private | REAL |
Description: Radius of uniformly charged sphere
| ||
Range | Default: 1.0 | |
0:* | ||
solver | Scope: private | STRING |
Description: Name of TATelliptic solver that should be used
| ||
Range | Default: TATJacobi | |
.* | must be an activated TATelliptic solver
| |
Implements:
poisson
Inherits:
boundary
grid
Group Names | Variable Names | Details | |
potential | compact | 0 | |
phi | description | Potential for elliptic equation | |
dimensions | 3 | ||
distribution | DEFAULT | ||
group type | GF | ||
timelevels | 1 | ||
variable type | REAL | ||
residual | compact | 0 | |
res | description | Residual for elliptic equation | |
dimensions | 3 | ||
distribution | DEFAULT | ||
group type | GF | ||
timelevels | 1 | ||
variable type | REAL | ||
Uses header:
carpet.h
TATelliptic.h
This section lists all the variables which are assigned storage by thorn CactusExamples/Poisson. Storage can either last for the duration of the run (Always means that if this thorn is activated storage will be assigned, Conditional means that if this thorn is activated storage will be assigned for the duration of the run if some condition is met), or can be turned on for the duration of a schedule function.
Always: | |
potential residual | |
CCTK_INITIAL
poisson_prepare
set up initial guess for initial data
Language: | c | |
Type: | function | |
Writes: | poisson::phi(everywhere) | |
CCTK_POSTINITIAL
poisson_solve
calculate uniform charge initial data
Language: | c | |
Reads: | poisson::phi(everywhere) | |
grid::coordinates(interior) | ||
Type: | function | |
Writes: | poisson::res(interior) | |
poisson_boundaries
apply boundary conditions to initial data
Type: | group | |
Poisson_boundaries
poisson_boundaries_select
select boundary conditions for initial data
Language: | c | |
Options: | level | |
Sync: | potential | |
Type: | function | |
Poisson_boundaries
applybcs
apply boundary conditions to initial data
After: | poisson_boundaries_select | |
Type: | group | |
Alias Name: | Function Name: |
ApplyBCs | Poisson_boundaries_apply |