diff --git a/Project.toml b/Project.toml index 54345e2..a54ec45 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "FMICore" uuid = "8af89139-c281-408e-bce2-3005eb87462f" authors = ["TT ", "LM ", "JK "] -version = "0.6.3" +version = "0.7.0" [compat] julia = "^1.5" \ No newline at end of file diff --git a/src/FMI2.jl b/src/FMI2.jl index ee5625c..49bfbf6 100644 --- a/src/FMI2.jl +++ b/src/FMI2.jl @@ -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`, ...) @@ -16,6 +17,29 @@ 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. """ @@ -23,6 +47,7 @@ mutable struct FMU2Component compAddr::Ptr{Nothing} fmu # ::FMU2 state::fmi2ComponentState + componentEnvironment::FMU2ComponentEnvironment loggingOn::Bool callbackFunctions::fmi2CallbackFunctions @@ -121,7 +146,6 @@ mutable struct FMU2 <: FMU modelDescription::fmi2ModelDescription type::fmi2Type - callbackFunctions::fmi2CallbackFunctions components::Array # {fmi2Component} # c-functions @@ -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 @@ -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" @@ -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" @@ -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" @@ -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 + diff --git a/src/FMI2_c.jl b/src/FMI2_c.jl index a364f5b..e597d17 100644 --- a/src/FMI2_c.jl +++ b/src/FMI2_c.jl @@ -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 """ @@ -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} @@ -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 @@ -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 @@ -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() diff --git a/src/FMICore.jl b/src/FMICore.jl index d7c5528..40e3a1d 100644 --- a/src/FMICore.jl +++ b/src/FMICore.jl @@ -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