soft4pes.sim.simulation#

Simulation environment for power electronic systems.

Classes#

ProgressPrinter

A class used to print the progress of the simulation process.

SwitchingLogic

A class to handle switching-related logic, such as quantizing switching time instants and

Simulation

Simulation environment.

Module Contents#

class soft4pes.sim.simulation.ProgressPrinter(total_steps)[source]#

A class used to print the progress of the simulation process.

Parameters:

total_steps (int) – The total number of steps in the process.

total_steps[source]#

The total number of steps in the process.

Type:

int

last_printed_percent[source]#

The last printed percentage of progress.

Type:

int

__call__(current_step)[source]#

Prints the current progress with steps of 5 percent.

Parameters:

current_step (int) – The number of the current step in the process.

class soft4pes.sim.simulation.SwitchingLogic(Ts_sim, Ts)[source]#

A class to handle switching-related logic, such as quantizing switching time instants and extracting the three-phase switch position or modulating signal.

Parameters:
  • Ts_sim (float) – Simulation sampling interval [s].

  • Ts (float) – Control system sampling interval [s].

Ts_sim[source]#

Simulation sampling interval [s].

Type:

float

Ts[source]#

Control system sampling interval [s].

Type:

float

k_switch[source]#

Quantized switching times.

Type:

ndarray

u_abc[source]#

Three-phase switch position or modulating signal.

Type:

ndarray

quantize_switching_time_instants(t_switch)[source]#

Quantize the switching time instants.

Parameters:

t_switch (ndarray) – Switching time instants.

Returns:

Quantized switching time instants.

Return type:

ndarray

get_switch_positions(ctr_output, k_sim)[source]#

Get the three-phase switch position or modulating signal for the current discrete time instant. The switching time instants are quantized to the simulation sampling interval in the beginning of the control interval.

Parameters:
  • ctr_output (SimpleNamespace) – Output from the controller including the switching time instants and the corresponding switch position or modulating signal.

  • k_sim (int) – The current simulation step within the control interval.

Returns:

Three-phase switch positions or modulating signal for current simulation step.

Return type:

ndarray

class soft4pes.sim.simulation.Simulation(sys, ctr, Ts_sim, disc_method='forward_euler')[source]#

Simulation environment.

Parameters:
  • sys (system object) – System model.

  • ctr (controller object) – Control system.

  • Ts_sim (float) – Simulation sampling interval [s].

sys[source]#

System model.

Type:

system object

ctr[source]#

Control system.

Type:

controller object.

Ts_sim[source]#

Simulation sampling interval [s].

Type:

float

t_stop[source]#

Simulation stop time [s].

Type:

float

matrices[source]#

Discrete state-space matrices of the simulated system.

Type:

SimpleNamespace

simulation_data[source]#

Data from the simulation.

Type:

dict

switching_logic[source]#

Object for handling switching logic.

Type:

SwitchingLogic

simulate(t_stop)[source]#

Simulate the system.

Parameters:

t_stop (float) – Simulation length [s]. Simulation start time is always 0 s, i.e. kTs = 0.

save_data(filename='sim_data.mat', path='')[source]#

Save the simulation data to a .mat file.

Parameters:
  • filename (str, optional) – Name of the file to save the data to. The default filename is ‘sim_data.mat’.

  • path (str, optional) – Directory path to save the file to. The path can be absolute or relative to the current directory. The default saving directory is the current directory.

process_simulation_data(data)[source]#

Recursively convert lists of arrays in a SimpleNamespace to NumPy arrays.

Parameters:

data (SimpleNamespace or list of ndarray) – The data to be converted. Can be a SimpleNamespace or a list of arrays.

Returns:

A SimpleNamespace with lists of arrays converted to NumPy arrays, or a NumPy array if the input is a list of arrays.

Return type:

SimpleNamespace or ndarray