Dynamic models¶
Model classes, one module per category key of the model dictionary.
gen
¶
GenEvents
¶
Bases: ModelEvents
connect
¶
Connect a generator to its bus. It is kept in step with the bus while disconnected, so it connects without a large transient, at the mechanical power its governor gives at that moment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gen_name
|
Name of the generator. |
required |
Returns:
| Type | Description |
|---|---|
|
The change in the admittance matrix. |
Source code in src/tops/dyn_models/gen.py
disconnect
¶
Disconnect a generator from its bus. It then runs at no load, with its exciter, and a synchronizer keeps its
speed and angle in step with the bus (see GEN).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gen_name
|
Name of the generator. |
required |
Returns:
| Type | Description |
|---|---|
|
The change in the admittance matrix. |
Source code in src/tops/dyn_models/gen.py
GEN
¶
Bases: DAEModel
Synchronous machine (sixth order).
A generator can be out of service: from the start, with the optional connected column, or after a
disconnect event. It then gives no current, its terminal voltage is its own open-circuit voltage (so that its
exciter keeps regulating it), and its mechanical power is ignored: a synchronizer, a critically damped second-order
loop with natural frequency sync_omega (rad/s, default 2), drives its speed and angle to those of the bus
voltage, so that it can be connected again at any time.
Source code in src/tops/dyn_models/gen.py
bus_idx
instance-attribute
¶
bus_idx = np.array(
np.zeros(self.n_units),
dtype=[
(key, int) for key in self.bus_ref_spec().keys()
],
)
bus_idx_red
instance-attribute
¶
bus_idx_red = np.array(
np.zeros(self.n_units),
dtype=[
(key, int) for key in self.bus_ref_spec().keys()
],
)
bus_ref_spec
¶
load_flow_pv
¶
init_from_load_flow
¶
Source code in src/tops/dyn_models/gen.py
dyn_const_adm
¶
Source code in src/tops/dyn_models/gen.py
admittance_change
¶
Change in the reduced admittance matrix when connecting (sign=1) or disconnecting (sign=-1) a generator.
Source code in src/tops/dyn_models/gen.py
state_list
¶
input_list
¶
reduced_system
¶
current_injections
¶
Source code in src/tops/dyn_models/gen.py
state_derivatives
¶
Source code in src/tops/dyn_models/gen.py
d
¶
q
¶
v_t
¶
v_t_abs
¶
v_setp
¶
e_q_st
¶
e_d_st
¶
e_q_t
¶
e_d_t
¶
angle
¶
speed
¶
e_st
¶
e_t
¶
i
¶
I
¶
i_d
¶
i_q
¶
s_e
¶
p_e
¶
q_e
¶
S_e
¶
P_e
¶
Q_e
¶
avr
¶
AVR
¶
output_list
¶
connections
¶
Source code in src/tops/dyn_models/avr.py
SEXS
¶
Source code in src/tops/dyn_models/utils.py
input_list
¶
add_blocks
¶
Source code in src/tops/dyn_models/avr.py
init_from_connections
¶
SEXS_PI
¶
Source code in src/tops/dyn_models/utils.py
input_list
¶
add_blocks
¶
Source code in src/tops/dyn_models/avr.py
init_from_connections
¶
Source code in src/tops/dyn_models/avr.py
IEEET1
¶
Saturation not yet included!
Source code in src/tops/dyn_models/utils.py
input_list
¶
add_blocks
¶
Source code in src/tops/dyn_models/avr.py
SCRX
¶
Missing negative current logic!
Source code in src/tops/dyn_models/utils.py
input_list
¶
add_blocks
¶
Source code in src/tops/dyn_models/avr.py
gov
¶
GovEvents
¶
Bases: ModelEvents
set_reference
¶
Set the power reference of a governor: the mechanical power that it gives in steady state at rated speed. At other speeds, its droop moves the power away from the reference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gov_name
|
Name of the governor. |
required | |
P_m
|
Mechanical power in p.u. of the generator's rating (machine base). |
required |
Returns:
| Type | Description |
|---|---|
|
No effects on the network. |
Source code in src/tops/dyn_models/gov.py
GOV
¶
input_list
¶
reference_bias
¶
The bias input that gives a mechanical power in steady state at rated speed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
P_m
|
Mechanical power in p.u. of the generator's rating (machine base). |
required | |
idx
|
Indices of the units. |
slice(None)
|
Source code in src/tops/dyn_models/gov.py
set_reference
¶
Set the power reference of units (see GovEvents.set_reference).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
idx
|
Indices of the units. |
required | |
P_m
|
Mechanical power in p.u. of the generator's rating (machine base). |
required |
Source code in src/tops/dyn_models/gov.py
output_list
¶
connections
¶
Source code in src/tops/dyn_models/gov.py
TGOV1
¶
Source code in src/tops/dyn_models/utils.py
add_blocks
¶
Source code in src/tops/dyn_models/gov.py
reference_bias
¶
init_from_connections
¶
HYGOV
¶
Implementation of the HYGOV model. Some limiters are missing.
Source code in src/tops/dyn_models/utils.py
add_blocks
¶
Source code in src/tops/dyn_models/gov.py
reference_bias
¶
init_from_connections
¶
Source code in src/tops/dyn_models/gov.py
IEESGO
¶
Source code in src/tops/dyn_models/utils.py
add_blocks
¶
Source code in src/tops/dyn_models/gov.py
reference_bias
¶
init_from_connections
¶
pss
¶
STAB1
¶
Source code in src/tops/dyn_models/utils.py
add_blocks
¶
Source code in src/tops/dyn_models/pss.py
loads
¶
LoadEvents
¶
Bases: ModelEvents
Load
¶
Bases: DAEModel
Source code in src/tops/dyn_models/loads.py
bus_idx
instance-attribute
¶
bus_idx = np.array(
np.zeros(self.n_units),
dtype=[
(key, int) for key in self.bus_ref_spec().keys()
],
)
bus_idx_red
instance-attribute
¶
bus_idx_red = np.array(
np.zeros(self.n_units),
dtype=[
(key, int) for key in self.bus_ref_spec().keys()
],
)
bus_ref_spec
¶
reduced_system
¶
load_flow_pq
¶
init_from_load_flow
¶
Source code in src/tops/dyn_models/loads.py
dyn_const_adm
¶
power_change
¶
Set the power of a load in MW and Mvar (None keeps it), at the voltage of the load flow.
Returns the change in the reduced admittance matrix, or None if the power is as it was.
Source code in src/tops/dyn_models/loads.py
i
¶
I
¶
s
¶
p
¶
q
¶
P
¶
DynamicLoad
¶
Bases: DAEModel
Source code in src/tops/dyn_models/loads.py
bus_idx
instance-attribute
¶
bus_idx = np.array(
np.zeros(self.n_units),
dtype=[
(key, int) for key in self.bus_ref_spec().keys()
],
)
bus_idx_red
instance-attribute
¶
bus_idx_red = np.array(
np.zeros(self.n_units),
dtype=[
(key, int) for key in self.bus_ref_spec().keys()
],
)
input_list
¶
bus_ref_spec
¶
reduced_system
¶
load_flow_pq
¶
init_from_load_flow
¶
Source code in src/tops/dyn_models/loads.py
g_load
¶
b_load
¶
y_load
¶
dyn_var_adm
¶
i
¶
I
¶
s
¶
p
¶
q
¶
P
¶
DynamicLoadFiltered
¶
Bases: DynamicLoad
Dynamic load where the input is filtered using a low pass filter.
The load is an admittance which is determined by the output of two low pass filters, one for G (conductance) and one for B (susceptance).
Source code in src/tops/dyn_models/loads.py
add_blocks
¶
g_load
¶
b_load
¶
init_from_load_flow
¶
Source code in src/tops/dyn_models/loads.py
ConstPowerLoad
¶
Bases: DAEModel
Source code in src/tops/dyn_models/loads.py
bus_idx
instance-attribute
¶
bus_idx = np.array(
np.zeros(self.n_units),
dtype=[
(key, int) for key in self.bus_ref_spec().keys()
],
)
bus_idx_red
instance-attribute
¶
bus_idx_red = np.array(
np.zeros(self.n_units),
dtype=[
(key, int) for key in self.bus_ref_spec().keys()
],
)
bus_ref_spec
¶
reduced_system
¶
load_flow_pq
¶
power_change
¶
Set the power of a load in MW and Mvar (None keeps it). The power is read at every step, so there is no change of the admittance matrix to return.
read_power
¶
A power in MW or Mvar given to set_power, as a finite float.
Source code in src/tops/dyn_models/loads.py
float_power_columns
¶
The load table with float P and Q, as set_power must not truncate the integer columns a table may have.
Source code in src/tops/dyn_models/loads.py
write_power
¶
Write the power of a load, in MW and Mvar (None keeps it), to the table of its model.
Nothing is changed if a value is refused, or if the bus of the load is not in the reduced system. Returns False if the power is as it was.
Source code in src/tops/dyn_models/loads.py
lines
¶
LineEvents
¶
Bases: ModelEvents
connect
¶
Line
¶
Bases: DAEModel
Source code in src/tops/dyn_models/lines.py
bus_idx
instance-attribute
¶
bus_idx = np.array(
np.zeros(self.n_units),
dtype=[
(key, int) for key in self.bus_ref_spec().keys()
],
)
bus_idx_red
instance-attribute
¶
bus_idx_red = np.array(
np.zeros(self.n_units),
dtype=[
(key, int) for key in self.bus_ref_spec().keys()
],
)
bus_ref_spec
¶
event
¶
Apply a line event directly (connect/disconnect). Kept for backwards compatibility, see LineEvents.
admittance_change
¶
Change in the reduced admittance matrix when connecting (sign=1) or disconnecting (sign=-1) a line.
Source code in src/tops/dyn_models/lines.py
init_extras
¶
Source code in src/tops/dyn_models/lines.py
load_flow_adm
¶
Source code in src/tops/dyn_models/lines.py
dyn_const_adm
¶
i_from
¶
i_to
¶
I_from
¶
I_to
¶
s_from
¶
s_to
¶
p_from
¶
p_to
¶
q_from
¶
q_to
¶
s_line
¶
p_line
¶
q_line
¶
switches
¶
Switches (breakers, disconnectors): ideal connections between two buses, modelled as a very high admittance.
SwitchEvents
¶
Bases: ModelEvents
close
¶
Switch
¶
Bases: DAEModel
Switch between two buses.
A closed switch is a series admittance y (pu on system base, default :attr:y_closed), large enough that the
voltage across it is negligible. An open switch is removed from the network.
Parameters (table columns): name, from_bus, to_bus, and optionally closed (initial state, boolean
or 1/0, default closed) and y (admittance when closed, pu on system base). The state is kept in connected,
like for lines and transformers.
Source code in src/tops/dyn_models/switches.py
admittance
instance-attribute
¶
admittance = (
data["y"].astype(complex)
if "y" in names
else np.full(self.n_units, self.y_closed, complex)
)
bus_idx
instance-attribute
¶
bus_idx = np.array(
np.zeros(self.n_units),
dtype=[
(key, int) for key in self.bus_ref_spec().keys()
],
)
bus_idx_red
instance-attribute
¶
bus_idx_red = np.array(
np.zeros(self.n_units),
dtype=[
(key, int) for key in self.bus_ref_spec().keys()
],
)
bus_ref_spec
¶
admittance_change
¶
Change in the reduced admittance matrix when closing (sign=1) or opening (sign=-1) a switch.
Source code in src/tops/dyn_models/switches.py
load_flow_adm
¶
Source code in src/tops/dyn_models/switches.py
dyn_const_adm
¶
i_from
¶
i_to
¶
I_from
¶
s_from
¶
s_to
¶
p_from
¶
q_from
¶
p_to
¶
trafos
¶
TrafoEvents
¶
Bases: ModelEvents
Trafo
¶
Bases: DAEModel
Source code in src/tops/dyn_models/trafos.py
bus_idx
instance-attribute
¶
bus_idx = np.array(
np.zeros(self.n_units),
dtype=[
(key, int) for key in self.bus_ref_spec().keys()
],
)
bus_idx_red
instance-attribute
¶
bus_idx_red = np.array(
np.zeros(self.n_units),
dtype=[
(key, int) for key in self.bus_ref_spec().keys()
],
)
bus_ref_spec
¶
admittance_change
¶
Change in the reduced admittance matrix when connecting (sign=1) or disconnecting (sign=-1) a transformer.
Source code in src/tops/dyn_models/trafos.py
init_extras
¶
Source code in src/tops/dyn_models/trafos.py
load_flow_adm
¶
Source code in src/tops/dyn_models/trafos.py
dyn_const_adm
¶
i_from
¶
i_to
¶
I_from
¶
I_to
¶
s_from
¶
s_to
¶
p_from
¶
p_to
¶
q_from
¶
q_to
¶
s_line
¶
p_line
¶
q_line
¶
DynTrafo
¶
Bases: Trafo
Source code in src/tops/dyn_models/trafos.py
input_list
¶
load_flow_adm
¶
Source code in src/tops/dyn_models/trafos.py
admittance_change
¶
init_from_load_flow
¶
dyn_const_adm
¶
dyn_var_adm
¶
Source code in src/tops/dyn_models/trafos.py
i_from
¶
Source code in src/tops/dyn_models/trafos.py
i_to
¶
Source code in src/tops/dyn_models/trafos.py
shunts
¶
Shunt
¶
Bases: DAEModel
Source code in src/tops/dyn_models/shunts.py
bus_idx
instance-attribute
¶
bus_idx = np.array(
np.zeros(self.n_units),
dtype=[
(key, int) for key in self.bus_ref_spec().keys()
],
)
bus_idx_red
instance-attribute
¶
bus_idx_red = np.array(
np.zeros(self.n_units),
dtype=[
(key, int) for key in self.bus_ref_spec().keys()
],
)
bus_ref_spec
¶
reduced_system
¶
load_flow_adm
¶
vsc
¶
VSC
¶
Bases: DAEModel
Grid-following voltage source converter, modelled as a controlled current source.
The active and reactive power injected at the terminal bus are measured and controlled by PI
regulators. The outputs of the regulators, filtered by the time constant T_i, give the
d- and q-axis currents, which are aligned with the voltage angle estimated by a PLL
(PLL1).
Quantities are in physical units, not per unit: power in MW and Mvar, current in kA and voltage in kV. The gains of the regulators are thus in kA/MW (kA/Mvar).
Parameters (columns in the model dict):
bus: Terminal bus.T_pll: Time constant of the PLL angle filter [s].T_i: Time constant of the current response [s].P_K_p,P_K_i: Proportional and integral gain of the active power regulator.Q_K_p,Q_K_i: Proportional and integral gain of the reactive power regulator.P_setp,Q_setp: Initial active [MW] and reactive [Mvar] power setpoints. Positive values are injected into the grid. The setpoints are inputs, which can be changed during the simulation withset_input.
Source code in src/tops/dyn_models/vsc.py
bus_idx
instance-attribute
¶
bus_idx = np.array(
np.zeros(self.n_units),
dtype=[
(key, int) for key in self.bus_ref_spec().keys()
],
)
bus_idx_red
instance-attribute
¶
bus_idx_red = np.array(
np.zeros(self.n_units),
dtype=[
(key, int) for key in self.bus_ref_spec().keys()
],
)
bus_ref_spec
¶
add_blocks
¶
Source code in src/tops/dyn_models/vsc.py
I_inj
¶
input_list
¶
S
¶
Complex power [MVA] injected into the terminal bus.
P
¶
Q
¶
load_flow_pq
¶
init_from_load_flow
¶
Source code in src/tops/dyn_models/vsc.py
pll
¶
PLL1
¶
Bases: DAEModel
Source code in src/tops/dyn_models/pll.py
bus_idx
instance-attribute
¶
bus_idx = np.array(
np.zeros(self.n_units),
dtype=[
(key, int) for key in self.bus_ref_spec().keys()
],
)
bus_idx_red
instance-attribute
¶
bus_idx_red = np.array(
np.zeros(self.n_units),
dtype=[
(key, int) for key in self.bus_ref_spec().keys()
],
)
bus_ref_spec
¶
add_blocks
¶
Source code in src/tops/dyn_models/pll.py
freq_est
¶
PLL2
¶
Bases: PLL1
Source code in src/tops/dyn_models/pll.py
bus_idx
instance-attribute
¶
bus_idx = np.array(
np.zeros(self.n_units),
dtype=[
(key, int) for key in self.bus_ref_spec().keys()
],
)
bus_idx_red
instance-attribute
¶
bus_idx_red = np.array(
np.zeros(self.n_units),
dtype=[
(key, int) for key in self.bus_ref_spec().keys()
],
)
bus_ref_spec
¶
add_blocks
¶
Source code in src/tops/dyn_models/pll.py
utils
¶
AlgebraicLoopError
¶
Bases: RuntimeError
Raised when an output depends on itself without passing through a state.
DAEModel
¶
Base class for dynamic models.
Parameters are given in one of three ways: as a structured array (par), as keyword arguments with one array per parameter (e.g. Gain(K=k)), or as the number of units (n_units) for models without parameters.
Source code in src/tops/dyn_models/utils.py
par
instance-attribute
¶
par = dps_uf.structured_array_from_list(
names=["name"],
entries=[(type(self).__name__,)] * n_units,
)
idx
instance-attribute
¶
state_desc
instance-attribute
¶
state_desc = np.vstack(
[
np.repeat(self.par["name"], self.n_states),
np.tile(self.state_list(), self.n_units),
]
).T
state_idx
instance-attribute
¶
state_idx_global
instance-attribute
¶
state_idx_global = np.zeros(
(self.n_units,),
dtype=[(state, int) for state in self.state_list()],
)
events
instance-attribute
¶
blocks
property
¶
Blocks (sub-models) of the model, by attribute name, in the order they were created.
state_list
¶
Returns list of states for dynamic model. Should be overwritten (if model has one or more states)
input_list
¶
Returns list of inputs for dynamic model. Should be overwritten (if model has one or more inputs)
output_list
¶
Returns list of outputs for dynamic model, i.e. names of functions f(x, v) of the model that other models connect to. Should be overwritten (if model has one or more outputs).
Within store_outputs, each listed output is computed once per evaluation and the stored
value is returned on later calls. A listed output that depends on itself without passing
through a state (an algebraic loop) raises AlgebraicLoopError. Outputs may be methods or
functions assigned in add_blocks (e.g. self.output = lambda x, v: ...), but should
not be reassigned after the model is created.
Source code in src/tops/dyn_models/utils.py
all_outputs
¶
Outputs listed by output_list() of the model's class and all its base classes. A
mixin's list is thereby not hidden by another, e.g. for class MyAVR(DAEModel, AVR),
where DAEModel.output_list() comes before AVR.output_list().
Source code in src/tops/dyn_models/utils.py
reset_outputs
¶
set_input
¶
Set the value of an input. Units where the input is connected to another model's output are not affected, since their value is given by the connection.
Source code in src/tops/dyn_models/utils.py
disconnect_input
¶
Make the input read its value from _input_values (set with set_input), replacing any connection. Set on the instance, so that other instances and the class are not affected.
Source code in src/tops/dyn_models/utils.py
add_blocks
¶
Create blocks (sub-models) by assigning them to attributes, e.g. self.gain = Gain(...). Should be overwritten (if model has blocks).
update_block_names
¶
Name the blocks (recursively) after their attribute, e.g. 'AVR1/gain' or 'VSC1/pll/filter'.
Source code in src/tops/dyn_models/utils.py
parse_input_data
¶
Read parameters from kwargs, with one array (with one value per unit) per parameter.
Source code in src/tops/dyn_models/utils.py
local_view
¶
read_connected
¶
In-service flags of the branches of a model table; all connected if it has no such column.
Source code in src/tops/dyn_models/utils.py
determine_connections
¶
Resolve the connections declared by each model's connections() method.
A connection is declared on one model (the local side) and points to models in another
container (the remote side), either as a 'source' (remote output -> local input) or as a
'destination' (local output -> remote input). The 'id' list of the connection is aligned
with the local model's units and is looked up among the remote models' names.
With order_by='input' the result is {dest_mdl: {input: [entry, ...]}} where each entry
names the source model and output. With order_by='output' it is
{source_mdl: {output: [entry, ...]}} where each entry names the destination model and input.
Source code in src/tops/dyn_models/utils.py
get_submodules
¶
Return mdl followed by all its blocks (recursively), in the order they were created.
output
¶
Deprecated: list the output in the model's output_list() instead.
Outputs in output_list() are stored and checked for algebraic loops by DAEModel (see
DAEModel.output_list). The decorator returns f unchanged.
Source code in src/tops/dyn_models/utils.py
store_outputs
¶
Within the context, each output (in output_list) of the models is computed once and then stored. Should be entered for each evaluation, since stored outputs do not depend on (x, v).
Source code in src/tops/dyn_models/utils.py
summation
¶
Creates a new function which sums the output of functions and constants/ constant arrays specified as arguments
Source code in src/tops/dyn_models/utils.py
auto_init
¶
Numerically initialize mdl (including its submodules) to a steady state.
Solves for the states and the given free_inputs such that all state derivatives are zero
and mdl.output equals output_0. Each unit is solved separately, since the units of a
model are independent (all model equations are elementwise over units). This keeps the number
of free variables per solve at n_states_per_unit + len(free_inputs), regardless of
n_units. The residual is still evaluated for all units (the models are vectorized), but only
the entries of the unit being solved are used.
free_inputs are inputs of mdl that are not connected to other models (typically a
'bias' input). Their solved values are stored in mdl._input_values.