Opened 15 years ago

Last modified 15 years ago

#1110 closed defect (fixed)

DAE equation generated by OMC 1.4.5 seems to be wrong

Reported by: Schubert TUD Owned by: Schubert TUD
Priority: high Milestone:
Component: Simulation Code Generation Version: 1.4.5
Keywords: Cc: Schubert TUD,

Description

Hello everybody,

here a problem I also reported in the OpenModelicaInterest mailing list.

When trying to simulate the following model, a different set of equations (neglecting v) is generated as C-Code.

model FlatTest

Real pb(start = 12000000);
Real Qb;
Real pa(start = 12000000);
Real Qa;
parameter Real s = 1;
input Real v;
input Real inFlow;


equation

der(pb) = (Qb - v) / s;
der(pa) = (Qa - v) / s;
pa = pb;
inFlow + Qa + Qb = 0;


end FlatTest;

Looking at the C-code generated by the OMC given below, one can reconstruct that the following (incorrect) system of linear equations has been implemented by the OMC:

der(pa) -s/s2*Qa = 0; <- v is missing !
-der(pb) + der(pa) = 0;
-s/s
2*Qb + der(pb) = 0; <- v is missing !
Qb + Qa = -inFlow;

Strangely, when you turn the "parameter Real s=1" into a "constant Real s =1" everything is fine. The system of equations then reads:

der(pa) - Qa = -v;
-der(pb) + der(pa) = 0;
-Qb + der(pb) = -v;
Qb + Qa = -inFlow;

Kind regards,

Christian Schubert


  • C-Code: (FlatTest.cpp) *


int functionODE()
{

state mem_state;
mem_state = get_memory_state();
declare_matrix(A34,4,4);
declare_vector(b34,4);
set_matrix_elt(A34,0, 3, 4, ((-$s) / ($s * $s)));
set_matrix_elt(A34,0, 2, 4, 1.0);
set_matrix_elt(A34,1, 1, 4, -1.0);
set_matrix_elt(A34,1, 2, 4, 1.0);
set_matrix_elt(A34,2, 0, 4, ((-$s) / ($s * $s)));
set_matrix_elt(A34,2, 1, 4, 1.0);
set_matrix_elt(A34,3, 0, 4, 1.0);
set_matrix_elt(A34,3, 3, 4, 1.0);
set_vector_elt(b34,0, 0.0);
set_vector_elt(b34,1, 0.0);
set_vector_elt(b34,2, 0.0);
set_vector_elt(b34,3, (-$inFlow));
solve_linear_equation_system(A34,b34,4,34);
$Qa = get_vector_elt(b34,3);
$der$lPpa$rP = get_vector_elt(b34,2);
$DER$pb = get_vector_elt(b34,1);
$Qb = get_vector_elt(b34,0);
restore_memory_state(mem_state);
return 0;

}

Change History (0)

Note: See TracTickets for help on using tickets.