Skip to content

Commit

Permalink
V0.17.2 (#44)
Browse files Browse the repository at this point in the history
* added fields for "automatic" parameter optimzation of FMUs

* FMU parameter sensitivites

* removed type `Nothing` for optim_p

* changed data type

* zero state FMU simulation

* minor adaptions

* progress meter for components
  • Loading branch information
ThummeTo authored Jun 30, 2023
1 parent 7111101 commit 2d1210b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "FMICore"
uuid = "8af89139-c281-408e-bce2-3005eb87462f"
authors = ["TT <[email protected]>", "LM <[email protected]>", "JK <[email protected]>"]
version = "0.17.1"
version = "0.17.2"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
2 changes: 1 addition & 1 deletion src/FMI2/cconst.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const fmi2ValueReference = Cuint
const fmi2FMUstate = Ptr{Cvoid}
const fmi2Component = Ptr{Cvoid}
const fmi2ComponentEnvironment = Ptr{Cvoid}
const fmi2Enum = Array{Array{String}} # TODO: correct it
const fmi2Enum = Array{Array{String}} # TODO: remove, this is not part of the spec!
export fmi2Char, fmi2String, fmi2Boolean, fmi2Real, fmi2Integer, fmi2Byte, fmi2ValueReference, fmi2FMUstate, fmi2Component, fmi2ComponentEnvironment, fmi2Enum

"""
Expand Down
49 changes: 47 additions & 2 deletions src/FMI2/struct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,21 @@ mutable struct FMU2Solution{C} <: FMUSolution where {C}
events::Array{FMU2Event, 1}

evals_∂ẋ_∂x::Integer
evals_∂ẋ_∂u::Integer
evals_∂y_∂x::Integer
evals_∂ẋ_∂u::Integer
evals_∂y_∂u::Integer
evals_∂ẋ_∂t::Integer
evals_∂y_∂t::Integer
evals_∂ẋ_∂p::Integer
evals_∂y_∂p::Integer

evals_fx_inplace::Integer
evals_fx_outofplace::Integer
evals_condition::Integer
evals_affect::Integer
evals_stepcompleted::Integer
evals_timechoice::Integer
evals_savevalues::Integer

function FMU2Solution{C}() where {C}
inst = new{C}()
Expand All @@ -69,11 +79,21 @@ mutable struct FMU2Solution{C} <: FMUSolution where {C}
inst.events = []

inst.evals_∂ẋ_∂x = 0
inst.evals_∂ẋ_∂u = 0
inst.evals_∂y_∂x = 0
inst.evals_∂ẋ_∂u = 0
inst.evals_∂y_∂u = 0
inst.evals_∂ẋ_∂t = 0
inst.evals_∂y_∂t = 0
inst.evals_∂ẋ_∂p = 0
inst.evals_∂y_∂p = 0

inst.evals_fx_inplace = 0
inst.evals_fx_outofplace = 0
inst.evals_condition = 0
inst.evals_affect = 0
inst.evals_stepcompleted = 0
inst.evals_timechoice = 0
inst.evals_savevalues = 0

return inst
end
Expand All @@ -93,6 +113,9 @@ Overload the Base.show() function for custom printing of the FMU2.
function Base.show(io::IO, sol::FMU2Solution)
print(io, "Model name:\n\t$(sol.component.fmu.modelDescription.modelName)\nSuccess:\n\t$(sol.success)\n")

print(io, "f(x)-Evaluations:\n")
print(io, "\tIn-place: $(sol.evals_fx_inplace)\n")
print(io, "\tOut-of-place: $(sol.evals_fx_outofplace)\n")
print(io, "Jacobian-Evaluations:\n")
print(io, "\t∂ẋ_∂x: $(sol.evals_∂ẋ_∂x)\n")
print(io, "\t∂ẋ_∂u: $(sol.evals_∂ẋ_∂u)\n")
Expand All @@ -101,6 +124,12 @@ function Base.show(io::IO, sol::FMU2Solution)
print(io, "Gradient-Evaluations:\n")
print(io, "\t∂ẋ_∂t: $(sol.evals_∂ẋ_∂t)\n")
print(io, "\t∂y_∂t: $(sol.evals_∂y_∂t)\n")
print(io, "Callback-Evaluations:\n")
print(io, "\tCondition (event-indicators): $(sol.evals_condition)\n")
print(io, "\tTime-Choice (event-instances): $(sol.evals_timechoice)\n")
print(io, "\tAffect (event-handling): $(sol.evals_affect)\n")
print(io, "\tSave values: $(sol.evals_savevalues)\n")
print(io, "\tSteps completed: $(sol.evals_stepcompleted)\n")

if sol.states != nothing
print(io, "States [$(length(sol.states))]:\n")
Expand Down Expand Up @@ -191,6 +220,7 @@ mutable struct FMU2Component{F}
eventInfo::Union{fmi2EventInfo, Nothing}

t::fmi2Real # the system time
next_t::fmi2Real # the next system time to be automatically set for the next evaluation
t_offset::fmi2Real # time offset between simulation environment and FMU
x::Union{Array{fmi2Real, 1}, Nothing} # the system states (or sometimes u)
::Union{Array{fmi2Real, 1}, Nothing} # the system state derivative (or sometimes u̇)
Expand All @@ -214,6 +244,8 @@ mutable struct FMU2Component{F}
B::Union{FMUJacobian, Nothing}
C::Union{FMUJacobian, Nothing}
D::Union{FMUJacobian, Nothing}
E::Union{FMUJacobian, Nothing}
F::Union{FMUJacobian, Nothing}

# deprecated
realValues::Dict
Expand All @@ -226,12 +258,14 @@ mutable struct FMU2Component{F}

jacobianUpdate! # function for a custom jacobian constructor (optimization)
skipNextDoStep::Bool # allows skipping the next `fmi2DoStep` like it is not called
progressMeter # progress plot

# constructor
function FMU2Component{F}() where {F}
inst = new()
inst.state = fmi2ComponentStateInstantiated
inst.t = -Inf
inst.next_t = -1.0
inst.t_offset = 0.0
inst.eventInfo = fmi2EventInfo()
inst.problem = nothing
Expand Down Expand Up @@ -263,6 +297,7 @@ mutable struct FMU2Component{F}
# initialize further variables
inst.skipNextDoStep = false
inst.jacobianUpdate! = nothing
inst.progressMeter = nothing

# deprecated
inst.senseFunc = :auto
Expand Down Expand Up @@ -495,8 +530,15 @@ mutable struct FMU2 <: FMU

# execution configuration
executionConfig::FMU2ExecutionConfiguration

# events
hasStateEvents::Union{Bool, Nothing}
hasTimeEvents::Union{Bool, Nothing}
isZeroState::Bool

# parameters that are catched by optimizers (like in FMIFlux.jl)
optim_p_refs::AbstractVector{<:fmi2ValueReference}
optim_p::AbstractVector{<:Real}

# c-libraries
libHandle::Ptr{Nothing}
Expand All @@ -522,6 +564,9 @@ mutable struct FMU2 <: FMU
inst.hasStateEvents = nothing
inst.hasTimeEvents = nothing

inst.optim_p_refs = Vector{fmi2ValueReference}()
inst.optim_p = Vector{fmi2Real}()

inst.executionConfig = FMU2_EXECUTION_CONFIGURATION_NO_RESET
inst.threadComponents = Dict{Integer, Union{FMU2Component, Nothing}}()
inst.cFunctionPtrs = Dict{String, Ptr{Nothing}}()
Expand Down

2 comments on commit 2d1210b

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

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.17.2 -m "<description of version>" 2d1210ba2100743adda0311b0a0549d4dd41b784
git push origin v0.17.2

Please sign in to comment.