pythonvectorinterfacemodelicadymola

How to add parameters as vectors in the Python interface to Dymola?


I have a model in Dymola which I run from Python (using the example interface that is given in the Dymola installation folder). Everything works well, but when I want to add an input parameter that has to be in vector form in Dymola (in de Dymola syntax this means that the value has to be between two curly brackets {}) everything fails.

Below is the line I use in Python to execute the Dymola model: result = dymola.simulateExtendedModel(problem=My_Model, startTime=0.0, stopTime=50000, numberOfIntervals=500, method="Dassl", tolerance=1e-07, resultFile = r"C:\Users\arty\Desktop\DYMOLAEXTRACT\Resultats", initialNames=["evaporatorGas_altered.Shot", "evaporatorGas_altered.Scold", "PI2.y_start", "HPT.Xi_cool_stat", "HPT.Xi_cool_rot"], initialValues=[i, i, PI_initial_output_propeller_torque[counter], **0.0208189** , **0.03122835**], finalNames=dym_lst_vars)

The two values in bold font are the two values that give me issues. Dymola only accepts these values in vector form (so if I go to the Dymola model and manually enter {0.0208189} and {0.03122835}, everything works.

I tried to enter these values in the same syntax in Python, but that doesn't work. I tried:

result = dymola.simulateExtendedModel(problem=My_Model, startTime=0.0, stopTime=50000, numberOfIntervals=500, method="Dassl", tolerance=1e-07, resultFile = r"C:\Users\arty\Desktop\DYMOLAEXTRACT\Resultats", initialNames=["evaporatorGas_altered.Shot", "evaporatorGas_altered.Scold", "PI2.y_start", "HPT.Xi_cool_stat", "HPT.Xi_cool_rot"], initialValues=[i, i, PI_initial_output_propeller_torque[counter], "{"+str(0.0208189)+"}" , "{"+str(0.03122835)+"}"], finalNames=dym_lst_vars)

But it seems that Dymola doesn't understand this.

The error code that I get in Python is: Error: Failed to parse response from Dymola. Error when calling Dymola function "simulateExtendedModel".


Solution

  • This seems complicated to investigate without the model. However, based on normal naming I would assume that Xi is a vector, and given that it can be set to {0.0208189} that it is a vector of one element.

    That would indicate that the correct command is:

    result = dymola.simulateExtendedModel(problem=My_Model, 
      startTime=0.0, 
      stopTime=50000, 
      numberOfIntervals=500, 
      method="Dassl", 
      tolerance=1e-07, 
      resultFile = r"C:\Users\arty\Desktop\DYMOLAEXTRACT\Resultats",
      initialNames=["evaporatorGas_altered.Shot", "evaporatorGas_altered.Scold", "PI2.y_start", 
        "HPT.Xi_cool_stat[1]", "HPT.Xi_cool_rot[1]"], 
      initialValues=[i, i, PI_initial_output_propeller_torque[counter], 
        0.0208189, 0.03122835], 
      finalNames=dym_lst_vars)
    

    Note that it was changed to "HPT.Xi_cool_stat[1]" and "HPT.Xi_cool_rot[1]".