Skip to content

Commit

Permalink
v0.4.0 (#44)
Browse files Browse the repository at this point in the history
* changes for FMIBase.jl

* adaptions for FMIBase

* python test action for exported FMUs

* updates for FMIBUild v0.3.1

* updated example deps
  • Loading branch information
ThummeTo authored Aug 9, 2024
1 parent 362e173 commit d1ec513
Show file tree
Hide file tree
Showing 16 changed files with 185 additions and 115 deletions.
8 changes: 3 additions & 5 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
name = "FMIExport"
uuid = "31b88311-cab6-44ed-ba9c-fe5a9abbd67a"
authors = ["TT <tobias.thummerer@informatik.uni-augsburg.de>", "LM <lars.mikelsons@informatik.uni-augsburg.de>"]
version = "0.3.2"
version = "0.4.0"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
EzXML = "8f5d6c58-4d21-5cfd-889c-e3ad7ee6a615"
FMICore = "8af89139-c281-408e-bce2-3005eb87462f"
FMIBase = "900ee838-d029-460e-b485-d98a826ceef2"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[compat]
Dates = "1"
EzXML = "1.1.0"
FMICore = "0.18.0 - 0.20"
FMIBase = "1.0.0"
UUIDs = "1"
julia = "1.6"
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ To keep dependencies nice and clean, the original package [*FMI.jl*](https://git
- [*FMI.jl*](https://github.com/ThummeTo/FMI.jl): High level loading, manipulating, saving or building entire FMUs from scratch
- [*FMIImport.jl*](https://github.com/ThummeTo/FMIImport.jl): Importing FMUs into Julia
- [*FMIExport.jl*](https://github.com/ThummeTo/FMIExport.jl): Exporting stand-alone FMUs from Julia Code
- [*FMIBase.jl*](https://github.com/ThummeTo/FMIBase.jl): Common concepts for import and export of FMUs
- [*FMICore.jl*](https://github.com/ThummeTo/FMICore.jl): C-code wrapper for the FMI-standard
- [*FMISensitivity.jl*](https://github.com/ThummeTo/FMISensitivity.jl): Static and dynamic sensitivities over FMUs
- [*FMIBuild.jl*](https://github.com/ThummeTo/FMIBuild.jl): Compiler/Compilation dependencies for FMIExport.jl
- [*FMIFlux.jl*](https://github.com/ThummeTo/FMIFlux.jl): Machine Learning with FMUs (differentiation over FMUs)
- [*FMIFlux.jl*](https://github.com/ThummeTo/FMIFlux.jl): Machine Learning with FMUs
- [*FMIZoo.jl*](https://github.com/ThummeTo/FMIZoo.jl): A collection of testing and example FMUs

## What Platforms are supported?
Expand Down
2 changes: 1 addition & 1 deletion examples/FMI2/BouncingBall/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ FMIBuild = "226f0e26-6dd6-4589-ada7-1d32f6e1d800"
FMIExport = "31b88311-cab6-44ed-ba9c-fe5a9abbd67a"

[compat]
FMIBuild = "0.2.0"
FMIBuild = "0.3.2"
julia = "1.6"
21 changes: 13 additions & 8 deletions examples/FMI2/BouncingBall/src/BouncingBall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
#

using FMIExport
using FMIExport.FMICore: fmi2True, fmi2False
using FMIExport.FMIBase.FMICore: fmi2True, fmi2False

EPS = 1e-6

FMU_FCT_INIT = function()
m = 1.0 # ball mass
Expand Down Expand Up @@ -34,14 +36,12 @@ FMU_FCT_EVALUATE = function(t, x_c, ẋ_c, x_d, u, p, eventMode)
sticking = x_d[1]
_, a = ẋ_c

eps = 1e-10

if sticking == fmi2True
a = 0.0
else
elseif sticking == fmi2False
if eventMode
if s < r && v < 0.0
s = r + eps # so that indicator is not triggered again
s = r + EPS # so that indicator is not triggered again
v = -v*d

# stop bouncing to prevent high frequency bouncing (and maybe tunneling the floor)
Expand All @@ -50,9 +50,14 @@ FMU_FCT_EVALUATE = function(t, x_c, ẋ_c, x_d, u, p, eventMode)
v = 0.0
end
end
else
# no specials in continuos time mode
end

a = (m * -g) / m # the system's physical equation
a = (m * -g) / m # the system's physical equation (a little longer than necessary)
else
@error "Unknown value for `sticking` == $(sticking)."
return (x_c, ẋ_c, x_d, p)
end

x_c = [s, v]
Expand Down Expand Up @@ -134,8 +139,8 @@ tmpDir = mktempdir(; prefix="fmibuildjl_test_", cleanup=false)
fmu_save_path = joinpath(tmpDir, "BouncingBall.fmu")

fmu = FMIBUILD_CONSTRUCTOR()
using FMIBuild: fmi2Save # <= this must be excluded during export, because FMIBuild cannot execute itself (but it is able to build)
fmi2Save(fmu, fmu_save_path; debug=true) # <= this must be excluded during export, because fmi2Save would start an infinte build loop with itself (debug=true allows debug messages, but is slow during execution!)
using FMIBuild: saveFMU # <= this must be excluded during export, because FMIBuild cannot execute itself (but it is able to build)
saveFMU(fmu, fmu_save_path; debug=true, compress=false) # <= this must be excluded during export, because fmi2Save would start an infinte build loop with itself (debug=true allows debug messages, but is slow during execution!)

### some tests ###
# using FMI
Expand Down
2 changes: 1 addition & 1 deletion examples/FMI2/Manipulation/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ FMIImport = "9fcbc62e-52a0-44e9-a616-1359a0008194"
FMIZoo = "724179cf-c260-40a9-bd27-cccc6fe2f195"

[compat]
FMIBuild = "0.2.0"
FMIBuild = "0.3.2"
julia = "1.6"
14 changes: 7 additions & 7 deletions examples/FMI2/Manipulation/src/Manipulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#

using FMIExport: fmi2SetFctGetReal, fmi2CreateEmbedded
using FMIExport.FMICore: fmi2Real, fmi2Component, fmi2StatusOK, fmi2ValueReference
using FMIExport.FMICore: fmi2CausalityParameter, fmi2VariabilityTunable, fmi2InitialExact
using FMIImport: fmi2Load
using FMIExport.FMIBase.FMICore: fmi2Real, fmi2Component, fmi2StatusOK, fmi2ValueReference
using FMIExport.FMIBase.FMICore: fmi2CausalityParameter, fmi2VariabilityTunable, fmi2InitialExact
using FMIImport: loadFMU
import FMIExport

originalGetReal = nothing # function pointer to the original fmi2GetReal c-function
Expand All @@ -17,7 +17,7 @@ function myGetReal!(c::fmi2Component, vr::Union{Array{fmi2ValueReference}, Ptr{f
global originalGetReal

# first, we do what the original function does
status = FMIExport.FMICore.fmi2GetReal!(originalGetReal, c, vr, nvr, value)
status = FMIExport.FMIBase.FMICore.fmi2GetReal!(originalGetReal, c, vr, nvr, value)

# if we have a pointer to an array, we must interprete it as array to access elements
if isa(value, Ptr{fmi2Real})
Expand All @@ -44,7 +44,7 @@ FMIBUILD_CONSTRUCTOR = function(resPath)
global originalGetReal

# loads an existing FMU inside the FMU
fmu = fmi2Load(joinpath(resPath, "SpringDamperPendulum1D.fmu"))
fmu = loadFMU(joinpath(resPath, "SpringDamperPendulum1D.fmu"))

# create a FMU that embedds the existing FMU
fmu = fmi2CreateEmbedded(fmu)
Expand Down Expand Up @@ -78,8 +78,8 @@ fmu_save_path = joinpath(tmpDir, "Manipulation.fmu")

sourceFMU = FMIZoo.get_model_filename("SpringDamperPendulum1D", "Dymola", "2022x")
fmu = FMIBUILD_CONSTRUCTOR(dirname(sourceFMU))
import FMIBuild:fmi2Save # <= this must be excluded during export, because FMIBuild cannot execute itself (but it is able to build)
fmi2Save(fmu, fmu_save_path; resources=Dict(sourceFMU=>"SpringDamperPendulum1D.fmu")) # <= this must be excluded during export, because fmi2Save would start an infinte build loop with itself
import FMIBuild:saveFMU # <= this must be excluded during export, because FMIBuild cannot execute itself (but it is able to build)
saveFMU(fmu, fmu_save_path; resources=Dict(sourceFMU=>"SpringDamperPendulum1D.fmu")) # <= this must be excluded during export, because fmi2Save would start an infinte build loop with itself

# some tests
# using FMI
Expand Down
2 changes: 1 addition & 1 deletion examples/FMI2/NeuralFMU/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ FMIImport = "9fcbc62e-52a0-44e9-a616-1359a0008194"
FMIZoo = "724179cf-c260-40a9-bd27-cccc6fe2f195"

[compat]
FMIBuild = "0.2.0"
FMIBuild = "0.3.2"
julia = "1.6"
14 changes: 7 additions & 7 deletions examples/FMI2/NeuralFMU/src/NeuralFMU.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ using FMIExport: Dense, Chain
using FMIExport: fmi2SetFctGetDerivatives, fmi2SetFctGetReal, fmi2SetFctSetReal, fmi2SetFctSetTime, fmi2SetFctSetContinuousStates
using FMIExport: fmi2CreateEmbedded
using FMIExport: fmi2AddRealParameter
using FMIExport.FMICore: fmi2Real, fmi2Component, fmi2StatusOK, fmi2ValueReference
using FMIExport.FMICore: fmi2CausalityParameter, fmi2VariabilityTunable, fmi2InitialExact
using FMIImport: fmi2Load
using FMIExport.FMIBase.FMICore: fmi2Real, fmi2Component, fmi2StatusOK, fmi2ValueReference
using FMIExport.FMIBase.FMICore: fmi2CausalityParameter, fmi2VariabilityTunable, fmi2InitialExact
using FMIImport: loadFMU
import FMIExport

fmu = nothing
Expand Down Expand Up @@ -141,7 +141,7 @@ function updateDerivatives(_component::fmi2Component, ndx::Csize_t)

if !DERIVATIVES_VALID
# first, we do what the original function does
status = FMIExport.FMICore.fmi2GetDerivatives!(originalGetDerivatives, _component, DERIVATIVES, ndx)
status = FMIExport.FMIBase.FMICore.fmi2GetDerivatives!(originalGetDerivatives, _component, DERIVATIVES, ndx)

if status != fmi2StatusOK
logError(_component, "fmi2GetDerivatives failed!")
Expand Down Expand Up @@ -305,7 +305,7 @@ FMIBUILD_CONSTRUCTOR = function(resPath)
global fmu, ANN_PARAMETERS

# loads an existing FMU
fmu = fmi2Load(joinpath(resPath, "SpringDamperPendulum1D.fmu"))
fmu = loadFMU(joinpath(resPath, "SpringDamperPendulum1D.fmu"))

# create a FMU that embedds the existing FMU
fmu = fmi2CreateEmbedded(fmu)
Expand Down Expand Up @@ -366,8 +366,8 @@ fmu_save_path = joinpath(tmpDir, "NeuralFMU.fmu")

sourceFMU = FMIZoo.get_model_filename("SpringDamperPendulum1D", "Dymola", "2022x")
fmu = FMIBUILD_CONSTRUCTOR(dirname(sourceFMU))
import FMIBuild:fmi2Save # <= this must be excluded during export, because FMIBuild cannot execute itself (but it is able to build)
fmi2Save(fmu, fmu_save_path; compress=false, debug=true, resources=Dict(sourceFMU=>"SpringDamperPendulum1D.fmu")) # <= this must be excluded during export, because fmi2Save would start an infinte build loop with itself
import FMIBuild:saveFMU # <= this must be excluded during export, because FMIBuild cannot execute itself (but it is able to build)
saveFMU(fmu, fmu_save_path; compress=false, debug=true, resources=Dict(sourceFMU=>"SpringDamperPendulum1D.fmu")) # <= this must be excluded during export, because fmi2Save would start an infinte build loop with itself

### some tests ###
# using FMI
Expand Down
12 changes: 9 additions & 3 deletions src/FMI2_md.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
# Licensed under the MIT license. See LICENSE file in the project root for details.
#

using EzXML
using FMIBase.EzXML
import UUIDs
import Dates

import FMIBase.FMICore: fmi2ModelDescriptionModelExchange, fmi2ModelDescriptionCoSimulation
import FMIBase.FMICore: fmi2RealAttributesExt, fmi2IntegerAttributesExt, fmi2BooleanAttributesExt, fmi2StringAttributesExt, fmi2EnumerationAttributesExt

function fmi2CreateModelDescription()
md = fmi2ModelDescription()
md.guid = UUIDs.uuid1()
Expand Down Expand Up @@ -138,7 +141,10 @@ function fmi2ModelDescriptionAddIntegerDiscreteState(md::fmi2ModelDescription, n
_Integer = fmi2IntegerAttributesExt()
_Integer.start = start

sv = fmi2ModelDescriptionAddModelVariable(md, name; attribute=_Integer, kwargs...)
sv = fmi2ModelDescriptionAddModelVariable(md, name;
attribute=_Integer,
variability=fmi2VariabilityDiscrete,
kwargs...)

push!(md.discreteStateValueReferences, sv.valueReference)
push!(md.stringValueReferences, sv.name => sv.valueReference)
Expand All @@ -147,7 +153,7 @@ function fmi2ModelDescriptionAddIntegerDiscreteState(md::fmi2ModelDescription, n
end

function fmi2ModelDescriptionAddEventIndicator(md::fmi2ModelDescription)
if md.numberOfEventIndicators == nothing
if isnothing(md.numberOfEventIndicators)
md.numberOfEventIndicators = 0
end
md.numberOfEventIndicators += 1
Expand Down
Loading

2 comments on commit d1ec513

@ThummeTo
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/112752

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.0 -m "<description of version>" d1ec513bc4354d49febd60647ec9d9eef2cdacad
git push origin v0.4.0

Please sign in to comment.