# 直流电源¶

## 无层级电源模型¶

within ModelicaByExample.Subsystems.PowerSupply.Examples;
model FlatCircuit "A model with power source, AC-DC conversion and load in one diagram"
import Modelica.Electrical.Analog;
Analog.Sources.SineVoltage wall_voltage(V=120, freqHz=60)
annotation (Placement(transformation(
extent={{-10,-10},{10,10}},
rotation=270, origin={-90,0})));
Analog.Ideal.IdealClosingSwitch switch(Goff=0)
annotation (Placement(transformation(extent={{-80,30},{-60,50}})));
Analog.Ideal.IdealTransformer transformer(Lm1=1, n=10, considerMagnetization=false)
annotation (Placement(transformation(extent={{-50,0},{-30,20}})));
Analog.Ideal.IdealDiode D1(Vknee=0, Ron=1e-5, Goff=1e-5)
annotation (Placement(
transformation(
extent={{-10,-10},{10,10}},
rotation=45, origin={-12,20})));
Analog.Basic.Capacitor capacitor(C=1e-2)
annotation (Placement(
transformation(
extent={{-10,-10},{10,10}},
rotation=270, origin={60,-10})));
annotation (Placement(
transformation(
extent={{-10,-10},{10,10}},
rotation=270, origin={100,-10})));
Modelica.Blocks.Sources.BooleanStep step(startTime=0.25)
annotation (Placement(transformation(extent={{-100,50},{-80,70}})));
Analog.Ideal.IdealDiode D2(Vknee=0, Ron=1e-5, Goff=1e-5)
annotation (Placement(
transformation(
extent={{-10,-10},{10,10}},
rotation=-45, origin={12,20})));
Analog.Ideal.IdealDiode D3(Vknee=0, Ron=1e-5, Goff=1e-5)
annotation (Placement(
transformation(
extent={{-10,-10},{10,10}},
rotation=-45, origin={-12,0})));
Analog.Ideal.IdealDiode D4(Vknee=0, Ron=1e-5, Goff=1e-5)
annotation (Placement(
transformation(
extent={{-10,-10},{10,10}},
rotation=45, origin={12,0})));
Analog.Basic.Ground ground1
annotation (Placement(transformation(extent={{-100,-52},{-80,-32}})));
equation
connect(switch.p, wall_voltage.p) annotation (Line(
points={{-80,40},{-90,40},{-90,10}},
color={0,0,255}, smooth=Smooth.None));
connect(switch.n, transformer.p1) annotation (Line(
points={{-60,40},{-50,40},{-50,15}},
color={0,0,255}, smooth=Smooth.None));
connect(step.y, switch.control) annotation (Line(
points={{-79,60},{-70,60},{-70,47}},
color={255,0,255}, smooth=Smooth.None));
connect(D3.n, D4.p) annotation (Line(
points={{-4.92893,-7.07107},{-2.46446,-7.07107},{-2.46446,-7.07107},{
1.09406e-006,-7.07107},{1.09406e-006,-7.07107},{4.92893,-7.07107}},
color={0,0,255}, smooth=Smooth.None));
connect(D1.n, D2.p) annotation (Line(
points={{-4.92893,27.0711},{2.18813e-006,28},{4.92893,28},{4.92893, 27.0711}},
color={0,0,255}, smooth=Smooth.None));
connect(D1.p, D3.p) annotation (Line(
points={{-19.0711,12.9289},{-20,10},{-19.0711,7.07107}},
color={0,0,255}, smooth=Smooth.None));
connect(D2.n, D4.n) annotation (Line(
points={{19.0711,12.9289},{19.0711,11.4644},{19.0711,11.4644},{19.0711,10},
{19.0711,7.07107},{19.0711,7.07107}},
color={0,0,255}, smooth=Smooth.None));
connect(transformer.p2, D1.n) annotation (Line(
points={{-30,15},{-30,34},{0,34},{0,27.0711},{-4.92893,27.0711}},
color={0,0,255}, smooth=Smooth.None));
connect(D4.p, transformer.n2) annotation (Line(
points={{4.92893,-7.07107},{0,-7.07107},{0,-20},{-30,-20},{-30,5}},
color={0,0,255}, smooth=Smooth.None));
connect(wall_voltage.n, transformer.n1) annotation (Line(
points={{-90,-10},{-90,-20},{-50,-20},{-50,5}},
color={0,0,255}, smooth=Smooth.None));
connect(wall_voltage.n, ground1.p) annotation (Line(
points={{-90,-10},{-90,-32}},
color={0,0,255}, smooth=Smooth.None));
connect(transformer.n2, ground1.p) annotation (Line(
points={{-30,5},{-30,-32},{-90,-32}},
color={0,0,255}, smooth=Smooth.None));
points={{100,0},{100,12},{20,12},{20,12.9289},{19.0711,12.9289}},
color={0,0,255}, smooth=Smooth.None));
points={{100,0},{100,12},{60,12},{60,0}},
color={0,0,255}, smooth=Smooth.None));
connect(D1.p, capacitor.n) annotation (Line(
points={{-19.0711,12.9289},{-24,12.9289},{-24,-32},{60,-32},{60,-20}},
color={0,0,255}, smooth=Smooth.None));
points={{100,-20},{100,-32},{60,-32},{60,-20}},
color={0,0,255}, smooth=Smooth.None));
end FlatCircuit;


## 有层级电源¶

within ModelicaByExample.Subsystems.PowerSupply.Components;
model BasicPowerSupply "Power supply with transformer and rectifier"
import Modelica.Electrical.Analog;
parameter Modelica.SIunits.Capacitance C
"Filter capacitance"
annotation(Dialog(group="General"));
parameter Modelica.SIunits.Conductance Goff=1.E-5
"Backward state-off conductance (opened diode conductance)"
annotation(Dialog(group="General"));
parameter Modelica.SIunits.Resistance Ron=1.E-5
"Forward state-on differential resistance (closed diode resistance)"
annotation(Dialog(group="General"));
parameter Real n
"Turns ratio primary:secondary voltage"
annotation(Dialog(group="Transformer"));
parameter Boolean considerMagnetization=false
"Choice of considering magnetization"
annotation(Dialog(group="Transformer"));
parameter Modelica.SIunits.Inductance Lm1
"Magnetization inductance w.r.t. primary side"
annotation(Dialog(group="Transformer", enable=considerMagnetization));

Analog.Interfaces.NegativePin gnd
"Pin to ground power supply"
annotation (Placement(transformation(extent={{-110,-70},{-90,-50}})));
Analog.Interfaces.PositivePin p
"Positive pin on supply side"
annotation (Placement(transformation(extent={{-110,50},{-90,70}})));
annotation (Placement(transformation(extent={{90,50},{110,70}})));
annotation (Placement(transformation(extent={{90,-70},{110,-50}})));
protected
Analog.Ideal.IdealTransformer transformer(
final n=n, final considerMagnetization=considerMagnetization,
final Lm1=Lm1)
annotation (Placement(transformation(extent={{-60,-10},{-40,10}})));
Analog.Ideal.IdealDiode D1(final Vknee=0, final Ron=Ron, final Goff=Goff)
annotation (Placement(
transformation(
extent={{-10,-10},{10,10}},
rotation=45,
origin={-2,10})));
Analog.Basic.Capacitor capacitor(C=C)
annotation (Placement(
transformation(
extent={{-10,-10},{10,10}},
rotation=270,
origin={70,-20})));
Analog.Ideal.IdealDiode D2(final Vknee=0, final Ron=Ron, final Goff=Goff)
annotation (Placement(
transformation(
extent={{-10,-10},{10,10}},
rotation=-45,
origin={22,10})));
Analog.Ideal.IdealDiode D3(final Vknee=0, final Ron=Ron, final Goff=Goff)
annotation (Placement(
transformation(
extent={{-10,-10},{10,10}},
rotation=-45,
origin={-2,-10})));
Analog.Ideal.IdealDiode D4(final Vknee=0, final Ron=Ron, final Goff=Goff)
annotation (Placement(
transformation(
extent={{-10,-10},{10,10}},
rotation=45,
origin={22,-10})));
equation
connect(D3.n,D4. p) annotation (Line(
points={{5.07107,-17.0711},{10,-18},{14.9289,-17.0711}},
color={0,0,255},
smooth=Smooth.None));
connect(D1.n,D2. p) annotation (Line(
points={{5.07107,17.0711},{10,18},{14.9289,18},{14.9289,17.0711}},
color={0,0,255},
smooth=Smooth.None));
connect(D1.p,D3. p) annotation (Line(
points={{-9.07107,2.92893},{-10,0},{-9.07107,-2.92893}},
color={0,0,255},
smooth=Smooth.None));
connect(D2.n,D4. n) annotation (Line(
points={{29.0711,2.92893},{30,0},{29.0711,-2.92893}},
color={0,0,255},
smooth=Smooth.None));
connect(transformer.p2,D1. n) annotation (Line(
points={{-40,5},{-40,24},{10,24},{10,17.0711},{5.07107,17.0711}},
color={0,0,255},
smooth=Smooth.None));
connect(D4.p,transformer. n2) annotation (Line(
points={{14.9289,-17.0711},{10,-17.0711},{10,-30},{-40,-30},{-40,-5}},
color={0,0,255},
smooth=Smooth.None));
connect(D1.p, capacitor.n) annotation (Line(
points={{-9.07107,2.92893},{-14,2.92893},{-14,-42},{70,-42},{70,-30}},
color={0,0,255},
smooth=Smooth.None));
connect(transformer.n1, gnd) annotation (Line(
points={{-60,-5},{-60,-60},{-100,-60}},
color={0,0,255},
smooth=Smooth.None));
connect(transformer.n2, gnd) annotation (Line(
points={{-40,-5},{-40,-60},{-100,-60}},
color={0,0,255},
smooth=Smooth.None));
connect(transformer.p1, p) annotation (Line(
points={{-60,5},{-60,60},{-100,60}},
color={0,0,255},
smooth=Smooth.None));
connect(capacitor.p, D2.n) annotation (Line(
points={{70,-10},{70,2.92893},{29.0711,2.92893}},
color={0,0,255},
smooth=Smooth.None));
points={{70,-10},{70,60},{100,60}},
color={0,0,255},
smooth=Smooth.None));
points={{70,-30},{70,-60},{100,-60}},
color={0,0,255},
smooth=Smooth.None));
end BasicPowerSupply;