A powerful Python package for simulating electrical circuits and generators.
Project description
Electric Circuit Simulator
📚 Overview
Electric Circuit Simulator is a powerful Python package for simulating electrical circuits and generators. It supports both sinusoidal and square wave generators, as well as RL circuit simulations. The core calculations are written in C++ for optimal performance, and Python bindings are provided using pybind11 for easy integration.
This tool allows you to simulate, analyze, and visualize the behavior of resistive-inductive (RL) circuits powered by different signal generators.
🧮 Mathematical Explanation
Sinusoidal Generator
The voltage $V(t)$ generated by a sinusoidal generator is given by the equation:
$$ V(t) = A \sin(2 \pi f t + \phi) $$
Where:
- $A$ is the amplitude
- $f$ is the frequency
- $\phi$ is the phase
- $t$ is time
Square Wave Generator
The voltage $V(t)$ produced by a square wave generator is:
Where:
- $A$ is the amplitude
- $T$ is the period (with $ T = \frac{1}{f} $)
- $f$ is the frequency
- $t$ is time
RL Circuit Simulation
The RL circuit's behavior is governed by the differential equation:
$$ V(t) = L \frac{dI(t)}{dt} + R I(t) $$
Where:
- $V(t)$ is the voltage from the generator
- $I(t)$ is the current flowing through the circuit
- $L$ is the inductance
- $R$ is the resistance
This equation is solved iteratively using the Euler method for simulation.
🛠 Package Contents
- core: C++ bindings for generators and circuit simulation.
- analyze: Tools for analyzing and visualizing simulation results.
📦 Installation
From PyPI
Install the package directly from PyPI:
pip install XXXXXX
From Source
To install from the source, follow these steps:
git clone https://github.com/yourusername/electric-circuit-simulator.git
cd electric-circuit-simulator
python -m venv .venv
source .venv/bin/activate
pip install .
🧑💻 Usage Example
Here’s how you can use the Electric Circuit Simulator to analyze an RL circuit with different generators.
#Example 1
from circuit_simulator.core import CircuitRL, SquareWaveGenerator
# Create generator
square_gen = SquareWaveGenerator(frequency=0.5, amplitude=0.5)
# Create RL circuit
circuit = CircuitRL(resistance=1, inductance=5)
# Simulate Circuit
result = circuit.simulate(generator=square_gen, t_end=1, dt=0.1)
# Print result
print(result) # [(0.0, 0.5, 0.010000000000000002), (0.1, 0.5, 0.019800000000000005), (0.2, 0.5, 0.029404000000000007), ...]
#Example 2
from circuit_simulator.analyze import CircuitRLAnalyzer
from circuit_simulator.core import CircuitRL, SinusoidalGenerator, SquareWaveGenerator
# Create generators
sin_gen = SinusoidalGenerator(frequency=0.25, amplitude=0.5)
square_gen = SquareWaveGenerator(frequency=0.2, amplitude=0.2)
# Create RL circuit
circuit = CircuitRL(resistance=0.5, inductance=15)
# Create analyzer
analyzer = CircuitRLAnalyzer(generators={"sin": sin_gen, "square": square_gen}, circuit=circuit)
# Analyze the circuit
analyzer.analyze(end_time=10.0, step=0.1)
# Plot the results
analyzer.plot_results()
🚀 Features
- High Performance: Core computations are implemented in C++ for maximum performance.
- Python Bindings: Seamless Python API provided by
pybind11. - Flexible Generators: Includes both sinusoidal and square wave generators for different testing conditions.
- RL Circuit Simulation: Simulate the response of an RL circuit under varying conditions.
- Analysis Tools: Built-in functionality for analyzing and plotting the simulation results.
📜 License
This project is licensed under the MIT License. See the LICENSE file for more details.
🤝 Contributing
We welcome contributions! If you'd like to contribute to Electric Circuit Simulator, please feel free to:
- Fork the repository
- Make your changes
- Submit a pull request
For any issues or feature requests, please open an issue in the repository.
💡 Additional Information
The Electric Circuit Simulator is ideal for educational purposes, research, and testing different electrical circuits using realistic signal generators. It provides a robust and easy-to-use platform for simulating real-world electrical systems.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file electriccircuitsim-0.0.2.tar.gz.
File metadata
- Download URL: electriccircuitsim-0.0.2.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
11216d46d9d0954b52a555e8de3b2c15ea6b27ee94a96d0cf26da9ffdd517572
|
|
| MD5 |
80d2ade6ab4ca39fc6f54424df2c0788
|
|
| BLAKE2b-256 |
bd9c3985cc0047d8c73b938057b743ec95f4d47098dedc7959e6b4a20cb17aef
|
File details
Details for the file electriccircuitsim-0.0.2-cp311-cp311-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: electriccircuitsim-0.0.2-cp311-cp311-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 90.4 kB
- Tags: CPython 3.11, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c40f3e8185af6aac5b1fc51b6e0faf162f3307d1d4e2aa79ac3e55f71f195912
|
|
| MD5 |
04dfb6cb0a61f04ea5337a09c96b93a7
|
|
| BLAKE2b-256 |
90fd37115125ffc5792f33ce0bcc3f18cc6ce52731bd1e662266c230205f7acb
|
File details
Details for the file ElectricCircuitSim-0.0.2-py3-none-any.whl.
File metadata
- Download URL: ElectricCircuitSim-0.0.2-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d8b92a94ab3e652187f864b4d9cdef5b18da78110b88b04fbfcb7f45b0f61d05
|
|
| MD5 |
b68f1470f0ad581c1c87c0d687f57966
|
|
| BLAKE2b-256 |
5a17c317a4e31c277c84b58553044880f8c87b3213fab9e87a549a6de485f47f
|