# Computing the capacity of a cube with a re-entrant corner

### Background

The capacity $\text{cap}(\Omega)$ of an isolated conductor $\Omega\subset\mathbb{R}^3$ with boundary $\Gamma$ measures its ability to store charges. It is defined as the ratio of the total surface equilibrium charge relative to its surface potential value. To compute the capacity, we need to solve the following exterior Laplace problem for the equilibrium potential $u$ with unit surface value:
$$
\begin{align}
-\Delta u &= 0\quad\text{in }\Omega^\text{+},\\
u &= 1\quad\text{on }\Gamma,\\
|u(\mathbf{x})| &=\mathcal{O}\left(|\mathbf{x}|^{-1}\right)\quad\text{as }|\mathbf{x}|\rightarrow\infty.
\end{align}
$$
Here $\Omega^\text{+}$ is the domain exterior to $\Omega$.
The total surface charge of an isolated conductor is given by Gauss law as
$$
\text{cap}(\Omega)=-\epsilon_0\int_{\Gamma}\frac{\partial u}{\partial\nu}(\mathbf{x})\,\mathrm{d}\mathbf{x}.
$$
$\nu(\mathbf{x})$ is the outward pointing normal direction for $\mathbf{x}\in\Gamma$, and $\epsilon_0$ is the electric constant with value $\epsilon_0\approx 8.854\times 10^{-12}\,{\rm F/m}$. In the following we will use the normalized capacity $\text{cap}^*(\Omega)=-\frac{1}{4\pi}\int_{\Gamma}\frac{\partial u}{\partial\nu}\,d\mathbf{x}$. The normalized capacity has the value $1$ for the unit sphere.

Using Green's representation theorem and noting that the exterior Laplace double layer potential is zero for constant densities, we can represent the solution $u$ as
$$
u(\mathbf{x}) = -\int_{\Gamma} g(\mathbf{x},\mathbf{y})\phi(\mathbf{y})\,\mathrm{d}\mathbf{y} \quad\text{for all }\mathbf{x}\in\Omega^\text{+},
$$
where $\phi:={\partial u}/{\partial\nu}$ is the normal derivative of the exterior solution $u$ and $g(\mathbf{x},\mathbf{y}):=\frac{1}{4\pi|\mathbf{x}-\mathbf{y}|}$ is the Green's function of the 3D Laplacian. By taking boundary traces, we arrive at the following boundary integral equation of the first kind.
$$
1 = -\int_{\Gamma} g(\mathbf{x},\mathbf{y})\phi(\mathbf{y})\,\mathrm{d}\mathbf{y} =: -\mathsf{V}\phi(\mathbf{x})\quad\text{for all }\mathbf{x}\in\Gamma.
$$
The normalized capacity is now simply given by
$$
\text{cap}^*(\Omega) = -\frac{1}{4\pi}\int_\Gamma \phi(\mathbf{x}) \,\mathrm{d}\mathbf{x}.
$$

### Implementation

We start with the usual imports.


```python
import bempp.api
import numpy as np
```

The grid re-entrant cube is predefined in the shapes module. By default it refines towards the singular corner. As function space on the grid we choose a simple space of piecewise constant functions.


```python
grid = bempp.api.shapes.reentrant_cube(h=0.02, refinement_factor=1)
space = bempp.api.function_space(grid, "DP", 0)
```

Next, we define the right-hand side.


```python
@bempp.api.real_callable
def one_fun(x, n, domain_index, res):
    res[0] = 1
    
rhs = bempp.api.GridFunction(space, fun=one_fun)
```

The following code defines the left-hand side single-layer boundary operator.


```python
op = bempp.api.operators.boundary.laplace.single_layer(space, space, space)
```

We use GMRES to solve the system. To improve convergence we use a strong form discretisation that automatically preconditions with the mass matrix.


```python
sol, _, iteration_count = bempp.api.linalg.gmres(op, rhs, use_strong_form=True, return_iteration_count=True)

print("Number of iterations: {0}".format(iteration_count))
```

    scipy/sparse/linalg/dsolve/linsolve.py:296: SparseEfficiencyWarning: splu requires CSC matrix format
      warn('splu requires CSC matrix format', SparseEfficiencyWarning)


    Number of iterations: 35


To obtain the capacity we simply integrate the solution across the boundary.


```python
normalized_capacity = 1./ ( 4 * np.pi) * sol.integrate()[0]
print("The normalized capacity is {0}.".format(normalized_capacity))
```

    The normalized capacity is 0.6455178938316151.


7a1f7dabb0b9b67b4c0c3019d64fe674e8eff0c0
ipynb
Jupyter Notebook
notebooks/laplace/reentrant_cube_capacity.ipynb
pescap/bempp-cl
3a68666e8db0e873d418b734289067483f68f12e
MIT
2019-09-04T15:15:05.000Z
2022-03-22T16:54:40.000Z
notebooks/laplace/reentrant_cube_capacity.ipynb
pescap/bempp-cl
3a68666e8db0e873d418b734289067483f68f12e
MIT
2020-01-16T08:31:00.000Z
2022-03-25T11:18:59.000Z
notebooks/laplace/reentrant_cube_capacity.ipynb
pescap/bempp-cl
3a68666e8db0e873d418b734289067483f68f12e
MIT
2019-09-30T08:50:33.000Z
2022-03-20T19:37:22.000Z
Qwen/Qwen-72B
1. YES
2. YES