- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » when-s in algorithms and 'if...
when-s in algorithms and 'if equations' (custom diode component)
when-s in algorithms and 'if equations' (custom diode component)
Hello All,
The model (electrical TestCircuit) has an ideal diode component, a sine voltage source, a ground and a resistor in a series composition. All the components are from the Modelica Standard Library except the diode model. We would like to run the simulation for 1 seconds.
Diode model:
This model has 2 states (on and off) and each state has its associated equation set.
1) On: V = VKnee
2) Off: I = 0
We ran the TestCircuit simulation using Dymola and it produced the expected simulation results. We also tried the OpenModelica (OM18 build rev 10584, OS: Win x64) tool to run the same example, but the diode does not change its state during the simulation. So, the generated plots are completely different.
We tried to change some of the conditions/structure in the model as follows:
A) If we change the enumeration into Boolean or Real it still does not work with OM.
B) If we change the guards in the when statements into 'time < 0.4'. OM can run the simulation and produces the expected simulation plots i.e. the mode is changing during the simulation.
If the 'when statement' has a guard which is a time dependent variable in the system does not change states during the simulation (OM).
Could you please give us hints how can we make this model compatible with the OM compiler/simulator?
Thanks,
Zsolt
PS: Please find the models below. I could not upload any attachments. (I have tried Chrome, Firefox, Internet Explorer)
------------------------------------------------------------------------------------------------------------------------------------
IdealIdealDiodeModesReduced.mo
Code:
within ;
model IdealDiodeModesReduced
extends Modelica.Electrical.Analog.Interfaces.OnePort;
parameter Modelica.SIunits.Resistance Ron(final min=0) = 1.E-5;
parameter Modelica.SIunits.Conductance Goff(final min=0) = 1.E-5;
parameter Modelica.SIunits.Voltage Vknee(final min=0, start=0);
//extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort;
type Model = enumeration(
on,
off);
Model m(start=Model.off);
algorithm
when (i - Goff * Vknee) < 0 then
m:= Model.off;
elsewhen (v - Vknee) >= 0 then
m:= Model.on;
end when;
equation
if m ==Model.off then
i = 0;/*(v - Vknee) * Goff = (i - (Goff * Vknee));*/
else
v = Vknee; /*(v - Vknee) = (i - (Goff * Vknee)) * Ron;*/
end if;
//LossPower = v * i;
annotation (uses(Modelica(version="3.2")),
version="2",
conversion(noneFromVersion="", noneFromVersion="1"));
end IdealDiodeModesReduced;
-------------------------------------------------------------------------------------------------------------------------------------------------------------
TestCircuit.mo
Code:
within ;
model TestCircuit
IdealDiodeModesReduced idealDiodeModesReduced(Vknee=0.6)
annotation (Placement(
transformation(extent={{-36,36},{-16,56}}, rotation=0)));
Modelica.Electrical.Analog.Sources.SineVoltage sineVoltage annotation (
Placement(transformation(extent={{-42,-14},{-22,6}}, rotation=0)));
Modelica.Electrical.Analog.Basic.Ground ground annotation (Placement(
transformation(extent={{-12,-22},{8,-2}}, rotation=0)));
Modelica.Electrical.Analog.Basic.Resistor resistor annotation (Placement(
transformation(extent={{14,36},{34,56}}, rotation=0)));
equation
connect(sineVoltage.p, idealDiodeModesReduced.p) annotation (Line(
points={{-42,-4},{-52,-4},{-52,46},{-36,46}},
color={0,0,255},
smooth=Smooth.None));
connect(sineVoltage.n, ground.p) annotation (Line(
points={{-22,-4},{-12,-4},{-12,-2},{-2,-2}},
color={0,0,255},
smooth=Smooth.None));
connect(idealDiodeModesReduced.n, resistor.p) annotation (Line(
points={{-16,46},{14,46}},
color={0,0,255},
smooth=Smooth.None));
connect(resistor.n, ground.p) annotation (Line(
points={{34,46},{52,46},{52,-2},{-2,-2}},
color={0,0,255},
smooth=Smooth.None));
annotation (
uses(IdealDiodeModesReduced(version="2"), Modelica(version="3.2")),
Diagram(graphics),
version="1",
conversion(noneFromVersion=""));
end TestCircuit;
------------------------------------------------------------------------------------------------------------------------
- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » when-s in algorithms and 'if...