From 2bdda813537a5cae5097f40f17f0384a6f6bc3ee Mon Sep 17 00:00:00 2001 From: TT Date: Thu, 29 Aug 2024 14:31:42 +0200 Subject: [PATCH 1/3] added snapshot tolerance --- Project.toml | 2 +- src/snapshot.jl | 9 ++++++++- src/struct.jl | 2 ++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 64cb3f7..3748589 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "FMIBase" uuid = "900ee838-d029-460e-b485-d98a826ceef2" authors = ["TT ", "LM "] -version = "1.0.5" +version = "1.0.6" [deps] ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" diff --git a/src/snapshot.jl b/src/snapshot.jl index d309117..4779448 100644 --- a/src/snapshot.jl +++ b/src/snapshot.jl @@ -26,7 +26,14 @@ function snapshot!(sol::FMUSolution) end export snapshot! -function snapshot_if_needed!(obj::Union{FMUInstance,FMUSolution}, t::Real; atol = 1e-8) +function snapshotDeltaTimeTolerance(inst::FMIInstance) + return inst.fmu.executionConfig.snapshotDeltaTimeTolerance +end +function snapshotDeltaTimeTolerance(sol::FMISolution) + return snapshotDeltaTimeTolerance(sol.instance) +end + +function snapshot_if_needed!(obj::Union{FMUInstance,FMUSolution}, t::Real; atol = snapshotDeltaTimeTolerance(obj)) if !hasSnapshot(obj, t; atol = atol) snapshot!(obj) end diff --git a/src/struct.jl b/src/struct.jl index a1bc6b2..5e4c03f 100644 --- a/src/struct.jl +++ b/src/struct.jl @@ -52,6 +52,7 @@ mutable struct FMUExecutionConfiguration maxNewDiscreteStateCalls::UInt # max calls for fmi2NewDiscreteStates before throwing an exception maxStateEventsPerSecond::UInt # max state events allowed to occur per second (more is interpreted as event chattering) + snapshotDeltaTimeTolerance::Float64 # distance to distinguish between snapshots eval_t_gradients::Bool # if time gradients ∂ẋ_∂t and ∂y_∂t should be sampled (not part of the FMI standard) JVPBuiltInDerivatives::Bool # use built-in directional derivatives for JVP-sensitivities over FMU without caching the jacobian (because this is done in the FMU, but not per default) @@ -94,6 +95,7 @@ mutable struct FMUExecutionConfiguration inst.maxNewDiscreteStateCalls = 100 inst.maxStateEventsPerSecond = 100 + inst.snapshotDeltaTimeTolerance = 1e-8 inst.eval_t_gradients = false inst.JVPBuiltInDerivatives = false From 849a72f01d8dd9f9d7993bcf610e5f55913b73ea Mon Sep 17 00:00:00 2001 From: TT Date: Thu, 29 Aug 2024 14:35:05 +0200 Subject: [PATCH 2/3] typo --- src/snapshot.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/snapshot.jl b/src/snapshot.jl index 4779448..721a816 100644 --- a/src/snapshot.jl +++ b/src/snapshot.jl @@ -26,10 +26,10 @@ function snapshot!(sol::FMUSolution) end export snapshot! -function snapshotDeltaTimeTolerance(inst::FMIInstance) +function snapshotDeltaTimeTolerance(inst::FMUInstance) return inst.fmu.executionConfig.snapshotDeltaTimeTolerance end -function snapshotDeltaTimeTolerance(sol::FMISolution) +function snapshotDeltaTimeTolerance(sol::FMUSolution) return snapshotDeltaTimeTolerance(sol.instance) end From 4aec515c7fa64b120bb4c9563a2f54f090ca4c6d Mon Sep 17 00:00:00 2001 From: TT Date: Fri, 30 Aug 2024 12:19:03 +0200 Subject: [PATCH 3/3] typo --- src/callbacks.jl | 2 +- src/error_msg.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/callbacks.jl b/src/callbacks.jl index ad514c7..76a6d48 100644 --- a/src/callbacks.jl +++ b/src/callbacks.jl @@ -113,7 +113,7 @@ function f( f(c, dx, x, p, t) - # correct statisitics, because fx-call above -> this was in fact an out-of-place evaluation + # correct statistics, because fx-call above -> this was in fact an out-of-place evaluation c.solution.evals_fx_inplace -= 1 return dx diff --git a/src/error_msg.jl b/src/error_msg.jl index 25ce312..204f151 100644 --- a/src/error_msg.jl +++ b/src/error_msg.jl @@ -3,6 +3,6 @@ # Licensed under the MIT license. See LICENSE file in the project root for details. # -const ERR_MSG_CONT_TIME_MODE = "Function must be called in mode continuous time!\nThis is most probably because the FMU errored before. If no messages are printed, check that the FMU message prinintg is enabled (this is tool dependent and must be selected during export) and follow the message printing instructions under https://thummeto.github.io/FMI.jl/dev/features/#Debugging-/-Logging" +const ERR_MSG_CONT_TIME_MODE = "Function must be called in mode continuous time!\nThis is most probably because the FMU errored before. If no messages are printed, check that the FMU message printing is enabled (this is tool dependent and must be selected during export) and follow the message printing instructions under https://thummeto.github.io/FMI.jl/dev/features/#Debugging-/-Logging" ERR_MSG_NO_FMISENSITIVITY(varname, vartype) = "Wrong dispatched: `$(varname)` is `$(vartype)`.\nThis is most likely because you tried differentiating (AD) over a FMU.\nIf so, you need to `import FMISensitivity` first."