2. By setting the complete FMU state using
fmi3SetFMUState
, all variables are potentially changed.
All strings passed as arguments to fmi3SetString , as well as all binary values passed as arguments to fmi3SetBinary , must be copied
during these function calls, because there is no guarantee of the lifetime of strings or binary values, when these functions return.
2.2.6.3. Handling min/max Range Violations
Attributes min and max can be defined for variables of float, integer or enumeration types. The question is how fmi3Set{VariableType} ,
fmi3Get{VariableType} shall utilize this definition. There are several conflicting requirements:
Avoiding forbidden regions (for example, if
u is an input and "sqrt(u)" is computed in the FMU, min = 0 on u shall guarantee that only
values of
u in the allowed regions are provided). Numerical algorithms (solvers or optimizers) do not guarantee constraints. If a variable
is outside of the bounds, the solver tries to bring it back into the bounds. As a consequence, calling
fmi3Get{VariableType} during an
iteration of such a solver might return values that are not in the defined min/max region. After the iteration is finalized, it is only
guaranteed that a value is within its bounds up to a certain numerical precision.
During system creation and prototyping, checks on min/max should be performed. For maximum performance on production or real-
time systems, these checks might not be performed.
The approach in FMI is therefore that min/max definitions are an information from the FMU to the environment defining the region in
which the FMU is designed to operate. In any case, it is expected that the FMU handles variables appropriately where the region
definition is critical. For example, dividing by an
input (so the input should not be in a small range of zero) or taking the square root of
an
input (so the input should not be negative) may either result in returning fmi3Discard or fmi3Error , or the FMU is able to handle this
situation in other ways.
If the FMU is generated so that min/max shall be checked whenever meaningful (for example, for debug purposes), then the following
strategy should be used:
If
fmi3Set{VariableType} is called violating the min/max attribute settings of the corresponding variable, the following actions are
performed:
On a fixed or tunable parameter fmi3Status == fmi3Discard is returned.
On an input , the FMU decides what to return (If no computation is possible, it could return fmi3Status == fmi3Discard , in other
situations it may return
fmi3Warning or fmi3Error , or fmi3OK , if it is uncritical).
If an FMU defines min/max values for integer types and
<Enumeration> variables ( local and output variables), then the expected behavior
of the FMU is that
fmi3Get{VariableType} functions return values in the defined range.
If an FMU defines min/max values, then the expected behavior of the FMU is that
fmi3Get{VariableType} returns values at the solution
(accepted steps of the integrators) in the defined range with a certain uncertainty related to the tolerances of the numerical algorithms.]
2.2.6.4. Getting and Setting the Complete FMU State
The FMU has an internal state consisting of all values that are needed to continue a simulation. This internal state consists especially of
the values of the continuous states, iteration variables,
parameter values, input values, delay buffers, file identifiers, and FMU internal
status information. With the functions of this section, the internal FMU state can be copied and the pointer to this copy is returned to the
environment. The FMU state copy can be set as actual FMU state, in order to continue the simulation from it.
[Examples for using this feature:
For variable step-size control of co-simulation algorithms (get the FMU state for every accepted communication step; if the follow-up step is
not accepted, restart co-simulation from this FMU state).
For nonlinear Kalman filters (get the FMU state just before initialization; in every sample period, set new continuous states from the Kalman
filter algorithm based on measured values; integrate to the next sample instant and inquire the predicted continuous states that are used in
the Kalman filter algorithm as basis to set new continuous states).
For nonlinear model predictive control (get the FMU state just before initialization; in every sample period, set new continuous states from an
observer, initialize and get the FMU state after initialization. From this state, perform many simulations that are restarted after the
initialization with new input variables proposed by the optimizer).]