Some fixes

This commit is contained in:
2026-03-08 23:43:57 +01:00
parent 3bb0a04d4c
commit cc906cbd23
4 changed files with 138 additions and 10 deletions

View File

@@ -11,7 +11,7 @@ package BondGraphLib
parameter Real s[N] = fill(1.0, N) parameter Real s[N] = fill(1.0, N)
"Bond orientation signs used in the effort balance"; "Bond orientation signs used in the effort balance";
BondPort P[N] "Power ports" annotation( BondPort P[N] "Power ports" annotation(
Placement(transformation(origin = {-44, 18}, extent = {{-10, -10}, {10, 10}}), iconTransformation(origin = {0, 80}, extent = {{-10, -10}, {10, 10}}))); Placement(transformation(origin = {-44, 18}, extent = {{-10, -10}, {10, 10}}), iconTransformation(extent = {{-10, -10}, {10, 10}})));
Real f; Real f;
equation equation
// Efforts sum to zero, with signs from bond directions // Efforts sum to zero, with signs from bond directions
@@ -31,7 +31,7 @@ package BondGraphLib
parameter Real s[N] = fill(1.0, N) parameter Real s[N] = fill(1.0, N)
"Bond orientation signs used in the effort balance"; "Bond orientation signs used in the effort balance";
BondPort P[N] "Power ports" annotation( BondPort P[N] "Power ports" annotation(
Placement(transformation(origin = {-44, 18}, extent = {{-10, -10}, {10, 10}}), iconTransformation(origin = {0, 80}, extent = {{-10, -10}, {10, 10}}))); Placement(transformation(origin = {-44, 18}, extent = {{-10, -10}, {10, 10}}), iconTransformation(extent = {{-10, -10}, {10, 10}})));
Real e; Real e;
equation equation
// Flows sum to zero, with signs from bond directions // Flows sum to zero, with signs from bond directions
@@ -48,7 +48,7 @@ package BondGraphLib
partial model OnePortPassive "One-port passive bond graph element" partial model OnePortPassive "One-port passive bond graph element"
BondPort p "Generic power port" annotation( BondPort p "Generic power port" annotation(
Placement(transformation(origin = {-44, 18}, extent = {{-10, -10}, {10, 10}}), iconTransformation(origin = {0, 80}, extent = {{-10, -10}, {10, 10}}))); Placement(transformation(origin = {-44, 18}, extent = {{-10, -10}, {10, 10}}), iconTransformation(extent = {{-10, -10}, {10, 10}})));
end OnePortPassive; end OnePortPassive;
partial model OnePortEnergetic "One-port storage element" partial model OnePortEnergetic "One-port storage element"
@@ -91,7 +91,7 @@ package BondGraphLib
model Se "Effort source" model Se "Effort source"
BondPort p annotation( BondPort p annotation(
Placement(transformation(origin = {-44, 18}, extent = {{-10, -10}, {10, 10}}), iconTransformation(origin = {80, 0}, extent = {{-10, -10}, {10, 10}}))); Placement(transformation(origin = {-44, 18}, extent = {{-10, -10}, {10, 10}}), iconTransformation(origin = {80, 0}, extent = {{-10, -10}, {10, 10}})));
input Real e0 "Imposed effort"; parameter Real e0 "Imposed effort";
equation equation
p.e = e0; p.e = e0;
annotation( annotation(
@@ -101,7 +101,7 @@ package BondGraphLib
model Sf "Flow source" model Sf "Flow source"
BondPort p annotation( BondPort p annotation(
Placement(transformation(origin = {-44, 18}, extent = {{-10, -10}, {10, 10}}), iconTransformation(origin = {80, 0}, extent = {{-10, -10}, {10, 10}}))); Placement(transformation(origin = {-44, 18}, extent = {{-10, -10}, {10, 10}}), iconTransformation(origin = {80, 0}, extent = {{-10, -10}, {10, 10}})));
input Real f0 "Imposed flow"; parameter Real f0 "Imposed flow";
equation equation
p.f = f0; p.f = f0;
annotation( annotation(
@@ -189,6 +189,32 @@ package BondGraphLib
Icon(graphics = {Text(extent = {{-60, 100}, {60, -100}}, textString = "mGY")})); Icon(graphics = {Text(extent = {{-60, 100}, {60, -100}}, textString = "mGY")}));
end 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( 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)}), 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"))); uses(Modelica(version = "4.1.0")));

View File

@@ -11,7 +11,7 @@ package BondGraphLib2D
parameter Real s[N] = fill(1.0, N) parameter Real s[N] = fill(1.0, N)
"Bond orientation signs used in the effort balance"; "Bond orientation signs used in the effort balance";
BondPort P[N] "Power ports" annotation( BondPort P[N] "Power ports" annotation(
Placement(transformation(origin = {-44, 18}, extent = {{-10, -10}, {10, 10}}), iconTransformation(origin = {0, 80}, extent = {{-10, -10}, {10, 10}}))); Placement(transformation(origin = {-44, 18}, extent = {{-10, -10}, {10, 10}}), iconTransformation(extent = {{-10, -10}, {10, 10}})));
Real f[2]; Real f[2];
equation equation
// Efforts sum to zero, with signs from bond directions // Efforts sum to zero, with signs from bond directions
@@ -33,7 +33,7 @@ package BondGraphLib2D
parameter Real s[N] = fill(1.0, N) parameter Real s[N] = fill(1.0, N)
"Bond orientation signs used in the effort balance"; "Bond orientation signs used in the effort balance";
BondPort P[N] "Power ports" annotation( BondPort P[N] "Power ports" annotation(
Placement(transformation(origin = {-44, 18}, extent = {{-10, -10}, {10, 10}}), iconTransformation(origin = {0, 80}, extent = {{-10, -10}, {10, 10}}))); Placement(transformation(origin = {-44, 18}, extent = {{-10, -10}, {10, 10}}), iconTransformation(extent = {{-10, -10}, {10, 10}})));
Real e[2]; Real e[2];
equation equation
// Flows sum to zero, with signs from bond directions // Flows sum to zero, with signs from bond directions
@@ -52,7 +52,7 @@ package BondGraphLib2D
partial model OnePortPassive "One-port passive 2D multibond element" partial model OnePortPassive "One-port passive 2D multibond element"
BondPort p "Generic power port" annotation( BondPort p "Generic power port" annotation(
Placement(transformation(origin = {-44, 18}, extent = {{-10, -10}, {10, 10}}), iconTransformation(origin = {0, 80}, extent = {{-10, -10}, {10, 10}}))); Placement(transformation(origin = {-44, 18}, extent = {{-10, -10}, {10, 10}}), iconTransformation(extent = {{-10, -10}, {10, 10}})));
end OnePortPassive; end OnePortPassive;
partial model OnePortEnergetic "One-port 2D multibond storage element" partial model OnePortEnergetic "One-port 2D multibond storage element"
@@ -193,6 +193,45 @@ package BondGraphLib2D
Icon(graphics = {Text(extent = {{-60, 100}, {60, -100}}, textString = "mGY", textStyle = {TextStyle.Bold, TextStyle.UnderLine}) })); Icon(graphics = {Text(extent = {{-60, 100}, {60, -100}}, textString = "mGY", textStyle = {TextStyle.Bold, TextStyle.UnderLine}) }));
end mGY; end mGY;
package TransRotUtils
model mTFrot2lin
BondGraphLib.BondPort pR annotation(
Placement(transformation(origin = {-44, 18}, extent = {{-10, -10}, {10, 10}}), iconTransformation(origin = {-80, 0}, extent = {{-10, -10}, {10, 10}})));
BondPort pT annotation(
Placement(transformation(origin = {-44, 18}, extent = {{-10, -10}, {10, 10}}), iconTransformation(origin = {80, 0}, extent = {{-10, -10}, {10, 10}})));
parameter Real r_body[2] = {1,0};
protected
Real B[2];
equation
B = {-r_body[2], r_body[1]};
pT.f = B * pR.f;
pR.e = B[1]*pT.e[1] + B[2]*pT.e[2];
annotation(
Icon(graphics = {Text(extent = {{-70, 100}, {70, -100}}, textString = "rlTF", textStyle = {TextStyle.Bold, TextStyle.UnderLine})}));
end mTFrot2lin;
model rTF
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 phi "angle" annotation(
Placement(transformation(origin = {-8, -64}, extent = {{-20, -20}, {20, 20}}), iconTransformation(origin = {0, -78}, extent = {{-8, -8}, {8, 8}}, rotation = 90)));
protected
Real R[2,2];
equation
R = [cos(phi), -sin(phi);
sin(phi), cos(phi)];
p1.e = R * p2.e;
transpose(R) * p1.f = p2.f;
annotation(
Diagram(graphics),
Icon(graphics = {Text(extent = {{-60, 100}, {60, -100}}, textString = "rTF", textStyle = {TextStyle.Bold, TextStyle.UnderLine}) }));
end rTF;
end TransRotUtils;
annotation( annotation(
Icon(graphics = {Text(origin = {50, 0}, extent = {{-50, 100}, {50, -100}}, textString = "R", textStyle = {TextStyle.Bold}), 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), Line(origin = {-78, 16}, points = {{-26, 0}, {30, 0}}, thickness = 5)}), Icon(graphics = {Text(origin = {50, 0}, extent = {{-50, 100}, {50, -100}}, textString = "R", textStyle = {TextStyle.Bold}), 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), Line(origin = {-78, 16}, points = {{-26, 0}, {30, 0}}, thickness = 5)}),
uses(Modelica(version = "4.1.0")), uses(Modelica(version = "4.1.0")),

0
formatter.py Normal file → Executable file
View File

63
test2d.mo Normal file
View File

@@ -0,0 +1,63 @@
model test2d
BondGraphLib.J1 w_com(N = 3, s = {1, -1, -1}) annotation(
Placement(transformation(origin = {0, 120}, extent = {{-10, -10}, {10, 10}})));
BondGraphLib.Sf sf(f0 = 1) annotation(
Placement(transformation(origin = {50, 120}, extent = {{-10, -10}, {10, 10}}, rotation = 180)));
BondGraphLib2D.TransRotUtils.mTFrot2lin mTFrot2lin(r_body = {0.1, 0}) annotation(
Placement(transformation(origin = {0, 80}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
BondGraphLib2D.J0 j0(N = 3, s = {1, 1, -1}) annotation(
Placement(transformation(origin = {0, 40}, extent = {{-10, -10}, {10, 10}})));
BondGraphLib2D.J1 v_p_bff(N = 2, s = {1, -1}) annotation(
Placement(transformation(origin = {-40, 40}, extent = {{-10, -10}, {10, 10}})));
BondGraphLib2D.J1 v_com_bff(N = 2, s = {-1, -1}) annotation(
Placement(transformation(origin = {40, 40}, extent = {{-10, -10}, {10, 10}})));
BondGraphLib2D.TransRotUtils.rTF rTF annotation(
Placement(transformation(origin = {40, 0}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
BondGraphLib2D.TransRotUtils.rTF rTF1 annotation(
Placement(transformation(origin = {-40, 0}, extent = {{10, -10}, {-10, 10}}, rotation = 90)));
BondGraphLib.fsensor wsensor annotation(
Placement(transformation(origin = {50, 90}, extent = {{-10, -10}, {10, 10}})));
Modelica.Blocks.Continuous.Integrator w2phi annotation(
Placement(transformation(origin = {90, 90}, extent = {{-10, -10}, {10, 10}})));
BondGraphLib2D.J1 v_y_in(N = 1, s = {1}) annotation(
Placement(transformation(origin = {-40, -40}, extent = {{-10, -10}, {10, 10}})));
BondGraphLib2D.J1 v_com_in(N = 2, s = {1, -1}) annotation(
Placement(transformation(origin = {40, -40}, extent = {{-10, -10}, {10, 10}})));
BondGraphLib2D.I mass annotation(
Placement(transformation(origin = {80, -40}, extent = {{-10, -10}, {10, 10}})));
equation
connect(sf.p, w_com.P[1]) annotation(
Line(points = {{42, 120}, {0, 120}}, color = {0, 0, 127}, thickness = 0.75, arrow = {Arrow.None, Arrow.Half}, arrowSize = 6));
connect(w_com.P[2], mTFrot2lin.pR) annotation(
Line(points = {{0, 120}, {0, 88}}, color = {0, 0, 127}, thickness = 0.75, arrow = {Arrow.None, Arrow.Half}, arrowSize = 6));
connect(mTFrot2lin.pT, j0.P[1]) annotation(
Line(points = {{0, 72}, {0, 40}}, color = {0, 85, 0}, thickness = 0.75, arrow = {Arrow.None, Arrow.Half}, arrowSize = 6));
connect(v_com_bff.P[1], j0.P[2]) annotation(
Line(points = {{40, 40}, {0, 40}}, color = {0, 85, 0}, thickness = 0.75, arrow = {Arrow.None, Arrow.Half}, arrowSize = 6));
connect(j0.P[3], v_p_bff.P[1]) annotation(
Line(origin = {-1, 0},points = {{0, 40}, {-40, 40}}, color = {0, 85, 0}, thickness = 0.75, arrow = {Arrow.None, Arrow.Half}, arrowSize = 6));
connect(v_com_bff.P[2], rTF.p1) annotation(
Line(points = {{40, 40}, {40, 8}}, color = {0, 85, 0}, thickness = 0.75, arrow = {Arrow.None, Arrow.Half}, arrowSize = 6));
connect(v_p_bff.P[2], rTF1.p1) annotation(
Line(points = {{-40, 40}, {-40, 8}}, color = {0, 85, 0}, thickness = 0.75, arrow = {Arrow.None, Arrow.Half}, arrowSize = 6));
connect(w_com.P[3], wsensor.p) annotation(
Line(points = {{0, 120}, {42, 90}}, color = {0, 0, 127}, thickness = 0.75, arrow = {Arrow.None, Arrow.Half}, arrowSize = 6));
connect(wsensor.f, w2phi.u) annotation(
Line(points = {{58, 90}, {78, 90}}, color = {0, 0, 127}));
connect(w2phi.y, rTF1.phi) annotation(
Line(points = {{102, 90}, {110, 90}, {110, 20}, {0, 20}, {0, 0}, {-32, 0}}, color = {0, 0, 127}, arrow = {Arrow.None, Arrow.Filled}));
connect(w2phi.y, rTF.phi) annotation(
Line(points = {{102, 90}, {110, 90}, {110, 20}, {0, 20}, {0, 0}, {32, 0}}, color = {0, 0, 127}, arrow = {Arrow.None, Arrow.Filled}));
connect(rTF1.p2, v_y_in.P[1]) annotation(
Line(points = {{-40, -8}, {-40, -40}}, color = {0, 85, 0}, thickness = 0.75, arrow = {Arrow.None, Arrow.Half}, arrowSize = 6));
connect(rTF.p2, v_com_in.P[1]) annotation(
Line(origin = {1, 0},points = {{40, -8}, {40, -40}}, color = {0, 85, 0}, thickness = 0.75, arrow = {Arrow.None, Arrow.Half}, arrowSize = 6));
connect(v_com_in.P[2], mass.p) annotation(
Line(points = {{40, -40}, {80, -40}}, color = {0, 85, 0}, thickness = 0.75, arrow = {Arrow.None, Arrow.Half}, arrowSize = 6));
annotation(
uses(Modelica(version = "4.1.0")),
experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-06, Interval = 0.02),
Diagram(coordinateSystem(extent = {{-60, 140}, {120, -60}}), graphics = {Text(origin = {-40, -52}, extent = {{-12, 4}, {12, -4}}, textString = "v_p"), Text(origin = {40, -52}, extent = {{-12, 4}, {12, -4}}, textString = "v_com"), Text(origin = {0, 134}, extent = {{-12, 4}, {12, -4}}, textString = "w_com")}),
Icon(coordinateSystem(extent = {{-200, -200}, {200, 200}})),
version = "");
end test2d;