public class FMUImport extends TypedAtomicActor implements Advanceable, ContinuousStepSizeController, ContinuousStatefulComponent
Read in a .fmu
file named by the fmuFile parameter. The
.fmu
file is a zipped file that contains a file named
modelDescription.xml
that describes the ports and parameters
that are created. At run time, method calls are made to C functions that are
included in shared libraries included in the .fmu
file.
To use this actor from within Vergil, use File -> Import -> Import FMU, which will prompt for a .fmu file. This actor is not available from the actor pane via drag and drop. The problem is that dragging and dropping this actor ends up trying to read fmuImport.fmu, which does not exist. If we added such a file, then dragging and dropping the actor would create an arbitrary actor with arbitrary ports.
FMI documentation may be found at http://www.modelisar.com/fmi.html.
Under the Continuous director, this actor invokes fmiDoStep() at the
beginning of the fire() method whenever time has advanced since the last
invocation of the fire() method. If at this point the FMU discards the step,
then the fire method will nonetheless produce outputs, but they may not be
valid for the current time. This should not matter because the Continuous
director will call isStepSizeAccurate()
, which will return false,
and it will revert to the last committed and proceed with a smaller step
size. Under the Continuous director, when time is advanced, this actor will
be fired several times. The first firing will be at the beginning of the time
interval, which matches the last commit time of the last postfire()
invocation. The remaining firings will be at times greater than the last
commit time. These firings are all speculative, in that any actor may reject
the step size when they occur. In the event that a step is rejected, the
Continuous director will call rollBackToCommittedState()
. If the FMU
supports it, then this method will use fmiSetFMUstate() to restore the state
to the state of the FMU at the time of the last postfire() (or initialize(),
if postfire() has not yet been invoked).
If the FMU does not support rolling back (indicated by the canGetAndSetFMUstate element in the XML file), then this actor assumes that the FMU is stateless and hence can be rolled back without any particular action. This may not be a good assumption, so it issues a warning.
Many tools that export FMUs fail to correctly declare when outputs do not depend on inputs. For this reason, this actor provides each output port with a "dependencies" parameter. If this parameter is left blank, then the dependencies are determined by the FMU's modelDescription.xml file. Otherwise, if this parameter contains a space-separated list of names of input ports, then the output port depends directly on those named input ports. If this parameter contains the string "none", then the output port depends directly on none of the input ports. If contains the string "all", then this output port depends on all input ports. Although the FMI standard is ambiguous, we infer dependency to mean that the value of an output at time t depends on the input at time t. It is irrelevant whether it depends on the input at earlier times.
Note that if the display name of a port is set, display name is used in as the name of the FMU scalar variable instead of the port name. This is useful in case FMU scalar variable names contain a period, because periods are not allowed in port names.
Note that if you use an instance of this class with the ContinuousDirector, you should in general use model exchange, not cosimulation. This is because the ContinuousDirector may advance time by calling fmiDoStep, and then later reject a step size. The only exception is that if the FMU implements rollback (via fmiGetFMUState and fmiSetFMUState), then it can be used with the ContinuousDirector.
Modifier and Type | Class and Description |
---|---|
protected static class |
FMUImport.Input
A data structure representing an input to the FMU.
|
protected static class |
FMUImport.Output
A data structure representing an output from the FMU.
|
Entity.ContainedObjectsIterator
Modifier and Type | Field and Description |
---|---|
protected FMICallbackFunctions |
_callbacks
FMI-1.0 callback functions provided to the C code as a
struct.
|
protected FMI20CallbackFunctions |
_callbacks20
FMI-2.0 callback functions provided to the C code as a
struct.
|
protected FMI20EventInfo |
_eventInfoJNI
The eventInfo.
|
protected boolean |
_firstFire
Flag identifying the first invocation of fire() after initialize.
|
protected boolean |
_firstFireInIteration
Flag identifying the first invocation of fire() after each invocation of
initialize() or postfire().
|
protected com.sun.jna.Function |
_fmiCompletedIntegratorStepFunction
The fmiCompletedIntegratorStep() function.
|
protected com.sun.jna.Pointer |
_fmiComponent
The FMI component created by the modelIdentifier_fmiInstantiateSlave()
method.
|
protected com.sun.jna.Function |
_fmiDoStepFunction
The fmiDoStep() function.
|
protected com.sun.jna.Function |
_fmiEnterContinuousTimeModeFunction
The fmiEnterContinuousTimeMode Function, present only in FMI-2.0.
|
protected com.sun.jna.Function |
_fmiEnterInitializationModeFunction
The fmiEnterInitializationModeFunction, present only in FMI-2.0.
|
protected com.sun.jna.Function |
_fmiExitInitializationModeFunction
The fmiExitInitializationModeFunction, present only in FMI-2.0.
|
protected com.sun.jna.Function |
_fmiGetContinuousStatesFunction
Function to get the continuous states of the FMU for model exchange.
|
protected com.sun.jna.Function |
_fmiGetDerivativesFunction
Function to get the derivatives of a model-exchange FMU.
|
protected com.sun.jna.Function |
_fmiGetDirectionalDerivativeFunction
Function to get the directional derivatives of a model-exchange FMU.
|
protected com.sun.jna.Function |
_fmiGetEventIndicatorsFunction
Function to get the event indicators of the FMU for model exchange.
|
protected com.sun.jna.Function |
_fmiGetIntegerStatusFunction
The fmiGetIntegerStatus() function.
|
protected com.sun.jna.Function |
_fmiGetRealStatusFunction
The fmiGetRealStatus() function.
|
protected int |
_fmiJNIComponent
The index of the component.
|
protected FMIModelDescription |
_fmiModelDescription
A representation of the fmiModelDescription element of a Functional
Mock-up Unit (FMU) file.
|
protected com.sun.jna.Function |
_fmiNewDiscreteStatesFunction
The _fmi2NewDiscreteStates function, present only in FMI-2.0.
|
protected com.sun.jna.Function |
_fmiSetTimeFunction
Function to set the time of the FMU for model exchange.
|
protected com.sun.jna.Function |
_fmiSetupExperimentFunction
The _fmiSetupExperiment function.
|
protected double |
_fmiVersion
The version of FMI that the FMU declares it is compatible with, converted
to a double for easy comparison.
|
protected boolean |
_isStrict
Indicator of whether the actor is strict, meaning that all inputs must be
known to fire it.
|
protected Time |
_lastCommitTime
The time at which the last commit occurred (initialize or postfire).
|
protected int |
_lastFireMicrostep
The microstep at which the last fire occurred.
|
protected Time |
_lastFireTime
The time at which the last fire occurred.
|
protected boolean |
_modelInitialized
True if _fmiInitialize() completed.
|
protected double[] |
_newStates
The new states computed in fire(), to be committed in postfire.
|
protected double |
_refinedStepSize
Refined step size suggested by the FMU if doStep failed, or -1.0 if there
is no suggestion.
|
protected double |
_relativeTolerance
The relative tolerance for errors in double values.
|
protected java.nio.DoubleBuffer |
_states
For model exchange, the FMU state variables.
|
protected boolean |
_stepSizeRejected
Indicator that the proposed step size provided to the fire method has
been rejected by the FMU.
|
protected boolean |
_suggestZeroStepSize
Indicator that we have had iteration with a rejected step size, so the
next suggested step size should be zero.
|
protected double |
_threshold
The delta to exceed to produce outputs if QSS is used.
|
protected byte |
_toleranceControlled
Boolean indicating whether the director uses an error tolerance.
|
StringParameter |
fmiVersion
The FMI version of the FMU.
|
FileParameter |
fmuFile
The Functional Mock-up Unit (FMU) file.
|
Parameter |
modelExchange
If true, then this FMU is for model exchange rather than co-simulation.
|
Parameter |
persistentInputs
If true, then previously received input values will be re-used on
subsequent firings where inputs are absent.
|
Parameter |
removeDirectDependency
If true, then this, then the dependency of all inputs
on outputs are removed.
|
Parameter |
stateVariablesAsInputPorts
If true, then this FMU has state variables that are visible as
Ptolemy input ports.
|
Parameter |
suppressWarnings
If true, suppress warnings about the FMU not being able to roll back.
|
Parameter |
useRawJNI
If true, then use raw JNI instead of using JNA, which in turn
uses JNI.
|
Parameter |
visible
If true, indicate to the FMU (if it supports it) that it is allowed to
create displays and otherwise interact with the user.
|
_typesValid
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
COMPLETED, NOT_READY, STOP_ITERATING
Constructor and Description |
---|
FMUImport(CompositeEntity container,
java.lang.String name)
Construct an actor with the given container and name.
|
Modifier and Type | Method and Description |
---|---|
protected static boolean |
_acceptFMU(FMIModelDescription fmiModelDescription)
Determine if the model description is acceptable.
|
protected boolean |
_checkEventIndicators()
Return true if we are not in the first firing and the sign of
some event indicator has changed.
|
protected void |
_checkFmiCommon()
If _fmiModelDescription is null or does not have a non-null
modelIdentifier, then thrown an exception with an informative message.
|
protected boolean |
_completedIntegratorStepNotNeeded()
Return true if the modelExchangeCapabilities has a
completedIntegratorStepNotNeeded flag that is set to true.
|
protected void |
_debugToStdOut(java.lang.String message)
Print the debug message to stdout and flush stdout.
|
protected void |
_enterContinuousTimeMode()
Invoke the fmi2EnterContinuousTimeMode() function.
|
protected void |
_enterEventMode()
Invoke the fmi2EnterEventMode() function.
|
protected boolean |
_fmiCompletedIntegratorStep(boolean eventOccuredOrNoSetFMUStatePriorToCurrentPoint)
For model exchange, complete the integrator step.
|
protected void |
_fmiCompletedIntegratorStepJNI()
For model exchange, complete the integrator step.
|
protected double |
_fmiDoStep(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 |
_fmiEnterContinuousTimeModeJNI()
Enter continuous mode of the FMU
array.
|
protected void |
_fmiEnterEventModeJNI()
Enter event mode of the FMU.
|
protected void |
_fmiFreeInstance()
Free the instance of the FMU.
|
protected void |
_fmiGetContinuousStates(double[] values)
For model exchange, Get the continuous states of the FMU to the specified
array.
|
protected void |
_fmiGetContinuousStatesJNI(double[] values)
Get the continuous states of the FMU to the specified
array.
|
protected double[] |
_fmiGetDerivatives()
Return the derivatives of the continuous states provided by the FMU.
|
protected void |
_fmiGetDerivativesJNI(double[] values)
Get the derivatives of the FMU to the specified
array.
|
protected void |
_fmiGetEventIndicatorsJNI(double[] values)
Get the event indicators.
|
protected void |
_fmiGetRealJNI(double[] values,
long[] valueReferences)
Get the double inputs of the FMU to the specified
array.
|
protected void |
_fmiInitialize()
Invoke _fmiInitialize() (for model exchange) or _fmiInitializeSlave()
(for co-simulation) on the FMU.
|
protected void |
_fmiInitializeJNI()
Initialize the FMU
array.
|
protected java.lang.Integer |
_fmiInstantiateJNI(java.lang.String modelIdentifier,
java.lang.String fmuLibPath,
java.lang.String fmuResourceLocation,
double startime,
double stoptime,
double currentime,
java.lang.Integer toleranceDefined,
double quantum,
byte visible,
byte logging,
java.lang.String guid,
double[] derivatives,
double[] eventIndicators)
Instantiate the FMU
array.
|
protected void |
_fmiNewDiscreteStatesJNI()
Enter discrete states of the FMU
array.
|
protected void |
_fmiSetContinuousStates(double[] values)
For model exchange, set the continuous states of the FMU to the specified
array.
|
protected void |
_fmiSetContinuousStatesJNI(double[] values)
For model exchange, set the continuous states of the FMU to the specified
array.
|
protected void |
_fmiSetRealJNI(double[] values,
long[] valueReferences)
Set the double inputs of the FMU to the specified
array.
|
protected void |
_fmiSetTime(Time time)
Set the time of the FMU to the specified time.
|
protected void |
_fmiSetTimeJNI(double timeValue)
Set the time in the FMU.
|
protected static java.lang.String |
_fmiStatusDescription(int fmiStatus)
Return a string describing the specified fmiStatus.
|
protected void |
_fmiTerminate()
Terminate the FMU.
|
protected static java.lang.String |
_fmiType2PtolemyType(FMIType type)
Given a FMIType object, return a string suitable for setting the
TypeAttribute.
|
protected void |
_freeFMUState()
Free the memory recording FMU state, if the canGetAndSetFMUstate
capability flag for the FMU is true.
|
protected java.util.List<FMUImport.Input> |
_getInputs()
Return a list of inputs of the FMU.
|
protected java.util.List<FMUImport.Output> |
_getOutputs()
Return a list of connected outputs of the FMU.
|
protected Port |
_getPortByNameOrDisplayName(java.lang.String portName)
Get the port by display name or, if the display name is not set, then by
name.
|
protected double |
_getStepSize()
Return the current step size.
|
protected boolean |
_hasQSSDirector()
Return true if we use the QSSDirector.
|
protected static void |
_importFMU(java.lang.Object originator,
FileParameter fmuFileParameter,
NamedObj context,
double x,
double y,
boolean modelExchange,
boolean addMaximumStepSizeParameter,
boolean stateVariablesAsInputPorts,
java.lang.String actorClassName,
java.lang.reflect.Method acceptFMUMethod)
Import a FMUFile.
|
protected static boolean |
_isScalarAPtolemyInput(FMIModelDescription fmiModelDescription,
FMIScalarVariable scalar,
boolean stateVariablesAsInputPorts)
Return true if scalar is a Ptolemy input.
|
protected boolean |
_newDiscreteStatesNeeded(FMI20EventInfo.ByReference fmi20EventInfo)
Invoke newDiscreteStatesNeeded() and return true if
the fmu wants to terminate.
|
protected void |
_recordFMUState()
Record the current FMU state.
|
protected void |
_requestRefiringIfNecessary()
If the FMU can provide a maximum step size, query for that maximum step
size and call fireAt() to ensure that the FMU is invoked at the specified
time.
|
protected void |
_restoreFMUState()
Restore the current FMU state to match that most recently recorded, if
the canGetAndSetFMUstate capability flag for the FMU is true.
|
protected void |
_setFMUScalarVariable(FMIScalarVariable scalar,
Token token)
Set a scalar variable of the FMU to the value of a Ptolemy token.
|
protected void |
_setParameter(Parameter parameter,
FMIScalarVariable scalar)
Set a Ptolemy II Parameter to the value of a FMI ScalarVariable.
|
protected boolean |
_skipIfKnown()
Return true if outputs are skipped if known.
|
protected void |
_updateParameters()
Update the parameters listed in the modelDescription.xml file
contained in the zipped file named by the fmuFile
parameter.
|
protected boolean |
_useRawJNI()
Return true if we use use raw JNI instead of JNA.
|
boolean |
advance(Time time,
int microstep)
Advance to the specified time.
|
void |
attributeChanged(Attribute attribute)
If the specified attribute is fmuFile, then unzip the file and
load in the .xml file, creating and deleting parameters as necessary.
|
void |
declareDelayDependency()
Set the dependency between all output ports and all input ports of this
actor.
|
void |
fire()
Invoke fmiDoStep() of the slave FMU, if necessary to catch up to current
time, and then set the (known) inputs of the FMU and retrieve and send
out any outputs for which all inputs on which the output depends are
known.
|
java.util.List<FMIScalarVariable> |
getInputDependencyList(FMIScalarVariable scalar)
Return the input scalar dependency for a given FMI scalar.
|
java.util.List<FMIScalarVariable> |
getScalarVariables()
Return the list of all the scalar variables defined in the FMU
interface.
|
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 |
isStepSizeAccurate()
Return whether the most recent call to fmiDoStep() succeeded.
|
boolean |
isStrict()
Return false if any output has been found that not depend directly on an
input.
|
boolean |
postfire()
Override the base class to record the current time as the last commit
time.
|
void |
preinitialize()
Instantiate the slave FMU component.
|
double |
refinedStepSize()
Return suggested refined step size, if the FMU has provided one.
|
void |
rollBackToCommittedState()
Roll back to committed state, if the FMU has asserted
canGetAndSetFMUstate in the XML file and has provided the methods to set
and restore state.
|
static int |
runNativeFMU(int idx,
int fla,
java.lang.String instance,
java.lang.String jniResourceLocation,
java.lang.String fmuResourceLocation,
double tStart,
double tEnd,
double time,
int toleranceDefined,
double tolerance,
int visible,
int loggingOn,
java.lang.String guid,
double[] continuousStateDerivatives,
double[] continuousStatesFromFMU,
double[] continuousStatesToFMU,
double[] inputValues,
long[] inputValueReferences,
double[] outputValues,
long[] outputValueReferences,
long continuousStateDerivativesValueReference,
double[] directionalStateDerivatives,
long[] directionalStateDerivativesValueReferences,
double[] directionalInputDerivatives,
long[] directionalInputDerivativesValueReferences,
double[] continuousSecondDerivatives,
double[] eventIndicators,
double[] nextTimeEvent,
double[] stepEvent)
Interface to the FMU.
|
double |
suggestedStepSize()
Return the suggested next step size.
|
void |
wrapup()
Terminate and free the slave fmu.
|
_containedTypeConstraints, _customTypeConstraints, _defaultTypeConstraints, _fireAt, _fireAt, attributeTypeChanged, clone, clone, isBackwardTypeInferenceEnabled, newPort, typeConstraintList, typeConstraints
_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
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
_addPort, _description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
_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
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
isFireFunctional, iterate, prefire, stop, stopFire, terminate
addInitializable, removeInitializable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
getDerivedLevel, getDerivedList, propagateValue
public StringParameter fmiVersion
public FileParameter fmuFile
public Parameter modelExchange
public Parameter removeDirectDependency
public Parameter stateVariablesAsInputPorts
public Parameter persistentInputs
public Parameter suppressWarnings
public Parameter useRawJNI
public Parameter visible
protected FMICallbackFunctions _callbacks
protected FMI20CallbackFunctions _callbacks20
protected FMI20EventInfo _eventInfoJNI
protected com.sun.jna.Pointer _fmiComponent
protected int _fmiJNIComponent
protected FMIModelDescription _fmiModelDescription
protected double _fmiVersion
protected double _threshold
protected java.nio.DoubleBuffer _states
protected com.sun.jna.Function _fmiNewDiscreteStatesFunction
protected com.sun.jna.Function _fmiEnterContinuousTimeModeFunction
protected com.sun.jna.Function _fmiCompletedIntegratorStepFunction
protected com.sun.jna.Function _fmiSetTimeFunction
protected com.sun.jna.Function _fmiGetDerivativesFunction
protected com.sun.jna.Function _fmiGetContinuousStatesFunction
protected com.sun.jna.Function _fmiGetDirectionalDerivativeFunction
protected com.sun.jna.Function _fmiGetEventIndicatorsFunction
protected boolean _firstFire
protected boolean _firstFireInIteration
protected com.sun.jna.Function _fmiGetRealStatusFunction
protected com.sun.jna.Function _fmiGetIntegerStatusFunction
protected com.sun.jna.Function _fmiDoStepFunction
protected com.sun.jna.Function _fmiEnterInitializationModeFunction
protected com.sun.jna.Function _fmiExitInitializationModeFunction
protected com.sun.jna.Function _fmiSetupExperimentFunction
protected Time _lastCommitTime
protected Time _lastFireTime
protected int _lastFireMicrostep
protected boolean _modelInitialized
protected double[] _newStates
protected double _relativeTolerance
protected double _refinedStepSize
protected boolean _stepSizeRejected
protected boolean _isStrict
protected boolean _suggestZeroStepSize
protected byte _toleranceControlled
public FMUImport(CompositeEntity container, java.lang.String name) throws NameDuplicationException, IllegalActionException
container
- The container.name
- The name of this actor.IllegalActionException
- If the actor cannot be
contained by the proposed container.NameDuplicationException
- If the container already
has an actor with this name.public boolean advance(Time time, int microstep) throws IllegalActionException
advance
in interface Advanceable
time
- The time to advance.microstep
- The microstep to advance.IllegalActionException
- If an error occurs advancing
time.public void attributeChanged(Attribute attribute) throws IllegalActionException
attributeChanged
in class NamedObj
attribute
- The attribute that has changed.IllegalActionException
- If the specified attribute is
fmuFile and the file cannot be opened or there is a
problem creating or destroying the parameters listed in the
file.public void declareDelayDependency() throws IllegalActionException
declareDelayDependency
in class AtomicActor<TypedIOPort>
IllegalActionException
- Not thrown in this base
class, derived classes should throw this exception if the delay
dependency cannot be computed.AtomicActor.getCausalityInterface()
,
AtomicActor._declareDelayDependency(IOPort, IOPort, double)
public void fire() throws IllegalActionException
fire
in interface Executable
fire
in class AtomicActor<TypedIOPort>
IllegalActionException
- If the FMU indicates a failure.public java.util.List<FMIScalarVariable> getInputDependencyList(FMIScalarVariable scalar)
scalar
- The FMI scalar output port for which you want the
FMI input scalar dependency list.public java.util.List<FMIScalarVariable> getScalarVariables()
public static void importFMU(java.lang.Object originator, FileParameter fmuFileParameter, NamedObj context, double x, double y, boolean modelExchange) throws IllegalActionException, java.io.IOException
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.IllegalActionException
- If there is a problem
instantiating the actor.java.io.IOException
- If there is a problem parsing the fmu file.public void initialize() throws IllegalActionException
initialize
in interface Initializable
initialize
in class AtomicActor<TypedIOPort>
IllegalActionException
- If the slave FMU cannot be
initialized.public boolean isStepSizeAccurate()
isStepSizeAccurate
in interface ContinuousStepSizeController
public boolean isStrict()
isStrict
in interface Executable
isStrict
in class AtomicActor<TypedIOPort>
public boolean postfire() throws IllegalActionException
postfire
in interface Executable
postfire
in class AtomicActor<TypedIOPort>
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.public void preinitialize() throws IllegalActionException
preinitialize
in interface Initializable
preinitialize
in class AtomicActor<TypedIOPort>
IllegalActionException
- If it cannot be instantiated.public double refinedStepSize() throws IllegalActionException
refinedStepSize
in interface ContinuousStepSizeController
IllegalActionException
- If the step size cannot be
further refined.public void rollBackToCommittedState() throws IllegalActionException
rollBackToCommittedState
in interface ContinuousStatefulComponent
IllegalActionException
- If the rollback attempts to
go back further than the last committed time.public static int runNativeFMU(int idx, int fla, java.lang.String instance, java.lang.String jniResourceLocation, java.lang.String fmuResourceLocation, double tStart, double tEnd, double time, int toleranceDefined, double tolerance, int visible, int loggingOn, java.lang.String guid, double[] continuousStateDerivatives, double[] continuousStatesFromFMU, double[] continuousStatesToFMU, double[] inputValues, long[] inputValueReferences, double[] outputValues, long[] outputValueReferences, long continuousStateDerivativesValueReference, double[] directionalStateDerivatives, long[] directionalStateDerivativesValueReferences, double[] directionalInputDerivatives, long[] directionalInputDerivativesValueReferences, double[] continuousSecondDerivatives, double[] eventIndicators, double[] nextTimeEvent, double[] stepEvent)
This methods calls the FMU using JNI with different flags. 0: Instantiate. 1: Initialize. 2: Enter event mode. 3: Enter continuous mode. 4: Get continuous states. 5: Get state derivatives. 6: Set continuous states. 7: Set single inputs. 8: Get single outputs. 9: Complete integrator. -1: Terminate simulation. -10: Get directional derivatives."
idx
- The index of the FMU instance.fla
- The flag to determine the FMI functions to call.instance
- The FMU instance name.jniResourceLocation
- The path to the FMU native library.fmuResourceLocation
- The path to the FMU resource location.tStart
- The FMU simulation start time.tEnd
- the FMU simulation end time.time
- The current simulation time.toleranceDefined
- the flag is true if sover tolerance is defined.tolerance
- The FMU solver tolerance.visible
- The FMU visible flag.loggingOn
- The FMU logginOn flag.guid
- The FMU GUID.continuousStateDerivatives
- The FMU state derivatives to get.continuousStatesFromFMU
- The FMU continuous states to get.continuousStatesToFMU
- The FMU continuous states to set.inputValues
- The FMU input values.inputValueReferences
- The FMU input value references.outputValues
- The FMU output values.outputValueReferences
- The FMU output value references.continuousStateDerivativesValueReference
- The FMU state derivative value reference.directionalStateDerivatives
- The FMU directional state derivatives.directionalStateDerivativesValueReferences
- The FMU directional state derivatives value references.directionalInputDerivatives
- The FMU directional input derivatives.directionalInputDerivativesValueReferences
- The FMU directional input derivatives value references.continuousSecondDerivatives
- The FMU second derivatives.eventIndicators
- The FMU event indicators.nextTimeEvent
- The next FMU time event.stepEvent
- The step event indicator.public double suggestedStepSize() throws IllegalActionException
suggestedStepSize
in interface ContinuousStepSizeController
IllegalActionException
- If an actor suggests an illegal step size.public void wrapup() throws IllegalActionException
wrapup
in interface Initializable
wrapup
in class AtomicActor<TypedIOPort>
IllegalActionException
- If the slave fmu cannot be
terminated or freed.protected static boolean _acceptFMU(FMIModelDescription fmiModelDescription) throws java.io.IOException
fmiModelDescription
- The description of the model to be checked.java.io.IOException
- If the model description is not acceptable.protected boolean _checkEventIndicators() throws IllegalActionException
IllegalActionException
- If the fmiGetEventIndicators
function is missing, or if calling it does not return fmiOK.protected void _enterContinuousTimeMode() throws IllegalActionException
IllegalActionException
- If there is a problem
invoking the fmi2ContinuousTimeMode() function in the fmi.protected void _enterEventMode() throws IllegalActionException
IllegalActionException
- If there is a problem
invoking the fmi2EnterEventMode() function in the fmi.protected void _debugToStdOut(java.lang.String message)
message
- The message to be displayed.protected boolean _fmiCompletedIntegratorStep(boolean eventOccuredOrNoSetFMUStatePriorToCurrentPoint) throws IllegalActionException
Under FMI previous to 2.0, if the FMU indicates that fmiEventUpdate() should be called, call it.
Note that in FMI-2.0, the ModelExchange attribute as an element
FMI20ModelExchangeCapabilities.completedIntegratorStepNotNeeded
that in the default is false, which means that
fmiCompletedIntegratorStep() should be called. However, if
completedIntegratorStepNotNeeded is true, then fmiCompletedIntegratorStep
is not called.
Under FMI-2.0, if the fmi2CompletedIntegrationStep() method sets the
value of the terminateSimulation parameter to true, then
Director.finish()
is invoked.
eventOccuredOrNoSetFMUStatePriorToCurrentPoint
- For FMI
< 2.0, true if event update should be called. for FMI ≥
2.0, True if fmi2SetFMUState() will not be called for times
before the current time in this simulation.IllegalActionException
- If the FMU does not return fmiOK.protected void _fmiCompletedIntegratorStepJNI()
protected double _fmiDoStep(Time newTime, int newMicrostep) throws IllegalActionException
newTime
- The time to advance to.newMicrostep
- The microstep to advance to.IllegalActionException
- If fmiDoStep() returns
anything other than fmiDiscard or fmiOK.protected void _fmiEnterContinuousTimeModeJNI()
protected void _fmiEnterEventModeJNI()
protected void _fmiFreeInstance() throws IllegalActionException
IllegalActionException
- If the FMU does not return fmiOK.protected void _fmiGetContinuousStates(double[] values) throws IllegalActionException
values
- The values of the states.IllegalActionException
- If the length of the array
does not match the number of continuous states, or if the FMU
does not return fmiOK.protected void _fmiGetContinuousStatesJNI(double[] values)
values
- The values of the outputs to get.protected double[] _fmiGetDerivatives() throws IllegalActionException
IllegalActionException
- If the FMU does not return fmiOK.protected void _fmiGetDerivativesJNI(double[] values)
values
- The derivative values.protected void _fmiGetEventIndicatorsJNI(double[] values)
values
- The event indicators values.protected void _fmiGetRealJNI(double[] values, long[] valueReferences)
values
- The values of the outputs to get.valueReferences
- The value references of the outputs.protected void _fmiInitialize() throws IllegalActionException
IllegalActionException
- If the FMU does not return fmiOK.protected void _fmiInitializeJNI()
protected java.lang.Integer _fmiInstantiateJNI(java.lang.String modelIdentifier, java.lang.String fmuLibPath, java.lang.String fmuResourceLocation, double startime, double stoptime, double currentime, java.lang.Integer toleranceDefined, double quantum, byte visible, byte logging, java.lang.String guid, double[] derivatives, double[] eventIndicators)
modelIdentifier
- The model identifier of the FMU.fmuLibPath
- The path to the FMu library.fmuResourceLocation
- The path to the FMU resource.startime
- The FMU start time.stoptime
- The FMU stop time.currentime
- The FMU current time.toleranceDefined
- The FMU tolerance defined.quantum
- The FMU tolerance.visible
- The FMU visible attribute.logging
- The FMU logging attribute.guid
- The FMU GUID.derivatives
- The FMU first derivatives.eventIndicators
- The FMU event indicators.protected void _fmiNewDiscreteStatesJNI()
protected void _fmiSetContinuousStates(double[] values) throws IllegalActionException
values
- The values to assign to the states.IllegalActionException
- If the length of the array
does not match the number of continuous states, or if the FMU
does not return fmiOK.protected void _fmiSetContinuousStatesJNI(double[] values)
values
- The values to assign to the states.protected void _fmiSetRealJNI(double[] values, long[] valueReferences)
values
- The values to assign to the inputs.valueReferences
- The value references of the inputs.protected void _fmiSetTime(Time time) throws IllegalActionException
time
- The time.IllegalActionException
- If the FMU does not return fmiOK.protected void _fmiSetTimeJNI(double timeValue)
timeValue
- The current timeprotected static java.lang.String _fmiStatusDescription(int fmiStatus)
fmiStatus
- The status returned by an FMI procedure.protected void _fmiTerminate() throws IllegalActionException
IllegalActionException
- If the FMU does not return fmiOK.protected void _freeFMUState() throws IllegalActionException
IllegalActionException
- If freeing the memory the state fails.protected java.util.List<FMUImport.Input> _getInputs() throws IllegalActionException
FMIScalarVariable
.IllegalActionException
- If no port matching the name
of a variable declared as an input is found.protected java.util.List<FMUImport.Output> _getOutputs() throws IllegalActionException
FMIScalarVariable
, and a set of input port on which the output
declares that it depends (or a null if it makes no such dependency
declaration).IllegalActionException
- If an expected output is not
found, or if the width of the output cannot be determined.protected double _getStepSize() throws IllegalActionException
IllegalActionException
- If there is a problem getting
the currentStepSize.protected static void _importFMU(java.lang.Object originator, FileParameter fmuFileParameter, NamedObj context, double x, double y, boolean modelExchange, boolean addMaximumStepSizeParameter, boolean stateVariablesAsInputPorts, java.lang.String actorClassName, java.lang.reflect.Method acceptFMUMethod) throws IllegalActionException, java.io.IOException
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.addMaximumStepSizeParameter
- True if a parameter named
"maximumStepSize" should be added.stateVariablesAsInputPorts
- True if, under state variables in the FMU
should be represented as input ports in the Ptolemy actor. Typically,
this parameter is true, but for QSS, it would be false, indicating
that the state variables are output ports.actorClassName
- The class name of the Ptolemy actor
to be instantiated, for example "ptolemy.actor.lib.fmi.FMUImport".acceptFMUMethod
- The _acceptFMU(FMIModelDescription)
method. Derived classes provide a different method than
the parent class.IllegalActionException
- If there is a problem
instantiating the actor.java.io.IOException
- If there is a problem parsing the fmu file.protected static boolean _isScalarAPtolemyInput(FMIModelDescription fmiModelDescription, FMIScalarVariable scalar, boolean stateVariablesAsInputPorts)
fmiModelDescription
- The model description.scalar
- the FMIScalarVariable in questionstateVariablesAsInputPorts
- True if, under state variables in the FMU
should be represented as ports in the Ptolemy actor. Typically,
this parameter is true, but for QSS, it would be false.protected boolean _newDiscreteStatesNeeded(FMI20EventInfo.ByReference fmi20EventInfo) throws IllegalActionException
fmi20EventInfo
- A reference to the FMI-2.0 event information.IllegalActionException
- If there was a failure to
set a new discrete state.protected void _recordFMUState() throws IllegalActionException
IllegalActionException
- If recording the state fails.protected void _requestRefiringIfNecessary() throws IllegalActionException
IllegalActionException
- If the call to fireAt() throws it.protected void _restoreFMUState() throws IllegalActionException
IllegalActionException
- If there is no recorded
state, or if restoring the state fails.protected void _setParameter(Parameter parameter, FMIScalarVariable scalar) throws IllegalActionException
parameter
- The Ptolemy parameter to be set.scalar
- The FMI scalar variable that contains the value to be setIllegalActionException
- If the scalar is of a type that is not handled.protected void _setFMUScalarVariable(FMIScalarVariable scalar, Token token) throws IllegalActionException
scalar
- the FMI scalar to be set.token
- the Ptolemy token that contains the value to be set.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.protected boolean _skipIfKnown() throws IllegalActionException
IllegalActionException
- If there is a problem getting
the currentStepSize.protected void _updateParameters() throws IllegalActionException, NameDuplicationException
IllegalActionException
- If the file named by the
fmuFile parameter cannot be unzipped or if there is a
problem deleting any pre=existing parameters or creating new
parameters.NameDuplicationException
- If a parameter to be
created has the same name as a pre-existing parameter.protected boolean _completedIntegratorStepNotNeeded() throws IllegalActionException
IllegalActionException
- If the
modelExchangeCapabilities does not have a
completedIntegratorStepNotNeeded field.protected void _checkFmiCommon() throws IllegalActionException
IllegalActionException
- If critical information is missing.protected Port _getPortByNameOrDisplayName(java.lang.String portName)
portName
- The name of the port to find. The name might
have a period in it, for example "foo.bar".protected static java.lang.String _fmiType2PtolemyType(FMIType type) throws IllegalActionException
type
- The FMIType object.IllegalActionException
- If the type is not supported.protected boolean _hasQSSDirector()
protected boolean _useRawJNI() throws IllegalActionException
IllegalActionException
- If there is a problem
reading the useRawJNI parameter.