Issue with FMU Export after Manipulating Model in Julia

CurioMath
Wed, 09 Oct 2024 06:00:30 +0000
General Usage

Hi everyone,

I am trying to export an FMU in Julia after importing and manipulating an FMU model. Specifically, I followed the example for manipulation from the documentation of FMIExport.jl, which can be found here:

Manipulation Example

The code works fine up to the following point:

using FMI
using FMIExport
using FMICore
using FMIZoo

originalGetReal = nothing # function pointer to the original fmi2GetReal c-function

function myGetReal!(c::fmi2Component, vr::Union{Array{fmi2ValueReference}, Ptr{fmi2ValueReference}}, nvr::Csize_t, value::Union{Array{fmi2Real}, Ptr{fmi2Real}})
    global originalGetReal
    status = fmi2GetReal!(originalGetReal, c, vr, nvr, value)

    if isa(value, Ptr{fmi2Real})
        value = unsafe_wrap(Array{fmi2Real}, value, nvr, own=false)
    end
    if isa(vr, Ptr{fmi2Real})
        vr = unsafe_wrap(Array{fmi2Real}, vr, nvr, own=false)
    end

    for i in 1:nvr
        if vr[i] == 335544320 # value reference for "positionSensor.s"
            value[i] *= 2.0
        end
    end

    return status
end

FMIBUILD_CONSTRUCTOR = function(resPath)
    global originalGetReal
    fmu = loadFMU(joinpath(resPath, "SpringDamperPendulum1D.fmu"))
    originalGetReal = fmu.cGetReal
    fmi2SetFctGetReal(fmu, myGetReal!)
    return fmu
end

This generates the necessary files including binaries, documentation, source, and model description (XML). However, I am having trouble exporting it into a single .fmu file. I tried using the following code:

using FMIBuild
FMIBuild.saveFMU(fmu, fmu_save_path)

But it throws the following warnings and error:

┌ Warning: This FMU has a model name `SpringDamperPendulum1D` that does not fit the FMU filename `Manipulation.fmu`. Is this intended?
┌ Warning: This FMU has a model exchange identifier `SpringDamperPendulum1D` that does not fit the FMU filename `Manipulation.fmu`. Is this intended?
┌ Warning: This FMU has a co simulation identifier `SpringDamperPendulum1D` that does not fit the FMU filename `Manipulation.fmu`. Is this intended?
ERROR: AssertionError: ["fmiBuild(...): Cannot find a package where this file is stored in. For FMU-Export, this source file needs to be inside of a package."]

Can anyone shed light on what I might be doing wrong or whether you have faced similar issues?
Looking forward to your responses. Thanks!

9 posts - 4 participants