Package: dc-electricity
dcelectricity packageThe aim of this project is to understand the rudiments of DC electrical circuits and their functioning (primary and secondary school curricula).PrerequisitesPython : version 3All operating systemsInstalling dcelectricity python packageFrom Pypi repository :https://pypi.org/project/dc-electricitypip install dc-electricityBasic electrical quantitiesVoltage (volt)Current (ampere)Resistance (ohm)Conductance (siemens)Power (watt)Energy (joule / kWh)Electrical lawsKirchhoff’s current lawKirchhoff’s voltage lawOhm's lawResistors in series and parallelVoltage divider and current dividerMillman's theoremJoule's first law (P=I²R=V²/R)Power law (P=VI)Energy formula (P=E/t)DC Circuit diagramCircuit should only contain :independent voltage sourceindependent current sourceresistorsA complete exampleV1
        <---------
         +------+
   --->--| 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 ?>>>fromdcelectricity.dc_enimport*# english version>>># from dcelectricity.dc_fr import *  # french version>>>E=Voltage(12)>>>EVoltage:12.000000V>>>R1=Resistor(1,'k')>>>R1Resistance:1000Ω(1.000000kΩ)>>>R2=Resistor(2.7,'k')>>>R3=Resistor(1.8,'k')>>>R23=R2//R3# resistances in parallel>>>R23Resistance:1080Ω(1.080000kΩ)>>>Req=R1+R23# resistances in series>>>ReqResistance:2080Ω(2.080000kΩ)>>>I1=E/Req# Ohm's law>>>I1Current:0.00576923A(5.769231mA)>>>V1=I1*R1# Ohm's law>>>V1Voltage:5.769231V>>>V2=E-V1# Kirchhoff’s voltage law>>>V2Voltage:6.230769V>>>I2=V2/R2# Ohm's law>>>I2Current:0.00230769A(2.307692mA)>>>I3=I1-I2# Kirchhoff’s current law>>>I3Current:0.00346154A(3.461538mA)Resistances and conductances>>>G2=1/R2>>>G2Conductance:0.00037037S(370.370370µS)>>>G3=1/R3>>>1/(G2+G3)Resistance:1080Ω(1.080000kΩ)>>>R2*(R3/(R2+R3))Resistance:1080Ω(1.080000kΩ)>>>1/(1/R2+1/R3)Resistance:1080Ω(1.080000kΩ)Law class>>>law=Law()>>># voltage divider>>>V2=law.VoltageDivider(vtotal=E,r=R2//R3,r2=R1)>>>V2Voltage:6.230769V>>># Millman's theorem>>>gnd=Voltage(0)>>>V2=law.Millman(v_r=[(E,R1),(gnd,R2),(gnd,R3)])>>>V2Voltage:6.230769V>>>(E/R1)/(1/R1+1/R2+1/R3)Voltage:6.230769V>>>V2/E0.5192307692307693>>># current divider>>>I3=law.CurrentDivider(itotal=I1,r=R3,r2=R2)>>>I3Current:0.00346154A(3.461538mA)>>>I1*R2/(R2+R3)Current:0.00346154A(3.461538mA)Electrical power, Joule's first law>>>P=E*I1# source power>>>PPower:0.0692308W(69.230769mW)>>>P1=law.Joule(r=R1,i=I1)>>>P1Power:0.033284W(33.284024mW)>>>R1*I1*I1Power:0.033284W(33.284024mW)>>>law.Joule(r=R1,v=V1)Power:0.033284W(33.284024mW)>>>V1*(V1/R1)Power:0.033284W(33.284024mW)>>>P2=law.Joule(r=R2,i=I2)>>>P2Power:0.0143787W(14.378698mW)>>>P3=law.Joule(r=R3,i=I3)Power:0.021568W(21.568047mW)>>>P1+P2+P3Power:0.0692308W(69.230769mW)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)>>>EEnergy:2.7e+06J(2.700000MJ)0.75kWh>>>E/PTime:1800s(1.800000ks)0.5h>>>E/TPower:1500W(1.500000kW)Advantages and limitationsThis 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 -> ErrorTypeError>>>I=I1+0.5# A+number -> ErrorTypeError>>>I2=Current(0.5)>>>I=I1+I2>>>I=5*I2-V1/R1+I3The 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 -> ErrorTypeError>>>R2*(R3/(R2+R3))# Ω*(Ω/Ω) -> Ω*() -> Ω>>>R2*R3/(R2+R3)# Ω*Ω -> ErrorTypeError>>>P=V1*(V1/R1)# V*(V/Ω) -> V*A -> W>>>P=V1*V1/R1# V*V -> ErrorTypeError>>>V1()**2/R1()See alsohttp://fsincere.free.fr/isn/python/cours_python_dc.phphttps://pypi.org/project/ac-electricity