|
| 1 | +## status: correct |
| 2 | +## teardown_command: |
| 3 | +## linux: yes |
| 4 | +## ucrt64: yes |
| 5 | +## win: yes |
| 6 | +## mac: yes |
| 7 | + |
| 8 | + |
| 9 | +from poplib import CR |
| 10 | +from OMSimulator import SSP, CRef, Settings |
| 11 | + |
| 12 | +Settings.suppressPath = True |
| 13 | + |
| 14 | +# this example creates a composite model with FMI3 FMU and connects them together. |
| 15 | +# It then simulates the model and prints the results. |
| 16 | + |
| 17 | +model = SSP() |
| 18 | +model.addResource("../resources/Feedthrough3.fmu", new_name="resources/Feedthrough3.fmu") |
| 19 | +model.addComponent(CRef("default", "Feedthrough1"), "resources/Feedthrough3.fmu") |
| 20 | +model.addComponent(CRef("default", "Feedthrough2"), "resources/Feedthrough3.fmu") |
| 21 | + |
| 22 | + |
| 23 | +## connections |
| 24 | +model.addConnection(CRef("default", "Feedthrough1", "Float64_continuous_output"), CRef("default", "Feedthrough2", "Float64_continuous_input")) |
| 25 | +model.addConnection(CRef("default", "Feedthrough1", "Int64_output"), CRef("default", "Feedthrough2", "Int64_input")) |
| 26 | + |
| 27 | +instantiated_model = model.instantiate() ## internally generate the json file and also set the model state like virgin, |
| 28 | +instantiated_model.setResultFile("") |
| 29 | +instantiated_model.setStopTime(10.0) |
| 30 | +instantiated_model.setTolerance(1e-5) |
| 31 | + |
| 32 | +instantiated_model.setValue(CRef("default", "Feedthrough1", "Float64_continuous_input"), 3.5) |
| 33 | +instantiated_model.setValue(CRef("default", "Feedthrough1", "Int64_input"), 7) |
| 34 | + |
| 35 | +instantiated_model.initialize() |
| 36 | +instantiated_model.simulate() |
| 37 | +print(f"info: Feedthrough1.Float64_continuous_input : {instantiated_model.getValue(CRef('default', 'Feedthrough1', 'Float64_continuous_input'))}") |
| 38 | +print(f"info: Feedthrough1.Float64_continuous_output : {instantiated_model.getValue(CRef('default', 'Feedthrough1', 'Float64_continuous_output'))}") |
| 39 | +print(f"info: Feedthrough2.Float64_continuous_input : {instantiated_model.getValue(CRef('default', 'Feedthrough2', 'Float64_continuous_input'))}") |
| 40 | +print(f"info: Feedthrough2.Float64_continuous_output : {instantiated_model.getValue(CRef('default', 'Feedthrough2', 'Float64_continuous_output'))}") |
| 41 | +print(f"info: Feedthrough1.Int64_input : {instantiated_model.getValue(CRef('default', 'Feedthrough1', 'Int64_input'))}") |
| 42 | +print(f"info: Feedthrough1.Int64_output : {instantiated_model.getValue(CRef('default', 'Feedthrough1', 'Int64_output'))}") |
| 43 | +print(f"info: Feedthrough2.Int64_input : {instantiated_model.getValue(CRef('default', 'Feedthrough2', 'Int64_input'))}") |
| 44 | +print(f"info: Feedthrough2.Int64_output : {instantiated_model.getValue(CRef('default', 'Feedthrough2', 'Int64_output'))}") |
| 45 | + |
| 46 | +instantiated_model.terminate() |
| 47 | +instantiated_model.delete() |
| 48 | + |
| 49 | +## Result: |
| 50 | +## warning: Unknown FMI3 base type for var : Binary_input |
| 51 | +## warning: Unknown FMI3 base type for var : Binary_output |
| 52 | +## warning: Unknown FMI3 base type for var : Binary_input |
| 53 | +## warning: Unknown FMI3 base type for var : Binary_output |
| 54 | +## Loading FMI version 3... |
| 55 | +## Loading FMI version 3... |
| 56 | +## info: No result file will be created |
| 57 | +## info: Feedthrough1.Float64_continuous_input : 3.5 |
| 58 | +## info: Feedthrough1.Float64_continuous_output : 3.5 |
| 59 | +## info: Feedthrough2.Float64_continuous_input : 3.5 |
| 60 | +## info: Feedthrough2.Float64_continuous_output : 3.5 |
| 61 | +## info: Feedthrough1.Int64_input : 7 |
| 62 | +## info: Feedthrough1.Int64_output : 7 |
| 63 | +## info: Feedthrough2.Int64_input : 7 |
| 64 | +## info: Feedthrough2.Int64_output : 7 |
| 65 | +## info: 4 warnings |
| 66 | +## info: 0 errors |
| 67 | +## endResult |
0 commit comments