-
Notifications
You must be signed in to change notification settings - Fork 20
Add new node-type FMU #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 node-type FMU #1017
Changes from all commits
26b1d19
1923827
4c1c684
ac2fcd5
9f4fe99
c5d692a
2f6b5e9
dd5cbbb
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 | ||
| # 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-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University | ||
|
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. Fix copyright years |
||
| # 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) | ||
|
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. End description consistently with a period |
||
|
|
||
| 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: | ||
| type: number | ||
| description: | | ||
| Specifies the start time for the simulation. Value has to be at least one `stepSize` lesser than `stopTime`. | ||
|
|
||
| stopTime: | ||
| 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: | ||
| 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,61 @@ | ||||||
| # SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University | ||||||
|
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. Fix copyright years |
||||||
| # SPDX-License-Identifier: Apache-2.0 | ||||||
|
|
||||||
| nodes = { | ||||||
| file_output = { | ||||||
| type = "file" | ||||||
| # format = "csv" | ||||||
| uri = "/workspaces/node/fmu_temp/output.dat" | ||||||
| out = { | ||||||
|
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. Is this empty section required? |
||||||
|
|
||||||
| } | ||||||
| }, | ||||||
|
|
||||||
| 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 }, | ||||||
| ) | ||||||
| } | ||||||
| }, | ||||||
| fmu_node = { | ||||||
| type = "fmu" | ||||||
| # Path to fmu file | ||||||
|
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
|
||||||
| fmu_path = "/workspaces/node/fmu_temp/asine.fmu" | ||||||
| fmu_unpack_path = "/workspaces/node/fmu_temp/fmu_asine" | ||||||
| fmu_writefirst = true | ||||||
|
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
|
||||||
| stopTime = 10.0 | ||||||
|
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
Please use consistent setting names. |
||||||
| startTime = 0.0 | ||||||
| stepSize = 0.2 | ||||||
|
|
||||||
| in = { | ||||||
| signals = ( | ||||||
| {name = "In1", type = "float"} | ||||||
|
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
|
||||||
| ) | ||||||
| } | ||||||
|
|
||||||
| out = { | ||||||
| signals = ( | ||||||
| {name = "Out1", type = "float"}, | ||||||
| ) | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| paths = ( | ||||||
| { | ||||||
| in = "signal_node", | ||||||
| out = "fmu_node" | ||||||
| }, | ||||||
| { | ||||||
| in = "fmu_node", | ||||||
| out = "file_output" | ||||||
| }, | ||||||
| ) | ||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,76 @@ | ||||||
| /* Node type: Functional Mock-up unit. | ||||||
|
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
|
||||||
| * | ||||||
| * Author: Ritesh Karki <ritesh.karki@rwth-aachen.de>, Jitpanu Maneeratpongsuk <jitpanu.maneeratpongsuk@rwth-aachen.de> | ||||||
| * SPDX-FileCopyrightText: 2025 Institute for Automation of Complex Power Systems, RWTH Aachen University | ||||||
|
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. Fix copyright years |
||||||
| * SPDX-License-Identifier: Apache-2.0 | ||||||
| */ | ||||||
| #pragma once | ||||||
|
|
||||||
| #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 writingTurn = true; | ||||||
|
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. Use consistent variable naming (check VILLAS coding conventions). |
||||||
| const char *path; | ||||||
| const char *unpack_path; | ||||||
|
|
||||||
| timespec ts; | ||||||
| pthread_mutex_t mutex; | ||||||
|
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. Can we use C++ threads? |
||||||
| 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 { | ||||||
| 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.
Please add a contact mail address