Skip to content

Commit 53b12bc

Browse files
committed
??? no error !!!
1 parent 809235a commit 53b12bc

6 files changed

Lines changed: 474 additions & 62 deletions

File tree

OMPython/ModelicaSystemBase.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@
1616
import numpy as np
1717

1818
from OMPython.OMCSession import (
19-
OMCPath,
20-
OMCSession,
19+
OMPathBase,
20+
OMSessionBase,
2121
)
2222
from OMPython.ModelExecution import ModelExecutionCmd
2323

24+
OMCPath = OMPathBase
25+
OMCSession = OMSessionBase
26+
2427
# define logger using the current module name as ID
2528
logger = logging.getLogger(__name__)
2629

OMPython/ModelicaSystemDoE.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323
ModelicaSystemOMC,
2424
)
2525
from OMPython.OMCSession import (
26-
OMCSession,
26+
OMSessionBase,
2727
)
2828

29+
OMCSession = OMSessionBase
30+
2931
# define logger using the current module name as ID
3032
logger = logging.getLogger(__name__)
3133

OMPython/ModelicaSystemOMC.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
OMCSessionException,
2020
OMCSession,
2121
OMCSessionLocal,
22-
OMCPath,
22+
OMPathBase,
2323
)
2424

25+
OMCPath = OMPathBase
26+
2527
# define logger using the current module name as ID
2628
logger = logging.getLogger(__name__)
2729

OMPython/ModelicaSystemRunner.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Runner class for a pre-compiled model binary. It does not use OMC at all.
4+
"""
5+
import logging
6+
import os
7+
from typing import Optional
8+
9+
# Import base class and exception
10+
from OMPython.ModelicaSystemBase import (
11+
ModelicaSystemBase,
12+
ModelicaSystemError,
13+
)
14+
from OMPython.OMCSession import (
15+
OMSessionBase,
16+
OMSessionRunner,
17+
)
18+
19+
OMCSession = OMSessionBase
20+
OMCSessionDummy = OMSessionRunner
21+
22+
# define logger using the current module name as ID
23+
logger = logging.getLogger(__name__)
24+
25+
26+
class ModelicaSystemRunner(ModelicaSystemBase):
27+
"""
28+
Class to simulate a Modelica model using a pre-compiled model binary.
29+
"""
30+
31+
def __init__(
32+
self,
33+
work_directory: Optional[str | os.PathLike] = None,
34+
session: Optional[OMSessionBase] = None,
35+
) -> None:
36+
if session is None:
37+
session = OMCSessionDummy()
38+
39+
if not isinstance(session, OMCSessionDummy):
40+
raise ModelicaSystemError("Only working if OMCsessionDummy is used!")
41+
42+
super().__init__(
43+
work_directory=work_directory,
44+
session=session,
45+
)
46+
47+
def setup(
48+
self,
49+
model_name: Optional[str] = None,
50+
variable_filter: Optional[str] = None,
51+
) -> None:
52+
"""
53+
Needed definitions to set up the runner class. This class expects the model (defined by model_name) to exists
54+
within the working directory. At least two files are needed:
55+
56+
* model executable (as '<model_name>' or '<model_name>.exe'; in case of Windows additional '<model_name>.bat'
57+
is expected to evaluate the path to needed dlls
58+
* the model initialization file (as '<model_name>_init.xml')
59+
"""
60+
61+
if self._model_name is not None:
62+
raise ModelicaSystemError("Can not reuse this instance of ModelicaSystem "
63+
f"defined for {repr(self._model_name)}!")
64+
65+
if model_name is None or not isinstance(model_name, str):
66+
raise ModelicaSystemError("A model name must be provided!")
67+
68+
# set variables
69+
self._model_name = model_name # Model class name
70+
self._variable_filter = variable_filter
71+
72+
# test if the model can be executed
73+
self.check_model_executable()
74+
75+
# read XML file
76+
xml_file = self._session.omcpath(self.getWorkDirectory()) / f"{self._model_name}_init.xml"
77+
self._xmlparse(xml_file=xml_file)

0 commit comments

Comments
 (0)