Class FMUImportHybrid

    • Method Detail

      • fire

        public void fire()
                  throws IllegalActionException
        Invoke set() and get() on the FMU for the currently known inputs. The inputs of this actor are by default unknown. Every time we fire() this actor, we supply new known inputs that can be set on the FMU. This allows to compute new outputs on the FMU that are captured and sent to the output port of this actor. When all the inputs are known, the FMU compute the default step size by invoking fireAt().
        Specified by:
        fire in interface Executable
        Overrides:
        fire in class FMUImport
        Throws:
        IllegalActionException - If the FMU indicates a failure.
      • importFMU

        public static void importFMU​(java.lang.Object originator,
                                     FileParameter fmuFileParameter,
                                     NamedObj context,
                                     double x,
                                     double y,
                                     boolean modelExchange)
                              throws IllegalActionException,
                                     java.io.IOException
        Import a FMUFile.
        Parameters:
        originator - The originator of the change request.
        fmuFileParameter - The .fmuFile
        context - The context in which the FMU actor is created.
        x - The x-axis value of the actor to be created.
        y - The y-axis value of the actor to be created.
        modelExchange - True if the FMU should be imported as a model exchange FMU.
        Throws:
        IllegalActionException - If there is a problem instantiating the actor.
        java.io.IOException - If there is a problem parsing the fmu file.
      • initialize

        public void initialize()
                        throws IllegalActionException
        Initialize this FMU wrapper. For co-simulation, this initializes the FMU. For model exchange, it does not, because for model exchange, the inputs at the start time need to be provided prior to initialization. Initialization will therefore occur in the first invocation of fire().
        Specified by:
        initialize in interface Initializable
        Overrides:
        initialize in class FMUImport
        Throws:
        IllegalActionException - If the slave FMU cannot be initialized.
      • postfire

        public boolean postfire()
                         throws IllegalActionException
        Override the base class to record the current time as the last commit time.
        Specified by:
        postfire in interface Executable
        Overrides:
        postfire in class FMUImport
        Returns:
        True if execution can continue into the next iteration.
        Throws:
        IllegalActionException - If the step size was rejected, if thrown while requesting refiring if necessary, if thrown while the FMU state is being recorded or if thrown by the superclass.
      • getNextStepSize

        public Time getNextStepSize​(Time proposedTime)
                             throws IllegalActionException
        Compute the step size for the FMU. This can happen in two ways. If the FMU implements getMaxStepSize(), we simply use it. Otherwise, we propose a default step size to the FMU. The FMU in this case can partially accept the step size. We can check this looking at the internal state of the FMU. _fmiDoStepHybrid() returns the step size actually accepted from the FMU.
        Parameters:
        proposedTime - The proposed time
        Returns:
        the new time
        Throws:
        IllegalActionException - If thrown by while doing the step.
      • _allInputsAreKnown

        protected boolean _allInputsAreKnown()
                                      throws IllegalActionException
        Returns true if all inputs are known. Return false if at least one of the inputs is unknown. If an FMU has no inputs it also returns true.
        Returns:
        true if all the inputs are known.
        Throws:
        IllegalActionException - If throw while getting the width of an input port or checking if an input port is known.
      • _fmiDoStepHybrid

        protected Time _fmiDoStepHybrid​(Time newTime,
                                        int newMicrostep)
                                 throws IllegalActionException
        Advance from the last firing time or last commit time to the specified time and microstep by calling fmiDoStep(), if necessary. This method is for co-simulation only. Such an advance is necessary if the newTime is not equal to the last firing time, or if it is equal and the newMicrostep is greater than the last firing microstep. If the step size is rejected, then return a new suggested step size.
        Parameters:
        newTime - The time to advance to.
        newMicrostep - The microstep to advance to.
        Returns:
        A revised suggested step size, or -1.0 if the step size was accepted by the FMU.
        Throws:
        IllegalActionException - If fmiDoStep() returns anything other than fmiDiscard or fmiOK.
      • _setFMUScalarVariable

        protected void _setFMUScalarVariable​(FMIScalarVariable scalar,
                                             Token token)
                                      throws IllegalActionException
        Set a scalar variable of the FMU to the value of a Ptolemy token. This method works with the new proposal of FMI for Hybrid Co-Simulation. We suppose FMUs able to handle an explicit notion of "absent" signal.
        Overrides:
        _setFMUScalarVariable in class FMUImport
        Parameters:
        scalar - the FMI scalar to be set.
        token - the Ptolemy token that contains the value to be set.
        Throws:
        IllegalActionException - If the scalar is of a type that is not handled or if the type of the token does not match the type of the scalar.
      • _getFmuOutputs

        protected void _getFmuOutputs()
                               throws IllegalActionException
        Retrieve the outputs from the FMU. Only outputs with known inputs are retrieved. In an output cannot be retrieved, an AbsentToken is sent on the correspondent actor port. In case the output can be retrieved (all the dependent inputs are known) than we get this value, we create a Token and we send the token on the correspondent output port.
        Throws:
        IllegalActionException - If thrown while getting the inputs, determining if the inputs are known or have a token
      • _setFmuInputs

        protected void _setFmuInputs()
                              throws IllegalActionException
        Iterate through the scalarVariables and set all the inputs that are known.
        Throws:
        IllegalActionException - If thrown while getting the inputs, determining if the inputs are known or have a token