Opened 16 years ago

Last modified 14 years ago

#1021 closed defect (fixed)

Derivative of expressions der(x -y) does not generate correct code.

Reported by: Adrian Pop Owned by: Adrian Pop
Priority: high Milestone:
Component: Simulation Code Generation Version:
Keywords: Cc: Adrian Pop, Adrian Pop

Description

{{{connector ElectricalPin

Modelica.SIunits.Voltage v;
flow Modelica.SIunits.Current i;

end ElectricalPin;

model Resistor

import Modelica.SIunits;
parameter SIunits.Resistance R = 300;
ElectricalPin p, n;

equation

R * p.i = p.v - n.v;
p.i + n.i = 0;

end Resistor;

/* fix 1
model Capacitor

import Modelica.SIunits;
parameter SIunits.Capacitance C = 1e-6;
ElectricalPin p, n;
Modelica.SIunits.Voltage v;

equation

v = p.v - n.v;
p.i = C * der(v);
p.i + n.i = 0;

end Capacitor; */

/* fix 2 */
model Capacitor

import Modelica.SIunits;
parameter SIunits.Capacitance C = 1e-6;
ElectricalPin p, n;

equation

p.i = C * (der(p.v) - der(n.v)); the problem is here p.i = C * der(p.v - n.v);
p.i + n.i = 0;

end Capacitor;

model Inductor

import Modelica.SIunits;
parameter SIunits.Inductance L = 1e-3;
ElectricalPin p, n;

equation

L * der(p.i) = p.v - n.v;
p.i + n.i = 0;

end Inductor;

model Ground

ElectricalPin ground;

equation

ground.v = 0;

end Ground;

model VoltageSource

import Modelica.SIunits;
parameter SIunits.Voltage v1=0, v2=1;
parameter SIunits.Time jump_time=1.0;
ElectricalPin p, n;

equation

p.v - n.v = if time > jump_time then v2 else v1;
p.i + n.i = 0;

end VoltageSource;

model RLC4

Resistor R1(R = 15);
Resistor R2(R = 5000);
Capacitor C1(C = 100e-6);
Inductor L1(L = 100e-3);
VoltageSource vs;
Ground g;

equation

connect(vs.n, g.ground);
connect(vs.p, L1.p);
connect(L1.n, R1.p);
connect(L1.n, R2.p);
connect(R1.n, C1.p);
connect(C1.n, g.ground);
connect(R2.n, g.ground);

end RLC4;}}}

The problem is with expresion p.i = C * der(p.v - n.v);

Change History (1)

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

This was fixed in trunk

Note: See TracTickets for help on using tickets.