From 491c978949027349ef245c88c5d9e028add9c317 Mon Sep 17 00:00:00 2001 From: ThummeTo <83663542+ThummeTo@users.noreply.github.com> Date: Mon, 19 Aug 2024 14:28:09 +0200 Subject: [PATCH] V1.0.3 (#118) * removed dependencies * buf gix for `info` * fixed info --- Project.toml | 4 +- src/FMI2/c.jl | 8 +-- src/info.jl | 108 +++++++++++++++++++-------------- test/FMI2/model_description.jl | 2 + test/FMI3/model_description.jl | 2 + 5 files changed, 72 insertions(+), 52 deletions(-) diff --git a/Project.toml b/Project.toml index 5a8282e..0b39ade 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "FMIImport" uuid = "9fcbc62e-52a0-44e9-a616-1359a0008194" authors = ["TT ", "LM ", "JK "] -version = "1.0.2" +version = "1.0.3" [deps] Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6" @@ -20,4 +20,4 @@ Downloads = "1" FMIBase = "1.0.0" Libdl = "1" RelocatableFolders = "1" -julia = "1.6" \ No newline at end of file +julia = "1.6" diff --git a/src/FMI2/c.jl b/src/FMI2/c.jl index c1932ef..4ca3849 100644 --- a/src/FMI2/c.jl +++ b/src/FMI2/c.jl @@ -143,13 +143,13 @@ end import FMIBase.FMICore: fmi2SetDebugLogging """ - fmi2SetDebugLogging(c::FMU2Component, logginOn::fmi2Boolean, nCategories::Unsigned, categories::Ptr{Nothing}) + fmi2SetDebugLogging(c::FMU2Component, loggingOn::fmi2Boolean, nCategories::Unsigned, categories::Ptr{Nothing}) Control the use of the logging callback function, version independent. # Arguments - `c::FMU2Component`: Argument `c` is a Mutable struct represents an instantiated instance of an FMU in the FMI 2.0.2 Standard. -- `logginOn::fmi2Boolean`: If `loggingOn = fmi2True`, debug logging is enabled for the log categories specified in categories, otherwise it is disabled. Type `fmi2Boolean` is defined as an alias Type for the C-Type Boolean and is to be used with `fmi2True` and `fmi2False`. +- `loggingOn::fmi2Boolean`: If `loggingOn = fmi2True`, debug logging is enabled for the log categories specified in categories, otherwise it is disabled. Type `fmi2Boolean` is defined as an alias Type for the C-Type Boolean and is to be used with `fmi2True` and `fmi2False`. - `nCategories::Unsigned`: Argument `nCategories` defines the length of the argument `categories`. - `categories::Ptr{Nothing}`: @@ -169,9 +169,9 @@ More detailed: - FMISpec2.0.2[p.22]: 2.1.5 Creation, Destruction and Logging of FMU Instances See also [`fmi2SetDebugLogging`](@ref). """ -function FMICore.fmi2SetDebugLogging(c::FMU2Component, logginOn::fmi2Boolean, nCategories::Unsigned, categories::Ptr{Nothing}) +function FMICore.fmi2SetDebugLogging(c::FMU2Component, loggingOn::fmi2Boolean, nCategories::Unsigned, categories::Ptr{Nothing}) - status = fmi2SetDebugLogging(c.fmu.cSetDebugLogging, c.addr, logginOn, nCategories, categories) + status = fmi2SetDebugLogging(c.fmu.cSetDebugLogging, c.addr, loggingOn, nCategories, categories) checkStatus(c, status) return status end diff --git a/src/info.jl b/src/info.jl index aaf3ed7..d53f5e0 100644 --- a/src/info.jl +++ b/src/info.jl @@ -3,6 +3,28 @@ # Licensed under the MIT license. See LICENSE file in the project root for details. # +# Prints value references, but shortens if the number exceeds `max`. +function printValueReferences(fmu, vrs; max=10) + len = length(vrs) + if len <= max + for vr in vrs + println("\t\t$(vr) $(valueReferenceToString(fmu, vr))") + end + else + half = floor(Integer, max)-1 + for vr in vrs[1:half] + println("\t\t$(vr) $(valueReferenceToString(fmu, vr))") + end + println(".") + println(".") + println(".") + for vr in vrs[len-half:end] + println("\t\t$(vr) $(valueReferenceToString(fmu, vr))") + end + end + nothing +end + """ info(fmu) @@ -19,36 +41,33 @@ function info(fmu::FMU2) println("\tModel name:\t\t\t$(getModelName(fmu))") println("\tFMI-Version:\t\t\t$(fmi2GetVersion(fmu))") - println("\tGUID:\t\t\t\t$(fmi2GetGUID(fmu))") + println("\tGUID:\t\t\t\t$(getGUID(fmu))") println("\tGeneration tool:\t\t$(getGenerationTool(fmu))") - println("\tGeneration time:\t\t$(generationDateAndTime(fmu))") + println("\tGeneration time:\t\t$(getGenerationDateAndTime(fmu))") print("\tVar. naming conv.:\t\t") - if fmi2GetVariableNamingConvention(fmu) == fmi2VariableNamingConventionFlat + if getVariableNamingConvention(fmu) == fmi2VariableNamingConventionFlat println("flat") - elseif fmi2GetVariableNamingConvention(fmu) == fmi2VariableNamingConventionStructured + elseif getVariableNamingConvention(fmu) == fmi2VariableNamingConventionStructured println("structured") else println("[unknown]") end - println("\tEvent indicators:\t\t$(fmi2GetNumberOfEventIndicators(fmu))") + println("\tEvent indicators:\t\t$(getNumberOfEventIndicators(fmu))") println("\tInputs:\t\t\t\t$(length(fmu.modelDescription.inputValueReferences))") - for vr in fmu.modelDescription.inputValueReferences - println("\t\t$(vr) $(fmi2ValueReferenceToString(fmu, vr))") - end + printValueReferences(fmu, fmu.modelDescription.inputValueReferences) println("\tOutputs:\t\t\t$(length(fmu.modelDescription.outputValueReferences))") - for vr in fmu.modelDescription.outputValueReferences - println("\t\t$(vr) $(fmi2ValueReferenceToString(fmu, vr))") - end + printValueReferences(fmu, fmu.modelDescription.outputValueReferences) println("\tStates:\t\t\t\t$(length(fmu.modelDescription.stateValueReferences))") - for vr in fmu.modelDescription.stateValueReferences - println("\t\t$(vr) $(fmi2ValueReferenceToString(fmu, vr))") - end + printValueReferences(fmu, fmu.modelDescription.stateValueReferences) - println("\tSupports Co-Simulation:\t\t$(fmi2IsCoSimulation(fmu))") - if fmi2IsCoSimulation(fmu) + println("\tParameters:\t\t\t\t$(length(fmu.modelDescription.parameterValueReferences))") + printValueReferences(fmu, fmu.modelDescription.parameterValueReferences) + + println("\tSupports Co-Simulation:\t\t$(isCoSimulation(fmu))") + if isCoSimulation(fmu) println("\t\tModel identifier:\t$(fmu.modelDescription.coSimulation.modelIdentifier)") println("\t\tGet/Set State:\t\t$(fmu.modelDescription.coSimulation.canGetAndSetFMUstate)") println("\t\tSerialize State:\t$(fmu.modelDescription.coSimulation.canSerializeFMUstate)") @@ -59,8 +78,8 @@ function info(fmu::FMU2) println("\t\tMax order out. der.:\t$(fmu.modelDescription.coSimulation.maxOutputDerivativeOrder)") end - println("\tSupports Model-Exchange:\t$(fmi2IsModelExchange(fmu))") - if fmi2IsModelExchange(fmu) + println("\tSupports Model-Exchange:\t$(isModelExchange(fmu))") + if isModelExchange(fmu) println("\t\tModel identifier:\t$(fmu.modelDescription.modelExchange.modelIdentifier)") println("\t\tGet/Set State:\t\t$(fmu.modelDescription.modelExchange.canGetAndSetFMUstate)") println("\t\tSerialize State:\t$(fmu.modelDescription.modelExchange.canSerializeFMUstate)") @@ -72,41 +91,38 @@ end function info(fmu::FMU3) println("#################### Begin information for FMU ####################") - println("\tModel name:\t\t\t$(fmi3GetModelName(fmu))") + println("\tModel name:\t\t\t$(getModelName(fmu))") println("\tFMI-Version:\t\t\t$(fmi3GetVersion(fmu))") - println("\tInstantiation Token:\t\t\t\t$(fmi3GetInstantiationToken(fmu))") - println("\tGeneration tool:\t\t$(fmi3GetGenerationTool(fmu))") - println("\tGeneration time:\t\t$(fmi3GetGenerationDateAndTime(fmu))") + println("\tInstantiation Token:\t\t\t\t$(getInstantiationToken(fmu))") + println("\tGeneration tool:\t\t$(getGenerationTool(fmu))") + println("\tGeneration time:\t\t$(getGenerationDateAndTime(fmu))") print("\tVar. naming conv.:\t\t") - if fmi3GetVariableNamingConvention(fmu) == fmi3VariableNamingConventionFlat + if getVariableNamingConvention(fmu) == fmi3VariableNamingConventionFlat println("flat") - elseif fmi3GetVariableNamingConvention(fmu) == fmi3VariableNamingConventionStructured + elseif getVariableNamingConvention(fmu) == fmi3VariableNamingConventionStructured println("structured") else println("[unknown]") end - println("\tEvent indicators:\t\t$(fmi3GetNumberOfEventIndicators(fmu))") + println("\tEvent indicators:\t\t$(getNumberOfEventIndicators(fmu))") println("\tInputs:\t\t\t\t$(length(fmu.modelDescription.inputValueReferences))") - for vr in fmu.modelDescription.inputValueReferences - println("\t\t$(vr) $(fmi3ValueReferenceToString(fmu, vr))") - end + printValueReferences(fmu, fmu.modelDescription.inputValueReferences) println("\tOutputs:\t\t\t$(length(fmu.modelDescription.outputValueReferences))") - for vr in fmu.modelDescription.outputValueReferences - println("\t\t$(vr) $(fmi3ValueReferenceToString(fmu, vr))") - end + printValueReferences(fmu, fmu.modelDescription.outputValueReferences) println("\tStates:\t\t\t\t$(length(fmu.modelDescription.stateValueReferences))") - for vr in fmu.modelDescription.stateValueReferences - println("\t\t$(vr) $(fmi3ValueReferenceToString(fmu, vr))") - end + printValueReferences(fmu, fmu.modelDescription.stateValueReferences) + + println("\tParameters:\t\t\t\t$(length(fmu.modelDescription.parameterValueReferences))") + printValueReferences(fmu, fmu.modelDescription.parameterValueReferences) - println("\tSupports Co-Simulation:\t\t$(fmi3IsCoSimulation(fmu))") - if fmi3IsCoSimulation(fmu) + println("\tSupports Co-Simulation:\t\t$(isCoSimulation(fmu))") + if isCoSimulation(fmu) println("\t\tModel identifier:\t$(fmu.modelDescription.coSimulation.modelIdentifier)") - println("\t\tGet/Set State:\t\t$(fmu.modelDescription.coSimulation.canGetAndSetFMUstate)") - println("\t\tSerialize State:\t$(fmu.modelDescription.coSimulation.canSerializeFMUstate)") + println("\t\tGet/Set State:\t\t$(fmu.modelDescription.coSimulation.canGetAndSetFMUState)") + println("\t\tSerialize State:\t$(fmu.modelDescription.coSimulation.canSerializeFMUState)") println("\t\tDir. Derivatives:\t$(fmu.modelDescription.coSimulation.providesDirectionalDerivatives)") println("\t\tAdj. Derivatives:\t$(fmu.modelDescription.coSimulation.providesAdjointDerivatives)") println("\t\tEvent Mode:\t$(fmu.modelDescription.coSimulation.hasEventMode)") @@ -116,20 +132,20 @@ function info(fmu::FMU3) println("\t\tMax order out. der.:\t$(fmu.modelDescription.coSimulation.maxOutputDerivativeOrder)") end - println("\tSupports Model-Exchange:\t$(fmi3IsModelExchange(fmu))") - if fmi3IsModelExchange(fmu) + println("\tSupports Model-Exchange:\t$(isModelExchange(fmu))") + if isModelExchange(fmu) println("\t\tModel identifier:\t$(fmu.modelDescription.modelExchange.modelIdentifier)") - println("\t\tGet/Set State:\t\t$(fmu.modelDescription.modelExchange.canGetAndSetFMUstate)") - println("\t\tSerialize State:\t$(fmu.modelDescription.modelExchange.canSerializeFMUstate)") + println("\t\tGet/Set State:\t\t$(fmu.modelDescription.modelExchange.canGetAndSetFMUState)") + println("\t\tSerialize State:\t$(fmu.modelDescription.modelExchange.canSerializeFMUState)") println("\t\tDir. Derivatives:\t$(fmu.modelDescription.modelExchange.providesDirectionalDerivatives)") println("\t\tAdj. Derivatives:\t$(fmu.modelDescription.modelExchange.providesAdjointDerivatives)") end - println("\tSupports Scheduled-Execution:\t$(fmi3IsScheduledExecution(fmu))") - if fmi3IsScheduledExecution(fmu) + println("\tSupports Scheduled-Execution:\t$(isScheduledExecution(fmu))") + if isScheduledExecution(fmu) println("\t\tModel identifier:\t$(fmu.modelDescription.scheduledExecution.modelIdentifier)") - println("\t\tGet/Set State:\t\t$(fmu.modelDescription.scheduledExecution.canGetAndSetFMUstate)") - println("\t\tSerialize State:\t$(fmu.modelDescription.scheduledExecution.canSerializeFMUstate)") + println("\t\tGet/Set State:\t\t$(fmu.modelDescription.scheduledExecution.canGetAndSetFMUState)") + println("\t\tSerialize State:\t$(fmu.modelDescription.scheduledExecution.canSerializeFMUState)") println("\t\tNeeds Execution Tool:\t$(fmu.modelDescription.scheduledExecution.needsExecutionTool)") println("\t\tInstantiated Once Per Process:\t$(fmu.modelDescription.scheduledExecution.canBeInstantiatedOnlyOncePerProcess)") println("\t\tPer Element Dependencies:\t$(fmu.modelDescription.scheduledExecution.providesPerElementDependencies)") diff --git a/test/FMI2/model_description.jl b/test/FMI2/model_description.jl index 1fc80ca..1cbee24 100644 --- a/test/FMI2/model_description.jl +++ b/test/FMI2/model_description.jl @@ -30,6 +30,8 @@ myFMU = loadFMU("SpringFrictionPendulum1D", ENV["EXPORTINGTOOL"], ENV["EXPORTING @test getDefaultTolerance(myFMU.modelDescription) ≈ 1e-4 @test getDefaultStepSize(myFMU.modelDescription) === nothing +info(myFMU) # check if there is an error thrown + # comfort getters (dictionaries) @test length(getValueReferencesAndNames(myFMU.modelDescription)) == 42 diff --git a/test/FMI3/model_description.jl b/test/FMI3/model_description.jl index e94b3a7..cc37ecf 100644 --- a/test/FMI3/model_description.jl +++ b/test/FMI3/model_description.jl @@ -30,4 +30,6 @@ myFMU = loadFMU("BouncingBall", "ModelicaReferenceFMUs", "0.0.20", "3.0") @test getDefaultTolerance(myFMU.modelDescription) === nothing @test getDefaultStepSize(myFMU.modelDescription) === 0.01 +info(myFMU) # check if there is an error thrown + unloadFMU(myFMU)