Reference

FMU-specific functions

FMIExchange.jl currently supports only FMI version 2.0. FMIExchange.jl automatically generates the callbacks required for handling all FMU events. To simulate the FMU, a CachedFMU2 must be wrapped in a CachedModel (See Simulation Models)

FMIExchange.CachedFMU2Type
CachedFMU2{R}
CachedFMU2(fmuloc::String, start::Real, stop::Real, ins::AbstractVector, outs::AbstractVector, staterefs::AbstractVector, parameters::Union{Dict,Nothing}=nothing)

Wrapper struct for FMU2s. This is mainly used for dispatch purposes and ensures that the inputs, states and outputs are returned in the expected order

Arguments

  • fmuloc::String fmu file path
  • start::Real simulation start time
  • stop::Real simulation stop time
  • ins::AbstractVector vector of fmu inputs (as string or symbol)
  • outs::AbstractVector vector of fmu outputs (as string or symbol)
  • staterefs::AbstractVector vector of fmu states (as string or symbol)
  • parameters::Union{Dict, Nothing}=nothing dictionary of fmu parameters or nothing if the default parameters should be used

Fields

  • fmu::FMU2 fmu object as defined by FMICore.jl
  • c::FMU2Component fmu component object as defined by FMICore.jl
  • input_value_references::R vector of non-human-readable references to the inputs (for working with the fmu)
  • output_value_references::R vector of non-human-readable references to the outputs (for working with the fmu)
  • state_value_references::R vector of non-human-readable references to the states (for working with the fmu)
source
FMIExchange.condition!Method
condition!(model::CachedModel{<:CachedFMU2}, x, t, integrator)
condition!(out, model::CachedModel{<:CachedFMU2}, x, t, integrator)

Return event indicators out for the FMU (non-mutating and mutating version)

source
FMIExchange.get_state_callbacksFunction
get_state_callbacks(model::CachedModel{<:CachedFMU2})

Return a callback to handle state events in an FMU.

The returned callback is a continuous callback is able to detect events due to changes in the FMU state, but it will not be able to detect events due to changes in the FMU input.

See also get_input_callbacks

source
FMIExchange.get_input_callbacksFunction
get_input_callbacks(model::CachedModel{<:CachedFMU2})

Return a callback to handle state events in an FMU.

The returned callback is a discrete callback will be able to detect events due to changes in the FMU input, but it will not be able to detect events due to changes in the FMU state.

See also get_state_callbacks

source

Simulation Models

Simulation models can be directly simulated with DifferentialEquations.jl like one normally would. They contain machine-readable address maps which allow to easily combine multiple simulation models in one simulation.

FMIExchange.AbstractSimModelType
AbstractSimModel

Simulation model that can be directly simulated using DifferentialEquations.jl. An AbstractSimModel wraps an ODE with events such that it can be easily used in a simulation with multiple components.

Usage

A simulation model contains a number of inputs, states and outputs. States are subject to an ODE with events. Outputs can be calculated from the inputs and states of the model, but this calculation may not modify the state of the model.

source
FMIExchange.SimModelType
SimModel <: AbstractSimModel
SimModel(f, g, ilength::Integer, olength::Integer, xlength::Integer, cbs; ioffset = 0, xoffset = 0)

Return a basic simulation model

Arguments

  • f: function for calculating the derivative (refer to DifferentialEquations.jl)
  • g: function for calculating the output. This function is called as follows g(out, state, in, time) and should mutate the out variable
  • ilength: length of the model input
  • olength: length of the model output
  • xlength: length of the model state
  • cbs: callbacks associated with the model
  • ioffset=0: io memory buffer address offset
  • xoffset=0: state memory buffer address offset
source
FMIExchange.CachedModelType
CachedModel <: AbstractSimModel
CachedModel(fmu::CachedFMU2, uoffset=0, poffset=0)

Simulation model that contains caches for storing the state and input/output.

This is primarily used to accelerate FMUs: C-calls to the FMU cannot operate on array views. If a standard SimModel were used, every C-call to the FMU would thus convert that view to a new array, allocating memory and massively slowing down the simulation. This struct preallocates fixed-size caches of types which can be directly passed to C-calls and do not need to be converted.

source
FMIExchange.AbstractSimModelMethod
(::AbstractSimModel)(u, p, t)
(::AbstractSimModel)(du, u, p, t)

Calculate the derivative of the model state. Refer to the documentation of DifferentialEquations.jl

source
FMIExchange.get_callbacksMethod
get_callbacks(model::AbstractSimModel, start, stop)

Return a vector of callbacks associated with the simulation model.

Arguments

  • model::AbstractSimModel simulation model
  • start simulation start time
  • stop simulation stop time
source

Model Specifications

Model specifications contain human-readable address maps, and can be converted to simulation models for simulation.

FMIExchange.ModelSpecificationType
ModelSpecification{S1,S2,F,G} <: AbstractModelSpecification{S1,S2}

Fields

  • inputs::AbstractVector{S1}: Vector of human-readable input names
  • outputs::AbstractVector{S1}: Vector of human-readable output names
  • states::AbstractVector{S2}: Vector of human-readable state names
  • dynamics::F: Function for calculating the derivative (refer to DifferentialEquations.jl)
  • output::G: Function for calculating the output. This function is called as follows output(out, state, in, time) and should mutate the out variable

See also SimModel

source
FMIExchange.FMUSpecificationType
FMUSpecification{S1, S2, S3<:Union{Symbol,AbstractString}, P<:Union{Dict{String,Float64},Nothing}} <: AbstractModelSpecification{S1,S2}

A model specification that can be converted to a CachedModel{<:CachedFMU2}

Fields

  • inputs::AbstractVector{S1}: Vector of human-readable input names
  • outputs::AbstractVector{S1}: Vector of human-readable output names
  • states::AbstractVector{S2}: Vector of human-readable state names
  • fmu_location::S3: Path to the FMU
  • parameters::P: Dictionary with FMU parameters (or nothing to use defaults)
source
FMIExchange.usizeMethod
usize(spec::AbstractModelSpecification)

Return the length of the state memory buffer

source
FMIExchange.create_modelFunction
create_model(::AbstractModelSpecification, uoffset=0, poffset=0; start=0.0, stop=1.0)
create_model(specs::AbstractVector{<:AbstractModelSpecification}, uoffset=0, poffset=0; start=0.0, stop=1.0)

Return a simulation model (<:AbstractSimModel) with machine-readable address maps

If a vector of model specifications is provided, return a vector of simulation models with non-overlapping address maps

See also AbstractSimModel

source

Simulation composition functionality

Below functions are meant to simplify composing complex simulations with multiple models.

FMIExchange.address_mapMethod
address_map(ins, outs, states, m::AbstractSimModel)
address_map(spec::AbstractModelSpecification, uoffset=0, poffset=0)
address_map(specs::AbstractVector{<:AbstractModelSpecification}, uoffset=0, poffset=0)

Return two dictionaries linking human-readable strings/symbols for model inputs/outputs and states to machine-readable indices

source
FMIExchange.link_modelsMethod
link_models(src, dst)
link_models(src, dst, iomap)

Return a FunctionCallingCallback that connects inputs and outputs of models. This does not automatically resolve algebraic loops!

Arguments

  • src human-readable strings/symbols or machine-readable indices of the model io that will be copied
  • dst human-readable strings/symbols or machine-readable indices of the copy destinations
  • iomap dictionary mapping the human-readable strings/symbols to indices (if src and dst provided as string/symbol)
source
FMIExchange.output_callbackMethod
output_callback(m::AbstractSimModel)
output_callback(ms::AbstractVector{<:AbstractSimModel})

Return a callback that calls the output function of the simulation model m (or every simulation model in ms) after every integration step

source
FMIExchange.dynamicsMethod
dynamics(models)

Return a single DifferentialEquations.jl-compatible function that calculates derivatives of all models in models

source