# PETSc demos and BPs

## Area

This example is located in the subdirectory `examples/petsc`

.
It demonstrates a simple usage of libCEED with PETSc to calculate the surface area of a closed surface.
The code uses higher level communication protocols for mesh handling in PETSc’s DMPlex.
This example has the same mathematical formulation as Ex1-Volume, with the exception that the physical coordinates for this problem are \(\bm{x}=(x,y,z)\in \mathbb{R}^3\), while the coordinates of the reference element are \(\bm{X}=(X,Y) \equiv (X_0,X_1) \in \textrm{I} =[-1,1]^2\).

### Cube

This is one of the test cases of the computation of the Area of a 2D manifold embedded in 3D. This problem can be run with:

```
./area -problem cube
```

This example uses the following coordinate transformations for the computation of the geometric factors: from the physical coordinates on the cube, denoted by \(\bar{\bm{x}}=(\bar{x},\bar{y},\bar{z})\), and physical coordinates on the discrete surface, denoted by \(\bm{{x}}=(x,y)\), to \(\bm{X}=(X,Y) \in \textrm{I}\) on the reference element, via the chain rule

with Jacobian determinant given by

We note that in equation (8), the right-most Jacobian matrix \({\partial\bar{\bm{x}}}/{\partial \bm{X}}_{(3\times2)}\) is provided by the library, while \({\partial{\bm{x}}}/{\partial \bar{ \bm{x}}}_{(2\times3)}\) is provided by the user as

### Sphere

This problem computes the surface Area of a tensor-product discrete sphere, obtained by projecting a cube inscribed in a sphere onto the surface of the sphere. This discrete surface is sometimes referred to as a cubed-sphere (an example of such as a surface is given in figure Fig. 6). This problem can be run with:

```
./area -problem sphere
```

This example uses the following coordinate transformations for the computation of the geometric factors: from the physical coordinates on the sphere, denoted by \(\overset{\circ}{\bm{x}}=(\overset{\circ}{x},\overset{\circ}{y},\overset{\circ}{z})\), and physical coordinates on the discrete surface, denoted by \(\bm{{x}}=(x,y,z)\) (depicted, for simplicity, as coordinates on a circle and 1D linear element in figure Fig. 7), to \(\bm{X}=(X,Y) \in \textrm{I}\) on the reference element, via the chain rule

with Jacobian determinant given by

We note that in equation (10), the right-most Jacobian matrix \({\partial\bm{x}}/{\partial \bm{X}}_{(3\times2)}\) is provided by the library, while \({\partial \overset{\circ}{\bm{x}}}/{\partial \bm{x}}_{(3\times3)}\) is provided by the user with analytical derivatives. In particular, for a sphere of radius 1, we have

and thus

## Bakeoff problems and generalizations

The PETSc examples in this directory include a full suite of parallel bakeoff problems (BPs) using a “raw” parallel decomposition (see `bpsraw.c`

) and using PETSc’s `DMPlex`

for unstructured grid management (see `bps.c`

).
A generalization of these BPs to the surface of the cubed-sphere are available in `bpssphere.c`

.

### Bakeoff problems on the cubed-sphere

For the \(L^2\) projection problems, BP1-BP2, that use the mass operator, the coordinate transformations and the corresponding Jacobian determinant, equation (11), are the same as in the Sphere example. For the Poisson’s problem, BP3-BP6, on the cubed-sphere, in addition to equation (11), the pseudo-inverse of \(\partial \overset{\circ}{\bm{x}} / \partial \bm{X}\) is used to derive the contravariant metric tensor (please see figure Fig. 7 for a reference of the notation used). We begin by expressing the Moore-Penrose (left) pseudo-inverse:

This enables computation of gradients of an arbitrary function \(u(\overset{\circ}{\bm x})\) in the embedding space as

and thus the weak Laplacian may be expressed as

where we have identified the \(2\times 2\) contravariant metric tensor \(\bm g\) (sometimes written \(\bm g^{ij}\)), and where now \(\Omega\) represents the surface of the sphere, which is a two-dimensional closed surface embedded in the three-dimensional Euclidean space \(\mathbb{R}^3\). This expression can be simplified to avoid the explicit Moore-Penrose pseudo-inverse,

where we have dropped the transpose due to symmetry. This allows us to simplify (13) as

which is the form implemented in `qfunctions/bps/bp3sphere.h`

.

## Multigrid

This example is located in the subdirectory `examples/petsc`

.
It investigates \(p\)-multigrid for the Poisson problem, equation (14), using an unstructured high-order finite element discretization.
All of the operators associated with the geometric multigrid are implemented in libCEED.

The Poisson operator can be specified with the decomposition given by the equation in figure Operator Decomposition, and the restriction and prolongation operators given by interpolation basis operations, \(\bm{B}\), and \(\bm{B}^T\), respectively, act on the different grid levels with corresponding element restrictions, \(\bm{G}\). These three operations can be exploited by existing matrix-free multigrid software and smoothers. Preconditioning based on the libCEED finite element operator decomposition is an ongoing area of research.