Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve inheritance of classes in MultiBody #4091

Draft
wants to merge 19 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
within Modelica.Mechanics.MultiBody.Forces.Internal;
model ZeroForceAndTorque "Set force and torque to zero"
extends Modelica.Blocks.Icons.Block;
Interfaces.Frame_a frame_a
annotation (Placement(transformation(extent={{-116,-16},{-84,16}})));
extends Modelica.Blocks.Icons.Block;
extends Interfaces.PartialOneFrame_a;
equation
frame_a.f = zeros(3);
frame_a.t = zeros(3);
Expand Down
18 changes: 18 additions & 0 deletions Modelica/Mechanics/MultiBody/Interfaces/OneFrame_a.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
within Modelica.Mechanics.MultiBody.Interfaces;
partial model OneFrame_a
"Base model for components providing one frame_a connector and outer world"

Interfaces.Frame_a frame_a
"Coordinate system fixed to the component with one cut-force and cut-torque"
annotation (Placement(transformation(extent={{-116,-16},{-84,16}})));
protected
outer Modelica.Mechanics.MultiBody.World world;

annotation (Documentation(info="<html>
<p>
This partial model provides one frame_a connector and access to
the world object.
Therefore, inherit from this partial model if both is needed.
</p>
</html>"));
end OneFrame_a;
73 changes: 73 additions & 0 deletions Modelica/Mechanics/MultiBody/Interfaces/PartialConstraint.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
within Modelica.Mechanics.MultiBody.Interfaces;
partial model PartialConstraint
"Base model for elementary constraints"
extends PartialTwoFrames;

parameter Boolean x_locked=true
"= true, if constraint force in x-direction, resolved in frame_a"
annotation (Dialog(group="Constrain translational motion"), choices(checkBox=true));
parameter Boolean y_locked=true
"= true, if constraint force in y-direction, resolved in frame_a"
annotation (Dialog(group="Constrain translational motion"), choices(checkBox=true));
parameter Boolean z_locked=true
"= true, if constraint force in z-direction, resolved in frame_a"
annotation (Dialog(group="Constrain translational motion"), choices(checkBox=true));

protected
SI.Position r_rel_a[3]
"Position vector from origin of frame_a to origin of frame_b, resolved in frame_a";
Frames.Orientation R_rel
"Relative orientation object from frame_a to frame_b";
SI.InstantaneousPower P "Instantaneous power";

equation
// Determine relative position and orientation
r_rel_a = Frames.resolve2(frame_a.R, frame_b.r_0 - frame_a.r_0);
R_rel = Frames.relativeRotation(frame_a.R, frame_b.R);

// Constraint equations concerning translations
if x_locked then
r_rel_a[1]=0;
else
frame_a.f[1]=0;
end if;

if y_locked then
r_rel_a[2]=0;
else
frame_a.f[2]=0;
end if;

if z_locked then
r_rel_a[3]=0;
else
frame_a.f[3]=0;
end if;

// Force and torque balance
zeros(3) = frame_a.f + Frames.resolve1(R_rel, frame_b.f);
zeros(3) = frame_a.t + Frames.resolve1(R_rel, frame_b.t) - cross(r_rel_a, frame_a.f);
// - cross(r_rel_a, frame_a.f) gives the same result like cross(r_rel_a, Frames.resolve1(R_rel, frame_b.f))

// Instantaneous power
P = frame_a.t * Frames.angularVelocity2(frame_a.R) +
frame_b.t * Frames.angularVelocity2(frame_b.R) +
frame_a.f * Frames.resolve2(frame_a.R, der(frame_a.r_0)) +
frame_b.f * Frames.resolve2(frame_b.R, der(frame_b.r_0));

annotation (Documentation(info="<html>
<p>
All <strong>elementary joints defined by constraints</strong> should inherit
from this base model, i.e., joints that are directly defined by constraint
equations between the two frames.
</p>
<p>
This partial model provides relative kinematic quantities <code>r_rel_a</code>
and <code>R_rel</code> between the two frame connectors <code>frame_a</code>
and <code>frame_b</code>, and basic equations constraining translational movement.
The inheriting class shall additionally provide corresponding equations
constraining rotational movement.
</p>
</html>
"));
end PartialConstraint;
14 changes: 4 additions & 10 deletions Modelica/Mechanics/MultiBody/Interfaces/PartialElementaryJoint.mo
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
within Modelica.Mechanics.MultiBody.Interfaces;
partial model PartialElementaryJoint
"Base model for elementary joints (has two frames + outer world + assert to guarantee that the joint is connected)"
extends PartialTwoFrames;

Interfaces.Frame_a frame_a "Coordinate system fixed to the joint with one cut-force and cut-torque" annotation (Placement(transformation(extent={{-116,-16},{-84,16}})));
Interfaces.Frame_b frame_b "Coordinate system fixed to the joint with one cut-force and cut-torque" annotation (Placement(transformation(extent={{84,-16},{116,16}})));

protected
outer Modelica.Mechanics.MultiBody.World world;
equation
Connections.branch(frame_a.R, frame_b.R);
assert(cardinality(frame_a) > 0,
"Connector frame_a of joint object is not connected");
assert(cardinality(frame_b) > 0,
"Connector frame_b of joint object is not connected");

annotation (Documentation(info="<html>
<p>
All <strong>elementary joints</strong> should inherit from this base model, i.e.,
Expand All @@ -30,5 +23,6 @@ This partial model provides two frame connectors, a \"Connections.branch\"
between frame_a and frame_b, access to the world
object and an assert to check that both frame connectors are connected.
</p>
</html>"));
</html>
"));
end PartialElementaryJoint;
4 changes: 1 addition & 3 deletions Modelica/Mechanics/MultiBody/Interfaces/PartialOneFrame_a.mo
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
within Modelica.Mechanics.MultiBody.Interfaces;
partial model PartialOneFrame_a
"Base model for components providing one frame_a connector + outer world + assert to guarantee that the component is connected"
extends OneFrame_a;

Interfaces.Frame_a frame_a "Coordinate system fixed to the component with one cut-force and cut-torque" annotation (Placement(transformation(extent={{-116,-16},{-84,16}})));
protected
outer Modelica.Mechanics.MultiBody.World world;
equation
assert(cardinality(frame_a) > 0,
"Connector frame_a of component is not connected");
Expand Down
5 changes: 1 addition & 4 deletions Modelica/Mechanics/MultiBody/Interfaces/PartialTwoFrames.mo
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
within Modelica.Mechanics.MultiBody.Interfaces;
partial model PartialTwoFrames
"Base model for components providing two frame connectors + outer world + assert to guarantee that the component is connected"
extends TwoFrames;

Interfaces.Frame_a frame_a "Coordinate system a fixed to the component with one cut-force and cut-torque" annotation (Placement(transformation(extent={{-116,-16},{-84,16}})));
Interfaces.Frame_b frame_b "Coordinate system b fixed to the component with one cut-force and cut-torque" annotation (Placement(transformation(extent={{84,-16},{116,16}})));
protected
outer Modelica.Mechanics.MultiBody.World world;
equation
assert(cardinality(frame_a) > 0,
"Connector frame_a of component is not connected");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ within Modelica.Mechanics.MultiBody.Interfaces;
partial model PartialTwoFramesDoubleSize
"Base model for components providing two frame connectors + outer world + assert to guarantee that the component is connected (default icon size is factor 2 larger as usual)"

Interfaces.Frame_a frame_a "Coordinate system fixed to the component with one cut-force and cut-torque" annotation (Placement(transformation(extent={{-108,-8},{-92,8}})));
Interfaces.Frame_b frame_b "Coordinate system fixed to the component with one cut-force and cut-torque" annotation (Placement(transformation(extent={{92,-8},{108,8}})));
Interfaces.Frame_a frame_a "Coordinate system a fixed to the component with one cut-force and cut-torque" annotation (Placement(transformation(extent={{-108,-8},{-92,8}})));
TManikantan marked this conversation as resolved.
Show resolved Hide resolved
Interfaces.Frame_b frame_b "Coordinate system b fixed to the component with one cut-force and cut-torque" annotation (Placement(transformation(extent={{92,-8},{108,8}})));

protected
outer Modelica.Mechanics.MultiBody.World world;
Expand Down
8 changes: 2 additions & 6 deletions Modelica/Mechanics/MultiBody/Interfaces/PartialVisualizer.mo
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
within Modelica.Mechanics.MultiBody.Interfaces;
partial model PartialVisualizer
"Base model for visualizers (has a frame_a on the left side + outer world + assert to guarantee that the component is connected)"
extends PartialOneFrame_a(
frame_a "Coordinate system in which visualization data is resolved");

Interfaces.Frame_a frame_a "Coordinate system in which visualization data is resolved" annotation (Placement(transformation(extent={{-116,-16},{-84,16}})));
protected
outer Modelica.Mechanics.MultiBody.World world;
equation
assert(cardinality(frame_a) > 0,
"Connector frame_a of visualizer object is not connected");
annotation (Documentation(info="<html>
<p>
This partial model provides one frame_a connector, access to the world
Expand Down
36 changes: 36 additions & 0 deletions Modelica/Mechanics/MultiBody/Interfaces/TwoFrames.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
within Modelica.Mechanics.MultiBody.Interfaces;
partial model TwoFrames
"Base model for components providing two frame connectors and outer world"

Interfaces.Frame_a frame_a
"Coordinate system a fixed to the component with one cut-force and cut-torque"
annotation (Placement(transformation(extent={{-116,-16},{-84,16}})));
Interfaces.Frame_b frame_b
"Coordinate system b fixed to the component with one cut-force and cut-torque"
annotation (Placement(transformation(extent={{84,-16},{116,16}})));
protected
outer Modelica.Mechanics.MultiBody.World world;

annotation (
Icon(
coordinateSystem(
preserveAspectRatio=true,
extent={{-100,-100},{100,100}}),
graphics={
Text(
extent={{-136,-25},{-100,-50}},
textColor={128,128,128},
textString="a"),
Text(
extent={{100,-25},{136,-50}},
textColor={128,128,128},
textString="b")}),
Documentation(info="<html>
<p>
This partial model provides two frame connectors and access to
the world object.
Therefore, inherit from this partial model if the two frame
connectors are needed.
</p>
</html>"));
end TwoFrames;
7 changes: 5 additions & 2 deletions Modelica/Mechanics/MultiBody/Interfaces/package.order
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ Frame_b
Frame_resolve
FlangeWithBearing
FlangeWithBearingAdaptor
PartialTwoFrames
PartialTwoFramesDoubleSize
OneFrame_a
PartialOneFrame_a
PartialOneFrame_b
TwoFrames
PartialTwoFrames
PartialTwoFramesDoubleSize
PartialConstraint
PartialElementaryJoint
PartialForce
LineForceBase
Expand Down
49 changes: 1 addition & 48 deletions Modelica/Mechanics/MultiBody/Joints/Constraints/Prismatic.mo
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
within Modelica.Mechanics.MultiBody.Joints.Constraints;
model Prismatic
"Prismatic cut-joint and translational directions may be constrained or released"
extends Modelica.Mechanics.MultiBody.Interfaces.PartialTwoFrames;

parameter Boolean x_locked=true
"= true: constraint force in x-direction, resolved in frame_a"
annotation (Dialog(group="Constraints"),choices(checkBox=true));
parameter Boolean y_locked=true
"= true: constraint force in y-direction, resolved in frame_a"
annotation (Dialog(group="Constraints"),choices(checkBox=true));
parameter Boolean z_locked=true
"= true: constraint force in z-direction, resolved in frame_a"
annotation (Dialog(group="Constraints"),choices(checkBox=true));
extends Modelica.Mechanics.MultiBody.Interfaces.PartialConstraint;

parameter Boolean animation=true
"= true, if animation shall be enabled (show sphere)";
Expand All @@ -25,13 +15,6 @@ model Prismatic
"Reflection of ambient light (= 0: light is completely absorbed)"
annotation (Dialog(group="if animation = true", enable=animation));

protected
Frames.Orientation R_rel
"Dummy or relative orientation object from frame_a to frame_b";
SI.Position r_rel_a[3]
"Position vector from origin of frame_a to origin of frame_b, resolved in frame_a";
SI.InstantaneousPower P;

public
Visualizers.Advanced.Shape sphere(
shapeType="sphere",
Expand All @@ -46,40 +29,10 @@ public
r=frame_a.r_0,
R=frame_a.R) if world.enableAnimation and animation;
equation
// Determine relative position vector resolved in frame_a
R_rel = Frames.relativeRotation(frame_a.R, frame_b.R);
r_rel_a = Frames.resolve2(frame_a.R, frame_b.r_0 - frame_a.r_0);

// Constraint equations concerning rotations
// Same logic as for overdetermined connection graph loops to get good residuals.
zeros(3)=Modelica.Mechanics.MultiBody.Frames.Orientation.equalityConstraint(frame_a.R, frame_b.R);

// Constraint equations concerning translations
if x_locked then
r_rel_a[1]=0;
else
frame_a.f[1]=0;
end if;

if y_locked then
r_rel_a[2]=0;
else
frame_a.f[2]=0;
end if;

if z_locked then
r_rel_a[3]=0;
else
frame_a.f[3]=0;
end if;

zeros(3) = frame_a.t + Frames.resolve1(R_rel, frame_b.t) + cross(r_rel_a,
Frames.resolve1(R_rel, frame_b.f));
zeros(3) = Frames.resolve1(R_rel, frame_b.f) + frame_a.f;
P = frame_a.t*Frames.angularVelocity2(frame_a.R) + frame_b.t*
Frames.angularVelocity2(frame_b.R) + frame_b.f*Frames.resolve2(frame_b.R,
der(frame_b.r_0)) + frame_a.f*Frames.resolve2(frame_a.R, der(frame_a.r_0));

annotation (
defaultComponentName="constraint",
Icon(coordinateSystem(
Expand Down
Loading