pyfmu.fmi2.fmi2slave

Module Contents

pyfmu.fmi2.fmi2slave._slave_configuration_name = slave_configuration.json
pyfmu.fmi2.fmi2slave._internal_log_catergory = fmi2slave
pyfmu.fmi2.fmi2slave._internal_throw_category
pyfmu.fmi2.fmi2slave._internal_invalid_status_category
pyfmu.fmi2.fmi2slave._logging_override_name = pyfmu_log_all_override
pyfmu.fmi2.fmi2slave.log
pyfmu.fmi2.fmi2slave._uninitialized_variables_status
pyfmu.fmi2.fmi2slave._read_wrong_type_status
pyfmu.fmi2.fmi2slave._invalid_fmi_invalid_arguments
pyfmu.fmi2.fmi2slave._invalid_return_type_status
pyfmu.fmi2.fmi2slave._invalid_external_call_status
class pyfmu.fmi2.fmi2slave._Fmi2SlaveErrorDefinitions

Bases: enum.Enum

Defines which FMI2 error codes should be raised in response to various inconsistencies

uninitialized_variables
internal_log_catergory = fmi2slave
class pyfmu.fmi2.fmi2slave.Fmi2Slave(modelName: str, author='', copyright='', version='', description='', logging_callback=None, logging_logAll=False, logging_stdout=False, logging_add_standard_categories=True, logging_slave_fmi_calls=True, check_uninitialized_variables=True)
_configure(self)

Performs configuration of the FMI slave based on the contents of the slave configuration file.

The configuration function is only available for Fmi2Slaves which are running from inside an FMU, e.g. they have a slave_configuration.json

Options:
  1. Logging, allows the user to override log settings.

_set_resources_path(self, path)

Called by the wrapper to set the path to resource folder.

This is used for configuration.

Arguments:

path {[str]} – Path to the resources folder

_is_running_as_project(self)

Returns true if the Fmi2Slave is running inside a project that has not yet been exported.

_is_running_as_fmu(self)

Returns true if the FMI2Slave is running from inside an exported FMU

register_variable(self, name: str, data_type: Fmi2DataTypes = None, causality=Fmi2Causality.local, variability=Fmi2Variability.continuous, initial: Fmi2Initial = None, start=None, description: str = '', define_attribute: bool = True, value_reference: int = None)

Add a variable to the model such as an input, output or parameter.

Arguments:

name {str} – [description] data_type {Fmi2DataTypes} – [description]

Keyword Arguments:

causality {[type]} – defines the type of the variable, such as input, output or parameter (default: {Fmi2Causality.local}) variability {[type]} – defines the time dependency of the variable. (default: {Fmi2Variability.continuous}) initial {Fmi2Initial} – defines how the variable is initialized (default: {None}) start {[type]} – start value of the variable. (default: {None}) description {str} – a description of the variable which is added to the model description (default: {“”}) define_attribute {bool} – if true, automatically add the specified attribute to instance if it does not already exist. (default: {True})

Inference Rules:
i1. shorthands and aliases:

data_type,causality,initial and variablity can be defined using string shorthands.

i2. default start values:

if data_type is defined but start is undefined, default values are used based on data_type

i3. data type inference:

if data_type is undefined but start is defined, data_type is inferred from start’s type.

i4. initial based on causality and variability (2.2.7 p.49)
Default initial are defined based on the combination of causality and variability:
  • exact : constant[local|output], [fixed|tunable]parameter

  • calculated : [fixed|tunable][calculatedParameter|local], [continous|discrete][local|output]

  • (do not define) : [discrete|continuous]input, continous independent.

Validation Rules:
v1: data type and causality (2.2.7 p.48)

only real valued variables may have causality continuous

v2: causality and variablity (2.2.7 p.48-49)

Only the following combinations of variability and causality are allowed: * calculatedParameter: {fixed,tunable} * independent: {continuous} * input : {continuous,discrete} * local : {continuous,constant,discrete,fixed,tuneable} * output : {continuous,constant,discrete} * parameter : {fixed,tuneable}

v3: initial allowed (2.2.7 p.49)

Only certain certain intials are allowed for a given combination of varability and causality.

v4: should define start (2.2.7 p.47)

Only certain combinations of causality, intial are allowed to provide start values. * [exact|approx] -> must define start * calculated -> must not define start *

Ordering: i1 -> i2 -> i3 -> v2 -> i4 -> v1 -> v3

register_log_category(self, name: str)

Registers a new log category which will be visible to the simulation tool.. This information is used by co-simulation engines to filter messages.

Arguments:

name {str} – name of the category.

Examples:

``` self.register_log_category(‘runtime validation’)

```

_acquire_unused_value_reference(self)

Returns the an unused value reference

_setup_experiment(self, start_time: float, tolerance: float = None, stop_time: float = None)
setup_experiment(self, start_time: float, tolerance: float = None, stop_time: float = None)
_enter_initialization_mode(self)
enter_initialization_mode(self)
_exit_initialization_mode(self)
exit_initialization_mode(self)
_do_step(self, current_time: float, step_size: float, no_set_fmu_state_prior: bool)
do_step(self, current_time: float, step_size: float, no_set_fmu_state_prior: bool)
_reset(self)
reset(self)
_terminate(self)
terminate(self)
_set_debug_logging(self, logging_on: bool, categories: Iterable[str])
set_debug_logging(self, logging_on: bool, categories: Iterable[str])

Defines the set of active log categories for which log messages will logged. Messages logged to any other categories will be ignored.

This function is called by the tool though the fmi2SetDebugLogging function.

Note that the tool can only “see” categories registered in the model description using the register_log_category.

Arguments:

categories {Iterable[str]} – a set of categories which are set to be active logging_on {bool} – if true, enable the categories, otherwise disable them

Defaults category mapping:

FMI2 specifies several standardized categories.

  • logEvents : Log all events (during initialization and simulation).

  • logSingularLinearSystemsLog the solution of linear systems of equations if the solution is singular

    (and the tool picked one solution of the infinitely many solutions).

  • logNonlinearSystems : Log the solution of nonlinear systems of equations.

  • logDynamicStateSelection : Log the dynamic selection of states.

  • logStatusWarning : Log messages when returning fmi2Warning status from any function.

  • logStatusDiscard : Log messages when returning fmi2Discard status from any function.

  • logStatusError : Log messages when returning fmi2Error status from any function.

  • logStatusFatal : Log messages when returning fmi2Fatal status from any function.

  • logStatusPending : Log messages when returning fmi2Pending status from any function.

  • logAll : Log all messages.

The standard standard leaves it up to the implementation to decide which “categories” map to each of the log-categories.

` Python self.log(Fmi2Status.OK,"events","initialized FMU") `

Examples: ``` Python

# standard logging fmu = MyFMU() fmu.standard_log_catgories() fmu._set_debug_logging({‘LogAll’})

fmu.log(Fmi2Status.ok,’logEvents’,)

```

_get_xxx(self, vrs, values, data_type: Fmi2DataTypes)
_get_integer(self, vrs, values)
get_integer(self, vrs, values)
_get_real(self, vrs, values)
get_real(self, vrs, values)
_get_boolean(self, vrs, values)
get_boolean(self, vrs, values)
_get_string(self, vrs, values)
get_string(self, vrs, values)
_set_xxx(self, vrs, values, data_type: Fmi2DataTypes)

Generic implementation of setter methods used for set_real, set_integer, set_boolean and set_string

Arguments:

vrs {List[int]} – List of value references of the variables to be set values {List[]} – List of the values which must be assigned to the specified references. data_type {Fmi2DataTypes} – The datatype “expected” data type of the variable, used for validation.

Returns:

[FmiStatus] – a status indicating whether the call was succesful

_set_integer(self, vrs, values)
set_integer(self, vrs, values)
_set_real(self, vrs, values)
set_real(self, vrs, values)
_set_boolean(self, vrs, values)
set_boolean(self, vrs, values)
_set_string(self, vrs, values)
set_string(self, vrs, values)
_do_fmi_call(self, f, *args, **kwargs)

Performs the call to the fmi function implemented by the subclass and returns the status.

Purpose of the function is: 1. logging of the function calls 2. handle exceptions in implementation 3. convert return values to FMI status values

Arguments:

f {[type]} – the function to be invoked.

_define_variable(self, sv: Fmi2ScalarVariable)
_do_check_variable_initialization(self)

Check if variables with initial “calculated” and “approx” are initialized correctly.

log(self, message: str, category=None, status=Fmi2Status.ok)

Logs a message to the fmi interface.

Note that only categories which are set as active using the __set_debug_logging__, are propageted to the tool. The function is called by the tool using with the categories which the user wishes to be active.

Arguments:

status {Fmi2Status} – The current status of the FMU. category {str} – The category of the log message. message {str} – The log message itself.

Logging categories mappings:

_format_exc(self)
property available_categories(self)