Modelling¶
- class hilo_mpc.Model(id=None, name=None, discrete=False, solver=None, solver_options=None, time_unit='h', plot_backend=None)[source]¶
Class representing the dynamic model of a system over time
- Parameters:
id (str, optional) – The identifier of the model object. If no identifier is given, a random one will be generated.
name (str, optional) – The name of the model object. By default the model object has no name.
discrete (bool, optional) – Whether or not the dynamics of the model are discrete, defaults to False (i.e. the model has continuous-time dynamics)
solver (str, optional) – Name of the solver to be used for continuous-time integration, defaults to ‘cvodes’ if discrete is set to False. If discrete is set to True the argument solver will not be used.
solver_options (dict, optional) – Options to be passed to the selected solver. Only used when the model has continuous-time dynamics. By default no options will be set.
time_unit (str) – The time unit of the model. Common time units are seconds (‘s’), hours (‘h’) or days (‘d’). Will only be used for plotting and as an information storage. Defaults to ‘h’.
plot_backend (str, optional) – Plotting library that is used to visualize simulated data. At the moment only Matplotlib and Bokeh are supported. By default no plotting library is selected, i.e. no plots can be generated.
- add_algebraic_equations(equations, position=None, check_properties=False)¶
- Parameters:
equations –
position –
check_properties –
- Returns:
- add_algebraic_states(states, position=None)¶
- Parameters:
states –
position –
- Returns:
- add_dynamical_equations(equations, position=None, check_properties=False)¶
- Parameters:
equations –
position –
check_properties –
- Returns:
- add_dynamical_states(states, position=None)¶
- Parameters:
states –
position –
- Returns:
- add_equations(equations=None, **kwargs)¶
- Parameters:
equations –
kwargs –
- Returns:
- add_inputs(inputs, position=None)¶
- Parameters:
inputs –
position –
- Returns:
- add_measurement_equations(equations, position=None, check_properties=False)¶
- Parameters:
equations –
position –
check_properties –
- Returns:
- add_measurements(measurements, position=None)¶
- Parameters:
measurements –
position –
- Returns:
- add_options(opts=None, keys=None, values=None)¶
- Parameters:
opts –
keys –
values –
- Returns:
- add_parameters(parameters, position=None, **kwargs)¶
- Parameters:
parameters –
position –
kwargs –
- Returns:
- check_consistency()¶
- Returns:
- check_solver(solver)¶
- Parameters:
solver –
- Returns:
- discretize(method, order=None, butcher_tableau=None, degree=None, polynomial_type=None, inplace=False)[source]¶
Discretize a continuous-time model. Implemented discretization methods are explicit Runge-Kutta and collocation schemes.
- Note:
The
discretize()
method doesn’t require a numerical sampling time ‘dt’, since the discretization is executed symbolically.- Note:
If the model is already discrete, an according message will be displayed and the discretization attempt will be aborted.
- Parameters:
method (str) – The method used for discretization. At the moment only explicit Runge-Kutta methods and collocation schemes are supported. Accepted values are ‘rk4’ for the most widely known 4th order Runge-Kutta method, ‘erk’ for general order explicit Runge-Kutta methods and ‘collocation’ for the implicit collocation methods.
order (int, optional) – Order of the explicit Runge-Kutta method ‘erk’. Supported orders are 1 to 4. Will be ignored if ‘rk4’ or ‘collocation’ is selected. Defaults to 1 for ‘erk’.
butcher_tableau (str, optional) – The Butcher tableau used in the discretization with the explicit Runge-Kutta method ‘erk’. Will be ignored if ‘rk4’ or ‘collocation’ is selected. The default value of the Butcher tableau depends on the order of the explicit Runge-Kutta method. For more information on the Butcher tableau refer to the Modules section.
degree (int, optional) – Degree of the interpolating polynomial used in the collocation method. Will be ignored if ‘erk’ or ‘rk4’ is selected. Defaults to 2 for ‘collocation’.
polynomial_type (str, optional) – Polynomial used for calculating the collocation points, i.e. the roots of the polynomial. At the moment only Gauss-Legendre polynomials and Gauss-Radau polynomials are supported. Set polynomial_type to ‘legendre’ for Gauss-Legendre polynomials and to ‘radau’ for Gauss-Radau polynomials. Will be ignored if ‘erk’ or ‘rk4’ is selected. Defaults to ‘radau’ for ‘collocation’.
inplace (bool) – If True, do discretization on the current
Model
instance and return None, otherwise a new discretizedModel
instance will be returned. Defaults to False.
- Returns:
If argument inplace was set to True a new
Model
instance will be returned, otherwise None
- is_linear()¶
- Returns:
- is_linearized()¶
- Returns:
- is_time_variant()¶
- Returns:
- remove_algebraic_equations(indices, check_properties=False)¶
- Parameters:
indices –
check_properties –
- Returns:
- remove_algebraic_states(indices_or_names)¶
- Parameters:
indices_or_names –
- Returns:
- remove_dynamical_equations(indices, check_properties=False)¶
- Parameters:
indices –
check_properties –
- Returns:
- remove_dynamical_states(indices_or_names)¶
- Parameters:
indices_or_names –
- Returns:
- remove_equations(ode=None, alg=None, quad=None, meas=None)¶
- Parameters:
ode –
alg –
quad –
meas –
- Returns:
- remove_inputs(indices_or_names)¶
- Parameters:
indices_or_names –
- Returns:
- remove_measurement_equations(indices, check_properties=False)¶
- Parameters:
indices –
check_properties –
- Returns:
- remove_measurements(indices_or_names)¶
- Parameters:
indices_or_names –
- Returns:
- remove_options(keys)¶
- Parameters:
keys –
- Returns:
- remove_parameters(indices_or_names)¶
- Parameters:
indices_or_names –
- Returns:
- reset()¶
- Returns:
- reset_solution(keep_initial_conditions=True, keep_equilibrium_point=True)[source]¶
- Parameters:
keep_initial_conditions –
keep_equilibrium_point –
- Returns:
- scale(value, id=None, name=None)¶
- Parameters:
value –
id –
name –
- Returns:
- set_algebraic_equations(arg, delimiter=None, check_properties=False)¶
- Parameters:
arg –
delimiter –
check_properties –
- Returns:
- set_algebraic_states(*args, **kwargs)¶
- Parameters:
args –
kwargs –
- Returns:
- set_dynamical_equations(arg, delimiter=None, check_properties=False)¶
- Parameters:
arg –
delimiter –
check_properties –
- Returns:
- set_dynamical_states(*args, description=None, labels=None, units=None, **kwargs)¶
Sets the dynamical state vector of the model
- Parameters:
args – Possible combinations of how to supply arguments to this method can be taken from the table
description (str, sequence of str, optional) – Description of the single elements of the dynamical state vector. If only a single description is supplied, but the vector has a dimension higher than 1, it is assumed that all the elements of the vector have the same description. This is just for convenience, since the information stored in the description will not be used anywhere else.
labels (str, sequence of str, optional) – Labels of the single elements of the dynamical state vector. If only a single label is supplied, but the vector has a dimension higher than 1, it is assumed that all the elements of the vector have the same label. At the moment the label information is only used for automatically generating the y-axis labels for the plotting functionality.
units (str, sequence of str, optional) – Units of the single elements of the dynamical state vector. If only a single unit is supplied, but the vector has a dimension higher than 1, it is assumed that all the elements of the vector have the same unit. At the moment the unit information is only used for automatically generating the y-axis labels for the plotting functionality.
kwargs (str, optional) – Additional keyword arguments, see table
- Returns:
Differential state vector of the model as a symbolic expression
- Return type:
casadi.casadi.SX
|casadi.casadi.MX
args
kwargs
list of each state variable (sequence of str)
–
dimension of state vector (int)
name of state vector (str)
- set_equations(equations=None, **kwargs)¶
- Parameters:
equations –
kwargs –
- Returns:
- set_inputs(*args, **kwargs)¶
- Parameters:
args –
kwargs –
- Returns:
- set_measurement_equations(arg, delimiter=None, check_properties=False)¶
- Parameters:
arg –
delimiter –
check_properties –
- Returns:
- set_measurements(*args, **kwargs)¶
- Parameters:
args –
kwargs –
- Returns:
- set_parameters(*args, **kwargs)¶
- Parameters:
args –
kwargs –
- Returns:
- substitute(*args, **kwargs)¶
- Parameters:
args –
kwargs –
- Returns:
- substitute_from(obj)¶
- Parameters:
obj –
- Returns:
- property algebraic_equations¶
- Returns:
- property algebraic_state_description¶
- Returns:
- property algebraic_state_names¶
- Returns:
- property algebraic_state_units¶
- Returns:
- property algebraic_states¶
- Returns:
- property continuous¶
- Returns:
- property discrete¶
- Returns:
- property dynamical_equations¶
- Returns:
- property dynamical_state_description¶
- Returns:
- property dynamical_state_names¶
- Returns:
- property dynamical_state_units¶
- Returns:
- property dynamical_states¶
Differential state vector of the model
- Returns:
Differential state vector of the model as a symbolic expression
- Return type:
casadi.casadi.SX
|casadi.casadi.MX
- Alias:
x
- property feedthrough_matrix¶
- Returns:
- property initial_algebraic_states¶
- Returns:
- property initial_dynamical_states¶
- Returns:
- property initial_time¶
- Returns:
- Return type:
DM
- property input_description¶
- Returns:
- property input_matrix¶
- Returns:
- property input_names¶
- Returns:
- property input_units¶
- Returns:
- property inputs¶
- Returns:
- property measurement_description¶
- Returns:
- property measurement_equations¶
- Returns:
- property measurement_names¶
- Returns:
- property measurement_units¶
- Returns:
- property measurements¶
- Returns:
- property n_p¶
- Returns:
- property n_u¶
- Returns:
- property n_x¶
- Returns:
- property n_y¶
- Returns:
- property n_z¶
- Returns:
- property options¶
- Returns:
- property output_matrix¶
- Returns:
- property parameter_description¶
- Returns:
- property parameter_names¶
- Returns:
- property parameter_units¶
- Returns:
- property parameters¶
- Returns:
- property sampling_time¶
Sampling time variable of the model
- Returns:
Sampling time variable of the model as a symbolic expression
- Return type:
casadi.casadi.SX
|casadi.casadi.MX
- Alias:
dt
- property solution¶
- Returns:
- property solver¶
- Returns:
- property state_matrix¶
- Returns:
- property time¶
Time variable of the model
- Returns:
Time variable of the model as a symbolic expression
- Return type:
casadi.casadi.SX
|casadi.casadi.MX
- Alias:
t