TwoWayFlowControlValve

model TwoWayFlowControlValve
    extends HydraulicsByFluidon.Components.Valves.Base.PartialPressureFlowValve;

    parameter Modelica.SIunits.VolumeFlowRate Deviation = -8.33e-6 "Devitation";
    parameter Modelica.SIunits.Pressure DeviationPressureDifference = 1e+7 "Pressure difference @ Deviation";
    parameter Modelica.SIunits.Pressure CVOpeningPressure = 100000 "Opening pressure difference"
        annotation (Dialog(group = "Check valve"));
    parameter Modelica.SIunits.Pressure CVMaxOpeningPressure = 200000 "Max. opening pressure difference"
        annotation (Dialog(group = "Check valve"));
    parameter Modelica.SIunits.VolumeFlowRate CVNominalVolumeFlow = 5e-4 "Nominal volume flow"
        annotation (Dialog(group = "Check valve"));
    parameter Modelica.SIunits.Pressure CVNominalPressureDifference = 500000 "Nominal pressure difference"
        annotation (Dialog(group = "Check valve"));
    HydraulicsByFluidon.Components.Valves.CheckValves.CheckValvePT1 checkValvePT1(MaxOpeningPressure = CVMaxOpeningPressure, NominalPressureDifference = CVNominalPressureDifference, NominalVolumeFlow = CVNominalVolumeFlow, OpeningPressure = CVOpeningPressure, ReferenceDensity = ReferenceDensity, TimeConstant = timeConst, forwardFluidProperties = false) annotation (Placement(
        visible = true,
        transformation(
            origin = {40, 0},
            extent = {
                {-10, 10}, 
                {10, -10}},
            rotation = 0)));
    Modelica.Blocks.Continuous.LimIntegrator limIntegrator(k = timeConst ^ (-1), outMax = 1, outMin = 0) annotation (Placement(
        visible = true,
        transformation(
            origin = {-30, 0},
            extent = {
                {-10, -10}, 
                {10, 10}},
            rotation = 0)));
equation
    if noEvent(0 < fluidPortA.p - fluidPortB.p - NominalPressureDifference) then 
        limIntegrator.u = (NominalVolumeFlow + volumeFlowB + (fluidPortA.p - fluidPortB.p - NominalPressureDifference) / DeviationPressureDifference * Deviation) / NominalVolumeFlow;
    else 
        limIntegrator.u = (NominalVolumeFlow + volumeFlowB) / NominalVolumeFlow;
    end if;
    connect(checkValvePT1.fluidPortA,volumeB.fluidPort) annotation (Line(
        points = {
            {40, 10}, 
            {40, 70}, 
            {0, 70}},
        color = {0, 93, 152}));
    connect(checkValvePT1.fluidPortB,volumeA.fluidPort) annotation (Line(
        points = {
            {40, -10}, 
            {40, -70}, 
            {0, -70}},
        color = {0, 93, 152}));
    ssU = limIntegrator.y;

    annotation (
        Icon(
            coordinateSystem(
                extent = {
                    {-100, -100}, 
                    {100, 100}},
                preserveAspectRatio = false),
            graphics = {
                Rectangle(
                    fillColor = {255, 255, 255},
                    fillPattern = FillPattern.Solid,
                    extent = {
                        {-50, -80}, 
                        {100, 80}}), 
                Line(
                    origin = {0, -10},
                    points = {
                        {0, 30}, 
                        {0, -30}}), 
                Polygon(
                    origin = {0, 60},
                    fillPattern = FillPattern.Solid,
                    points = {
                        {0, 0}, 
                        {-5, -20}, 
                        {5, -20}, 
                        {0, 0}}), 
                Line(
                    origin = {0, -20},
                    points = {
                        {0, 120}, 
                        {0, -80}}), 
                Line(
                    origin = {10, 0},
                    points = {
                        {20, -20}, 
                        {0, 0}, 
                        {20, 20}}), 
                Line(
                    origin = {-10, 0},
                    points = {
                        {-20, -20}, 
                        {0, 0}, 
                        {-20, 20}}), 
                Line(points = {
                    {0, 90}, 
                    {0, -90}}), 
                Line(points = {
                    {-15, -25}, 
                    {15, 25}}), 
                Polygon(
                    origin = {25, 41.7},
                    rotation = -31,
                    fillPattern = FillPattern.Solid,
                    points = {
                        {0, 0}, 
                        {-5, -20}, 
                        {5, -20}, 
                        {0, 0}}), 
                Line(points = {
                    {0, 60}, 
                    {60, 60}, 
                    {60, 10}}), 
                Line(points = {
                    {60, 0}, 
                    {60, -60}, 
                    {0, -60}}), 
                Ellipse(
                    origin = {60, -5},
                    fillColor = {255, 255, 255},
                    fillPattern = FillPattern.Solid,
                    extent = {
                        {-10, -10}, 
                        {10, 10}}), 
                Line(
                    origin = {60, 10},
                    rotation = 180,
                    points = {
                        {-20, 20}, 
                        {0, 0}, 
                        {20, 20}}), 
                Ellipse(
                    origin = {0, -60},
                    fillPattern = FillPattern.Solid,
                    extent = {
                        {-2.5, -2.5}, 
                        {2.5, 2.5}}), 
                Ellipse(
                    origin = {0, 60},
                    fillPattern = FillPattern.Solid,
                    extent = {
                        {-2.5, -2.5}, 
                        {2.5, 2.5}})}),
        Documentation(info = "<html>\n            <p>\n                The component TwoWayFlowControlValve is a model of a 2-way flow control valve. \n                It maintains a largely constant outlet flow even at a variable (higher) inlet pressure.\n            </p>\n            <p>\n                <center><img src=\"modelica://HydraulicsByFluidon/Resources/Images/Components/Valves/FlowValves/TwoWayFlowControlValve.png\"></center>\n            </p>\n            <p>\n                If pressure difference <var>pA - pB</var> is less than <var>Nominal pressure difference</var> the valve acts like an orifice \n                with the characteristics <var>Nominal volume flow</var> and <var>Nominal pressure difference</var>.\n            </p>\n            <p>\n                For all pressures exceeding <var>Nominal pressure difference</var> the valve keeps the flow constant with the given \n                <var>Deviation</var> at <var>Pressure difference @ Deviation</var>.\n            </p>\n            <p>\n                <center><img src=\"modelica://HydraulicsByFluidon/Resources/Images/Components/Valves/FlowValves/TwoWayFlowControlValveSketch.png\"></center>\n            </p>\n            <p>\n                In reverse flow direction the check valve becomes active.\n            </p>\n            <p>\n                The component TwoWayFlowControlValve is not a model of a flow control valve according to its \n                physical structure. It merely represents the characteristic behavior of a flow control \n                valve. Therefore dynamic effects such as forces due to inertia will not be represented.\n            </p>\n            </html>"));
end TwoWayFlowControlValve;