From a3fcd4efe98e8cfd49bf9612a7c44737eb4d4e07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20H=C3=B6pfner?= Date: Fri, 13 Sep 2024 10:27:38 +0200 Subject: [PATCH 1/2] parse Event Indicator Dependencies --- src/FMI3/md.jl | 40 +++++----------------------------------- 1 file changed, 5 insertions(+), 35 deletions(-) diff --git a/src/FMI3/md.jl b/src/FMI3/md.jl index 60ac466..1f931db 100644 --- a/src/FMI3/md.jl +++ b/src/FMI3/md.jl @@ -48,6 +48,7 @@ function fmi3LoadModelDescription(pathToModellDescription::String) md.inputValueReferences = Array{fmi3ValueReference}(undef, 0) md.stateValueReferences = Array{fmi3ValueReference}(undef, 0) md.derivativeValueReferences = Array{fmi3ValueReference}(undef, 0) + md.eventIndicatorValueReferences = Array{fmi3ValueReference}(undef, 0) md.intermediateUpdateValueReferences = Array{fmi3ValueReference}(undef, 0) md.numberOfEventIndicators = 0 @@ -415,8 +416,10 @@ function parseModelStructure(md::fmi3ModelDescription, nodes::EzXML.Node) push!(md.modelStructure.initialUnknowns, varDep) elseif node.name == "EventIndicator" md.numberOfEventIndicators += 1 - push!(md.modelStructure.eventIndicators) - # [TODO] parse valueReferences to another array + varDep = parseDependencies(md, node) + push!(md.modelStructure.eventIndicators, varDep) + eIvalueRef = parseNode(node, "valueReference", fmi3ValueReference) + push!(md.eventIndicatorValueReferences, eIvalueRef) elseif node.name == "ContinuousStateDerivative" # find states and derivatives @@ -483,36 +486,3 @@ function parseDependencies(md::fmi3ModelDescription, node::EzXML.Node) return varDep end - -function parseContinuousStateDerivative(md::fmi3ModelDescription, nodes::EzXML.Node) - @assert (nodes.name == "ContinuousStateDerivative") "Wrong element name." - md.modelStructure.derivatives = [] - for node in eachelement(nodes) - if node.name == "InitialUnknown" - if haskey(node, "index") - varDep = parseUnknwon(md, node) - - # find states and derivatives - derSV = md.modelVariables[varDep.index] - derVR = derSV.valueReference - stateVR = md.modelVariables[derSV.derivative].valueReference - - if stateVR ∉ md.stateValueReferences - push!(md.stateValueReferences, stateVR) - end - if derVR ∉ md.derivativeValueReferences - push!(md.derivativeValueReferences, derVR) - end - - push!(md.modelStructure.derivatives, varDep) - else - @warn "Invalid entry for node `Unknown` in `ModelStructure`, missing entry `index`." - end - elseif node.name == "EventIndicator" - md.numberOfEventIndicators += 1 - # TODO parse valueReferences to another array - else - @warn "Unknown entry in `ModelStructure.Derivatives` named `$(node.name)`." - end - end -end From 390079033bd564739015f5d66d62e636c8d79c0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20H=C3=B6pfner?= Date: Fri, 13 Sep 2024 10:46:46 +0200 Subject: [PATCH 2/2] add Tests --- test/FMI3/model_description.jl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/FMI3/model_description.jl b/test/FMI3/model_description.jl index 7885022..23eb7cc 100644 --- a/test/FMI3/model_description.jl +++ b/test/FMI3/model_description.jl @@ -30,6 +30,11 @@ myFMU = loadFMU("BouncingBall", "ModelicaReferenceFMUs", "0.0.30", "3.0") @test getDefaultTolerance(myFMU.modelDescription) === nothing @test getDefaultStepSize(myFMU.modelDescription) === 0.01 +@test myFMU.modelDescription.numberOfEventIndicators == 1 +@test myFMU.modelDescription.eventIndicatorValueReferences == [1] +@test typeof(myFMU.modelDescription.modelStructure.eventIndicators[1]) == fmi3VariableDependency + + info(myFMU) # check if there is an error thrown unloadFMU(myFMU)