diff --git a/docs/make.jl b/docs/make.jl index 7e71a28f..62228d1c 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -3,7 +3,7 @@ # Licensed under the MIT license. See LICENSE file in the project root for details. # -using Documenter, FMI, Plots, FMIImport +using Documenter, FMI, Plots, FMIImport, FMICore using Documenter: GitHubActions makedocs(sitename="FMI.jl", @@ -11,8 +11,10 @@ makedocs(sitename="FMI.jl", collapselevel = 1, sidebar_sitename = false, edit_link = nothing, - size_threshold_ignore = ["fmi2_library.md"] + size_threshold_ignore = ["fmi_import_library.md","fmi2_import_library.md","fmi3_import_library.md"] ), + modules = [FMI, FMIImport, FMICore],#, FMIBuild] + checkdocs=:none,#:exports, warnonly=true, pages= Any[ "Introduction" => "index.md" @@ -28,9 +30,17 @@ makedocs(sitename="FMI.jl", "Multithreading" => "examples/multithreading.md" "Multiprocessing" => "examples/multiprocessing.md" ] - "Developer Level API" => "fmi2_library.md" - #"" => "fmi3_library.md" "User Level API" => "library.md" + "Developer Level API" => Any[ + #"fmi_import_library.md", + "fmi2_import_library.md", + "fmi3_import_library.md" + ] + "Foundation Level API" => Any[ + #"fmi_core_library.md", + "fmi2_core_library.md", + "fmi3_core_library.md" + ] "Related Publication" => "related.md" "Contents" => "contents.md" ] diff --git a/docs/src/fmi2_library.md b/docs/src/fmi2_library.md deleted file mode 100644 index 40cd8c94..00000000 --- a/docs/src/fmi2_library.md +++ /dev/null @@ -1,256 +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. - -```@docs -FMU2 -FMU2Component -fmi2Struct -``` - -### 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! -``` - -## additional 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 9d2d27ef..00000000 --- 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/library.md b/docs/src/library.md index acb5e3f3..93ed1407 100644 --- a/docs/src/library.md +++ b/docs/src/library.md @@ -30,3 +30,22 @@ fmiInfo ```@docs fmiPlot ``` + +# FMI2 specific + +```@docs +fmi2Info +fmi2Simulate +fmi2SimulateME +fmi2SimulateCS +``` + +# FMI3 specific + +```@docs +fmi3Info +fmi3Simulate +fmi3SimulateME +fmi3SimulateSE +fmi3SimulateCS +``` \ No newline at end of file diff --git a/src/FMI.jl b/src/FMI.jl index 1cb63135..16508965 100644 --- a/src/FMI.jl +++ b/src/FMI.jl @@ -107,6 +107,8 @@ export FMU3ExecutionConfiguration, FMU3_EXECUTION_CONFIGURATION_RESET, FMU3_EXEC using FMIImport: prepareValue, prepareValueReference export fmi2Real, fmi2Integer, fmi2String, fmi2Enumeration, fmi2Boolean +export fmi2Info, fmi3Info +export fmi2GetDependencies, fmi3GetDependencies include("check.jl") @@ -1329,6 +1331,8 @@ function fmiGetReal(str::fmi3Struct, args...; kwargs...) fmi3GetReal(str, args...; kwargs...) end +export fmiGetReal + """ fmiSampleJacobian(str::fmi2Struct, c::FMU2Component, diff --git a/src/FMI2/sim.jl b/src/FMI2/sim.jl index db843b72..7db0e27d 100644 --- a/src/FMI2/sim.jl +++ b/src/FMI2/sim.jl @@ -295,6 +295,30 @@ function setupODEProblem(c::FMU2Component, x0::AbstractArray{fmi2Real}, tspan::U end """ +function fmi2SimulateME(fmu::FMU2, c::Union{FMU2Component, Nothing}=nothing, tspan::Union{Tuple{Float64, Float64}, Nothing}=nothing; + tolerance::Union{Real, Nothing} = nothing, + dt::Union{Real, Nothing} = nothing, + solver = nothing, + customFx = nothing, + recordValues::fmi2ValueReferenceFormat = nothing, + recordEventIndicators::Union{AbstractArray{<:Integer, 1}, UnitRange{<:Integer}, Nothing} = nothing, + recordEigenvalues::Bool=false, + saveat = nothing, + x0::Union{AbstractArray{<:Real}, Nothing} = nothing, + setup::Union{Bool, Nothing} = nothing, + reset::Union{Bool, Nothing} = nothing, + instantiate::Union{Bool, Nothing} = nothing, + freeInstance::Union{Bool, Nothing} = nothing, + terminate::Union{Bool, Nothing} = nothing, + inputValueReferences::fmi2ValueReferenceFormat = nothing, + inputFunction = nothing, + parameters::Union{Dict{<:Any, <:Any}, Nothing} = nothing, + dtmax::Union{Real, Nothing} = nothing, + callbacksBefore = [], + callbacksAfter = [], + showProgress::Bool = true, + kwargs...) + ToDo: Update DocString Simulates a FMU instance for the given simulation time interval. @@ -586,6 +610,8 @@ function fmi2SimulateME(fmu::FMU2, c::Union{FMU2Component, Nothing}=nothing, tsp return fmusol end +export fmi2SimulateME + # function fmi2SimulateME(fmu::FMU2, # c::Union{AbstractArray{<:Union{FMU2Component, Nothing}}, Nothing}=nothing, tspan::Union{Tuple{Float64, Float64}, Nothing}=nothing; # x0::Union{AbstractArray{<:AbstractArray{<:Real}}, AbstractArray{<:Real}, Nothing} = nothing, @@ -603,6 +629,21 @@ end ############ Co-Simulation ############ """ + fmi2SimulateCS(fmu::FMU2, c::Union{FMU2Component, Nothing}=nothing, tspan::Union{Tuple{Float64, Float64}, Nothing}=nothing; + tolerance::Union{Real, Nothing} = nothing, + dt::Union{Real, Nothing} = nothing, + recordValues::fmi2ValueReferenceFormat = nothing, + saveat = [], + setup::Union{Bool, Nothing} = nothing, + reset::Union{Bool, Nothing} = nothing, + instantiate::Union{Bool, Nothing} = nothing, + freeInstance::Union{Bool, Nothing} = nothing, + terminate::Union{Bool, Nothing} = nothing, + inputValueReferences::fmi2ValueReferenceFormat = nothing, + inputFunction = nothing, + showProgress::Bool=true, + parameters::Union{Dict{<:Any, <:Any}, Nothing} = nothing) + Starts a simulation of the Co-Simulation FMU instance. Via the optional keyword arguments `inputValues` and `inputFunction`, a custom input function `f(c, t)` or `f(t)` with time `t` and component `c` can be defined, that should return a array of values for `fmi2SetReal(..., inputValues, inputFunction(...))`. @@ -774,6 +815,8 @@ function fmi2SimulateCS(fmu::FMU2, c::Union{FMU2Component, Nothing}=nothing, tsp return fmusol end +export fmi2SimulateCS + ##### CS & ME ##### # wrapper @@ -790,6 +833,7 @@ end # end """ +fmi2Simulate(fmu::FMU2, c::Union{FMU2Component, Nothing}=nothing, tspan::Union{Tuple{Float64, Float64}, Nothing}=nothing; kwargs...) Starts a simulation of the FMU instance for the matching FMU type, if both types are available, CS is preferred. Keywords: @@ -818,3 +862,5 @@ function fmi2Simulate(fmu::FMU2, c::Union{FMU2Component, Nothing}=nothing, tspan error(unknownFMUType) end end + +export fmi2Simulate \ No newline at end of file diff --git a/src/FMI3/sim.jl b/src/FMI3/sim.jl index 2eeb2301..48a2a29f 100644 --- a/src/FMI3/sim.jl +++ b/src/FMI3/sim.jl @@ -811,6 +811,26 @@ function setupODEProblem(c::FMU3Instance, x0::AbstractArray{fmi3Float64}, t_star end """ +fmi3SimulateME(fmu::FMU3, c::Union{FMU3Instance, Nothing}=nothing, t_start::Union{Real, Nothing} = nothing, t_stop::Union{Real, Nothing} = nothing; + tolerance::Union{Real, Nothing} = nothing, + dt::Union{Real, Nothing} = nothing, + solver = nothing, + customFx = nothing, + recordValues::fmi3ValueReferenceFormat = nothing, + saveat = nothing, + x0::Union{AbstractArray{<:Real}, Nothing} = nothing, + setup::Union{Bool, Nothing} = nothing, + reset::Union{Bool, Nothing} = nothing, + instantiate::Union{Bool, Nothing} = nothing, + freeInstance::Union{Bool, Nothing} = nothing, + terminate::Union{Bool, Nothing} = nothing, + inputValueReferences::fmi3ValueReferenceFormat = nothing, + inputFunction = nothing, + parameters::Union{Dict{<:Any, <:Any}, Nothing} = nothing, + dtmax::Union{Real, Nothing} = nothing, + callbacks = [], + showProgress::Bool = true, + kwargs...) Simulates a FMU instance for the given simulation time interval. State- and Time-Events are handled correctly. @@ -1033,6 +1053,8 @@ function fmi3SimulateME(fmu::FMU3, c::Union{FMU3Instance, Nothing}=nothing, t_st return fmusol end +export fmi3SimulateME + # wrapper function fmi3SimulateCS(c::FMU3Instance, t_start::Union{Real, Nothing} = nothing, t_stop::Union{Real, Nothing} = nothing; kwargs...) @@ -1042,6 +1064,21 @@ end ############ Co-Simulation ############ """ +fmi3SimulateCS(fmu::FMU3, c::Union{FMU3Instance, Nothing}=nothing, t_start::Union{Real, Nothing} = nothing, t_stop::Union{Real, Nothing} = nothing; + tolerance::Union{Real, Nothing} = nothing, + dt::Union{Real, Nothing} = nothing, + recordValues::fmi3ValueReferenceFormat = nothing, + saveat = [], + setup::Union{Bool, Nothing} = nothing, + reset::Union{Bool, Nothing} = nothing, + instantiate::Union{Bool, Nothing} = nothing, + freeInstance::Union{Bool, Nothing} = nothing, + terminate::Union{Bool, Nothing} = nothing, + inputValueReferences::fmi3ValueReferenceFormat = nothing, + inputFunction = nothing, + showProgress::Bool=true, + parameters::Union{Dict{<:Any, <:Any}, Nothing} = nothing) + Starts a simulation of the Co-Simulation FMU instance. Via the optional keyword arguments `inputValues` and `inputFunction`, a custom input function `f(c, t)` or `f(t)` with time `t` and instance `c` can be defined, that should return a array of values for `fmi3SetFloat64(..., inputValues, inputFunction(...))`. @@ -1231,7 +1268,27 @@ function fmi3SimulateCS(fmu::FMU3, c::Union{FMU3Instance, Nothing}=nothing, t_st return fmusol end +export fmi3SimulateCS + # TODO simulate ScheduledExecution +""" +fmi3SimulateSE(fmu::FMU3, c::Union{FMU3Instance, Nothing}=nothing, t_start::Union{Real, Nothing} = nothing, t_stop::Union{Real, Nothing} = nothing; + tolerance::Union{Real, Nothing} = nothing, + dt::Union{Real, Nothing} = nothing, + recordValues::fmi3ValueReferenceFormat = nothing, + saveat = [], + setup::Union{Bool, Nothing} = nothing, + reset::Union{Bool, Nothing} = nothing, + instantiate::Union{Bool, Nothing} = nothing, + freeInstance::Union{Bool, Nothing} = nothing, + terminate::Union{Bool, Nothing} = nothing, + inputValueReferences::fmi3ValueReferenceFormat = nothing, + inputFunction = nothing, + showProgress::Bool=true, + parameters::Union{Dict{<:Any, <:Any}, Nothing} = nothing) +TODO simulate ScheduledExecution +not yet implemented in library +""" function fmi3SimulateSE(fmu::FMU3, c::Union{FMU3Instance, Nothing}=nothing, t_start::Union{Real, Nothing} = nothing, t_stop::Union{Real, Nothing} = nothing; tolerance::Union{Real, Nothing} = nothing, dt::Union{Real, Nothing} = nothing, @@ -1248,6 +1305,8 @@ function fmi3SimulateSE(fmu::FMU3, c::Union{FMU3Instance, Nothing}=nothing, t_st parameters::Union{Dict{<:Any, <:Any}, Nothing} = nothing) @assert false "Not implemented" end +export fmi3SimulateSE + ##### CS & ME ##### # wrapper @@ -1256,7 +1315,8 @@ function fmi3Simulate(c::FMU3Instance, t_start::Union{Real, Nothing} = nothing, end """ -Starts a simulation of the FMU instance for the matching FMU type, if both types are available, CS is preferred. +fmi3Simulate(fmu::FMU3, c::Union{FMU3Instance, Nothing}=nothing, t_start::Union{Real, Nothing} = nothing, t_stop::Union{Real, Nothing} = nothing; kwargs...) +Starts a simulation of the FMU instance for the matching FMU type, if multiple types are available, CS is preferred over ME, over SE. Keywords: - recordValues: Array of variables (strings or variableIdentifiers) to record. Results are returned as `DiffEqCallbacks.SavedValues` @@ -1264,9 +1324,9 @@ Keywords: - reset: Boolean, if FMU should be reset before simulation (default reset=setup) - inputValues: Array of input variables (strings or variableIdentifiers) to set at every simulation step - inputFunction: Function to retrieve the values to set the inputs to - - saveat: [ME only] Time points to save values at (interpolated) - - solver: [ME only] Any Julia-supported ODE-solver (default is Tsit5) - - customFx: [ME only, deperecated] Ability to give a custom state derivative function ẋ=f(x,t) + - saveat: Time points to save values at (interpolated) + - solver: Any Julia-supported ODE-solver (default is default from DifferentialEquations.jl) + - customFx: [ME only, deprecated] Ability to give a custom state derivative function ẋ=f(x,t) Returns: - `success::Bool` for CS-FMUs @@ -1286,3 +1346,5 @@ function fmi3Simulate(fmu::FMU3, c::Union{FMU3Instance, Nothing}=nothing, t_star error(unknownFMUType) end end + +export fmi3Simulate