Skip to content

SIMBA Python API Examples

To get started, check our overview page and our get-started examples hereunder or here.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# Load modules
from aesim.simba import DesignExamples

# Load project
flybackConverter = DesignExamples.DCDC_Flyback()

# Get the job object and solve the system
job = flybackConverter.TransientAnalysis.NewJob()
status = job.Run()

# Get results
t = job.TimePoints
Vout = job.GetSignalByName('R2 - Instantaneous Voltage').DataPoints
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Load required modules
from aesim.simba import DesignExamples
import numpy as np

# Calculating Vout=f(dutycycle)
BuckBoostConverter = DesignExamples.BuckBoostConverter()
dutycycles = np.arange(0.00, 0.9, 0.9/50)
Vouts = []
for dutycycle in dutycycles:
    # Set duty cycle value
    PWM = BuckBoostConverter.Circuit.GetDeviceByName('C1')
    PWM.DutyCycle=dutycycle

    # Run calculation
    job = BuckBoostConverter.TransientAnalysis.NewJob()
    status = job.Run()

    # Retrieve results
    t = np.array(job.TimePoints)
    Vout = np.array(job.GetSignalByName('R1 - Instantaneous Voltage').DataPoints)

    # Average output voltage for t > 2ms
    indices = np.where(t >= 0.002)
    Vout = np.take(Vout, indices)
    Vout = np.average(Vout)

    # Save results
    Vouts.append(Vout)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#  Load required module
from aesim.simba import Design

#  Create Buck Converter Model
design = Design()
design.Name = "DC/DC - Buck Converter"
design.TransientAnalysis.TimeStep = 1e-6
design.TransientAnalysis.EndTime = 10e-3
circuit = design.Circuit

#  Add devices
V1 = circuit.AddDevice("DC Voltage Source", 2, 6)
V1.Voltage = 50
SW1 =circuit.AddDevice("Controlled Switch", 8, 4)
PWM = circuit.AddDevice("Square Wave", 2, 0)
PWM.Frequency = 5000
PWM.DutyCycle = 0.5
PWM.Amplitude = 1
D1 = circuit.AddDevice("Diode", 16, 9)
D1.RotateLeft()
L1 = circuit.AddDevice("Inductor", 20, 5)
L1.Value = 1E-3
C1 = circuit.AddDevice("Capacitor", 28, 9)
C1.RotateRight()
C1.Value = 100E-6
R1 = circuit.AddDevice("Resistor", 34, 9)
R1.RotateRight()
R1.Value = 5
R1.Name = "R1"
for scope in R1.Scopes:
    scope.Enabled = True
g = circuit.AddDevice("Ground", 3, 14) 

# Make connections
circuit.AddConnection(V1.P, SW1.P)
circuit.AddConnection(SW1.N, D1.Cathode)
circuit.AddConnection(D1.Cathode, L1.P)
circuit.AddConnection(L1.N, C1.P)
circuit.AddConnection(L1.N, R1.P)
circuit.AddConnection(PWM.Out, SW1.In)
circuit.AddConnection(V1.N, g.Pin)
circuit.AddConnection(D1.Anode, g.Pin)
circuit.AddConnection(C1.N, g.Pin)
circuit.AddConnection(R1.N, g.Pin)

#  Run Simulation
job = design.TransientAnalysis.NewJob()
status = job.Run()
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Load modules
from aesim.simba import DesignExamples, ACSweep

# Load AC Sweep Design Example
buck_converter = DesignExamples.DCDC_Buck_Converter_ACSweep()

# Create the AC Sweep Test bench and assign the perturbation device
buck_converter_acsweep = ACSweep()
buck_converter_acsweep.Design = buck_converter;
buck_converter_acsweep.Device = buck_converter.Circuit.GetDeviceByName("Control")
buck_converter_acsweep.Fmin = 100;
buck_converter_acsweep.Fmax = 1E5;
buck_converter_acsweep.MagMin  = 0.03;
buck_converter_acsweep.MagMax  = 0.05;
buck_converter_acsweep.NumberOfPoints  = 41;

# Create and run the job
job = buck_converter_acsweep.NewJob();
status = job.Run();

# Retrieve Transfer Function
mag_sim = job.GetSignalByName('Rload - Voltage Magnitude').DataPoints
phase_sim = job.GetSignalByName('Rload - Voltage Angle').DataPoints

More Examples

A collection of simple Python script examples using the SIMBA Python API is available on this GitHub repository