Skip to main content

Arbitrary Capacitance Matrix

Compute the capacitance matrix of N conducting spheres in an arbitrary spatial distribution using the method of mirror images.

This project is based on the numerical implementation I developed during my BSc thesis. It allows for the computation of the mutual capacitance matrix of multiple spherical conductors in a bounded region using a physically grounded and mathematically robust approach.

🚀 Installation

Install the package using pip:

pip install arbitrary-capacitance-matrix

Or for development:

git clone https://github.com/carlosperezespinar/arbitrary-capacitance-matrix.git
cd arbitrary-capacitance-matrix
pip install -e .

📖 Quick Start

import numpy as np
from capmatrix import compute_capacitance_matrix, Sphere

# Define two spheres
spheres = [
    Sphere(center=[0, 0, 0], radius=1e-9),      # 1 nm radius at origin
    Sphere(center=[3e-9, 0, 0], radius=1e-9)    # 1 nm radius, 3 nm away
]

# Compute capacitance matrix
C = compute_capacitance_matrix(spheres)
print("Capacitance matrix (F):")
print(C)

🔬 Background & Theory

The method of mirror images is a classic electrostatics technique to enforce boundary conditions by introducing fictitious "image charges." For a system of N conducting spheres, we recursively place image charges inside each sphere to satisfy the equipotential condition, then assemble the resulting potentials into the capacitance matrix C:

C_ij = 4 * π * ε₀ * R_i * Q_ij

where Q_ij is the total induced charge on sphere i when sphere j is held at unit potential and all others are grounded.

This approach handles:

  • Arbitrary number (N) of spheres
  • Random positions & radii
  • No assumed symmetries or simplifying approximations

🖼 Images & Diagrams

1. Basic image-charge construction

Mirror‐image construction for two spheres
Iterative placement of image charges inside each sphere to enforce constant potential.

2. Generalized vector formulation

Vector form of image‐charge positions
Vector-based formula for computing the coordinates and strength of each new image charge from known charge positions.

🔍 Examples

Two Spheres

from capmatrix import compute_capacitance_matrix, Sphere

# Two identical spheres
radius = 1e-9  # 1 nm
separation = 3e-9  # 3 nm center-to-center

spheres = [
    Sphere([0, 0, 0], radius),
    Sphere([separation, 0, 0], radius)
]

C = compute_capacitance_matrix(spheres)

Three Spheres in a Line

# Three spheres with different radii
spheres = [
    Sphere([-6e-9, 0, 0], 2e-9),   # Left sphere
    Sphere([0, 0, 0], 1.5e-9),     # Center sphere  
    Sphere([6e-9, 0, 0], 1e-9)     # Right sphere
]

C = compute_capacitance_matrix(spheres, tolerance=1e-10, max_iterations=100)

See the examples/ folder for complete working examples:

  • examples/two_spheres.py - Two sphere benchmark with analytical comparison
  • examples/three_spheres.py - Three sphere configuration
  • demo.py - Simple demonstration script

📋 API Reference

Classes

Sphere(center, radius)

Represents a conducting sphere.

  • center: 3D coordinates [x, y, z]
  • radius: Sphere radius (must be positive)

Charge(value, radial_distance, coordinates, sphere_index, iteration=0)

Represents a point charge in the system.

Functions

compute_capacitance_matrix(spheres, tolerance=1e-8, max_iterations=50)

Compute the capacitance matrix for a list of spheres.

Parameters:

  • spheres: List of Sphere objects
  • tolerance: Convergence tolerance (default: 1e-8)
  • max_iterations: Maximum iterations (default: 50)

Returns: NxN numpy array of capacitances in Farads

🧪 Testing

Run the test suite:

pytest tests/

📚 References

  1. Wasshuber, C. (1997). About Single-Electron Devices and Circuits. PhD Thesis, Technische Universität Wien. Online PDF – Chapter on method of images
  2. Pérez Espinar, C. BSc Thesis (2019), Universitat de Barcelona

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

Metadata

Release files for arbitrary-capacitance-matrix 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for arbitrary-capacitance-matrix 0.1.0
File Size Uploaded
arbitrary_capacitance_matrix-0.1.0.tar.gz 1.1 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for arbitrary-capacitance-matrix 0.1.0
File Interpreter ABI Platform
arbitrary_capacitance_matrix-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 1.2 MB

Release files / arbitrary_capacitance_matrix-0.1.0.tar.gz

Download URL arbitrary_capacitance_matrix-0.1.0.tar.gz
Size 1.1 MB
Tags Source
SHA-256 checksum
How to use checksums
913b845f3f2dc54f4d2a89b8f97f8fee0bac030a1c699ed60fe0a7c9bdf770ec
BLAKE2b-256 checksum
How to use checksums
eb5cc4a411a34cc3be709b8ac8b95eaac8d654cd4c9d3c8d978716a525eb2bcc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Release files / arbitrary_capacitance_matrix-0.1.0-py3-none-any.whl

Download URL arbitrary_capacitance_matrix-0.1.0-py3-none-any.whl
Size 9.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5fa2f656721970f56e9601182bd11f9bc419f79fa9b8f8e837d29dd421ca260f
BLAKE2b-256 checksum
How to use checksums
85e23b08bb9e4196ce234c3a16515f3b0a8e9cfe573ebf2af7e85b5155ea0e89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page