Hi,

You could try as a workaround:
initial equation
  p =  outRec(a^2, a^3);

Cheers,
Adrian Pop/

On 2012-02-09 19:46, Tom Short wrote:
Thanks, Lennart. My initialization involves a few variables in nested
for loops, so a function call or an algorithm makes the most sense. I
also tried packaging up return values in a record, but my attempt at
that also failed in OpenModelica (it worked in Dymola).

package testInitialAlgorithm
   record outRec
     Real y(fixed = false);
     Real z(fixed = false);
   end outRec;

   function fun2
     input Real x;
     output outRec out;
   algorithm
     out.y := x^2;
     out.z := x^3;
   end fun2;

   model m5
     parameter Real a = 3;
     parameter outRec p;
   initial equation
     p =  fun2(a);
   end m5;

end testInitialAlgorithm;


On Thu, Feb 9, 2012 at 12:02 PM, Lennart Ochel
<[email protected]>  wrote:
Hello,

currently we do not support initial algorithms at all.

As an workaround you can try to convert your initial
algorithm into an initial equation. This will help for
testInitialAlgorithm.m1 and testInitialAlgorithm.m2.

Tomorrow I will take a closer look on how to provide
initial algorithms and functions with multiple return-values.

Best regards,
Lennart Ochel



-----Ursprüngliche Nachricht----- From: Tom Short<[email protected]>
Reply-to: [email protected]
To: [email protected]
Subject: Initialization issues during simulation
Date: Thu, 09 Feb 2012 09:45:03 -0500


Hello,

I'm working on a package where I would eventually like to support both
Dymola and OpenModelica. One part relies on quite a bit of
pre-processing to initialize several parameters before models are
simulated. I haven't found a good way to do this in OpenModelica. The
following example shows several ways I've tried to initialize
parameters. The first two (m1 and m2) simulate, but the parameters are
not initialized properly. The second two (m3 and m4) fail when
generating code. Does anyone see errors in my code or know of
workarounds for this? All models seem to flatten properly and pass
check (except for m4).

package testInitialAlgorithm
  model m1
   parameter Real a = 3;
   parameter Real b(fixed = false);
  initial algorithm
   b:=a ^ 2;
  end m1;

  model m2
   m1 m(a = 4);
   Real c;
  equation
   c = m.b + 1.0;
  end m2;

  function fun
   input Real x;
   output Real y;
   output Real z;
  algorithm
   y:=x ^ 2;
   z:=x ^ 3;
  end fun;

  model m3
   parameter Real a = 3;
   parameter Real b(fixed = false);
   parameter Real c(fixed = false);
  initial equation
   (b,c) = fun(a);
  end m3;

  model m4
   parameter Real a = 3;
   parameter Real b(fixed = false);
   parameter Real c(fixed = false);
  initial algorithm
   (b,c):=fun(a);
  end m4;
end testInitialAlgorithm;

The model m3 fails with the following error:

   CodegenC.tpl: Template error: Unknown expression: (b,c)

The model m4 fails with the following error:

  Tuple assignment only allowed when rhs is function call (in
testInitialAlgorithm.fun(a))

I tested this on r11033 on 64-bit win7 and r11047 on ubuntu.

- Tom



Reply via email to