-
Notifications
You must be signed in to change notification settings - Fork 21
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
Open
riteshk001
wants to merge
9
commits into
master
Choose a base branch
from
node-fmu
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add new node-type FMU #1017
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
26b1d19
feat (node-fmu): New node fmu using FMI3.0
riteshk001 1923827
fix (node-fmu): Fix pre-commit and SPDX error
riteshk001 4c1c684
feat (node-fmu): Add yaml files for node fmu for documentation
riteshk001 ac2fcd5
fix (node-fmu): Fix SPDX author name for fmu node
riteshk001 9f4fe99
fix (node-fmu): Fix author in SPDX header
riteshk001 c5d692a
Trigger CI
al3xa23 2f6b5e9
Trigger CI with sign-off
al3xa23 dd5cbbb
fix (node-fmu): Fix fmu simulations with no input signals
riteshk001 e055d5e
Update copyrights, email, format
al3xa23 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: | ||
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 }, | ||
| ) | ||
| } | ||
| }, | ||
| 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" | ||
| }, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.