From dba0a367c8e0e614bf19bbeaadac18901c1cd447 Mon Sep 17 00:00:00 2001 From: Simon Exner Date: Fri, 29 Sep 2023 10:27:40 +0200 Subject: [PATCH 01/12] doc fixes + function exports --- src/FMIImport.jl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/FMIImport.jl b/src/FMIImport.jl index d274598..a9a5ef8 100644 --- a/src/FMIImport.jl +++ b/src/FMIImport.jl @@ -69,6 +69,7 @@ export fmi2GetJacobian, fmi2GetJacobian!, fmi2GetFullJacobian, fmi2GetFullJacobi export fmi2Get, fmi2Get!, fmi2Set export fmi2GetUnit, fmi2GetInitial, fmi2GetStartValue, fmi2SampleJacobian export fmi2GetContinuousStates +export fmi2GetDeclaredType, fmi2GetSimpleTypeAttributeStruct # FMI2_md.jl export fmi2LoadModelDescription @@ -142,7 +143,14 @@ export fmi3GetModelIdentifier, fmi3CanGetSetState, fmi3CanSerializeFMUState, fmi ### +""" +Union containing a [`FMU2`](@ref) or a [`FMU2Component`](@ref) +""" fmi2Struct = Union{FMU2, FMU2Component} + +""" +Union containing a [`FMU3`](@ref) or a [`FMU3Component`](@ref) +""" fmi3Struct = Union{FMU3, FMU3Instance} export fmi2Struct, fmi3Struct From 1a4533b1f59f092bd801f7cea0ca3ef8bc130390 Mon Sep 17 00:00:00 2001 From: Simon Exner Date: Fri, 6 Oct 2023 15:06:10 +0200 Subject: [PATCH 02/12] fixes for fmi.jl doc; moved doc to fmi.jl --- docs/.gitignore | 2 - docs/Project.toml | 5 - docs/make.jl | 26 ---- docs/src/contents.md | 4 - docs/src/fmi2_library.md | 250 --------------------------------------- docs/src/fmi3_library.md | 3 - docs/src/overview.md | 3 - docs/src/related.md | 5 - src/FMI2/md.jl | 4 +- src/FMIImport.jl | 4 +- 10 files changed, 4 insertions(+), 302 deletions(-) delete mode 100644 docs/.gitignore delete mode 100644 docs/Project.toml delete mode 100644 docs/make.jl delete mode 100644 docs/src/contents.md delete mode 100644 docs/src/fmi2_library.md delete mode 100644 docs/src/fmi3_library.md delete mode 100644 docs/src/overview.md delete mode 100644 docs/src/related.md diff --git a/docs/.gitignore b/docs/.gitignore deleted file mode 100644 index 8a5f33c..0000000 --- a/docs/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -build/ -Manifest.toml diff --git a/docs/Project.toml b/docs/Project.toml deleted file mode 100644 index 67a236d..0000000 --- a/docs/Project.toml +++ /dev/null @@ -1,5 +0,0 @@ -[deps] -Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" - -[compat] -julia = "1.6" diff --git a/docs/make.jl b/docs/make.jl deleted file mode 100644 index 5e634e7..0000000 --- a/docs/make.jl +++ /dev/null @@ -1,26 +0,0 @@ -# -# Copyright (c) 2021 Tobias Thummerer, Johannes Stoljar, Lars Mikelsons -# Licensed under the MIT license. See LICENSE file in the project root for details. -# - -using Documenter, FMIImport - -makedocs(sitename="FMIImport.jl", - format = Documenter.HTML( - collapselevel = 1, - sidebar_sitename = false, - edit_link = nothing - ), - modules = [FMIImport], - checkdocs = :exports, - pages= Any[ - "Introduction" => "index.md" - "Examples" => "overview.md" - "FMI2 Library Functions" => "fmi2_library.md" - "FMI3 Library Functions" => "fmi3_library.md" - "Related Publication" => "related.md" - "Contents" => "contents.md" - ] - ) - -deploydocs(repo = "github.com/ThummeTo/FMIImport.jl.git", devbranch = "main") diff --git a/docs/src/contents.md b/docs/src/contents.md deleted file mode 100644 index 5aae11c..0000000 --- a/docs/src/contents.md +++ /dev/null @@ -1,4 +0,0 @@ - -```@contents -Depth = 2 -``` diff --git a/docs/src/fmi2_library.md b/docs/src/fmi2_library.md deleted file mode 100644 index 0cf5bc6..0000000 --- a/docs/src/fmi2_library.md +++ /dev/null @@ -1,250 +0,0 @@ - -# [FMI2 Library Functions](@id library) - -## FMI2 Common Concepts for Model Exchange and Co-Simulation -In both cases, FMI defines an input/output block of a dynamic model where the distribution of the block, the -platform dependent header file, several access functions, as well as the schema files are identical. - -### Reading the model description -This section documents functions to inquire information about the model description of an FMU. - -#### Load/Parse the FMI model description -```@docs -fmi2LoadModelDescription -``` -#### Get value functions -```@docs -fmi2GetDefaultStartTime -fmi2GetDefaultStopTime -fmi2GetDefaultTolerance -fmi2GetDefaultStepSize -fmi2GetModelName -fmi2GetGUID -fmi2GetGenerationTool -fmi2GetGenerationDateAndTime -fmi2GetVariableNamingConvention -fmi2GetNumberOfEventIndicators -fmi2GetNumberOfStates -fmi2IsCoSimulation -fmi2IsModelExchange -``` - -#### Information functions - - -```@docs -fmi2DependenciesSupported -fmi2DerivativeDependenciesSupported -fmi2GetModelIdentifier -fmi2CanGetSetState -fmi2CanSerializeFMUstate -fmi2ProvidesDirectionalDerivative -fmi2GetValueReferencesAndNames -fmi2GetNames -fmi2GetModelVariableIndices -fmi2GetInputValueReferencesAndNames -fmi2GetInputNames -fmi2GetOutputValueReferencesAndNames -fmi2GetOutputNames -fmi2GetParameterValueReferencesAndNames -fmi2GetParameterNames -fmi2GetStateValueReferencesAndNames -fmi2GetStateNames -fmi2GetDerivateValueReferencesAndNames -fmi2GetDerivativeNames -fmi2GetNamesAndDescriptions -fmi2GetNamesAndUnits -fmi2GetNamesAndInitials -fmi2GetInputNamesAndStarts -fmi2GetVersion -fmi2GetTypesPlatform -fmi2GetSolutionDerivative -``` - -### Creation, Destruction and Logging of FMU Instances -This section documents functions that deal with instantiation, destruction and logging of FMUs. - -```@docs -fmi2Instantiate! -fmi2FreeInstance! -fmi2SetDebugLogging - -``` - -### Initialization, Termination, and Resetting an FMU -This section documents functions that deal with initialization, termination, resetting of an FMU. - -```@docs -fmi2SetupExperiment -fmi2EnterInitializationMode -fmi2ExitInitializationMode -fmi2Terminate -fmi2Reset -``` -### Getting and Setting Variable Values -All variable values of an FMU are identified with a variable handle called “value reference”. The handle is -defined in the modelDescription.xml file (as attribute “valueReference” in element -“ScalarVariable”). Element “valueReference” might not be unique for all variables. If two or more -variables of the same base data type (such as fmi2Real) have the same valueReference, then they -have identical values but other parts of the variable definition might be different [(for example, min/max -attributes)]. - -```@docs -fmi2Get -fmi2Get! -fmi2Set -fmi2GetReal -fmi2GetReal! -fmi2GetInteger -fmi2GetInteger! -fmi2GetBoolean -fmi2GetBoolean! -fmi2GetString -fmi2GetString! -fmi2SetReal -fmi2SetInteger -fmi2SetBoolean -fmi2SetString -``` - - -### Getting and Setting the Complete FMU State -The FMU has an internal state consisting of all values that are needed to continue a simulation. This internal state consists especially of the values of the continuous-time states, iteration variables, parameter values, input values, delay buffers, file identifiers, and FMU internal status information. With the functions of this section, the internal FMU state can be copied and the pointer to this copy is returned to the environment. The FMU state copy can be set as actual FMU state, in order to continue the simulation from it. - -```@docs -fmi2GetFMUstate -fmi2GetFMUstate! -fmi2SetFMUstate -fmi2FreeFMUstate! -fmi2SerializedFMUstateSize -fmi2SerializedFMUstateSize! -fmi2SerializeFMUstate -fmi2SerializeFMUstate! -fmi2DeSerializeFMUstate -fmi2DeSerializeFMUstate! -``` - -### Getting Partial Dervatives -It is optionally possible to provide evaluation of partial derivatives for an FMU. For Model Exchange, this -means computing the partial derivatives at a particular time instant. For Co-Simulation, this means to -compute the partial derivatives at a particular communication point. One function is provided to compute -directional derivatives. This function can be used to construct the desired partial derivative matrices. - - -```@docs -fmi2GetDirectionalDerivative! -fmi2SetRealInputDerivatives -fmi2GetRealOutputDerivatives! -fmi2SampleJacobian -fmi2SampleJacobian! -``` - -## FMI for Model Exchange - -This chapter contains the interface description to access the equations of a dynamic system from a C -program. - -### Providing Independent Variables and Re-initialization of Caching -Depending on the situation, different variables need to be computed. In order to be efficient, it is important that the interface requires only the computation of variables that are needed in the present context. The state derivatives shall be reused from the previous call. This feature is called “caching of variables” in the sequel. Caching requires that the model evaluation can detect when the input arguments, like time or states, have changed. - -```@docs -fmi2SetTime -fmi2SetContinuousStates -``` - -### Evaluation of Model Equations -This section contains the core functions to evaluate the model equations. - - -```@docs -fmi2EnterEventMode -fmi2NewDiscreteStates -fmi2NewDiscreteStates! -fmi2EnterContinuousTimeMode -fmi2CompletedIntegratorStep -fmi2CompletedIntegratorStep! -fmi2GetDerivatives -fmi2GetDerivatives! -fmi2GetEventIndicators -fmi2GetEventIndicators! -fmi2GetContinuousStates -fmi2GetContinuousStates! -fmi2GetNominalsOfContinuousStates -fmi2GetNominalsOfContinuousStates! -``` - -## FMI for Co-Simulation -This chapter defines the Functional Mock-up Interface (FMI) for the coupling of two or more simulation -models in a Co-Simulation environment (FMI for Co-Simulation). Co-Simulation is a rather general -approach to the simulation of coupled technical systems and coupled physical phenomena in -engineering with focus on instationary (time-dependent) problems. - - -### Transfer of Input / Output Values and Parameters -In order to enable the slave to interpolate the continuous real inputs between communication steps, the -derivatives of the inputs with respect to time can be provided. Also, higher derivatives can be set to allow -higher order interpolation. - -```@docs -fmi2GetRealOutputDerivatives -``` - -### Computation -The computation of time steps is controlled by the following function. - -```@docs -fmi2DoStep -fmi2CancelStep -``` - -### Retrieving Status Information from the Slave -Status information is retrieved from the slave by the following functions: - -```@docs -fmi2GetStatus! -fmi2GetRealStatus! -fmi2GetIntegerStatus! -fmi2GetBooleanStatus! -fmi2GetStringStatus! -``` - -## add functions -These new functions, that are useful, but not part of the FMI-spec. (example: `fmi2Load`, `fmi2SampleJacobian`) - -### Opening and closing FMUs -```@docs -fmi2Unzip -fmi2Unload -fmi2Load -fmi2Reload -``` -### Conversion functions - -```@docs -fmi2StringToValueReference -fmi2ModelVariablesForValueReference -fmi2ValueReferenceToString -fmi2GetSolutionState -fmi2GetSolutionValue -fmi2GetSolutionTime -``` - -### External/Additional functions - -```@docs -fmi2GetJacobian -fmi2GetJacobian! -fmi2GetFullJacobian -fmi2GetFullJacobian! -fmi2GetStartValue -fmi2GetUnit -fmi2GetDeclaredType -fmi2GetInitial -fmi2GetSimpleTypeAttributeStruct -``` - - -## All functions - -```@index -``` diff --git a/docs/src/fmi3_library.md b/docs/src/fmi3_library.md deleted file mode 100644 index 9d2d27e..0000000 --- a/docs/src/fmi3_library.md +++ /dev/null @@ -1,3 +0,0 @@ -# [FMI3 Library Functions](@id library) - -## FMI2 Common Concepts for Model Exchange and Co-Simulation diff --git a/docs/src/overview.md b/docs/src/overview.md deleted file mode 100644 index 7eeaf4d..0000000 --- a/docs/src/overview.md +++ /dev/null @@ -1,3 +0,0 @@ -# Examples - Overview - -To see the handling with FMUs in Julia, you can have a look at the [examples](https://thummeto.github.io/FMI.jl/dev/examples/overview/) from the FMI.jl package. diff --git a/docs/src/related.md b/docs/src/related.md deleted file mode 100644 index e7b086c..0000000 --- a/docs/src/related.md +++ /dev/null @@ -1,5 +0,0 @@ -# Related Publications - -Thummerer T, Kircher J and Mikelsons L: __Neural FMU: Towards structual integration of FMUs into neural networks__ (Preprint, accepted 14th International Modelica Conference) [pdf](https://arxiv.org/abs/2109.04351)|DOI - -Thummerer T, Tintenherr J, Mikelsons L: __Hybrid modeling of the human cardiovascular system using NeuralFMUs__ (Preprint, accepted 10th International Conference on Mathematical Modeling in Physical Sciences) [pdf](https://arxiv.org/abs/2109.04880)|DOI diff --git a/src/FMI2/md.jl b/src/FMI2/md.jl index c1f27d6..8b067ac 100644 --- a/src/FMI2/md.jl +++ b/src/FMI2/md.jl @@ -1471,7 +1471,7 @@ Returns a dictionary `Dict(fmi2ValueReference, Array{String})` of derivative val # Returns - `dict::Dict{fmi2ValueReference, Array{String}}`: Returns a dictionary that constructs a hash table with keys of type fmi2ValueReference and values of type Array{String}. So returns a dict with (vrs, names of derivatives) -See also [fmi2GetValueReferencesAndNames`](@ref) +See also [`fmi2GetValueReferencesAndNames`](@ref) """ function fmi2GetDerivateValueReferencesAndNames(md::fmi2ModelDescription) fmi2GetValueReferencesAndNames(md::fmi2ModelDescription; vrs=md.derivativeValueReferences) @@ -1487,7 +1487,7 @@ Returns a dictionary `Dict(fmi2ValueReference, Array{String})` of derivative val # Returns - `dict::Dict{fmi2ValueReference, Array{String}}`: Returns a dictionary that constructs a hash table with keys of type fmi2ValueReference and values of type Array{String}. So returns a dict with (vrs, names of derivatives) -See also [fmi2GetValueReferencesAndNames`](@ref) +See also [`fmi2GetValueReferencesAndNames`](@ref) """ function fmi2GetDerivateValueReferencesAndNames(fmu::FMU2) fmi2GetDerivateValueReferencesAndNames(fmu.modelDescription) diff --git a/src/FMIImport.jl b/src/FMIImport.jl index a9a5ef8..f0d6393 100644 --- a/src/FMIImport.jl +++ b/src/FMIImport.jl @@ -126,7 +126,7 @@ export fmi3GetStartValue, fmi3SampleDirectionalDerivative, fmi3CompletedIntegrat # FMI3_ext.jl -export fmi3Unzip, fmi3Load, fmi3Unload, fmi3InstantiateModelExchange!, fmi3InstantiateCoSimulation!, fmi3InstantiateScheduledExecution! +export fmi3Unzip, fmi3Load, fmi3Reload, fmi3Unload, fmi3InstantiateModelExchange!, fmi3InstantiateCoSimulation!, fmi3InstantiateScheduledExecution! export fmi3Get, fmi3Get!, fmi3Set export fmi3SampleDirectionalDerivative! export fmi3GetJacobian, fmi3GetJacobian!, fmi3GetFullJacobian, fmi3GetFullJacobian! @@ -149,7 +149,7 @@ Union containing a [`FMU2`](@ref) or a [`FMU2Component`](@ref) fmi2Struct = Union{FMU2, FMU2Component} """ -Union containing a [`FMU3`](@ref) or a [`FMU3Component`](@ref) +Union containing a [`FMU3`](@ref) or a [`FMU3Instance`](@ref) """ fmi3Struct = Union{FMU3, FMU3Instance} export fmi2Struct, fmi3Struct From 8154c62bb02ab89004bdb3a6c49c0df2b06c1aca Mon Sep 17 00:00:00 2001 From: Simon Exner Date: Tue, 10 Oct 2023 08:20:19 +0200 Subject: [PATCH 03/12] doc fixes --- src/FMI3/c.jl | 11 +++-------- src/FMI3/int.jl | 4 +--- src/FMIImport.jl | 10 ++++++++++ 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/FMI3/c.jl b/src/FMI3/c.jl index 65c7a40..3987d24 100644 --- a/src/FMI3/c.jl +++ b/src/FMI3/c.jl @@ -658,7 +658,7 @@ end """ - fmi3SetInt8!(c::FMU3Instance, vr::AbstractArray{fmi3ValueReference}, nvr::Csize_t, value::AbstractArray{fmi3Int8}, nvalue::Csize_t) + fmi3SetInt8(c::FMU3Instance, vr::AbstractArray{fmi3ValueReference}, nvr::Csize_t, value::AbstractArray{fmi3Int8}, nvalue::Csize_t) Functions to get and set values of variables idetified by their valueReference. @@ -683,7 +683,6 @@ More detailed: - FMISpec3.0: 2.2.3 Platform Dependent Definitions - FMISpec3.0: 2.2.4 Status Returned by Functions - FMISpec3.0: 2.2.6.2. Getting and Setting Variable Values -See also [`fmi3SetInt8!`](@ref). """ function fmi3SetInt8(c::FMU3Instance, vr::AbstractArray{fmi3ValueReference}, nvr::Csize_t, value::AbstractArray{fmi3Int8}, nvalue::Csize_t) status = fmi3SetInt8(c.fmu.cSetInt8, @@ -902,7 +901,6 @@ More detailed: - FMISpec3.0: 2.2.3 Platform Dependent Definitions - FMISpec3.0: 2.2.4 Status Returned by Functions - FMISpec3.0: 2.2.6.2. Getting and Setting Variable Values -See also [`fmi3SetUInt16!`](@ref). """ function fmi3SetUInt16(c::FMU3Instance, vr::AbstractArray{fmi3ValueReference}, nvr::Csize_t, value::AbstractArray{fmi3UInt16}, nvalue::Csize_t) status = fmi3SetUInt16(c.fmu.cSetUInt16, @@ -1584,7 +1582,6 @@ More detailed: - FMISpec3.0: 2.2.3 Platform Dependent Definitions - FMISpec3.0: 2.2.4 Status Returned by Functions - FMISpec3.0: 2.2.6.4. Getting and Setting the Complete FMU State -See also [`fmi3FreeFMUState!`](@ref). """ function fmi3FreeFMUState!(c::FMU3Instance, FMUstate::Ref{fmi3FMUState}) status = fmi3FreeFMUState!(c.fmu.cFreeFMUState, @@ -1697,8 +1694,8 @@ function fmi3DeSerializeFMUState!(c::FMU3Instance, serialzedState::AbstractArray return status end +# TODO Clocks and dependencies functions """ - fmi3SetIntervalDecimal(c::FMU3Instance, vr::AbstractArray{fmi3ValueReference}, nvr::Csize_t, intervals::AbstractArray{fmi3Float64}) Sets the interval until the next clock tick @@ -1724,7 +1721,6 @@ More detailed: - FMISpec3.0: 2.2.9. Clocks See also [`fmi3SetIntervalDecimal`](@ref). """ -# TODO Clocks and dependencies functions function fmi3SetIntervalDecimal(c::FMU3Instance, vr::AbstractArray{fmi3ValueReference}, nvr::Csize_t, intervals::AbstractArray{fmi3Float64}) status = fmi3SetIntervalDecimal(c.fmu.cSetIntervalDecimal, c.compAddr, vr, nvr, intervals) @@ -1954,8 +1950,8 @@ function fmi3ActivateModelPartition(c::FMU3Instance, vr::fmi3ValueReference, act return status end +# TODO not tested """ - fmi3GetNumberOfVariableDependencies!(c::FMU3Instance, vr::fmi3ValueReference, nvr::Ref{Csize_t}) The number of dependencies of a given variable, which may change if structural parameters are changed, can be retrieved by calling fmi3GetNumberOfVariableDependencies. @@ -1983,7 +1979,6 @@ More detailed: - FMISpec3.0: 2.2.10. Dependencies of Variables See also [`fmi3GetNumberOfVariableDependencies!`](@ref). """ -# TODO not tested function fmi3GetNumberOfVariableDependencies!(c::FMU3Instance, vr::fmi3ValueReference, nvr::Ref{Csize_t}) status = fmi3GetNumberOfVariableDependencies!(c.fmu.cGetNumberOfVariableDependencies, c.compAddr, vr, nvr) diff --git a/src/FMI3/int.jl b/src/FMI3/int.jl index 1648fa2..ddac83b 100644 --- a/src/FMI3/int.jl +++ b/src/FMI3/int.jl @@ -1777,7 +1777,7 @@ end """ - fmi3FreeFMUState(c::FMU3Instance, state::fmi3FMUState) + fmi3FreeFMUState!(c::FMU3Instance, state::fmi3FMUState) Free the allocated memory for the FMU state. @@ -1792,8 +1792,6 @@ Free the allocated memory for the FMU state. - FMISpec3.0 Link: [https://fmi-standard.org/](https://fmi-standard.org/) - FMISpec3.0: 2.2.3 Platform Dependent Definitions - FMISpec3.0: 2.2.6.4. Getting and Setting the Complete FMU State - -See also [`fmi3FreeFMUState`](@ref). """ function fmi3FreeFMUState!(c::FMU3Instance, state::fmi3FMUState) stateRef = Ref(state) diff --git a/src/FMIImport.jl b/src/FMIImport.jl index f0d6393..bd5ca81 100644 --- a/src/FMIImport.jl +++ b/src/FMIImport.jl @@ -18,6 +18,9 @@ prepareValue(value::AbstractVector) = value export prepareValue, prepareValueReference # wildcards for how a user can pass a fmi[X]ValueReference +""" +TODO +""" fmi2ValueReferenceFormat = Union{Nothing, String, AbstractArray{String,1}, fmi2ValueReference, AbstractArray{fmi2ValueReference,1}, Int64, AbstractArray{Int64,1}, Symbol} fmi3ValueReferenceFormat = Union{Nothing, String, AbstractArray{String,1}, fmi3ValueReference, AbstractArray{fmi3ValueReference,1}, Int64, AbstractArray{Int64,1}} export fmi2ValueReferenceFormat, fmi3ValueReferenceFormat @@ -154,7 +157,14 @@ Union containing a [`FMU3`](@ref) or a [`FMU3Instance`](@ref) fmi3Struct = Union{FMU3, FMU3Instance} export fmi2Struct, fmi3Struct +""" +Union containing a [`FMU2`](@ref), a [`FMU2Component`](@ref) or a [`fmi2ModelDescription`](@ref) +""" fmi2StructMD = Union{FMU2, FMU2Component, fmi2ModelDescription} + +""" +Union containing a [`FMU3`](@ref), a [`FMU3Instance`](@ref) or a [`fmi3ModelDescription`](@ref) +""" fmi3StructMD = Union{FMU3, FMU3Instance , fmi3ModelDescription} export fmi2StructMD, fmi3StructMD From 666ed9ad8c9624144c5eea4d10a330efc0ca259c Mon Sep 17 00:00:00 2001 From: Simon Exner Date: Mon, 16 Oct 2023 09:28:36 +0200 Subject: [PATCH 04/12] doc fixes --- src/FMI2/convert.jl | 3 ++- src/FMI2/ext.jl | 4 ++++ src/FMI3/c.jl | 44 ++++++++++++++++++++++++++++++++++++-------- src/FMI3/ext.jl | 21 ++++++++++++--------- src/FMI3/int.jl | 23 +++++++++++++++++++---- src/FMIImport.jl | 5 ++++- 6 files changed, 77 insertions(+), 23 deletions(-) diff --git a/src/FMI2/convert.jl b/src/FMI2/convert.jl index 87db3a8..4c629e7 100644 --- a/src/FMI2/convert.jl +++ b/src/FMI2/convert.jl @@ -109,7 +109,8 @@ function fmi2ModelVariablesForValueReference(md::fmi2ModelDescription, vr::fmi2V end """ -ToDo. + fmi2DataTypeForValueReference(md::fmi2ModelDescription, vr::fmi2ValueReference) +Returns the fmi2DataType (`fmi2Real`, `fmi2Integer`, `fmi2Boolean`, `fmi2String`) for a given Valuereference `vr` of a given FMU-ModelDescription `md` """ function fmi2DataTypeForValueReference(md::fmi2ModelDescription, vr::fmi2ValueReference) mv = fmi2ModelVariablesForValueReference(md, vr)[1] diff --git a/src/FMI2/ext.jl b/src/FMI2/ext.jl index 0d64955..fc829bc 100644 --- a/src/FMI2/ext.jl +++ b/src/FMI2/ext.jl @@ -255,6 +255,10 @@ function fmi2Load(pathToFMU::String; unpackPath::Union{String, Nothing}=nothing, return fmu end +""" + loadBinary(fmu::FMU2) +load pointers to `fmu`\`s c functions from shared library handle (provided by `fmu.libHandle`) +""" function loadBinary(fmu::FMU2) lastDirectory = pwd() cd(dirname(fmu.binaryPath)) diff --git a/src/FMI3/c.jl b/src/FMI3/c.jl index 3987d24..a865a65 100644 --- a/src/FMI3/c.jl +++ b/src/FMI3/c.jl @@ -1704,6 +1704,7 @@ Sets the interval until the next clock tick - `c::FMU3Instance`: Argument `c` is a Mutable struct represents an instantiated instance of an FMU in the FMI 3.0 Standard. - `vr::AbstractArray{fmi3ValueReference}`: Argument `vr` is an AbstractArray of `nvr` value handels called "ValueReference" that define the variable that shall be inquired. - `nvr::Csize_t`: Argument `nvr` defines the size of `vr`. +- `intervals::AbstractArray{fmi3Float64}`: # Returns - `status::fmi3Status`: Return `status` is an enumeration of type `fmi3Status` and indicates the success of the function call. @@ -1738,6 +1739,8 @@ Sets the interval until the next clock tick. Only allowed if the attribute 'supp - `c::FMU3Instance`: Argument `c` is a Mutable struct represents an instantiated instance of an FMU in the FMI 3.0 Standard. - `vr::AbstractArray{fmi3ValueReference}`: Argument `vr` is an AbstractArray of `nvr` value handels called "ValueReference" that define the variable that shall be inquired. - `nvr::Csize_t`: Argument `nvr` defines the size of `vr`. +- `intervalCounters::AbstractArray{fmi3UInt64}`: +- `resolutions::AbstractArray{fmi3UInt64}`: # Returns - `status::fmi3Status`: Return `status` is an enumeration of type `fmi3Status` and indicates the success of the function call. @@ -1779,6 +1782,8 @@ For information about fmi3IntervalQualifiers, call ?fmi3IntervalQualifier - `c::FMU3Instance`: Argument `c` is a Mutable struct represents an instantiated instance of an FMU in the FMI 3.0 Standard. - `vr::AbstractArray{fmi3ValueReference}`: Argument `vr` is an AbstractArray of `nvr` value handels called "ValueReference" that define the variable that shall be inquired. - `nvr::Csize_t`: Argument `nvr` defines the size of `vr`. +- `intervals::AbstractArray{fmi3Float64}`: +- `qualifiers::fmi3IntervalQualifier`: # Returns - `status::fmi3Status`: Return `status` is an enumeration of type `fmi3Status` and indicates the success of the function call. @@ -1820,6 +1825,9 @@ For information about fmi3IntervalQualifiers, call ?fmi3IntervalQualifier - `c::FMU3Instance`: Argument `c` is a Mutable struct represents an instantiated instance of an FMU in the FMI 3.0 Standard. - `vr::AbstractArray{fmi3ValueReference}`: Argument `vr` is an AbstractArray of `nvr` value handels called "ValueReference" that define the variable that shall be inquired. - `nvr::Csize_t`: Argument `nvr` defines the size of `vr`. +- `intervalCounters::AbstractArray{fmi3UInt64}`: +- `resolutions::AbstractArray{fmi3UInt64}`: +- `qualifiers::fmi3IntervalQualifier`: # Returns - `status::fmi3Status`: Return `status` is an enumeration of type `fmi3Status` and indicates the success of the function call. @@ -1855,6 +1863,7 @@ fmi3GetShiftDecimal retrieves the delay to the first Clock tick from the FMU. - `c::FMU3Instance`: Argument `c` is a Mutable struct represents an instantiated instance of an FMU in the FMI 3.0 Standard. - `vr::AbstractArray{fmi3ValueReference}`: Argument `vr` is an AbstractArray of `nvr` value handels called "ValueReference" that define the variable that shall be inquired. - `nvr::Csize_t`: Argument `nvr` defines the size of `vr`. +- `shifts::AbstractArray{fmi3Float64}`: # Returns - `status::fmi3Status`: Return `status` is an enumeration of type `fmi3Status` and indicates the success of the function call. @@ -1890,6 +1899,8 @@ fmi3GetShiftFraction retrieves the delay to the first Clock tick from the FMU. - `c::FMU3Instance`: Argument `c` is a Mutable struct represents an instantiated instance of an FMU in the FMI 3.0 Standard. - `vr::AbstractArray{fmi3ValueReference}`: Argument `vr` is an AbstractArray of `nvr` value handels called "ValueReference" that define the variable that shall be inquired. - `nvr::Csize_t`: Argument `nvr` defines the size of `vr`. +- `shiftCounters::AbstractArray{fmi3UInt64}`: +- `resolutions::AbstractArray{fmi3UInt64}`: # Returns - `status::fmi3Status`: Return `status` is an enumeration of type `fmi3Status` and indicates the success of the function call. @@ -1926,6 +1937,7 @@ Each `fmi3ActivateModelPartition` call is associated with the computation of an # Arguments - `c::FMU3Instance`: Argument `c` is a Mutable struct represents an instantiated instance of an FMU in the FMI 3.0 Standard. - `vr::fmi3ValueReference`: Argument `vr` is the value handel called "ValueReference" that define the variable that shall be inquired. +- `activationTime::AbstractArray{fmi3Float64}`: # Returns - `status::fmi3Status`: Return `status` is an enumeration of type `fmi3Status` and indicates the success of the function call. @@ -1992,21 +2004,20 @@ end elementIndiceOfInpendents::AbstractArray{Csize_t}, dependencyKind::AbstractArray{fmi3DependencyKind}, ndependencies::Csize_t) The actual dependencies (of type dependenciesKind) can be retrieved by calling the function fmi3GetVariableDependencies: - -# TODO argmuents + # Arguments - `c::FMU3Instance`: Argument `c` is a Mutable struct represents an instantiated instance of an FMU in the FMI 3.0 Standard. - `vr::fmi3ValueReference`: Argument `vr` is the value handel called "ValueReference" that define the variable that shall be inquired. - `nvr::Csize_t`: Argument `nvr` defines the size of `vr`. -- `elementIndicesOfDependent::AbstractArray{Csize_t}`: must point to a buffer of size_t values of size `nDependencies` allocated by the calling environment. +- `elementIndiceOfDependents::AbstractArray{Csize_t}`: must point to a buffer of size_t values of size `nDependencies` allocated by the calling environment. It is filled in by this function with the element index of the dependent variable that dependency information is provided for. The element indices start with 1. Using the element index 0 means all elements of the variable. (Note: If an array has more than one dimension the indices are serialized in the same order as defined for values in Section 2.2.6.1.) - `independents::AbstractArray{fmi3ValueReference}`: must point to a buffer of `fmi3ValueReference` values of size `nDependencies` allocated by the calling environment. It is filled in by this function with the value reference of the independent variable that this dependency entry is dependent upon. -- `elementIndicesIndependents::AbstractArray{Csize_t}`: must point to a buffer of size_t `values` of size `nDependencies` allocated by the calling environment. +- `elementIndiceOfInpendents::AbstractArray{Csize_t}`: must point to a buffer of size_t `values` of size `nDependencies` allocated by the calling environment. It is filled in by this function with the element index of the independent variable that this dependency entry is dependent upon. The element indices start with 1. Using the element index 0 means all elements of the variable. (Note: If an array has more than one dimension the indices are serialized in the same order as defined for values in Section 2.2.6.1.) -- `dependencyKinds::AbstractArray{fmi3DependencyKind}`: must point to a buffer of dependenciesKind values of size `nDependencies` allocated by the calling environment. +- `dependencyKind::AbstractArray{fmi3DependencyKind}`: must point to a buffer of dependenciesKind values of size `nDependencies` allocated by the calling environment. It is filled in by this function with the enumeration value describing the dependency of this dependency entry. -- `nDependencies::Csize_t`: specifies the number of dependencies that the calling environment allocated space for in the result buffers, and should correspond to value obtained by calling `fmi3GetNumberOfVariableDependencies`. +- `ndependencies::Csize_t`: specifies the number of dependencies that the calling environment allocated space for in the result buffers, and should correspond to value obtained by calling `fmi3GetNumberOfVariableDependencies`. # Returns - `status::fmi3Status`: Return `status` is an enumeration of type `fmi3Status` and indicates the success of the function call. @@ -2509,7 +2520,6 @@ function fmi3EvaluateDiscreteStates(c::FMU3Instance) end """ - fmi3UpdateDiscreteStates(c::FMU3Instance, discreteStatesNeedUpdate::Ref{fmi3Boolean}, terminateSimulation::Ref{fmi3Boolean}, nominalsOfContinuousStatesChanged::Ref{fmi3Boolean}, valuesOfContinuousStatesChanged::Ref{fmi3Boolean}, nextEventTimeDefined::Ref{fmi3Boolean}, nextEventTime::Ref{fmi3Float64}) @@ -2519,6 +2529,12 @@ This function is called to signal a converged solution at the current super-dens # TODO Arguments # Arguments - `c::FMU3Instance`: Mutable struct represents an instantiated instance of an FMU in the FMI 3.0 Standard. +- `discreteStatesNeedUpdate::Ref{fmi3Boolean}`: +- `terminateSimulation::Ref{fmi3Boolean}`: +- `nominalsOfContinuousStatesChanged::Ref{fmi3Boolean}`: +- `valuesOfContinuousStatesChanged::Ref{fmi3Boolean}`: +- `nextEventTimeDefined::Ref{fmi3Boolean}`: +- `nextEventTime::Ref{fmi3Float64}`: # Returns - `status::fmi3Status`: Return `status` is an enumeration of type `fmi3Status` and indicates the success of the function call. @@ -2535,7 +2551,6 @@ More detailed: - FMISpec3.0: 2.2.4 Status Returned by Functions - FMISpec3.0: 2.3.5. State: Event Mode -See also [`fmi3UpdateDiscreteStates`](@ref). """ function fmi3UpdateDiscreteStates(c::FMU3Instance, discreteStatesNeedUpdate::Ref{fmi3Boolean}, terminateSimulation::Ref{fmi3Boolean}, nominalsOfContinuousStatesChanged::Ref{fmi3Boolean}, valuesOfContinuousStatesChanged::Ref{fmi3Boolean}, @@ -2847,6 +2862,12 @@ The model enters Event Mode from the Continuous-Time Mode in ModelExchange oder # TODO argmuents # Arguments - `c::FMU3Instance`: Mutable struct represents an instantiated instance of an FMU in the FMI 3.0 Standard. +- `stepEvent::fmi3Boolean`: +- `stateEvent::fmi3Boolean`: +- `rootsFound::AbstractArray{fmi3Int32}`: +- `nEventIndicators::Csize_t`: +- `timeEvent::fmi3Boolean`: +- `soft::Bool=false`: # Keywords - `soft::Bool=false`: If the Keyword `soft = true` the `fmi3Teminate` needs to be called in state `fmi3InstanceStateContinuousTimeMode` or `fmi3InstanceStateEventMode`. @@ -2897,6 +2918,13 @@ The computation of a time step is started. # TODO argmuents # Arguments - `c::FMU3Instance`: Mutable struct represents an instantiated instance of an FMU in the FMI 3.0 Standard. +- `currentCommunicationPoint::fmi3Float64`: +- `communicationStepSize::fmi3Float64`: +- `noSetFMUStatePriorToCurrentPoint::fmi3Boolean`: +- `eventEncountered::Ref{fmi3Boolean}`: +- `terminateSimulation::Ref{fmi3Boolean}`: +- `earlyReturn::Ref{fmi3Boolean}`: +- `lastSuccessfulTime::Ref{fmi3Float64}`: # Returns - `status::fmi3Status`: Return `status` is an enumeration of type `fmi3Status` and indicates the success of the function call. diff --git a/src/FMI3/ext.jl b/src/FMI3/ext.jl index 0b92cf9..eee523f 100644 --- a/src/FMI3/ext.jl +++ b/src/FMI3/ext.jl @@ -227,7 +227,8 @@ function fmi3Load(pathToFMU::String; unpackPath=nothing, type=nothing, cleanup=t end """ -TODO + loadBinary(fmu::FMU3) +load pointers to `fmu`\`s c functions from shared library handle (provided by `fmu.libHandle`) """ function loadBinary(fmu::FMU3) lastDirectory = pwd() @@ -736,8 +737,7 @@ function fmi3Unload(fmu::FMU3, cleanUp::Bool = true) end """ - -fmi3SampleDirectionalDerivative(c::FMU3Instance, + fmi3SampleDirectionalDerivative(c::FMU3Instance, vUnknown_ref::AbstractArray{fmi3ValueReference}, vKnown_ref::AbstractArray{fmi3ValueReference}, steps::Union{AbstractArray{fmi3Float64}, Nothing} = nothing) @@ -788,8 +788,7 @@ end """ - -fmi3SampleDirectionalDerivative!(c::FMU3Instance, + fmi3SampleDirectionalDerivative!(c::FMU3Instance, vUnknown_ref::AbstractArray{fmi3ValueReference}, vKnown_ref::AbstractArray{fmi3ValueReference}, steps::Union{AbstractArray{fmi3Float64}, Nothing} = nothing) @@ -1278,9 +1277,6 @@ function fmi3Set(inst::FMU3Instance, vrs::fmi3ValueReferenceFormat, srcArray::Ar return retcodes end -""" -ToDo: DocString -""" function fmi3Set(inst::FMU3Instance, vr::Union{fmi3ValueReference, String}, value) vrs = prepareValueReference(inst, vr) @@ -1430,7 +1426,14 @@ function fmi3GetStartValue(mv::fmi3Variable) end """ -TODO + function fmi3SampleDirectionalDerivative(c::FMU3Instance, + vUnknown_ref::Array{fmi3ValueReference}, + vKnown_ref::Array{fmi3ValueReference}, + steps::Array{fmi3Float64} = ones(fmi3Float64, length(vKnown_ref)).*1e-5) + +Wrapper for [`fmi3SampleDirectionalDerivative!`](@ref) with `dvUnknown` initialized with zeros + +Returning dvUnknown, modified by `fmi3SampleDirectionalDerivative!` call. """ function fmi3SampleDirectionalDerivative(c::FMU3Instance, vUnknown_ref::Array{fmi3ValueReference}, diff --git a/src/FMI3/int.jl b/src/FMI3/int.jl index ddac83b..ed33faa 100644 --- a/src/FMI3/int.jl +++ b/src/FMI3/int.jl @@ -2581,8 +2581,7 @@ function fmi3GetContinuousStateDerivatives!(c::FMU3Instance, derivatives::Abstr end """ - -fmi3UpdateDiscreteStates(c::FMU3Instance) + fmi3UpdateDiscreteStates(c::FMU3Instance) This function is called to signal a converged solution at the current super-dense time instant. fmi3UpdateDiscreteStates must be called at least once per super-dense time instant. @@ -2591,14 +2590,18 @@ This function is called to signal a converged solution at the current super-dens # TODO returns # Returns -- +- `discreteStatesNeedUpdate` +- `terminateSimulation` +- `nominalsOfContinuousStatesChanged` +- `valuesOfContinuousStatesChanged` +- `nextEventTimeDefined` +- `nextEventTime` # Source - FMISpec3.0 Link: [https://fmi-standard.org/](https://fmi-standard.org/) - FMISpec3.0: 2.2.3 Platform Dependent Definitions - FMISpec3.0: 2.3.5. State: Event Mode -See also [`fmi3UpdateDiscreteStates`](@ref). """ function fmi3UpdateDiscreteStates(c::FMU3Instance) discreteStatesNeedUpdate = fmi3True @@ -2706,6 +2709,11 @@ The model enters Event Mode from the Continuous-Time Mode in ModelExchange oder # TODO argmuents # Arguments - `c::FMU3Instance`: Mutable struct represents an instantiated instance of an FMU in the FMI 3.0 Standard. +- `stepEvent::Bool`: +- `stateEvent::Bool`: +- `rootsFound::AbstractArray{fmi3Int32}`: +- `nEventIndicators::Csize_t`: +- `timeEvent::Bool`: # Returns - `status::fmi3Status`: Return `status` is an enumeration of type `fmi3Status` and indicates the success of the function call. @@ -2737,6 +2745,13 @@ The computation of a time step is started. # TODO argmuents # Arguments - `c::FMU3Instance`: Mutable struct represents an instantiated instance of an FMU in the FMI 3.0 Standard. +- `currentCommunicationPoint::Union{Real, Nothing} = nothing` +- `communicationStepSize::Union{Real, Nothing} = nothing` +- `noSetFMUStatePriorToCurrentPoint::Bool = true` +- `eventEncountered::fmi3Boolean = fmi3False` +- `terminateSimulation::fmi3Boolean = fmi3False` +- `earlyReturn::fmi3Boolean = fmi3False` +- `lastSuccessfulTime::fmi3Float64 = 0.0` # Returns - `status::fmi3Status`: Return `status` is an enumeration of type `fmi3Status` and indicates the success of the function call. diff --git a/src/FMIImport.jl b/src/FMIImport.jl index bd5ca81..53cac0f 100644 --- a/src/FMIImport.jl +++ b/src/FMIImport.jl @@ -19,9 +19,12 @@ export prepareValue, prepareValueReference # wildcards for how a user can pass a fmi[X]ValueReference """ -TODO +Union of (wildcard for) all ways to describe and pass a fmi2ValueReference (e.g. String, Int64, Array, fmi2ValueReference, ...) """ fmi2ValueReferenceFormat = Union{Nothing, String, AbstractArray{String,1}, fmi2ValueReference, AbstractArray{fmi2ValueReference,1}, Int64, AbstractArray{Int64,1}, Symbol} +""" +Union of (wildcard for) all ways to describe and pass a fmi3ValueReference (e.g. String, Int64, Array, fmi3ValueReference, ...) +""" fmi3ValueReferenceFormat = Union{Nothing, String, AbstractArray{String,1}, fmi3ValueReference, AbstractArray{fmi3ValueReference,1}, Int64, AbstractArray{Int64,1}} export fmi2ValueReferenceFormat, fmi3ValueReferenceFormat From c20ad4940c7cd613e3e3c12afe4d0381d01f493f Mon Sep 17 00:00:00 2001 From: Simon Exner Date: Tue, 17 Oct 2023 13:51:04 +0200 Subject: [PATCH 05/12] changed logWarn to logWarning --- src/FMI2/ext.jl | 4 ++-- src/FMI2/sens.jl | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/FMI2/ext.jl b/src/FMI2/ext.jl index fc829bc..a7b4fb0 100644 --- a/src/FMI2/ext.jl +++ b/src/FMI2/ext.jl @@ -97,7 +97,7 @@ end function dlsym_opt(libHandle, symbol) addr = dlsym(libHandle, symbol; throw_error=false) if addr == nothing - logWarn(fmu, "This FMU does not support function '$symbol'.") + logWarning(fmu, "This FMU does not support function '$symbol'.") addr = Ptr{Cvoid}(C_NULL) end addr @@ -454,7 +454,7 @@ function fmi2Instantiate!(fmu::FMU2; end if !isnothing(component) - logWarn(fmu, "fmi2Instantiate!(...): This component was already registered. This may be because you created the FMU by yourself with FMIExport.jl.") + logWarning(fmu, "fmi2Instantiate!(...): This component was already registered. This may be because you created the FMU by yourself with FMIExport.jl.") else component = FMU2Component(compAddr, fmu) diff --git a/src/FMI2/sens.jl b/src/FMI2/sens.jl index be38e7a..319a704 100644 --- a/src/FMI2/sens.jl +++ b/src/FMI2/sens.jl @@ -84,7 +84,7 @@ function (fmu::FMU2)(;dx::AbstractVector{<:Real}=Vector{fmi2Real}(), if hasCurrentComponent(fmu) c = getCurrentComponent(fmu) else - logWarn(fmu, "No FMU2Component found. Allocating one.") + logWarning(fmu, "No FMU2Component found. Allocating one.") c = fmi2Instantiate!(fmu) fmi2EnterInitializationMode(c) fmi2ExitInitializationMode(c) From 92a972147a4e97effe79ba137dd369bd8ac437bf Mon Sep 17 00:00:00 2001 From: TT Date: Mon, 6 Nov 2023 14:48:52 +0100 Subject: [PATCH 06/12] removed outdated file --- src/FMI2/sens.jl | 796 ----------------------------------------------- 1 file changed, 796 deletions(-) delete mode 100644 src/FMI2/sens.jl diff --git a/src/FMI2/sens.jl b/src/FMI2/sens.jl deleted file mode 100644 index 319a704..0000000 --- a/src/FMI2/sens.jl +++ /dev/null @@ -1,796 +0,0 @@ -# -# Copyright (c) 2022 Tobias Thummerer, Lars Mikelsons -# Licensed under the MIT license. See LICENSE file in the project root for details. -# - -# What is included in the file `FMI2_sens.jl`? -# - calling function for FMU2 and FMU2Component -# - ForwardDiff- and ChainRulesCore-Sensitivities over FMUs -# - ToDo: colouring of dependency types (known from model description) for fast jacobian build-ups - -import SciMLSensitivity.ForwardDiff -import SciMLSensitivity.ReverseDiff -using ChainRulesCore -import ForwardDiffChainRules: @ForwardDiff_frule -import SciMLSensitivity.ReverseDiff: @grad_from_chainrules -import ChainRulesCore: ZeroTangent, NoTangent, @thunk -import FMICore: fmi2ValueReference - -# in FMI2 we can use fmi2GetDirectionalDerivative for JVP-computations -function fmi2JVP!(c::FMU2Component, mtxCache::Symbol, ∂f_refs, ∂x_refs, seed) - - if c.fmu.executionConfig.JVPBuiltInDerivatives && fmi2ProvidesDirectionalDerivative(c.fmu.modelDescription) - jac = getfield(c, mtxCache) - if jac.b == nothing || size(jac.b) != (length(seed),) - jac.b = zeros(length(seed)) - end - - fmi2GetDirectionalDerivative!(c, ∂f_refs, ∂x_refs, jac.b, seed) - return jac.b - else - jac = getfield(c, mtxCache) - - return FMICore.jvp!(jac, seed; ∂f_refs=∂f_refs, ∂x_refs=∂x_refs) - end -end - -# in FMI2 there is no helper for VJP-computations (but in FMI3) ... -function fmi2VJP!(c::FMU2Component, mtxCache::Symbol, ∂f_refs, ∂x_refs, seed) - - jac = getfield(c, mtxCache) - return FMICore.vjp!(jac, seed; ∂f_refs=∂f_refs, ∂x_refs=∂x_refs) -end - -""" - - (fmu::FMU2)(;dx::Union{AbstractVector{<:Real}, Nothing}=nothing, - y::Union{AbstractVector{<:Real}, Nothing}=nothing, - y_refs::Union{AbstractVector{<:fmi2ValueReference}, Nothing}=nothing, - x::Union{AbstractVector{<:Real}, Nothing}=nothing, - u::Union{AbstractVector{<:Real}, Nothing}=nothing, - u_refs::Union{AbstractVector{<:fmi2ValueReference}, Nothing}=nothing, - t::Union{Real, Nothing}=nothing) - -Evaluates a `FMU2` by setting the component state `x`, inputs `u` and/or time `t`. If no component is available, one is allocated. The result of the evaluation might be the system output `y` and/or state-derivative `dx`. -Not all options are available for any FMU type, e.g. setting state is not supported for CS-FMUs. Assertions will be generated for wrong use. - -# Keywords -- `dx`: An array to store the state-derivatives in. If not provided but necessary, a suitable array is allocated and returned. Not supported by CS-FMUs. -- `y`: An array to store the system outputs in. If not provided but requested, a suitable array is allocated and returned. -- `y_refs`: An array of value references to indicate which system outputs shall be returned. -- `x`: An array containing the states to be set. Not supported by CS-FMUs. -- `u`: An array containing the inputs to be set. -- `u_refs`: An array of value references to indicate which system inputs want to be set. -- `p`: An array of FMU parameters to be set. -- `p_refs`: An array of parameter references to indicate which system parameter sensitivities need to be determined. -- `t`: A scalar value holding the system time to be set. - -# Returns (as Tuple) -- `y::Union{AbstractVector{<:Real}, Nothing}`: The system output `y` (if requested, otherwise `nothing`). -- `dx::Union{AbstractVector{<:Real}, Nothing}`: The system state-derivaitve (if ME-FMU, otherwise `nothing`). -""" -function (fmu::FMU2)(;dx::AbstractVector{<:Real}=Vector{fmi2Real}(), - y::AbstractVector{<:Real}=Vector{fmi2Real}(), - y_refs::AbstractVector{<:fmi2ValueReference}=Vector{fmi2ValueReference}(), - x::AbstractVector{<:Real}=Vector{fmi2Real}(), - u::AbstractVector{<:Real}=Vector{fmi2Real}(), - u_refs::AbstractVector{<:fmi2ValueReference}=Vector{fmi2ValueReference}(), - p::AbstractVector{<:Real}=fmu.optim_p, - p_refs::AbstractVector{<:fmi2ValueReference}=fmu.optim_p_refs, - t::Real=-1.0) - - c = nothing - - if hasCurrentComponent(fmu) - c = getCurrentComponent(fmu) - else - logWarning(fmu, "No FMU2Component found. Allocating one.") - c = fmi2Instantiate!(fmu) - fmi2EnterInitializationMode(c) - fmi2ExitInitializationMode(c) - end - - if t == -1.0 - t = c.next_t - end - - c(;dx=dx, y=y, y_refs=y_refs, x=x, u=u, u_refs=u_refs, p=p, p_refs=p_refs, t=t) -end - -""" - - (c::FMU2Component)(;dx::Union{AbstractVector{<:Real}, Nothing}=nothing, - y::Union{AbstractVector{<:Real}, Nothing}=nothing, - y_refs::Union{AbstractVector{<:fmi2ValueReference}, Nothing}=nothing, - x::Union{AbstractVector{<:Real}, Nothing}=nothing, - u::Union{AbstractVector{<:Real}, Nothing}=nothing, - u_refs::Union{AbstractVector{<:fmi2ValueReference}, Nothing}=nothing, - t::Union{Real, Nothing}=nothing) - -Evaluates a `FMU2Component` by setting the component state `x`, inputs `u` and/or time `t`. The result of the evaluation might be the system output `y` and/or state-derivative `dx`. -Not all options are available for any FMU type, e.g. setting state is not supported for CS-FMUs. Assertions will be generated for wrong use. - -# Keywords -- `dx`: An array to store the state-derivatives in. If not provided but necessary, a suitable array is allocated and returned. Not supported by CS-FMUs. -- `y`: An array to store the system outputs in. If not provided but requested, a suitable array is allocated and returned. -- `y_refs`: An array of value references to indicate which system outputs shall be returned. -- `x`: An array containing the states to be set. Not supported by CS-FMUs. -- `u`: An array containing the inputs to be set. -- `u_refs`: An array of value references to indicate which system inputs want to be set. -- `p`: An array of FMU parameters to be set. -- `p_refs`: An array of parameter references to indicate which system parameter sensitivities need to be determined. -- `t`: A scalar value holding the system time to be set. - -# Returns (as Tuple) -- `y::Union{AbstractVector{<:Real}, Nothing}`: The system output `y` (if requested, otherwise `nothing`). -- `dx::Union{AbstractVector{<:Real}, Nothing}`: The system state-derivaitve (if ME-FMU, otherwise `nothing`). -""" -function (c::FMU2Component)(;dx::AbstractVector{<:Real}=Vector{fmi2Real}(), - y::AbstractVector{<:Real}=Vector{fmi2Real}(), - y_refs::AbstractVector{<:fmi2ValueReference}=Vector{fmi2ValueReference}(), - x::AbstractVector{<:Real}=Vector{fmi2Real}(), - u::AbstractVector{<:Real}=Vector{fmi2Real}(), - u_refs::AbstractVector{<:fmi2ValueReference}=Vector{fmi2ValueReference}(), - p::AbstractVector{<:Real}=c.fmu.optim_p, - p_refs::AbstractVector{<:fmi2ValueReference}=c.fmu.optim_p_refs, - t::Real=c.next_t) - - if length(y_refs) > 0 - if length(y) <= 0 - y = zeros(fmi2Real, length(y_refs)) - end - end - - @assert (length(y) == length(y_refs)) "Length of `y` must match length of `y_refs`." - @assert (length(u) == length(u_refs)) "Length of `u` must match length of `u_refs`." - @assert (length(p) == length(p_refs)) "Length of `p` must match length of `p_refs`." - - if fmi2IsModelExchange(c.fmu) - - if c.type == fmi2TypeModelExchange::fmi2Type - if length(dx) <= 0 - dx = zeros(fmi2Real, fmi2GetNumberOfStates(c.fmu.modelDescription)) - end - end - end - - if fmi2IsCoSimulation(c.fmu) - if c.type == fmi2TypeCoSimulation::fmi2Type - @assert length(dx) <= 0 "Keyword `dx != nothing` is invalid for CS-FMUs. Setting a state-derivative is not possible in CS." - @assert length(x) <= 0 "Keyword `x != nothing` is invalid for CS-FMUs. Setting a state is not possible in CS." - @assert t < 0.0 "Keyword `t != nothing` is invalid for CS-FMUs. Setting explicit time is not possible in CS." - end - end - - # ToDo: This is necessary, because ForwardDiffChainRules.jl can't handle arguments with type `Ptr{Nothing}`. - cRef = nothing - ignore_derivatives() do - cRef = pointer_from_objref(c) - cRef = UInt64(cRef) - end - - return eval!(cRef, dx, y, y_refs, x, u, u_refs, p, p_refs, t) -end - -function eval!(cRef::UInt64, - dx::AbstractVector{<:Real}, - y::AbstractVector{<:Real}, - y_refs::AbstractVector{<:fmi2ValueReference}, - x::AbstractVector{<:Real}, - u::AbstractVector{<:Real}, - u_refs::AbstractVector{<:fmi2ValueReference}, - p::AbstractVector{<:Real}, - p_refs::AbstractVector{<:fmi2ValueReference}, - t::Real) - - c = unsafe_pointer_to_objref(Ptr{Nothing}(cRef)) - - @assert (!isdual(x) && !istracked(x)) "eval!(...): Wrong dispatched: `x` is ForwardDiff.Dual/ReverseDiff.TrackedReal, please open an issue with MWE." - @assert (!isdual(u) && !istracked(u)) "eval!(...): Wrong dispatched: `u` is ForwardDiff.Dual/ReverseDiff.TrackedReal, please open an issue with MWE." - @assert (!isdual(t) && !istracked(t)) "eval!(...): Wrong dispatched: `t` is ForwardDiff.Dual/ReverseDiff.TrackedReal, please open an issue with MWE." - @assert (!isdual(p) && !istracked(p)) "eval!(...): Wrong dispatched: `p` is ForwardDiff.Dual/ReverseDiff.TrackedReal, please open an issue with MWE." - - x = unsense(x) - t = unsense(t) - u = unsense(u) - # p = unsense(p) # no need to unsense `p` because it is not beeing used further - - # set state - if length(x) > 0 && !c.fmu.isZeroState - fmi2SetContinuousStates(c, x) - end - - # set time - if t >= 0.0 - fmi2SetTime(c, t) - end - - # set input - if length(u) > 0 - fmi2SetReal(c, u_refs, u) - end - - # get derivative - if length(dx) > 0 - if isdual(dx) - - dx_tmp = nothing - - if c.fmu.isZeroState - dx_tmp = [1.0] - else - dx_tmp = collect(ForwardDiff.value(e) for e in dx) - fmi2GetDerivatives!(c, dx_tmp) - end - - T, V, N = fd_eltypes(dx) - dx[:] = collect(ForwardDiff.Dual{T, V, N}(dx_tmp[i], ForwardDiff.partials(dx[i]) ) for i in 1:length(dx)) - - elseif istracked(dx) - - dx_tmp = zeros(fmi2Real, length(dx)) - fmi2GetDerivatives!(c, dx_tmp) - - for e in 1:length(dx) - dx[e].value = dx_tmp[e] - end - else - if c.fmu.isZeroState - dx[:] = [1.0] - else - fmi2GetDerivatives!(c, dx) - end - end - end - - # get output - if length(y) > 0 - if isdual(y) - #@info "y is dual!" - y_tmp = collect(ForwardDiff.value(e) for e in y) - fmi2GetReal!(c, y_refs, y_tmp) - T, V, N = fd_eltypes(y) - y[:] = collect(ForwardDiff.Dual{T, V, N}(y_tmp[i], ForwardDiff.partials(y[i]) ) for i in 1:length(y)) - else - if !isa(y, AbstractVector{fmi2Real}) - y = convert(Vector{fmi2Real}, y) - end - fmi2GetReal!(c, y_refs, y) - end - end - - if c.fmu.executionConfig.concat_y_dx - return vcat(y, dx) # [y..., dx...] - else - return y, dx - end -end - -function ChainRulesCore.frule(Δtuple, - ::typeof(eval!), - cRef, - dx, - y, - y_refs, - x, - u, - u_refs, - p, - p_refs, - t) - - Δtuple = undual(Δtuple) - Δself, ΔcRef, Δdx, Δy, Δy_refs, Δx, Δu, Δu_refs, Δp, Δp_refs, Δt = Δtuple - - ### ToDo: Somehow, ForwardDiff enters with all types beeing Float64, this needs to be corrected. - - cRef = undual(cRef) - if typeof(cRef) != UInt64 - cRef = UInt64(cRef) - end - - t = undual(t) - u = undual(u) - x = undual(x) - - p = undual(p) - - y_refs = undual(y_refs) - y_refs = convert(Array{UInt32,1}, y_refs) - - u_refs = undual(u_refs) - u_refs = convert(Array{UInt32,1}, u_refs) - - p_refs = undual(p_refs) - p_refs = convert(Array{UInt32,1}, p_refs) - - ### - - c = unsafe_pointer_to_objref(Ptr{Nothing}(cRef)) - - outputs = (length(y_refs) > 0) - inputs = (length(u_refs) > 0) - derivatives = (length(dx) > 0) - states = (length(x) > 0) - times = (t >= 0.0) - parameters = (length(p_refs) > 0) - - Ω = eval!(cRef, dx, y, y_refs, x, u, u_refs, p, p_refs, t) - - # time, states and inputs where already set in `eval!`, no need to repeat it here - - ∂y = ZeroTangent() - ∂dx = ZeroTangent() - - if Δx != NoTangent() && length(Δx) > 0 - - if !isa(Δx, AbstractVector{fmi2Real}) - Δx = convert(Vector{fmi2Real}, Δx) - end - - if states - if derivatives - ∂dx += fmi2JVP!(c, :A, c.fmu.modelDescription.derivativeValueReferences, c.fmu.modelDescription.stateValueReferences, Δx) - c.solution.evals_∂ẋ_∂x += 1 - #@info "$(Δx)" - end - - if outputs - ∂y += fmi2JVP!(c, :C, y_refs, c.fmu.modelDescription.stateValueReferences, Δx) - c.solution.evals_∂y_∂x += 1 - end - end - end - - - if Δu != NoTangent() && length(Δu) > 0 - - if !isa(Δu, AbstractVector{fmi2Real}) - Δu = convert(Vector{fmi2Real}, Δu) - end - - if inputs - if derivatives - ∂dx += fmi2JVP!(c, :B, c.fmu.modelDescription.derivativeValueReferences, u_refs, Δu) - c.solution.evals_∂ẋ_∂u += 1 - end - - if outputs - ∂y += fmi2JVP!(c, :D, y_refs, u_refs, Δu) - c.solution.evals_∂y_∂u += 1 - end - end - end - - if Δp != NoTangent() && length(Δp) > 0 - - if !isa(Δp, AbstractVector{fmi2Real}) - Δp = convert(Vector{fmi2Real}, Δp) - end - - if parameters - if derivatives - ∂dx += fmi2JVP!(c, :E, c.fmu.modelDescription.derivativeValueReferences, p_refs, Δp) - c.solution.evals_∂ẋ_∂p += 1 - end - - if outputs - ∂y += fmi2JVP!(c, :F, y_refs, p_refs, Δp) - c.solution.evals_∂y_∂p += 1 - end - end - end - - if c.fmu.executionConfig.eval_t_gradients - # partial time derivatives are not part of the FMI standard, so must be sampled in any case - if Δt != NoTangent() && times && (derivatives || outputs) - - dt = 1e-6 # ToDo: Find a better value, e.g. based on the current solver step size - - dx1 = nothing - dx2 = nothing - y1 = nothing - y2 = nothing - - if derivatives - dx1 = zeros(fmi2Real, length(c.fmu.modelDescription.derivativeValueReferences)) - dx2 = zeros(fmi2Real, length(c.fmu.modelDescription.derivativeValueReferences)) - fmi2GetDerivatives!(c, dx1) - end - - if outputs - y1 = zeros(fmi2Real, length(y)) - y2 = zeros(fmi2Real, length(y)) - fmi2GetReal!(c, y_refs, y1) - end - - fmi2SetTime(c, t + dt; track=false) - - if derivatives - fmi2GetDerivatives!(c, dx2) - - ∂dx_t = (dx2-dx1)/dt - ∂dx += ∂dx_t * Δt - - c.solution.evals_∂ẋ_∂t += 1 - end - - if outputs - fmi2GetReal!(c, y_refs, y2) - - ∂y_t = (y2-y1)/dt - ∂y += ∂y_t * Δt - - c.solution.evals_∂y_∂t += 1 - end - - fmi2SetTime(c, t; track=false) - end - end - - @debug "frule: ∂y=$(∂y) ∂dx=$(∂dx)" - - ∂Ω = nothing - if c.fmu.executionConfig.concat_y_dx - ∂Ω = vcat(∂y, ∂dx) # [∂y..., ∂dx...] - else - ∂Ω = (∂y, ∂dx) - end - - return Ω, ∂Ω -end - -function isZeroTangent(d) - return false -end - -function isZeroTangent(d::ZeroTangent) - return true -end - -function isZeroTangent(d::AbstractArray{<:ZeroTangent}) - return true -end - -function ChainRulesCore.rrule(::typeof(eval!), - cRef, - dx, - y, - y_refs, - x, - u, - u_refs, - p, - p_refs, - t) - - @assert !isa(cRef, FMU2Component) "Wrong dispatched!" - - c = unsafe_pointer_to_objref(Ptr{Nothing}(cRef)) - - outputs = (length(y_refs) > 0) - inputs = (length(u_refs) > 0) - derivatives = (length(dx) > 0) - states = (length(x) > 0) - times = (t >= 0.0) - parameters = (length(p_refs) > 0) - - Ω = eval!(cRef, dx, y, y_refs, x, u, u_refs, p, p_refs, t) - - # if !inputs - # Ω = eval!(cRef, dx, y, y_refs, x, t) - # elseif !states - # Ω = eval!(cRef, dx, y, y_refs, u, u_refs, t) - # else - # Ω = eval!(cRef, dx, y, y_refs, x, u, u_refs, t) - # end - - ############## - - function eval_pullback(r̄) - - ȳ = nothing - d̄x = nothing - - if c.fmu.executionConfig.concat_y_dx - ylen = (isnothing(y_refs) ? 0 : length(y_refs)) - ȳ = r̄[1:ylen] - d̄x = r̄[ylen+1:end] - else - ȳ, d̄x = r̄ - end - - outputs = outputs && !isZeroTangent(ȳ) - derivatives = derivatives && !isZeroTangent(d̄x) - - if !isa(ȳ, AbstractArray) - ȳ = collect(ȳ) # [ȳ...] - end - - if !isa(d̄x, AbstractArray) - d̄x = collect(d̄x) # [d̄x...] - end - - # between building and using the pullback maybe the time, state or inputs where changed, so we need to re-set them - - if states && c.x != x - fmi2SetContinuousStates(c, x) - end - - if inputs ## && c.u != u - fmi2SetReal(c, u_refs, u) - end - - if times && c.t != t - fmi2SetTime(c, t) - end - - n_dx_x = ZeroTangent() - n_dx_u = ZeroTangent() - n_dx_p = ZeroTangent() - n_dx_t = ZeroTangent() - - n_y_x = ZeroTangent() - n_y_u = ZeroTangent() - n_y_p = ZeroTangent() - n_y_t = ZeroTangent() - - @debug "rrule pullback ȳ, d̄x = $(ȳ), $(d̄x)" - - dx_refs = c.fmu.modelDescription.derivativeValueReferences - x_refs = c.fmu.modelDescription.stateValueReferences - - if derivatives - if states - n_dx_x = fmi2VJP!(c, :A, dx_refs, x_refs, d̄x) - c.solution.evals_∂ẋ_∂x += 1 - end - - if inputs - n_dx_u = fmi2VJP!(c, :B, dx_refs, u_refs, d̄x) - c.solution.evals_∂ẋ_∂u += 1 - end - - if parameters - n_dx_p = fmi2VJP!(c, :E, dx_refs, p_refs, d̄x) - c.solution.evals_∂ẋ_∂p += 1 - - # if rand(1:100) == 1 - # #@info "$(c.E.mtx)" - # #@info "$(p_refs)" - # @info "$(fmi2GetJacobian(c, dx_refs, p_refs))" - # end - end - end - - if outputs - if states - n_y_x = fmi2VJP!(c, :C, y_refs, x_refs, ȳ) - c.solution.evals_∂y_∂x += 1 - end - - if inputs - n_y_u = fmi2VJP!(c, :D, y_refs, u_refs, ȳ) - c.solution.evals_∂y_∂u += 1 - end - - if parameters - n_y_p = fmi2VJP!(c, :F, y_refs, p_refs, ȳ) - c.solution.evals_∂y_∂p += 1 - end - end - - if c.fmu.executionConfig.eval_t_gradients - # sample time partials - # in rrule this should be done even if no new time is actively set - if (derivatives || outputs) # && times - - # if no time is actively set, use the component current time for sampling - if !times - t = c.t - end - - dt = 1e-6 # ToDo: better value - - dx1 = nothing - dx2 = nothing - y1 = nothing - y2 = nothing - - if derivatives - dx1 = zeros(fmi2Real, length(dx_refs)) - dx2 = zeros(fmi2Real, length(dx_refs)) - fmi2GetDerivatives!(c, dx1) - end - - if outputs - y1 = zeros(fmi2Real, length(y)) - y2 = zeros(fmi2Real, length(y)) - fmi2GetReal!(c, y_refs, y1) - end - - fmi2SetTime(c, t + dt; track=false) - - if derivatives - fmi2GetDerivatives!(c, dx2) - - ∂dx_t = (dx2-dx1) / dt - n_dx_t = ∂dx_t' * d̄x - - c.solution.evals_∂ẋ_∂t += 1 - end - - if outputs - fmi2GetReal!(c, y_refs, y2) - - ∂y_t = (y2-y1) / dt - n_y_t = ∂y_t' * ȳ - - c.solution.evals_∂y_∂t += 1 - end - - fmi2SetTime(c, t; track=false) - end - end - - # write back - f̄ = NoTangent() - c̄Ref = ZeroTangent() - d̄x = ZeroTangent() - ȳ = ZeroTangent() - ȳ_refs = ZeroTangent() - t̄ = n_y_t + n_dx_t - - x̄ = n_y_x + n_dx_x - - ū = n_y_u + n_dx_u - ū_refs = ZeroTangent() - - p̄ = n_y_p + n_dx_p - p̄_refs = ZeroTangent() - - @debug "rrule: $((f̄, c̄Ref, d̄x, ȳ, ȳ_refs, x̄, ū, ū_refs, p̄, p̄_refs, t̄))" - - return (f̄, c̄Ref, d̄x, ȳ, ȳ_refs, x̄, ū, ū_refs, p̄, p̄_refs, t̄) - end - - return (Ω, eval_pullback) -end - -# dx, y, x, u, t -@ForwardDiff_frule eval!(cRef::UInt64, - dx ::AbstractVector{<:ForwardDiff.Dual}, - y ::AbstractVector{<:ForwardDiff.Dual}, - y_refs::AbstractVector{<:fmi2ValueReference}, - x ::AbstractVector{<:ForwardDiff.Dual}, - u ::AbstractVector{<:ForwardDiff.Dual}, - u_refs::AbstractVector{<:fmi2ValueReference}, - p ::AbstractVector{<:Real}, - p_refs::AbstractVector{<:fmi2ValueReference}, - t ::ForwardDiff.Dual) - -@grad_from_chainrules eval!(cRef::UInt64, - dx ::AbstractVector{<:ReverseDiff.TrackedReal}, - y ::AbstractVector{<:ReverseDiff.TrackedReal}, - y_refs::AbstractVector{<:UInt32}, - x ::AbstractVector{<:ReverseDiff.TrackedReal}, - u ::AbstractVector{<:ReverseDiff.TrackedReal}, - u_refs::AbstractVector{<:UInt32}, - p ::AbstractVector{<:Real}, - p_refs::AbstractVector{<:UInt32}, - t ::ReverseDiff.TrackedReal) - -# x, p -@ForwardDiff_frule eval!(cRef::UInt64, - dx ::AbstractVector{<:Real}, - y ::AbstractVector{<:Real}, - y_refs::AbstractVector{<:fmi2ValueReference}, - x ::AbstractVector{<:ForwardDiff.Dual}, - u ::AbstractVector{<:Real}, - u_refs::AbstractVector{<:fmi2ValueReference}, - p ::AbstractVector{<:ForwardDiff.Dual}, - p_refs::AbstractVector{<:fmi2ValueReference}, - t ::Real) - -@grad_from_chainrules eval!(cRef::UInt64, - dx ::AbstractVector{<:Real}, - y ::AbstractVector{<:Real}, - y_refs::AbstractVector{<:UInt32}, - x ::AbstractVector{<:ReverseDiff.TrackedReal}, - u ::AbstractVector{<:Real}, - u_refs::AbstractVector{<:UInt32}, - p ::AbstractVector{<:ReverseDiff.TrackedReal}, - p_refs::AbstractVector{<:UInt32}, - t ::Real) - -# t -@ForwardDiff_frule eval!(cRef::UInt64, - dx ::AbstractVector{<:Real}, - y ::AbstractVector{<:Real}, - y_refs::AbstractVector{<:fmi2ValueReference}, - x ::AbstractVector{<:Real}, - u ::AbstractVector{<:Real}, - u_refs::AbstractVector{<:fmi2ValueReference}, - p ::AbstractVector{<:Real}, - p_refs::AbstractVector{<:fmi2ValueReference}, - t ::ForwardDiff.Dual) - -@grad_from_chainrules eval!(cRef::UInt64, - dx ::AbstractVector{<:Real}, - y ::AbstractVector{<:Real}, - y_refs::AbstractVector{<:UInt32}, - x ::AbstractVector{<:Real}, - u ::AbstractVector{<:Real}, - u_refs::AbstractVector{<:UInt32}, - p ::AbstractVector{<:Real}, - p_refs::AbstractVector{<:UInt32}, - t ::ReverseDiff.TrackedReal) - -# x -@ForwardDiff_frule eval!(cRef::UInt64, - dx ::AbstractVector{<:Real}, - y ::AbstractVector{<:Real}, - y_refs::AbstractVector{<:fmi2ValueReference}, - x ::AbstractVector{<:ForwardDiff.Dual}, - u ::AbstractVector{<:Real}, - u_refs::AbstractVector{<:fmi2ValueReference}, - p ::AbstractVector{<:Real}, - p_refs::AbstractVector{<:fmi2ValueReference}, - t ::Real) - -@grad_from_chainrules eval!(cRef::UInt64, - dx ::AbstractVector{<:Real}, - y ::AbstractVector{<:Real}, - y_refs::AbstractVector{<:UInt32}, - x ::AbstractVector{<:ReverseDiff.TrackedReal}, - u ::AbstractVector{<:Real}, - u_refs::AbstractVector{<:UInt32}, - p ::AbstractVector{<:Real}, - p_refs::AbstractVector{<:UInt32}, - t ::Real) - -# u -@ForwardDiff_frule eval!(cRef::UInt64, - dx ::AbstractVector{<:Real}, - y ::AbstractVector{<:Real}, - y_refs::AbstractVector{<:fmi2ValueReference}, - x ::AbstractVector{<:Real}, - u ::AbstractVector{<:ForwardDiff.Dual}, - u_refs::AbstractVector{<:fmi2ValueReference}, - p ::AbstractVector{<:Real}, - p_refs::AbstractVector{<:fmi2ValueReference}, - t ::Real) - -@grad_from_chainrules eval!(cRef::UInt64, - dx ::AbstractVector{<:Real}, - y ::AbstractVector{<:Real}, - y_refs::AbstractVector{<:UInt32}, - x ::AbstractVector{<:Real}, - u ::AbstractVector{<:ReverseDiff.TrackedReal}, - u_refs::AbstractVector{<:UInt32}, - p ::AbstractVector{<:Real}, - p_refs::AbstractVector{<:UInt32}, - t ::Real) - -# p -@ForwardDiff_frule eval!(cRef::UInt64, - dx ::AbstractVector{<:Real}, - y ::AbstractVector{<:Real}, - y_refs::AbstractVector{<:fmi2ValueReference}, - x ::AbstractVector{<:Real}, - u ::AbstractVector{<:Real}, - u_refs::AbstractVector{<:fmi2ValueReference}, - p ::AbstractVector{<:ForwardDiff.Dual}, - p_refs::AbstractVector{<:fmi2ValueReference}, - t ::Real) - -@grad_from_chainrules eval!(cRef::UInt64, - dx ::AbstractVector{<:Real}, - y ::AbstractVector{<:Real}, - y_refs::AbstractVector{<:UInt32}, - x ::AbstractVector{<:Real}, - u ::AbstractVector{<:Real}, - u_refs::AbstractVector{<:UInt32}, - p ::AbstractVector{<:ReverseDiff.TrackedReal}, - p_refs::AbstractVector{<:UInt32}, - t ::Real) \ No newline at end of file From 9571d5805680f96ef93d8f81a38238925a047d49 Mon Sep 17 00:00:00 2001 From: TT Date: Mon, 6 Nov 2023 14:59:15 +0100 Subject: [PATCH 07/12] removed documentation action --- .github/workflows/Documentation.yml | 44 ----------------------------- README.md | 1 - 2 files changed, 45 deletions(-) delete mode 100644 .github/workflows/Documentation.yml diff --git a/.github/workflows/Documentation.yml b/.github/workflows/Documentation.yml deleted file mode 100644 index 24b6ca6..0000000 --- a/.github/workflows/Documentation.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: Documentation - -on: - pull_request: - push: - branches: - - main - paths: - - 'docs/**' - - 'README.md' - - '.github/workflows/Documentation.yml' - tags: - - '*' - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: "Check out repository" - uses: actions/checkout@v3 - with: - ref: main - - - name: "Copy readme" - - run: | - git fetch - cp ./README.md ./docs/src/index.md - - - name: "Set up Julia" - uses: julia-actions/setup-julia@v1 - with: - version: '1.6' - arch: x64 - - - name: "Install dependencies" - run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()' - - - name: "Build and deploy" - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # For authentication with GitHub Actions token - DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} # For authentication with SSH deploy key - run: julia --project=docs/ docs/make.jl diff --git a/README.md b/README.md index c0b8153..85e45ff 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,6 @@ [![Dev Docs](https://img.shields.io/badge/docs-dev-blue.svg)](https://ThummeTo.github.io/FMI.jl/dev) [![Run Tests](https://github.com/ThummeTo/FMIImport.jl/actions/workflows/Test.yml/badge.svg)](https://github.com/ThummeTo/FMIImport.jl/actions/workflows/Test.yml) -[![Build Docs](https://github.com/ThummeTo/FMIImport.jl/actions/workflows/Documentation.yml/badge.svg)](https://github.com/ThummeTo/FMIImport.jl/actions/workflows/Documentation.yml) [![Run PkgEval](https://github.com/ThummeTo/FMIImport.jl/actions/workflows/Eval.yml/badge.svg)](https://github.com/ThummeTo/FMIImport.jl/actions/workflows/Eval.yml) [![Coverage](https://codecov.io/gh/ThummeTo/FMIImport.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/ThummeTo/FMIImport.jl) [![ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://img.shields.io/badge/ColPrac-Contributor's%20Guide-blueviolet)](https://github.com/SciML/ColPrac) From 13cfa25404bab1f4652de4aa0bfd012e8d7fb59f Mon Sep 17 00:00:00 2001 From: Simon Exner Date: Thu, 9 Nov 2023 12:01:13 +0100 Subject: [PATCH 08/12] minor docstring fix --- src/FMI3/int.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/FMI3/int.jl b/src/FMI3/int.jl index ed33faa..a441620 100644 --- a/src/FMI3/int.jl +++ b/src/FMI3/int.jl @@ -1749,7 +1749,6 @@ function fmi3SetClock(c::FMU3Instance, vr::fmi3ValueReferenceFormat, values::Uni end """ - fmi3GetFMUState(c::FMU3Instance) Makes a copy of the internal FMU state and returns a pointer to this copy. From 6ac2460e32d60e66788da21eb6fb5edc2407ca7c Mon Sep 17 00:00:00 2001 From: Simon Exner <43469235+0815Creeper@users.noreply.github.com> Date: Fri, 23 Aug 2024 15:09:07 +0200 Subject: [PATCH 09/12] docstring fixes: fmi2FreeFMUstate! no longer exists --- src/FMI2/c.jl | 2 +- src/FMI2/int.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/FMI2/c.jl b/src/FMI2/c.jl index 20bb5b6..86485a7 100644 --- a/src/FMI2/c.jl +++ b/src/FMI2/c.jl @@ -955,7 +955,7 @@ More detailed: - FMISpec2.0.2[p.16]: 2.1.3 Status Returned by Functions - FMISpec2.0.2[p.25]: 2.1.8 Getting and Setting the Complete FMU State -See also [`fmi2FreeFMUstate!`](@ref). +See also [`fmi2FreeFMUstate`](@ref). """ function fmi2FreeFMUstate!(c::FMU2Component, FMUstate::Ref{fmi2FMUstate}) diff --git a/src/FMI2/int.jl b/src/FMI2/int.jl index 0549383..3d753f4 100644 --- a/src/FMI2/int.jl +++ b/src/FMI2/int.jl @@ -641,7 +641,7 @@ Free the memory for the allocated FMU state - FMISpec2.0.2[p.16]: 2.1.3 Status Returned by Functions - FMISpec2.0.2[p.25]: 2.1.8 Getting and Setting the Complete FMU State -See also [`fmi2FreeFMUstate!`](@ref). +See also [`fmi2FreeFMUstate`](@ref). """ function fmi2FreeFMUstate!(c::FMU2Component, state::fmi2FMUstate) stateRef = Ref(state) From bd2ad827529ee21b92644889f6e70abba90f9fa0 Mon Sep 17 00:00:00 2001 From: Simon Exner <43469235+0815Creeper@users.noreply.github.com> Date: Fri, 23 Aug 2024 15:20:23 +0200 Subject: [PATCH 10/12] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index edfb51b..07ca224 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # FMIImport.jl ## What is FMIImport.jl? -[*FMIImport.jl*](https://github.com/ThummeTo/FMIImport.jl) implements the import functionalities of the FMI-standard ([fmi-standard.org](http://fmi-standard.org/)) for the Julia programming language. +[*FMIImport.jl*](https://github.com/ThummeTo/FMIImport.jl) implements the import functionalities of the FMI-standard ([fmi-standard.org](https://fmi-standard.org/)) for the Julia programming language. [*FMIImport.jl*](https://github.com/ThummeTo/FMIImport.jl) provides the foundation for the Julia packages [*FMI.jl*](https://github.com/ThummeTo/FMI.jl) and [*FMIFlux.jl*](https://github.com/ThummeTo/FMIFlux.jl). From 5e8e044ecbad537126fe939cb6d3b00f713514fd Mon Sep 17 00:00:00 2001 From: Simon Exner <43469235+0815Creeper@users.noreply.github.com> Date: Fri, 23 Aug 2024 15:23:43 +0200 Subject: [PATCH 11/12] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 07ca224..897f8e9 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,10 @@ [*FMIImport.jl*](https://github.com/ThummeTo/FMIImport.jl) provides the foundation for the Julia packages [*FMI.jl*](https://github.com/ThummeTo/FMI.jl) and [*FMIFlux.jl*](https://github.com/ThummeTo/FMIFlux.jl). -[![Dev Docs](https://img.shields.io/badge/docs-dev-blue.svg)](https://ThummeTo.github.io/FMI.jl/dev) +[![Dev Docs](https://img.shields.io/badge/docs-dev-blue.svg)](https://thummeto.github.io/FMI.jl/dev/) [![Run Tests](https://github.com/ThummeTo/FMIImport.jl/actions/workflows/Test.yml/badge.svg)](https://github.com/ThummeTo/FMIImport.jl/actions/workflows/Test.yml) [![Run PkgEval](https://github.com/ThummeTo/FMIImport.jl/actions/workflows/Eval.yml/badge.svg)](https://github.com/ThummeTo/FMIImport.jl/actions/workflows/Eval.yml) -[![Coverage](https://codecov.io/gh/ThummeTo/FMIImport.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/ThummeTo/FMIImport.jl) +[![Coverage](https://app.codecov.io/gh/ThummeTo/FMIImport.jl/branch/main/graph/badge.svg)](https://app.codecov.io/gh/ThummeTo/FMIImport.jl) [![ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://img.shields.io/badge/ColPrac-Contributor's%20Guide-blueviolet)](https://github.com/SciML/ColPrac) [![SciML Code Style](https://img.shields.io/static/v1?label=code%20style&message=SciML&color=9558b2&labelColor=389826)](https://github.com/SciML/SciMLStyle) From 7d3b4d5b569d810dd63c2f9346550ad07e4d6ebf Mon Sep 17 00:00:00 2001 From: Simon Exner <43469235+0815Creeper@users.noreply.github.com> Date: Fri, 23 Aug 2024 15:30:10 +0200 Subject: [PATCH 12/12] fixes README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 897f8e9..41b51d8 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ [![Dev Docs](https://img.shields.io/badge/docs-dev-blue.svg)](https://thummeto.github.io/FMI.jl/dev/) [![Run Tests](https://github.com/ThummeTo/FMIImport.jl/actions/workflows/Test.yml/badge.svg)](https://github.com/ThummeTo/FMIImport.jl/actions/workflows/Test.yml) [![Run PkgEval](https://github.com/ThummeTo/FMIImport.jl/actions/workflows/Eval.yml/badge.svg)](https://github.com/ThummeTo/FMIImport.jl/actions/workflows/Eval.yml) -[![Coverage](https://app.codecov.io/gh/ThummeTo/FMIImport.jl/branch/main/graph/badge.svg)](https://app.codecov.io/gh/ThummeTo/FMIImport.jl) +[![Coverage](https://codecov.io/gh/ThummeTo/FMIImport.jl/branch/main/graph/badge.svg)](https://app.codecov.io/gh/ThummeTo/FMIImport.jl) [![ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://img.shields.io/badge/ColPrac-Contributor's%20Guide-blueviolet)](https://github.com/SciML/ColPrac) [![SciML Code Style](https://img.shields.io/static/v1?label=code%20style&message=SciML&color=9558b2&labelColor=389826)](https://github.com/SciML/SciMLStyle)