Skip to content

Commit d090601

Browse files
committed
Improve ModelicaSystem.__init__ docstring
1 parent 1c50417 commit d090601

1 file changed

Lines changed: 49 additions & 11 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import numpy as np
4444
import importlib
4545
import pathlib
46+
from typing import Optional
4647

4748
from OMPython.OMCSession import OMCSessionBase, OMCSessionZMQ
4849

@@ -55,17 +56,54 @@ class ModelicaSystemError(Exception):
5556

5657

5758
class ModelicaSystem:
58-
def __init__(self, fileName=None, modelName=None, lmodel=None, commandLineOptions=None,
59-
variableFilter=None, customBuildDirectory=None, verbose=True, raiseerrors=False,
60-
omhome: str = None, session: OMCSessionBase = None): # 1
61-
"""
62-
"constructor"
63-
It initializes to load file and build a model, generating object, exe, xml, mat, and json files. etc. It can be called :
64-
•without any arguments: In this case it neither loads a file nor build a model. This is useful when a FMU needed to convert to Modelica model
65-
•with two arguments as file name with ".mo" extension and the model name respectively
66-
•with three arguments, the first and second are file name and model name respectively and the third arguments is Modelica standard library to load a model, which is common in such models where the model is based on the standard library. For example, here is a model named "dcmotor.mo" below table 4-2, which is located in the directory of OpenModelica at "C:\\OpenModelica1.9.4-dev.beta2\\share\\doc\\omc\\testmodels".
67-
Note: If the model file is not in the current working directory, then the path where file is located must be included together with file name. Besides, if the Modelica model contains several different models within the same package, then in order to build the specific model, in second argument, user must put the package name with dot(.) followed by specific model name.
68-
ex: myModel = ModelicaSystem("ModelicaModel.mo", "modelName")
59+
def __init__(
60+
self,
61+
fileName: Optional[str | os.PathLike] = None,
62+
modelName: Optional[str] = None,
63+
lmodel: Optional[list[str | tuple[str, str]]] = None,
64+
commandLineOptions: Optional[str] = None,
65+
variableFilter: Optional[str] = None,
66+
customBuildDirectory: Optional[str | os.PathLike] = None,
67+
verbose: bool = True,
68+
raiseerrors: bool = False,
69+
omhome: Optional[str] = None,
70+
session: Optional[OMCSessionBase] = None
71+
):
72+
"""Initialize, load and build a model.
73+
74+
The constructor loads the model file and builds it, generating exe and
75+
xml files, etc.
76+
77+
Args:
78+
fileName: Path to the model file. Either absolute or relative to
79+
the current working directory.
80+
modelName: The name of the model class. If it is contained within
81+
a package, "PackageName.ModelName" should be used.
82+
lmodel: List of libraries to be loaded before the model itself is
83+
loaded. Two formats are supported for the list elements:
84+
lmodel=["Modelica"] for just the library name
85+
and lmodel=[("Modelica","3.2.3")] for specifying both the name
86+
and the version.
87+
commandLineOptions: String with extra command line options to be
88+
provided to omc via setCommandLineOptions().
89+
variableFilter: A regular expression. Only variables fully
90+
matching the regexp will be stored in the result file.
91+
Leaving it unspecified is equivalent to ".*".
92+
customBuildDirectory: Path to a directory to be used for temporary
93+
files like the model executable. If left unspecified, a tmp
94+
directory will be created.
95+
verbose: If True, enable verbose logging.
96+
raiseerrors: If True, raise exceptions instead of just logging
97+
OpenModelica errors.
98+
omhome: OPENMODELICAHOME value to be used when creating the OMC
99+
session.
100+
session: OMC session to be used. If unspecified, a new session
101+
will be created.
102+
103+
Examples:
104+
mod = ModelicaSystem("ModelicaModel.mo", "modelName")
105+
mod = ModelicaSystem("ModelicaModel.mo", "modelName", ["Modelica"])
106+
mod = ModelicaSystem("ModelicaModel.mo", "modelName", [("Modelica","3.2.3"), "PowerSystems"])
69107
"""
70108
if fileName is None and modelName is None and not lmodel: # all None
71109
raise Exception("Cannot create ModelicaSystem object without any arguments")

0 commit comments

Comments
 (0)