SweptVolume

model SweptVolume "varying cylindric volume depending on the position of the piston"
    import Modelica.Constants.pi;

    parameter SI.Area pistonCrossArea "Cross sectional area of piston";
    parameter SI.Volume clearance "Remaining volume at zero piston stroke";
    SI.Volume V "fluid volume";

    extends Modelica.Fluid.Vessels.BaseClasses.PartialLumpedVessel(final fluidVolume = V, heatTransfer(surfaceAreas = {pistonCrossArea + 2 * sqrt(pistonCrossArea * pi) * (flange.s + clearance / pistonCrossArea)}));

    Modelica.Mechanics.Translational.Interfaces.Flange_b flange "translation flange for piston"
        annotation (Placement(transformation(extent = {
            {-10, 90}, 
            {10, 110}})));
equation
    for i in 1:nPorts loop
        vessel_ps_static[i] = medium.p;
    end for;
    assert(0 <= flange.s, "Piston stroke (given by flange.s) must not be smaller than zero!");
    0 = flange.f + (medium.p - system.p_ambient) * pistonCrossArea;
    V = clearance + flange.s * pistonCrossArea;
    Wb_flow = medium.p * pistonCrossArea * (-der(flange.s));

    annotation (
        Icon(
            coordinateSystem(
                preserveAspectRatio = true,
                extent = {
                    {-100, -100}, 
                    {100, 100}}),
            graphics = {
                Rectangle(
                    extent = {
                        {-50, 36}, 
                        {50, -90}},
                    lineColor = {0, 0, 255},
                    pattern = LinePattern.None,
                    lineThickness = 1,
                    fillColor = {170, 213, 255},
                    fillPattern = FillPattern.Solid), 
                Polygon(
                    points = {
                        {-52, 62}, 
                        {-48, 62}, 
                        {-48, -30}, 
                        {-52, -30}, 
                        {-52, 62}},
                    lineColor = {95, 95, 95},
                    fillColor = {135, 135, 135},
                    fillPattern = FillPattern.Backward), 
                Polygon(
                    points = {
                        {48, 60}, 
                        {52, 60}, 
                        {52, -34}, 
                        {48, -34}, 
                        {48, 60}},
                    lineColor = {95, 95, 95},
                    fillColor = {135, 135, 135},
                    fillPattern = FillPattern.Backward), 
                Rectangle(
                    extent = {
                        {-48, 40}, 
                        {48, 30}},
                    lineColor = {95, 95, 95},
                    fillColor = {135, 135, 135},
                    fillPattern = FillPattern.Forward), 
                Rectangle(
                    extent = {
                        {-6, 92}, 
                        {6, 40}},
                    lineColor = {95, 95, 95},
                    fillColor = {135, 135, 135},
                    fillPattern = FillPattern.Forward), 
                Polygon(
                    points = {
                        {-48, -90}, 
                        {48, -90}, 
                        {48, 70}, 
                        {52, 70}, 
                        {52, -94}, 
                        {-52, -94}, 
                        {-52, 70}, 
                        {-48, 70}, 
                        {-48, -90}},
                    lineColor = {95, 95, 95},
                    fillColor = {135, 135, 135},
                    fillPattern = FillPattern.Backward), 
                Line(
                    visible = use_HeatTransfer,
                    points = {
                        {-100, 0}, 
                        {-52, 0}},
                    color = {198, 0, 0})}),
        Documentation(
            info = "<html>\n<p> Mixing volume with varying size. The size of the volume is given by:</p>\n<ul>\n  <li>cross sectional piston area</li>\n  <li>piston stroke given by the flange position s</li>\n  <li>clearance (volume at flange position = 0)</li>\n</ul>\n<p>Losses are neglected. The shaft power is completely converted into mechanical work on the fluid.</p>\n\n<p> The flange position has to be equal or greater than zero. Otherwise the simulation stops. The force of the flange results from the pressure difference between medium and ambient pressure and the cross sectional piston area. For using the component, a top level instance of the ambient model with the inner attribute is needed.</p>\n<p> The pressure at both fluid ports equals the medium pressure in the volume. No suction nor discharge valve is included in the model.</p>\n<p>The thermal port is directly connected to the medium. The temperature of the thermal port equals the medium temperature. The heat capacity of the cylinder and the piston are not includes in the model.</p>\n</html>",
            revisions = "<html>\n<ul>\n<li><em>29 Oct 2007</em>\n    by Carsten Heinrich:<br>\n       Model added to the Fluid library</li>\n</ul>\n</html>"));
end SweptVolume;