222 lines
11 KiB
Plaintext
222 lines
11 KiB
Plaintext
package BondGraphLib
|
|
|
|
connector BondPort "Bond graph power port"
|
|
Real e "Effort variable";
|
|
flow Real f "Flow variable";annotation(
|
|
Icon(graphics = {Rectangle(lineColor = {0, 0, 127}, fillColor = {0, 0, 127},fillPattern = FillPattern.Solid, extent = {{-60, 60}, {60, -60}})}));
|
|
end BondPort;
|
|
|
|
model J1 "Bond graph 1-junction (common flow, efforts sum to zero)"
|
|
parameter Integer N(min=1) = 2 "# of power ports";
|
|
parameter Real s[N] = fill(1.0, N)
|
|
"Bond orientation signs used in the effort balance";
|
|
BondPort P[N] "Power ports" annotation(
|
|
Placement(transformation(origin = {-44, 18}, extent = {{-10, -10}, {10, 10}}), iconTransformation(extent = {{-10, -10}, {10, 10}})));
|
|
Real f;
|
|
equation
|
|
// Efforts sum to zero, with signs from bond directions
|
|
sum(s[i] * P[i].e for i in 1:N) = 0;
|
|
|
|
// Flows are all equal
|
|
for i in 2:N loop
|
|
P[i].f = P[i-1].f;
|
|
end for;
|
|
f = P[1].f;
|
|
annotation(
|
|
Icon(graphics = {Text(extent = {{-100, 100}, {100, -100}}, textString = "1")}));
|
|
end J1;
|
|
|
|
model J0 "Bond graph 0-junction (common effort, flows sum to zero)"
|
|
parameter Integer N(min=1) = 2 "# of power ports";
|
|
parameter Real s[N] = fill(1.0, N)
|
|
"Bond orientation signs used in the effort balance";
|
|
BondPort P[N] "Power ports" annotation(
|
|
Placement(transformation(origin = {-44, 18}, extent = {{-10, -10}, {10, 10}}), iconTransformation(extent = {{-10, -10}, {10, 10}})));
|
|
Real e;
|
|
equation
|
|
// Flows sum to zero, with signs from bond directions
|
|
sum(s[i] * P[i].f for i in 1:N) = 0;
|
|
|
|
// Efforts are all equal
|
|
for i in 2:N loop
|
|
P[i].e = P[1].e;
|
|
end for;
|
|
e = P[1].e;
|
|
annotation(
|
|
Icon(graphics = {Text(extent = {{-100, 100}, {100, -100}}, textString = "0")}));
|
|
end J0;
|
|
|
|
partial model OnePortPassive "One-port passive bond graph element"
|
|
BondPort p "Generic power port" annotation(
|
|
Placement(transformation(origin = {-44, 18}, extent = {{-10, -10}, {10, 10}}), iconTransformation(extent = {{-10, -10}, {10, 10}})));
|
|
end OnePortPassive;
|
|
|
|
partial model OnePortEnergetic "One-port storage element"
|
|
extends OnePortPassive annotation(
|
|
Placement(transformation(origin = {-44, 18}, extent = {{-10, -10}, {10, 10}}), iconTransformation(origin = {0, 80}, extent = {{-10, -10}, {10, 10}})));
|
|
Real state "Conserved quantity";
|
|
end OnePortEnergetic;
|
|
|
|
model C "Bond graph C element"
|
|
extends OnePortEnergetic(state(start=q0, fixed=true));
|
|
parameter Real c(min=0) = 1 "Capacitance";
|
|
parameter Real q0 = 0 "Initial stored quantity (charge)";
|
|
equation
|
|
der(state) = p.f;
|
|
p.e = state / c;
|
|
annotation(
|
|
Icon(graphics = {Text(extent = {{-100, 100}, {100, -100}}, textString = "C")}));
|
|
end C;
|
|
|
|
model I "Bond graph I element"
|
|
extends OnePortEnergetic(state(start=p0, fixed=true));
|
|
parameter Real I(min=0) = 1 "Inertance / inductance / mass";
|
|
parameter Real p0 = 0 "Initial stored quantity (momentum / flux)";
|
|
equation
|
|
der(state) = p.e;
|
|
p.f = state / I;
|
|
annotation(
|
|
Icon(graphics = {Text(extent = {{-100, 100}, {100, -100}}, textString = "I")}));
|
|
end I;
|
|
|
|
model R "Bond graph resistor"
|
|
extends OnePortPassive;
|
|
parameter Real R(min=0) = 1 "Resistance";
|
|
equation
|
|
p.e = R * p.f;
|
|
annotation(
|
|
Icon(graphics = {Text(extent = {{-100, 100}, {100, -100}}, textString = "R")}));
|
|
end R;
|
|
|
|
model Se "Effort source"
|
|
BondPort p annotation(
|
|
Placement(transformation(origin = {-44, 18}, extent = {{-10, -10}, {10, 10}}), iconTransformation(origin = {80, 0}, extent = {{-10, -10}, {10, 10}})));
|
|
parameter Real e0 "Imposed effort";
|
|
equation
|
|
p.e = e0;
|
|
annotation(
|
|
Icon(graphics = {Text(origin = {-20, 0}, extent = {{-80, 100}, {80, -100}}, textString = "Se")}));
|
|
end Se;
|
|
|
|
model Sf "Flow source"
|
|
BondPort p annotation(
|
|
Placement(transformation(origin = {-44, 18}, extent = {{-10, -10}, {10, 10}}), iconTransformation(origin = {80, 0}, extent = {{-10, -10}, {10, 10}})));
|
|
parameter Real f0 "Imposed flow";
|
|
equation
|
|
p.f = f0;
|
|
annotation(
|
|
Icon(graphics = {Text(origin = {-20, 0}, extent = {{-80, 100}, {80, -100}}, textString = "Sf")}));
|
|
end Sf;
|
|
|
|
model TF "Bond graph transformer"
|
|
BondPort p1 "Port 1" annotation(
|
|
Placement(transformation(origin = {-44, 18}, extent = {{-10, -10}, {10, 10}}), iconTransformation(origin = {-80, 0}, extent = {{-10, -10}, {10, 10}})));
|
|
BondPort p2 "Port 2" annotation(
|
|
Placement(transformation(origin = {-44, 18}, extent = {{-10, -10}, {10, 10}}), iconTransformation(origin = {80, 0}, extent = {{-10, -10}, {10, 10}})));
|
|
|
|
parameter Real n = 1 "Transformer ratio";
|
|
equation
|
|
p1.e = n * p2.e;
|
|
p2.f = n * p1.f;
|
|
annotation(
|
|
Icon(graphics = {Text(extent = {{-80, 100}, {80, -100}}, textString = "TF")}));
|
|
end TF;
|
|
|
|
model GY "Bond graph gyrator"
|
|
BondPort p1 "Port 1" annotation(
|
|
Placement(transformation(origin = {-44, 18}, extent = {{-10, -10}, {10, 10}}), iconTransformation(origin = {-80, 0}, extent = {{-10, -10}, {10, 10}})));
|
|
BondPort p2 "Port 2" annotation(
|
|
Placement(transformation(origin = {-44, 18}, extent = {{-10, -10}, {10, 10}}), iconTransformation(origin = {80, 0}, extent = {{-10, -10}, {10, 10}})));
|
|
parameter Real r = 1 "Gyrator modulus";
|
|
equation
|
|
p1.e = r * p2.f;
|
|
p2.e = r * p1.f;
|
|
annotation(
|
|
Icon(graphics = {Text(extent = {{-80, 100}, {80, -100}}, textString = "GY")}));
|
|
end GY;
|
|
|
|
model mSe "Bond graph modulated effort source"
|
|
BondPort p annotation(
|
|
Placement(transformation(origin = {-44, 18}, extent = {{-10, -10}, {10, 10}}), iconTransformation(origin = {80, 0}, extent = {{-10, -10}, {10, 10}})));
|
|
Modelica.Blocks.Interfaces.RealInput e0 "Imposed effort" annotation(
|
|
Placement(transformation(origin = {-8, -64}, extent = {{-20, -20}, {20, 20}}), iconTransformation(origin = {0, -78}, extent = {{-8, -8}, {8, 8}}, rotation = 90)));
|
|
|
|
equation
|
|
p.e = e0;
|
|
annotation(
|
|
Icon(graphics = {Text(origin = {-20, 0}, extent = {{-80, 100}, {80, -100}}, textString = "mSe")}));
|
|
end mSe;
|
|
|
|
model mSf "Bond graph modulated flow source"
|
|
BondPort p annotation(
|
|
Placement(transformation(origin = {-44, 18}, extent = {{-10, -10}, {10, 10}}), iconTransformation(origin = {80, 0}, extent = {{-10, -10}, {10, 10}})));
|
|
Modelica.Blocks.Interfaces.RealInput f0 "Imposed flow" annotation(
|
|
Placement(transformation(origin = {-8, -64}, extent = {{-20, -20}, {20, 20}}), iconTransformation(origin = {0, -78}, extent = {{-8, -8}, {8, 8}}, rotation = 90)));
|
|
|
|
equation
|
|
p.f = f0;
|
|
annotation(
|
|
Icon(graphics = {Text(origin = {-20, 0}, extent = {{-80, 100}, {80, -100}}, textString = "mSf")}));
|
|
end mSf;
|
|
|
|
model mTF "Bond graph modulated transformer"
|
|
BondPort p1 "Port 1" annotation(
|
|
Placement(transformation(origin = {-44, 18}, extent = {{-10, -10}, {10, 10}}), iconTransformation(origin = {-80, 0}, extent = {{-10, -10}, {10, 10}})));
|
|
BondPort p2 "Port 2" annotation(
|
|
Placement(transformation(origin = {-44, 18}, extent = {{-10, -10}, {10, 10}}), iconTransformation(origin = {80, 0}, extent = {{-10, -10}, {10, 10}})));
|
|
Modelica.Blocks.Interfaces.RealInput m "Modulation" annotation(
|
|
Placement(transformation(origin = {-8, -64}, extent = {{-20, -20}, {20, 20}}), iconTransformation(origin = {0, -78}, extent = {{-8, -8}, {8, 8}}, rotation = 90)));
|
|
equation
|
|
p1.e = m * p2.e;
|
|
p2.f = m * p1.f;
|
|
annotation(
|
|
Diagram(graphics),
|
|
Icon(graphics = {Text(extent = {{-60, 100}, {60, -100}}, textString = "mTF")}));
|
|
end mTF;
|
|
|
|
model mGY "Bond graph modulated gyrator"
|
|
BondPort p1 "Port 1" annotation(
|
|
Placement(transformation(origin = {-44, 18}, extent = {{-10, -10}, {10, 10}}), iconTransformation(origin = {-80, 0}, extent = {{-10, -10}, {10, 10}})));
|
|
BondPort p2 "Port 2" annotation(
|
|
Placement(transformation(origin = {-44, 18}, extent = {{-10, -10}, {10, 10}}), iconTransformation(origin = {80, 0}, extent = {{-10, -10}, {10, 10}})));
|
|
Modelica.Blocks.Interfaces.RealInput m "Modulation" annotation(
|
|
Placement(transformation(origin = {-8, -64}, extent = {{-20, -20}, {20, 20}}), iconTransformation(origin = {0, -78}, extent = {{-8, -8}, {8, 8}}, rotation = 90)));
|
|
equation
|
|
p1.e = m * p2.f;
|
|
p2.e = m * p1.f;
|
|
annotation(
|
|
Diagram(graphics),
|
|
Icon(graphics = {Text(extent = {{-60, 100}, {60, -100}}, textString = "mGY")}));
|
|
end mGY;
|
|
|
|
model fsensor
|
|
BondPort p annotation(
|
|
Placement(transformation(origin = {-44, 18}, extent = {{-10, -10}, {10, 10}}), iconTransformation(origin = {-80, 0}, extent = {{-10, -10}, {10, 10}})));
|
|
Modelica.Blocks.Interfaces.RealOutput f "Flow output" annotation(
|
|
Placement(transformation(origin = {-8, -64}, extent = {{-20, -20}, {20, 20}}), iconTransformation(origin = {82, 0}, extent = {{-8, -8}, {8, 8}})));
|
|
equation
|
|
// Ideal flow sensor in bond-graph form: zero effort loading.
|
|
p.e = 0;
|
|
f = p.f;
|
|
annotation(
|
|
Icon(graphics = {Text(extent = {{-80, 100}, {80, -100}}, textString = "f", textStyle = {TextStyle.Italic})}));
|
|
end fsensor;
|
|
|
|
model esensor
|
|
BondPort p annotation(
|
|
Placement(transformation(origin = {-44, 18}, extent = {{-10, -10}, {10, 10}}), iconTransformation(origin = {-80, 0}, extent = {{-10, -10}, {10, 10}})));
|
|
Modelica.Blocks.Interfaces.RealOutput e "Effort output" annotation(
|
|
Placement(transformation(origin = {-8, -64}, extent = {{-20, -20}, {20, 20}}), iconTransformation(origin = {82, 0}, extent = {{-8, -8}, {8, 8}})));
|
|
equation
|
|
// Ideal effort sensor in bond-graph form: zero flow loading.
|
|
p.f = 0;
|
|
e = p.e;
|
|
annotation(
|
|
Icon(graphics = {Text(extent = {{-80, 100}, {80, -100}}, textString = "e", textStyle = {TextStyle.Italic})}));
|
|
end esensor;
|
|
|
|
annotation(
|
|
Icon(graphics = {Text(origin = {50, 0}, extent = {{-50, 100}, {50, -100}}, textString = "R"), Line(origin = {-45.22, 20.19}, points = {{-58.7774, -20.1934}, {21.2226, -20.1934}, {-38.7774, 19.8066}}, thickness = 5), Line(origin = {-9.81, -8.19}, points = {{-10.1934, 48.1934}, {-10.1934, -31.8066}}, thickness = 5)}),
|
|
uses(Modelica(version = "4.1.0")));
|
|
end BondGraphLib;
|