Skip to content

Commit

Permalink
v0.15.4 (#88)
Browse files Browse the repository at this point in the history
* fixed bug in fmi2GetSolutionState

* Return type of `fmi2GetNames` (#87)

* Add pkgeval (#85)

* Add pkgeval as action

* Bug fix

* fix: make the return type of `fmi2GetNames` to Vector of strings instead of Vector of Any

* refactor: convert to string before returning

---------

Co-authored-by: Johannes Stoljar <[email protected]>

* fixed bug in Fmi2GetSolutionValue

---------

Co-authored-by: Sathvik Bhagavan <[email protected]>
Co-authored-by: Johannes Stoljar <[email protected]>
  • Loading branch information
3 people authored Apr 11, 2023
1 parent 3cade52 commit 804fbe5
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 58 deletions.
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 = "0.15.3"
version = "0.15.4"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand Down
110 changes: 54 additions & 56 deletions src/FMI2/convert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -234,35 +234,41 @@ More detailed: `fmi2ValueReferenceFormat = Union{Nothing, String, Array{String,1
- FMISpec2.0.2 Link: [https://fmi-standard.org/](https://fmi-standard.org/)
- FMISpec2.0.2[p.22]: 2.1.2 Platform Dependent Definitions (fmi2TypesPlatform.h)
"""
function fmi2GetSolutionState(solution::FMU2Solution, vr::fmi2ValueReferenceFormat; isIndex::Bool=false)
function fmi2GetSolutionState(solution::FMU2Solution, vrs::fmi2ValueReferenceFormat; isIndex::Bool=false)

indices = []

if isIndex
if length(vr) == 1
indices = [vr]
if length(vrs) == 1
indices = [vrs]
else
indices = vr
indices = vrs
end
else
ignore_derivatives() do
vr = prepareValueReference(solution.component.fmu, vr)

if solution.states !== nothing
for i in 1:length(solution.component.fmu.modelDescription.stateValueReferences)
if solution.component.fmu.modelDescription.stateValueReferences[i] == vr
push!(indices, i)
vrs = prepareValueReference(solution.component.fmu, vrs)

if !isnothing(solution.states)
for vr in vrs
found = false
for i in 1:length(solution.component.fmu.modelDescription.stateValueReferences)
if solution.component.fmu.modelDescription.stateValueReferences[i] == vr
push!(indices, i)
found = true
break
end
end
@assert found "Couldn't find the index for value reference `$(vr)`! This is probaly because this value reference does not belong to a system state."
end
end

end # ignore_derivatives
end

# found something
if length(indices) == length(vr)
if length(indices) == length(vrs)

if length(vr) == 1 # single value
if length(vrs) == 1 # single value
return collect(u[indices[1]] for u in solution.states.u)

else # multi value
Expand Down Expand Up @@ -294,34 +300,40 @@ More detailed: `fmi2ValueReferenceFormat = Union{Nothing, String, Array{String,1
- FMISpec2.0.2 Link: [https://fmi-standard.org/](https://fmi-standard.org/)
- FMISpec2.0.2[p.22]: 2.1.2 Platform Dependent Definitions (fmi2TypesPlatform.h)
"""
function fmi2GetSolutionDerivative(solution::FMU2Solution, vr::fmi2ValueReferenceFormat; isIndex::Bool=false)
function fmi2GetSolutionDerivative(solution::FMU2Solution, vrs::fmi2ValueReferenceFormat; isIndex::Bool=false)
indices = []

if isIndex
if length(vr) == 1
indices = [vr]
if length(vrs) == 1
indices = [vrs]
else
indices = vr
indices = vrs
end
else
ignore_derivatives() do
vr = prepareValueReference(solution.component.fmu, vr)

if solution.states !== nothing
for i in 1:length(solution.component.fmu.modelDescription.stateValueReferences)
if solution.component.fmu.modelDescription.stateValueReferences[i] == vr
push!(indices, i)
vrs = prepareValueReference(solution.component.fmu, vrs)

if !isnothing(solution.states)
for vr in vrs
found = false
for i in 1:length(solution.component.fmu.modelDescription.stateValueReferences)
if solution.component.fmu.modelDescription.stateValueReferences[i] == vr
push!(indices, i)
found = true
break
end
end
@assert found "Couldn't find the index for value reference `$(vr)`! This is probaly because this value reference does not belong to a system state."
end
end

end # ignore_derivatives
end

# found something
if length(indices) == length(vr)
if length(indices) == length(vrs)

if length(vr) == 1 # single value
if length(vrs) == 1 # single value
return collect(ForwardDiff.derivative(t -> solution.states(t)[indices[1]], myt) for myt in solution.states.t)

else # multi value
Expand Down Expand Up @@ -353,55 +365,41 @@ More detailed: `fmi2ValueReferenceFormat = Union{Nothing, String, Array{String,1
- FMISpec2.0.2 Link: [https://fmi-standard.org/](https://fmi-standard.org/)
- FMISpec2.0.2[p.22]: 2.1.2 Platform Dependent Definitions (fmi2TypesPlatform.h)
"""
function fmi2GetSolutionValue(solution::FMU2Solution, vr::fmi2ValueReferenceFormat; isIndex::Bool=false)
function fmi2GetSolutionValue(solution::FMU2Solution, vrs::fmi2ValueReferenceFormat; isIndex::Bool=false)

indices = []

if isIndex
if length(vr) == 1
indices = [vr]
if length(vrs) == 1
indices = [vrs]
else
indices = vr
indices = vrs
end
else
ignore_derivatives() do
vr = prepareValueReference(solution.component.fmu, vr)

if solution.states !== nothing
for i in 1:length(solution.component.fmu.modelDescription.stateValueReferences)
if solution.component.fmu.modelDescription.stateValueReferences[i] vr
push!(indices, i)
end
end
end

# found something
if length(indices) == length(vr)

if length(vr) == 1 # single value
return collect(u[indices[1]] for u in solution.states.u)

else # multi value
return collect(collect(u[indices[i]] for u in solution.states.u) for i in 1:length(indices))

end
end

if solution.values !== nothing
for i in 1:length(solution.valueReferences)
if solution.valueReferences[i] vr
push!(indices, i)
vrs = prepareValueReference(solution.component.fmu, vrs)

if !isnothing(solution.values)
for vr in vrs
found = false
for i in 1:length(solution.valueReferences)
if solution.valueReferences[i] == vr
push!(indices, i)
found = true
break
end
end
@assert found "Couldn't find the index for value reference `$(vr)`! This is probaly because this value reference does not exist for this system."
end
end

end # ignore_derivatives
end

# found something
if length(indices) == length(vr)
if length(indices) == length(vrs)

if length(vr) == 1 # single value
if length(vrs) == 1 # single value
return collect(u[indices[1]] for u in solution.values.saveval)

else # multi value
Expand Down
2 changes: 1 addition & 1 deletion src/FMI2/md.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,7 @@ function fmi2GetNames(md::fmi2ModelDescription; vrs=md.valueReferences, mode=:fi
@assert false "fmi2GetNames(...) unknown mode `mode`, please choose between `:first`, `:group` and `:flat`."
end
end
return names
return mode == :group ? [string.(name) for name in names] : string.(names)
end

"""
Expand Down

2 comments on commit 804fbe5

@ThummeTo
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/81384

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.15.4 -m "<description of version>" 804fbe5ab4e25622315b792a3dafe99e8cc5772c
git push origin v0.15.4

Please sign in to comment.