电路搭建解析
在模型实例部分,电路由以下元件组成:
交流电源(VsourceAC)
电阻R1和R2(10Ω)
电感L(0.1H)
电容C(0.01F)
接地Ground
connect(R1.p, AC.p):R1的一端连接交流电源正端,提供电流路径。
connect(R1.n, C.p):R1另一端连接电容C的正端。
connect(R2.p, R1.p):R2的正端与R1并联。
connect(R2.n, L.p):R2负端连接电感L正端,形成分支。
connect(C.n, AC.n):电容负端连接到电源负端,完成回路。
connect(L.n, C.n):电感负端连接到电容负端,形成串联分支。
connect(ground.p, AC.n):电源负端接地。
模型代码
model RCL
connector Pin
Real V;
flow Real I;
annotation (Diagram(graphics={ Rectangle(
extent = {{-40, 40}, {40, -40}},
lineColor = {0, 0, 255},
fillColor = {0, 0, 255},
fillPattern = FillPattern.Solid)}), Icon(graphics={
Rectangle(
extent = {{-100, 100}, {100, -100}},
lineColor = {0, 0, 255},
fillColor = {0, 0, 255},
fillPattern = FillPattern.Solid)}));
end Pin;
partial model TwoPin
Real v;
Real i;
Pin p annotation (Placement(transformation(extent = {{-100, 0}, {-80, 20}}),
iconTransformation(extent = {{-100, 0}, {-80, 20}})));
Pin n annotation (Placement(transformation(extent = {{80, 0}, {100, 20}}),
iconTransformation(extent = {{80, 0}, {100, 20}})));
equation
v = p.V - n.V;
0 = p.I + n.I;
i = p.I;
end TwoPin;
model Resistor1 = Resistor(R=10);
model Resistor
"Ideal electrical resistor"
extends TwoPin;
parameter Real R(unit = "Ohm")
"Resistance";
equation
R * i = v;
annotation (Icon(graphics={
Rectangle(
extent = {{-70, 40}, {70, -20}},
lineColor = {0, 0, 255},
fillColor = {255, 255, 255},
fillPattern = FillPattern.Solid),
Line(points = {{-80, 10}, {-70, 10}}, color = {28, 108, 200}),
Line(points = {{70, 10}, {80, 10}}, color = {28, 108, 200}),
Text(
extent = {{-144, 92}, {156, 52}},
textString = "%name",
textColor = {0, 0, 255})}));
end Resistor;
model Capacitor
extends TwoPin;
parameter Real C(unit = "F")
"Capacitance";
equation
C * der(v) = i;
annotation (Icon(graphics={
Line(
points = {{-20, 60}, {-20, -40}},
color = {28, 108, 200},
thickness = 1),
Line(
points = {{20, 60}, {20, -40}},
color = {28, 108, 200},
thickness = 1),
Line(
points = {{-80, 12}, {-20, 12}},
color = {28, 108, 200},
thickness = 1),
Line(
points = {{20, 12}, {80, 12}},
color = {28, 108, 200},
thickness = 1),
Text(
extent = {{-144, 104}, {156, 64}},
textString = "%name",
textColor = {0, 0, 255})}));
end Capacitor;
model Inductor
extends TwoPin;
parameter Real L(unit = "H")
"Inductance";
equation
v = L * der(i);
annotation (Icon(graphics={
Line(points = {{60, 10}, {80, 10}},
color = {0, 0, 255}),
Line(points = {{-80, 10}, {-60, 10}},
color = {0, 0, 255}),
Line(
points = {{-60, 10}, {-59, 16}, {-52, 24}, {-38, 24}, {-31, 16}, {-30, 10}},
color = {0, 0, 255},
smooth = Smooth.Bezier),
Line(
points = {{-30, 10}, {-29, 16}, {-22, 24}, {-8, 24}, {-1, 16}, {0, 10}},
color = {0, 0, 255},
smooth = Smooth.Bezier),
Line(
points = {{0, 10}, {1, 16}, {8, 24}, {22, 24}, {29, 16}, {30, 10}},
color = {0, 0, 255},
smooth = Smooth.Bezier),
Line(
points = {{30, 10}, {31, 16}, {38, 24}, {52, 24}, {59, 16}, {60, 10}},
color = {0, 0, 255},
smooth = Smooth.Bezier),
Text(
extent = {{-146, 84}, {154, 44}},
textString = "%name",
textColor = {0, 0, 255})}));
end Inductor;
model VsourceAC
"Sin-wave voltage source"
extends TwoPin;
parameter Real VA = 220
"Amplitude";
parameter Real f(unit = "Hz") = 50
"Frequency";
constant Real PI = 3.141592653589793;
equation
v = VA * sin(2 * PI * f * time);
annotation (Icon(graphics={
Ellipse(
extent = {{-50, 60}, {50, -40}},
lineColor = {0, 0, 255},
fillColor = {255, 255, 255},
fillPattern = FillPattern.Solid),
Text(
extent = {{-150, 70}, {150, 110}},
textString = "%name",
textColor = {0, 0, 255}),
Line(points = {{-80, 10}, {80, 10}},
color = {0, 0, 255}),
Line(points = {{-80, 30}, {-60, 30}}, color = {0, 0, 255}),
Line(points = {{-70, 40}, {-70, 20}}, color = {0, 0, 255}),
Line(points = {{60, 30}, {80, 30}}, color = {0, 0, 255}),
Line(points = {{-70, -60}, {0, -60}, {0, 80}, {69, 80}},
color = {192, 192, 192})}));
end VsourceAC;
model Ground
"Ground"
Pin p annotation (Placement(transformation(extent = {{-10, 40}, {10, 60}}),
iconTransformation(extent = {{-10, 40}, {10, 60}})));
equation
p.V = 0;
annotation (Icon(graphics={
Line(points = {{-60, 0}, {60, 0}}, color = {0, 0, 255}),
Line(points = {{-40, -20}, {40, -20}},
color = {0, 0, 255}),
Line(points = {{-20, -40}, {20, -40}},
color = {0, 0, 255}),
Line(points = {{0, 40}, {0, 0}}, color = {0, 0, 255}),
Text(
extent = {{-150, -60}, {150, -100}},
textString = "%name",
textColor = {0, 0, 255})}));
end Ground;