|
31 | 31 | OMPathABC, |
32 | 32 |
|
33 | 33 | OMSessionABC, |
| 34 | + OMSessionRunner, |
34 | 35 | ) |
35 | 36 |
|
36 | 37 | # define logger using the current module name as ID |
@@ -2579,3 +2580,57 @@ class ModelicaSystemDoE(ModelicaDoEOMC): |
2579 | 2580 | """ |
2580 | 2581 | Compatibility class. |
2581 | 2582 | """ |
| 2583 | + |
| 2584 | + |
| 2585 | +class ModelicaSystemRunner(ModelicaSystemABC): |
| 2586 | + """ |
| 2587 | + Class to simulate a Modelica model using a pre-compiled model binary. |
| 2588 | + """ |
| 2589 | + |
| 2590 | + def __init__( |
| 2591 | + self, |
| 2592 | + work_directory: Optional[str | os.PathLike] = None, |
| 2593 | + session: Optional[OMSessionABC] = None, |
| 2594 | + ) -> None: |
| 2595 | + if session is None: |
| 2596 | + session = OMSessionRunner() |
| 2597 | + |
| 2598 | + if not isinstance(session, OMSessionRunner): |
| 2599 | + raise ModelicaSystemError("Only working if OMCsessionDummy is used!") |
| 2600 | + |
| 2601 | + super().__init__( |
| 2602 | + work_directory=work_directory, |
| 2603 | + session=session, |
| 2604 | + ) |
| 2605 | + |
| 2606 | + def setup( |
| 2607 | + self, |
| 2608 | + model_name: Optional[str] = None, |
| 2609 | + variable_filter: Optional[str] = None, |
| 2610 | + ) -> None: |
| 2611 | + """ |
| 2612 | + Needed definitions to set up the runner class. This class expects the model (defined by model_name) to exists |
| 2613 | + within the working directory. At least two files are needed: |
| 2614 | +
|
| 2615 | + * model executable (as '<model_name>' or '<model_name>.exe'; in case of Windows additional '<model_name>.bat' |
| 2616 | + is expected to evaluate the path to needed dlls |
| 2617 | + * the model initialization file (as '<model_name>_init.xml') |
| 2618 | + """ |
| 2619 | + |
| 2620 | + if self._model_name is not None: |
| 2621 | + raise ModelicaSystemError("Can not reuse this instance of ModelicaSystem " |
| 2622 | + f"defined for {repr(self._model_name)}!") |
| 2623 | + |
| 2624 | + if model_name is None or not isinstance(model_name, str): |
| 2625 | + raise ModelicaSystemError("A model name must be provided!") |
| 2626 | + |
| 2627 | + # set variables |
| 2628 | + self._model_name = model_name # Model class name |
| 2629 | + self._variable_filter = variable_filter |
| 2630 | + |
| 2631 | + # test if the model can be executed |
| 2632 | + self.check_model_executable() |
| 2633 | + |
| 2634 | + # read XML file |
| 2635 | + xml_file = self._session.omcpath(self.getWorkDirectory()) / f"{self._model_name}_init.xml" |
| 2636 | + self._xmlparse(xml_file=xml_file) |
0 commit comments