Class 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(...).

    Since:
    Ptolemy II 10.0
    Version:
    $Id$
    Author:
    Christopher Brooks
    Pt.AcceptedRating:
    Red (cxh)
    Pt.ProposedRating:
    Red (cxh)
    • Constructor Summary

      Constructors 
      Constructor Description
      FMUDriver()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      protected void _processArgs​(java.lang.String[] args)
      Process command line arguments for co-simulation or model exchange of Functional Mock-up Unit (.fmu) files.
      protected void _setEnableLogging​(boolean enableLogging)
      Set the _enableLogging field.
      com.sun.jna.Function getFunction​(java.lang.String name)
      Deprecated.
      Call FMIModelDescription.getFmiFunction() instead.
      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.
      void invoke​(FMIModelDescription fmiModelDescription, 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
    • Constructor Detail

      • FMUDriver

        public FMUDriver()
    • Method Detail

      • getFunction

        @Deprecated
        public com.sun.jna.Function getFunction​(java.lang.String name)
        Deprecated.
        Call FMIModelDescription.getFmiFunction() instead.
        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​(FMIModelDescription fmiModelDescription,
                           java.lang.String name,
                           java.lang.Object[] arguments,
                           java.lang.String message)
                    throws java.lang.UnsatisfiedLinkError,
                           java.io.IOException
        Invoke a function that returns an integer representing the FMIStatus return value.
        Parameters:
        fmiModelDescription - The FMIModelDescription used to look up the function by name.
        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.
        Throws:
        java.lang.UnsatisfiedLinkError - If the function is not found using either format.
        java.io.IOException - If the native library cannot be found.
      • 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 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 void _setEnableLogging​(boolean enableLogging)
        Set the _enableLogging field.
        Parameters:
        enableLogging - the value of the enable logging field.