Skip to content

FMU Analysis ​

The FMUAnalysis builds an FMU from a Dyad model for use and execution in a myriad of simulation tools.

Method Overview ​

The Dyad compiler uses the physical description of the system to generate a system of differential-algebraic equations:

x′=f(x,y,u,p,t)0=g(x,y,u,p,t)h(x,y,u,p,t)

where x are the differential variables, y are the algebraic variables, p are the parameters, and t is the independent variable (time). Notably, the difference from the other analyses, such as TransientAnalysis and SteadyStateAnalysis, is the existance of the values u which are the input functions. These u(t) are values which are given by connections in the system in which the FMU connected. Additionally, h is the output function. As such the generated FMU is a causal component defined with only input and output connectors, no acausal connectors.

For a Model Exechange FMU, a binary is created which executes the (f,g,h) functions of the right-hand side from the state and input values. For a Cosimulation FMU, an ODE solver of the form from a TransientAnalysis is embedded into the system. I.e. a Cosimulation FMU is a clocked component which takes a dt and solves using an ODE solver to predict (x(t),y(t),h(x(t),y(t),u,p,t)) where the input value u is a constant given at the clock time.

Example Definition ​

dyad
analysis MyFMUAnalysis
  extends DyadFMUGeneration.FMUAnalysis()
  model = BlockComponents.Sine(frequency = 1.0, amplitude = 1.0)
end

The Dyad compiler will generate the MyFMUAnalysis function that will run the analysis.

julia
result = MyFMUAnalysis()
DyadFMUGeneration.FMUAnalysisSolution{DyadFMUGeneration.FMUAnalysisSpec{ModelingToolkit.System, String, String, String, Vector{String}, Vector{String}}}(DyadFMUGeneration.FMUAnalysisSpec{ModelingToolkit.System, String, String, String, Vector{String}, Vector{String}}(:FMUAnalysis, Model Sine:
Equations (1):
  1 standard: see equations(Sine)
Unknowns (1): see unknowns(Sine)
  y(t)
Parameters (5): see parameters(Sine)
  start_time [defaults to 0]: Time at which the signal starts changing from its offset value
  offset [defaults to 0]: Constant value added to the signal output
  amplitude [defaults to 1]: Peak value of the sine wave
  frequency [defaults to 1]: Number of cycles per time unit
  â‹®, "FMI_V2", "FMI_BOTH", "auto", 0, String[], 0, String[]), "/home/actions-runner-1/.julia/scratchspaces/ca28fe3e-7809-4c0f-9d3e-a21c6e6f3e9d/JSDeploymentjl/0k8KzF/Sine.fmu")

This builds an FMU. The path for the FMU is given as an artifact:

julia
using DyadInterface
fmu_path = artifacts(result, :FMU)
"/home/actions-runner-1/.julia/scratchspaces/ca28fe3e-7809-4c0f-9d3e-a21c6e6f3e9d/JSDeploymentjl/0k8KzF/Sine.fmu"

Analysis Arguments ​

Required Arguments ​

  • model: the Dyad model that the analysis is being applied to.

Optional Arguments ​

  • version::String: the FMU version to use. Defaults to "FMI_V2", with the other possible choice being "FMI_V3".

  • type::String: the type of FMU to build. Choices are "FMI_ME" for Model Exchange, "FMI_CS" for Cosimulation, or "FMI_BOTH" for a binary which has both embedded within it.

  • alg::String: chooses the solver algorithm for the solution process of the Cosimulation FMU. The default is "auto". The choices are:

    • "auto" - Automatic algorithm choice with stiffness detection, size detection, and linear solve swapping from OrdinaryDiffEq.jl.

    • "Rodas5P" - Adaptive time Rosenbrock method from OrdinaryDiffEqRosenbrock.jl. The Rosenbrock methods are specifically fast for small systems of stiff equations and DAEs which avoid Jacobian singularity issues (i.e. no variable-index DAE behavior).

    • "FBDF" - Adaptive order, adaptive time fixed leading coefficient backwards differentiation formulae (BDF) method from OrdinaryDiffEqBDF.jl, modeled after the FLC formulation of VODE. This is a good method for large stiff systems and DAEs.

    • "Tsit5" - 5th order explicit Runge-Kutta method from OrdinaryDiffEqTsit5.jl. This method is not applicable to DAEs and is only applicable to systems which have no algebraic constraints (post simplification).

  • n_inputs::Integer: the number of inputs, i.e. the length of the u(t) vector.

  • inputs::String[n_inputs]: the variables of the Dyad model which will be defined by the inputs. The ordering of the vector needs to match the ordering of the u(t) vector definition.

  • n_outputs::Integer: the number of outputs, i.e. the length of the output of h.

  • outputs::String[n_outputs]: the names of the variables to include in the output vector h. The ordering of the vector needs to match the ordering of h.

Artifacts ​

The FMUAnalysis returns the following artifacts:

Standard Artifacts ​

  • :FMU: A string for the path to the generated FMU.