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.

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

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)
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.

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)
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

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
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

FMIExchange.affectFMU!Method
affectFMU!(model::CachedModel{<:CachedFMU2}, integrator, idx)

Handle events in the FMU

FMIExchange.cache!Method
cache!(cm::CachedModel, u, p)

Store the relevant parts of the state and io memory buffers in the cache

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)

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

FMIExchange.derivative!Method
derivative!(cm::CachedModel, dst)

Copy the cached derivative in cm to the destination

FMIExchange.dynamicsMethod
dynamics(models)

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

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
FMIExchange.get_input_callbacksMethod
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

FMIExchange.get_state_callbacksMethod
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

FMIExchange.get_step_callbacksMethod
get_step_callbacks(model::CachedModel{<:CachedFMU2})

Return a callback to handle integrator step completion in the FMU

FMIExchange.get_time_callbacksMethod
get_time_callbacks(model::CachedModel{<:CachedFMU2}, start, stop)

Return a callback to handle all time events in the FMU

FMIExchange.indicators!Method
indicators!(dst, cm::CachedModel)

Copy event indicators from cm to the destination

FMIExchange.indicators!Method
indicators!(cm::CachedModel, src)

Copy event indicators from the source to the relevant cache in cm

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)
FMIExchange.output!Method
output!(::AbstractSimModel, u, p, t)

Write the model output to the relevant indices of p

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

FMIExchange.psizeMethod
psize(spec::AbstractModelSpecification)

Return the length of the io memory buffer

FMIExchange.uncache!Method
uncache!(cm::CachedModel, dst)

Copy the cache new state in cm to the destination

This is used in event handling where the state is discontinuous. In these cases the cache for the derivative is used to store the new state. Thus this method is an alias for derivative!

FMIExchange.usizeMethod
usize(spec::AbstractModelSpecification)

Return the length of the state memory buffer