Skip to content

Commit 340d77a

Browse files
authored
Merge pull request #46 from INTO-CPS-Association/#44
#44
2 parents 23dcdfa + 21a2c08 commit 340d77a

File tree

7 files changed

+204
-441
lines changed

7 files changed

+204
-441
lines changed

README.md

Lines changed: 14 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,31 @@
33
# UniFMU - Universal Functional Mock-Up Units
44

55
The [_Functional Mock-Up Interface_](https://fmi-standard.org/) _(FMI)_ defines an exchange format that allows models, referred to as _Functional Mock-Up Unit (FMU)_, to be shared between tools supporting the standard.
6+
In general, an FMU must be implemented in a programming language that can produce binaries that can be called from C, such as C itself or C++.
7+
While this allows efficient execution of a simulation, it is a significant limitation when prototyping models.
68

7-
Traditionally, an FMU must be implemented in a programming language that is compatible with C's binary interface such as C itself or C++.
9+
UniFMU is a command line tool that facilitates the implementation of FMUs in other popular languages that would otherwise not be able to produce C-compatible binaries.
10+
It does this by providing a precompiled binary that is C-compatible, which then dispatches calls to the implementation of the model in the target language.
811

9-
UniFMU is a command line tool that facilitates the implementation of FMUs in languages in several languages, such as:
12+
| Specification Version | FMU Types | Languages |
13+
| --------------------- | ------------ | ---------- |
14+
| FMI3 | | |
15+
| FMI2 | cosimulation | Python, C# |
16+
| FMI1 | | |
1017

11-
- Python
12-
- C#
18+
Examples of generated FMUs can be found in the [unifmu_examples](https://github.com/INTO-CPS-Association/unifmu_examples) repo.
1319

14-
This is made possible by providing a generic binary that dispatches calls to the users implementation using _remote procedure call_ _(RPC)_.
20+
## Getting the tool
1521

16-
## Installing the tool
17-
18-
The current and revious versions of the tool can be downloaded from the releases tab of the repository.
19-
20-
For convenience the tool can be copied to a directory that is in the systems path such as `/usr/bin/` for most Linux distributions.
22+
The tool can be downloaded from [releases](https://github.com/INTO-CPS-Association/unifmu/releases) tab of the repository.
23+
It is a single executable that bundles all assets used during FMU generation as part of the binary.
2124

2225
## How to use the command line interface?
2326

2427
To display the synopsis use the `--help` flag.
2528

2629
```
27-
UniFMU 0.0.4
30+
UniFMU 0.0.6
2831
Implement 'Functional Mock-up units' (FMUs) in various source languages.
2932
3033
USAGE:
@@ -93,74 +96,6 @@ Like the file structure, the workflow for modifying FMUs varies depending on the
9396
Depending on the language a `README.md` is placed in the root of the generated FMU, which serves as documentation for the particular language.
9497
For reference the `README.md` copied into Python FMUs looks like [README.md](tool/unifmu/resources/backends/python/README.md).
9598

96-
## Building and Testing
97-
98-
Build the cross compilation image from the dockerfile stored in `docker-build` folder:
99-
100-
```
101-
docker build -t unifmu-build docker-build
102-
```
103-
104-
**Note: This process may take a long time 10-30 minutes, but must only be done once.**
105-
106-
Start a container with the name `builder` from the cross-compilation image `unifmu-build`:
107-
108-
```bash
109-
docker run --name builder -it -v $(pwd):/workdir unifmu-build # bash
110-
```
111-
112-
```powershell
113-
$pwd = (pwd).Path
114-
docker run --name builder -it -v ${pwd}:/workdir unifmu-build # powershell
115-
```
116-
117-
**Note: On windows you may have to enable the use of shared folders through the dockers interface, otherwise the container fails to start.**
118-
119-
To build the code invoke the script `docker-build/build_all.sh` in the `workdir` of the container:
120-
121-
``` bash
122-
bash ./docker-build/build_all.sh
123-
```
124-
125-
This generates and copies all relevant build artifacts into the `assets/auto_generated` directory:
126-
127-
```
128-
📦auto_generated
129-
┣ 📜.gitkeep
130-
┣ 📜unifmu.dll
131-
┣ 📜unifmu.dylib
132-
┣ 📜unifmu.so
133-
┣ 📜UnifmuFmi2.cs
134-
┗ 📜unifmu_fmi2_pb2.py
135-
```
136-
137-
**Note: On windows Git may be configured to replace LF line-endings with CRLF, which are not compatible with bash.**
138-
139-
Following this the cli is compiled for each platform, including the assets that were just compiled.
140-
The final standalone executables can be found in the target folder, under the host tripple:
141-
142-
- linux: unifmu-x86_64-unknown-linux-gnu-0.0.4.zip
143-
- windows: unifmu-x86_64-pc-windows-gnu-0.0.4.zip
144-
- macOS: unifmu-x86_64-apple-darwin-0.0.4.zip
145-
146-
## Environment Variables
147-
148-
In addition to the systems environment variables, UniFMU defines the following variables in the process created during instantiation of a slave.
149-
These can be accessed during execution by the model implementation or the backend.
150-
151-
| Variable | Description | Example |
152-
| ------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | ------------------------------------- |
153-
| UNIFMU_GUID | The global unique identifier, passed as an argument to fmi2Instantiate | 77236337-210e-4e9c-8f2c-c1a0677db21b |
154-
| UNIFMU_INSTANCE_NAME | Name of the slave instance, passed as an argument to fmi2Instantiate | left_wheel_motor |
155-
| UNIFMU_VISIBLE | Flag used to indicating if the instance should run in visible mode, passed as an argument to fmi2Instantiate | {true, false} |
156-
| UNIFMU_LOGGING_ON | Flag used to indicating if the instance should run with logging, passed as an argument to fmi2Instantiate | {true, false} |
157-
| UNIFMU_FMU_TYPE | Flag used to indicating if the instance is running in co-sim or model exchange mode, passed as an argument to fmi2Instantiate | {fmi2ModelExchange, fmi2CoSimulation} |
158-
| UNIFMU_DISPATCHER_ENDPOINT | Endpoint bound by the zmq socket of the binary | tcp://127.0.0.1/5000 |
159-
| UNIFMU_DISPATCHER_ENDPOINT_PORT | Port component of UNIFMU_DISPATCHER_ENDPOINT | 5000 |
160-
| UNIFMU_REFS_TO_ATTRS | Mapping from value references to variable names encoded as a JSON dictionary\*. | {"0": "my_input", "1" : "my_output"} |
161-
162-
\* This variable is only defined if the modelDescription.xml is present in the parent directory of the resources folder passed to fmi2Instantiate.
163-
16499
## Citing the tool
165100

166101
When citing the tool, please cite the following paper:

assets/csharp/model.cs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
using System.IO;
44
using System.Reflection;
55

6-
7-
using Newtonsoft.Json;
86
using System.Linq;
97
using Fmi2Proto;
108

@@ -28,18 +26,21 @@ public class Model
2826

2927
public Model()
3028
{
31-
// Populate map from value reference to attributes of the model.
32-
string references_to_values = System.Environment.GetEnvironmentVariable("UNIFMU_REFS_TO_ATTRS");
33-
if (references_to_values == null)
34-
{
35-
Console.WriteLine("the environment variable 'UNIFMU_REFS_TO_ATTRS' was not set");
36-
Environment.Exit(-1);
37-
}
38-
var dict = JsonConvert.DeserializeObject<Dictionary<uint, String>>(references_to_values);
39-
foreach (var (vref, variable) in dict)
29+
this.reference_to_attributes = new Dictionary<uint, PropertyInfo>
4030
{
41-
this.reference_to_attributes.Add(vref, this.GetType().GetProperty(variable));
42-
}
31+
{ 0, this.GetType().GetProperty("real_a") },
32+
{ 1, this.GetType().GetProperty("real_b") },
33+
{ 2, this.GetType().GetProperty("real_c") },
34+
{ 3, this.GetType().GetProperty("integer_a") },
35+
{ 4, this.GetType().GetProperty("integer_b") },
36+
{ 5, this.GetType().GetProperty("integer_c") },
37+
{ 6, this.GetType().GetProperty("boolean_a") },
38+
{ 7, this.GetType().GetProperty("boolean_b") },
39+
{ 8, this.GetType().GetProperty("boolean_c") },
40+
{ 9, this.GetType().GetProperty("string_a") },
41+
{ 10, this.GetType().GetProperty("string_b") },
42+
{ 11, this.GetType().GetProperty("string_c") },
43+
};
4344

4445
}
4546
public Fmi2Status Fmi2DoStep(double currentTime, double stepSize, bool noStepPrior)

0 commit comments

Comments
 (0)