Skip to main content

An educational package about linear DC electrical circuits

Project description

dcelectricity package

The aim of this project is to understand the rudiments of DC electrical circuits and their functioning (primary and secondary school curricula).

Prerequisites

Python : version 3
All operating systems

Installing dcelectricity python package

From Pypi repository :
https://pypi.org/project/dc-electricity

pip install dc-electricity

Basic electrical quantities

  • Voltage (volt)
  • Current (ampere)
  • Resistance (ohm)
  • Conductance (siemens)
  • Power (watt)
  • Energy (joule / kWh)

Electrical laws

  • Kirchhoff’s current law
  • Kirchhoff’s voltage law
  • Ohm's law
  • Resistors in series and parallel
  • Voltage divider and current divider
  • Millman's theorem
  • Joule's first law (P=I²R=V²/R)
  • Power law (P=VI)
  • Energy formula (P=E/t)

DC Circuit diagram

Circuit should only contain :

  • independent voltage source
  • independent current source
  • resistors

A complete example

            V1
        <---------
         +------+
   --->--| R1   |--------+-------+
     I1  +------+        |       |
 ^                    I2 v       v I3
 |                       |       |      ^
 |                     +---+   +---+    |
 |                     |   |   |   |    |
E|                     |R2 |   |R3 |    | V2
 |                     |   |   |   |    |
 |                     +---+   +---+    |
 |                       |       |
                         |       |
   ----------------------+-------+

Datas :
E = 12 V ; R1 = 1 kΩ ; R2 = 2.7 kΩ ; R3 = 1.8 kΩ
What are the I1, I2, I3 currents ?
What are the V1, V2 voltages ?

>>> from dcelectricity.dc_en import *  # english version
>>> # from dcelectricity.dc_fr import *  # french version
>>> E = Voltage(12)
>>> E
Voltage : 12.000000 V
>>> R1 = Resistor(1, 'k')
>>> R1
Resistance : 1000 Ω (1.000000 )
>>> R2 = Resistor(2.7, 'k')
>>> R3 = Resistor(1.8, 'k')
>>> R23 = R2//R3  # resistances in parallel
>>> R23
Resistance : 1080 Ω (1.080000 )
>>> Req = R1 + R23  # resistances in series
>>> Req
Resistance : 2080 Ω (2.080000 )
>>> I1 = E/Req  # Ohm's law
>>> I1
Current : 0.00576923 A (5.769231 mA)
>>> V1 = I1*R1  # Ohm's law
>>> V1
Voltage : 5.769231 V
>>> V2 = E - V1  # Kirchhoff’s voltage law
>>> V2
Voltage : 6.230769 V
>>> I2 = V2/R2  # Ohm's law
>>> I2
Current : 0.00230769 A (2.307692 mA)
>>> I3 = I1 - I2  # Kirchhoff’s current law
>>> I3
Current : 0.00346154 A (3.461538 mA)

Resistances and conductances

>>> G2 = 1/R2
>>> G2
Conductance : 0.00037037 S (370.370370 µS)
>>> G3 = 1/R3
>>> 1/(G2+G3)
Resistance : 1080 Ω (1.080000 )
>>> R2*(R3/(R2+R3))
Resistance : 1080 Ω (1.080000 )
>>> 1/(1/R2 + 1/R3)
Resistance : 1080 Ω (1.080000 )

Law class

>>> law = Law()
>>> # voltage divider
>>> V2 = law.VoltageDivider(vtotal=E, r=R2//R3, r2=R1)
>>> V2
Voltage : 6.230769 V
>>> # Millman's theorem
>>> gnd = Voltage(0)
>>> V2 = law.Millman(v_r=[(E, R1), (gnd, R2), (gnd, R3)])
>>> V2
Voltage : 6.230769 V
>>> (E/R1)/(1/R1 + 1/R2 + 1/R3)
Voltage : 6.230769 V
>>> V2/E
0.5192307692307693
>>> # current divider
>>> I3 = law.CurrentDivider(itotal=I1, r=R3, r2=R2)
>>> I3
Current : 0.00346154 A (3.461538 mA)
>>> I1*R2/(R2+R3)
Current : 0.00346154 A (3.461538 mA)

Electrical power, Joule's first law

>>> P = E*I1  # source power
>>> P
Power : 0.0692308 W (69.230769 mW)
>>> P1 = law.Joule(r=R1, i=I1)
>>> P1
Power : 0.033284 W (33.284024 mW)
>>> R1*I1*I1
Power : 0.033284 W (33.284024 mW)
>>> law.Joule(r=R1, v=V1)
Power : 0.033284 W (33.284024 mW)
>>> V1*(V1/R1)
Power : 0.033284 W (33.284024 mW)
>>> P2 = law.Joule(r=R2, i=I2)
>>> P2
Power : 0.0143787 W (14.378698 mW)
>>> P3 = law.Joule(r=R3, i=I3)
Power : 0.021568 W (21.568047 mW)
>>> P1+P2+P3
Power : 0.0692308 W (69.230769 mW)

Energy and power

>>> T = Time(1800)  # or T = Time(0.5, 'h')
>>> P = Power(1500)
>>> E = P*T  # or E = law.Energy(t=T, p=P)
>>> E
Energy : 2.7e+06 J (2.700000 MJ) 0.75 kWh
>>> E/P
Time : 1800 s (1.800000 ks) 0.5 h
>>> E/T
Power : 1500 W (1.500000 kW)

Advantages and limitations

This module manages basic arithmetic operations + - * / as well as // which designates two resistors in parallel.

The dimensional homogeneity is checked :

>>> V3 = V1 - V2 + I3  # V+A -> Error
TypeError
>>> I = I1 + 0.5  # A+number -> Error
TypeError
>>> I2 = Current(0.5)
>>> I = I1 + I2
>>> I = 5*I2 - V1/R1 + I3

The result of an operation must give a quantity whose unit is one of : V, A, Ω, S, W, J, s, no unit (ratio).
Otherwise, you will get an error :

>>> R1/V1  # Ω/V -> 1/A -> Error
TypeError
>>> R2*(R3/(R2+R3))  # Ω*(Ω/Ω) -> Ω*() -> Ω
>>> R2*R3/(R2+R3)  # Ω*Ω -> Error
TypeError
>>> P = V1*(V1/R1)  # V*(V/Ω) -> V*A -> W
>>> P = V1*V1/R1    # V*V -> Error
TypeError
>>> V1()**2/R1()

See also

http://fsincere.free.fr/isn/python/cours_python_dc.php

https://pypi.org/project/ac-electricity

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

dc-electricity-0.2.9.tar.gz (23.0 kB view details)

Uploaded Source

File details

Details for the file dc-electricity-0.2.9.tar.gz.

File metadata

  • Download URL: dc-electricity-0.2.9.tar.gz
  • Upload date:
  • Size: 23.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.5.2

File hashes

Hashes for dc-electricity-0.2.9.tar.gz
Algorithm Hash digest
SHA256 0ecbefbd8fe992ea5b1065bfdf063249d9514f02b68f00e4f58be4221f06d3ff
MD5 59ef3dc7bfef3139c220f261ee8d1d58
BLAKE2b-256 8514ba3cba154d7f35ecc830888c393590918ada0893e0fcd4603507726e3627

See more details on using hashes here.

Supported by

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