Skip to main content

A library for basic electrotechnical calculations

Project description

Electrotechnics

A Python library for linear circuit analysis using Modified Nodal Analysis (MNA). Supports DC and AC (phasor) analysis.

This repository provides utilities for:

  • Building and solving linear circuits with passive elements, voltage and current sources
  • Computing Thevenin equivalent impedances between nodes
  • Generating detailed reports including voltages, currents, and power analysis
  • Example scripts for frequency response and power flow analysis

Features

Circuit Analysis:

  • Solve linear circuits using Modified Nodal Analysis (MNA)
  • Support for:
    • Passive branches (complex impedances/admittances)
    • Independent voltage sources
    • Independent current sources
    • Ground node selection
  • Compute node voltages and branch currents
  • Power flow analysis (complex power delivered/absorbed)

Thevenin Analysis:

  • Build nodal Laplacian (admittance) matrices from edge lists (impedance or admittance input).
  • Compute equivalent Thevenin impedance between two nodes using the Moore–Penrose pseudoinverse or test-current method.

Reporting:

  • Detailed solution reports with:
    • Node voltages (magnitude and phase)
    • Branch currents and powers
    • Source currents and delivered powers
    • Power summaries and conservation checks
  • Export reports to Excel workbooks

Examples:

  • Frequency response analysis
  • Power flow visualization
  • Complete circuit solving examples

Installation

Install the lastest stable version from the PyPI repository.

pip install electrotechnics -U

On MS Windows you may prefer:

python -m pip install electrotechnics -U

Once installed, run the example in a Python script or console:

from electrotechnics.examples import example1

Requirements

  • Python 3.8+
  • numpy
  • matplotlib (only required for the example plotting)
  • pandas (for report generation)
  • openpyxl (for Excel export)

Install the required packages (recommended in a virtual environment):

python -m pip install numpy matplotlib pandas openpyxl

Usage

Run the provided example (from the repository root). The example script is inside the src package, so run it on Linux with PYTHONPATH set to src.

env PYTHONPATH=src python -m electrotechnics.examples.example1

This will print the Thevenin impedance at a reference frequency and open two plots (magnitude and phase vs frequency).

You can also import the core functions in your code:

# Example 1: Thevenin impedance
from electrotechnics.circuit import z_th_circuit

# edges: list of (n1, n2, z) where z is complex impedance
edges = [(1, 0, 100.0), (1, 2, 1j*2*np.pi*1000*10e-3)]
Z = z_th_circuit(edges, a=1, b=0)

# Example 2: Full circuit solution with voltage and current sources
from electrotechnics.circuit import solve_circuit, report, export_report_to_excel

# Define circuit elements
edges = [
    (1, 0, 100),        # R1 = 100 Ω between nodes 1-0
    (1, 2, 50),         # R2 = 50 Ω between nodes 1-2
    (2, 0, 1j*100)      # XL = j100 Ω between nodes 2-0
]

# Add sources
voltage_sources = [(1, 0, 10+0j)]     # 10 V source between nodes 1-0
current_sources = [(2, 0, 0.1+0j)]    # 0.1 A source between nodes 2-0

# Solve circuit
solution = solve_circuit(edges, voltage_sources, current_sources, ground=0)

# Generate detailed report
report_data = report(edges, voltage_sources, current_sources, solution)

# Access results
node_voltages = solution['node_voltages']           # All node voltages
branch_currents = solution['branch_currents']       # Currents through passive branches
source_currents = solution['voltage_source_currents']  # Currents through voltage sources

# Export report to Excel
export_report_to_excel(report_data, 'circuit_solution.xlsx')

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

electrotechnics-1.3.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

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

electrotechnics-1.3-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file electrotechnics-1.3.tar.gz.

File metadata

  • Download URL: electrotechnics-1.3.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.2

File hashes

Hashes for electrotechnics-1.3.tar.gz
Algorithm Hash digest
SHA256 42bcea15ec36374637cb5590004320b4afe3b67ac6a5049368b897d07247b812
MD5 0e8b8764bd54a203218d39ee85720886
BLAKE2b-256 7c02769aac735b4e9bedbba85265306b28ab8413a3867dc40ee40ab9bcf49e15

See more details on using hashes here.

File details

Details for the file electrotechnics-1.3-py3-none-any.whl.

File metadata

  • Download URL: electrotechnics-1.3-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.2

File hashes

Hashes for electrotechnics-1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8b82691d1069fac8aaf1edafb93e4db0f51fcec445455d96dcf6bf824e82332e
MD5 77305bd4641234833a58b99d4c8188fd
BLAKE2b-256 b3ebad09f6a7536db95fdfb7c8e1026c4b62b22e236b4c5b02d5f9d260f9edc0

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