Opened 14 years ago

Last modified 14 years ago

#1334 closed task (fixed)

Do dependency analysis in instElementList

Reported by: Martin Sjölund Owned by: Martin Sjölund
Priority: high Milestone: White December
Component: Version:
Keywords: Cc: Martin Sjölund, Per Östlund

Description

In order to instantiate Modelica.Media models, we need to instantiate elements in the order of dependencies.
First constants, then parameters, then variables.
You need to start with constants that have no dependencies on other constants in the package.
As a first step, we could simply say that constants with bindings that contain function calls are instantiated after any other constant (functions may refer to constants in this package). If this does not solve the issues, we need all dependencies in all functions called by this function, etc.

You can verify that this solves some issues in Modelica.Media by changing the order of the declared constants in packages.

Note: You cannot do the dependency analysis lazy (instElement on another element if we realize it's needed). The reason for this is that you sometimes end up with infinite loops.

Attachments (1)

TestGlycolTotal.mo (67.7 KB ) - added by Martin Sjölund 14 years ago.
I can't remember if I modified this test or not work around lookup issues. So I'll attach the model I used.

Download all attachments as: .zip

Change History (7)

comment:1 by Per Östlund, 14 years ago

In Inst.Classdef2 we currently sort all conditional components so that they are instantiated last, since they might depend on other components (this is safe to do, since conditional components can't be dependencies of each other or other components). If we do dependency checking I guess this is not needed any more.

comment:2 by Adrian Pop, 14 years ago

Martin, can you provide a model for this?

comment:3 by Martin Sjölund, 14 years ago

Modelica.Media.Incompressible.Examples.Glycol47 :)

The following function is called before TinK is instantiated:

        function h_T "Compute specific enthalpy from temperature"
          import Modelica.SIunits.Conversions.to_degC;
          extends Modelica.Icons.Function;
          input SI.Temperature T "Temperature";
          output SI.SpecificEnthalpy h "Specific enthalpy at p, T";
        algorithm
          h :=h0 + Poly.integralValue(poly_Cp, if TinK then T else Cv.to_degC(T), if TinK then 
          T0 else Cv.to_degC(T0));
        end h_T;

Note that I also found:

        function invertTemp "function to invert temperatures"
          input Real[:] table "table temperature data";
          input Boolean Tink "flag for Celsius or Kelvin";
          output Real invTable[size(table,1)] "inverted temperatures";
        algorithm
          for i in 1:size(table,1) loop
            invTable[i] := if TinK then 1/table[i] else 1/Cv.from_degC(table[i]);
          end for;
        end invertTemp;

So I'm guessing Dymola didn't handle this at some point in time either (note that the Tink input is not used any longer).

by Martin Sjölund, 14 years ago

Attachment: TestGlycolTotal.mo added

I can't remember if I modified this test or not work around lookup issues. So I'll attach the model I used.

comment:4 by Adrian Pop, 14 years ago

Thanks. I'll look into it.

comment:5 by Per Östlund, 14 years ago

Dependency sorting of constants and parameters in a package (without looking in called functions) has now been implemented. This seems to solve the problems with Glycol47 at least, but it remains to be seen if this is enough for the rest of Media or not.

comment:6 by Martin Sjölund, 14 years ago

1/3 works....

model M
  function fn1
    output Real r;
  external "C" r = sin(c1+c3);
  end fn1;

  function fn2
    output Real r := sin(c1+c3);
  end fn2;

  function fn3
    output Real r;
  algorithm
    r := sin(c1+c3);
  end fn3;
  constant Real c1 = 1.0;
  constant Real c2 = fn1();
  constant Real c3 = c1+1.0;
end M;
Note: See TracTickets for help on using tickets.