test_circuit.py 1.13 KB
Newer Older
Markus Mirz's avatar
Markus Mirz committed
1
import os
2
import dpsim
Markus Mirz's avatar
Markus Mirz committed
3
4
5

PATH = os.path.dirname(__file__)

6
def test_circuit():
7
    # Nodes
8
9
10
11
    gnd = dpsim.dp.Node.GND()
    n1 =  dpsim.dp.Node("n1")
    n2 =  dpsim.dp.Node("n2")
    n3 =  dpsim.dp.Node("n3")
Markus Mirz's avatar
Markus Mirz committed
12

13
    # Components
Markus Mirz's avatar
Markus Mirz committed
14
    v1 = dpsim.dp.ph1.VoltageSource("v_1", [gnd, n1], v_ref=10)
15
16
17
    lL = dpsim.dp.ph1.Inductor("l_L", [n2, n3], inductance=0.001)
    rL = dpsim.dp.ph1.Resistor("r_L", [n1, n2], resistance=0.1)
    r1 = dpsim.dp.ph1.Resistor("r_1", [n3, gnd], resistance=20)
Markus Mirz's avatar
Markus Mirz committed
18

19
    system = dpsim.SystemTopology(50, [gnd, n1, n2, n3], [v1, lL, rL, r1])
20

21
    sim = dpsim.Simulation(__name__, system, duration=0.2, timestep=0.0005)
Markus Mirz's avatar
Markus Mirz committed
22
23
    sim.run()

Markus Mirz's avatar
Markus Mirz committed
24
    #results = rt.read_timeseries_dpsim_cmpl('Logs/' + sim.name + '_LeftVector.csv')
Markus Mirz's avatar
Markus Mirz committed
25
26
27
28
29
30
31
32
33
    #expected = rt.read_timeseries_dpsim_real('Examples/Results/Simulink/Circuits/SL_' + sim.name() + '.csv')

    err = 0
    #err += ts.TimeSeries.rmse(expected[0], results[0].dynphasor_shift_to_emt('n1_emt', 50))
    #err += ts.TimeSeries.rmse(expected[1], results[1].dynphasor_shift_to_emt('n2_emt', 50))

    print("Total RMSE: %g" % (err))

    assert err < 1e-4
34
35
36

if __name__ == "__main__":
    test_circuit()