Cylinder

model Cylinder "Simple model of a piston in a cylinder"
    import Modelica.Constants.small;

    extends Modelica.Thermal.FluidHeatFlow.Interfaces.Partials.SinglePortLeft(final Exchange = true);

    parameter Modelica.SIunits.Area A "Cross section of cylinder/piston";
    parameter Modelica.SIunits.Length L "Length of cylinder";

    extends Modelica.Mechanics.Translational.Interfaces.PartialElementaryOneFlangeAndSupport2(s(start = small));

    Modelica.SIunits.Force f = flange.f "Force at piston";
protected
    Modelica.SIunits.Mass m "Mass of medium";
    Modelica.SIunits.Enthalpy H "Enthalpy of medium";
equation
    assert(s <= L, getInstanceName() + ":Piston hit top of cylinder!");
    assert(small <= s, getInstanceName() + ": Piston hit bottom of cylinder!");
    flowPort.p * A = -f;
    H = m * h;
    m = medium.rho * A * s;
    der(H) = flowPort.H_flow;
    der(m) = flowPort.m_flow;

    annotation (
        Documentation(info = "<html>\n<p>This is a simple model of a piston in a cylinder:</p>\n<p>The translational flange is connected to the piston, the cylinder has a flowPort at the bottom.</p>\n<p>\nThe position of the piston within the cylinder goes from 0 at the bottom to L (length of the cylinder) at the top of the cylinder.\nIf the piston leaves the cylinder, an assertion is triggered.\n</p>\n<ul>\n<li>A movement of the piston is coupled with volume flow through the flowPort.</li>\n<li>The force at the piston is equal to pressure of the fluid times A (cross section of the piston).</li>\n</ul>\n<p>\nThe piston is considered without mass.\n</p>\n<p>\nNote: Take care of the initial conditions. The position of the piston (relative to the support) should be in the range (0, L).\nThe position of the flange (as well as of the support, if useSupport=true) is influenced by connected components.\n</p>\n</html>"),
        Icon(
            coordinateSystem(
                preserveAspectRatio = true,
                extent = {
                    {-100, -100}, 
                    {100, 100}}),
            graphics = {
                Text(
                    extent = {
                        {-150, 140}, 
                        {150, 100}},
                    lineColor = {0, 0, 255},
                    textString = "%name"), 
                Polygon(
                    points = {
                        {-90, 10}, 
                        {-70, 10}, 
                        {-70, 60}, 
                        {70, 60}, 
                        {70, -60}, 
                        {-70, -60}, 
                        {-70, -10}, 
                        {-90, -10}, 
                        {-90, 10}},
                    lineColor = {255, 0, 0},
                    fillColor = {0, 0, 255},
                    fillPattern = FillPattern.Solid,
                    lineThickness = 0.5), 
                Rectangle(
                    extent = {
                        {-14, 58}, 
                        {68, -58}},
                    lineColor = {28, 108, 200},
                    fillColor = {255, 255, 255},
                    fillPattern = FillPattern.Solid), 
                Rectangle(
                    extent = {
                        {-24, 58}, 
                        {-14, -58}},
                    lineThickness = 0.5,
                    fillColor = {192, 192, 192},
                    fillPattern = FillPattern.HorizontalCylinder), 
                Rectangle(
                    extent = {
                        {-14, 10}, 
                        {90, -10}},
                    lineThickness = 0.5,
                    lineColor = {0, 127, 0},
                    fillColor = {160, 215, 160},
                    fillPattern = FillPattern.HorizontalCylinder), 
                Line(points = {
                    {-10, -72}, 
                    {70, -72}}), 
                Polygon(
                    points = {
                        {-40, -72}, 
                        {-10, -62}, 
                        {-10, -82}, 
                        {-40, -72}},
                    lineColor = {128, 128, 128},
                    fillColor = {128, 128, 128},
                    fillPattern = FillPattern.Solid)}));
end Cylinder;