Skip to content

Commit

Permalink
v0.13.2 (#214)
Browse files Browse the repository at this point in the history
* performance improvements

* WIP
  • Loading branch information
ThummeTo authored Feb 3, 2024
1 parent 0bb69e1 commit 0185867
Show file tree
Hide file tree
Showing 20 changed files with 333 additions and 426 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "FMI"
uuid = "14a09403-18e3-468f-ad8a-74f8dda2d9ac"
authors = ["TT <[email protected]>", "LM <[email protected]>", "JK <[email protected]>"]
version = "0.13.1"
version = "0.13.2"

[deps]
DifferentialEquations = "0c46a032-eb83-5123-abaf-570d42b7fbaa"
Expand All @@ -14,7 +14,7 @@ Requires = "ae029012-a4dd-5104-9daa-d747884805df"
ThreadPools = "b189fb0b-2eb5-4ed4-bc0c-d34c51242431"

[compat]
DifferentialEquations = "7.7.0 - 7.11"
DifferentialEquations = "7.7.0 - 7.12"
Downloads = "1"
FMIExport = "0.3.0"
FMIImport = "0.16.0"
Expand Down
44 changes: 22 additions & 22 deletions src/FMI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,34 +127,34 @@ include("FMI3/sim.jl")
include("deprecated.jl")

# from FMI2_plot.jl
function fmiPlot(solution::FMUSolution; kwargs...)
@assert false "fmiPlot(...) needs `Plots` package. Please install `Plots` and do `using Plots` or `import Plots`."
end
function fmiPlot!(fig, solution::FMUSolution; kwargs...)
@assert false "fmiPlot!(...) needs `Plots` package. Please install `Plots` and do `using Plots` or `import Plots`."
end
export fmiPlot, fmiPlot!
# function fmiPlot(solution::FMUSolution; kwargs...)
# @assert false "fmiPlot(...) needs `Plots` package. Please install `Plots` and do `using Plots` or `import Plots`."
# end
# function fmiPlot!(fig, solution::FMUSolution; kwargs...)
# @assert false "fmiPlot!(...) needs `Plots` package. Please install `Plots` and do `using Plots` or `import Plots`."
# end
# export fmiPlot, fmiPlot!

# from FMI2_JLD2.jl
function fmiSaveSolutionJLD2(solution::FMUSolution, filepath::AbstractString; keyword="solution")
@assert false "fmiSave(...) needs `JLD2` package. Please install `JLD2` and do `using JLD2` or `import JLD2`."
end
function fmiLoadSolutionJLD2(path::AbstractString; keyword="solution")
@assert false "fmiLoad(...) needs `JLD2` package. Please install `JLD2` and do `using JLD2` or `import JLD2`."
end
export fmiSaveSolutionJLD2, fmiLoadSolutionJLD2
# function fmiSaveSolutionJLD2(solution::FMUSolution, filepath::AbstractString; keyword="solution")
# @assert false "fmiSave(...) needs `JLD2` package. Please install `JLD2` and do `using JLD2` or `import JLD2`."
# end
# function fmiLoadSolutionJLD2(path::AbstractString; keyword="solution")
# @assert false "fmiLoad(...) needs `JLD2` package. Please install `JLD2` and do `using JLD2` or `import JLD2`."
# end
# export fmiSaveSolutionJLD2, fmiLoadSolutionJLD2

# from CSV.jl
function fmiSaveSolutionCSV(solution::FMUSolution, filepath::AbstractString)
@assert false "fmiSave(...) needs `CSV` and `DataFrames` package. Please install `CSV` and `DataFrames` and do `using CSV, DataFrames` or `import CSV, DataFrames`."
end
export fmiSaveSolutionCSV
# function fmiSaveSolutionCSV(solution::FMUSolution, filepath::AbstractString)
# @assert false "fmiSave(...) needs `CSV` and `DataFrames` package. Please install `CSV` and `DataFrames` and do `using CSV, DataFrames` or `import CSV, DataFrames`."
# end
# export fmiSaveSolutionCSV

# from MAT.jl
function fmiSaveSolutionMAT(solution::FMUSolution, filepath::AbstractString)
@assert false "fmiSave(...) needs `MAT` package. Please install `MAT` and do `using MAT` or `import MAT`."
end
export fmiSaveSolutionMAT
# function fmiSaveSolutionMAT(solution::FMUSolution, filepath::AbstractString)
# @assert false "fmiSave(...) needs `MAT` package. Please install `MAT` and do `using MAT` or `import MAT`."
# end
# export fmiSaveSolutionMAT

# from FMI3_plot.jl
# function fmiPlot(solution::FMU3Solution; kwargs...)
Expand Down
2 changes: 1 addition & 1 deletion src/FMI2/sim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ function saveEventIndicators(c::FMU2Component, recordEventIndicators, x, t, inte
c.solution.evals_saveeventindicators += 1

out = zeros(fmi2Real, c.fmu.modelDescription.numberOfEventIndicators)
condition!(c, out, x, t, inputFunction)
indicators!(c, out, x, t, inputFunction)

# ToDo: Replace by inplace statement!
return (out[recordEventIndicators]...,)
Expand Down
1 change: 1 addition & 0 deletions src/extensions/CSV.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ function fmiSaveSolutionCSV(solution::FMUSolution, filepath::AbstractString)
end
CSV.write(filepath, df)
end
export fmiSaveSolutionCSV
4 changes: 3 additions & 1 deletion src/extensions/JLD2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ See also [`fmiSaveSolutionCSV`](@ref), [`fmiSaveSolutionMAT`](@ref), [`fmiLoadSo
function fmiSaveSolutionJLD2(solution::FMUSolution, filepath::AbstractString; keyword="solution")
return JLD2.save(filepath, Dict(keyword=>solution))
end
export fmiSaveSolutionJLD2

"""
fmiLoadSolutionJLD2(filepath::AbstractString; keyword="solution")
Expand All @@ -27,4 +28,5 @@ See also [`fmiSaveSolutionCSV`](@ref), [`fmiSaveSolutionMAT`](@ref), [`fmiSaveSo
"""
function fmiLoadSolutionJLD2(filepath::AbstractString; keyword="solution")
return JLD2.load(filepath, keyword)
end
end
export fmiLoadSolutionJLD2
3 changes: 2 additions & 1 deletion src/extensions/MAT.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ function fmiSaveSolutionMAT(solution::FMUSolution, filepath::AbstractString)
end

MAT.close(file)
end
end
export fmiSaveSolutionMAT
2 changes: 2 additions & 0 deletions src/extensions/Plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function fmiPlot(solution::FMUSolution; kwargs...)
fmiPlot!(fig, solution; kwargs...)
return fig
end
export fmiPlot

"""
fmiPlot!(fig::Plots.Plot, solution::FMUSolution;
Expand Down Expand Up @@ -209,6 +210,7 @@ function fmiPlot!(fig::Plots.Plot, solution::FMUSolution;

return fig
end
export fmiPlot!

"""
Plots.plot(solution::FMUSolution; kwargs...)
Expand Down
42 changes: 7 additions & 35 deletions test/FMI2/cs_me.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,9 @@
t_start = 0.0
t_stop = 1.0

myFMU = fmiLoad("SpringPendulum1D", ENV["EXPORTINGTOOL"], ENV["EXPORTINGVERSION"])
@test fmiIsCoSimulation(myFMU)
@test fmiIsModelExchange(myFMU)

comp = fmiInstantiate!(myFMU; loggingOn=false)
@test comp != 0
# choose FMU or FMUComponent
fmuStruct = nothing
envFMUSTRUCT = ENV["FMUSTRUCT"]
if envFMUSTRUCT == "FMU"
fmuStruct = myFMU
elseif envFMUSTRUCT == "FMUCOMPONENT"
fmuStruct = comp
end
@assert fmuStruct !== nothing "Unknown fmuStruct, environment variable `FMUSTRUCT` = `$envFMUSTRUCT`"
###

fmuStruct, myFMU = getFMUStruct("SpringPendulum1D")

sol = fmiSimulateCS(fmuStruct, (t_start, t_stop))
@test sol.success
Expand All @@ -28,34 +16,18 @@ sol = fmiSimulateME(fmuStruct, (t_start, t_stop); solver=FBDF(autodiff=false))

fmiUnload(myFMU)

###

fmuStruct, myFMU = getFMUStruct("SpringPendulum1D"; type=:ME)

myFMU = fmiLoad("SpringPendulum1D", ENV["EXPORTINGTOOL"], ENV["EXPORTINGVERSION"]; type=:ME)
@test myFMU.type == FMI.fmi2TypeModelExchange
comp = fmiInstantiate!(myFMU; loggingOn=false)
@test comp.type == FMI.fmi2TypeModelExchange
fmuStruct = nothing
if envFMUSTRUCT == "FMU"
fmuStruct = myFMU
elseif envFMUSTRUCT == "FMUCOMPONENT"
fmuStruct = comp
end
sol = fmiSimulate(fmuStruct, (t_start, t_stop); solver=FBDF(autodiff=false))
@test sol.success
fmiUnload(myFMU)

###

fmuStruct, myFMU = getFMUStruct("SpringPendulum1D"; type=:CS)

myFMU = fmiLoad("SpringPendulum1D", ENV["EXPORTINGTOOL"], ENV["EXPORTINGVERSION"]; type=:CS)
@test myFMU.type == FMI.fmi2TypeCoSimulation
comp = fmiInstantiate!(myFMU; loggingOn=false)
@test comp.type == FMI.fmi2TypeCoSimulation
fmuStruct = nothing
if envFMUSTRUCT == "FMU"
fmuStruct = myFMU
elseif envFMUSTRUCT == "FMUCOMPONENT"
fmuStruct = comp
end
sol = fmiSimulate(fmuStruct, (t_start, t_stop))
@test sol.success
fmiUnload(myFMU)
53 changes: 26 additions & 27 deletions test/FMI2/exec_config.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,27 @@ using FMI.FMIImport
t_start = 0.0
t_stop = 1.0

myFMU = fmiLoad("SpringPendulum1D", ENV["EXPORTINGTOOL"], ENV["EXPORTINGVERSION"])

comp = fmiInstantiate!(myFMU; loggingOn=false, type=fmi2TypeCoSimulation)
@test comp != 0
# choose FMU or FMUComponent
fmuStruct = nothing
envFMUSTRUCT = ENV["FMUSTRUCT"]
if envFMUSTRUCT == "FMU"
fmuStruct = myFMU
elseif envFMUSTRUCT == "FMUCOMPONENT"
fmuStruct = comp
end
@assert fmuStruct !== nothing "Unknown fmuStruct, environment variable `FMUSTRUCT` = `$envFMUSTRUCT`"
fmuStruct = Dict{Symbol, Union{FMU2, FMU2Component}}()
myFMU = Dict{Symbol, FMU2}()

fmuStruct[:ME], myFMU[:ME] = getFMUStruct("SpringPendulum1D"; type=:ME)
fmuStruct[:CS], myFMU[:CS] = getFMUStruct("SpringPendulum1D"; type=:CS)

for execConf in (FMU2_EXECUTION_CONFIGURATION_NO_FREEING, FMU2_EXECUTION_CONFIGURATION_RESET, FMU2_EXECUTION_CONFIGURATION_NO_RESET) # ToDo: Add `FMU2_EXECUTION_CONFIGURATION_NOTHING`
for mode in (:CS, :ME)
global fmuStruct
global fmuStruct, myFMU

@info "\t$(mode) | $(execConf)"

myFMU.executionConfig = execConf
myFMU[mode].executionConfig = execConf

# sim test
numInst = length(myFMU.components)
numInst = length(myFMU[mode].components)

if mode == :CS
fmiSimulateCS(fmuStruct, (t_start, t_stop))
fmiSimulateCS(fmuStruct[mode], (t_start, t_stop))
elseif mode == :ME
fmiSimulateME(fmuStruct, (t_start, t_stop))
fmiSimulateME(fmuStruct[mode], (t_start, t_stop))
else
@assert false "Unknown mode `$(mode)`."
end
Expand All @@ -47,26 +40,32 @@ for execConf in (FMU2_EXECUTION_CONFIGURATION_NO_FREEING, FMU2_EXECUTION_CONFIGU
numInst -= 1
end

@test length(myFMU.components) == numInst
@test length(myFMU[mode].components) == numInst

othermode = (mode == :CS ? :ME : :CS)

# prepare next run start
if envFMUSTRUCT == "FMU"
if isa(fmuStruct[mode], FMU2)
if !execConf.freeInstance
fmi2FreeInstance!(myFMU)
end
fmi2Instantiate!(myFMU; type=(mode==:CS ? fmi2TypeModelExchange : fmi2TypeCoSimulation))
fmi2FreeInstance!(myFMU[mode])
end

fmi2Instantiate!(myFMU[othermode]; type=(othermode==:ME ? fmi2TypeModelExchange : fmi2TypeCoSimulation))

elseif envFMUSTRUCT == "FMUCOMPONENT"
elseif isa(fmuStruct[mode], FMU2Component)
if !execConf.freeInstance
fmi2FreeInstance!(fmuStruct)
fmi2FreeInstance!(fmuStruct[mode])
end
fmuStruct = fmi2Instantiate!(myFMU; type=(mode==:CS ? fmi2TypeModelExchange : fmi2TypeCoSimulation))
fmuStruct[othermode] = fmi2Instantiate!(myFMU[othermode]; type=(othermode==:ME ? fmi2TypeModelExchange : fmi2TypeCoSimulation))

else
@assert false "Unknwon fmuStruct type `$(typeof(fmuStruct[mode]))`"
end

# prepare next run end

end
end

fmiUnload(myFMU)
fmiUnload(myFMU[:ME])
fmiUnload(myFMU[:CS])
17 changes: 5 additions & 12 deletions test/FMI2/getter_setter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,12 @@
# Prepare FMU #
###############

myFMU = fmiLoad("IO", ENV["EXPORTINGTOOL"], ENV["EXPORTINGVERSION"]; type=:CS)
comp = fmiInstantiate!(myFMU; loggingOn=false)
@test comp != 0

# choose FMU or FMUComponent
fmuStruct = nothing
envFMUSTRUCT = ENV["FMUSTRUCT"]
if envFMUSTRUCT == "FMU"
fmuStruct = myFMU
elseif envFMUSTRUCT == "FMUCOMPONENT"
fmuStruct = comp
fmuStruct, myFMU = getFMUStruct("IO"; type=:CS)

if isa(fmuStruct, FMU2)
# [Note] no instance allocated at this point
fmi2Instantiate!(fmuStruct)
end
@assert fmuStruct != nothing "Unknown fmuStruct, environment variable `FMUSTRUCT` = `$envFMUSTRUCT`"

@test fmiSetupExperiment(fmuStruct, 0.0) == 0

Expand Down
2 changes: 1 addition & 1 deletion test/FMI2/load_save.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ t_start = 0.0
t_stop = 8.0

# load the FMU container
myFMU = fmiLoad("SpringFrictionPendulum1D", ENV["EXPORTINGTOOL"], ENV["EXPORTINGVERSION"])
fmuStruct, myFMU = getFMUStruct("SpringFrictionPendulum1D")

recordValues = ["mass.s", "mass.v"]
solutionME = fmiSimulateME(myFMU, (t_start, t_stop); recordValues=recordValues, solver=FBDF(autodiff=false))
Expand Down
Loading

2 comments on commit 0185867

@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/100205

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.13.2 -m "<description of version>" 0185867749319df2ff02bf0b70acedd4854a8c76
git push origin v0.13.2

Please sign in to comment.