Skip to content
This repository was archived by the owner on Apr 16, 2025. It is now read-only.

Commit af6a2b9

Browse files
committed
Set direct feedthrough inputs in mdlZeroCrossings and mdlUpdate
and document calling sequence
1 parent 24421f3 commit af6a2b9

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

docs/fmu_import.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,23 @@ Use `FMIKit.setRelativeTolerance()` to set the relative tolerance for the embedd
183183
FMIKit.setRelativeTolerance(gcb, '1e-3')
184184
```
185185

186+
## Calling sequence
187+
188+
The S-function `sfun_fmurun` associated to the `FMU` block loads and connects the FMU to [Simulink's simulation loop](https://www.mathworks.com/help/simulink/sfg/how-the-simulink-engine-interacts-with-c-s-functions.html) by setting its inputs and retrieving its outputs.
189+
The S-function's `mdl*` callbacks in which the respective FMI functions are called depend on the interface type of the FMU and are described below.
190+
191+
### Co-Simulation calling sequence
192+
193+
For Co-Simulation all input variables are set in [`mdlUpdate`](https://www.mathworks.com/help/simulink/sfg/mdlupdate.html) and all output variables are retrieved in [`mdlOutputs`](https://www.mathworks.com/help/simulink/sfg/mdloutputs.html).
194+
[Direct feedthrough](https://www.mathworks.com/help/simulink/sfg/sssetinputportdirectfeedthrough.html) is disabled for all input ports.
195+
196+
### Model Exchange calling sequence
197+
198+
For Model Exchange direct feedthrough is enabled for an input port if any output variable declares a dependency on the corresponding input variable in the `<ModelStructrue>`.
199+
If any internal variable is added to the outputs of the FMU block direct feedthrough is enabled for all input ports.
200+
Input variables with [direct feedthrough](https://www.mathworks.com/help/simulink/sfg/sssetinputportdirectfeedthrough.html) enabled are set in [`mdlDerivatives`](https://www.mathworks.com/help/simulink/sfg/mdlderivatives.html?searchHighlight=mdlDerivatives), [`mdlZeroCrossings`](https://www.mathworks.com/help/simulink/sfg/mdlzerocrossings.html) and [`mdlOutputs`](https://www.mathworks.com/help/simulink/sfg/mdloutputs.html).
201+
In [`mdlUpdate`](https://www.mathworks.com/help/simulink/sfg/mdlupdate.html) all input variables are set.
202+
186203
## UserData struct
187204

188205
The information from the block dialog is stored in the parameter `UserData` of the FMU block:

sfun_fmurun.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,8 @@ static void mdlZeroCrossings(SimStruct *S) {
10041004

10051005
if (model) {
10061006

1007+
setInput(S, true);
1008+
10071009
auto z = ssGetNonsampledZCs(S);
10081010

10091011
if (nz(S) > 0) {
@@ -1025,6 +1027,9 @@ static void mdlDerivatives(SimStruct *S) {
10251027
auto model = component<Model>(S);
10261028

10271029
if (model) {
1030+
1031+
setInput(S, true);
1032+
10281033
auto x = ssGetContStates(S);
10291034
auto dx = ssGetdX(S);
10301035

0 commit comments

Comments
 (0)