PyFMI Folder

Base pyfmi

The JModelica.org Python package for working with FMI <http:/www.jmodelica.org/>

Module fmi

Module containing the FMI interface Python wrappers.

class pyfmi.fmi.DeclaredType2

Bases: object

Class defining data structure based on the XML element Type.

description

Get the value of the description attribute.

Returns:

The description attribute value as string (empty string if
not set).
name

Get the value of the name attribute.

Returns:

The name attribute value as string.
class pyfmi.fmi.EnumerationType2

Bases: pyfmi.fmi.DeclaredType2

Class defining data structure based on the XML element Enumeration.

items

Get the items of the enumeration type.

Returns:

The items of the enumeration type as a dict. The key is the
enumeration value and the dict value is a tuple containing
the name and description of the enumeration item.
quantity

Get the quantity of the enumeration type.

Returns:

The quantity as string (empty string if
not set).
exception pyfmi.fmi.FMUException

Bases: exceptions.Exception

An FMU exception.

class pyfmi.fmi.FMUModel

Bases: pyfmi.fmi.FMUModelME1

class pyfmi.fmi.FMUModelBase

Bases: pyfmi.fmi.ModelBase

An FMI Model loaded from a DLL.

get_author()

Return the name and organization of the model author.

get_boolean()

Returns the boolean-values from the valuereference(s).

Parameters:

valueref --
    A list of valuereferences.

Returns:

values --
    The values retrieved from the FMU.

Example:

val = model.get_boolean([232])

Calls the low-level FMI function: fmiGetBoolean

get_default_experiment_start_time()

Returns the default experiment start time as defined the XML description.

get_default_experiment_stop_time()

Returns the default experiment stop time as defined the XML description.

get_default_experiment_tolerance()

Returns the default experiment tolerance as defined in the XML description.

get_description()

Return the model description.

get_generation_tool()

Return the model generation tool.

get_guid()

Return the model GUID.

get_identifier()

Return the model identifier, name of binary model file and prefix in the C-function names of the model.

get_integer()

Returns the integer-values from the valuereference(s).

Parameters:

valueref --
    A list of valuereferences.

Return:

values --
    The values retrieved from the FMU.

Example:

val = model.get_integer([232])

Calls the low-level FMI function: fmiGetInteger

get_model_time_varying_value_references()

Extract the value references of the variables in a model that are time-varying. This method is typically used to retrieve the variables for which the result can be stored.

Parameters:

filter --
    Filter the variables using a unix filename pattern
    matching (filter="*der*"). Can also be a list of filters
    See http://docs.python.org/2/library/fnmatch.html.
    Default None

Returns:

Three lists with the real, integer and boolean value-references
get_model_variables()

Extract the names of the variables in a model.

Parameters:

type --
    The type of the variables (Real==0, Int==1, Bool=2,
    String==3, Enumeration==4). Default None (i.e all).
include_alias --
    If alias should be included or not. Default True
causality --
    The causality of the variables (Input==0, Output==1,
    Internal==2, None==3). Default None (i.e all).
variability --
    The variability of the variables (Constant==0,
    Parameter==1, Discrete==2, Continuous==3). Default None
    (i.e. all)
only_start --
    If only variables that has a start value should be
    returned. Default False
only_fixed --
    If only variables that has a start value that is fixed
    should be returned. Default False
filter --
    Filter the variables using a unix filename pattern
    matching (filter="*der*"). Can also be a list of filters
    See http://docs.python.org/2/library/fnmatch.html.
    Default None

Returns:

Dict with variable name as key and a ScalarVariable class as
value.
get_name()

Return the model name as used in the modeling environment.

get_ode_sizes()

Returns the number of continuous states and the number of event indicators.

Returns:

nbr_cont --
    The number of continuous states.

nbr_ind --
    The number of event indicators.

Example:

[nCont, nEvent] = model.get_ode_sizes()
get_real()

Returns the real-values from the valuereference(s).

Parameters:

valueref --
    A list of valuereferences.

Returns:

values --
    The values retrieved from the FMU.

Example:

val = model.get_real([232])

Calls the low-level FMI function: fmiGetReal

get_scalar_variable()

Get the variable as a scalar variable instance.

Parameter:

variable_name --
    The name of the variable.

Returns:

Instance of ScalarVariable.
get_string()

Returns the string-values from the valuereference(s).

Parameters:

valueref --
    A list of valuereferences.

Returns:

values --
    The values retrieved from the FMU.

Example:

val = model.get_string([232])

Calls the low-level FMI function: fmiGetString

get_variable_alias()

Return a dict of all alias variables belonging to the provided variable where the key are the names and the value indicating whether the variable should be negated or not.

Returns:

A dict consisting of the alias variables along with no alias variable.
The values indicates wheter or not the variable should be negated or not.

Raises:

FMUException if the variable is not in the model.
get_variable_alias_base()

Returns the base variable for the provided variable name.

Parameters:

variable_name--
    Name of the variable.

Returns:

The base variable.
get_variable_by_valueref()

Get the name of a variable given a value reference. Note that it returns the no-aliased variable.

Parameters:

valueref --
    The value reference of the variable

type --
    The type of the variables (Real==0, Int==1, Bool=2,
    String==3, Enumeration==4). Default 0 (i.e Real).
get_variable_causality()

Get the causality of the variable.

Parameters:

variable_name --
    The name of the variable.

Returns:

The variability of the variable, INPUT(0), OUTPUT(1),
INTERNAL(2), NONE(3)
get_variable_data_type()

Get data type of variable.

Parameter:

variable_name --
    The name of the variable.

Returns:

The type of the variable.
get_variable_description()

Get the description of a given variable.

Parameter:

variable_name --
    The name of the variable

Returns:

The description of the variable.
get_variable_fixed()

Returns if the start value is fixed (True - The value is used as an initial value) or not (False - The value is used as a guess value).

Parameters:

variable_name --
    The name of the variable

Returns:

If the start value is fixed or not.
get_variable_max()

Returns the maximum value for the given variable.

Parameters:

variable_name --
    The name of the variable.

Returns:

The maximum value for the variable.
get_variable_min()

Returns the minimum value for the given variable.

Parameters:

variable_name --
    The name of the variable.

Returns:

The minimum value for the variable.
get_variable_nominal()

Returns the nominal value from a real variable determined by either its value reference or its variable name.

Parameters:

variable_name --
    The name of the variable.
    
valueref --
    The value reference of the variable.

Returns:

The nominal value of the given variable.
get_variable_start()

Returns the start value for the variable or else raises FMUException.

Parameters:

variable_name --
    The name of the variable

Returns:

The start value.
get_variable_valueref()

Extract the ValueReference given a variable name.

Parameters:

variable_name --
    The name of the variable.

Returns:

The ValueReference for the variable passed as argument.
get_variable_variability()

Get variability of variable.

Parameters:

variablename --

    The name of the variable.

Returns:

The variability of the variable, CONSTANT(0), PARAMETER(1), 
DISCRETE(2) or CONTINUOUS(3)
get_version()

Returns the FMI version of the Model which it was generated according.

Returns:

version --
    The version.

Example:

model.get_version()
set_boolean()

Sets the boolean-values in the FMU as defined by the valuereference(s).

Parameters:

valueref --
    A list of valuereferences.

values --
    Values to be set.

Example:

model.set_boolean([234,235],[True,False])

Calls the low-level FMI function: fmiSetBoolean

set_debug_logging()

Specifies if the logging from the FMU should be turned on or off. Note that this only determines the output from the FMU to PyFMI which are additionally filtered using the method ‘set_log_level’. To specify actual given logging output, please use also use that method.

Parameters:

flag --
    Boolean value.

Calls the low-level FMI function: fmiSetDebuggLogging

set_fmil_log_level()
set_integer()

Sets the integer-values in the FMU as defined by the valuereference(s).

Parameters:

valueref --
    A list of valuereferences.

values --
    Values to be set.

Example:

model.set_integer([234,235],[12,-3])

Calls the low-level FMI function: fmiSetInteger

set_real()

Sets the real-values in the FMU as defined by the valuereference(s).

Parameters:

valueref --
    A list of valuereferences.

values --
    Values to be set.

Example:

model.set_real([234,235],[2.34,10.4])

Calls the low-level FMI function: fmiSetReal

set_string()

Sets the string-values in the FMU as defined by the valuereference(s).

Parameters:

valueref --
    A list of valuereferences.

values --
    Values to be set.

Example:

model.set_string([234,235],['text','text'])

Calls the low-level FMI function: fmiSetString

version

Returns the FMI version of the Model which it was generated according.

Returns:

version --
    The version.

Example:

model.version
class pyfmi.fmi.FMUModelBase2

Bases: pyfmi.fmi.ModelBase

FMI Model loaded from a dll.

deserialize_fmu_state()

De-serialize the provided byte-vector and returns the corresponding FMU-state.

Parameters:

serialized_fmu--
    A serialized FMU-state.

Returns:

A deserialized FMU-state.

Example:

FMU_state = Model.get_fmu_state()
serialized_fmu = Model.serialize_fmu_state(FMU_state)
FMU_state = Model.deserialize_fmu_state(serialized_fmu)
enter_initialization_mode()

Enters initialization mode by calling the low level FMI function fmi2EnterInitializationMode.

Note that the method initialize() performs both the enter and exit of initialization mode.

exit_initialization_mode()

Exit initialization mode by calling the low level FMI function fmi2ExitInitializationMode.

Note that the method initialize() performs both the enter and exit of initialization mode.

free_fmu_state()

Free a previously saved FMU-state from the memory.

Parameters:

state--
    A pointer to the FMU-state to be set free.

Example:

FMU_state = Model.get_fmu_state()
Model.free_fmu_state(FMU_state)
free_instance()

Calls the FMI function fmi2FreeInstance() on the FMU. Note that this is not needed generally.

get_author()

Return the name and organization of the model author.

get_boolean()

Returns the boolean-values from the valuereference(s).

Parameters:

valueref --
    A list of valuereferences.

Returns:

values --
    The values retrieved from the FMU.

Example:

val = model.get_boolean([232])

Calls the low-level FMI function: fmi2GetBoolean

get_categories()

Method used to retrieve the logging categories.

Returns:

A list with the categories available for logging.

Return the model copyright.

get_default_experiment_start_time()

Returns the default experiment start time as defined the XML description.

get_default_experiment_step()

Returns the default experiment step as defined in the XML description.

get_default_experiment_stop_time()

Returns the default experiment stop time as defined the XML description.

get_default_experiment_tolerance()

Returns the default experiment tolerance as defined in the XML description.

get_derivatives_dependencies()

Retrieve the list of variables that the derivatives are dependent on. Returns two dictionaries, one with the states and one with the inputs.

get_derivatives_list()

Returns a dictionary with the states derivatives.

Returns:

An ordered dictionary with the derivative variables.
get_description()

Return the model description.

get_directional_derivative()

Returns the directional derivatives of the functions with respect to the given variables and in the given direction. In other words, it returns linear combinations of the partial derivatives of the given functions with respect to the selected variables. The point of evaluation is the current time-point.

Parameters:

var_ref --
    A list of variable references that the partial derivatives
    will be calculated with respect to.

func_ref --
    A list of function references for which the partial derivatives will be calculated.

v --
    A seed vector specifying the linear combination of the partial derivatives.

Returns:

value --
    A vector with the directional derivatives (linear combination of
    partial derivatives) evaluated in the current time point.

Example:

states = model.get_states_list()
states_references = [s.value_reference for s in states.values()]
derivatives = model.get_derivatives_list()
derivatives_references = [d.value_reference for d in derivatives.values()]
model.get_directional_derivative(states_references, derivatives_references, v)

This returns Jv, where J is the Jacobian and v the seed vector.

Also, only a subset of the derivatives and and states can be selected:

model.get_directional_derivative(var_ref = [0,1], func_ref = [2,3], v = [1,2])

This returns a vector with two values where:

values[0] = (df2/dv0) * 1 + (df2/dv1) * 2
values[1] = (df3/dv0) * 1 + (df3/dv1) * 2
get_fmil_log_level()

Returns:

The current fmil log-level.
get_fmu_state()

Creates a copy of the recent FMU-state and returns a pointer to this state which later can be used to set the FMU to this state.

Parameters:

state --
    Optionally a pointer to an already allocated FMU state

Returns:

A pointer to a copy of the recent FMU state.

Example:

FMU_state = model.get_fmu_state()
get_generation_date_and_time()

Return the model generation date and time.

get_generation_tool()

Return the model generation tool.

get_guid()

Return the model GUID.

get_identifier()

Return the model identifier, name of binary model file and prefix in the C-function names of the model.

get_input_list()

Returns a dictionary with input variables

Returns:

An ordered dictionary with the (real) (continuous) input variables.
get_integer()

Returns the integer-values from the valuereference(s).

Parameters:

valueref --
    A list of valuereferences.

Returns:

values --
    The values retrieved from the FMU.

Example:

val = model.get_integer([232])

Calls the low-level FMI function: fmi2GetInteger

get_license()

Return the model license.

get_model_time_varying_value_references()

Extract the value references of the variables in a model that are time-varying. This method is typically used to retrieve the variables for which the result can be stored.

Parameters:

filter --
    Filter the variables using a unix filename pattern
    matching (filter="*der*"). Can also be a list of filters
    See http://docs.python.org/2/library/fnmatch.html.
    Default None

Returns:

Three lists with the real, integer and boolean value-references
get_model_types_platform()

Returns the set of valid compatible platforms for the Model, extracted from the XML.

get_model_variables()

Extract the names of the variables in a model.

Parameters:

type --
    The type of the variables (Real==0, Int==1, Bool==2,
    String==3, Enumeration==4).
    Default: None (i.e all).

include_alias --
    If alias should be included or not.
    Default: True

causality --
    The causality of the variables (Parameter==0, 
    Calculated Parameter==1, Input==2, Output==3, Local==4, 
    Independent==5, Unknown==6).
    Default: None (i.e all).

variability --
    The variability of the variables (Constant==0,
    Fixed==1, Tunable==2, Discrete==3, Continuous==4, Unknown==5).
    Default: None (i.e. all)

only_start --
    If only variables that has a start value should be
    returned.
    Default: False

only_fixed --
    If only variables that has a start value that is fixed
    should be returned.
    Default: False

filter --
    Filter the variables using a unix filename pattern
    matching (filter="*der*"). Can also be a list of filters
    See http://docs.python.org/2/library/fnmatch.html.
    Default None

Returns:

Dict with variable name as key and a ScalarVariable class as
value.
get_model_version()

Returns the version of the FMU.

get_name()

Return the model name as used in the modeling environment.

get_ode_sizes()

Returns the number of continuous states and the number of event indicators.

Returns:

nbr_cont --
    The number of continuous states.

nbr_ind --
    The number of event indicators.

Example:

[nCont, nEvent] = model.get_ode_sizes()
get_output_dependencies()

Retrieve the list of variables that the outputs are dependent on. Returns two dictionaries, one with the states and one with the inputs.

get_output_list()

Returns a dictionary with output variables

Returns:

An ordered dictionary with the (real) (continuous) output variables.
get_real()

Returns the real-values from the valuereference(s).

Parameters:

valueref --
    A list of valuereferences.

Returns:

values --
    The values retrieved from the FMU.

Example:

val = model.get_real([232])

Calls the low-level FMI function: fmi2GetReal

get_scalar_variable()

The variable as a scalar variable.

Parameter:

variable_name --
    The name of the variable

Returns:

Instance of a ScalarVariable2
get_state_space_representation()

Returns a state space representation of the model. I.e:

der(x) = Ax + Bu
    y  = Cx + Du

Which of the matrices to be returned can be choosen by the arguments.

Parameters:

A --
    If the 'A' matrix should be computed or not.
    Default: True
    
B --
    If the 'B' matrix should be computed or not.
    Default: True
    
C --
    If the 'C' matrix should be computed or not.
    Default: True
    
D --
    If the 'D' matrix should be computed or not.
    Default: True
    
use_structure_info --
    Determines if the structure should be taken into account 
    or not. If so, a sparse representation is returned, 
    otherwise a dense.
    Default: True
Returns::
The A,B,C,D matrices. If not all are computed, the ones that are not computed will be represented by a boolean flag.
get_states_list()

Returns a dictionary with the states.

Returns:

An ordered dictionary with the state variables.
get_string()

Returns the string-values from the valuereference(s).

Parameters:

valueref --
    A list of valuereferences.

Returns:

values --
    The values retrieved from the FMU.

Example:

val = model.get_string([232])

Calls the low-level FMI function: fmi2GetString

get_variable_alias()

Return a dict of all alias variables belonging to the provided variable where the key are the names and the value indicating whether the variable should be negated or not.

Parameters:

variable_name--
    Name of the variable to find alias of.

Returns:

A dict consisting of the alias variables along with no alias variable.
The values indicates whether or not the variable should be negated or not.

Raises:

FMUException if the variable is not in the model.
get_variable_alias_base()

Returns the base variable for the provided variable name.

Parameters:

variable_name--
    Name of the variable.

Returns:

The base variable.
get_variable_by_valueref()

Get the name of a variable given a value reference. Note that it returns the no-aliased variable.

Parameters:

valueref --
    The value reference of the variable.

type --
    The type of the variables (Real==0, Int==1, Bool==2,
    String==3, Enumeration==4).
    Default: 0 (i.e Real).

Returns:

The name of the variable.
get_variable_causality()

Get the causality of the variable.

Parameters:

variable_name --
    The name of the variable.

Returns:

The causality of the variable, PARAMETER(0), CALCULATED_PARAMETER(1), INPUT(2),
OUTPUT(3), LOCAL(4), INDEPENDENT(5), UNKNOWN(6)
get_variable_data_type()

Get data type of variable.

Parameter:

variable_name --
    The name of the variable.

Returns:

The type of the variable.
get_variable_declared_type()

Return the given variables declared type.

Parameters:

variable_name --
    The name of the variable.

Returns:

The name of the declared type.
get_variable_description()

Get the description of a given variable.

Parameter:

variable_name --
    The name of the variable

Returns:

The description of the variable.
get_variable_display_unit()

Get the display unit of the variable.

Parameters:

variable_name --
    The name of the variable.

Returns:

String representing the display unit of the variable.
get_variable_display_value()

Get the display value of the variable. This value takes into account the display unit (i.e. converts the value in its base unit to the value in its display unit.)

Parameters:

variable_name --
    The name of the variable.

Returns:

Variable value in its display unit (raises exception if no display unit).
get_variable_initial()

Get initial of the variable.

Parameters:

variable_name --
    The name of the variable.

Returns:

The initial of the variable: EXACT(0), APPROX(1), 
CALCULATED(2), UNKNOWN(3)
get_variable_max()

Returns the maximum value for the given variable.

Parameters:

variable_name --
    The name of the variable.

Returns:

The maximum value for the variable.
get_variable_min()

Returns the minimum value for the given variable.

Parameters:

variable_name --
    The name of the variable.

Returns:

The minimum value for the variable.
get_variable_naming_convention()

Return the variable naming convention.

get_variable_nominal()

Returns the nominal value from a real variable determined by either its value reference or its variable name.

Parameters:

variable_name --
    The name of the variable.

valueref --
    The value reference of the variable.

Returns:

The nominal value of the given variable.
get_variable_references()

Retrieves the value references of all variables. The information about the variables are retrieved from the XML-file.

Returns:

vr_real --
    The Real-valued variables.

vr_int --
    The Integer-valued variables.

vr_bool --
    The Boolean-valued variables.

vr_str --
    The String-valued variables.

vr_enum --
    The Enum-valued variables

Example:

[r,i,b,s,e] = model.get_value_references()
get_variable_start()

Returns the start value for the variable or else raises FMUException.

Parameters:

variable_name --
    The name of the variable

Returns:

The start value.
get_variable_unit()

Get the unit of the variable.

Parameters:

variable_name --
    The name of the variable.

Returns:

String representing the unit of the variable.
get_variable_valueref()

Extract the ValueReference given a variable name.

Parameters:

variable_name --
    The name of the variable.

Returns:

The ValueReference for the variable passed as argument.
get_variable_variability()

Get variability of the variable.

Parameters:

variable_name --
    The name of the variable.

Returns:

The variability of the variable: CONSTANT(0), FIXED(1),
TUNABLE(2), DISCRETE(3), CONTINUOUS(4) or UNKNOWN(5)
get_version()

Returns the FMI version of the Model which it was generated according.

Returns:

version --
    The version.

Example:

model.get_version()
initialize()

Initializes the model and computes initial values for all variables. Additionally calls the setup experiment, if not already called.

Parameters:

tolerance_defined --
    Specifies if the model is to be solved with an error
    controlled algorithm.
    Default: True
    
tolerance --
    The tolerance used by the error controlled algorithm.
    Default: The tolerance defined in the model description

start_time --
    Start time of the simulation.
    Default: The start time defined in the model description.

stop_time_defined --
    Defines if a fixed stop time is defined or not. If this is
    set the simulation cannot go past the defined stop time.
    Default: False

stop_time --
    Stop time of the simulation.
    Default: The stop time defined in the model description.
Calls the low-level FMI functions: fmi2_import_setup_experiment (optionally)
fmi2EnterInitializationMode, fmi2ExitInitializationMode
instantiate()

Instantiate the model.

Parameters:

name --
    The name of the instance.
    Default: 'Model'

visible --
    Defines if the simulator application window should be visible or not.
    Default: False, not visible.

Calls the low-level FMI function: fmi2Instantiate.

reset()

Resets the FMU back to its original state. Note that the environment has to initialize the FMU again after this function-call.

serialize_fmu_state()

Serialize the data referenced by the input argument.

Parameters:

state --
    A FMU-state.
Returns::
A vector with the serialized FMU-state.
Example::
FMU_state = Model.get_fmu_state() serialized_fmu = Model.serialize_fmu_state(FMU_state)
serialized_fmu_state_size()

Returns the required size of a vector needed to serialize the specified FMU-state

Parameters:

state--
    A FMU-state

Returns:

The size of the vector.
set_boolean()

Sets the boolean-values in the FMU as defined by the valuereference(s).

Parameters:

valueref --
    A list of valuereferences.

values --
    Values to be set.

Example:

model.set_boolean([234,235],[True,False])

Calls the low-level FMI function: fmi2SetBoolean

set_debug_logging()

Specifies if the debugging should be turned on or off. Currently the only allowed value for categories is an empty list.

Parameters:

logging_on --
    Boolean value.

categories --
    List of categories to log, call get_categories() for list of categories.
    Default: [] (all categories)

Calls the low-level FMI function: fmi2SetDebuggLogging

set_fmil_log_level()
set_fmu_state()

Set the FMU to a previous saved state.

Parameter:

state--
    A pointer to a FMU-state.

Example:

FMU_state = Model.get_fmu_state()
Model.set_fmu_state(FMU_state)
set_integer()

Sets the integer-values in the FMU as defined by the valuereference(s).

Parameters:

valueref --
    A list of valuereferences.

values --
    Values to be set.

Example:

model.set_integer([234,235],[12,-3])

Calls the low-level FMI function: fmi2SetInteger

set_real()

Sets the real-values in the FMU as defined by the valuereference(s).

Parameters:

valueref --
    A list of valuereferences.

values --
    Values to be set.

Example:

model.set_real([234,235],[2.34,10.4])

Calls the low-level FMI function: fmi2SetReal

set_string()

Sets the string-values in the FMU as defined by the valuereference(s).

Parameters:

valueref --
    A list of valuereferences.

values --
    Values to be set.

Example:

model.set_string([234,235],['text','text'])

Calls the low-level FMI function: fmi2SetString

setup_experiment()

Calls the underlying FMU method for creating an experiment.

Parameters:

tolerance_defined --
    Specifies that the model is used together with an external
    algorithm that is error controlled.
    Default: True
    
tolerance --
    Tolerance used in the simulation.
    Default: The tolerance defined in the model description.
    
start_time --
    Start time of the simulation.
    Default: The start time defined in the model description.
    
stop_time_defined --
    Defines if a fixed stop time is defined or not. If this is
    set the simulation cannot go past the defined stop time.
    Default: False
    
stop_time --
    Stop time of the simulation.
    Default: The stop time defined in the model description.
terminate()

Calls the FMI function fmi2Terminate() on the FMU. After this call, any call to a function changing the state of the FMU will fail.

class pyfmi.fmi.FMUModelCS1

Bases: pyfmi.fmi.FMUModelBase

cancel_step()

Cancel a current integrator step. Can only be called if the status from do_step returns FMI_PENDING.

do_step()

Performs an integrator step.

Parameters:

current_t --
        The current communication point (current time) of
        the master.
step_size --
        The length of the step to be taken.
new_step --
        True the last step was accepted by the master and
        False if not.

Returns:

status --
        The status of function which can be checked against
        FMI_OK, FMI_WARNING. FMI_DISCARD, FMI_ERROR,
        FMI_FATAL,FMI_PENDING...

Calls the underlying low-level function fmiDoStep.

free_instance()

Calls the FMI function fmiFreeSlaveInstance on the FMU. Note that this is not needed in general as it is done automatically.

get_capability_flags()

Returns a dictionary with the capability flags of the FMU.

Capabilities:

canHandleVariableCommunicationStepSize
canHandleEvents
canRejectSteps
canInterpolateInputs
maxOutputDerivativeOrder
canRunAsynchronuously
canSignalEvents
canBeinstantiatedOnlyOncePerProcess
canNotUseMemoryManagementFunctions
get_output_derivatives()

Returns the output derivatives for the specified variables. The order specifies the nth-derivative.

Parameters:

variables --
        The variables for which the output derivatives
        should be returned.
order --
        The derivative order.
get_real_status()
initialize()

Initializes the slave.

Parameters:

start_time --
    Start time of the simulation.
    Default: The start time defined in the model description.

stop_time --
    Stop time of the simulation.
    Default: The stop time defined in the model description.

stop_time_defined --
    Defines if a fixed stop time is defined or not. If this is
    set the simulation cannot go past the defined stop time.
    Default: False

Calls the low-level FMU function: fmiInstantiateSlave

instantiate_slave()

Instantiate the slave.

Parameters:

name --
    The name of the instance.
    Default: 'Slave'

logging --
    Defines if the logging should be turned on or off.
    Default: False, no logging.

Calls the low-level FMI function: fmiInstantiateSlave.

reset()

This method resets the FMU according to the reset method defined in the FMI1 specification.

set_input_derivatives()

Sets the input derivative order for the specified variables.

Parameters:

variables --
        The variables for which the input derivative
        should be set.
values --
        The actual values.
order --
        The derivative orders to set.
simulate()

Compact function for model simulation.

The simulation method depends on which algorithm is used, this can be set with the function argument ‘algorithm’. Options for the algorithm are passed as option classes or as pure dicts. See FMUModel.simulate_options for more details.

The default algorithm for this function is FMICSAlg.

Parameters:

start_time --
    Start time for the simulation.
    Default: Start time defined in the default experiment from
            the ModelDescription file.

final_time --
    Final time for the simulation.
    Default: Stop time defined in the default experiment from
            the ModelDescription file.

input --
    Input signal for the simulation. The input should be a 2-tuple
    consisting of first the names of the input variable(s) and then
    the data matrix.
    Default: Empty tuple.

algorithm --
    The algorithm which will be used for the simulation is specified
    by passing the algorithm class as string or class object in this
    argument. 'algorithm' can be any class which implements the
    abstract class AlgorithmBase (found in algorithm_drivers.py). In
    this way it is possible to write own algorithms and use them
    with this function.
    Default: 'FMICSAlg'

options --
    The options that should be used in the algorithm. For details on
    the options do:

        >> myModel = FMUModel(...)
        >> opts = myModel.simulate_options()
        >> opts?

    Valid values are:
        - A dict which gives AssimuloFMIAlgOptions with
          default values on all options except the ones
          listed in the dict. Empty dict will thus give all
          options with default values.
        - An options object.
    Default: Empty dict

Returns:

Result object, subclass of common.algorithm_drivers.ResultBase.
simulate_options()

Get an instance of the simulate options class, filled with default values. If called without argument then the options class for the default simulation algorithm will be returned.

Parameters:

algorithm --
    The algorithm for which the options class should be fetched.
    Possible values are: 'FMICSAlg'.
    Default: 'FMICSAlg'

Returns:

Options class for the algorithm specified with default values.
terminate()

Calls the FMI function fmiTerminateSlave() on the FMU. After this call, any call to a function changing the state of the FMU will fail.

time

Property for accessing the current time of the simulation. Calls the low-level FMI function: fmiSetTime.

types_platform

Returns the set of valid compatible platforms for the Model, extracted from the XML.

Returns:

types_platform --
    The valid platforms.

Example:

model.types_platform
class pyfmi.fmi.FMUModelCS2

Bases: pyfmi.fmi.FMUModelBase2

Co-simulation model loaded from a dll

cancel_step()

Cancel a current integrator step. Can only be called if the status from do_step returns FMI_PENDING. After this function has been called it is only allowed to reset the model (i.e. start over).

do_step()

Performs an integrator step.

Parameters:

current_t --
    The current communication point (current time) of
    the master.

step_size --
    The length of the step to be taken.

new_step --
    True the last step was accepted by the master and
    False if not.

Returns:

status --
        The status of function which can be checked against
        FMI_OK, FMI_WARNING. FMI_DISCARD, FMI_ERROR,
        FMI_FATAL,FMI_PENDING...

Calls the underlying low-level function fmi2DoStep.

get_boolean_status()

Retrieves the status, represented as a boolean-value, for the specified fmi-status-kind. See docstring for function get_status() for more information about fmi-status-kind.

Parameters:

status_kind--
    integer indicating the status kind

Returns:

The status.
get_capability_flags()

Returns a dictionary with the capability flags of the FMU.

Returns::
Dictionary with keys: needsExecutionTool canHandleVariableCommunicationStepSize canInterpolateInputs maxOutputDerivativeOrder canRunAsynchronuously canBeInstantiatedOnlyOncePerProcess canNotUseMemoryManagementFunctions canGetAndSetFMUstate providesDirectionalDerivatives
get_integer_status()

Retrieves the status, represented as a integer-value, for the specified fmi-status-kind. See docstring for function get_status() for more information about fmi-status-kind.

Parameters:

status_kind--
    integer indicating the status kind

Returns:

The status.
get_output_derivatives()

Returns the output derivatives for the specified variables. The order specifies the nth-derivative.

Parameters:

variables --
    The variables for which the output derivatives
    should be returned.

order --
    The derivative order.

Returns:

The derivatives of the specified order.
get_real_status()

Retrieves the status, represented as a real-value, for the specified fmi-status-kind. See docstring for function get_status() for more information about fmi-status-kind.

Parameters:

status_kind--
    integer indicating the status kind

Returns:

The status.
get_status()

Retrieves the fmi-status for the the specified fmi-staus-kind.

Parameters:

status_kind --
    An integer corresponding to one of the following:
    fmi2DoStepStatus       = 0
    fmi2PendingStatus      = 1
    fmi2LastSuccessfulTime = 2
    fmi2Terminated         = 3

Returns:

status_ok      = 0
status_warning = 1
status_discard = 2
status_error   = 3
status_fatal   = 4
status_pending = 5
get_string_status()

Retrieves the status, represented as a string-value, for the specified fmi-status-kind. See docstring for function get_status() for more information about fmi-status-kind.

Parameters:

status_kind--
    integer indicating the status kind

Returns:

The status.
set_input_derivatives()

Sets the input derivative order for the specified variables.

Parameters:

variables --
        The variables as a string or list of strings for
        which the input derivative(s) should be set.

values --
        The actual values.

order --
        The derivative order to set.
simulate()

Compact function for model simulation.

The simulation method depends on which algorithm is used, this can be set with the function argument ‘algorithm’. Options for the algorithm are passed as option classes or as pure dicts. See FMUModel.simulate_options for more details.

The default algorithm for this function is FMICSAlg.

Parameters:

start_time --
    Start time for the simulation.
    Default: Start time defined in the default experiment from
            the ModelDescription file.

final_time --
    Final time for the simulation.
    Default: Stop time defined in the default experiment from
            the ModelDescription file.

input --
    Input signal for the simulation. The input should be a 2-tuple
    consisting of first the names of the input variable(s) and then
    the data matrix.
    Default: Empty tuple.

algorithm --
    The algorithm which will be used for the simulation is specified
    by passing the algorithm class as string or class object in this
    argument. 'algorithm' can be any class which implements the
    abstract class AlgorithmBase (found in algorithm_drivers.py). In
    this way it is possible to write own algorithms and use them
    with this function.
    Default: 'FMICSAlg'

options --
    The options that should be used in the algorithm. For details on
    the options do:

        >> myModel = FMUModel(...)
        >> opts = myModel.simulate_options()
        >> opts?

    Valid values are:
        - A dict which gives AssimuloFMIAlgOptions with
          default values on all options except the ones
          listed in the dict. Empty dict will thus give all
          options with default values.
        - An options object.
    Default: Empty dict

Returns:

Result object, subclass of common.algorithm_drivers.ResultBase.
simulate_options()

Get an instance of the simulate options class, filled with default values. If called without argument then the options class for the default simulation algorithm will be returned.

Parameters:

algorithm --
    The algorithm for which the options class should be fetched.
    Possible values are: 'FMICSAlg'.
    Default: 'FMICSAlg'

Returns:

Options class for the algorithm specified with default values.
time

Property for accessing the current time of the simulation. Calls the low-level FMI function: fmiSetTime

class pyfmi.fmi.FMUModelME1

Bases: pyfmi.fmi.FMUModelBase

An FMI Model loaded from a DLL.

completed_integrator_step()

This method must be called by the environment after every completed step of the integrator. If the return is True, then the environment must call event_update() otherwise, no action is needed.

Returns:

True -> Call event_update().
False -> Do nothing.

Calls the low-level FMI function: fmiCompletedIntegratorStep.

continuous_states

Property for accessing the current values of the continuous states. Calls the low-level FMI function: fmiSetContinuousStates/fmiGetContinuousStates.

event_update()

Updates the event information at the current time-point. If intermediateResult is set to True the update_event will stop at each event iteration which would require to loop until event_info.iterationConverged == fmiTrue.

Parameters:

intermediateResult --
    If set to True, the update_event will stop at each event
    iteration.
    Default: False.

Example:

model.event_update()

Calls the low-level FMI function: fmiEventUpdate

free_instance()

Calls the FMI function fmiFreeModelInstance on the FMU. Note that this is not needed in general as it is done automatically.

get_derivatives()

Returns the derivative of the continuous states.

Returns:

dx --
    The derivative as an array.

Example:

dx = model.get_derivatives()

Calls the low-level FMI function: fmiGetDerivatives

get_event_indicators()

Returns the event indicators at the current time-point.

Return:

evInd --
    The event indicators as an array.

Example:

evInd = model.get_event_indicators()

Calls the low-level FMI function: fmiGetEventIndicators

get_event_info()

Returns the event information from the FMU.

Returns:

The event information, a struct which contains:

iterationConverged --
    Event iteration converged (if True).

stateValueReferencesChanged --
    ValueReferences of states x changed (if True).

stateValuesChanged --
    Values of states x have changed (if True).

terminateSimulation --
    Error, terminate simulation (if True).

upcomingTimeEvent -
    If True, nextEventTime is the next time event.

nextEventTime --
    The next time event.

Example:

event_info    = model.event_info
nextEventTime = model.event_info.nextEventTime
get_state_value_references()

Returns the continuous states valuereferences.

Returns:

val --
    The references to the continuous states.

Example:

val = model.get_continuous_value_reference()

Calls the low-level FMI function: fmiGetStateValueReferences

get_tolerances()

Returns the relative and absolute tolerances. If the relative tolerance is defined in the XML-file it is used, otherwise a default of 1.e-4 is used. The absolute tolerance is calculated and returned according to the FMI specification, atol = 0.01*rtol*(nominal values of the continuous states).

Returns:

rtol --
    The relative tolerance.

atol --
    The absolute tolerance.

Example:

[rtol, atol] = model.get_tolerances()
initialize()

Initializes the model and computes initial values for all variables, including setting the start values of variables defined with a the start attribute in the XML-file.

Parameters:

tolerance_defined --
    If the model are going to be called by numerical solver using
    step-size control. Boolean flag.
    Default: True
    
tolerance --
    If the model are controlled by a numerical solver using
    step-size control, the same tolerance should be provided here.
    Else the default tolerance from the XML-file are used.

Calls the low-level FMI function: fmiInitialize.

instantiate_model()

Instantiate the model.

Parameters:

name --
    The name of the instance.
    Default: 'Model'

logging --
    Defines if the logging should be turned on or off.
    Default: False, no logging.

Calls the low-level FMI function: fmiInstantiateModel.

model_types_platform

Returns the set of valid compatible platforms for the Model, extracted from the XML.

Returns:

model_types_platform --
    The valid platforms.

Example:

model.model_types_platform
nominal_continuous_states

Property for accessing the nominal values of the continuous states. Calls the low-level FMI function: fmiGetNominalContinuousStates.

reset()

This metod resets the FMU by first calling fmiTerminate and fmiFreeModelInstance and then reloads the DLL and finally re-instantiates using fmiInstantiateModel.

simulate()

Compact function for model simulation.

The simulation method depends on which algorithm is used, this can be set with the function argument ‘algorithm’. Options for the algorithm are passed as option classes or as pure dicts. See FMUModel.simulate_options for more details.

The default algorithm for this function is AssimuloFMIAlg.

Parameters:

start_time --
    Start time for the simulation.
    Default: Start time defined in the default experiment from
            the ModelDescription file.

final_time --
    Final time for the simulation.
    Default: Stop time defined in the default experiment from
            the ModelDescription file.

input --
    Input signal for the simulation. The input should be a 2-tuple
    consisting of first the names of the input variable(s) and then
    the data matrix or a function. If a data matrix, the first
    column should be a time vector and then the variable vectors as
    columns. If instead a function, the argument should correspond
    to time and the output the variable data. See the users-guide
    for examples.
    Default: Empty tuple.

algorithm --
    The algorithm which will be used for the simulation is specified
    by passing the algorithm class as string or class object in this
    argument. 'algorithm' can be any class which implements the
    abstract class AlgorithmBase (found in algorithm_drivers.py). In
    this way it is possible to write own algorithms and use them
    with this function.
    Default: 'AssimuloFMIAlg'

options --
    The options that should be used in the algorithm. For details on
    the options do:

        >> myModel = FMUModel(...)
        >> opts = myModel.simulate_options()
        >> opts?

    Valid values are:
        - A dict which gives AssimuloFMIAlgOptions with
          default values on all options except the ones
          listed in the dict. Empty dict will thus give all
          options with default values.
        - An options object.
    Default: Empty dict

Returns:

Result object, subclass of common.algorithm_drivers.ResultBase.
simulate_options()

Get an instance of the simulate options class, filled with default values. If called without argument then the options class for the default simulation algorithm will be returned.

Parameters:

algorithm --
    The algorithm for which the options class should be fetched.
    Possible values are: 'AssimuloFMIAlg'.
    Default: 'AssimuloFMIAlg'

Returns:

Options class for the algorithm specified with default values.
terminate()

Calls the FMI function fmiTerminate() on the FMU. After this call, any call to a function changing the state of the FMU will fail.

time

Property for accessing the current time of the simulation. Calls the low-level FMI function: fmiSetTime.

class pyfmi.fmi.FMUModelME2

Bases: pyfmi.fmi.FMUModelBase2

Model-exchange model loaded from a dll

completed_integrator_step()

This method must be called by the environment after every completed step of the integrator. If the return is True, then the environment must call event_update() otherwise, no action is needed.

Returns:

True -> Call event_update().
False -> Do nothing.

Calls the low-level FMI function: fmi2CompletedIntegratorStep.

continuous_states

Property for accessing the current values of the continuous states. Calls the low-level FMI function: fmi2SetContinuousStates/fmi2GetContinuousStates.

enter_continuous_time_mode()

Sets the FMU to be in continuous time mode by calling the underlying FMU method.

enter_event_mode()

Sets the FMU to be in event mode by calling the underlying FMU method.

event_update()

Updates the event information at the current time-point. If intermediateResult is set to True the update_event will stop at each event iteration which would require to loop until event_info.newDiscreteStatesNeeded == fmiFalse.

Parameters:

intermediateResult --
    If set to True, the update_event will stop at each event
    iteration.
    Default: False.

Example:

model.event_update()

Calls the low-level FMI function: fmi2NewDiscreteStates

force_finite_differences
get_capability_flags()

Returns a dictionary with the capability flags of the FMU.

Returns::
Dictionary with keys: needsExecutionTool completedIntegratorStepNotNeeded canBeInstantiatedOnlyOncePerProcess canNotUseMemoryManagementFunctions canGetAndSetFMUstate canSerializeFMUstate providesDirectionalDerivatives completedEventIterationIsProvided
get_derivatives()

Returns the derivative of the continuous states.

Returns:

dx --
    The derivatives as an array.

Example:

dx = model.get_derivatives()

Calls the low-level FMI function: fmi2GetDerivatives

get_event_indicators()

Returns the event indicators at the current time-point.

Returns:

evInd --
    The event indicators as an array.

Example:

evInd = model.get_event_indicators()

Calls the low-level FMI function: fmiGetEventIndicators

get_event_info()

Returns the event information from the FMU.

Returns:

The event information, a struct which contains:

newDiscreteStatesNeeded --
    Event iteration did not converge (if True).

terminateSimulation --
    Error, terminate simulation (if True).

nominalsOfContinuousStatesChanged --
    Values of states x have changed (if True).

valuesOfContinuousStatesChanged --
    ValueReferences of states x changed (if True).

nextEventTimeDefined -
    If True, nextEventTime is the next time event.

nextEventTime --
    The next time event.

Example:

event_info    = model.event_info
nextEventTime = model.event_info.nextEventTime
get_tolerances()

Returns the relative and absolute tolerances. If the relative tolerance is defined in the XML-file it is used, otherwise a default of 1.e-4 is used. The absolute tolerance is calculated and returned according to the FMI specification, atol = 0.01*rtol*(nominal values of the continuous states).

Returns:

rtol --
    The relative tolerance.

atol --
    The absolute tolerance.

Example:

[rtol, atol] = model.get_tolerances()
nominal_continuous_states

Property for accessing the nominal values of the continuous states. Calls the low-level FMI function: fmi2GetNominalContinuousStates.

simulate()

Compact function for model simulation.

The simulation method depends on which algorithm is used, this can be set with the function argument ‘algorithm’. Options for the algorithm are passed as option classes or as pure dicts. See FMUModel.simulate_options for more details.

The default algorithm for this function is AssimuloFMIAlg.

Parameters:

start_time --
    Start time for the simulation.
    Default: Start time defined in the default experiment from
            the ModelDescription file.

final_time --
    Final time for the simulation.
    Default: Stop time defined in the default experiment from
            the ModelDescription file.

input --
    Input signal for the simulation. The input should be a 2-tuple
    consisting of first the names of the input variable(s) and then
    the data matrix or a function. If a data matrix, the first
    column should be a time vector and then the variable vectors as
    columns. If instead a function, the argument should correspond
    to time and the output the variable data. See the users-guide
    for examples.
    Default: Empty tuple.

algorithm --
    The algorithm which will be used for the simulation is specified
    by passing the algorithm class as string or class object in this
    argument. 'algorithm' can be any class which implements the
    abstract class AlgorithmBase (found in algorithm_drivers.py). In
    this way it is possible to write own algorithms and use them
    with this function.
    Default: 'AssimuloFMIAlg'

options --
    The options that should be used in the algorithm. For details on
    the options do:

        >> myModel = FMUModel(...)
        >> opts = myModel.simulate_options()
        >> opts?

    Valid values are:
        - A dict which gives AssimuloFMIAlgOptions with
          default values on all options except the ones
          listed in the dict. Empty dict will thus give all
          options with default values.
        - An options object.
    Default: Empty dict

Returns:

Result object, subclass of common.algorithm_drivers.ResultBase.
simulate_options()

Get an instance of the simulate options class, filled with default values. If called without argument then the options class for the default simulation algorithm will be returned.

Parameters:

algorithm --
    The algorithm for which the options class should be fetched.
    Possible values are: 'AssimuloFMIAlg'.
    Default: 'AssimuloFMIAlg'

Returns:

Options class for the algorithm specified with default values.
time

Property for accessing the current time of the simulation. Calls the low-level FMI function: fmiSetTime.

class pyfmi.fmi.FMUState2

Bases: object

Class containing a pointer to a FMU-state.

class pyfmi.fmi.IntegerType2

Bases: pyfmi.fmi.DeclaredType2

Class defining data structure based on the XML element Enumeration.

max

Get the max value for the type.

Returns:

The max value.
min

Get the min value for the type.

Returns:

The min value.
class pyfmi.fmi.ModelBase

Bases: object

Abstract Model class containing base functionality.

append_log_message()
cache
estimate()

Compact function for model estimation.

The estimation method depends on which algorithm is used, this can be set with the function argument ‘algorithm’. Options for the algorithm are passed as option classes or as pure dicts. See model.estimate_options for more details.

The default algorithm for this function is SciEstAlg.

Parameters:

parameters --
    The tunable parameters (required)

measurements --
    The measurements data (name, data). Note that the measurements
    needs to be distinct and equally spaced. (required)

input --
    Input signal for the estimation. The input should be a 2-tuple
    consisting of first the names of the input variable(s) and then
    the data matrix.
    Default: Empty tuple.

algorithm --
    The algorithm which will be used for the estimation is specified
    by passing the algorithm class as string or class object in this
    argument. 'algorithm' can be any class which implements the
    abstract class AlgorithmBase (found in algorithm_drivers.py). In
    this way it is possible to write own algorithms and use them
    with this function.
    Default: 'SciEstAlg'

options --
    The options that should be used in the algorithm. For details on
    the options do:

        >> myModel = load_fmu(...)
        >> opts = myModel.estimate_options()
        >> opts?

    Valid values are:
        - A dict which gives SciEstAlgOptions with
          default values on all options except the ones
          listed in the dict. Empty dict will thus give all
          options with default values.
        - An options object.
    Default: Empty dict

Returns:

Result object, subclass of common.algorithm_drivers.ResultBase.
estimate_options()

Get an instance of the estimation options class, filled with default values. If called without argument then the options class for the default estimation algorithm will be returned.

Parameters:

algorithm --
    The algorithm for which the options class should be fetched.
    Possible values are: 'SciEstAlg'.
    Default: 'SciEstAlg'

Returns:

Options class for the algorithm specified with default values.
file_object
get()

Returns the value(s) of the specified variable(s). The method both accept a single variable and a list of variables.

Parameters:

variable_name --
    The name of the variable(s) as string/list.

Returns:

The value(s).

Example:

# Returns the variable d
model.get('damper.d')
# Returns a list of the variables
model.get(['damper.d','gear.a'])
get_log()

Returns the log information as a list. To turn on the logging use load_fmu(..., log_level=1-7) in the loading of the FMU. The log is stored as a list of lists. For example log[0] are the first log message to the log and consists of, in the following order, the instance name, the status, the category and the message.

Returns:

log - A list of lists.
get_log_file_name()
get_log_filename()
get_log_level()

Returns the log level for PyFMI, i.e., as set in set_log_level. Type: int

get_max_log_size()

Returns the limit (in characters) of the log file.

get_number_of_lines_log()

Returns the number of lines in the log file.

print_log()

Prints the log information to the prompt.

set()

Sets the given value(s) to the specified variable name(s) into the model. The method both accept a single variable and a list of variables.

Parameters:

variable_name --
    The name of the variable(s) as string/list.

value --
    The value(s) to set.

Example:

model.set('damper.d', 1.1)
model.set(['damper.d','gear.a'], [1.1, 10])
set_additional_logger()

Set an additional logger function that will, an addition to the normal FMU log file, also be fed with all model log messages.

Parameter:

additional_logger --
    The callback function that should accept three arguments:
    module(str), log_level(int), message(str)
set_log_level()

Specifies the log level for PyFMI. Note that this is different from the FMU logging which is specified via set_debug_logging.

Parameters:

level --
    The log level. Available values:
        NOTHING = 0
        FATAL = 1
        ERROR = 2
        WARNING = 3
        INFO = 4
        VERBOSE = 5
        DEBUG = 6
        ALL = 7
set_max_log_size()

Specifies the maximum number of characters to be written to the log file.

Parameters:

number_of_characters --
    The maximum number of characters in the log.
    Default: 1024^3 (about 1GB)
class pyfmi.fmi.PyEventInfo
class pyfmi.fmi.RealType2

Bases: pyfmi.fmi.DeclaredType2

Class defining data structure based on the XML element Enumeration.

display_unit

Get the display unit value for the type.

Returns:

The display unit value.
max

Get the max value for the type.

Returns:

The max value.
min

Get the min value for the type.

Returns:

The min value.
nominal

Get the nominal value for the type.

Returns:

The nominal value.
relative_quantity

Get the relative quantity value for the type.

Returns:

The relative quantity value.
unbounded

Get the unbounded value for the type.

Returns:

The unbounded value.
unit

Get the unit value for the type.

Returns:

The unit value.
class pyfmi.fmi.ScalarVariable

Bases: object

Class defining data structure based on the XML element ScalarVariable.

alias

Get the value of the alias attribute.

Returns:

The alias attribute value as enumeration: FMI_NO_ALIAS(0),
FMI_ALIAS(1) or FMI_NEGATED_ALIAS(-1).
causality

Get the value of the causality attribute.

Returns:

The causality attribute value as enumeration: FMI_INPUT(0),
FMI_OUTPUT(1), FMI_INTERNAL(2) or FMI_NONE(3).
description

Get the value of the description attribute.

Returns:

The description attribute value as string (empty string if
not set).
name

Get the value of the name attribute.

Returns:

The name attribute value as string.
type

Get the value of the data type attribute.

Returns:

The data type attribute value as enumeration: FMI_REAL(0),
FMI_INTEGER(1), FMI_BOOLEAN(2), FMI_STRING(3) or FMI_ENUMERATION(4).
value_reference

Get the value of the value reference attribute.

Returns:

The value reference as unsigned int.
variability

Get the value of the variability attribute.

Returns:

The variability attribute value as enumeration:
FMI_CONSTANT(0), FMI_PARAMETER(1), FMI_DISCRETE(2) or FMI_CONTINUOUS(3).
class pyfmi.fmi.ScalarVariable2

Bases: object

Class defining data structure based on the XML element ScalarVariable.

alias

Get the value of the alias attribute.

Returns:

The alias attribute value as enumeration: FMI_NO_ALIAS,
FMI_ALIAS or FMI_NEGATED_ALIAS.
causality

Get the value of the causality attribute.

Returns:

The causality of the variable, FMI2_PARAMETER(0), FMI2_CALCULATED_PARAMETER(1), FMI2_INPUT(2),
FMI2_OUTPUT(3), FMI2_LOCAL(4), FMI2_INDEPENDENT(5), FMI2_UNKNOWN(6)
description

Get the value of the description attribute.

Returns:

The description attribute value as string (empty string if
not set).
initial

Get the value of the initial attribute.

Returns:

The initial attribute value as enumeration: FMI2_INITIAL_EXACT, 
                  FMI2_INITIAL_APPROX, FMI2_INITIAL_CALCULATED, 
                  FMI2_INITIAL_UNKNOWN    
name

Get the value of the name attribute.

Returns:

The name attribute value as string.
type

Get the value of the data type attribute.

Returns:

The data type attribute value as enumeration: FMI2_REAL(0),
FMI2_INTEGER(1), FMI2_BOOLEAN(2), FMI2_STRING(3) or FMI2_ENUMERATION(4).
value_reference

Get the value of the value reference attribute.

Returns:

The value reference as unsigned int.
variability

Get the value of the variability attribute.

Returns:

The variability of the variable: FMI2_CONSTANT(0), FMI2_FIXED(1),
FMI2_TUNABLE(2), FMI2_DISCRETE(3), FMI2_CONTINUOUS(4) or FMI2_UNKNOWN(5)
exception pyfmi.fmi.TimeLimitExceeded

Bases: pyfmi.fmi.FMUException

pyfmi.fmi.decode()
pyfmi.fmi.encode()
pyfmi.fmi.load_fmu()

Helper method for creating a model instance.

Parameters:

fmu --
    Name of the fmu as a string.

path --
    Path to the fmu-directory.
    Default: '.' (working directory)

enable_logging [DEPRECATED] --
    This option is DEPRECATED and will be removed. Please use
    the option "log_level" instead.

log_file_name --
    Filename for file used to save logmessages.
    Default: "" (Generates automatically)

kind --
    String indicating the kind of model to create. This is only
    needed if a FMU contains both a ME and CS model.
    Availible options:
        - 'ME'
        - 'CS'
        - 'auto'
    Default: 'auto' (Chooses ME before CS if both available)

log_level --
    Determines the logging output. Can be set between 0 
    (no logging) and 7 (everything).
    Default: 2 (log error messages)

Returns:

A model instance corresponding to the loaded FMU.

Module fmi_coupled

class pyfmi.fmi_coupled.CoupledFMUModelBase

Bases: pyfmi.fmi_coupled.CoupledModelBase

compute_evaluation_order()
connection_setup()
connections
define_graph()
deserialize_fmu_state()

De-serialize the provided byte-vector and returns the corresponding FMU-state.

Parameters:

serialized_fmu--
    A serialized FMU-state.

Returns:

A deserialized FMU-state.

Example:

FMU_state = Model.get_fmu_state()
serialized_fmu = Model.serialize_fmu_state(FMU_state)
FMU_state = Model.deserialize_fmu_state(serialized_fmu)
enter_initialization_mode()

Enters initialization mode by calling the low level FMI function fmi2EnterInitializationMode.

Note that the method initialize() performs both the enter and exit of initialization mode.

exit_initialization_mode()

Exit initialization mode by calling the low level FMI function fmi2ExitInitializationMode.

Note that the method initialize() performs both the enter and exit of initialization mode.

free_fmu_state()

Free a previously saved FMU-state from the memory.

Parameters:

state--
    A pointer to the FMU-state to be set free.

Example:

FMU_state = Model.get_fmu_state()
Model.free_fmu_state(FMU_state)
free_instance()

Calls the FMI function fmi2FreeInstance() on the FMU. Note that this is not needed generally.

get_author()

Return the name and organization of the model author.

get_boolean()

Returns the boolean-values from the valuereference(s).

Parameters:

valueref --
    A list of valuereferences.

Returns:

values --
    The values retrieved from the FMU.

Example:

val = model.get_boolean([232])

Calls the low-level FMI function: fmi2GetBoolean

get_categories()

Method used to retrieve the logging categories.

Returns:

A list with the categories available for logging.

Return the model copyright.

get_default_experiment_start_time()

Returns the default experiment start time as defined by the greatest start time of the coupled system.

get_default_experiment_step()

Returns the default experiment step as defined by the minimum step of all the models in the coupled system.

get_default_experiment_stop_time()

Returns the default experiment stop time as defined by the minimum stop time of the coupled system.

get_default_experiment_tolerance()

Returns the default experiment tolerance as defined by the smallest tolerance of all the models in the coupled system.

get_derivatives_dependencies()

Retrieve the list of variables that the derivatives are dependent on. Returns two dictionaries, one with the states and one with the inputs.

get_derivatives_list()

Returns a dictionary with the states derivatives.

Returns:

An ordered dictionary with the derivative variables.
get_description()

Return the model description.

get_directional_derivative()

Returns the directional derivatives of the functions with respect to the given variables and in the given direction. In other words, it returns linear combinations of the partial derivatives of the given functions with respect to the selected variables. The point of evaluation is the current time-point.

Parameters:

var_ref --
    A list of variable references that the partial derivatives
    will be calculated with respect to.

func_ref --
    A list of function references for which the partial derivatives will be calculated.

v --
    A seed vector specifying the linear combination of the partial derivatives.

Returns:

value --
    A vector with the directional derivatives (linear combination of
    partial derivatives) evaluated in the current time point.

Example:

states = model.get_states_list()
states_references = [s.value_reference for s in states.values()]
derivatives = model.get_derivatives_list()
derivatives_references = [d.value_reference for d in derivatives.values()]
model.get_directional_derivative(states_references, derivatives_references, v)

This returns Jv, where J is the Jacobian and v the seed vector.

Also, only a subset of the derivatives and and states can be selected:

model.get_directional_derivative(var_ref = [0,1], func_ref = [2,3], v = [1,2])

This returns a vector with two values where:

values[0] = (df2/dv0) * 1 + (df2/dv1) * 2
values[1] = (df3/dv0) * 1 + (df3/dv1) * 2
get_fmu_state()

Creates a copy of the recent FMU-state and returns a pointer to this state which later can be used to set the FMU to this state.

Parameters:

state --
    Optionally a pointer to an already allocated FMU state

Returns:

A pointer to a copy of the recent FMU state.

Example:

FMU_state = model.get_fmu_state()
get_generation_date_and_time()

Return the model generation date and time.

get_generation_tool()

Return the model generation tool.

get_guid()

Return the model GUID.

get_identifier()

Return the model identifier, name of binary model file and prefix in the C-function names of the model.

get_input_list()

Returns a dictionary with input variables

Returns:

An ordered dictionary with the (real) (continuous) input variables.
get_integer()

Returns the integer-values from the valuereference(s).

Parameters:

valueref --
    A list of valuereferences.

Returns:

values --
    The values retrieved from the FMU.

Example:

val = model.get_integer([232])

Calls the low-level FMI function: fmi2GetInteger

get_license()

Return the model license.

get_model_time_varying_value_references()

Extract the value references of the variables in a model that are time-varying. This method is typically used to retrieve the variables for which the result can be stored.

Parameters:

filter --
    Filter the variables using a unix filename pattern
    matching (filter="*der*"). Can also be a list of filters
    See http://docs.python.org/2/library/fnmatch.html.
    Default None

Returns:

Three lists with the real, integer and boolean value-references
get_model_types_platform()

Returns the set of valid compatible platforms for the Model, extracted from the XML.

get_model_variables()

Extract the names of the variables in a model.

Parameters:

type --
    The type of the variables (Real==0, Int==1, Bool==2,
    String==3, Enumeration==4).
    Default: None (i.e all).

include_alias --
    If alias should be included or not.
    Default: True

causality --
    The causality of the variables (Parameter==0, 
    Calculated Parameter==1, Input==2, Output==3, Local==4, 
    Independent==5, Unknown==6).
    Default: None (i.e all).

variability --
    The variability of the variables (Constant==0,
    Fixed==1, Tunable==2, Discrete==3, Continuous==4, Unknown==5).
    Default: None (i.e. all)

only_start --
    If only variables that has a start value should be
    returned.
    Default: False

only_fixed --
    If only variables that has a start value that is fixed
    should be returned.
    Default: False

filter --
    Filter the variables using a unix filename pattern
    matching (filter="*der*"). Can also be a list of filters
    See http://docs.python.org/2/library/fnmatch.html.
    Default None

Returns:

Dict with variable name as key and a ScalarVariable class as
value.
get_model_version()

Returns the version of the FMU.

get_name()

Return the model name as used in the modeling environment.

get_ode_sizes()

Returns the number of continuous states and the number of event indicators.

Returns:

nbr_cont --
    The number of continuous states.

nbr_ind --
    The number of event indicators.

Example:

[nbr_cont, nbr_event_ind] = model.get_ode_sizes()
get_output_dependencies()

Retrieve the list of variables that the outputs are dependent on. Returns two dictionaries, one with the states and one with the inputs.

get_output_list()

Returns a dictionary with output variables

Returns:

An ordered dictionary with the (real) (continuous) output variables.
get_real()

Returns the real-values from the valuereference(s).

Parameters:

valueref --
    A list of valuereferences.

Returns:

values --
    The values retrieved from the FMU.

Example:

val = model.get_real([232])

Calls the low-level FMI function: fmi2GetReal

get_states_list()

Returns a dictionary with the states.

Returns:

An ordered dictionary with the state variables.
get_string()

Returns the string-values from the valuereference(s).

Parameters:

valueref --
    A list of valuereferences.

Returns:

values --
    The values retrieved from the FMU.

Example:

val = model.get_string([232])

Calls the low-level FMI function: fmi2GetString

get_variable_alias()

Return a dict of all alias variables belonging to the provided variable where the key are the names and the value indicating whether the variable should be negated or not.

Parameters:

variable_name--
    Name of the variable to find alias of.

Returns:

A dict consisting of the alias variables along with no alias variable.
The values indicates whether or not the variable should be negated or not.

Raises:

FMUException if the variable is not in the model.
get_variable_alias_base()

Returns the base variable for the provided variable name.

Parameters:

variable_name--
    Name of the variable.

Returns:

The base variable.
get_variable_by_valueref()

Get the name of a variable given a value reference. Note that it returns the no-aliased variable.

Parameters:

valueref --
    The value reference of the variable.

type --
    The type of the variables (Real==0, Int==1, Bool==2,
    String==3, Enumeration==4).
    Default: 0 (i.e Real).

Returns:

The name of the variable.
get_variable_causality()

Get the causality of the variable.

Parameters:

variable_name --
    The name of the variable.

Returns:

The variability of the variable, PARAMETER(0), CALCULATED_PARAMETER(1), INPUT(2),
OUTPUT(3), LOCAL(4), INDEPENDENT(5), UNKNOWN(6)
get_variable_data_type()

Get data type of variable.

Parameter:

variable_name --
    The name of the variable.

Returns:

The type of the variable.
get_variable_description()

Get the description of a given variable.

Parameter:

variable_name --
    The name of the variable

Returns:

The description of the variable.
get_variable_initial()

Get initial of the variable.

Parameters:

variable_name --
    The name of the variable.

Returns:

The initial of the variable: EXACT(0), APPROX(1), 
CALCULATED(2), UNKNOWN(3)
get_variable_max()

Returns the maximum value for the given variable.

Parameters:

variable_name --
    The name of the variable.

Returns:

The maximum value for the variable.
get_variable_min()

Returns the minimum value for the given variable.

Parameters:

variable_name --
    The name of the variable.

Returns:

The minimum value for the variable.
get_variable_naming_convention()

Return the variable naming convention.

get_variable_nominal()

Returns the nominal value from a real variable determined by either its value reference or its variable name.

Parameters:

variable_name --
    The name of the variable.

valueref --
    The value reference of the variable.

Returns:

The nominal value of the given variable.
get_variable_start()

Returns the start value for the variable or else raises FMUException.

Parameters:

variable_name --
    The name of the variable

Returns:

The start value.
get_variable_valueref()

Extract the ValueReference given a variable name.

Parameters:

variable_name --
    The name of the variable.

Returns:

The ValueReference for the variable passed as argument.
get_variable_variability()

Get variability of the variable.

Parameters:

variable_name --
    The name of the variable.

Returns:

The variability of the variable: CONSTANT(0), FIXED(1),
TUNABLE(2), DISCRETE(3), CONTINUOUS(4) or UNKNOWN(5)
get_version()

Returns the FMI version of the Model which it was generated according.

Returns:

version --
    The version.

Example:

model.get_version()
index
initialize()

Initializes the model and computes initial values for all variables. Additionally calls the setup experiment, if not already called.

Calls the low-level FMI functions: fmi2_import_setup_experiment (optionally)
fmi2EnterInitializationMode, fmi2ExitInitializationMode
models
models_dict
models_id_mapping
names
reset()

Resets the FMU back to its original state. Note that the environment has to initialize the FMU again after this function-call.

serialize_fmu_state()

Serialize the data referenced by the input argument.

Parameters:

state --
    A FMU-state.
Returns::
A vector with the serialized FMU-state.
Example::
FMU_state = Model.get_fmu_state() serialized_fmu = Model.serialize_fmu_state(FMU_state)
serialized_fmu_state_size()

Returns the required size of a vector needed to serialize the specified FMU-state

Parameters:

state--
    A FMU-state

Returns:

The size of the vector.
set_boolean()

Sets the boolean-values in the FMU as defined by the valuereference(s).

Parameters:

valueref --
    A list of valuereferences.

values --
    Values to be set.

Example:

model.set_boolean([234,235],[True,False])

Calls the low-level FMI function: fmi2SetBoolean

set_debug_logging()

Specifies if the debugging should be turned on or off. Currently the only allowed value for categories is an empty list.

Parameters:

logging_on --
    Boolean value.

categories --
    List of categories to log, call get_categories() for list of categories.
    Default: [] (all categories)

Calls the low-level FMI function: fmi2SetDebuggLogging

set_fmu_state()

Set the FMU to a previous saved state.

Parameter:

state--
    A pointer to a FMU-state.

Example:

FMU_state = Model.get_fmu_state()
Model.set_fmu_state(FMU_state)
set_integer()

Sets the integer-values in the FMU as defined by the valuereference(s).

Parameters:

valueref --
    A list of valuereferences.

values --
    Values to be set.

Example:

model.set_integer([234,235],[12,-3])

Calls the low-level FMI function: fmi2SetInteger

set_real()

Sets the real-values in the FMU as defined by the valuereference(s).

Parameters:

valueref --
    A list of valuereferences.

values --
    Values to be set.

Example:

model.set_real([234,235],[2.34,10.4])

Calls the low-level FMI function: fmi2SetReal

set_string()

Sets the string-values in the FMU as defined by the valuereference(s).

Parameters:

valueref --
    A list of valuereferences.

values --
    Values to be set.

Example:

model.set_string([234,235],['text','text'])

Calls the low-level FMI function: fmi2SetString

setup_experiment()

Calls the underlying FMU method for creating an experiment.

Parameters:

tolerance_defined --
    Specifies that the model is used together with an external
    algorithm that is error controlled.
    Default: True
    
tolerance --
    Tolerance used in the simulation.
    Default: The tolerance defined in the model description.
    
start_time --
    Start time of the simulation.
    Default: The start time defined in the model description.
    
stop_time_defined --
    Defines if a fixed stop time is defined or not. If this is
    set the simulation cannot go past the defined stop time.
    Default: False
    
stop_time --
    Stop time of the simulation.
    Default: The stop time defined in the model description.
terminate()

Calls the FMI function fmi2Terminate() on the FMU. After this call, any call to a function changing the state of the FMU will fail.

verify_connection_variables()
class pyfmi.fmi_coupled.CoupledFMUModelME2

Bases: pyfmi.fmi_coupled.CoupledFMUModelBase

A class for coupled ME models

completed_integrator_step()

This method must be called by the environment after every completed step of the integrator. If the return is True, then the environment must call event_update() otherwise, no action is needed.

Returns:

True -> Call event_update().
False -> Do nothing.

Calls the low-level FMI function: fmi2CompletedIntegratorStep.

continuous_states

Returns a vector with the values of the continuous states.

Returns:

The continuous states.
enter_continuous_time_mode()

Sets the FMU to be in continuous time mode by calling the underlying FMU method.

enter_event_mode()

Sets the FMU to be in event mode by calling the underlying FMU method.

event_update()

Updates the event information at the current time-point. If intermediateResult is set to True the update_event will stop at each event iteration which would require to loop until event_info.newDiscreteStatesNeeded == fmiFalse.

Parameters:

intermediateResult --
    If set to True, the update_event will stop at each event
    iteration.
    Default: False.

Example:

model.event_update()
get_capability_flags()

Returns a dictionary with the capability flags of the FMU.

Returns::
Dictionary with keys:
needsExecutionTool completedIntegratorStepNotNeeded canBeInstantiatedOnlyOncePerProcess canNotUseMemoryManagementFunctions canGetAndSetFMUstate canSerializeFMUstate providesDirectionalDerivatives completedEventIterationIsProvided
get_derivatives()

Returns the derivative of the continuous states.

Returns:

dx --
    The derivatives as an array.

Example:

dx = model.get_derivatives()
get_event_indicators()

Returns the event indicators at the current time-point.

Returns:

evInd --
    The event indicators as an array.

Example:

evInd = model.get_event_indicators()
get_event_info()

Returns the event information from the FMU.

Returns:

The event information, a struct which contains:

newDiscreteStatesNeeded --
    Event iteration did not converge (if True).

terminateSimulation --
    Error, terminate simulation (if True).

nominalsOfContinuousStatesChanged --
    Values of states x have changed (if True).

valuesOfContinuousStatesChanged --
    ValueReferences of states x changed (if True).

nextEventTimeDefined -
    If True, nextEventTime is the next time event.

nextEventTime --
    The next time event.

Example:

event_info    = model.event_info
nextEventTime = model.event_info.nextEventTime
get_tolerances()

Returns the relative and absolute tolerances. If the relative tolerance is defined in the XML-file it is used, otherwise a default of 1.e-4 is used. The absolute tolerance is calculated and returned according to the FMI specification, atol = 0.01*rtol*(nominal values of the continuous states).

Returns:

rtol --
    The relative tolerance.

atol --
    The absolute tolerance.

Example:

[rtol, atol] = model.get_tolerances()
nominal_continuous_states

Returns the nominal values of the continuous states.

Returns:

The nominal values.
simulate()

Compact function for model simulation.

The simulation method depends on which algorithm is used, this can be set with the function argument ‘algorithm’. Options for the algorithm are passed as option classes or as pure dicts. See FMUModel.simulate_options for more details.

The default algorithm for this function is AssimuloFMIAlg.

Parameters:

start_time --
    Start time for the simulation.
    Default: Start time defined in the default experiment from
            the ModelDescription file.

final_time --
    Final time for the simulation.
    Default: Stop time defined in the default experiment from
            the ModelDescription file.

input --
    Input signal for the simulation. The input should be a 2-tuple
    consisting of first the names of the input variable(s) and then
    the data matrix or a function. If a data matrix, the first
    column should be a time vector and then the variable vectors as
    columns. If instead a function, the argument should correspond
    to time and the output the variable data. See the users-guide
    for examples.
    Default: Empty tuple.

algorithm --
    The algorithm which will be used for the simulation is specified
    by passing the algorithm class as string or class object in this
    argument. 'algorithm' can be any class which implements the
    abstract class AlgorithmBase (found in algorithm_drivers.py). In
    this way it is possible to write own algorithms and use them
    with this function.
    Default: 'AssimuloFMIAlg'

options --
    The options that should be used in the algorithm. For details on
    the options do:

        >> myModel = FMUModel(...)
        >> opts = myModel.simulate_options()
        >> opts?

    Valid values are:
        - A dict which gives AssimuloFMIAlgOptions with
          default values on all options except the ones
          listed in the dict. Empty dict will thus give all
          options with default values.
        - An options object.
    Default: Empty dict

Returns:

Result object, subclass of common.algorithm_drivers.ResultBase.
simulate_options()

Get an instance of the simulate options class, filled with default values. If called without argument then the options class for the default simulation algorithm will be returned.

Parameters:

algorithm --
    The algorithm for which the options class should be fetched.
    Possible values are: 'AssimuloFMIAlg'.
    Default: 'AssimuloFMIAlg'

Returns:

Options class for the algorithm specified with default values.
time

Returns the current time of the simulation.

Returns:

The time.
class pyfmi.fmi_coupled.CoupledModelBase

Bases: object

cache
get()

Returns the value(s) of the specified variable(s). The method both accept a single variable and a list of variables.

Parameters:

variable_name --
    The name of the variable(s) as string/list.

Returns:

The value(s).

Example:

# Returns the variable d
Model.get('damper.d')
# Returns a list of the variables
Model.get(['damper.d','gear.a'])
set()

Sets the given value(s) to the specified variable name(s) into the model. The method both accept a single variable and a list of variables.

Parameters:

variable_name --
    The name of the variable(s) as string/list.

value --
    The value(s) to set.

Example:

Model.set('damper.d', 1.1)
Model.set(['damper.d','gear.a'], [1.1, 10])
pyfmi.fmi_coupled.init_f_block()

Module fmi_extended

Module containing the FMI interface Python wrappers.

class pyfmi.fmi_extended.FMUModelME1Extended

Bases: pyfmi.fmi.FMUModelME1

cancel_step()

Cancel a current integrator step. Can only be called if the status from do_step returns FMI_PENDING.

do_step()

Performs an integrator step.

Parameters:

current_time --
        The current communication point (current time) of
        the master.
step_size --
        The length of the step to be taken.
new_step --
        True the last step was accepted by the master and
        False if not.

Returns:

status --
        The status of function which can be checked against
        FMI_OK, FMI_WARNING. FMI_DISCARD, FMI_ERROR,
        FMI_FATAL,FMI_PENDING...

Calls the underlying low-level function fmiDoStep.

get_capability_flags()

Returns a dictionary with the cability flags of the FMU.

Capabilities:

canHandleVariableCommunicationStepSize
canHandleEvents
canRejectSteps
canInterpolateInputs
maxOutputDerivativeOrder
canRunAsynchronuously
canSignalEvents
canBeinstantiatedOnlyOncePerProcess
canNotUseMemoryManagementFunctions
get_derivatives()

Returns the derivative of the continuous states.

Returns:

dx --
    The derivative as an array.

Example:

dx = model.get_derivatives()

Calls the low-level FMI function: fmiGetDerivatives

get_fmu_state()

Copies the internal state of the FMU and returns a class which can be used to again set the state of the FMU at a later time.

note:

fmiStatus fmiGetFMUstate (fmiComponent c, fmiFMUstate* FMUstate);
get_output_derivatives()

Returns the output derivatives for the specified variables. The order specifies the nth-derivative.

Parameters:

variables --
        The variables for which the output derivatives
        should be returned.
order --
        The derivative order.
get_solver_options()

Returns the default solver options

initialize()

Initializes the slave.

Parameters:

start_time --
    Start time of the simulation.
    Default: The start time defined in the model description.

stop_time --
    Stop time of the simulation.
    Default: The stop time defined in the model description.

stop_time_defined --
    Defines if a fixed stop time is defined or not. If this is
    set the simulation cannot go past the defined stop time.
    Default: False

Calls the low-level FMU function: fmiInstantiateSlave

instantiate_slave()

Instantiate the slave.

Parameters:

name --
    The name of the instance.
    Default: 'Slave'

logging --
    Defines if the logging should be turned on or off.
    Default: False, no logging.

Calls the low-level FMI function: fmiInstantiateSlave.

set_fmu_state()

Sets the internal state of the FMU using a class that has been returned from the method get_fmu_state.

note:

fmiStatus fmiSetFMUstate (fmiComponent c, fmiFMUstate  FMUstate);
set_input_derivatives()

Sets the input derivative order for the specified variables.

Parameters:

variables --
        The variables for which the input derivative
        should be set.
values --
        The actual values.
order --
        The derivative orders to set.
set_solver_options()

Specifies the underlying solver and the options to the specified solver.

simulate()

Compact function for model simulation.

The simulation method depends on which algorithm is used, this can be set with the function argument ‘algorithm’. Options for the algorithm are passed as option classes or as pure dicts. See FMUModel.simulate_options for more details.

The default algorithm for this function is FMICSAlg.

Parameters:

start_time --
    Start time for the simulation.
    Default: Start time defined in the default experiment from
            the ModelDescription file.

final_time --
    Final time for the simulation.
    Default: Stop time defined in the default experiment from
            the ModelDescription file.

input --
    Input signal for the simulation. The input should be a 2-tuple
    consisting of first the names of the input variable(s) and then
    the data matrix.
    Default: Empty tuple.

algorithm --
    The algorithm which will be used for the simulation is specified
    by passing the algorithm class as string or class object in this
    argument. 'algorithm' can be any class which implements the
    abstract class AlgorithmBase (found in algorithm_drivers.py). In
    this way it is possible to write own algorithms and use them
    with this function.
    Default: 'FMICSAlg'

options --
    The options that should be used in the algorithm. For details on
    the options do:

        >> myModel = FMUModel(...)
        >> opts = myModel.simulate_options()
        >> opts?

    Valid values are:
        - A dict which gives AssimuloFMIAlgOptions with
          default values on all options except the ones
          listed in the dict. Empty dict will thus give all
          options with default values.
        - An options object.
    Default: Empty dict

Returns:

Result object, subclass of common.algorithm_drivers.ResultBase.
simulate_options()

Get an instance of the simulate options class, prefilled with default values. If called without argument then the options class for the default simulation algorithm will be returned.

Parameters:

algorithm --
    The algorithm for which the options class should be fetched.
    Possible values are: 'FMICSAlg'.
    Default: 'FMICSAlg'

Returns:

Options class for the algorithm specified with default values.
types_platform

Returns the set of valid compatible platforms for the Model, extracted from the XML.

Returns:

types_platform --
    The valid platforms.

Example:

model.types_platform

Module master

class pyfmi.master.Master

Bases: object

DL_prev
I
L
algebraic_loops
check_algebraic_loops()

Simplified check for algebraic loops in simulation mode due to the limited capacity of solving the loops

check_support_storing_fmu_state()
compute_evaluation_order()
compute_global_A()
compute_global_B()
compute_global_C()
compute_global_D()
connection_setup()
connections
copy_fmu_addresses()
correct_output()
correct_output_derivative()
correct_output_second_derivative()
define_connection_matrix()
define_graph()
elapsed_time
elapsed_time_init
error_controlled
exchange_connection_data()
get_connection_derivatives()
get_connection_outputs()
get_connection_second_derivatives()
get_results()

For each model, write the result and load the result file

get_specific_connection_outputs()
initialize()
initialize_result_objects()
input_traj
jacobi_algorithm()
linear_correction
max_output_derivative_order
models
models_dict
models_id_mapping
modify_input()
opts
print_statistics()
report_solution()
reset()

Reset the coupled models.

set_connection_inputs()
set_input()
set_model_order()
set_specific_connection_inputs()
simulate()

Simulates the system.

simulate_options()
simulate_profile()
specify_external_input()
statistics
storing_fmu_state
support_directional_derivatives
support_interpolate_inputs
support_storing_fmu_states
u_m1
ud_m1
udd_m1
verify_connection_variables()
visualize_connections()
y_m1
y_prev
yd_m1
yd_prev
class pyfmi.master.MasterAlgOptions

Bases: pyfmi.common.algorithm_drivers.OptionBase

Options for solving coupled FMI 2 CS FMUs.

Options:

step_size --
    Specfies the global step-size to be used for simulating
    the coupled system.
    Default: 0.01
    
initialize --
    If set to True, the initializing algorithm defined in the FMU models
    are invoked, otherwise it is assumed the user have manually initialized
    all models.
    Default is True.
    
block_initialization --
    If set to True, the initialization algorithm computes the evaluation
    order of the FMUs and tries to resolve algebraic loops by this
    evaluation order.
    Default is False.

extrapolation_order --
    Defines the extrapolation used in the simulation.
    Default is 0 (constant extrapolation).

smooth_coupling --
    Defines if the extrapolation should be smoothen, i.e. the input
    values are adapted so that they are C^0 instead of C^(-1) in case
    extrapolation_order is > 0.
    Default is True

linear_correction --
    Defines if linear correction should be used during the simulation.
    Note that this increases the simulation robustness in case of 
    algebraic loops.
    Default is True

execution --
    Defines if the models are to be evaluated in parallel (note that it
    is not an algorithm change, just an evaluation execution within
    the same algorithm). Note that it requires that PyFMI has been
    installed with OpenMP.
    Default is serial
    
num_threads --
    Defines the number of threads used when the execution is set
    to parallel.
    Default: Number of cores / OpenMP environment variable
    
error_controlled --
    Defines if the algorithm should adapt the step-size during
    the simulation. Note requires that all FMUs support save/get
    state.
    Default: False
    
atol --
    Defines the absolute tolerance used when an error controlled
    simulation is performed.
    Default: 1e-4

rtol --
    Defines the relative tolerance used when an error controlled
    simulation is performed.
    Default: 1e-4
    
maxh --
    Defines the maximum step-size allowed to be used together
    with an error controlled simulation.
    Default: 0.0 (i.e. inactive)

result_file_name --
    Specifies the name of the file where the simulation result is
    written. Setting this option to an empty string results in a default
    file name that is based on the name of the model class.
    Default: Empty string

result_handling --
    Specifies how the result should be handled. Either stored to
    file or stored in memory. One can also use a custom handler.
    Available options: "file", "memory", "csv", "custom"
    Default: "file"

result_handler --
    The handler for the result. Depending on the option in
    result_handling this either defaults to ResultHandlerFile
    or ResultHandlerMemory. If result_handling custom is choosen
    This MUST be provided.
    Default: None

filter --
    A filter for choosing which variables to actually store
    result for. The syntax can be found in
    http://en.wikipedia.org/wiki/Glob_%28programming%29 . An
    example is filter = "*der" , stor all variables ending with
    'der'. Can also be a list. Note that there should be one
    filter for each model.
    Default: None
pyfmi.master.init_f()
pyfmi.master.init_f_block()
pyfmi.master.init_jac()

Module fmi_algorithm_drivers

Module for simulation algorithms to be used together with pyfmi.fmi.FMUModel.simulate.

class pyfmi.fmi_algorithm_drivers.AssimuloFMIAlg(start_time, final_time, input, model, options)[source]

Bases: pyfmi.common.algorithm_drivers.AlgorithmBase

Simulation algortihm for FMUs using the Assimulo package.

classmethod get_default_options()[source]

Get an instance of the options class for the AssimuloFMIAlg algorithm, prefilled with default values. (Class method.)

get_result()[source]

Write result to file, load result data and create an AssimuloSimResult object.

Returns:

The AssimuloSimResult object.
solve()[source]

Runs the simulation.

class pyfmi.fmi_algorithm_drivers.AssimuloFMIAlgOptions(*args, **kw)[source]

Bases: pyfmi.common.algorithm_drivers.OptionBase

Options for the solving the FMU using the Assimulo simulation package.

Assimulo options:

solver --
    Specifies the simulation algorithm that is to be used.
    Default: 'CVode'

ncp    --
    Number of communication points. If ncp is zero, the solver will
    return the internal steps taken.
    Default: '0'

initialize --
    If set to True, the initializing algorithm defined in the FMU model
    is invoked, otherwise it is assumed the user have manually invoked
    model.initialize()
    Default is True.

write_scaled_result --
    Set this parameter to True to write the result to file without
    taking scaling into account. If the value of scaled is False,
    then the variable scaling factors of the model are used to
    reproduced the unscaled variable values.
    Default: False

result_file_name --
    Specifies the name of the file where the simulation result is
    written. Setting this option to an empty string results in a default
    file name that is based on the name of the model class.
    Default: Empty string

with_jacobian --
    Determines if the Jacobian should be computed from PyFMI (using 
    either the directional derivatives, if available, or estimed using
    finite differences) or if the Jacobian should be computed by the
    choosen solver. The default is to use PyFMI if directional
    derivatives are available, otherwise computed by the choosen
    solver.
    Default: "Default"

logging --
    If True, creates a logfile from the solver in the current
    directory.
    Default: False

result_handling --
    Specifies how the result should be handled. Either stored to
    file (txt or binary) or stored in memory. One can also use a 
    custom handler.
    Available options: "file", "binary", "memory", "csv", "custom"
    Default: "binary"

result_handler --
    The handler for the result. Depending on the option in
    result_handling this either defaults to ResultHandlerFile
    or ResultHandlerMemory. If result_handling custom is chosen
    This MUST be provided.
    Default: None
    
return_result --
    Determines if the simulation result should be returned or 
    not. If set to False, the simulation result is not loaded
    into memory after the simulation finishes.
    Default: True

filter --
    A filter for choosing which variables to actually store
    result for. The syntax can be found in
    http://en.wikipedia.org/wiki/Glob_%28programming%29 . An
    example is filter = "*der" , stor all variables ending with
    'der'. Can also be a list.
    Default: None

The different solvers provided by the Assimulo simulation package provides different options. These options are given in dictionaries with names consisting of the solver name concatenated by the string ‘_options’. The most common solver options are documented below, for a complete list of options see, http://www.jmodelica.org/assimulo

Options for CVode:

rtol    --
    The relative tolerance. The relative tolerance are retrieved from
    the 'default experiment' section in the XML-file and if not
    found are set to 1.0e-4
    Default: "Default" (1.0e-4)

atol    --
    The absolute tolerance.
    Default: "Default" (rtol*0.01*(nominal values of the continuous states))

discr   --
    The discretization method. Can be either 'BDF' or 'Adams'
    Default: 'BDF'

iter    --
    The iteration method. Can be either 'Newton' or 'FixedPoint'
    Default: 'Newton'
class pyfmi.fmi_algorithm_drivers.FMICSAlg(start_time, final_time, input, model, options)[source]

Bases: pyfmi.common.algorithm_drivers.AlgorithmBase

Simulation algortihm for FMUs (Co-simulation).

classmethod get_default_options()[source]

Get an instance of the options class for the FMICSAlg algorithm, prefilled with default values. (Class method.)

get_result()[source]

Write result to file, load result data and create an FMICSResult object.

Returns:

The FMICSResult object.
solve()[source]

Runs the simulation.

class pyfmi.fmi_algorithm_drivers.FMICSAlgOptions(*args, **kw)[source]

Bases: pyfmi.common.algorithm_drivers.OptionBase

Options for the solving the CS FMU.

Options:

ncp    --
    Number of communication points.
    Default: '500'

initialize --
    If set to True, the initializing algorithm defined in the FMU model
    is invoked, otherwise it is assumed the user have manually invoked
    model.initialize()
    Default is True.
    
stop_time_defined --
    If set to True, the model cannot be computed past the set final_time,
    even in a continuation run. This is only applicable when initialize
    is set to True. For more information, see the FMI specification.
    Default False.

write_scaled_result --
    Set this parameter to True to write the result to file without
    taking scaling into account. If the value of scaled is False,
    then the variable scaling factors of the model are used to
    reproduced the unscaled variable values.
    Default: False

result_file_name --
    Specifies the name of the file where the simulation result is
    written. Setting this option to an empty string results in a default
    file name that is based on the name of the model class.
    Default: Empty string

result_handling --
    Specifies how the result should be handled. Either stored to
    file (txt or binary) or stored in memory. One can also use a 
    custom handler.
    Available options: "file", "binary", "memory", "csv", "custom"
    Default: "binary"

result_handler --
    The handler for the result. Depending on the option in
    result_handling this either defaults to ResultHandlerFile
    or ResultHandlerMemory. If result_handling custom is chosen
    This MUST be provided.
    Default: None

return_result --
    Determines if the simulation result should be returned or 
    not. If set to False, the simulation result is not loaded
    into memory after the simulation finishes.
    Default: True
    
time_limit --
    Specifies an upper bound on the time allowed for the 
    integration to be completed. The time limit is specified 
    in seconds. Note that the time limit is only checked after
    a completed step. This means that if a do step takes a lot
    of time, the execution will not stop at exactly the time
    limit.
    Default: none

filter --
    A filter for choosing which variables to actually store
    result for. The syntax can be found in
    http://en.wikipedia.org/wiki/Glob_%28programming%29 . An
    example is filter = "*der" , stor all variables ending with
    'der'. Can also be a list.
    Default: None
class pyfmi.fmi_algorithm_drivers.FMIResult(model=None, result_file_name=None, solver=None, result_data=None, options=None, status=0, detailed_timings=None)[source]

Bases: pyfmi.common.algorithm_drivers.JMResultBase

class pyfmi.fmi_algorithm_drivers.SciEstAlg(parameters, measurements, input, model, options)[source]

Bases: pyfmi.common.algorithm_drivers.AlgorithmBase

Estimation algortihm for FMUs.

classmethod get_default_options()[source]

Get an instance of the options class for the SciEstAlg algorithm, prefilled with default values. (Class method.)

get_result()[source]

Write result to file, load result data and create an SciEstResult object.

Returns:

The SciEstResult object.
solve()[source]

Runs the estimation.

class pyfmi.fmi_algorithm_drivers.SciEstAlgOptions(*args, **kw)[source]

Bases: pyfmi.common.algorithm_drivers.OptionBase

Options for the solving an estimation problem.

Options:

tolerance    --
    The tolerance for the estimation algorithm
    Default: 1e-6
    
method       --
    The method to use, available methods are methods from:
    scipy.optimize.minimize.
    Default: 'Nelder-Mead'
    
scaling      --
    The scaling of the parameters during the estimation.
    Default: The nominal values
    
simulate_options    --
    The simulation options to use when simulating the model
    in order to get the estimated data.
    Default: The default options for the underlying model.
    
result_file_name --
    Specifies the name of the file where the result is written.
    Setting this option to an empty string results in a default
    file name that is based on the name of the model class.
    Default: Empty string

Module debug

This file contains methods for helping with debugging a simulation.

class pyfmi.debug.CVodeDebugInformation(file_name)[source]

Bases: pyfmi.debug.DebugInformation

plot_error(threshold=None, region=None, legend=True)[source]
plot_order()[source]
class pyfmi.debug.DebugInformation(file_name)[source]
plot_cumulative_time_elapsed(log_scale=False)[source]
plot_event_indicators(mask=None, region=None)[source]
plot_step_size()[source]
plot_time_distribution(normalized=False)[source]
class pyfmi.debug.ExplicitEulerDebugInformation(file_name)[source]

Bases: pyfmi.debug.DebugInformation

class pyfmi.debug.ImplicitEulerDebugInformation(file_name)[source]

Bases: pyfmi.debug.DebugInformation

class pyfmi.debug.Radau5ODEDebugInformation(file_name)[source]

Bases: pyfmi.debug.CVodeDebugInformation

Module fmi_util

Module containing the FMI interface Python wrappers.

class pyfmi.fmi_util.Graph
add_edges_between_outputs()
compute_evaluation_order()
compute_evaluation_order_old()
dfs()
dump_graph_dot()
digraph { node [texmode = “math”]; u12 -> y12 -> u23 -> y13 -> u21 -> y11 -> u12 -> y22; u11 -> y21 -> u22 -> y12; y22 -> u13 -> y23; u11 [label=”u_1^{[1]}”, pos=”-0.9,4!”]; u12;// [label=”u_1^{[2]}”]; u22 [label=”u_2^{[2]}”]; u21 [label=”u_2^{[1]}”]; u13;// [label=”u_1^{[3]}”]; u23 [label=”u_2^{[3]}”]; y11 [label=”y_1^{[1]}”]; y21 [label=”y_2^{[1]}”]; y12 [label=”y_1^{[2]}”]; y22;// [label=”y_2^{[2]}”]; y13 [label=”y_1^{[3]}”]; y23;// [label=”y_2^{[3]}”];

}

group_connected_components()
group_node()
grouped_order()
join_output_trees()
prepare_graph()
simple_loop()
split_components()
strongly_connected_components()
tear_graph()
tear_node()
class pyfmi.fmi_util.OrderedSet

Bases: _abcoll.MutableSet

add()
discard()
pop()
pyfmi.fmi_util.convert_array_names_list_names()
pyfmi.fmi_util.convert_array_names_list_names_int()
pyfmi.fmi_util.convert_scalarvariable_name_to_str()
pyfmi.fmi_util.convert_str_list()
pyfmi.fmi_util.cpr_seed()
pyfmi.fmi_util.enable_caching()
pyfmi.fmi_util.parameter_estimation_f()
pyfmi.fmi_util.prepare_data_info()