FMIImport.jl implements the import functionalities of the FMI-standard (fmi-standard.org) for the Julia programming language. FMIImport.jl provides the foundation for the Julia packages FMI.jl and FMIFlux.jl.
Hi, I'm using FMIImport in part of my simulations, and ran into some issues here. I'm running my own simulation loop (so not the standard fmiSimulate function) but I copied parts of that loop in FMI.jl. To set the inputs when calling the fmu I use something akin to the following:
The issue is that fmi2SetReal only works with non-abstract vectors for the values argument. In my case, values is a view of an array, then the call fmi2SetReal(c::FMUComponent, vr::Vector{UInt32}, values::SubArray{Float64, 1, ...}) throws the following error
AssertionError: fmi2SetReal(...): `vr` (4) and `values` (1) need to be the same length.
The culprit is the[prepareValue function in FMIImport.jl, which transforms values::SubArray to a vector with 1 element values::Vector{SubArray}. values fails the check isa(values, Array). When I override this implementation (see below) my sim! function runs perfectly. Note that Array has been replaced by AbstractArray
function FMIImport.prepareValue(value)
if isa(value, AbstractArray) && length(size(value)) == 1
return value
else
return [value]
end
@assert false "prepareValue(...): Unknown dimension of structure `$dim`."
end
A multiple dispatch solution may be a bit more elegant though.
FMIImport.prepareValue(value) = [value]
FMIImport.prepareValue(value::AbstractVector) = value
Hi, I'm using FMIImport in part of my simulations, and ran into some issues here. I'm running my own simulation loop (so not the standard
fmiSimulate
function) but I copied parts of that loop inFMI.jl
. To set the inputs when calling the fmu I use something akin to the following:The issue is that
fmi2SetReal
only works with non-abstract vectors for thevalues
argument. In my case,values
is a view of an array, then the callfmi2SetReal(c::FMUComponent, vr::Vector{UInt32}, values::SubArray{Float64, 1, ...})
throws the following errorThe culprit is the[
prepareValue
function inFMIImport.jl
, which transformsvalues::SubArray
to a vector with 1 elementvalues::Vector{SubArray}
.values
fails the checkisa(values, Array)
. When I override this implementation (see below) mysim!
function runs perfectly. Note thatArray
has been replaced byAbstractArray
A multiple dispatch solution may be a bit more elegant though.