4

To override multiple parameters of a permanent magnet DC machine with the content of a DcPermanentMagnetData record I use this construct:

Modelica.Electrical.Machines.Utilities.ParameterRecords.DcPermanentMagnetData dcpmData(
    IaNominal = 1, 
    VaNominal = 2, 
    wNominal = 3);

Modelica.Electrical.Machines.BasicMachines.DCMachines.DC_PermanentMagnet dcpm(
    IaNominal = dcpmData.IaNominal,
    VaNominal = dcpmData.VaNominal,
    wNominal = dcpmData.wNominal);

Is it possible to set multiple parameter values of a model with a single command instead?

MWE:

model MWE

  record Rec
    parameter Real x_init;
    parameter Real y_init;
  end Rec;

  model HelloWorld
    parameter Real x_init;
    parameter Real y_init;
    Real x;
    Real y;
    initial equation
      x = x_init;
      y = y_init;
    equation
      der(x)=-x;
      der(y)=-y;
  end HelloWorld;

  Rec r (x_init = 1, y_init = 2);
  HelloWorld hi (x_init = r.x_init, y_init = r.y_init);  // this works
  //HelloWorld hi ( allValuesFrom(r) );  // <--- something like this

end MWE;
id -un
  • 188
  • 1
  • 8

1 Answers1

2

You can pass the whole record to the model. For that you have to replace your parameters with an instance of the record:

model MWE
      record Rec
        parameter Real x_init;
        parameter Real y_init;
      end Rec;

      model HelloWorld
        input Rec r;
        Real x;
        Real y;
      initial equation 
          x = r.x_init;
          y = r.y_init;
      equation 
          der(x)=-x;
          der(y)=-y;
      end HelloWorld;

      Rec r( x_init = 1, y_init = 2);
      HelloWorld hi(r=r);
end MWE;
marco
  • 5,944
  • 10
  • 22
  • This works, but the Modelica system library is read-only. Wrapping the motor model to accept a record as an input certainly helps for repeated usage but only pushes the problem into another model that has to be defined for every new system model (eg. different motor types). – id -un Nov 06 '19 at 13:37
  • 2
    Then I think the answers is that you can't. What you need is a concept like kwargs and unpacking of dictionaries in python, which does not exist in Modelica. But I would be happy if someone knows better and provides a solution for this problem. – marco Nov 06 '19 at 14:12
  • 1
    I would write "parameter Rec r;" instead of "input Rec r;" The advantage is that r then appears in the parameter-dialog. – Hans Olsson Nov 07 '19 at 09:18
  • In Dymola yes, but OpenModelica refuses to compile the model. – marco Nov 07 '19 at 09:30