Basics

class rtctools.simulation.simulation_problem.SimulationProblem(**kwargs)

Bases: object

Implements the BMI Interface.

Base class for all Simulation problems. Loads the Modelica Model.

Variables:modelica_library_folders – Folders containing any referenced Modelica libraries. Default is an empty list.
get_current_time()

Return current time of simulation.

Returns:The current simulation time.
get_end_time()

Return end time of experiment.

Returns:The end time of the experiment.
get_start_time()

Return start time of experiment.

Returns:The start time of the experiment.
get_var(name)

Return a numpy array from FMU.

Parameters:name – Variable name.
Returns:The value of the variable.
get_var_count()

Return the number of variables in the model.

Returns:The number of variables in the model.
get_var_name(i)

Returns the name of a variable.

Parameters:i – Index in ordered dictionary returned by method get_variables.
Returns:The name of the variable.
get_var_rank(name)

Not implemented

get_var_shape(name)

Not implemented

get_var_type(name)

Return type, compatible with numpy.

Parameters:name – String variable name.
Returns:The numpy-compatible type of the variable.
Raises:KeyError
get_variables()

Return all variables (both internal and user defined)

Returns:An ordered dictionary of all variables supported by the model.
initialize(config_file=None)

Initialize state vector with default values

Parameters:config_file – Path to an initialization file.
post()

Any postprocessing takes place here.

pre()

Any preprocessing takes place here.

reset()

Reset the FMU.

setup_experiment(start, stop, dt)

Method for subclasses (PIMixin, CSVMixin, or user classes) to set timing information for a simulation run.

Parameters:
  • start – Start time for the simulation.
  • stop – Final time for the simulation.
  • dt – Time step size.
simulate()

Run model from start_time to end_time.

update(dt)

Performs one timestep.

The methods setup_experiment and initialize must have been called before.

Parameters:dt – Time step size.
rtctools.util.run_simulation_problem(simulation_problem_class, base_folder='..', log_level=20)

Sets up and runs a simulation problem.

Parameters:
  • simulation_problem_class – Optimization problem class to solve.
  • base_folder – Folder within which subfolders “input”, “output”, and “model” exist, containing input and output data, and the model, respectively.
  • log_level – The log level to use.
Returns:

SimulationProblem instance.