-
Notifications
You must be signed in to change notification settings - Fork 1.2k
MOOSE FMU interface development #30912
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: next
Are you sure you want to change the base?
Conversation
d106c24 to
1e2adbe
Compare
211f66d to
a40cada
Compare
afb3c10 to
f20ccbb
Compare
42a1b26 to
2b49506
Compare
Clean up interface and add test
Add testing examples in documentation Add unit test
Update tests Add more unit tests
Add moose fmu tester Fix unicode character errors
Python unit tests need to use platform and do not have capabilities available
|
Job Precheck, step Versioner verify on afb834d wanted to post the following: Versioner templatesFound 14 templates, 0 failed Versioner influential filesFound 58 influential files, 3 changed, 0 added, 0 removed
Versioner versionsFound 9 packages, 2 changed, 0 failed
|
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.
Can we sit together tomorrow briefly for you to show me an example with this? Would help with the review quite a bit
Of course! Let's do that |
| @@ -0,0 +1,145 @@ | |||
| # MOOSE FMU Interface | |||
|
|
|||
| The `MOOSEFMU` defines the `Moose2FMU` base class which contains the boilerplate needed to wrap a MOOSE simulation as a Functional Mock-up Unit (FMU). Users only need to implement their own `__init__` and `do_step` methods when deriving from `Moose2FMU`. | |||
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.
| The `MOOSEFMU` defines the `Moose2FMU` base class which contains the boilerplate needed to wrap a MOOSE simulation as a Functional Mock-up Unit (FMU). Users only need to implement their own `__init__` and `do_step` methods when deriving from `Moose2FMU`. | |
| The `MOOSEFMU` defines the `Moose2FMU` Python base class which contains the boilerplate needed to wrap a MOOSE simulation as a Functional Mock-up Unit (FMU). Users only need to implement their own `__init__` and `do_step` methods when deriving from `Moose2FMU`. |
| `Moose2FMU` accepts a number of keyword arguments that configure how the | ||
| underlying MOOSE simulation is launched and interacted with: | ||
|
|
||
| - `flag`: Optional flag that is forwarded to the MOOSE input deck. |
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.
how to pass multiple?
-flag a -flag b ? or -flag a b ?
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.
is the rules for spaces same as for CLI args?
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.
is the rules for spaces same as for CLI args?
Yes, this is just pass CLI args to MOOSE control. I can add an example here to show it. I keep all the examples in moose_fmu folder. I can refer that here
| `Moose2FMU` provides a small collection of convenience methods that simplify | ||
| interacting with a running MOOSE simulation: | ||
|
|
||
| - `set_controllable_real` and `set_controllable_vector` push new controllable |
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.
vectors are controllable now?
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.
In MOOSE web server control, controllable_vector is supported so I just include the option here. Not quiet sure if controllable vector actually used anywhere in the code. Maybe under stochastic tools? Here I just provide APIs we have in MOOSE web server control
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.
we should check, let's get a test
| `get_postprocessor_value` also accept per-call `flag` arguments. Passing custom | ||
| flags in these locations allows FMUs to react to user-defined synchronization | ||
| points while still benefiting from the built-in defaults. Refer to | ||
| [SetupInterface.md]for additional details on |
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.
| [SetupInterface.md]for additional details on | |
| [SetupInterface.md] for additional details on |
| MOOSE execute flags. | ||
|
|
||
| ### Creating a Custom FMU | ||
|
|
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.
is there a script you could use a listing from instead?
|
|
||
| Save the custom class in a Python file and use [`pythonfmu`](https://github.com/NTNU-IHB/PythonFMU) to build the FMU: | ||
|
|
||
| ```bash |
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.
so we dont include this package in our conda distrib? not through fmpy?
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.
We include pythonfmu in conda, but to build a MOOSE fmu customized fmu input, output, you still use pythonfmu build command to do that. We don't need to install pythonfmu package every time we want to build fmu
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.
I dont see a pythonfmu new package in conda?
Does it come with fmpy?
| pythonfmu build custom_moose.py | ||
| ``` | ||
|
|
||
| The resulting `.fmu` file can then be imported into any compliant co-simulation environment. |
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.
| The resulting `.fmu` file can then be imported into any compliant co-simulation environment. | |
| The resulting `.fmu` file can then be imported into any standard-compliant co-simulation environment. |
| @@ -0,0 +1,145 @@ | |||
| # MOOSE FMU Interface | |||
|
|
|||
| The `MOOSEFMU` defines the `Moose2FMU` base class which contains the boilerplate needed to wrap a MOOSE simulation as a Functional Mock-up Unit (FMU). Users only need to implement their own `__init__` and `do_step` methods when deriving from `Moose2FMU`. | |||
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.
what standard did you implement for FMU ? 2? 3? do we have the whole standard implemented or partiaL?
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.
We support FMU 2 standard. The whole standard is implemented by pythonFMU and we use that to build MOOSE FMU
| !syntax parameters /Controls/MOOSEFMU | ||
|
|
||
| !syntax inputs /Controls/MOOSEFMU | ||
|
|
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.
I dont see a MOOSEFMU class registered? this shouldt work, what am I missing
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.
Good catch, I'll fix it
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.
looks great. This is well organized and understandable at a good level
I think the next thing we need is a tutorial on MOOSE-FMU showing:
- building the FMU
- running it from python
- controlling its stepping
- controlling its inputs
- plotting its outputs
- coupling it to another FMU
which basically matches the tests you created!
| `Moose2FMU` provides a small collection of convenience methods that simplify | ||
| interacting with a running MOOSE simulation: | ||
|
|
||
| - `set_controllable_real` and `set_controllable_vector` push new controllable |
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.
we should check, let's get a test
| fmu_utils.set_string(fmu, vr_map, "mode", "active") | ||
| fmu_utils.set_bool(fmu, vr_map, "enabled", False) | ||
|
|
||
| self.assertEqual(fmu.calls["getReal"], [(1,)]) |
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.
add a comment for these 3, what is this checking? the call log?
| fmu = _DummyFmu() | ||
| vr_map = {"temperature": 1, "mode": 2, "enabled": 3} | ||
|
|
||
| self.assertEqual(fmu_utils.get_real(fmu, vr_map, "temperature"), 12.5) |
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.
so you always need to give the vr_map to a get_something call? that seems inefficient
I would imagine fmu.getReal("temperature") would be enough information ?
|
|
||
| Save the custom class in a Python file and use [`pythonfmu`](https://github.com/NTNU-IHB/PythonFMU) to build the FMU: | ||
|
|
||
| ```bash |
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.
I dont see a pythonfmu new package in conda?
Does it come with fmpy?
| @@ -0,0 +1,601 @@ | |||
| from pythonfmu import Fmi2Slave | |||
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.
we need the copyright header everywhere in the python files
#* This file is part of the MOOSE framework
#* https://mooseframework.inl.gov
#*
#* All rights reserved, see COPYRIGHT for full restrictions
#* https://github.com/idaholab/moose/blob/master/COPYRIGHT
#*
#* Licensed under LGPL 2.1, please see LICENSE for details
#* https://www.gnu.org/licenses/lgpl-2.1.html
| (a) rebuild the FMU with the desired dt with DefaultExperiment, or | ||
| (b) drive the FMU step-by-step (manual do_step loop) instead of simulate_fmu. | ||
| - simulate_fmu integrates *up to* stop_time but does not necessarily perform a |
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.
so this is an issue with fmpy?
I would not expect a do_step at the stop time?
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.
do we have to store this or can we generate it in the test suite using a RunCommand?
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.
what test is using this file?
|
|
||
| df = pd.DataFrame(result) | ||
|
|
||
| df.to_csv("run_fmu.csv", index=False) |
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.
ok I see how this handled to create a CSV
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.
copyright on all these files
Reason
This PR will develop a MOOSE FMU interface
Design
The current MOOSE FMU interface will leverage web server control capability to communicate with MOOSE simulation. It requires a running MOOSE simulation on side.
Impact
This will be the first step to pack MOOSE as a FMU and integrates with other FMUs for co-simulation