Skip to content

Commit 19d9519

Browse files
committed
Improve ModelicaSystem.__init__ docstring
1 parent 0b63a2b commit 19d9519

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
@@ -108,17 +108,54 @@ def __getitem__(self, index: int):
108108

109109

110110
class ModelicaSystem:
111-
def __init__(self, fileName=None, modelName=None, lmodel=None, commandLineOptions=None,
112-
variableFilter=None, customBuildDirectory=None, verbose=True, raiseerrors=False,
113-
omhome: str = None, session: OMCSessionBase = None): # 1
114-
"""
115-
"constructor"
116-
It initializes to load file and build a model, generating object, exe, xml, mat, and json files. etc. It can be called :
117-
•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
118-
•with two arguments as file name with ".mo" extension and the model name respectively
119-
•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".
120-
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.
121-
ex: myModel = ModelicaSystem("ModelicaModel.mo", "modelName")
111+
def __init__(
112+
self,
113+
fileName: Optional[str | os.PathLike] = None,
114+
modelName: Optional[str] = None,
115+
lmodel: Optional[list[str | tuple[str, str]]] = None,
116+
commandLineOptions: Optional[str] = None,
117+
variableFilter: Optional[str] = None,
118+
customBuildDirectory: Optional[str | os.PathLike] = None,
119+
verbose: bool = True,
120+
raiseerrors: bool = False,
121+
omhome: Optional[str] = None,
122+
session: Optional[OMCSessionBase] = None
123+
):
124+
"""Initialize, load and build a model.
125+
126+
The constructor loads the model file and builds it, generating exe and
127+
xml files, etc.
128+
129+
Args:
130+
fileName: Path to the model file. Either absolute or relative to
131+
the current working directory.
132+
modelName: The name of the model class. If it is contained within
133+
a package, "PackageName.ModelName" should be used.
134+
lmodel: List of libraries to be loaded before the model itself is
135+
loaded. Two formats are supported for the list elements:
136+
lmodel=["Modelica"] for just the library name
137+
and lmodel=[("Modelica","3.2.3")] for specifying both the name
138+
and the version.
139+
commandLineOptions: String with extra command line options to be
140+
provided to omc via setCommandLineOptions().
141+
variableFilter: A regular expression. Only variables fully
142+
matching the regexp will be stored in the result file.
143+
Leaving it unspecified is equivalent to ".*".
144+
customBuildDirectory: Path to a directory to be used for temporary
145+
files like the model executable. If left unspecified, a tmp
146+
directory will be created.
147+
verbose: If True, enable verbose logging.
148+
raiseerrors: If True, raise exceptions instead of just logging
149+
OpenModelica errors.
150+
omhome: OPENMODELICAHOME value to be used when creating the OMC
151+
session.
152+
session: OMC session to be used. If unspecified, a new session
153+
will be created.
154+
155+
Examples:
156+
mod = ModelicaSystem("ModelicaModel.mo", "modelName")
157+
mod = ModelicaSystem("ModelicaModel.mo", "modelName", ["Modelica"])
158+
mod = ModelicaSystem("ModelicaModel.mo", "modelName", [("Modelica","3.2.3"), "PowerSystems"])
122159
"""
123160
if fileName is None and modelName is None and not lmodel: # all None
124161
raise Exception("Cannot create ModelicaSystem object without any arguments")

0 commit comments

Comments
 (0)