Opened 13 years ago

Last modified 13 years ago

#1594 closed defect (fixed)

Some calculations with three-dimensional variables cause errors

Reported by: lempinen Owned by: lempinen
Priority: high Milestone:
Component: Version: 1.7.0
Keywords: Cc: lempinen,

Description

Following simulates

model ArrayTest 
  Real Stock[1,1,1](each fixed = false, each start = 0.0); 
  Real Valve1[1,1,1] = fill(1, 1, 1, 1); 
  Real Valve2[1,1,1] = fill(1, 1, 1, 1); 
equation 
  der(Stock) = - Valve1 - Valve2; 
end ArrayTest; 

and flattens to

class ArrayTest 
  Real Stock[1,1,1](start = 0.0, fixed = false); 
  Real Valve1[1,1,1] = 1.0; 
  Real Valve2[1,1,1] = 1.0; 
equation 
  der(Stock1,1,1) = (-Valve11,1,1) - Valve21,1,1; 
end ArrayTest;

Following does not simulate

model ArrayTest 
  Real Stock[1,1,1](each fixed = false, each start = 0.0); 
  Real Valve1[1,1,1] = fill(1, 1, 1, 1); 
  Real Valve2[1,1,1] = fill(1, 1, 1, 1); 
equation 
  der(Stock) = Valve1 - Valve2; 
end ArrayTest;
Error: Error building simulator. Buildlog: The syntax of the command is incorrect.
gcc  -O3 -falign-functions -msse2 -mfpmath=sse   -I\"C:/OpenModelica1.7.0//inclu 
de/omc\" -I.    -c -o ArrayTest.o ArrayTest.c 
ArrayTest.c: In function `functionODE': 
ArrayTest.c:321: error: invalid lvalue in unary `&' 
ArrayTest.c: In function `functionDAE': 
ArrayTest.c:389: error: invalid lvalue in unary `&' 
\MinGW
bin
mingw32-make: *** ArrayTest.o Error 1 

And flattens strangely to

class ArrayTest 
  Real Stock[1,1,1](start = 0.0, fixed = false); 
  Real Valve1[1,1,1] = 1.0; 
  Real Valve2[1,1,1] = 1.0; 
equation 
  der(Stock1,1,1) = ({Valve11,1,1} - {Valve21,1,1})[1]; 
end ArrayTest; 

The flattened model basically seems right, but a little too complex. I don't know where the actual problem is, but the simulations will not work.

The problem appears or dissappears with different operator combinations.
The follwing combinations work and flatten nicely

  der(Stock) = Valve1 .* Valve2; 
  der(Stock) = - Valve1 - Valve2; 
  der(Stock) = Valve1 ./ Valve2; 
  der(Stock) = - Valve1 + Valve2; 
  der(Stock) = - Valve1 + Valve2 + Valve1 + Valve2;

But the following do not

  der(Stock) = Valve1 + Valve2; 
  der(Stock) = Valve1 - Valve2;

The problem is quite urgent for us, since we need three-dimensional arrays for a model in the OpenProd project.

Change History (4)

comment:1 Changed 13 years ago by sjoelund.se

Made some formatting changes

comment:2 Changed 13 years ago by sjoelund.se

And readding the brackets that were lost

comment:3 Changed 13 years ago by sjoelund.se

Seems to be a problem in ExpressionSimplify; should be very easy to fix:

    solve:
      der(Stock[1,1,1]) = 0.0[1]
      =>
      der(Stock[1,1,1]) = 0.0[1]
    added assertions:
  
    derive:
      d/dtime der(Stock[1,1,1])
      =>
      der(Stock[1,1,1])
    simplify:
      ({1.0} - {1.0})[1]
      =>
      0.0[1]
    subst:
      ({Valve1[1,1,1]} - {Valve2[1,1,1]})[1]
      =>
      ({1.0} - {Valve2[1,1,1]})[1]
      =>
      ({1.0} - {1.0})[1]

comment:4 Changed 13 years ago by sjoelund.se

Now works correctly in r9695 (Linux/Mac nightly builds expected to be up in 27 hours; Windows builds unknown).

Note: See TracTickets for help on using tickets.