diff --git a/OMPython/ModelicaSystem.py b/OMPython/ModelicaSystem.py index e362520a..ee444c0f 100644 --- a/OMPython/ModelicaSystem.py +++ b/OMPython/ModelicaSystem.py @@ -314,7 +314,7 @@ def parse_simflags(simflags: str) -> dict[str, Optional[str | dict[str, str]]]: class ModelicaSystem: def __init__( self, - fileName: Optional[str | os.PathLike] = None, + fileName: Optional[str | os.PathLike | pathlib.Path] = None, modelName: Optional[str] = None, lmodel: Optional[list[str | tuple[str, str]]] = None, commandLineOptions: Optional[str] = None, @@ -360,9 +360,13 @@ def __init__( mod = ModelicaSystem("ModelicaModel.mo", "modelName", ["Modelica"]) mod = ModelicaSystem("ModelicaModel.mo", "modelName", [("Modelica","3.2.3"), "PowerSystems"]) """ + if fileName is None and modelName is None and not lmodel: # all None raise ModelicaSystemError("Cannot create ModelicaSystem object without any arguments") + if modelName is None: + raise ModelicaSystemError("A modelname must be provided (argument modelName)!") + self.quantitiesList = [] self.paramlist = {} self.inputlist = {} diff --git a/tests/test_ModelicaSystem.py b/tests/test_ModelicaSystem.py index 202e066d..71da85c8 100644 --- a/tests/test_ModelicaSystem.py +++ b/tests/test_ModelicaSystem.py @@ -57,7 +57,7 @@ def test_setParameters(): def test_setSimulationOptions(): omc = OMPython.OMCSessionZMQ() model_path = omc.sendExpression("getInstallationDirectoryPath()") + "/share/doc/omc/testmodels/" - mod = OMPython.ModelicaSystem(model_path + "BouncingBall.mo", "BouncingBall") + mod = OMPython.ModelicaSystem(fileName=model_path + "BouncingBall.mo", modelName="BouncingBall") # method 1 mod.setSimulationOptions("stopTime=1.234") @@ -88,7 +88,7 @@ def test_relative_path(model_firstorder): model_relative = str(model_file) assert "/" not in model_relative - mod = OMPython.ModelicaSystem(model_relative, "M") + mod = OMPython.ModelicaSystem(fileName=model_relative, modelName="M") assert float(mod.getParameters("a")[0]) == -1 finally: model_file.unlink() # clean up the temporary file @@ -145,7 +145,7 @@ def test_getters(tmp_path): y = der(x); end M_getters; """) - mod = OMPython.ModelicaSystem(model_file.as_posix(), "M_getters") + mod = OMPython.ModelicaSystem(fileName=model_file.as_posix(), modelName="M_getters") q = mod.getQuantities() assert isinstance(q, list) @@ -324,7 +324,7 @@ def test_simulate_inputs(tmp_path): y = x; end M_input; """) - mod = OMPython.ModelicaSystem(model_file.as_posix(), "M_input") + mod = OMPython.ModelicaSystem(fileName=model_file.as_posix(), modelName="M_input") mod.setSimulationOptions("stopTime=1.0") diff --git a/tests/test_ModelicaSystemCmd.py b/tests/test_ModelicaSystemCmd.py index f82510df..32f111b2 100644 --- a/tests/test_ModelicaSystemCmd.py +++ b/tests/test_ModelicaSystemCmd.py @@ -16,7 +16,7 @@ def model_firstorder(tmp_path): def test_simflags(model_firstorder): - mod = OMPython.ModelicaSystem(model_firstorder.as_posix(), "M") + mod = OMPython.ModelicaSystem(fileName=model_firstorder.as_posix(), modelName="M") mscmd = OMPython.ModelicaSystemCmd(runpath=mod.tempdir, modelname=mod.modelName) mscmd.args_set({ "noEventEmit": None, diff --git a/tests/test_linearization.py b/tests/test_linearization.py index e9f0f6d7..2c79190c 100644 --- a/tests/test_linearization.py +++ b/tests/test_linearization.py @@ -55,7 +55,7 @@ def test_getters(tmp_path): y2 = phi + u1; end Pendulum; """) - mod = OMPython.ModelicaSystem(model_file.as_posix(), "Pendulum", ["Modelica"]) + mod = OMPython.ModelicaSystem(fileName=model_file.as_posix(), modelName="Pendulum", lmodel=["Modelica"]) d = mod.getLinearizationOptions() assert isinstance(d, dict) diff --git a/tests/test_optimization.py b/tests/test_optimization.py index 672de4a6..aa74df79 100644 --- a/tests/test_optimization.py +++ b/tests/test_optimization.py @@ -33,7 +33,7 @@ def test_optimization_example(tmp_path): end BangBang2021; """) - mod = OMPython.ModelicaSystem(model_file.as_posix(), "BangBang2021") + mod = OMPython.ModelicaSystem(fileName=model_file.as_posix(), modelName="BangBang2021") mod.setOptimizationOptions(["numberOfIntervals=16", "stopTime=1", "stepSize=0.001", "tolerance=1e-8"])