Skip to content

Commit 4c89ea3

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

1 file changed

Lines changed: 48 additions & 11 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,54 @@ class ModelicaSystemError(Exception):
5555

5656

5757
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")
58+
def __init__(
59+
self,
60+
fileName: Optional[str | os.PathLike] = None,
61+
modelName: Optional[str] = None,
62+
lmodel: Optional[list[str | tuple[str, str]]] = None,
63+
commandLineOptions: Optional[str] = None,
64+
variableFilter: Optional[str] = None,
65+
customBuildDirectory: Optional[str | os.PathLike] = None,
66+
verbose: bool = True,
67+
raiseerrors: bool = False,
68+
omhome: Optional[str] = None,
69+
session: Optional[OMCSessionBase] = None
70+
):
71+
"""Initialize, load and build a model.
72+
73+
The constructor loads the model file and builds it, generating exe and
74+
xml files, etc.
75+
76+
Args:
77+
fileName: Path to the model file. Either absolute or relative to
78+
the current working directory.
79+
modelName: The name of the model class. If it is contained within
80+
a package, "PackageName.ModelName" should be used.
81+
lmodel: List of libraries to be loaded before the model itself is
82+
loaded. Two formats are supported for the list elements:
83+
lmodel=["Modelica"] for just the library name
84+
and lmodel=[("Modelica","3.2.3")] for specifying both the name
85+
and the version.
86+
commandLineOptions: String with extra command line options to be
87+
provided to omc via setCommandLineOptions().
88+
variableFilter: A regular expression. Only variables fully
89+
matching the regexp will be stored in the result file.
90+
Leaving it unspecified is equivalent to ".*".
91+
customBuildDirectory: Path to a directory to be used for temporary
92+
files like the model executable. If left unspecified, a tmp
93+
directory will be created.
94+
verbose: If True, enable verbose logging.
95+
raiseerrors: If True, raise exceptions instead of just logging
96+
OpenModelica errors.
97+
omhome: OPENMODELICAHOME value to be used when creating the OMC
98+
session.
99+
session: OMC session to be used. If unspecified, a new session
100+
will be created.
101+
102+
Examples:
103+
mod = ModelicaSystem("ModelicaModel.mo", "modelName")
104+
mod = ModelicaSystem("ModelicaModel.mo", "modelName", ["Modelica"])
105+
mod = ModelicaSystem("ModelicaModel.mo", "modelName", [("Modelica","3.2.3"), "PowerSystems"])
69106
"""
70107
if fileName is None and modelName is None and not lmodel: # all None
71108
raise Exception("Cannot create ModelicaSystem object without any arguments")

0 commit comments

Comments
 (0)