public class FMUQSS extends FMUImport implements DerivativeFunction
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 for QSS integration, 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.
This actor uses any QSS solver to integrate the FMUs for model exchange. A package of QSS solvers can be found in org.ptolemy.qss. This actor extends from FMUImport.java and should be used along with the QSSDirector.FMUImport.Input, FMUImport.Output
Entity.ContainedObjectsIterator
Modifier and Type | Field and Description |
---|---|
Parameter |
eventDetection
If true, indicate the FMU can do state/time/step event detection.
|
Parameter |
initFMUParameters
If true, indicate the FMU to initialize parameters variables
parameters.
|
_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, _stepSizeRejected, _suggestZeroStepSize, _threshold, _toleranceControlled, fmiVersion, fmuFile, modelExchange, persistentInputs, removeDirectDependency, stateVariablesAsInputPorts, suppressWarnings, useRawJNI, visible
_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 |
---|
FMUQSS(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.
|
int |
evaluateDerivatives(Time time,
double[] stateVariables,
double[] inputVariables,
double[] stateVariableDerivatives)
Evaluate the derivative function.
|
int |
evaluateDerivatives(Time time,
double[] dtSample,
double[] eventIndicatorVariableDerivatives,
double[] eventIndicatorVariableDerivatives2,
double[] eventIndicatorVariableDerivatives3,
int order)
Evaluate the derivative function for state event detection.
|
double |
evaluateDirectionalDerivatives(int stateDerivIndex,
double[] stateVariableDerivatives,
double[] inputVariableDerivatives)
Evaluate directional derivative and compute second derivative.
|
int |
eventIndicatorDerivativeInputs(Time time,
double[] stateVariables,
double[] inputVariables,
Time timeSample,
double[] stateVariablesSample,
double[] inputVariablesSample,
double dtSample,
Time timeSample2,
double[] stateVariablesSample2,
double[] inputVariablesSample2,
double dtSample2,
Time timeSample3,
double[] stateVariablesSample3,
double[] inputVariablesSample3,
double dtSample3,
Time timeSample4,
double[] stateVariablesSample4,
double[] inputVariablesSample4,
double dtSample4,
Time timeSample5,
double[] stateVariablesSample5,
double[] inputVariablesSample5,
double dtSample5,
int stateModelOrder)
Provide inputs to evaluate the derivative
function for event indicators using finite difference methods.
|
void |
fire()
Override the FMUImport base class to produce outputs.
|
int |
getEventIndicatorCount()
Return the count of event indicator variables.
|
int |
getInputVariableCount()
Return the count of input variables.
|
boolean |
getProvidesDirectionalDerivatives()
Indicate existence of directional derivatives.
|
int |
getStateCount()
Return the count of state variables.
|
static void |
importFMU(java.lang.Object originator,
FileParameter fmuFileParameter,
NamedObj context,
double x,
double y)
Override the importFMU in FMUImport base class.
|
void |
initialize()
Initialize this FMU wrapper.
|
boolean |
postfire()
Update the calculation of the next output time and request a refiring at
that time.
|
void |
preinitialize()
Initialize the continuous states.
|
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)
Interface to the FMU.
|
void |
wrapup()
Terminate and free the slave fmu.
|
_checkEventIndicators, _checkFmiCommon, _completedIntegratorStepNotNeeded, _debugToStdOut, _enterContinuousTimeMode, _enterEventMode, _fmiCompletedIntegratorStep, _fmiCompletedIntegratorStepJNI, _fmiDoStep, _fmiEnterContinuousTimeModeJNI, _fmiEnterEventModeJNI, _fmiFreeInstance, _fmiGetContinuousStates, _fmiGetContinuousStatesJNI, _fmiGetDerivatives, _fmiGetDerivativesJNI, _fmiGetEventIndicatorsJNI, _fmiGetRealJNI, _fmiInitialize, _fmiInitializeJNI, _fmiInstantiateJNI, _fmiNewDiscreteStatesJNI, _fmiSetContinuousStates, _fmiSetContinuousStatesJNI, _fmiSetRealJNI, _fmiSetTime, _fmiSetTimeJNI, _fmiStatusDescription, _fmiTerminate, _fmiType2PtolemyType, _freeFMUState, _getInputs, _getOutputs, _getPortByNameOrDisplayName, _getStepSize, _hasQSSDirector, _importFMU, _isScalarAPtolemyInput, _newDiscreteStatesNeeded, _recordFMUState, _requestRefiringIfNecessary, _restoreFMUState, _setFMUScalarVariable, _setParameter, _skipIfKnown, _updateParameters, _useRawJNI, advance, attributeChanged, declareDelayDependency, getInputDependencyList, getScalarVariables, importFMU, isStepSizeAccurate, isStrict, refinedStepSize, rollBackToCommittedState, runNativeFMU, suggestedStepSize
_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 Parameter initFMUParameters
public Parameter eventDetection
public FMUQSS(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 final int evaluateDerivatives(Time time, double[] dtSample, double[] eventIndicatorVariableDerivatives, double[] eventIndicatorVariableDerivatives2, double[] eventIndicatorVariableDerivatives3, int order) throws IllegalActionException
evaluateDerivatives
in interface DerivativeFunction
time
- The current simulation time.dtSample
- The delta time used to approximate the first derivative.eventIndicatorVariableDerivatives
- The (output) vector of
time rates of change of the event indicators variables
at time
.eventIndicatorVariableDerivatives2
- The (output) vector of
time rates of change of the event indicators variables.eventIndicatorVariableDerivatives3
- The (output) vector of
time rates of change of the event indicators variables.order
- The order.IllegalActionException
- If an error occurred.public final int evaluateDerivatives(Time time, double[] stateVariables, double[] inputVariables, double[] stateVariableDerivatives) throws IllegalActionException
evaluateDerivatives
in interface DerivativeFunction
time
- The current simulation time.stateVariables
- The vector of state variables at time
.inputVariables
- The vector of input variables at time
.stateVariableDerivatives
- The (output) vector of time rates of change of the state variables
at time
.IllegalActionException
- If using raw JNI throws it,
if the time cannot be set, if the continuous states cannot be
set or if the state count cannot be read.public final double evaluateDirectionalDerivatives(int stateDerivIndex, double[] stateVariableDerivatives, double[] inputVariableDerivatives) throws IllegalActionException
evaluateDirectionalDerivatives
in interface DerivativeFunction
stateDerivIndex
- The state derivative index.stateVariableDerivatives
- The state derivatives.inputVariableDerivatives
- The input derivatives.IllegalActionException
- If thrown while computing the directional derivative.public int eventIndicatorDerivativeInputs(Time time, double[] stateVariables, double[] inputVariables, Time timeSample, double[] stateVariablesSample, double[] inputVariablesSample, double dtSample, Time timeSample2, double[] stateVariablesSample2, double[] inputVariablesSample2, double dtSample2, Time timeSample3, double[] stateVariablesSample3, double[] inputVariablesSample3, double dtSample3, Time timeSample4, double[] stateVariablesSample4, double[] inputVariablesSample4, double dtSample4, Time timeSample5, double[] stateVariablesSample5, double[] inputVariablesSample5, double dtSample5, int stateModelOrder) throws IllegalActionException
eventIndicatorDerivativeInputs
in interface DerivativeFunction
time
- Simulation time.stateVariables
- The vector of state variables at time
.inputVariables
- The vector of input variables at time
.timeSample
- Simulation time.stateVariablesSample
- The vector of state variables at timeSample
.inputVariablesSample
- The vector of input variables at timeSample
.dtSample
- The delta between timeSample
and time
.timeSample2
- Simulation time.stateVariablesSample2
- The vector of state variables at timeSample2
.inputVariablesSample2
- The vector of input variables at timeSample2
.dtSample2
- The delta between timeSample2
and time
.timeSample3
- Simulation time.stateVariablesSample3
- The vector of state variables at timeSample3
.inputVariablesSample3
- The vector of input variables at timeSample3
.dtSample3
- The delta between timeSample3
and time
.timeSample4
- Simulation time.stateVariablesSample4
- The vector of state variables at timeSample4
.inputVariablesSample4
- The vector of input variables at timeSample4
.dtSample4
- The delta between timeSample4
and time
.timeSample5
- Simulation time.stateVariablesSample5
- The vector of state variables at timeSample5
.inputVariablesSample5
- The vector of input variables at timeSample5
.dtSample5
- The delta between timeSample4
and time
.stateModelOrder
- The model order.IllegalActionException
- If an error occurred.public void fire() throws IllegalActionException
According to "System Design, Modeling, and Simulation Using Ptolemy II", version 1.02, section 12.3.1 "Execution Control": "The main computation of the actor is typically performed during the fire action, when it reads input data, performs computation, and produces output data."
If it is time to produce a quantized output, produce it. 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.fire
in interface Executable
fire
in class FMUImport
IllegalActionException
- If FMU indicates a failure.public final int getEventIndicatorCount()
getEventIndicatorCount
in interface DerivativeFunction
public final int getInputVariableCount()
getInputVariableCount
in interface DerivativeFunction
public final boolean getProvidesDirectionalDerivatives()
getProvidesDirectionalDerivatives
in interface DerivativeFunction
public final int getStateCount()
getStateCount
in interface DerivativeFunction
public static void importFMU(java.lang.Object originator, FileParameter fmuFileParameter, NamedObj context, double x, double y) 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.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
According to "System Design, Modeling, and Simulation Using Ptolemy II", version 1.02, section 12.3.1 "Execution Control": "The initialize action of the setup phase initializes parameters, resets local state, and sends out any initial messages."
initialize
in interface Initializable
initialize
in class FMUImport
IllegalActionException
- If the slave FMU cannot be initialized.public boolean postfire() throws IllegalActionException
According to "System Design, Modeling, and Simulation Using Ptolemy II", version 1.02, section 12.3.1 "Execution Control": "An actor may have persistent state that evolves during execution; the postfire action updates that state in response to any inputs. The fact that the state of an actor is updated only in postfire is an important part of the actor abstract semantics..."
If there is a new input, read it and update the slope.postfire
in interface Executable
postfire
in class FMUImport
IllegalActionException
- If reading inputs or parameters fails.public void preinitialize() throws IllegalActionException
preinitialize
in interface Initializable
preinitialize
in class FMUImport
IllegalActionException
- if an exception occurs.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)
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.public void wrapup() throws IllegalActionException
wrapup
in interface Initializable
wrapup
in class FMUImport
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