Tags and keywords
The Modelica By Example target code (using 'initial equation') is:
model SwitchedRLC "An RLC circuit with a switch"
type Voltage=Real(unit="V");
type Current=Real(unit="A");
type Resistance=Real(unit="Ohm");
type Capacitance=Real(unit="F");
type Inductance=Real(unit="H");
parameter Voltage Vb=24 "Battery voltage";
parameter Inductance L = 1;
parameter Resistance R = 100;
parameter Capacitance C = 1e-3;
Voltage Vs;
Voltage V;
Current i_L;
Current i_R;
Current i_C;
equation
Vs = if time>0.5 then Vb else 0;
i_R = V/R;
i_C = C*der(V);
i_L=i_R+i_C;
L*der(i_L) = (Vs-V);
end SwitchedRLC;
We once again encounter this limitation:
MagicDraw/Cameo could not handle export of the following expression:
Vs = if time>0.5 then Vb else 0;
It gave this:
vs=null0.5nullnullnullnullnull;
It turns out, however, that MagicDraw/Cameo can export the following fine (just not the inline "switching" form):
if time>0.5 then
vs=vb;
else
vs=0;
end if;
The exported Modelica code is:
model SwitchedRLC
SwitchedRLC _SwitchedRLC;
model SwitchedRLC
parameter Voltage vb(start=24.0,fixed=true);
parameter Inductance l(start=1.0,fixed=true);
parameter Resistance r(start=100.0,fixed=true);
parameter Capacitance c(start=0.001,fixed=true);
Voltage vs;
Voltage v;
Current i_l;
Current i_r;
Current i_c;
equation
i_r=v/r;
i_c=c*der(v);
l*der(i_l)=(vs-v);
i_l=i_r+i_c;
if time>0.5 then
vs=vb;
else
vs=0;
end if;
end SwitchedRLC;
type Voltage=Real(unit="V");
type Inductance=Real(unit="H");
type Resistance=Real(unit="Ω");
type Capacitance=Real(unit="F");
type Current=Real(unit="A");
end SwitchedRLC;