Package ptolemy.actor.lib.fmi
Class FMUImportHybrid
- java.lang.Object
-
- All Implemented Interfaces:
java.lang.Cloneable
,Actor
,Advanceable
,ContinuousStatefulComponent
,ContinuousStepSizeController
,Executable
,FiringsRecordable
,Initializable
,TypedActor
,Changeable
,Debuggable
,DebugListener
,Derivable
,Instantiable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
public class FMUImportHybrid extends FMUImport
Import a Hybrid Co-Simulation FMU. This actor is strongly based on FMUImport.java developed by Christopher Brooks, Michael Wetter, Edward A. Lee.- Since:
- Ptolemy II 11.0
- Version:
- $Id: FMUImportHybrid.java$
- Author:
- Fabio Cremona
- Pt.AcceptedRating:
- Red (cxh)
- Pt.ProposedRating:
- Red (cxh)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.actor.lib.fmi.FMUImport
FMUImport.Input, FMUImport.Output
-
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
-
-
Field Summary
-
Fields inherited from class ptolemy.actor.lib.fmi.FMUImport
_callbacks, _callbacks20, _eventInfoJNI, _firstFire, _firstFireInIteration, _fmiCompletedIntegratorStepFunction, _fmiComponent, _fmiDoStepFunction, _fmiEnterContinuousTimeModeFunction, _fmiEnterInitializationModeFunction, _fmiExitInitializationModeFunction, _fmiGetContinuousStatesFunction, _fmiGetDerivativesFunction, _fmiGetDirectionalDerivativeFunction, _fmiGetEventIndicatorsFunction, _fmiGetIntegerStatusFunction, _fmiGetRealStatusFunction, _fmiJNIComponent, _fmiModelDescription, _fmiNewDiscreteStatesFunction, _fmiSetTimeFunction, _fmiSetupExperimentFunction, _fmiVersion, _isStrict, _lastCommitTime, _lastFireMicrostep, _lastFireTime, _modelInitialized, _newStates, _refinedStepSize, _relativeTolerance, _states, _stepSizeRejected, _suggestZeroStepSize, _threshold, _toleranceControlled, fmiVersion, fmuFile, modelExchange, persistentInputs, removeDirectDependency, stateVariablesAsInputPorts, suppressWarnings, useRawJNI, visible
-
Fields inherited from class ptolemy.actor.TypedAtomicActor
_typesValid
-
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
-
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
-
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
-
-
Constructor Summary
Constructors Constructor Description FMUImportHybrid(CompositeEntity container, java.lang.String name)
Construct an actor with the given container and name.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
_allInputsAreKnown()
Returns true if all inputs are known.protected Time
_fmiDoStepHybrid(Time newTime, int newMicrostep)
Advance from the last firing time or last commit time to the specified time and microstep by calling fmiDoStep(), if necessary.protected void
_fmiInitialize()
Initialize the FMU.protected void
_getFmuOutputs()
Retrieve the outputs from the FMU.protected void
_setFmuInputs()
Iterate through the scalarVariables and set all the inputs that are known.protected void
_setFMUScalarVariable(FMIScalarVariable scalar, Token token)
Set a scalar variable of the FMU to the value of a Ptolemy token.void
fire()
Invoke set() and get() on the FMU for the currently known inputs.Time
getNextStepSize(Time proposedTime)
Compute the step size for the FMU.static void
importFMU(java.lang.Object originator, FileParameter fmuFileParameter, NamedObj context, double x, double y, boolean modelExchange)
Import a FMUFile.void
initialize()
Initialize this FMU wrapper.boolean
postfire()
Override the base class to record the current time as the last commit time.void
preinitialize()
Instantiate the slave FMU component.-
Methods inherited from class ptolemy.actor.lib.fmi.FMUImport
_acceptFMU, _checkEventIndicators, _checkFmiCommon, _completedIntegratorStepNotNeeded, _debugToStdOut, _enterContinuousTimeMode, _enterEventMode, _fmiCompletedIntegratorStep, _fmiCompletedIntegratorStepJNI, _fmiDoStep, _fmiEnterContinuousTimeModeJNI, _fmiEnterEventModeJNI, _fmiFreeInstance, _fmiGetContinuousStates, _fmiGetContinuousStatesJNI, _fmiGetDerivatives, _fmiGetDerivativesJNI, _fmiGetEventIndicatorsJNI, _fmiGetRealJNI, _fmiInitializeJNI, _fmiInstantiateJNI, _fmiNewDiscreteStatesJNI, _fmiSetContinuousStates, _fmiSetContinuousStatesJNI, _fmiSetRealJNI, _fmiSetTime, _fmiSetTimeJNI, _fmiStatusDescription, _fmiTerminate, _fmiType2PtolemyType, _freeFMUState, _getInputs, _getOutputs, _getPortByNameOrDisplayName, _getStepSize, _hasQSSDirector, _importFMU, _isScalarAPtolemyInput, _newDiscreteStatesNeeded, _recordFMUState, _requestRefiringIfNecessary, _restoreFMUState, _setParameter, _skipIfKnown, _updateParameters, _useRawJNI, advance, attributeChanged, declareDelayDependency, getInputDependencyList, getScalarVariables, isStepSizeAccurate, isStrict, refinedStepSize, rollBackToCommittedState, runNativeFMU, suggestedStepSize, wrapup
-
Methods inherited from class ptolemy.actor.TypedAtomicActor
_containedTypeConstraints, _customTypeConstraints, _defaultTypeConstraints, _fireAt, _fireAt, attributeTypeChanged, clone, clone, isBackwardTypeInferenceEnabled, newPort, typeConstraintList, typeConstraints
-
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, _declareDelayDependency, addActorFiringListener, addInitializable, connectionsChanged, createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, iterate, newReceiver, outputPortList, prefire, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate
-
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
-
Methods inherited from class ptolemy.kernel.Entity
_addPort, _description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
-
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
-
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, notifyOfNameChange, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
-
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
-
Methods inherited from interface ptolemy.actor.Executable
isFireFunctional, iterate, prefire, stop, stopFire, terminate
-
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, removeInitializable
-
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
-
-
-
-
Constructor Detail
-
FMUImportHybrid
public FMUImportHybrid(CompositeEntity container, java.lang.String name) throws NameDuplicationException, IllegalActionException
Construct an actor with the given container and name.- Parameters:
container
- The container.name
- The name of this actor.- Throws:
IllegalActionException
- If the actor cannot be contained by the proposed container.NameDuplicationException
- If the container already has an actor with this name.
-
-
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 interfaceExecutable
- Overrides:
fire
in classFMUImport
- 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 .fmuFilecontext
- 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 interfaceInitializable
- Overrides:
initialize
in classFMUImport
- 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 interfaceExecutable
- Overrides:
postfire
in classFMUImport
- 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.
-
preinitialize
public void preinitialize() throws IllegalActionException
Instantiate the slave FMU component.- Specified by:
preinitialize
in interfaceInitializable
- Overrides:
preinitialize
in classFMUImport
- Throws:
IllegalActionException
- If it cannot be instantiated.
-
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.
-
_fmiInitialize
protected void _fmiInitialize() throws IllegalActionException
Initialize the FMU. This _fmiInitialize() is specific for FMI 2.1 Hybrid Co-Simulation- Overrides:
_fmiInitialize
in classFMUImport
- Throws:
IllegalActionException
- If the FMU does not return fmiOK.
-
_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 classFMUImport
- 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
-
-