Skip to content

Commit 7153f98

Browse files
committed
Improve docstring for getSolutions()
1 parent 3bd069a commit 7153f98

1 file changed

Lines changed: 33 additions & 12 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -986,20 +986,41 @@ def simulate(self,
986986

987987
self._simulationFlag = True
988988

989-
# to extract simulation results
990-
def getSolutions(self, varList=None, resultfile=None): # 12
991-
"""
992-
This method returns tuple of numpy arrays. It can be called:
993-
•with a list of quantities name in string format as argument: it returns the simulation results of the corresponding names in the same order. Here it supports Python unpacking depending upon the number of variables assigned.
994-
usage:
995-
>>> getSolutions()
996-
>>> getSolutions("Name1")
997-
>>> getSolutions(["Name1","Name2"])
998-
>>> getSolutions(resultfile="c:/a.mat")
999-
>>> getSolutions("Name1",resultfile=""c:/a.mat"")
1000-
>>> getSolutions(["Name1","Name2"],resultfile=""c:/a.mat"")
989+
def getSolutions(self, varList: Optional[str | list[str]] = None, resultfile: Optional[str] = None) -> tuple[str] | np.ndarray:
990+
"""Extract simulation results from a result data file.
991+
992+
Args:
993+
varList: Names of variables to be extracted. Either unspecified to
994+
get names of available variables, or a single variable name
995+
as a string, or a list of variable names.
996+
resultfile: Path to the result file. If unspecified, the result
997+
file created by simulate() is used.
998+
999+
Returns:
1000+
If varList is None, a tuple with names of all variables
1001+
is returned.
1002+
If varList is a string, a 1D numpy array is returned.
1003+
If varList is a list, a 2D numpy array is returned.
1004+
1005+
Examples:
1006+
>>> mod.getSolutions()
1007+
('a', 'der(x)', 'time', 'x')
1008+
>>> mod.getSolutions("x")
1009+
np.array([[1. , 0.90483742, 0.81873075]])
1010+
>>> mod.getSolutions(["x", "der(x)"])
1011+
np.array([[1. , 0.90483742 , 0.81873075],
1012+
[-1. , -0.90483742, -0.81873075]])
1013+
>>> mod.getSolutions(resultfile="c:/a.mat")
1014+
('a', 'der(x)', 'time', 'x')
1015+
>>> mod.getSolutions("x", resultfile="c:/a.mat")
1016+
np.array([[1. , 0.90483742, 0.81873075]])
1017+
>>> mod.getSolutions(["x", "der(x)"], resultfile="c:/a.mat")
1018+
np.array([[1. , 0.90483742 , 0.81873075],
1019+
[-1. , -0.90483742, -0.81873075]])
10011020
"""
10021021
if resultfile is None:
1022+
if self._resultfile is None:
1023+
raise ModelicaSystemError("No result file found. Run simulate() first.")
10031024
resFile = self._resultfile.as_posix()
10041025
else:
10051026
resFile = resultfile

0 commit comments

Comments
 (0)