Skip to content

Commit

Permalink
v1.0.0 (#63)
Browse files Browse the repository at this point in the history
* refactoring for FMIBase.jl

* PkgEval test

* WIP
  • Loading branch information
ThummeTo committed Apr 17, 2024
1 parent 8c266ef commit f8b9874
Show file tree
Hide file tree
Showing 26 changed files with 369 additions and 3,142 deletions.
6 changes: 1 addition & 5 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
name = "FMICore"
uuid = "8af89139-c281-408e-bce2-3005eb87462f"
authors = ["TT <tobias.thummerer@informatik.uni-augsburg.de>", "LM <lars.mikelsons@informatik.uni-augsburg.de>", "JK <josef.kircher@student.uni-augsburg.de>"]
version = "0.20.1"
version = "1.0.0"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"

[compat]
ChainRulesCore = "1.16"
Dates = "1"
Requires = "1.3.0"
julia = "1.6"
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

## What is FMICore.jl?
[*FMICore.jl*](https://github.com/ThummeTo/FMICore.jl) implements the low-level equivalents of the C-functions and C-data types of the FMI-standard ([fmi-standard.org](http://fmi-standard.org/)) for the Julia programming language.
[*FMICore.jl*](https://github.com/ThummeTo/FMICore.jl) provides the foundation for the Julia packages [*FMIImport.jl*](https://github.com/ThummeTo/FMIImport.jl) and [*FMIExport.jl*](https://github.com/ThummeTo/FMIExport.jl).

[![Dev Docs](https://img.shields.io/badge/docs-dev-blue.svg)](https://ThummeTo.github.io/FMI.jl/dev)
[![Run Tests](https://github.com/ThummeTo/FMICore.jl/actions/workflows/Test.yml/badge.svg)](https://github.com/ThummeTo/FMICore.jl/actions/workflows/Test.yml)
Expand Down Expand Up @@ -31,14 +30,15 @@ To keep dependencies nice and clean, the original package [*FMI.jl*](https://git
- [*FMI.jl*](https://github.com/ThummeTo/FMI.jl): High level loading, manipulating, saving or building entire FMUs from scratch
- [*FMIImport.jl*](https://github.com/ThummeTo/FMIImport.jl): Importing FMUs into Julia
- [*FMIExport.jl*](https://github.com/ThummeTo/FMIExport.jl): Exporting stand-alone FMUs from Julia Code
- [*FMIBase.jl*](https://github.com/ThummeTo/FMIBase.jl): Common concepts for import and export of FMUs
- [*FMICore.jl*](https://github.com/ThummeTo/FMICore.jl): C-code wrapper for the FMI-standard
- [*FMISensitivity.jl*](https://github.com/ThummeTo/FMISensitivity.jl): Static and dynamic sensitivities over FMUs
- [*FMIBuild.jl*](https://github.com/ThummeTo/FMIBuild.jl): Compiler/Compilation dependencies for FMIExport.jl
- [*FMIFlux.jl*](https://github.com/ThummeTo/FMIFlux.jl): Machine Learning with FMUs (differentiation over FMUs)
- [*FMIFlux.jl*](https://github.com/ThummeTo/FMIFlux.jl): Machine Learning with FMUs
- [*FMIZoo.jl*](https://github.com/ThummeTo/FMIZoo.jl): A collection of testing and example FMUs

## What Platforms are supported?
[*FMICore.jl*](https://github.com/ThummeTo/FMICore.jl) is tested (and testing) under Julia Versions *v1.6 LTS* and *v1 latest* on Windows *latest*, Ubuntu *latest* and MacOS *latest*. `x64` and `x86` architectures are tested.
[*FMICore.jl*](https://github.com/ThummeTo/FMICore.jl) is tested (and testing) under Julia Versions *v1.6 LTS* and *v1 latest* on Windows *latest* (`x64` and `x86`) and Ubuntu *latest* (`x64`). MacOS is not CI-tested but should work with Mac-FMUs.

## How to cite?
Tobias Thummerer, Lars Mikelsons and Josef Kircher. 2021. **NeuralFMU: towards structural integration of FMUs into neural networks.** Martin Sjölund, Lena Buffoni, Adrian Pop and Lennart Ochel (Ed.). Proceedings of 14th Modelica Conference 2021, Linköping, Sweden, September 20-24, 2021. Linköping University Electronic Press, Linköping (Linköping Electronic Conference Proceedings ; 181), 297-306. [DOI: 10.3384/ecp21181297](https://doi.org/10.3384/ecp21181297)
Expand Down
57 changes: 20 additions & 37 deletions src/FMI2/cconst.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,6 @@ const fmi2Component = Ptr{Cvoid}
const fmi2ComponentEnvironment = Ptr{Cvoid}
export fmi2Char, fmi2String, fmi2Boolean, fmi2Real, fmi2Integer, fmi2Byte, fmi2ValueReference, fmi2FMUstate, fmi2Component, fmi2ComponentEnvironment

# wildcards for how a user can pass a fmi2ValueReference
fmi2ValueReferenceFormat = Union{Nothing, String, AbstractArray{String,1}, fmi2ValueReference, AbstractArray{fmi2ValueReference,1}, Int64, AbstractArray{Int64,1}, Symbol}
export fmi2ValueReferenceFormat

const fmi2Status = Cuint
const fmi2StatusOK = Cuint(0)
const fmi2StatusWarning = Cuint(1)
const fmi2StatusDiscard = Cuint(2)
const fmi2StatusError = Cuint(3)
const fmi2StatusFatal = Cuint(4)
const fmi2StatusPending = Cuint(5)

"""
Source: FMISpec2.0.2[p.18]: 2.1.3 Status Returned by Functions
Expand All @@ -60,7 +48,13 @@ This can be done if the capability flag canGetAndSetFMUstate is true and fmi2Get
- fmi2Fatal – the model computations are irreparably corrupted for all FMU instances. [For example, due to a run-time exception such as access violation or integer division by zero during the execution of an fmi function]. Function “logger” was called in the FMU (see below), and it is expected that this function has shown the prepared information message to the user. It is not possible to call any other function for any of the FMU instances.
- fmi2Pending – this status is returned only from the co-simulation interface, if the slave executes the function in an asynchronous way. That means the slave starts to compute but returns immediately. The master has to call fmi2GetStatus(..., fmi2DoStepStatus) to determine if the slave has finished the computation. Can be returned only by fmi2DoStep and by fmi2GetStatus (see section 4.2.3).
"""
fmi2Status, fmi2StatusOK, fmi2StatusWarning, fmi2StatusDiscard, fmi2StatusError, fmi2StatusFatal, fmi2StatusPending
const fmi2Status = Cuint
const fmi2StatusOK = Cuint(0)
const fmi2StatusWarning = Cuint(1)
const fmi2StatusDiscard = Cuint(2)
const fmi2StatusError = Cuint(3)
const fmi2StatusFatal = Cuint(4)
const fmi2StatusPending = Cuint(5)
export fmi2Status, fmi2StatusOK, fmi2StatusWarning, fmi2StatusDiscard, fmi2StatusError, fmi2StatusFatal, fmi2StatusPending

"""
Expand Down Expand Up @@ -126,17 +120,24 @@ const fmi2InitialApprox = Cuint(1)
const fmi2InitialCalculated = Cuint(2)
export fmi2Initial, fmi2InitialExact, fmi2InitialApprox, fmi2InitialCalculated

const fmi2True = fmi2Boolean(true)
const fmi2False = fmi2Boolean(false)
"""
Source: FMISpec2.0.2[p.16]: 2.1.2 Platform Dependent Definitions
To simplify porting, no C types are used in the function interfaces, but the alias types are defined in this section.
All definitions in this section are provided in the header file “fmi2TypesPlatform.h”.
"""
fmi2True, fmi2False
const fmi2True = fmi2Boolean(true)
const fmi2False = fmi2Boolean(false)
export fmi2True, fmi2False

"""
ToDo
"""
const fmi2VariableNamingConvention = Cuint
const fmi2VariableNamingConventionFlat = Cuint(0)
const fmi2VariableNamingConventionStructured = Cuint(1)
export fmi2VariableNamingConvention, fmi2VariableNamingConventionFlat, fmi2VariableNamingConventionStructured

"""
Source: FMISpec2.0.2[p.19]: 2.1.5 Creation, Destruction and Logging of FMU Instances
Expand All @@ -161,14 +162,14 @@ const fmi2StatusKindLastSuccessfulTime = Cuint(2)
const fmi2StatusKindTerminated = Cuint(3)
export fmi2StatusKind, fmi2StatusKindDoStepStatus, fmi2StatusKindPendingStatus, fmi2StatusKindLastSuccessfulTime, fmi2StatusKindTerminated

# Custom helper, not part of the FMI-Spec.
"""
Types of dependency:
- `fmi2DependencyKindDependent`: no particular structure, f(v)
- `fmi2DependencyKindConstant`: constant factor, c*v (for Real valued variables only)
- `fmi2DependencyKindFixed`: tunable factor, p*v (for Real valued variables only)
- `fmi2DependencyKindDependent`: discrete factor, d*v (for Real valued variables only)
- `fmi2DependencyKindTunable` [ToDo]
- `fmi2DependencyKindDiscrete` [ToDo]
Source: FMI2.0.3 Spec for fmi2VariableDependency [p.60]
"""
Expand All @@ -178,22 +179,4 @@ const fmi2DependencyKindConstant = Cuint(1)
const fmi2DependencyKindFixed = Cuint(2)
const fmi2DependencyKindTunable = Cuint(3)
const fmi2DependencyKindDiscrete = Cuint(4)
export fmi2DependencyKind, fmi2DependencyKindDependent, fmi2DependencyKindConstant, fmi2DependencyKindFixed, fmi2DependencyKindTunable, fmi2DependencyKindDiscrete

# Custom helper, not part of the FMI-Spec.
const fmi2VariableNamingConvention = Cuint
const fmi2VariableNamingConventionFlat = Cuint(0)
const fmi2VariableNamingConventionStructured = Cuint(1)
export fmi2VariableNamingConvention, fmi2VariableNamingConventionFlat, fmi2VariableNamingConventionStructured

# this is a custom type to catch the internal mode of the component
const fmi2ComponentState = Cuint
const fmi2ComponentStateInstantiated = Cuint(0) # after instantiation
const fmi2ComponentStateInitializationMode = Cuint(1) # after finishing initialization
const fmi2ComponentStateEventMode = Cuint(2)
const fmi2ComponentStateContinuousTimeMode = Cuint(3)
const fmi2ComponentStateTerminated = Cuint(4)
const fmi2ComponentStateError = Cuint(5)
const fmi2ComponentStateFatal = Cuint(6)
export fmi2ComponentState, fmi2ComponentStateInstantiated, fmi2ComponentStateInitializationMode, fmi2ComponentStateEventMode, fmi2ComponentStateContinuousTimeMode, fmi2ComponentStateTerminated, fmi2ComponentStateError, fmi2ComponentStateFatal

export fmi2DependencyKind, fmi2DependencyKindDependent, fmi2DependencyKindConstant, fmi2DependencyKindFixed, fmi2DependencyKindTunable, fmi2DependencyKindDiscrete
10 changes: 5 additions & 5 deletions src/FMI2/cfunc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ If a null pointer is provided for “c”, the function call is ignored (does no
Removes the component from the FMUs component list.
"""
function fmi2FreeInstance!(cfunc::Ptr{Cvoid}, c::fmi2Component)
function fmi2FreeInstance(cfunc::Ptr{Cvoid}, c::fmi2Component)

ccall(cfunc, Cvoid, (fmi2Component,), c)
@debug "fmi2FreeInstance(c: $(c)) → [nothing]"
return nothing
end
export fmi2FreeInstance!
export fmi2FreeInstance

"""
Source: FMISpec2.0.2[p.22]: 2.1.4 Inquire Platform and Version Number of Header Files
Expand Down Expand Up @@ -320,15 +320,15 @@ Source: FMISpec2.0.2[p.26]: 2.1.8 Getting and setting the complete FMU state
fmi2FreeFMUstate frees all memory and other resources allocated with the fmi2GetFMUstate call for this FMUstate.
"""
function fmi2FreeFMUstate!(cfunc::Ptr{Cvoid}, c::fmi2Component, FMUstate::Ref{fmi2FMUstate})
function fmi2FreeFMUstate(cfunc::Ptr{Cvoid}, c::fmi2Component, FMUstate::Ref{fmi2FMUstate})
status = ccall(cfunc,
fmi2Status,
(fmi2Component, Ptr{fmi2FMUstate}),
c, FMUstate)
@debug "fmi2FreeFMUstate!(c: $(c), FMUstate: $(FMUstate)) → $(status)"
@debug "fmi2FreeFMUstate(c: $(c), FMUstate: $(FMUstate)) → $(status)"
return status
end
export fmi2FreeFMUstate!
export fmi2FreeFMUstate

"""
Source: FMISpec2.0.2[p.26]: 2.1.8 Getting and Setting the Complete FMU State
Expand Down
3 changes: 2 additions & 1 deletion src/FMI2/cfunc_unload.jl
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,5 @@ function unload_fmi2GetNominalsOfContinuousStates(_component::fmi2Component, _x_
return fmi2StatusFatal
end

# ToDo: Add CS functions!
# ToDo: Add CS functions!
# ToDo: This shoudl be doable with a macro like @unloaded_version fmi2GetContinuousStates
Loading

2 comments on commit f8b9874

@ThummeTo
Copy link
Owner Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/105102

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

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

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

git tag -a v1.0.0 -m "<description of version>" f8b987474f84c5430a08f7bc151607ef14e56d61
git push origin v1.0.0

Please sign in to comment.