-
Notifications
You must be signed in to change notification settings - Fork 22
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
Open
riteshk001
wants to merge
4
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 FMU node-type #1017
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1b45a58
feat (node-fmu): Add new FMU node-type
riteshk001 75eee1f
fix (node-fmu): Remove duplicate FMI context allocation
riteshk001 06ca5d5
fix (node-fmu): Add missing Node::stop
riteshk001 718bdfe
fix (node-fmu): Fix tag version for git repos in deps.sh
riteshk001 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). | ||
|
|
||
| fmu_write_first: | ||
| 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. | ||
|
|
||
| start_time: | ||
| type: number | ||
| description: | | ||
| Specifies the start time for the simulation. Value has to be at least one `step_size` lesser than `stop_time`. | ||
|
|
||
| stop_time: | ||
| type: number | ||
| description: | | ||
| Specifies the stop time for the simulation. The number of steps is calculated then by the difference between `start_time` and `stop_time` divided by the `step_size`. | ||
|
|
||
| step_size: | ||
| type: number | ||
| description: | | ||
| Specifies the step size 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,27 @@ | ||
| # SPDX-FileCopyrightText: 2014-2026 Institute for Automation of Complex Power Systems, RWTH Aachen University | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| nodes = { | ||
| 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 | ||
| start_time = 0.0 | ||
| step_size = 0.2 | ||
|
|
||
| in = { | ||
| signals = ( | ||
| { name = "in1", type = "float" } | ||
| ) | ||
| } | ||
|
|
||
| out = { | ||
| signals = ( | ||
| { name = "out1", type = "float" }, | ||
| ) | ||
| } | ||
| } | ||
| } |
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,80 @@ | ||
| /* 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; | ||
|
|
||
| struct FmuSignal { | ||
| unsigned int ref = 0; | ||
| fmi3_base_type_enu_t type = fmi3_base_type_enu_t::fmi3_base_type_float64; | ||
| std::string name; | ||
| }; | ||
|
|
||
| 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 *unpackPath; | ||
|
|
||
| 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 = ""); | ||
|
|
||
| std::vector<FmuSignal> signalIn; | ||
| std::vector<FmuSignal> signalOut; | ||
|
|
||
| int prepare() override; | ||
|
|
||
| int check() override; | ||
|
|
||
| int start() override; | ||
|
|
||
| int stop() override; | ||
|
|
||
| private: | ||
| void parseSignal(json_t *json, bool in); | ||
|
|
||
| double currentTime = 0; | ||
| double step_size = 0.1; | ||
| double stop_time = 0; | ||
| double start_time = 0; | ||
| bool stop_time_defined = false; | ||
| double nextTime = 0.0; | ||
|
|
||
| void getValueReference(const char *varName, 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
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.