PlungerCylinder

model PlungerCylinder
    import HydraulicsByFluidon.Media.Base.FluidInterface;
    import SI = Modelica.SIunits;

    parameter SI.Length cylinderDiameter(displayUnit = "mm") = 0.1 "Inner diameter of cylinder"
        annotation (Dialog(group = "Geometry"));
    parameter SI.Length plungerDiameter(displayUnit = "mm") = 0.05 "Plunger diameter"
        annotation (Dialog(group = "Geometry"));
    parameter SI.Length cylinderLength(displayUnit = "mm") = 0.4 "Cylinder length"
        annotation (Dialog(group = "Geometry"));
    parameter SI.Length plungerLength(displayUnit = "mm") = 0.4 "Plunger length"
        annotation (Dialog(group = "Geometry"));
    parameter SI.Angle angle(displayUnit = "deg") = 0 "Inclination angle"
        annotation (Dialog(group = "Geometry"));
    parameter SI.Volume deadVolume(displayUnit = "l") = 1e-4 "Dead volume"
        annotation (Dialog(group = "Geometry"));
    parameter SI.Mass massPlunger = 50 "Plunger mass"
        annotation (Dialog(group = "Mass"));
    parameter SI.Mass massCylinder = 40 "Cylinder mass"
        annotation (Dialog(group = "Mass"));
    SI.Position stroke(start = 0, displayUnit = "mm") "Distance between cylinder and piston";
    SI.Velocity relVelocity(start = 0) "Relative speed between cylinder and piston";
    SI.AbsolutePressure pA(start = environment.pAmbient, nominal = 100000) "Pressure in chamber A";
    parameter Real fProp(final unit = "N.s/m", final min = 0) = 10000 "Velocity dependent friction"
        annotation (Dialog(
            tab = "Losses",
            group = "Friction"));
    parameter Modelica.SIunits.Force fCoulomb = 250 "Constant friction/Coulomb force"
        annotation (Dialog(
            tab = "Losses",
            group = "Friction"));
    parameter Modelica.SIunits.Force fBreakaway = 500 "Breakaway friction force"
        annotation (Dialog(
            tab = "Losses",
            group = "Friction"));
    parameter Modelica.SIunits.Velocity vM = 0.005 "Velocity parameter for Stribeck friction"
        annotation (Dialog(
            tab = "Losses",
            group = "Friction"));
    parameter Boolean relFric = false "Use \"relative friction factor\" to calculate friction"
        annotation (
            Dialog(
                tab = "Losses",
                group = "Friction"),
            Evaluate = true,
            HideResult = true,
            choices(checkBox = true));
    parameter Real relFricFactor = 0 "Relative friction factor"
        annotation (Dialog(
            tab = "Losses",
            group = "Friction"));
    parameter SI.Velocity vSmall = 1e-4 "Relative velocity near to zero"
        annotation (Dialog(
            tab = "Losses",
            group = "Friction"));
    parameter SI.VolumeFlowRate leakageFlowRateExternal(min = 0, displayUnit = "l/min") = 0 "External leakage: volume flow"
        annotation (Dialog(
            tab = "Losses",
            group = "Leakage"));
    parameter SI.Pressure leakagePressureDiffExternal(min = 0) = 1e+7 "External leakage: pressure difference"
        annotation (Dialog(
            tab = "Losses",
            group = "Leakage"));
    parameter Modelica.SIunits.Density leakageReferenceDensity = 860 "Reference density for volume flow and pressure difference"
        annotation (Dialog(
            tab = "Losses",
            group = "Leakage"));
    Modelica.Mechanics.Translational.Interfaces.Flange_a flange_c annotation (Placement(
        visible = true,
        transformation(
            origin = {-100, 0},
            extent = {
                {-10, -10}, 
                {10, 10}},
            rotation = 0),
        iconTransformation(
            origin = {-120, 0},
            extent = {
                {-10, -10}, 
                {10, 10}},
            rotation = 0)));
    Modelica.Mechanics.Translational.Interfaces.Flange_b flange_p annotation (Placement(
        visible = true,
        transformation(
            origin = {100, 0},
            extent = {
                {-10, -10}, 
                {10, 10}},
            rotation = 0),
        iconTransformation(
            origin = {160, 0},
            extent = {
                {-10, -10}, 
                {10, 10}},
            rotation = 0)));
    HydraulicsByFluidon.Interfaces.FluidPort fluidPortA "Hydraulic port A"
        annotation (Placement(
            visible = true,
            transformation(
                extent = {
                    {-90, -90}, 
                    {-70, -110}},
                rotation = 0),
            iconTransformation(
                extent = {
                    {-90, -50}, 
                    {-70, -70}},
                rotation = 0)));
    Modelica.Blocks.Interfaces.RealOutput strokeOut "Relative position of piston"
        annotation (Placement(
            visible = true,
            transformation(
                extent = {
                    {100, 50}, 
                    {120, 70}},
                rotation = 0),
            iconTransformation(
                extent = {
                    {112, 30}, 
                    {132, 50}},
                rotation = 0)));
    HydraulicsByFluidon.Components.Base.SimplePlunger internalCylinder(angle = angle, cylinderLength = cylinderLength, deadVolume = deadVolume, fCoulomb = fCoulomb, fProp = fProp, fBreakaway = fBreakaway, massCylinder = massCylinder, massPiston = massPlunger, pistonDiameter = cylinderDiameter, rodDiameterB = plungerDiameter, rodLength = plungerLength, vM = vM, vSmall = vSmall, relFric = relFric, relFricFactor = relFricFactor) annotation (Placement(
        visible = true,
        transformation(
            origin = {-32, 0},
            extent = {
                {-19, -8}, 
                {21, 12}},
            rotation = 0)));
    HydraulicsByFluidon.Components.Volumes.OpenTank leakageTank annotation (Placement(
        visible = true,
        transformation(
            origin = {20, -50},
            extent = {
                {-10, -10}, 
                {10, 10}},
            rotation = 0)));
    HydraulicsByFluidon.Components.Resistors.IdealResistor externalLeakage(forwardFluidProperties = true, NominalPressureDifference = leakagePressureDiffExternal, NominalVolumeFlow = leakageFlowRateExternal, ReferenceDensity = leakageReferenceDensity, resistorType = HydraulicsByFluidon.Types.TResistorTypes.Throttle) annotation (Placement(
        visible = true,
        transformation(
            origin = {-10, -40},
            extent = {
                {-10, -10}, 
                {10, 10}},
            rotation = 90)));
protected
    outer HydraulicsByFluidon.Media.Environment environment;
equation
    connect(fluidPortA,externalLeakage.fluidPortB) annotation (Line(
        points = {
            {-80, -100}, 
            {-80, -100}, 
            {-80, -40}, 
            {-20, -40}, 
            {-20, -40}},
        color = {0, 93, 152}));
    connect(externalLeakage.fluidPortA,leakageTank.fluidPort) annotation (Line(
        points = {
            {0, -40}, 
            {20, -40}, 
            {20, -40}, 
            {20, -40}},
        color = {0, 93, 152}));
    connect(externalLeakage.fluidPortB,internalCylinder.fluidPortA) annotation (Line(
        points = {
            {-20, -40}, 
            {-40, -40}, 
            {-40, -6}, 
            {-40, -6}, 
            {-40, -6}},
        color = {0, 93, 152}));
    connect(internalCylinder.flange_c,flange_c) annotation (Line(
        points = {
            {-44, 0}, 
            {-100, 0}},
        color = {0, 127, 0}));
    connect(internalCylinder.flange_p,flange_p) annotation (Line(
        points = {
            {-44, 0}, 
            {-100, 0}},
        color = {0, 127, 0}));
    connect(internalCylinder.strokeOut,strokeOut) annotation (Line(
        points = {
            {-20, 4}, 
            {-20, 60}, 
            {110, 60}},
        color = {0, 0, 127}));
    pA = internalCylinder.pA;
    stroke = internalCylinder.stroke;
    relVelocity = internalCylinder.relVelocity;

    annotation (
        defaultComponentName = "plungerCylinder",
        Documentation(info = "<html>\n            <p>\n                Model of a plunger cylinder with Stribeck friction and volumetric losses.\n            </p>\n            <p>\n                The fundamental geometrical properties of the plunger cylinder are the cylinder and \n                plunger diameters (<var>Inner diameter of cylinder</var>, <var>Plunger diameter</var>) as well as the\n                lengths of the cylinder and the plunger (<var>Cylinder length</var> and <var>Plunger length</var>). \n                By using the parameter <var>Inclination angle</var>, \n                the inclination of the cylinder with respect to the horizon can be adjusted. \n                The resulting forces due to gravity are taken into account automatically.\n            </p>\n            <p>\n                For dynamic calculations, the masses of the plunger and the cylinder are required. These\n                can be provided by specifying the parameters <var>Plunger mass</var> and <var>Cylinder mass</var>.\n                The dynamic mass of the fluid, which acts as an additional inertia, is automatically taken\n                into account by the model.\n            </p>\n            <p>\n                The parameters <var>Breakaway friction force</var>, <var>Constant friction/Coulomb force</var>, <var>Velocity dependent friction</var> \n                and <var>Velocity parameter for Stribeck friction</var> (velocity where the friction force begins to grow linearly) characterize \n                the velocity dependence of the friction force between piston and cylinder.\n                Instead of using the Stribeck friction model, a simplified friction calculation can be enabled by setting the check mark <var>relFric</var>. In this case,\n                the friction force equals the net force acting on the interface between piston and cylinder multiplied by the parameter <var>Relative friction factor</var>.\n                Regardless of which friction model is used, the friction force is not influenced by the inclination of the cylinder or the system pressure.\n                The parameter <var>Relative velocity near to zero</var> is used by the internal state machine of the cylinder model \n                and determines the velocity below which the piston is considered stuck.\n            </p>\n            <p>\n                <center><img src=\"modelica://HydraulicsByFluidon/Resources/Images/Components/Cylinders/DiagramStribeckFriction.png\" width=\"400\"></center>\n            </p>\n            <p>\n                The pressure in the chamber can be initialized by assigning start values to <var>Pressure in chamber A</var>.\n                The parameter <var>Dead volume</var> determines the size of the parasitic volume which remains even if the plunger has reached the mechanical stops at the cylinder ends.\n            </p>\n            <p>\n                The volumetric losses due to external leakage are parameterized by providing the flow rate (<var>External leakage: volume flow</var>),\n                associated pressure drop (<var>External leakage: pressure difference</var>) and the fluid density \n                <var>Reference density for volume flow and pressure difference</var> for which these values were obtained.\n            </p></html>"),
        Icon(
            coordinateSystem(
                extent = {
                    {-190, -80}, 
                    {210, 120}},
                initialScale = 0.1),
            graphics = {
                Rectangle(
                    fillColor = {255, 255, 255},
                    pattern = LinePattern.None,
                    fillPattern = FillPattern.Solid,
                    extent = {
                        {-90, -40}, 
                        {90, 40}}), 
                Line(points = {
                    {90, 10}, 
                    {90, 40}, 
                    {-90, 40}, 
                    {-90, -40}, 
                    {90, -40}, 
                    {90, -10}}), 
                Rectangle(
                    fillColor = {255, 255, 0},
                    fillPattern = FillPattern.Solid,
                    extent = {
                        {-50, -30}, 
                        {130, 30}}), 
                Line(
                    points = {
                        {130, 0}, 
                        {160, 0}},
                    color = {0, 127, 0}), 
                Line(
                    points = {
                        {-90, 0}, 
                        {-120, 0}},
                    color = {0, 127, 0}), 
                Text(
                    lineColor = {0, 0, 255},
                    extent = {
                        {-90, 100}, 
                        {90, 60}},
                    textString = "%name",
                    horizontalAlignment = TextAlignment.Left), 
                Line(points = {
                    {-80, -40}, 
                    {-80, -60}}), 
                Line(points = {
                    {90, 40}, 
                    {120, 40}})}));
end PlungerCylinder;