Skip to main content

Compute the capacitance matrix of N conducting spheres using the method of mirror images

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

arbitrary_capacitance_matrix-0.1.0.tar.gz (1.1 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

arbitrary_capacitance_matrix-0.1.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file arbitrary_capacitance_matrix-0.1.0.tar.gz.

File metadata

File hashes

Hashes for arbitrary_capacitance_matrix-0.1.0.tar.gz
Algorithm Hash digest
SHA256 913b845f3f2dc54f4d2a89b8f97f8fee0bac030a1c699ed60fe0a7c9bdf770ec
MD5 0e61bdb4876b89c0f2447cdbd447d701
BLAKE2b-256 eb5cc4a411a34cc3be709b8ac8b95eaac8d654cd4c9d3c8d978716a525eb2bcc

See more details on using hashes here.

File details

Details for the file arbitrary_capacitance_matrix-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for arbitrary_capacitance_matrix-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5fa2f656721970f56e9601182bd11f9bc419f79fa9b8f8e837d29dd421ca260f
MD5 29e04aa1fc7b2d3b31051ecbcb85c0e7
BLAKE2b-256 85e23b08bb9e4196ce234c3a16515f3b0a8e9cfe573ebf2af7e85b5155ea0e89

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page