Common Folder

Base common

The JModelica.org <http:/www.jmodelica.org/> Python package for common classes and functions.

Module algorithm_drivers

Module containing optimization, simulation and initialization algorithms.

class pyfmi.common.algorithm_drivers.AlgorithmBase(model, alg_args)[source]

Bases: object

Abstract class which all algorithms that are to be used in simulating/optimization/initialization with Model classes extending common.core.BaseModel must implement.

classmethod get_default_options()[source]
get_result()[source]
solve()[source]
class pyfmi.common.algorithm_drivers.AssimuloSimResult(model=None, result_file_name=None, solver=None, result_data=None, options=None)[source]

Bases: pyfmi.common.algorithm_drivers.JMResultBase

exception pyfmi.common.algorithm_drivers.InvalidAlgorithmOptionException(arg)[source]

Bases: exceptions.Exception

Exception raised when an algorithm options argument is encountered that is not valid.

exception pyfmi.common.algorithm_drivers.InvalidSolverArgumentException(arg)[source]

Bases: exceptions.Exception

Exception raised when a solver argument is encountered that does not exist.

class pyfmi.common.algorithm_drivers.JMResultBase(model=None, result_file_name=None, solver=None, result_data=None, options=None)[source]

Bases: pyfmi.common.algorithm_drivers.ResultBase

data_matrix

Property for accessing the result matrix.

final(key)[source]

Returns the final value of a variable result trajectory.

Parameters:

key --
    Name of the variable/parameter/constant.
get_column(name)[source]

Returns the column number in the data matrix where the values of the variable are stored.

Parameters:

name --
    Name of the variable/parameter/constant.

Returns:

The column number.
initial(key)[source]

Returns the initial value of a variable result trajectory.

Parameters:

key --
    Name of the variable/parameter/constant.
is_negated(name)[source]
is_variable(name)[source]

Returns True if the given name corresponds to a time-varying variable.

Parameters:

name --
    Name of the variable/parameter/constant.

Returns:

True if the variable is time-varying.
keys()[source]

Returns the variable names in the result file.

class pyfmi.common.algorithm_drivers.OptionBase(*args, **kw)[source]

Bases: dict

Base class for an algorithm option class.

All algorithm option classes should extend this class.

This class extends the dict class overriding __init__, __setitem__, update and setdefault methods with the purpose of offering a key check for the extending classes.

The extending class can define a set of keys and default values by overriding __init__ or when instantiating the extended class and thereby not allow any other keys to be added to the dict.

Example overriding __init__:

class MyOptionsClass(OptionBase):
    def __init__(self, *args, **kw):
        mydefaults = {'def1':1, 'def2':2}
        super(MyOptionsClass,self).__init__(mydefaults)
    
        self.update(*args, **kw)
        
>> opts = MyOptionsClass()
>> opts['def1'] = 3   // ok
>> opts.update({'def2':4})   // ok
>> opts['def3']= 5   // not ok

        
 * Example setting defaults in constructor:
 
 class MyOptionsClass(OptionBase):pass
 
>> opts = MyOptionsClass(def1=1, def2=2)
>> opts['def1'] = 3   // ok
>> opts.update({'def2':4})   // ok
>> opts['def3']= 5   // not ok

>> opts2 = MyOptionsClass()   // this class has no restrictions on keys
>> opts2['def5'] = 'hello'   //ok
setdefault(key, value=None)[source]
update(*args, **kw)[source]
class pyfmi.common.algorithm_drivers.ResultBase(model=None, result_file_name=None, solver=None, result_data=None, options=None)[source]

Bases: object

Base class for an algorithm result. All algorithms used in any of the high-level functions should return an object which extends this class.

model

Property for accessing the model that was used in the algorithm.

options

Property for accessing he options object holding the options used in the algorithm.

result_data

Property for accessing the result data matrix that was created in the algorithm.

result_file

Property for accessing the name of the result file created in the algorithm.

solver

Property for accessing the solver that was used in the algorithm.

exception pyfmi.common.algorithm_drivers.UnrecognizedOptionError[source]

Bases: exceptions.Exception

Module core

Module containing base classes and functionality.

class pyfmi.common.core.ModelBase[source]

Bases: object

Abstract Model class containing base functionality.

get(variable_name)[source]

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
(FMU)Model.get('damper.d') 
# Returns a list of the variables
(FMU)Model.get(['damper.d','gear.a'])
get_boolean(valueref)[source]
get_integer(valueref)[source]
get_real(valueref)[source]
get_string(valueref)[source]
initialize()[source]
initialize_options(algorithm)[source]
optimize()[source]
optimize_options(algorithm)[source]
set(variable_name, value)[source]

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:

(FMU)Model.set('damper.d', 1.1)
(FMU)Model.set(['damper.d','gear.a'], [1.1, 10])
set_boolean(valueref, value)[source]
set_integer(valueref, value)[source]
set_real(valueref, value)[source]
set_string(valueref, value)[source]
simulate()[source]
simulate_options(algorithm)[source]
class pyfmi.common.core.Trajectory(abscissa, ordinate, tol=1e-08)[source]

Base class for representation of trajectories.

abscissa

Property for accessing the abscissa of the trajectory.

eval(x)[source]

Evaluate the trajectory at a specifed abscissa.

Parameters:

x -- 
    One dimensional numpy array, or scalar number, containing n 
    abscissa value(s).

Returns:

Two dimensional n x m matrix containing the ordinate values 
corresponding to the argument x.
ordinate

Property for accessing the ordinate of the trajectory.

class pyfmi.common.core.TrajectoryConstantInterpolationExtrapolation(abscissa, ordinate, tol=1e-08)[source]

Bases: pyfmi.common.core.Trajectory

eval(x)[source]

Evaluate the trajectory at a specified abscissa. If the values are inside the data range the values are interpolated and if they are outside, extrapolated.

Parameters:

x -- 
    One dimensional numpy array, or scalar number, containing n 
    abscissa value(s).

Returns:

Two dimensional n x m matrix containing the ordinate values 
corresponding to the argument x.

Note:

See http://stackoverflow.com/questions/2745329/how-to-make-scipy-interpolate-give-a-an-extrapolated-result-beyond-the-input-ran
set_mode(mode)[source]

Specifices whether or not forward or backward mode should be used in the interpolation/extrapolation.

class pyfmi.common.core.TrajectoryLinearInterpolation(abscissa, ordinate, tol=1e-08)[source]

Bases: pyfmi.common.core.Trajectory

eval(x)[source]

Evaluate the trajectory at a specifed abscissa.

Parameters:

x -- 
    One dimensional numpy array, or scalar number, containing n 
    abscissa value(s).

Returns:

Two dimensional n x m matrix containing the ordinate values 
corresponding to the argument x.
class pyfmi.common.core.TrajectoryLinearInterpolationExtrapolation(abscissa, ordinate, tol=1e-08)[source]

Bases: pyfmi.common.core.Trajectory

eval(x)[source]

Evaluate the trajectory at a specified abscissa. If the values are inside the data range the values are interpolated and if they are outside, extrapolated.

Parameters:

x -- 
    One dimensional numpy array, or scalar number, containing n 
    abscissa value(s).

Returns:

Two dimensional n x m matrix containing the ordinate values 
corresponding to the argument x.

Note:

See http://stackoverflow.com/questions/2745329/how-to-make-scipy-interpolate-give-a-an-extrapolated-result-beyond-the-input-ran
class pyfmi.common.core.TrajectoryUserFunction(func)[source]

Bases: pyfmi.common.core.Trajectory

eval(x)[source]

Evaluate the trajectory at a specifed abscissa.

Parameters:

x -- 
    One dimensional numpy array, or scalar number, containing a 
    abscissa value.

Returns:

Two dimensional n x m matrix containing the ordinate values 
corresponding to the argument x.
pyfmi.common.core.create_temp_dir()[source]

Create a temporary directory for extracting an FMU in or similar

pyfmi.common.core.create_temp_file()[source]

Create a temporary file.

pyfmi.common.core.delete_temp_dir(tmp_dir)[source]

This method deletes a temporary directory that has been created by for instance create_temp_dir.

pyfmi.common.core.delete_temp_file(tmp_file)[source]

This method deletes a temporary file that has been created by for instance create_temp_file.

pyfmi.common.core.get_files_in_archive(path)[source]

Get paths to all unit files and directories in archive.

Parameters:

path --
    The path to the archive directory.

Returns:

Dict with path to the file or directory as value or None if not found. 
Keys are used to access the unit specific files or directories, possible 
values are:
    - root : Root of archive (same as path)
    - model_desc : XML description of model (required)
    - image : Image file of model icon (optional)
    - documentation_dir : Directory containing the model documentation (optional)
    - sources_dir : Directory containing source files (optional)
    - binaries_dir : Directory containing the binaries (required)
    - resources_dir : Directory containing resources needed by the model (optional)
pyfmi.common.core.get_platform_dir()[source]

Get the platform specific name of binaries directory.

Returns:

The name of the binaries directory. Possible values are:
    - win32
    - win64
    - darwin32
    - darwin64
    - linux32
    - linux64
pyfmi.common.core.get_platform_suffix(type='dynamic_lib')[source]

Get the platform dependent suffix based on the file type.

Parameters:

type --
    The file type. Currently only dynamic_lib is possible.
    Default: 'dynamic_lib'

Returns:

The platform specific file suffix depending on type or empty string if 
no possible match was found.
pyfmi.common.core.get_temp_location()[source]

Get the directory where the temporary files are placed.

Returns:

The location of temporary files.
pyfmi.common.core.get_unit_name(class_name, unit_type='FMU')[source]

Computes the unit name from a class name.

Parameters:

class_name -- 
    The name of the model.
    
unit_type --
    The unit type. Possible values: FMU, FMUX.
    Default: 'FMU'

Returns:

The unit name (replaced dots with underscores).
pyfmi.common.core.list_to_string(item_list)[source]

Helper function that takes a list of items, which are typed to str and returned as a string with the list items separated by platform dependent path separator. For example:

(platform = win)
item_list = [1, 2, 3]
return value: '1;2;3'
pyfmi.common.core.rename_to_tmp(filename, path='.', filetype='dynamic_lib')[source]

Take a file and give it a random temporary name.

Parameters:

filename --
    Name of file to rename.
    
path --
    Path to the file to rename. This is also where the renamed file will 
    end up.
    Default: Current directory.
    
filetype --
    Type of file to rename, used so that platform specific suffixes can 
    be taken into consideration. Currently only dynamic libary is possible.
    Default: 'dynamic_lib'
pyfmi.common.core.unzip_unit(archive, path='.')[source]

Unzip a unit file.

Extracts all files in archive in temporary location as returned by get_temp_location().

Parameters:

archive --
    The archive file name.
    
path --
    The path to the archive file.
    Default: Current directory.

Returns:

Path to the root of the extracted archive.

Module io

Module for writing optimization and simulation results to file.

exception pyfmi.common.io.JIOError(message)[source]

Bases: exceptions.Exception

Base class for exceptions specific to this module.

class pyfmi.common.io.ResultCSVTextual(filename, delimiter=';')[source]
get_data_matrix()[source]

Returns the result matrix.

Returns:

The result data matrix.
get_variable_data(name)[source]

Retrieve the data sequence for a variable with a given name.

Parameters:

name --
    Name of the variable.

Returns:

A Trajectory object containing the time vector and the data vector 
of the variable.
is_negated(name)[source]
is_variable(name)[source]
class pyfmi.common.io.ResultDymola[source]

Base class for representation of a result file.

get_variable_index(name)[source]

Retrieve the index in the name vector of a given variable.

Parameters:

name --
    Name of variable.

Returns:

In integer index.
class pyfmi.common.io.ResultDymolaBinary(fname)[source]

Bases: pyfmi.common.io.ResultDymola

Class representing a simulation or optimization result loaded from a Dymola binary file.

description

Property for accessing the description vector.

get_column(name)[source]

Returns the column number in the data matrix where the values of the variable are stored.

Parameters:

name -- 
    Name of the variable/parameter/constant.

Returns:

The column number.
get_data_matrix()[source]

Returns the result matrix.

Returns:

The result data matrix.
get_variable_data(name)[source]

Retrieve the data sequence for a variable with a given name.

Parameters:

name --
    Name of the variable.

Returns:

A Trajectory object containing the time vector and the data vector 
of the variable.
is_negated(name)[source]

Returns True if the given name corresponds to a negated result vector.

Parameters:

name -- 
    Name of the variable/parameter/constant.

Returns:

True if the result should be negated
is_variable(name)[source]

Returns True if the given name corresponds to a time-varying variable.

Parameters:

name -- 
    Name of the variable/parameter/constant.

Returns:

True if the variable is time-varying.
class pyfmi.common.io.ResultDymolaTextual(fname)[source]

Bases: pyfmi.common.io.ResultDymola

Class representing a simulation or optimization result loaded from a Dymola binary file.

append(res)[source]

Append another simulation result. The time vector of the appended trajectories is shifted so that the appended trajectories appears after the original result trajectories.

Parameters::
res –
A simulation result object of type DymolaResultTextual.
get_column(name)[source]

Returns the column number in the data matrix where the values of the variable are stored.

Parameters:

name -- 
    Name of the variable/parameter/constant.

Returns:

The column number.
get_data_matrix()[source]

Returns the result matrix.

Returns:

The result data matrix.
get_variable_data(name)[source]

Retrieve the data sequence for a variable with a given name.

Parameters:

name --
    Name of the variable.

Returns:

A Trajectory object containing the time vector and the data vector 
of the variable.
is_negated(name)[source]

Returns True if the given name corresponds to a negated result vector.

Parameters:

name -- 
    Name of the variable/parameter/constant.

Returns:

True if the result should be negated
is_variable(name)[source]

Returns True if the given name corresponds to a time-varying variable.

Parameters:

name -- 
    Name of the variable/parameter/constant

Returns:

True if the variable is time-varying.
shift_time(time_shift)[source]

Shift the time vector using a fixed offset.

Parameters::
time_shift –
The time shift offset.
class pyfmi.common.io.ResultHandler[source]
get_result()[source]

Method for retrieving the result. This method should return a result of an instance of ResultStorage or of an instance of a subclass of ResultStorage.

initialize_complete()[source]

This method is called after the initialization method of the FMU has been been called.

integration_point(solver=None)[source]

This method is called for each time-point for which result are to be stored as indicated by the “number of communcation points” provided to the simulation method.

set_options(options)[source]

Options are the options dictionary provided to the simulation method.

simulation_end()[source]

This method is called at the end of a simulation.

simulation_start()[source]

This method is called before the simulation has started and after the initialization call for the FMU.

class pyfmi.common.io.ResultHandlerBinaryFile(model)[source]

Bases: pyfmi.common.io.ResultHandler

Export an optimization or simulation result to file in Dymola’s binary result file format (MATLAB v4 format).

convert_char_array(data)[source]
dump_data(data)[source]
dump_native_data(data)[source]
get_result()[source]

Method for retrieving the result. This method should return a result of an instance of ResultBase or of an instance of a subclass of ResultBase.

initialize_complete()[source]
integration_point(solver=None)[source]

Writes the current status of the model to file. If the header has not been written previously it is written now. If data is specified it is written instead of the current status.

Parameters:

data --
    A one dimensional array of variable trajectory data. data 
    should consist of information about the status in the order 
    specified by FMUModel.save_time_point()
    Default: None
set_options(options)[source]

Options are the options dictionary provided to the simulation method.

simulation_end()[source]

Finalize the writing by filling in the blanks in the created file. The blanks consists of the number of points and the final time (in data set 1). Also closes the file.

simulation_start()[source]

Opens the file and writes the header. This includes the information about the variables and a table determining the link between variables and data.

class pyfmi.common.io.ResultHandlerCSV(model, delimiter=';')[source]

Bases: pyfmi.common.io.ResultHandler

get_result()[source]

Method for retrieving the result. This method should return a result of an instance of ResultBase or of an instance of a subclass of ResultBase.

initialize_complete()[source]
integration_point(solver=None)[source]

Writes the current status of the model to file. If the header has not been written previously it is written now. If data is specified it is written instead of the current status.

Parameters:

data --
    A one dimensional array of variable trajectory data. data 
    should consist of information about the status in the order 
    specified by FMUModel.save_time_point()
    Default: None
set_options(options)[source]

Options are the options dictionary provided to the simulation method.

simulation_end()[source]

Finalize the writing by filling in the blanks in the created file. The blanks consists of the number of points and the final time (in data set 1). Also closes the file.

simulation_start()[source]

Opens the file and writes the header. This includes the information about the variables and a table determining the link between variables and data.

class pyfmi.common.io.ResultHandlerDummy(model)[source]

Bases: pyfmi.common.io.ResultHandler

get_result()[source]
class pyfmi.common.io.ResultHandlerFile(model)[source]

Bases: pyfmi.common.io.ResultHandler

Export an optimization or simulation result to file in Dymola’s result file format.

get_result()[source]

Method for retrieving the result. This method should return a result of an instance of ResultBase or of an instance of a subclass of ResultBase.

initialize_complete()[source]
integration_point(solver=None)[source]

Writes the current status of the model to file. If the header has not been written previously it is written now. If data is specified it is written instead of the current status.

Parameters:

data --
    A one dimensional array of variable trajectory data. data 
    should consist of information about the status in the order 
    specified by FMUModel.save_time_point()
    Default: None
set_options(options)[source]

Options are the options dictionary provided to the simulation method.

simulation_end()[source]

Finalize the writing by filling in the blanks in the created file. The blanks consists of the number of points and the final time (in data set 1). Also closes the file.

simulation_start()[source]

Opens the file and writes the header. This includes the information about the variables and a table determining the link between variables and data.

class pyfmi.common.io.ResultHandlerMemory(model)[source]

Bases: pyfmi.common.io.ResultHandler

get_result()[source]

Method for retrieving the result. This method should return a result of an instance of ResultBase or of an instance of a subclass of ResultBase.

initialize_complete()[source]

This method is called after the initialization method of the FMU has been been called.

integration_point(solver=None)[source]

This method is called for each time-point for which result are to be stored as indicated by the “number of communcation points” provided to the simulation method.

set_options(options)[source]

Options are the options dictionary provided to the simulation method.

simulation_end()[source]

The finalize method can be used to for instance close the file. ANd this method is called after the simulation has completed.

simulation_start()[source]

This method is called before the simulation has started and before the initialization of the model.

class pyfmi.common.io.ResultStorage[source]
get_variable_data(key)[source]
is_negated(var)[source]
is_variable(var)[source]
class pyfmi.common.io.ResultStorageMemory(model, data, vars_ref, vars)[source]

Bases: pyfmi.common.io.ResultDymola

Class representing a simulation result that is kept in MEMORY.

get_column(name)[source]

Returns the column number in the data matrix where the values of the variable are stored.

Parameters:

name --  
    Name of the variable/parameter/constant. 

Returns:

The column number. 
get_data_matrix()[source]

Returns the result matrix.

Returns:

The result data matrix. 
get_variable_data(name)[source]

Retrieve the data sequence for a variable with a given name.

Parameters:

name -- 
    Name of the variable. 

Returns:

A Trajectory object containing the time vector and the data vector  
of the variable. 
is_negated(name)[source]

Returns True if the given name corresponds to a negated result vector.

Parameters:

name --  
    Name of the variable/parameter/constant. 

Returns:

True if the result should be negated 
is_variable(name)[source]

Returns True if the given name corresponds to a time-varying variable.

Parameters:

name --  
    Name of the variable/parameter/constant. 

Returns:

True if the variable is time-varying. 
class pyfmi.common.io.ResultWriter[source]

Base class for writing results to file.

write_finalize()[source]

The finalize method can be used to for instance close the file.

write_header()[source]

The header is intended to be used for writing general information about the model. This is intended to be called once.

write_point()[source]

This method does the writing of the actual result.

class pyfmi.common.io.ResultWriterDymola(model, format='txt')[source]

Bases: pyfmi.common.io.ResultWriter

Export an optimization or simulation result to file in Dymola’s result file format.

write_finalize()[source]

Finalize the writing by filling in the blanks in the created file. The blanks consists of the number of points and the final time (in data set 1). Also closes the file.

write_header(file_name='', parameters=None)[source]

Opens the file and writes the header. This includes the information about the variables and a table determining the link between variables and data.

Parameters:

file_name --
    If no file name is given, the name of the model (as defined by 
    FMUModel.get_identifier()) concatenated with the string '_result' is 
    used. A file suffix equal to the format argument is then 
    appended to the file name.
    Default: Empty string.
write_point(data=None, parameter_data=[])[source]

Writes the current status of the model to file. If the header has not been written previously it is written now. If data is specified it is written instead of the current status.

Parameters:

data --
    A one dimensional array of variable trajectory data. data 
    should consist of information about the status in the order 
    specified by FMUModel.save_time_point()
    Default: None
class pyfmi.common.io.Trajectory(t, x)[source]

Class for storing a time series.

exception pyfmi.common.io.VariableNotFoundError(message)[source]

Bases: pyfmi.common.io.JIOError

Exception that is thrown when a variable is not found in a data file.

exception pyfmi.common.io.VariableNotTimeVarying(message)[source]

Bases: pyfmi.common.io.JIOError

Exception that is thrown when a column is asked for a parameter/constant.

pyfmi.common.io.robust_float(value)[source]

Function for robust handling of float values such as INF and NAN.

Module xmlparser

Module containing XML parser and validator providing an XML data structure based on the XML schemas fmiModelDescription.xsd, fmiExtendedModelDescription.xsd and jmodelicaModelDescription.xsd which can be used to extract information from an XML file - provided the XML file will validate with the above schemas.

class pyfmi.common.xmlparser.Annotation(element)[source]

Class defining data structure based on the XML element Annotation.

get_name()[source]

Get the value of the name attribute.

Returns:

The name attribute value as string.
get_value()[source]

Get the value of the value attribute.

Returns:

The value attribute value as string.
class pyfmi.common.xmlparser.BaseUnit(element)[source]

Class defining data structure based on the XML element BaseUnit.

get_display_units()[source]

Get all display units in the BaseUnit element.

Returns:

A list of all display units (type: DisplayUnitDefinition)
get_unit()[source]

Get the BaseUnit attribute unit.

Returns:

The unit attribute value as string.
class pyfmi.common.xmlparser.Boolean(element)[source]

Class defining data structure based on the XML element Boolean.

get_declared_type()[source]

Get the value of the declared type attribute.

Returns:

The declared type attribute value as string (empty string if not 
set).
get_fixed()[source]

Get the value of the fixed attribute.

Returns:

The fixed attribute value as bool (None if not set).
get_free()[source]

Get the value of the free attribute.

Returns:

The free attribute value as bool (None if not set).
get_initial_guess()[source]

Get the value of the attribute.

Returns:

The initial guess attribute value as bool (None if not set).
get_start()[source]

Get the value of the start attribute.

Returns:

The start attribute value as bool (None if not set).
class pyfmi.common.xmlparser.BooleanParameter(element)[source]

Bases: pyfmi.common.xmlparser.Parameter

Class representing an independent boolean parameter in a IndependentParameters XML document representation.

get_value()[source]

Get the value of the parameter.

Returns:

The value of the parameter as boolean.
set_value(value)[source]

Set the value of the parameter.

Parameters:

value --
    The new value of the parameter.
class pyfmi.common.xmlparser.BooleanType(element)[source]

Class defining data structure based on the XML element BooleanType. Is empty since XML element contains no attributes or other elements.

class pyfmi.common.xmlparser.DefaultExperiment(element)[source]

Class defining data structure based on the XML element DefaultExperiment.

get_start_time()[source]

Get the value of the start time attribute.

Returns:

The start time attribute value as float (None if not set).
get_stop_time()[source]

Get the value of the stop time attribute.

Returns:

The stop time attribute value as float (None if not set).
get_tolerance()[source]

Get the value of the tolerance attribute.

Returns:

The tolerance attribute value as float (None if not set).
class pyfmi.common.xmlparser.DirectDependency(element)[source]

Class defining data structure based on the XML element DirectDependency.

get_names()[source]

Get the names of the input variables needed to compute this output.

Returns:

A list of variable names as string.
class pyfmi.common.xmlparser.DisplayUnitDefinition(element)[source]

Class defining data structure based on the XML element DisplayUnitDefinition.

get_display_unit()[source]

Get the value of the display unit attribute.

Returns:

The display unit attribute value as string.
get_gain()[source]

Get the value of the gain attribute.

Returns:

The gain attribute value as float (default: 1).
get_offset()[source]

Get the value of the offset attribute.

Returns:

The offset attribute value as float (default: 0).
class pyfmi.common.xmlparser.EnumParameter(element)[source]

Bases: pyfmi.common.xmlparser.Parameter

Class representing an independent enumeration parameter in a IndependentParameters XML document representation.

get_value()[source]

Get the value of the parameter.

Returns:

The value of the parameter as integer.
set_value(value)[source]

Set the value of the parameter.

Parameters:

value --
    The new value of the parameter.
class pyfmi.common.xmlparser.Enumeration(element)[source]

Class defining data structure based on the XML element Enumeration.

get_declared_type()[source]

Get the value of the declared type attribute.

Returns:

The declared type attribute value as string.
get_fixed()[source]

Get the value of the fixed attribute.

Returns:

The fixed attribute value as bool (None if not set).
get_free()[source]

Get the value of the free attribute.

Returns:

The free attribute value as bool (None if not set).
get_max()[source]

Get the value of the max attribute.

Returns:

The max attribute value as int (None if not set).
get_min()[source]

Get the value of the min attribute.

Returns:

The min attribute value as int (None if not set).
get_quantity()[source]

Get the value of the quantity attribute.

Returns:

The quantity attribute value as string (empty string if not 
set).
get_start()[source]

Get the value of the start attribute.

Returns:

The start attribute value as int (None if not set).
class pyfmi.common.xmlparser.EnumerationType(element)[source]

Class defining data structure based on the XML element EnumerationType.

get_items()[source]

Get the items defined in the enumeration.

Returns:

A list of all items (type: Item)
get_max()[source]

Get the value of the max attribute.

Returns:

The max attribute value as int (None if not set).
get_min()[source]

Get the value of the min attribute.

Returns:

The min attribute value as int (None if not set).
get_quantity()[source]

Get the value of the quantity attribute.

Returns:

The quantity attribute value as string (empty string if not set).
class pyfmi.common.xmlparser.IndependentParameters(filename, schemaname='')[source]
get_all_parameters()[source]

Get a list of all parameters in this XML representation.

Returns:

A list of all parameters.
get_iparam_values(ignore_cache=False)[source]

Extract name and value for all independent parameters in the XML document.

Returns:

A dict with variable name as key and parameter as value.
write_to_file(filename)[source]

Create a new XML file of the document representation.

Parameters:

filename --
    Full path of the file to create.
class pyfmi.common.xmlparser.Integer(element)[source]

Class defining data structure based on the XML element Integer.

get_declared_type()[source]

Get the value of the declared type attribute.

Returns:

The declared type attribute value as string (empty string if not 
set).
get_fixed()[source]

Get the value of the fixed attribute.

Returns:

The fixed attribute value as bool (None if not set).
get_free()[source]

Get the value of the free attribute.

Returns:

The free attribute value as bool (None if not set).
get_initial_guess()[source]

Get the value of the attribute.

Returns:

The initial guess attribute value as int (None if not set).
get_max()[source]

Get the value of the max attribute.

Returns:

The max attribute value as int (None if not set).
get_min()[source]

Get the value of the min attribute.

Returns:

The min attribute value as int (None if not set).
get_quantity()[source]

Get the value of the quantity attribute.

Returns:

The quantity attribute value as string (empty string if not set).
get_start()[source]

Get the value of the start attribute.

Returns:

The start attribute value as int (None if not set).
class pyfmi.common.xmlparser.IntegerParameter(element)[source]

Bases: pyfmi.common.xmlparser.Parameter

Class representing an independent integer parameter in a IndependentParameters XML document representation.

get_value()[source]

Get the value of the parameter.

Returns:

The value of the parameter as integer.
set_value(value)[source]

Set the value of the parameter.

Parameters:

value --
    The new value of the parameter.
class pyfmi.common.xmlparser.IntegerType(element)[source]

Class defining data structure based on the XML element IntegerType.

get_max()[source]

Get the value of the max attribute.

Returns:

The max attribute value as int (None if not set).
get_min()[source]

Get the value of the min attribute.

Returns:

The min attribute value as int (None if not set).
get_quantity()[source]

Get the value of the quantity attribute.

Returns:

The quantity attribute value as string (empty string if not set).
class pyfmi.common.xmlparser.Item(element)[source]

Class defining data structure based on the XML element Item.

get_description()[source]

Get the value of the description attribute.

Returns:

The description attribute value as string.
get_name()[source]

Get the value of the name attribute.

Returns:

The name attribute value as string.
class pyfmi.common.xmlparser.MSDerivative(element)[source]

Bases: pyfmi.common.xmlparser.MSVariable

Class describing a derivative variable in the ModelStructure section.

get_input_dependency()[source]

Get the input dependency. The variable depends directly on the states corresponding to the returned list of indices.

Returns:

A list of input indices.
get_state()[source]

Get the name of the state corresponding to the derivative.

Returns:

The name of the state.
get_state_dependency()[source]

Get the state dependency. The variable depends directly on the states corresponding to the returned list of indices.

Returns:

A list of state indices.
class pyfmi.common.xmlparser.MSInput(element)[source]

Bases: pyfmi.common.xmlparser.MSVariable

Class describing an input variable in the ModelStructure section.

class pyfmi.common.xmlparser.MSOutput(element)[source]

Bases: pyfmi.common.xmlparser.MSVariable

Class describing a derivative variable in the ModelStructure section.

get_input_dependency()[source]

Get the input dependency. The variable depends directly on the states corresponding to the returned list of indices.

Returns:

A list of input indices.
get_state_dependency()[source]

Get the state dependency. The variable depends directly on the states corresponding to the returned list of indices.

Returns:

A list of state indices.
class pyfmi.common.xmlparser.MSVariable(element)[source]

Base class describing a variable in the ModelStructure section.

get_name()[source]

Get the name of the variable.

Returns:

The name of the variable.
class pyfmi.common.xmlparser.ModelDescription(filename, schemaname='')[source]
get_aliases_for_variable(variablename, ignore_cache=False)[source]

Get a list of all alias variables belonging to the aliased variable passed as argument to the function along with a list of booleans indicating whether the alias variable should be negated or not.

Parameters:

variable --
    The aliased variable.
    
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A tuple of lists, the first containing the names of the alias 
variables, the second containing booleans for each alias 
variable indicating whether the variable is a negated variable 
or not.

A tuple of empty lists if the variable has no alias variables. 

None if variable cannot be found in model.
get_all_boolean_variables(include_alias=True, ignore_cache=False)[source]

Get all boolean variables in the model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of all ScalarVariables of type Boolean.
get_all_integer_variables(include_alias=True, ignore_cache=False)[source]

Get all integer variables in the model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
    
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of all ScalarVariables of type Integer.
get_all_real_variables(include_alias=True, ignore_cache=False)[source]

Get all real variables in the model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
    
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of all ScalarVariables of type Real.
get_all_string_variables(include_alias=True, ignore_cache=False)[source]

Get all string variables in the model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
    
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of all ScalarVariables of type String.
get_author()[source]

Get model attribute author.

Returns:

The author attribute value as string (empty string if not specified 
in XML).
get_continous_inputs_value_references()[source]

Get the value references of the of continuous inputs.

Returns:

A list of value references.
get_continous_outputs_value_references()[source]

Get the value references of the of continuous outputs.

Returns:

A list of value references.
get_data_type(variablename, ignore_cache=False)[source]

Get data type of variable.

Parameters:

variablename --
    The name of the variable.
    
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

The type of the variable, REAL, INTEGER, BOOLEAN or STRING.

Raises:

XMLException if variable was not found.
get_default_experiment()[source]

Get default experiment data set in model.

Returns:

An object of type DefaultExperiment or None if not set.
get_description()[source]

Get model attribute description.

Returns:

The description attribute value as string (empty string if not 
specified in XML).
get_dx_fixed(include_alias=True, ignore_cache=False)[source]

Get the fixed attributes of the derivatives (variable_category:derivative) in the model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and value of fixed 
attribute respectively.
get_dx_initial_guess(include_alias=True, ignore_cache=False)[source]

Get the initial guess attribute of the derivatives (variable_category:derivative) in the model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and value of initial 
guess attribute respectively.
get_dx_islinear(include_alias=True, ignore_cache=False)[source]

Get value reference and boolean value describing if variable appears linearly in all equations and constraints for all derivatives (variable_category:derivative) in the model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and value of is linear 
element respectively.
get_dx_linear_timed_variables(include_alias=True, ignore_cache=False)[source]

Get value reference and linear timed variables for all derivatives (variable_category:derivative) in the model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples with value reference and list of linear time 
variables respectively.
get_dx_max(include_alias=True, ignore_cache=False)[source]

Get the max attribute of the derivatives (variable_category:derivative) in the model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and value of max 
attribute respectively.
get_dx_min(include_alias=True, ignore_cache=False)[source]

Get the min attribute of the derivatives (variable_category:derivative) in the model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and value of min 
attribute respectively.
get_dx_start(include_alias=True, ignore_cache=False)[source]

Get the start attributes of the derivatives (variable_category:derivative) in the model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and value of start 
attribute respectively.
get_dx_variable_names(include_alias=True, ignore_cache=False)[source]

Get the names of all derivatives.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
    
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and name respectively.
get_fmi_version()[source]

Get model attribute fmi version.

Returns:

The FMI version attribute as string.
get_generation_date_and_time()[source]

Get model attribute date and time.

Returns:

The date and time attribute value as string (empty string if not 
specified in XML).
get_generation_tool()[source]

Get model attribute generation tool.

Returns:

The generation tool attribute value as string (empty string if not 
specified in XML).
get_guid()[source]

Get model attribute GUID.

Returns:

The GUID attribute value as string.
get_model_identifier()[source]

Get model attribute model identifier.

Returns:

The model identifier attribute value as string.
get_model_name()[source]

Get model attribute name.

Returns:

The model name attribute value as string.
get_model_variables()[source]

Get all variables in model.

Returns:

A list of all variables (type: ScalarVariable)
get_number_of_continuous_inputs()[source]

Get the number of continuous inputs.

Returns:

The number of continuous inputs.
get_number_of_continuous_outputs()[source]

Get the number of continuous outputs.

Returns:

The number of continuous outputs.
get_number_of_continuous_states()[source]

Get model attribute number of continuous states.

Returns:

The number of continuous states attribute value as unsigned int.
get_number_of_event_indicators()[source]

Get model attribute number of event indicators.

Returns:

The number of event indicators attribute value as unsigned int.
get_number_of_inputs()[source]

Get the number of inputs.

Returns:

The number of inputs.
get_number_of_outputs()[source]

Get the number of outputs.

Returns:

The number of outputs.
get_opt_finaltime(ignore_cache=False)[source]

Get the optimization interval final time.

Parameters:

ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

The optimization interval final time. None if there is no 
optimization part.
get_opt_finaltime_free(ignore_cache=False)[source]

Get the optimization interval final time free attribute.

Parameters:

ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

The optimization interval final time free attribute. None if there 
is no optimization part.
get_opt_starttime(ignore_cache=False)[source]

Get the optimization interval start time.

Parameters:

ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

The optimization interval start time. None if there is no 
optimization part.
get_opt_starttime_free(ignore_cache=False)[source]

Get the optimization interval start time free attribute.

Parameters:

ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

The optimization interval start time free attribute. None if there 
is no optimization part.
get_opt_timepoints(ignore_cache=False)[source]

Get the optimization time points.

Parameters:

ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

The optimization time points. None if there is no optimization part.
get_optimization()[source]

Get optimization data set in model.

Returns:

An object of type Optimization if model is Optimica, otherwise None.
get_p_opt_initial_guess(include_alias=True, ignore_cache=False)[source]

Get value reference and initial guess attribute for all optimized independent parameters (variability:parameter, free: true).

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and value of initial 
guess attribute respectively.
get_p_opt_islinear(include_alias=True, ignore_cache=False)[source]

Get value reference and boolean value describing if variable appears linearly in all equations and constraints for all optimized independent parameters.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and value of is linear 
element respectively.
get_p_opt_max(include_alias=True, ignore_cache=False)[source]

Get value reference and max attribute for all optimized independent parameters (variability:parameter, free: true).

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and value of max 
attribute respectively.
get_p_opt_min(include_alias=True, ignore_cache=False)[source]

Get value reference and min attribute for all optimized independent parameters (variability:parameter, free: true).

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and value of min 
attribute respectively.
get_p_opt_nominal(include_alias=True, ignore_cache=False)[source]

Get the nominal attributes for all optimized parameters (variability:parameter, free: true).

Parameters:

include_alias --
    If True, also include variables which are alias variables in
    the result. If False, only non-alias variables will be included
    in the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and value of nominal 
attribute respectively.
get_p_opt_start(include_alias=True, ignore_cache=False)[source]

Get the start attributes of the independent paramenters (variability:parameter, free: true) in the model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and value of start 
attribute respectively.
get_p_opt_value_reference(ignore_cache=False)[source]

Get value reference for all optimized independent parameters.

Parameters:

ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of value reference for all optimized independent parameters.
get_p_opt_variable_names(include_alias=True, ignore_cache=False)[source]

Get the names of all optimized independent parameters.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and name respectively.
get_type_definitions()[source]

Get all type definitions set in model.

Returns:

A list of type definitions (type: Type)
get_u_fixed(include_alias=True, ignore_cache=False)[source]

Get the fixed attributes of the inputs (variable_category:algebraic, causality: input) in the model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and value of fixed 
attribute respectively.
get_u_initial_guess(include_alias=True, ignore_cache=False)[source]

Get the initial guess attributes of the inputs (variable_category:algebraic, causality: input) in the model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and value of initial 
guess attribute respectively.
get_u_islinear(include_alias=True, ignore_cache=False)[source]

Get value reference and boolean value describing if variable appears linearly in all equations and constraints for all inputs (variable_category:algebraic, causality: input) in the model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and value of is linear 
element respectively.
get_u_linear_timed_variables(include_alias=True, ignore_cache=False)[source]

Get value reference and linear timed variables for all inputs (variable_category:algebraic, causality: input) in the model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples with value reference and list of linear time 
variables respectively.
get_u_max(include_alias=True, ignore_cache=False)[source]

Get the max attributes of the inputs (variable_category:algebraic, causality: input) in the model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and value of max 
attribute respectively.
get_u_min(include_alias=True, ignore_cache=False)[source]

Get the min attributes of the inputs (variable_category:algebraic, causality: input) in the model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and value of min 
attribute respectively.
get_u_nominal(include_alias=True, ignore_cache=False)[source]

Get the nominal attributes of the inputs (variable_category:algebraic, causality: input) in the model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and value of nominal 
attribute respectively.
get_u_start(include_alias=True, ignore_cache=False)[source]

Get the start attributes of the inputs (variable_category:algebraic, causality: input) in the model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and value of start 
attribute respectively.
get_u_variable_names(include_alias=True, ignore_cache=False)[source]

Get the names of all inputs.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and name respectively.
get_unit_definitions()[source]

Get all unit definitions set in model.

Returns:

A list of unit definitions (type: BaseUnit)
get_value_reference(variablename, ignore_cache=False)[source]

Get the value reference given a variable name.

Parameters:

variablename -- 
    The name of the variable.
    
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

The value reference for the variable passed as argument.

Raises:

XMLEexception if variable was not found.
get_variability(variablename, ignore_cache=False)[source]

Get variability of variable.

Parameters:

variablename --
    The name of the variable.
    
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

The variability of the variable, CONTINUOUS, CONSTANT, PARAMETER or 
DISCRETE

Raises:

XMLException if variable was not found.
get_variable_aliases(ignore_cache=False)[source]

Extract the alias data for each variable in the model.

Parameters:

ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value references and alias data 
respectively.
get_variable_descriptions(include_alias=True, ignore_cache=False)[source]

Extract the descriptions of the variables in a model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
    
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and description 
respectively.
get_variable_fixed_attributes(include_alias=True, ignore_cache=False)[source]

Get the fixed attribute of the variables in the model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
    
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and value of fixed 
attribute respectively.
get_variable_names(include_alias=True, ignore_cache=False)[source]

Extract the names of the variables in a model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
    
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value references and names respectively.
get_variable_naming_convention()[source]

Get model attribute variable naming convention.

Returns:

The variable naming convention attribute value as string.
get_variable_nominal_attributes(include_alias=True, ignore_cache=False)[source]

Get the nominal attribute of the variables in the model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
    
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and value of nominal 
attribute respectively.
get_variable_start_attributes(include_alias=True, ignore_cache=False)[source]

Get the start attributes of the variables in the model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
    
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and value of start 
attribute respectively.
get_variable_variabilities(include_alias=True, ignore_cache=False)[source]

Get the variability of the variables in the model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
    
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and variability 
respectively.
get_vendor_annotations()[source]

Get all vendor annotations set in model.

Returns:

A list of vendor annotations (type: Tool)
get_version()[source]

Get model attribute version (of FMU).

Returns:

The version attribute value as float if set, otherwise None.
get_w_fixed(include_alias=True, ignore_cache=False)[source]

Get the fixed attributes of the algebraic variables (variable_category:algebraic, causality: not input) in the model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and value of fixed 
attribute respectively.
get_w_initial_guess(include_alias=True, ignore_cache=False)[source]

Get the initial guess attributes of the algebraic variables (variable_category:algebraic, causality: not input) in the model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and value of initial 
guess attribute respectively.
get_w_islinear(include_alias=True, ignore_cache=False)[source]

Get value reference and boolean value describing if variable appears linearly in all equations and constraints for all algebraic variables (variable_category:algebraic, causality: not input) in the model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and value of is linear 
element respectively.
get_w_linear_timed_variables(include_alias=True, ignore_cache=False)[source]

Get value reference and linear timed variables for all algebraic variables (variable_category:algebraic, causality: not input) in the model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples with value reference and list of linear time 
variables respectively.
get_w_max(include_alias=True, ignore_cache=False)[source]

Get the max attributes of the algebraic variables (variable_category:algebraic, causality: not input) in the model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and value of max 
attribute respectively.
get_w_min(include_alias=True, ignore_cache=False)[source]

Get the min attributes of the algebraic variables (variable_category:algebraic, causality: not input) in the model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and value of min 
attribute respectively.
get_w_nominal(include_alias=True, ignore_cache=False)[source]

Get the nominal attributes of the algebraic variables (variable_category:algebraic, causality: not input) in the model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and value of nominal 
attribute respectively.
get_w_start(include_alias=True, ignore_cache=False)[source]

Get the start attributes of the algebraic variables (variable_category:algebraic, causality: not input) in the model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and value of start 
attribute respectively.
get_w_variable_names(include_alias=True, ignore_cache=False)[source]

Get the names of all algebraic variables.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and name respectively.
get_x_fixed(include_alias=True, ignore_cache=False)[source]

Get the fixed attributes of the states (variable_category:state) in the model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and value of fixed 
attribute respectively.
get_x_initial_guess(include_alias=True, ignore_cache=False)[source]

Get the initial guess attributes of the states (variable_category:state) in the model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and value of initial 
guess attribute respectively.
get_x_islinear(include_alias=True, ignore_cache=False)[source]

Get value reference and boolean value describing if variable appears linearly in all equations and constraints for all states (variable_category:state) in the model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and value of is linear 
element respectively.
get_x_linear_timed_variables(include_alias=True, ignore_cache=False)[source]

Get value reference and linear timed variables for all states (variable_category:state) in the model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples with value reference and list of linear time 
variables respectively.
get_x_max(include_alias=True, ignore_cache=False)[source]

Get the max attributes of the states (variable_category:state) in the model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and value of max 
attribute respectively.
get_x_min(include_alias=True, ignore_cache=False)[source]

Get the min attributes of the states (variable_category:state) in the model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and value of min 
attribute respectively.
get_x_nominal(include_alias=True, ignore_cache=False)[source]

Get the nominal attributes of the states (variable_category:state) in the model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and value of nominal 
attribute respectively.
get_x_start(include_alias=True, ignore_cache=False)[source]

Get the start attributes of the states (variable_category:state) in the model.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and value of start 
attribute respectively.
get_x_variable_names(include_alias=True, ignore_cache=False)[source]

Get the names of all states.

Parameters:

include_alias --
    If True, also include variables which are alias variables in the 
    result. If False, only non-alias variables will be included in 
    the result.
    Default: True
    
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

A list of tuples containing value reference and name respectively.
is_alias(variablename, ignore_cache=False)[source]

Find out if variable is an alias or negated alias.

Parameters:

variablename --
    The name of the variable.
    
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

True if variable is alias or negated alias, False otherwise.

Raises:

XMLException if variable was not found.
is_constant(variablename, ignore_cache=False)[source]

Find out if variable is a constant or not.

Parameters:

variablename --
    The name of the variable.
    
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

True if variable is a constant, False otherwise.

Raises:

XMLException if variable was not found.
is_negated_alias(variablename, ignore_cache=False)[source]

Find out if variable is a negated alias or not.

Parameters:

variablename --
    The name of the variable.
    
ignore_cache -- 
    If False look for the value in the cache first, if True skip 
    cache and derive value from data structure.
    Default: False

Returns:

True if variable is a negated alias, False otherwise.

Raises:

XMLException if variable was not found.
class pyfmi.common.xmlparser.ModelDescription2(filename, schemaname='')[source]

Bases: pyfmi.common.xmlparser.ModelDescription

A class for storing the ModelDescription information in FMI 2.0.

get_continous_inputs_value_references()[source]

Get the value references of the of continuous inputs.

Returns:

A list of value references.
get_continous_outputs_value_references()[source]

Get the value references of the of continuous outputs.

Returns:

A list of value references.
get_input_dependency(variable)[source]

Get the input dependencies of a particular derivative or output variable.

Returns:

A list of input indices (0-indexing).
get_number_of_continuous_inputs()[source]

Get the number of continuous inputs.

Returns:

The number of continuous inputs.
get_number_of_continuous_outputs()[source]

Get the number of continuous outputs.

Returns:

The number of continuous outputs.
get_number_of_inputs()[source]

Get the number of inputs.

Returns:

The number of inputs.
get_number_of_outputs()[source]

Get the number of outputs.

Returns:

The number of outputs.
get_state_dependency(variable)[source]

Get the state dependencies of a particular derivative or output variable.

Returns:

A list of state indices (0-indexing).
class pyfmi.common.xmlparser.Opt_IntervalTime(element)[source]

Class defining data structure based on the XML element OptIntervalFinalTime and OptIntervalStartTime.

get_free()[source]

Get the free of the value element.

Returns:

The free attribute value as bool (None if not set).
get_initial_guess()[source]

Get the value of the initial guess element.

Returns:

The initial guess attribute value as float (None if not set).
get_value()[source]

Get the value of the value element.

Returns:

The value attribute value as float (None if not set).
class pyfmi.common.xmlparser.Opt_TimePoint(e_index, e_value)[source]

Class defining data structure based on the XML element TimePoint.

get_index()[source]

Get the value of the index element.

Returns:

The index attribute value as int.
get_value()[source]

Get the value of the value element.

Returns:

The value attribute value as float.
class pyfmi.common.xmlparser.Optimization(element)[source]

Class defining data structure based on the XML element Optimization.

get_interval_final_time()[source]

Get the interval final time set for this model.

Returns:

An object of type Opt_IntervalTime containing final time data (None 
if not set).
get_interval_start_time()[source]

Get the interval start time set for this model.

Returns:

An object of type Opt_IntervalTime containing start time data (None 
if not set).
get_static()[source]

Get the value of the static attribute.

Returns:

The static attribute value as bool (None if not set).
get_time_points()[source]

Get the optimization time points set for this model.

Returns:

A list of all time points (type: Opt_TimePoint).
class pyfmi.common.xmlparser.Parameter(element)[source]

Class representing an independent parameter in a IndependentParameters XML document representation.

get_name()[source]

Get the name of the parameter.

Returns:

The name of the parameter.
get_value()[source]

Get the value of the parameter.

Abstract method - must be implemented by extending classes.

set_value(value)[source]

Set the value of the parameter.

Abstract method - must be implemented by extending classes.

class pyfmi.common.xmlparser.Real(element)[source]

Class defining data structure based on the XML element Real.

get_declared_type()[source]

Get the value of the declared type attribute.

Returns:

The declared type attribute value as string (empty string if not 
set).
get_display_unit()[source]

Get the value of the display unit attribute.

Returns:

The display unit attribute value as string (empty string if not 
set).
get_fixed()[source]

Get the value of the fixed attribute.

Returns:

The fixed attribute value as bool (None if not set).
get_free()[source]

Get the value of the free attribute.

Returns:

The free attribute value as bool (None if not set).
get_initial_guess()[source]

Get the value of the attribute.

Returns:

The initial guess attribute value as float (None if not set).
get_max()[source]

Get the value of the max attribute.

Returns:

The max attribute value as float (None if not set).
get_min()[source]

Get the value of the min attribute.

Returns:

The min attribute value as float (None if not set).
get_nominal()[source]

Get the value of the nominal attribute.

Returns:

The nominal attribute value as float (None if not set).
get_quantity()[source]

Get the value of the quantity attribute.

Returns:

The quantity attribute value as string (empty string if not set).
get_relative_quantity()[source]

Get the value of the relative quantity attribute.

Returns:

The relative quantity attribute value as bool (default: false).
get_start()[source]

Get the value of the start attribute.

Returns:

The start attribute value as float (None if not set).
get_unit()[source]

Get the value of the unit attribute.

Returns:

The unit attribute value as string (empty string if not set).
class pyfmi.common.xmlparser.RealParameter(element)[source]

Bases: pyfmi.common.xmlparser.Parameter

Class representing an independent real parameter in a IndependentParameters XML document representation.

get_value()[source]

Get the value of the parameter.

Returns:

The value of the parameter as real.
set_value(value)[source]

Set the value of the parameter.

Parameters:

value --
    The new value of the parameter.
class pyfmi.common.xmlparser.RealType(element)[source]

Class defining data structure based on the XML element RealType.

get_display_unit()[source]

Get the value of the display unit attribute.

Returns:

The display unit attribute value as string (empty string if not 
set).
get_max()[source]

Get the value of the max attribute.

Returns:

The max attribute value as float (None if not set).
get_min()[source]

Get the value of the min attribute.

Returns:

The min attribute value as float (None if not set).
get_nominal()[source]

Get the value of the nominal attribute.

Returns:

The nominal attribute value as float (None if not set).
get_quantity()[source]

Get the value of the quantity attribute.

Returns:

The quantity attribute value as string (empty string if not set).
get_relative_quantity()[source]

Get the value of the relative quantity attribute.

Returns:

The relative quantity attribute value as bool (default: false).
get_unit()[source]

Get the value of the unit attribute.

Returns:

The unit attribute value as string (empty string if not set).
class pyfmi.common.xmlparser.ScalarVariable(element)[source]

Class defining data structure based on the XML element ScalarVariable.

get_alias()[source]

Get the value of the alias attribute.

Returns:

The alias attribute value as enumeration: NO_ALIAS, ALIAS or 
NEGATED_ALIAS. (default: NO_ALIAS).
get_causality()[source]

Get the value of the causality attribute.

Returns:

The causality attribute value as enumeration: INTERNAL, INPUT, 
OUTPUT or NONE. (default: INTERNAL).
get_description()[source]

Get the value of the description attribute.

Returns:

The description attribute value as string (empty string if not set).
get_direct_dependency()[source]

Get the direct dependencies set for the variable.

Returns:

An object of type DirectDependency (None if not set).
get_fundamental_type()[source]

Get the type of the type defined. (Real, Integer, Boolean, String or Enumeration Type)

Returns:

An object of type Real, Integer, Boolean, String or Enumeration.
get_is_linear()[source]

Get the value of the is linear element.

Returns:

The is linear attribute value as bool (None if not set).
get_is_linear_timed_variables()[source]

Get all is linear timed variables set for the variable.

Returns:

A list of all linear timed variables (type: TimePoint)
get_name()[source]

Get the value of the name attribute.

Returns:

The name attribute value as string.
get_value_reference()[source]

Get the value of the value reference attribute.

Returns:

The value reference as unsigned int.
get_variability()[source]

Get the value of the variability attribute.

Returns:

The variability attribute value as enumeration: CONTINUOUS, 
CONSTANT, PARAMETER or DISCRETE (default: CONTINUOUS).
get_variable_category()[source]

Get the value of the variable category element.

Returns:

The variable category attribute value as enumeration: 
ALGEBRAIC, STATE, DEPENDENT_CONSTANT, INDEPENDENT_CONSTANT, 
DEPENDENT_PARAMETER, INDEPENDENT_PARAMETER or DERIVATIVE  
(default: ALGEBRAIC).
class pyfmi.common.xmlparser.String(element)[source]

Class defining data structure based on the XML element String.

get_declared_type()[source]

Get the value of the declared type attribute.

Returns:

The declared type attribute value as string (empty string if not 
set).
get_fixed()[source]

Get the value of the fixed attribute.

Returns:

The fixed attribute value as bool (None if not set).
get_start()[source]

Get the value of the start attribute.

Returns:

The start attribute value as string (None if not set).
class pyfmi.common.xmlparser.StringParameter(element)[source]

Bases: pyfmi.common.xmlparser.Parameter

Class representing an independent string parameter in a IndependentParameters XML document representation.

get_value()[source]

Get the value of the parameter.

Returns:

The value of the parameter as string.
set_value(value)[source]

Set the value of the parameter.

Parameters:

value --
    The new value of the parameter.
class pyfmi.common.xmlparser.StringType(element)[source]

Class defining data structure based on the XML element StringType. Is empty since XML element contains no attributes or other elements.

class pyfmi.common.xmlparser.TimePoint(element)[source]

Class defining data structure based on the XML element TimePoint.

get_index()[source]

Get the value of the index attribute.

Returns:

The index attribute value as int.
get_is_linear()[source]

Get the value of the is linear attribute.

Returns:

The is linear attribute value as bool.
class pyfmi.common.xmlparser.Tool(element)[source]

Class defining data structure based on the XML element Tool.

get_annotations()[source]

Get all annotations set for the tool.

Returns:

A list of all annotations (type: Annotation)
get_name()[source]

Get the value of the name attribute.

Returns:

The name attribute value as string.
class pyfmi.common.xmlparser.Type(element)[source]

Class defining data structure based on the XML element Type.

get_description()[source]

Get the value of the description attribute.

Returns:

The description attribute value as string (empty string if not set).
get_fundamental_type()[source]

Get the type of the type defined. (Real, Integer, Boolean, String or Enumeration Type)

Returns:

An object of type RealType, IntegerType, BooleanType, StringType or 
EnumerationType.
get_name()[source]

Get the value of the name attribute.

Returns:

The name attribute value as string.
exception pyfmi.common.xmlparser.XMLException[source]

Bases: exceptions.Exception

Class for all XML related errors that can occur in this module.

class pyfmi.common.xmlparser.XMLFunctionCache[source]

Class representing cache for loaded XML doc.

Function return values from function calls in XMLDoc are saved in a dict structure. The first time a function call is made for a particular instance of XMLDoc will result in a new entry in the internal cache (dict). If the function has an argument, the function entry will get the value equal to a new dict with return values dependent on function argument.

Note: The current version only supports functions with no or one argument.

add(obj, function, key=None)[source]

Add a function call to cache and save result dependent on the argument key. If key is None, the function has no arguments and the dict entry will simply contain one value which is the return value for the specific function. If key is not none, the value of the dict entry will contain yet another dict with an entry for each argument to the function.

Parameters:

obj --
    The object instance on which the function call is made.
function --
    The function call for which the result should be saved.
key --
    Function argument. If None then the function has no arguments.
    Default: None
get(obj, function, key=None)[source]

Get the function return value (cached value) for the specific function and key.

Parameters:

obj --
    The object instance on which the function call is made.
function --
    The function call for which the result is saved.
key --
    Function argument. If None then the function has no arguments.
    Default: None

Returns:

The return value of the function for the specific key (if any) as 
saved in the cache.