beutlich/LastLib

Start value of the minimum

tinrabuzin opened this issue · 16 comments

Hi,

Thanks for the great library! I noticed after the latest commit that the computation of the minimum does not start from the specified y_start value. See the screenshot bellow. I get this result on Linux OM v1.16.5.

image

@beutlich I don't know if this is the good fix, but I was playing around with the models and realized that if I write in the line 263 of LastLib.Last_omc the following:

  flowParamsStart := fmi1Functions.fmi1SetRealParameter(fmi1me, {1.0}, {y_start});

instead of

  flowParamsStart := fmi1Functions.fmi1SetRealParameter(fmi1me, {0.0}, {y_start});

the example starts from the correct y_start.

Sorry, I missed this one completely.

Can you share the model MinimumTest.Test please that you edited with OMEdit? Maybe the workaround mentioned on page 13 of https://tinyurl.com/lastlibfmu still needs to be applied.

I haven't changed MinimumTest.Test. It was LastLib.Last_omc that I was changing. I'll make a draft PR if you want?

Still you need to adapt MinimumTest.Test to select the redeclared model of Last being LastLib.Last_omc.

Right, I think I did that already:

block Minimum
  extends Modelica.Blocks.Interfaces.SISO;
  parameter Real y_start=Modelica.Constants.inf "Initialization of minimum";
  replaceable model Last = LastLib.Last_omc constrainedby LastLib.LastBase(y_start=y_start) "Last FMU"
    annotation(choices(
     choice(redeclare model Last = LastLib.Last_dymola_linux "Last for Dymola (Linux)"),
     choice(redeclare model Last = LastLib.Last_dymola_windows "Last for Dymola (Windows)"),
     choice(redeclare model Last = LastLib.Last_omc "Last for OpenModelica (C runtime)"),
     choice(redeclare model Last = LastLib.Last_simx "Last for SimulationX")));
  Last last(y_start=y_start) "Last FMU" annotation(Placement(transformation(extent={{-30,10},{-10,30}})));
  Modelica.Blocks.Math.Min min annotation(Placement(transformation(extent={{10,-10},{30,10}})));
  equation
    connect(u, min.u2) annotation(Line(points={{-120,0},{0,0},{0,-6},{8,-6}}, color={0,0,127}));
    connect(min.y, y) annotation(Line(points={{31,0},{110,0}}, color={0,0,127}));
    connect(last.y, min.u1) annotation(Line(points={{-9,20},{0,20},{0,6},{8,6}}, color={0,0,127}));
    connect(min.y, last.u) annotation(Line(points={{31,0},{40,0},{40,40},{-40,40},{-40,20},{-32,20}}, color={0,0,127}));
  annotation(defaultComponentName="min", preferredView="diagram");
end Minimum;

OK, I have another idea:

--- a/LastLib/Resources/sources/last.c
+++ b/LastLib/Resources/sources/last.c
@@ -34,7 +34,7 @@ void setStartValues(ModelInstance *comp) {
 // called by fmiInitialize() after setting eventInfo to defaults
 // Used to set the first time event, if any.
 void initialize(ModelInstance* comp, fmiEventInfo* eventInfo) {
-    r(y_) = r(y_start_);
+    r(u_) = r(y_start_);
 }
 
 // called by fmiCompletedIntegratorStep()

I can provide the updated FMU binaries if you want to test it,

Yes, please do!

They are now available from new branch fix-y_start.

But fail to correctly initialize in Dymola ...

... and pushed again.

OK, need to check in more detail later,

I deleted my comment since I was doing things in a wrong terminal. I checkout out the latest commit in the branch and it works now! At least on Windows OMC. Thanks!

Phew, thanks for confirmation. If you can test in Linux later, just let me know, if it also works there,

It works on Linux as well!

Resolved by 65f205f.