Skip to content

Commit

Permalink
0.7.0 (#7)
Browse files Browse the repository at this point in the history
* bug-fix

* Optimized modeldescription parsing FMI2

* Disable FMU output
  • Loading branch information
ThummeTo authored Mar 18, 2022
1 parent f69f678 commit f20f31b
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 54 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.6.3"
version = "0.7.0"

[compat]
julia = "^1.5"
66 changes: 61 additions & 5 deletions src/FMI2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

# What is included in this file:
# - the `fmi2ComponentState`-enum which mirrors the internal FMU state (state-machine, not the system state)
# - the `FMU2ComponentEnvironment`-struct
# - the `FMU2Component`-struct
# - the `FMU2`-struct
# - string/enum-converters for FMI-attribute-structs (e.g. `fmi2StatusToString`, ...)
Expand All @@ -16,13 +17,37 @@
fmi2ComponentStateModelInitialized
end

"""
ToDo.
"""
mutable struct FMU2ComponentEnvironment
logStatusOK::Bool
logStatusWarning::Bool
logStatusDiscard::Bool
logStatusError::Bool
logStatusFatal::Bool
logStatusPending::Bool

function FMU2ComponentEnvironment()
inst = new()
inst.logStatusOK = true
inst.logStatusWarning = true
inst.logStatusDiscard = true
inst.logStatusError = true
inst.logStatusFatal = true
inst.logStatusPending = true
return inst
end
end

"""
The mutable struct represents an instantiated instance of an FMU in the FMI 2.0.2 Standard.
"""
mutable struct FMU2Component
compAddr::Ptr{Nothing}
fmu # ::FMU2
state::fmi2ComponentState
componentEnvironment::FMU2ComponentEnvironment

loggingOn::Bool
callbackFunctions::fmi2CallbackFunctions
Expand Down Expand Up @@ -121,7 +146,6 @@ mutable struct FMU2 <: FMU
modelDescription::fmi2ModelDescription

type::fmi2Type
callbackFunctions::fmi2CallbackFunctions
components::Array # {fmi2Component}

# c-functions
Expand Down Expand Up @@ -184,7 +208,7 @@ mutable struct FMU2 <: FMU
callbackLibHandle::Ptr{Nothing}

# START: experimental section (to FMIFlux.jl)
dependencies::Matrix{fmi2DependencyKind}
dependencies::Matrix{Union{fmi2DependencyKind, Nothing}}

# END: experimental section

Expand Down Expand Up @@ -257,7 +281,7 @@ function fmi2CausalityToString(c::fmi2Causality)
end
end

function fmi2StringToCausality(s::String)
function fmi2StringToCausality(s::AbstractString)
if s == "parameter"
return fmi2CausalityParameter
elseif s == "calculatedParameter"
Expand Down Expand Up @@ -291,7 +315,7 @@ function fmi2VariabilityToString(c::fmi2Variability)
end
end

function fmi2StringToVariability(s::String)
function fmi2StringToVariability(s::AbstractString)
if s == "constant"
return fmi2VariabilityConstant
elseif s == "fixed"
Expand Down Expand Up @@ -319,7 +343,7 @@ function fmi2InitialToString(c::fmi2Initial)
end
end

function fmi2StringToInitial(s::String)
function fmi2StringToInitial(s::AbstractString)
if s == "approx"
return fmi2InitialApprox
elseif s == "exact"
Expand All @@ -331,3 +355,35 @@ function fmi2StringToInitial(s::String)
end
end

function fmi2DependencyKindToString(c::fmi2DependencyKind)
if c == fmi2DependencyKindDependent
return "dependent"
elseif c == fmi2DependencyKindConstant
return "constant"
elseif c == fmi2DependencyKindFixed
return "fixed"
elseif c == fmi2DependencyKindTunable
return "tunable"
elseif c == fmi2DependencyKindDiscrete
return "discrete"
else
@assert false "fmi2DependencyKindToString(...): Unknown dependency kind."
end
end

function fmi2StringToDependencyKind(s::AbstractString)
if s == "dependent"
return fmi2DependencyKindDependent
elseif s == "exact"
return fmi2DependencyKindConstant
elseif s == "fixed"
return fmi2DependencyKindFixed
elseif s == "tunable"
return fmi2DependencyKindTunable
elseif s == "discrete"
return fmi2DependencyKindDiscrete
else
@assert false "fmi2StringToDependencyKind($(s)): Unknown dependency kind."
end
end

118 changes: 71 additions & 47 deletions src/FMI2_c.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,79 +150,105 @@ const fmi2Type = Cuint
const fmi2TypeModelExchange = Cuint(0)
const fmi2TypeCoSimulation = Cuint(1)

"""
Source: FMISpec2.0.2[p.40]: 2.2.3 Definition of Types (TypeDefinitions)
FMISpec2.0.2[p.56]: 2.2.7 Definition of Model Variables (ModelVariables)
# ToDo: Explanation.
"""
mutable struct fmi2DatatypeVariable
# Custom helper, not part of the FMI-Spec.
mutable struct fmi2ModelDescriptionReal
# mandatory
datatype::Union{Nothing, Type{fmi2String}, Type{fmi2Real}, Type{fmi2Integer}, Type{fmi2Boolean}, Type{fmi2Enum}}
declaredType::String

# Optional
start::Union{fmi2Integer, fmi2Real, fmi2Boolean, String, Nothing}
min::Union{fmi2Integer, fmi2Real, Nothing}
max::Union{fmi2Integer, fmi2Real, Nothing}
# (nothing)

# optional
declaredType::Union{String, Nothing}
quantity::Union{String, Nothing}
unit::Union{String, Nothing}
displayUnit::Union{String, Nothing}
relativeQuantity::Union{fmi2Boolean, Nothing}
nominal::Union{fmi2Real, Nothing}
unbounded::Union{fmi2Boolean, Nothing}
derivative::Union{Unsigned, Nothing}
reinit::Union{fmi2Boolean, Nothing}

# Constructor
fmi2DatatypeVariable() = new()
end

# Custom helper, not part of the FMI-Spec.
mutable struct fmi2ModelDescriptionReal
# optional
start::Union{String, Nothing}
relativeQuantity::Union{Bool, Nothing}
min::Union{Real, Nothing}
max::Union{Real, Nothing}
nominal::Union{Real, Nothing}
unbounded::Union{Bool, Nothing}
start::Union{Real, Nothing}
derivative::Union{UInt, Nothing}

# constructor
fmi2ModelDescriptionReal() = new()
function fmi2ModelDescriptionReal()
inst = new()

inst.start = nothing
inst.derivative = nothing
inst.quantity = nothing
inst.unit = nothing
inst.displayUnit = nothing
inst.relativeQuantity = nothing
inst.min = nothing
inst.max = nothing
inst.nominal = nothing
inst.unbounded = nothing
inst.start = nothing
inst.derivative = nothing

return inst
end
end

# Custom helper, not part of the FMI-Spec.
mutable struct fmi2ModelDescriptionInteger
# optional
start::Union{String, Nothing}
start::Union{fmi2Integer, Nothing}
declaredType::Union{String, Nothing}
# ToDo: remaining attributes

# constructor
fmi2ModelDescriptionInteger() = new()
function fmi2ModelDescriptionInteger()
inst = new()
inst.start = nothing
return inst
end
end

# Custom helper, not part of the FMI-Spec.
mutable struct fmi2ModelDescriptionBoolean
# optional
start::Union{String, Nothing}
start::Union{fmi2Boolean, Nothing}
declaredType::Union{String, Nothing}
# ToDo: remaining attributes

# constructor
fmi2ModelDescriptionBoolean() = new()
function fmi2ModelDescriptionBoolean()
inst = new()
inst.start = nothing
return inst
end
end

# Custom helper, not part of the FMI-Spec.
mutable struct fmi2ModelDescriptionString
# optional
start::Union{String, Nothing}
declaredType::Union{String, Nothing}
# ToDo: remaining attributes

# constructor
fmi2ModelDescriptionString() = new()
function fmi2ModelDescriptionString()
inst = new()
inst.start = nothing
return inst
end
end

# Custom helper, not part of the FMI-Spec.
mutable struct fmi2ModelDescriptionEnumeration
# optional
start::Union{String, Nothing}
# mandatory
declaredType::Union{String, Nothing}

# optional
start::Union{fmi2Enum, Nothing}
# ToDo: remaining attributes

# constructor
fmi2ModelDescriptionEnumeration() = new()
function fmi2ModelDescriptionEnumeration()
inst = new()
inst.start = nothing
return inst
end
end

"""
Expand All @@ -234,8 +260,7 @@ mutable struct fmi2ScalarVariable
# attributes (mandatory)
name::String
valueReference::fmi2ValueReference
datatype::fmi2DatatypeVariable


# attributes (optional)
description::Union{String, Nothing}
causality::Union{fmi2Causality, Nothing}
Expand All @@ -255,12 +280,11 @@ mutable struct fmi2ScalarVariable
inst = new()
inst.name = name
inst.valueReference = valueReference
inst.datatype = fmi2DatatypeVariable()
inst.description = ""
inst.causality = fmi2CausalityLocal
inst.variability = fmi2VariabilityContinuous
inst.initial = fmi2InitialCalculated
inst.canHandleMultipleSetPerTimeInstant = fmi2False
inst.description = nothing # ""
inst.causality = nothing # fmi2CausalityLocal
inst.variability = nothing # fmi2VariabilityContinuous
inst.initial = nothing # fmi2InitialCalculated
inst.canHandleMultipleSetPerTimeInstant = nothing
inst.annotations = nothing

inst._Real = nothing
Expand Down Expand Up @@ -337,7 +361,7 @@ const fmi2DependencyKindDependent = Cuint(0)
const fmi2DependencyKindConstant = Cuint(1)
const fmi2DependencyKindFixed = Cuint(2)
const fmi2DependencyKindTunable = Cuint(3)
const fmi2DependencyKindUnknown = Cuint(4)
const fmi2DependencyKindDiscrete = Cuint(4)

# Custom helper, not part of the FMI-Spec.
const fmi2VariableNamingConvention = Cuint
Expand Down Expand Up @@ -505,7 +529,7 @@ mutable struct fmi2ModelDescription
enumerations::fmi2Enum

# additional fields (non-FMI-specific)
valueReferenceIndicies::Dict{Integer,Integer}
valueReferenceIndicies::Dict{UInt, UInt}

# Constructor for uninitialized struct
function fmi2ModelDescription()
Expand Down
3 changes: 2 additions & 1 deletion src/FMICore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ include("FMI3.jl")
export FMU

# FMI2.jl
export FMU2, FMU2Component
export FMU2, FMU2Component, FMU2ComponentEnvironment
export fmi2StatusToString
export fmi2CausalityToString, fmi2StringToCausality
export fmi2VariabilityToString, fmi2StringToVariability
export fmi2InitialToString, fmi2StringToInitial
export fmi2DependencyKindToString, fmi2StringToDependencyKind

# FMI2_c.jl

Expand Down

2 comments on commit f20f31b

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

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

Please sign in to comment.