org.ptolemy.fmi.driver
Class FMUDriver

java.lang.Object
  extended by org.ptolemy.fmi.driver.FMUDriver
Direct Known Subclasses:
FMUCoSimulation, FMUModelExchange

public abstract class FMUDriver
extends java.lang.Object

Base class to invoke a Functional Mock-up Unit (.fmu) file as either co-simulation or model exchange.

Derived classes should implement the simulate(...) method and create a static main(String args) method that invokes _processArgs(args) and them simulate(...).

Version:
$Id: FMUDriver.java 66133 2013-04-25 21:59:22Z cxh $
Author:
Christopher Brooks
Accepted Rating:
Red (cxh)
Proposed Rating:
Red (cxh)

Field Summary
(package private) static char _csvSeparator
          The comma separated value separator.
(package private) static boolean _enableLogging
          True if logging is enabled.
(package private) static double _endTime
          The end time, in seconds.
(package private)  FMULibrary.FMUAllocateMemory _fmuAllocateMemory
          Memory allocator callback.
(package private) static java.lang.String _fmuFileName
          The name of the .fmu file.
(package private)  java.lang.String _modelIdentifier
          The modelIdentifier from modelDescription.xml.
(package private)  com.sun.jna.NativeLibrary _nativeLibrary
          The NativeLibrary that contains the functions.
(package private) static java.lang.String _outputFileName
          The output file name.
(package private) static double _stepSize
          The step size, in seconds.
 
Constructor Summary
FMUDriver()
           
 
Method Summary
protected static void _processArgs(java.lang.String[] args)
          Process command line arguments for co-simulation or model exchange of Functional Mock-up Unit (.fmu) files.
protected static void _setEnableLogging(boolean enableLogging)
          Set the _enableLogging field.
 com.sun.jna.Function getFunction(java.lang.String name)
          Return a function by name.
 void invoke(com.sun.jna.Function function, java.lang.Object[] arguments, java.lang.String message)
          Invoke a function that returns an integer representing the FMIStatus return value.
 void invoke(java.lang.String name, java.lang.Object[] arguments, java.lang.String message)
          Invoke a function that returns an integer representing the FMIStatus return value.
abstract  void simulate(java.lang.String fmuFileName, double endTime, double stepSize, boolean enableLogging, char csvSeparator, java.lang.String outputFileName)
          Perform co-simulation or model exchange using the named Functional Mock-up Unit (FMU) file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_csvSeparator

static char _csvSeparator
The comma separated value separator. The initial value is ','. If the separator is ',', columns are separated by ',' and '.' is used for floating-point numbers. Otherwise, the given separator (e.g. ';' or '\t') is to separate columns, and ',' is used as decimal dot in floating-point numbers.


_enableLogging

static boolean _enableLogging
True if logging is enabled. The initial value is false.


_endTime

static double _endTime
The end time, in seconds. The initial default is 1.0.


_fmuAllocateMemory

FMULibrary.FMUAllocateMemory _fmuAllocateMemory
Memory allocator callback. At the end, call dispose() to free memory.


_fmuFileName

static java.lang.String _fmuFileName
The name of the .fmu file. The initial default is the empty string.


_modelIdentifier

java.lang.String _modelIdentifier
The modelIdentifier from modelDescription.xml.


_nativeLibrary

com.sun.jna.NativeLibrary _nativeLibrary
The NativeLibrary that contains the functions.


_outputFileName

static java.lang.String _outputFileName
The output file name. The initial value is "results.csv".


_stepSize

static double _stepSize
The step size, in seconds. The initial default is 0.1 seconds.

Constructor Detail

FMUDriver

public FMUDriver()
Method Detail

getFunction

public com.sun.jna.Function getFunction(java.lang.String name)
Return a function by name.

Parameters:
name - The name of the function. The value of the modelIdentifier is prepended to the value of this parameter to yield the function name.
Returns:
the function.

invoke

public void invoke(java.lang.String name,
                   java.lang.Object[] arguments,
                   java.lang.String message)
Invoke a function that returns an integer representing the FMIStatus return value.

Parameters:
name - The name of the function.
arguments - The arguments to be passed to the function.
message - The error message to be used if there is a problem. The message should end with ": " because the return value of the function will be printed after the error message.

invoke

public void invoke(com.sun.jna.Function function,
                   java.lang.Object[] arguments,
                   java.lang.String message)
Invoke a function that returns an integer representing the FMIStatus return value.

Parameters:
function - The function to be invoked.
arguments - The arguments to be passed to the function.
message - The error message to be used if there is a problem. The message should end with ": " because the return value of the function will be printed after the error message.

simulate

public abstract void simulate(java.lang.String fmuFileName,
                              double endTime,
                              double stepSize,
                              boolean enableLogging,
                              char csvSeparator,
                              java.lang.String outputFileName)
                       throws java.lang.Exception
Perform co-simulation or model exchange using the named Functional Mock-up Unit (FMU) file.

Derived classes should implement this method.

Parameters:
fmuFileName - The pathname of the co-simulation .fmu file
endTime - The ending time in seconds.
stepSize - The step size in seconds.
enableLogging - True if logging is enabled.
csvSeparator - The character used for separating fields. Note that sometimes the decimal point in floats is converted to ','.
outputFileName - The output file.
Throws:
java.lang.Exception - If there is a problem parsing the .fmu file or invoking the methods in the shared library.

_processArgs

protected static void _processArgs(java.lang.String[] args)
                            throws java.lang.Exception
Process command line arguments for co-simulation or model exchange of Functional Mock-up Unit (.fmu) files.

The command line arguments have the following meaning:

file.fmu
The co-simulation or model exchange Functional Mock-up Unit (FMU) file. In FMI-1.0, co-simulation fmu files contain a modelDescription.xml file that has an <Implementation> element. Model exchange fmu files do not have this element.
endTime
The endTime in seconds, defaults to 1.0.
stepTime
The time between steps in seconds, defaults to 0.1.
enableLogging
If "true", then enable logging. The default is false.
outputFile
The name of the output file. The default is results.csv

The format of the arguments is based on the fmusim command from the fmusdk by QTronic Gmbh.

Parameters:
args - The arguments: file.fmu [endTime] [stepTime] [loggingOn] [csvSeparator] [outputFile]
Throws:
java.lang.Exception - If there is a problem parsing the .fmu file or invoking the methods in the shared library.

_setEnableLogging

protected static void _setEnableLogging(boolean enableLogging)
Set the _enableLogging field.

Parameters:
enableLogging - the value of the enable logging field.