diff --git a/CHANGELOG.md b/CHANGELOG.md index 34ebc5e..385b1ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,15 @@ The changelog format is based on [Keep a Changelog](https://keepachangelog.com/e ## [Unreleased] +### Changed +* Default build target in builder to wind_to_power example + +### Added +* Wind to power model example in examples + * Onnx file containing ml model + * Interface json file containing information needed not contained in onnx file +* The generated fmu files resulting from running running builder on the new wind_to_power example + ### Changed * CMakeList.txt (from old repo) to be able to take an arbitrary path where the fmu files to be compiled are located * Builder to run commands to compile generated files into an fmu diff --git a/examples/wind_to_power/WindToPower/modelDescription.xml b/examples/wind_to_power/WindToPower/modelDescription.xml new file mode 100644 index 0000000..66f8997 --- /dev/null +++ b/examples/wind_to_power/WindToPower/modelDescription.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/wind_to_power/WindToPower/resources/example.onnx b/examples/wind_to_power/WindToPower/resources/example.onnx new file mode 100644 index 0000000..09df826 Binary files /dev/null and b/examples/wind_to_power/WindToPower/resources/example.onnx differ diff --git a/examples/wind_to_power/WindToPower/sources/fmu.cpp b/examples/wind_to_power/WindToPower/sources/fmu.cpp new file mode 100644 index 0000000..c670488 --- /dev/null +++ b/examples/wind_to_power/WindToPower/sources/fmu.cpp @@ -0,0 +1,23 @@ +#include "model_definitions.h" +#include "fmu-uuid.h" +#include +#include + + +class WindToPower : public OnnxFmu{ +public: + WindToPower(cppfmu::FMIString fmuResourceLocation) : OnnxFmu(fmuResourceLocation){} +private: +}; + + +cppfmu::UniquePtr CppfmuInstantiateSlave( + cppfmu::FMIString /*instanceName*/, cppfmu::FMIString fmuGUID, cppfmu::FMIString fmuResourceLocation, + cppfmu::FMIString /*mimeType*/, cppfmu::FMIReal /*timeout*/, cppfmu::FMIBoolean /*visible*/, + cppfmu::FMIBoolean /*interactive*/, cppfmu::Memory memory, cppfmu::Logger /*logger*/) +{ + if (std::strcmp(fmuGUID, FMU_UUID) != 0) { + throw std::runtime_error("FMU GUID mismatch"); + } + return cppfmu::AllocateUnique(memory, fmuResourceLocation); +} diff --git a/examples/wind_to_power/WindToPower/sources/model_definitions.h b/examples/wind_to_power/WindToPower/sources/model_definitions.h new file mode 100644 index 0000000..7968330 --- /dev/null +++ b/examples/wind_to_power/WindToPower/sources/model_definitions.h @@ -0,0 +1,20 @@ +#define NUM_FMU_VARIABLES 3 + +#define NUM_ONNX_INPUTS 2 +#define NUM_ONNX_FMU_INPUTS 2 +#define NUM_ONNX_OUTPUTS 1 +#define NUM_ONNX_FMU_OUTPUTS 1 +#define NUM_ONNX_STATES 0 +#define NUM_ONNX_STATES_OUTPUTS 0 + +#define ONNX_INPUT_VALUE_REFERENCES 0, 0, 1, 1 +#define ONNX_OUTPUT_VALUE_REFERENCES 0, 2 +#define ONNX_STATE_OUTPUT_INDEXES + +#define ONNX_USE_TIME_INPUT false + +#define ONNX_INPUT_NAME "args_0" +#define ONNX_OUTPUT_NAME "output_1" +#define ONNX_STATE_NAME "" +#define ONNX_TIME_INPUT_NAME "" +#define ONNX_FILENAME L"example.onnx" \ No newline at end of file diff --git a/examples/wind_to_power/config/example.onnx b/examples/wind_to_power/config/example.onnx new file mode 100644 index 0000000..09df826 Binary files /dev/null and b/examples/wind_to_power/config/example.onnx differ diff --git a/examples/wind_to_power/config/interface.json b/examples/wind_to_power/config/interface.json new file mode 100644 index 0000000..41ccc10 --- /dev/null +++ b/examples/wind_to_power/config/interface.json @@ -0,0 +1,33 @@ +{ + "name": "WindToPower", + "description": "A Machine Learning based FMU that outputs the estimated power output of a windmill given the wind speed and direction.", + "inputs": [ + { + "name": "windSpeed", + "description": "Noise to be added to the change in wind speed", + "agentInputIndexes": [ + "0" + ] + }, + { + "name": "windDirection", + "description": "Noise to be added to the change in wind direction", + "agentInputIndexes": [ + "1" + ] + } + ], + "parameters": [], + "outputs": [ + { + "name": "power", + "description": "The estimated windmill power output", + "agentOutputIndexes": [ + "0" + ] + } + ], + "states": { + "agentOutputIndexes": [] + } +} \ No newline at end of file diff --git a/src/mlfmu/utils/builder.py b/src/mlfmu/utils/builder.py index 6801f48..b9939a2 100644 --- a/src/mlfmu/utils/builder.py +++ b/src/mlfmu/utils/builder.py @@ -16,9 +16,9 @@ # TODO: I had some problems with this absolute_path.parent.parent, so I changed it to this to make it work. # These are just temporary hard coded values that should be provided by the user. So it isn't that important. template_parent_path = absolute_path / "templates" / "fmu" -json_interface = absolute_path / "examples" / "wind_generator" / "config" / "interface.json" -fmu_src_path = absolute_path / "examples" / "wind_generator" -onnx_path = absolute_path / "examples" / "wind_generator" / "config" / "example.onnx" +json_interface = absolute_path / "examples" / "wind_to_power" / "config" / "interface.json" +fmu_src_path = absolute_path / "examples" / "wind_to_power" +onnx_path = absolute_path / "examples" / "wind_to_power" / "config" / "example.onnx" build_path = absolute_path / "build_fmu" save_fmu_path = absolute_path / "fmus"