Skip to content

Commit

Permalink
v0.18.0 (#48)
Browse files Browse the repository at this point in the history
* initial

* Performance (#47)

* Prevent allocation at fmi2CompletedIntegratorStep

* Set for fast lookup

* resolved minor ToDos

* FMIImport performance, FMIExport compatibility

* performance improvements

* added support for FMISensitivity.jl

* optimized unsense and others

* minor change

* refined unsense

---------

Co-authored-by: CasBex <[email protected]>
  • Loading branch information
ThummeTo and CasBex authored Oct 7, 2023
1 parent b2d8111 commit c4bcada
Show file tree
Hide file tree
Showing 20 changed files with 1,189 additions and 543 deletions.
6 changes: 5 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
name = "FMICore"
uuid = "8af89139-c281-408e-bce2-3005eb87462f"
authors = ["TT <[email protected]>", "LM <[email protected]>", "JK <[email protected]>"]
version = "0.17.3"
version = "0.18.0"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"

[compat]
ChainRulesCore = "1.16.0"
Requires = "1.3.0"
julia = "1.6"
7 changes: 5 additions & 2 deletions src/FMI2/cconst.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ const fmi2ValueReference = Cuint
const fmi2FMUstate = Ptr{Cvoid}
const fmi2Component = Ptr{Cvoid}
const fmi2ComponentEnvironment = Ptr{Cvoid}
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
export fmi2Char, fmi2String, fmi2Boolean, fmi2Real, fmi2Integer, fmi2Byte, fmi2ValueReference, fmi2FMUstate, fmi2Component, fmi2ComponentEnvironment

# wildcards for how a user can pass a fmi2ValueReference
fmi2ValueReferenceFormat = Union{Nothing, String, AbstractArray{String,1}, fmi2ValueReference, AbstractArray{fmi2ValueReference,1}, Int64, AbstractArray{Int64,1}, Symbol}
export fmi2ValueReferenceFormat

"""
Source: FMISpec2.0.2[p.18]: 2.1.3 Status Returned by Functions
Expand Down
92 changes: 46 additions & 46 deletions src/FMI2/cfunc.jl

Large diffs are not rendered by default.

156 changes: 156 additions & 0 deletions src/FMI2/cfunc_unload.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
#
# Copyright (c) 2021 Tobias Thummerer, Lars Mikelsons, Josef Kircher
# Licensed under the MIT license. See LICENSE file in the project root for details.
#

function unload_fmi2GetTypesPlatform()
@assert false "The function `fmi2GetTypesPlatform` is not callable anymore, because the FMU is unloaded!"
str = ""
return pointer(str)
end

function unload_fmi2GetVersion()
@assert false "The function `fmi2GetVersion()` is not callable anymore, because the FMU is unloaded!"
str = ""
return pointer(str)
end

# 2.1.5
function unload_fmi2Instantiate(_instanceName::fmi2String,
fmuType::fmi2Type,
_fmuGUID::fmi2String,
_fmuResourceLocation::fmi2String,
_functions::Ptr{fmi2CallbackFunctions},
visible::fmi2Boolean,
loggingOn::fmi2Boolean)

@assert false "The function `fmi2Instantiate` is not callable anymore, because the FMU is unloaded!"
return C_NULL
end

function unload_fmi2FreeInstance(_component::fmi2Component)
@assert false "The function `fmi2FreeInstance` is not callable anymore, because the FMU is unloaded!"
return nothing
end

function unload_fmi2SetDebugLogging(_component::fmi2Component, loggingOn::fmi2Boolean, nCategories::Csize_t, categories::Ptr{fmi2String})
@assert false "The function `fmi2SetDebugLogging` is not callable anymore, because the FMU is unloaded!"
return fmi2StatusFatal
end

function unload_fmi2SetupExperiment(_component::fmi2Component, toleranceDefined::fmi2Boolean, tolerance::fmi2Real, startTime::fmi2Real, stopTimeDefined::fmi2Boolean, stopTime::fmi2Real)
@assert false "The function `fmi2SetupExperiment` is not callable anymore, because the FMU is unloaded!"
return fmi2StatusFatal
end

function unload_fmi2EnterInitializationMode(_component::fmi2Component)
@assert false "The function `fmi2EnterInitializationMode` is not callable anymore, because the FMU is unloaded!"
return fmi2StatusFatal
end

function unload_fmi2ExitInitializationMode(_component::fmi2Component)
@assert false "The function `fmi2ExitInitializationMod` is not callable anymore, because the FMU is unloaded!"
return fmi2StatusFatal
end

function unload_fmi2Terminate(_component::fmi2Component)
@assert false "The function `fmi2Terminate` is not callable anymore, because the FMU is unloaded!"
return fmi2StatusFatal
end

function unload_fmi2Reset(_component::fmi2Component)
@assert false "The function `fmi2Reset` is not callable anymore, because the FMU is unloaded!"
return fmi2StatusFatal
end

function unload_fmi2GetReal(_component::fmi2Component, _vr::Ptr{fmi2ValueReference}, nvr::Csize_t, _value::Ptr{fmi2Real})
@assert false "The function `fmi2GetReal` is not callable anymore, because the FMU is unloaded!"
return fmi2StatusFatal
end

function unload_fmi2GetInteger(_component::fmi2Component, _vr::Ptr{fmi2ValueReference}, nvr::Csize_t, _value::Ptr{fmi2Integer})
@assert false "The function `fmi2GetInteger` is not callable anymore, because the FMU is unloaded!"
return fmi2StatusFatal
end

function unload_fmi2GetBoolean(_component::fmi2Component, _vr::Ptr{fmi2ValueReference}, nvr::Csize_t, _value::Ptr{fmi2Boolean})
@assert false "The function `fmi2GetBoolean` is not callable anymore, because the FMU is unloaded!"
return fmi2StatusFatal
end

function unload_fmi2GetString(_component::fmi2Component, _vr::Ptr{fmi2ValueReference}, nvr::Csize_t, _value::Ptr{fmi2String})
@assert false "The function `fmi2GetString` is not callable anymore, because the FMU is unloaded!"
return fmi2StatusFatal
end

function unload_fmi2SetReal(_component::fmi2Component, _vr::Ptr{fmi2ValueReference}, nvr::Csize_t, _value::Ptr{fmi2Real})
@assert false "The function `fmi2SetReal` is not callable anymore, because the FMU is unloaded!"
return fmi2StatusFatal
end

function unload_fmi2SetInteger(_component::fmi2Component, _vr::Ptr{fmi2ValueReference}, nvr::Csize_t, _value::Ptr{fmi2Integer})
@assert false "The function `fmi2SetInteger` is not callable anymore, because the FMU is unloaded!"
return fmi2StatusFatal
end

function unload_fmi2SetBoolean(_component::fmi2Component, _vr::Ptr{fmi2ValueReference}, nvr::Csize_t, _value::Ptr{fmi2Boolean})
@assert false "The function `fmi2SetBoolean` is not callable anymore, because the FMU is unloaded!"
return fmi2StatusFatal
end

function unload_fmi2SetString(_component::fmi2Component, _vr::Ptr{fmi2ValueReference}, nvr::Csize_t, _value::Ptr{fmi2String})
@assert false "The function `fmi2SetString` is not callable anymore, because the FMU is unloaded!"
return fmi2StatusFatal
end

function unload_fmi2SetTime(_component::fmi2Component, time::fmi2Real)
@assert false "The function `fmi2SetTime` is not callable anymore, because the FMU is unloaded!"
return fmi2StatusFatal
end

function unload_fmi2SetContinuousStates(_component::fmi2Component, _x::Ptr{fmi2Real}, nx::Csize_t)
@assert false "The function `fmi2SetContinuousStates` is not callable anymore, because the FMU is unloaded!"
return fmi2StatusFatal
end

function unload_fmi2EnterEventMode(_component::fmi2Component)
@assert false "The function `fmi2EnterEventMode` is not callable anymore, because the FMU is unloaded!"
return fmi2StatusFatal
end

function unload_fmi2NewDiscreteStates(_component::fmi2Component, _fmi2eventInfo::Ptr{fmi2EventInfo})
@assert false "The function `fmi2NewDiscreteStates` is not callable anymore, because the FMU is unloaded!"
return fmi2StatusFatal
end

function unload_fmi2EnterContinuousTimeMode(_component::fmi2Component)
@assert false "The function `fmi2EnterContinuousTimeMode` is not callable anymore, because the FMU is unloaded!"
return fmi2StatusFatal
end

function unload_fmi2CompletedIntegratorStep(_component::fmi2Component, noSetFMUStatePriorToCurrentPoint::fmi2Boolean, enterEventMode::Ptr{fmi2Boolean}, terminateSimulation::Ptr{fmi2Boolean})
@assert false "The function `fmi2CompletedIntegratorStep` is not callable anymore, because the FMU is unloaded!"
return fmi2StatusFatal
end

function unload_fmi2GetDerivatives(_component::fmi2Component, _derivatives::Ptr{fmi2Real}, nx::Csize_t)
@assert false "The function `fmi2GetDerivatives` is not callable anymore, because the FMU is unloaded!"
return fmi2StatusFatal
end

function unload_fmi2GetEventIndicators(_component::fmi2Component, _eventIndicators::Ptr{fmi2Real}, ni::Csize_t)
@assert false "The function `fmi2GetEventIndicators` is not callable anymore, because the FMU is unloaded!"
return fmi2StatusFatal
end

function unload_fmi2GetContinuousStates(_component::fmi2Component, _x::Ptr{fmi2Real}, nx::Csize_t)
@assert false "The function `fmi2GetContinuousStates` is not callable anymore, because the FMU is unloaded!"
return fmi2StatusFatal
end

function unload_fmi2GetNominalsOfContinuousStates(_component::fmi2Component, _x_nominal::Ptr{fmi2Real}, nx::Csize_t)
@assert false "The function `fmi2GetNominalsOfContinuousStates` is not callable anymore, because the FMU is unloaded!"
return fmi2StatusFatal
end

# ToDo: Add CS functions!
84 changes: 68 additions & 16 deletions src/FMI2/convert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
#

"""
Formats a fmi2Status/Integer to String.
fmi2StatusToString(status)
Converts a fmi2Status/Integer `status` to String.
"""
function fmi2StatusToString(status::Union{fmi2Status, Integer})
if status == fmi2StatusOK
Expand All @@ -20,13 +23,41 @@ function fmi2StatusToString(status::Union{fmi2Status, Integer})
elseif status == fmi2StatusPending
return "Pending"
else
@assert false "fmi2StatusToString($(status)): Unknown FMU status."
@assert false "fmi2StatusToString($(status)): Unknown FMU status `$(status)`."
end
end
export fmi2StatusToString

"""
fmi2StringToStatus(s)
Converts a String `s` to fmi2Status.
"""
function fmi2StatusToString(s::AbstractString)
if s == "OK"
return fmi2StatusOK
elseif s == "Warning"
return fmi2StatusWarning
elseif s == "Discard"
return fmi2StatusDiscard
elseif s == "Error"
return fmi2StatusError
elseif s == "Fatal"
return fmi2StatusFatal
elseif s == "Pending"
return fmi2StatusPending
else
@assert false "fmi2StatusToString($(s)): Unknown FMU status `$(s)`."
end
end
export fmi2StatusToString

"""
ToDo.
fmi2CausalityToString(c)
Converts a fmi2Causality `c` to String.
"""
function fmi2CausalityToString(c::fmi2Causality)
if c == fmi2CausalityParameter
Expand All @@ -48,7 +79,10 @@ end
export fmi2CausalityToString

"""
ToDo.
fmi2StringToCausality(s)
Converts a String `s` to fmi2Causality.
"""
function fmi2StringToCausality(s::AbstractString)
if s == "parameter"
Expand All @@ -70,7 +104,10 @@ end
export fmi2StringToCausality

"""
ToDo.
fmi2VariabilityToString(c)
Converts a fmi2Variablitiy `c` to fmi2Variability.
"""
function fmi2VariabilityToString(c::fmi2Variability)
if c == fmi2VariabilityConstant
Expand All @@ -90,7 +127,10 @@ end
export fmi2VariabilityToString

"""
ToDo.
fmi2StringToVariability(s)
Converts a String `s` to fmi2Variablitiy.
"""
function fmi2StringToVariability(s::AbstractString)
if s == "constant"
Expand All @@ -110,7 +150,10 @@ end
export fmi2StringToVariability

"""
ToDo.
fmi2InitialToString(c)
Converts a fmi2Initial `c` to String.
"""
function fmi2InitialToString(c::fmi2Initial)
if c == fmi2InitialApprox
Expand All @@ -126,7 +169,10 @@ end
export fmi2InitialToString

"""
ToDo.
fmi2StringToInitial(s)
Converts a String `s` to fmi2Initial.
"""
function fmi2StringToInitial(s::AbstractString)
if s == "approx"
Expand All @@ -142,18 +188,21 @@ end
export fmi2StringToInitial

"""
ToDo.
fmi2DependencyKindToString(dk)
Converts a fmi2DependencyKind `dk` to String.
"""
function fmi2DependencyKindToString(c::fmi2DependencyKind)
if c == fmi2DependencyKindDependent
function fmi2DependencyKindToString(dk::fmi2DependencyKind)
if dk == fmi2DependencyKindDependent
return "dependent"
elseif c == fmi2DependencyKindConstant
elseif dk == fmi2DependencyKindConstant
return "constant"
elseif c == fmi2DependencyKindFixed
elseif dk == fmi2DependencyKindFixed
return "fixed"
elseif c == fmi2DependencyKindTunable
elseif dk == fmi2DependencyKindTunable
return "tunable"
elseif c == fmi2DependencyKindDiscrete
elseif dk == fmi2DependencyKindDiscrete
return "discrete"
else
@assert false "fmi2DependencyKindToString($(c)): Unknown dependency kind."
Expand All @@ -162,7 +211,10 @@ end
export fmi2DependencyKindToString

"""
ToDo.
fmi2StringToDependencyKind(s)
Converts a String `s` to fmi2DependencyKind.
"""
function fmi2StringToDependencyKind(s::AbstractString)
if s == "dependent"
Expand Down
Loading

2 comments on commit c4bcada

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

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.18.0 -m "<description of version>" c4bcadaf0bfd1b2c6849f68aeadc17942ed4a41b
git push origin v0.18.0

Please sign in to comment.