FMI3 Types definitions - #808
davidhjp01 wants to merge 22 commits into
Conversation
Use FMI Library 3.0.4 and carry the repository CI/package updates needed by the FMI 3 stack.
Implement validated FMI 2 directional derivatives with a dedicated fixture, reference-FMU wiring, and contract tests.
Use FMI Library 3.0.4 and carry the repository CI/package updates needed by the FMI 3 stack.
Implement validated FMI 2 directional derivatives with a dedicated fixture, reference-FMU wiring, and contract tests.
Introduce the common exact type metadata, dimensions, declared-type structures, and owning variable-value model used by later FMI 3 layers.
Reject unsupported initial value types explicitly and recognize newly declared scalar types during metadata validation so the common value model remains buildable before later integration layers.
|
I'll review this one once #807 is done, in case there are changes which propagate to this PR. |
…metadata # Conflicts: # .github/workflows/ci-cmake.yml # include/cosim/fmi/v2/fmu.hpp # src/cosim/fmi/v2/fmu.cpp # tests/CMakeLists.txt # tests/fmi_v2_fmu_unittest.cpp
# Conflicts: # tests/CMakeLists.txt
restenb
left a comment
There was a problem hiding this comment.
Left some comments, but as far as I can see this covers the base FMI3 spec very well.
| std::vector<value_reference> outputReferences_; | ||
| std::vector<value_reference> derivativeReferences_; | ||
| std::vector<value_reference> initialUnknownReferences_; | ||
| std::vector<value_reference> continuousStateReferences_; |
There was a problem hiding this comment.
One thing that immediately confused me is that there is no /fmi/v3 with the actual implementation of a v3::fmu. If the intention was to just add the new type vocabulary in this PR that's still fine. But right now this PR is a large new API surface that immediately panics if anybody tries to use it.
There was a problem hiding this comment.
Yes, files in fmi/v3 will be added in the next PR.
| @@ -30,39 +33,81 @@ using value_reference = std::uint32_t; | |||
| /// Variable data types. | |||
| enum class variable_type | |||
There was a problem hiding this comment.
We can at least see that we are going from ~5 to ~15 types in this enum. This is used all over the code base in switch statements like this one from fixed_step_algorithm.cpp:
The switch only exists to pick the correct method to call e.g. target->set_real(ref, source->get_real(ref)). Maybe we can hide these details behind a type agnostic function or interface so we can instead just write something like target->set(c.target, source->get(c.source)) and do away with all the duplicate switch cases by hiding it inside that boundary. But we still want to know the type outside that interface, so the mechanism has to be thought through a bit.
There was a problem hiding this comment.
I think this will be addressed in the later PR
| enum class clock_interval_variability | ||
| { | ||
| /// No scheduling information is available. | ||
| unknown, |
There was a problem hiding this comment.
According to the Clock specs, unknown is not a valid type?
https://fmi-standard.org/docs/3.0/#Clock
There was a problem hiding this comment.
It is to keep consistent with what fmi-library implemented: https://github.com/modelon-community/fmi-library/blob/1599ab1e61eeb224db307a0d8893ee284168beff/src/Util/include/FMI3/fmi3_enums.h#L170
| struct variable_dimension | ||
| { | ||
| /// FMI value reference of the structural parameter. | ||
| value_reference structural_parameter = 0; |
There was a problem hiding this comment.
Per the spec https://fmi-standard.org/docs/3.0/#ModelVariables, it sounds like this can point either at a structural parameter or a constant UInt64. In either case the reference value is just used to determine the size, so a name like size_reference might be more appropriate?
There was a problem hiding this comment.
And a follow-up to the above, do we also need to model the constant option here, or is that OK to omit?
I think nearby in the code there was a fixed_variable_dimension or similar type?
There was a problem hiding this comment.
In schema, it is defined as valueReference (e.g. <Dimension valueReference="...">), so I think it would be good to preserve the naming.
There was a problem hiding this comment.
And a follow-up to the above, do we also need to model the
constantoption here, or is that OK to omit?I think nearby in the code there was a
fixed_variable_dimensionor similar type?
fixed_dimension is used for that purpose
| variable_type::uint32, | ||
| variable_type::int64, | ||
| variable_type::uint64, | ||
| variable_type::enumeration, |
There was a problem hiding this comment.
Elsewhere we have enumeration after string, for example in the variable_value_storage variant. Maybe we should stick to one ordering everywhere where the variable_types are in use.
| /// Variable data types. | ||
| enum class variable_type | ||
| { | ||
| /// FMI Float64. |
There was a problem hiding this comment.
A point to consider is whether we keep the legacy FMI2 names with us or not. Since FMI3 replaced e.g. real with float64, do we want to reflect that. Would require us to split variable_type implementations between FMI2 and FMI3 though.
There was a problem hiding this comment.
We can still have single variable_type, but define both that can be interchangeable.
Depends on PR #807
Summary
Extends the shared model-description layer with FMI 3 value types, arrays,
metadata, and detailed step outcomes while preserving existing FMI 1/2
behavior.
Changes
Clock.
values, and type-safe scalar/array storage.
variable_valuewith:flat_size()calculation.fixed_shape()to distinguish fixed arrays from arrays sized bystructural parameters.
step_result_info/step_outcomefor actual completion time, earlyreturn, event handling, termination requests, and retryability.
Compatibility and scope
importer and typed-access work.
operations.