-
Notifications
You must be signed in to change notification settings - Fork 21
Add new FMU node-type #1017
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add new FMU node-type #1017
Changes from all commits
26b1d19
1923827
4c1c684
ac2fcd5
9f4fe99
c5d692a
2f6b5e9
dd5cbbb
e055d5e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # CMakeLists.txt. | ||
| # | ||
| # Author: Ritesh Karki <ritesh.karki@rwth-aachen.de> | ||
| # SPDX-FileCopyrightText: 2014-2026 Institute for Automation of Complex Power Systems, RWTH Aachen University | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| find_path(FMI_INCLUDE_DIR | ||
| NAMES fmilib.h | ||
| ) | ||
|
|
||
| find_library(FMI_LIBRARY fmilib | ||
| PATHS /usr/local/lib /usr/local/lib64 | ||
| ) | ||
|
|
||
| include(FindPackageHandleStandardArgs) | ||
| find_package_handle_standard_args(FMI DEFAULT_MSG FMI_LIBRARY FMI_INCLUDE_DIR) | ||
|
|
||
| mark_as_advanced(FMI_INCLUDE_DIR FMI_LIBRARY) | ||
|
|
||
| if(FMI_FOUND) | ||
| add_library(FMI SHARED IMPORTED) | ||
| set_target_properties(FMI PROPERTIES | ||
| IMPORTED_LOCATION "${FMI_LIBRARY}" | ||
| INTERFACE_INCLUDE_DIRECTORIES "${FMI_INCLUDE_DIR}" | ||
| ) | ||
| endif() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # yaml-language-server: $schema=http://json-schema.org/draft-07/schema | ||
| # SPDX-FileCopyrightText: 2014-2026 Institute for Automation of Complex Power Systems, RWTH Aachen University | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| --- | ||
| allOf: | ||
| - $ref: ../node_obj.yaml | ||
| - $ref: file.yaml |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,71 @@ | ||||||
| # yaml-language-server: $schema=http://json-schema.org/draft-07/schema | ||||||
| # SPDX-FileCopyrightText: 2014-2026 Institute for Automation of Complex Power Systems, RWTH Aachen University | ||||||
| # SPDX-License-Identifier: Apache-2.0 | ||||||
| --- | ||||||
| allOf: | ||||||
| - type: object | ||||||
| properties: | ||||||
| fmu_path: | ||||||
| format: uri | ||||||
| description: | | ||||||
| Specifies the URI to a FMU model | ||||||
|
|
||||||
| fmu_unpack_path: | ||||||
| format: uri | ||||||
| description: | | ||||||
| Specifies the URI to a directory which has the unpacked files of the FMU model (mainly the shared library and the modelDescription.xml for the model). | ||||||
|
|
||||||
| fmuWritefirst: | ||||||
| type: boolean | ||||||
| description: | | ||||||
| Specifies whether the model has to be writtem with input values before running. `true` denotes that the model should use the input values. `false` would make the model use default values instead. | ||||||
|
|
||||||
| startTime: | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| type: number | ||||||
| description: | | ||||||
| Specifies the start time for the simulation. Value has to be at least one `stepSize` lesser than `stopTime`. | ||||||
|
|
||||||
| stopTime: | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| type: number | ||||||
| description: | | ||||||
| Specifies the stop time for the simulation. The number of steps is calculated then by the difference between `startTime` and `stopTime` divided by the `stepSize`. | ||||||
|
|
||||||
| stepSize: | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| type: number | ||||||
| description: | | ||||||
| Specifies the stepSize for the simulation. Special care has to be taken to ensure that the value is equal to the value mantioned in modelDescription.xml. | ||||||
|
|
||||||
| in: | ||||||
| type: object | ||||||
| properties: | ||||||
| signals: | ||||||
| type: array | ||||||
| description: | | ||||||
| The input signals for the model have to be mentioned here as elements of an array while specifying the name (should be the same as that found in the modelDescription file) and the datatype. | ||||||
|
|
||||||
| **Example**: | ||||||
|
|
||||||
| ``` | ||||||
| signals = ( | ||||||
| {name = "In1", type = "float"}, | ||||||
| {name = "In2", type = "int"} | ||||||
| ) | ||||||
| ``` | ||||||
| out: | ||||||
| type: object | ||||||
| properties: | ||||||
| signals: | ||||||
| type: array | ||||||
| description: | | ||||||
| The output signals for the model have to be mentioned here as elements of an array while specifying the name (should be the same as that found in the modelDescription file) and the datatype. | ||||||
|
|
||||||
| **Example**: | ||||||
|
|
||||||
| ``` | ||||||
| signals = ( | ||||||
| {name = "Out1", type = "float"} | ||||||
| ) | ||||||
| ``` | ||||||
|
|
||||||
| - $ref: ../node_signals.yaml | ||||||
| - $ref: ../node.yaml | ||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,58 @@ | ||||||||||||||||||||||||||||||||||||||||||
| # SPDX-FileCopyrightText: 2014-2026 Institute for Automation of Complex Power Systems, RWTH Aachen University | ||||||||||||||||||||||||||||||||||||||||||
| # SPDX-License-Identifier: Apache-2.0 | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| nodes = { | ||||||||||||||||||||||||||||||||||||||||||
| file_output = { | ||||||||||||||||||||||||||||||||||||||||||
| type = "file" | ||||||||||||||||||||||||||||||||||||||||||
| # format = "csv" | ||||||||||||||||||||||||||||||||||||||||||
| uri = "/workspaces/node/fmu_temp/output.dat" | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| signal_node = { | ||||||||||||||||||||||||||||||||||||||||||
| type = "signal.v2" | ||||||||||||||||||||||||||||||||||||||||||
| rate = 100.0 | ||||||||||||||||||||||||||||||||||||||||||
| realtime = true | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| limit = 100 | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| in = { | ||||||||||||||||||||||||||||||||||||||||||
| signals = ( | ||||||||||||||||||||||||||||||||||||||||||
| { name = "sine1", signal = "sine", amplitude = 1, frequency = 100 }, | ||||||||||||||||||||||||||||||||||||||||||
| # { name = "in2", signal = "constant", amplitude = 1 }, | ||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+5
to
+24
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
The example configuration file is embedded into the documentation and should only contain the node that this example is for. Runnable examples aren't part of this repo. |
||||||||||||||||||||||||||||||||||||||||||
| fmu_node = { | ||||||||||||||||||||||||||||||||||||||||||
| type = "fmu" | ||||||||||||||||||||||||||||||||||||||||||
| # Path to FMU file (.fmu) | ||||||||||||||||||||||||||||||||||||||||||
| fmu_path = "/workspaces/node/fmu_temp/asine.fmu" | ||||||||||||||||||||||||||||||||||||||||||
| fmu_unpack_path = "/workspaces/node/fmu_temp/fmu_asine" | ||||||||||||||||||||||||||||||||||||||||||
| fmu_write_first = true | ||||||||||||||||||||||||||||||||||||||||||
| stop_Time = 10.0 | ||||||||||||||||||||||||||||||||||||||||||
| startTime = 0.0 | ||||||||||||||||||||||||||||||||||||||||||
| stepSize = 0.2 | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| in = { | ||||||||||||||||||||||||||||||||||||||||||
| signals = ( | ||||||||||||||||||||||||||||||||||||||||||
| { name = "in1", type = "float" } | ||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| out = { | ||||||||||||||||||||||||||||||||||||||||||
| signals = ( | ||||||||||||||||||||||||||||||||||||||||||
| { name = "out1", type = "float" }, | ||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| paths = ( | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| in = "signal_node", | ||||||||||||||||||||||||||||||||||||||||||
| out = "fmu_node" | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| in = "fmu_node", | ||||||||||||||||||||||||||||||||||||||||||
| out = "file_output" | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+48
to
+58
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
See above. |
||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /* Node type: Functional Mock-up Unit. | ||
| * | ||
| * Author: Ritesh Karki <ritesh.karki@rwth-aachen.de>, Jitpanu Maneeratpongsuk <jitpanu.maneeratpongsuk@rwth-aachen.de> | ||
| * SPDX-FileCopyrightText: 2026 Institute for Automation of Complex Power Systems, RWTH Aachen University | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| #pragma once | ||
|
|
||
| #include <ctime> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| #include <fmilib.h> | ||
|
|
||
| #include <villas/format.hpp> | ||
| #include <villas/node.hpp> | ||
|
|
||
| namespace villas { | ||
| namespace node { | ||
|
|
||
| // Forward declarations | ||
| struct Sample; | ||
|
|
||
| class FmuNode : public Node { | ||
| protected: | ||
| int parse(json_t *json) override; | ||
|
|
||
| int _read(struct Sample *smps[], unsigned cnt) override; | ||
| int _write(struct Sample *smps[], unsigned cnt) override; | ||
|
|
||
| bool writing_turn = true; | ||
| const char *path; | ||
| const char *unpack_path; | ||
|
|
||
| std::timespec ts; | ||
| pthread_mutex_t mutex; | ||
|
al3xa23 marked this conversation as resolved.
|
||
| pthread_cond_t cv; | ||
|
|
||
| fmi3_import_t *fmu; | ||
| jm_callbacks callbacks; | ||
| fmi_import_context_t *context; | ||
|
|
||
| public: | ||
| FmuNode(const uuid_t &id = {}, const std::string &name = ""); | ||
| struct fmu_signal { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Types/classes defined in villas-node are PascalCase. Rename |
||
| unsigned int ref = 0; | ||
| fmi3_base_type_enu_t type = fmi3_base_type_enu_t::fmi3_base_type_float64; | ||
| std::string name; | ||
| }; | ||
|
|
||
| std::vector<fmu_signal> signalIn; | ||
| std::vector<fmu_signal> signalOut; | ||
|
|
||
| int prepare() override; | ||
|
|
||
| int check() override; | ||
|
|
||
| int start() override; | ||
|
|
||
| int stop() override; | ||
|
|
||
| // ~FmuNode(); | ||
|
|
||
| private: | ||
| void parse_signal(json_t *json, bool in); | ||
| double currentTime = 0; | ||
| double stepSize = 0.1; | ||
| double stopTime = 0; | ||
| double startTime = 0; | ||
| bool stopTimeDef = false; | ||
| double nextTime = 0.0; | ||
| void get_vr(const char *var_name, fmi3_value_reference_t &ref, | ||
| fmi3_base_type_enu_t &type); | ||
| }; | ||
|
|
||
| } // namespace node | ||
| } // namespace villas | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.