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

fixing MD parsing #132

Merged
merged 4 commits into from
Jan 31, 2025
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
4 changes: 2 additions & 2 deletions .github/workflows/TestLTS.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test v1.6 (LTS)
name: Test (LTS)

on:
workflow_dispatch:
Expand All @@ -18,7 +18,7 @@ jobs:
strategy:
fail-fast: false
matrix:
julia-version: ['1.6']
julia-version: ['lts']
julia-arch: [x64]
os: [ubuntu-latest, windows-latest]
experimental: [false]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/TestLatest.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test v1 (latest)
name: Test (latest)

on:
workflow_dispatch:
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "FMIImport"
uuid = "9fcbc62e-52a0-44e9-a616-1359a0008194"
authors = ["TT <[email protected]>", "LM <[email protected]>", "JK <[email protected]>"]
version = "1.0.8"
version = "1.0.9"

[deps]
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
Expand Down
4 changes: 2 additions & 2 deletions src/FMI2/md.jl
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ function parseUnknown(md::fmi2ModelDescription, node::EzXML.Node)
if length(dependenciesSplit) > 0
varDep.dependencies = collect(parse(UInt, e) for e in dependenciesSplit)
end
else
else
varDep.dependencies = UInt[]
end
end
Expand All @@ -421,7 +421,7 @@ function parseUnknown(md::fmi2ModelDescription, node::EzXML.Node)
stringToDependencyKind(md, e) for e in dependenciesKindSplit
)
end
else
else
varDep.dependenciesKind = fmi2DependencyKind[]
end
end
Expand Down
179 changes: 111 additions & 68 deletions src/FMI3/md.jl
Original file line number Diff line number Diff line change
Expand Up @@ -288,17 +288,21 @@ function parseModelVariables(md::fmi3ModelDescription, nodes::EzXML.Node)
modelVariables[index].clocks =
parseArrayValueReferences(md, parseNode(node, "clocks", String))

if typename ∉ ("Clock", "String")
modelVariables[index].intermediateUpdate =
parseNode(node, "intermediateUpdate", Bool)
else
@warn "Unsupported typename `$(typename)` for modelVariable attribute `intermediateUpdate`."
if haskey(node, "intermediateUpdate")
if typename ∉ ("Clock", "String")
modelVariables[index].intermediateUpdate =
parseNode(node, "intermediateUpdate", Bool)
else
@warn "Unsupported typename `$(typename)` for modelVariable attribute `intermediateUpdate`."
end
end

if typename ∉ ("Clock", "String")
modelVariables[index].previous = parseNode(node, "previous", Bool)
else
@warn "Unsupported typename `$(typename)` for modelVariable attribute `previous`."
if haskey(node, "previous")
if typename ∉ ("Clock", "String")
modelVariables[index].previous = parseNode(node, "previous", Bool)
else
@warn "Unsupported typename `$(typename)` for modelVariable attribute `previous`."
end
end

if haskey(node, "initial")
Expand All @@ -310,87 +314,126 @@ function parseModelVariables(md::fmi3ModelDescription, nodes::EzXML.Node)
end
end

if typename ∉ ("Clock", "String", "Binary", "Boolean")
modelVariables[index].quantity = parseNode(node, "quantity", String)
else
@warn "Unsupported typename `$(typename)` for modelVariable attribute `quantity`."
if haskey(node, "quantity")
if typename ∉ ("Clock", "String", "Binary", "Boolean")
modelVariables[index].quantity = parseNode(node, "quantity", String)
else
@warn "Unsupported typename `$(typename)` for modelVariable attribute `quantity`."
end
end

if typename == "Float64" || typename == "Float32"
modelVariables[index].unit = parseNode(node, "unit", String)
modelVariables[index].displayUnit = parseNode(node, "displayUnit", String)
if haskey(node, "unit")
if typename == "Float64" || typename == "Float32"
modelVariables[index].unit = parseNode(node, "unit", String)
modelVariables[index].displayUnit = parseNode(node, "displayUnit", String)
else
@warn "Unsupported typename `$(typename)` for modelVariable attribute `unit`."
end
end

if typename != "String"
modelVariables[index].declaredType = parseNode(node, "declaredType", String)
else
@warn "Unsupported typename `$(typename)` for modelVariable attribute `declaredType`."
if haskey(node, "declaredType")
if typename != "String"
modelVariables[index].declaredType = parseNode(node, "declaredType", String)
else
@warn "Unsupported typename `$(typename)` for modelVariable attribute `declaredType`."
end
end

if typename ∉ ("Clock", "String", "Binary", "Boolean")
modelVariables[index].min =
parseNode(node, "min", stringToDataType(md, typename))
else
@warn "Unsupported typename `$(typename)` for modelVariable attribute `min`."
if haskey(node, "min")
if typename ∉ ("Clock", "String", "Binary", "Boolean")
modelVariables[index].min =
parseNode(node, "min", stringToDataType(md, typename))
else
@warn "Unsupported typename `$(typename)` for modelVariable attribute `min`."
end
end

if typename ∉ ("Clock", "String", "Binary", "Boolean")
modelVariables[index].max =
parseNode(node, "max", stringToDataType(md, typename))
else
@warn "Unsupported typename `$(typename)` for modelVariable attribute `max`."
if haskey(node, "max")
if typename ∉ ("Clock", "String", "Binary", "Boolean")
modelVariables[index].max =
parseNode(node, "max", stringToDataType(md, typename))
else
@warn "Unsupported typename `$(typename)` for modelVariable attribute `max`."
end
end

if typename == "Float64" || typename == "Float32"
modelVariables[index].nominal =
parseNode(node, "nominal", stringToDataType(md, typename))
modelVariables[index].unbounded =
parseNode(node, "unbounded", stringToDataType(md, typename))
if haskey(node, "nominal")
if typename == "Float64" || typename == "Float32"
modelVariables[index].nominal =
parseNode(node, "nominal", stringToDataType(md, typename))
else
@warn "Unsupported typename `$(typename)` for modelVariable attribute `nominal`."
end
end

if typename ∉ ("Binary", "Clock")
if !isnothing(node.firstelement) && node.firstelement.name == "Dimension"
substrings = split(node["start"], " ")
if haskey(node, "unbounded")
if typename == "Float64" || typename == "Float32"
modelVariables[index].unbounded =
parseNode(node, "unbounded", stringToDataType(md, typename))
else
@warn "Unsupported typename `$(typename)` for modelVariable attribute `unbounded`."
end
end

T = stringToDataType(md, typename)
modelVariables[index].start = Array{T}(undef, 0)
for string in substrings
push!(modelVariables[index].start, parseType(string, T))
if haskey(node, "start")
if typename ∈ ("Binary", "Clock")
@warn "Unsupported typename `$(typename)` for modelVariable attribute `start`."
elseif typename == "Enum"
for i = 1:length(md.enumerations)
if modelVariables[index].declaredType == md.enumerations[i][1] # identify the enum by the name
modelVariables[index].start =
md.enumerations[i][1+parseNode(node, "start", Int)] # find the enum value and set it
end
end
else
if typename == "Enum"
for i = 1:length(md.enumerations)
if modelVariables[index].declaredType == md.enumerations[i][1] # identify the enum by the name
modelVariables[index].start =
md.enumerations[i][1+parseNode(node, "start", Int)] # find the enum value and set it
end
elseif typename == "String"
for n in eachelement(node)
if n.name == "Start"
modelVariables[index].start = n["value"]
end
end
elseif typename == "Binary"
for n in eachelement(node)
if n.name == "Start"
modelVariables[index].start = pointer(n["value"])
end
end
else # all "common" types
dimensions = Vector{UInt32}()
for element in eachelement(node)
if element.name == "Dimension"
push!(dimensions, parseType(element["start"], UInt32))
end
end
if length(dimensions) > 0
# substrings = split(node["start"], " ")

# T = stringToDataType(md, typename)
# modelVariables[index].start = Vector{T}()
# for string in substrings
# push!(modelVariables[index].start, parseType(string, T))
# end
@warn "Parsing of multi-dimension variable start values not supported, yet.\nDimension is $(dimensions)"
else
modelVariables[index].start =
parseNode(node, "start", stringToDataType(md, typename))
end
end
else
@warn "Unsupported typename `$(typename)` for modelVariable attribute `start`."
end

if typename == "Float64" || typename == "Float32"
modelVariables[index].derivative =
parseNode(node, "derivative", fmi3ValueReference)
modelVariables[index].reinit = parseNode(node, "reinit", Bool)
if haskey(node, "derivative")
if typename == "Float64" || typename == "Float32"
modelVariables[index].derivative =
parseNode(node, "derivative", fmi3ValueReference)
else
@warn "Unsupported typename `$(typename)` for modelVariable attribute `derivative`."
end
end

if typename == "String"
for nod in eachelement(node)
if nod.name == "Start"
modelVariables[index].start = nod["value"]
end
end
elseif typename == "Binary"
for nod in eachelement(node)
if nod.name == "Start"
modelVariables[index].start = pointer(nod["value"])
end
if haskey(node, "reinit")
if typename == "Float64" || typename == "Float32"
modelVariables[index].reinit = parseNode(node, "reinit", Bool)
else
@warn "Unsupported typename `$(typename)` for modelVariable attribute `reinit`."
end
end

Expand Down Expand Up @@ -464,7 +507,7 @@ function parseDependencies(md::fmi3ModelDescription, node::EzXML.Node)
if length(dependenciesSplit) > 0
varDep.dependencies = collect(parse(UInt, e) for e in dependenciesSplit)
end
else
else
varDep.dependencies = UInt[]
end
end
Expand All @@ -477,7 +520,7 @@ function parseDependencies(md::fmi3ModelDescription, node::EzXML.Node)
varDep.dependenciesKind =
collect(stringToDependencyKind(md, e) for e in dependenciesKindSplit)
end
else
else
varDep.dependenciesKind = fmi3DependencyKind[]
end
end
Expand Down
7 changes: 5 additions & 2 deletions test/FMI3/model_description.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ myFMU = loadFMU("BouncingBall", "ModelicaReferenceFMUs", "0.0.30", "3.0")

@test myFMU.modelDescription.numberOfEventIndicators == 1
@test myFMU.modelDescription.eventIndicatorValueReferences == [1]
@test typeof(myFMU.modelDescription.modelStructure.eventIndicators[1]) == fmi3VariableDependency
@test typeof(myFMU.modelDescription.modelStructure.eventIndicators[1]) ==
fmi3VariableDependency

@test isnothing(myFMU.modelDescription.modelStructure.continuousStateDerivatives[1].dependencies)
@test isnothing(
myFMU.modelDescription.modelStructure.continuousStateDerivatives[1].dependencies,
)


info(myFMU) # check if there is an error thrown
Expand Down
Loading