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

v1.0.6 #126

Merged
merged 2 commits into from
Sep 10, 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
4 changes: 2 additions & 2 deletions 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.5"
version = "1.0.6"

[deps]
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
Expand All @@ -17,7 +17,7 @@ FMIZooExt = ["FMIZoo"]

[compat]
Downloads = "1"
FMIBase = "1.0.0"
FMIBase = "1.0.8"
Libdl = "1"
RelocatableFolders = "1"
julia = "1.6"
22 changes: 17 additions & 5 deletions src/FMI2/prep.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ function prepareSolveFMU(

ignore_derivatives() do

autoInstantiated = false

# instantiate (hard)
if instantiate
# remove old one if we missed it (callback)
Expand All @@ -58,13 +60,15 @@ function prepareSolveFMU(
end

c = fmi2Instantiate!(fmu; type = type, instantiateKwargs...)

else # use existing instance
if c === nothing
if hasCurrentInstance(fmu)
c = getCurrentInstance(fmu)
else
@warn "Found no FMU instance, but executionConfig doesn't force allocation. Allocating one.\nUse `fmi2Instantiate(fmu)` to prevent this message."
c = fmi2Instantiate!(fmu; type = type, instantiateKwargs...)
autoInstantiated = true
end
end
end
Expand Down Expand Up @@ -183,11 +187,19 @@ function prepareSolveFMU(
x0 = fmi2GetContinuousStates(c)
end

if instantiate || reset # we have a fresh instance
@debug "[NEW INST]"
if instantiate || reset # autoInstantiated

if !setup
@debug "[AUTO] setup"

fmi2SetupExperiment(c, t_start, t_stop; tolerance = tolerance)
fmi2EnterInitializationMode(c)
fmi2ExitInitializationMode(c)
end

handleEvents(c)
end

c.fmu.hasStateEvents = (c.fmu.modelDescription.numberOfEventIndicators > 0)
c.fmu.hasTimeEvents = isTrue(c.eventInfo.nextEventTimeDefined)
end
Expand All @@ -208,7 +220,7 @@ function prepareSolveFMU(
elseif type == :SE
@assert false "FMU type `SE` is not supported in FMI2!"
else
@assert false "Unknwon FMU type `$(type)`"
@assert false "Unknown FMU type `$(type)`"
end
end

Expand Down Expand Up @@ -241,7 +253,7 @@ function finishSolveFMU(

# freeInstance (hard)
if freeInstance
fmi2FreeInstance!(c; popComponent = popComponent) # , doccall=freeInstance
fmi2FreeInstance!(c; popComponent = popComponent)
c = nothing
end
end
Expand Down
21 changes: 16 additions & 5 deletions src/FMI3/prep.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ function prepareSolveFMU(

ignore_derivatives() do

autoInstantiated = false

c = nothing

# instantiate (hard)
Expand All @@ -53,7 +55,7 @@ function prepareSolveFMU(
elseif type == fmi3TypeScheduledExecution
c = fmi3InstantiateScheduledExecution!(fmu; instantiateKwargs...)
else
@assert false "Unknwon fmi3Type `$(type)`"
@assert false "Unknown fmi3Type `$(type)`"
end
else
if c === nothing
Expand All @@ -63,12 +65,15 @@ function prepareSolveFMU(
@warn "Found no FMU instance, but executionConfig doesn't force allocation. Allocating one. Use `fmi3Instantiate[TYPE](fmu)` to prevent this message."
if type == fmi3TypeCoSimulation
c = fmi3InstantiateCoSimulation!(fmu; instantiateKwargs...)
autoInstantiated = true
elseif type == fmi3TypeModelExchange
c = fmi3InstantiateModelExchange!(fmu; instantiateKwargs...)
autoInstantiated = true
elseif type == fmi3TypeScheduledExecution
c = fmi3InstantiateScheduledExecution!(fmu; instantiateKwargs...)
autoInstantiated = true
else
@assert false "Unknwon FMU type `$(type)`."
@assert false "Unknown FMU type `$(type)`."
end
end
end
Expand Down Expand Up @@ -181,8 +186,14 @@ function prepareSolveFMU(
x0 = fmi3GetContinuousStates(c)
end

if instantiate || reset # we have a fresh instance
@debug "[NEW INST]"
if instantiate || reset # autoInstantiated
@debug "[AUTO] setup"

if !setup
fmi3EnterInitializationMode(c, t_start, t_stop; tolerance = tolerance)
fmi3ExitInitializationMode(c)
end

handleEvents(c)
end

Expand All @@ -202,7 +213,7 @@ function prepareSolveFMU(fmu::FMU3, c::Union{Nothing,FMU3Instance}, type::Symbol
elseif type == :SE
return prepareSolveFMU(fmu, c, fmi3TypeScheduledExecution; kwargs...)
else
@assert false "Unknwon FMU type `$(type)`"
@assert false "Unknown FMU type `$(type)`"
end
end

Expand Down
Loading