modelicadymola

Dymola's translateModel function with a model name and modifiers for the problem argument


Why does Dymola report that the variable x0 is undeclared when calling translateModel(problem="Sandbox.Test(x_start=x0)")? Notice that translateModel is a built-in, internal, Dymola function to initiate a model translation from the command line. The input to the function is the class as a string input.

In my example to demonstrate my question, the model Test is defined as in the following:

model Test
  parameter Real x0=1.234;
  parameter Real x_start=-1.234;
  Real x(start=x_start, fixed=true);

equation 
  der(x) = time;

end Test;

As expected, I can extend from test and apply the same modifier as in the following model:

model Tester
  extends Test(x_start=x0);
end Tester;

In the case of the Tester model, the call to translateModel(problem="Sandbox.Tester") succeeds without error.

This seems similar to the question posed in this post, but it's not quite the same.

So can someone clarify why the call translateModel(problem="Sandbox.Test(x_start=x0)") fails? Do the modifiers in this string need to be literal values? Or is there a different way to make this call with the modifer?


Solution

  • The modifiers in that argument for translateModel are handled similarly to

    model Tester=Test(x_start=x0);
    

    instead of as

    model Tester
      extends Test(x_start=x0);
    end Tester;
    

    So, even if not strictly limited to literals you cannot use any local variables from the model in the modifier.

    However, I'm unsure why you need this - if you included a more realistic example it might be easier to suggest another solution.