# Charge-Capacitance CalculationΒΆ

The total charge inside a given volume can be computed from
*Gauss’s Law* provided
you know the electric field over the surface of that volume, which
you can calculate with SIMION. So, the steps you need to perform
are

- Create and refine a SIMION potential array (solving the fields).
- Compute the Gauss’s Law integral over some region of the potential array to find total charge.

Computing the integral can be done in various ways. You might even
utilize SIMION Data Recording. However, this task is best
facilitated instead with a custom program.
See SIMION Example: gauss_law
(SIMION 8.0.4 or above), which in
SIMION 8.1 can also use *simionx.FieldAnalysis - Integration over Fields*.
This program will examine a SIMION
potential array (PA) file and calculate the total charge in the
specified 3D sphere or 3D box surface (3D or 2D cylindrical) or 2D
circle or 2D box perimeter (2D planar).

As an example, we’ll use the simple [spherical capacitor system
given in *Hemispherical Deflection Analyzer (HDA)*. According to theory, the charge on the inner
sphere should be Q = (Delta V) * 4 pi epsilon_0 (R1^-1 - R2^-1
)^-1, giving Q ~= 2.225300E-8 C, or the negative of that on the
outer sphere.

For this spherical capacitor system, the totalcharge.pl program is configured as follows:

```
# location of the SIMION potential array (PA) file.
my $pa_name = 'sc3d.pa'; # or sc2d.pa
my $lambda = 1; # gu/mm scaling factor used in the PA.
# load potential array
my $pa = SIMION::PA->new(file => $pa_name);
# define surface to integrate over
my $sphere = &sphere(0,0,0, 100); # center (xc,yc,zc) and radius (mm)
# calculate total charge using Gauss's Law.
# ... given PA, surface, grid density (gu/mm), and convergence limits
&total_charge($pa, $sphere, $lambda, 0.1, 0.0001);
```

SIMION results are 2.249E-8 C (3D), 2.242E-8 C (2D), 2.2269E-8 C (2D, lambda=10 gu/mm).

Wikipedia:Capacitance is then just Q / |Delta V|.