Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Event Indicator Parsing #127

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 5 additions & 35 deletions src/FMI3/md.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
5 changes: 5 additions & 0 deletions test/FMI3/model_description.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Loading