Basics

class rtctools.simulation.simulation_problem.SimulationProblem(**kwargs)[source]

Bases: DataStoreAccessor

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()[source]

Return current time of simulation.

Returns:

The current simulation time.

get_end_time()[source]

Return end time of experiment.

Returns:

The end time of the experiment.

get_start_time()[source]

Return start time of experiment.

Returns:

The start time of the experiment.

get_var(name)[source]

Return a numpy array from FMU.

Parameters:

name – Variable name.

Returns:

The value of the variable.

get_var_count()[source]

Return the number of variables in the model.

Returns:

The number of variables in the model.

get_var_name(i)[source]

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)[source]

Not implemented

get_var_shape(name)[source]

Not implemented

get_var_type(name)[source]

Return type, compatible with numpy.

Parameters:

name – String variable name.

Returns:

The numpy-compatible type of the variable.

Raises:

KeyError

get_variables()[source]

Return all variables (both internal and user defined)

Returns:

An ordered dictionary of all variables supported by the model.

initialize(config_file=None)[source]

Initialize state vector with default values

Initial values are first read from the given Modelica files. If an initial value equals zero or is not provided by a Modelica file, and the variable is not marked as fixed, then the initial value is tried to be set with the initial_state method. When using CSVMixin, this method by default looks for initial values in an initial_state.csv file. Furthermore, if a variable is not marked as fixed and no initial value is given by the initial_state method, the initial value can be overwritten using the seed method. When a variable is marked as fixed, the initial value is only read from the Modelica file.

Parameters:

config_file – Path to an initialization file.

post()[source]

Any postprocessing takes place here.

pre()[source]

Any preprocessing takes place here.

reset()[source]

Reset the FMU.

setup_experiment(start, stop, dt)[source]

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()[source]

Run model from start_time to end_time.

update(dt)[source]

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, **kwargs)[source]

Sets up and runs a simulation problem.

Parameters:
  • simulation_problem_class – Simulation 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.