PartialPressureValve_32

model PartialPressureValve_32
    import HydraulicsByFluidon.Media.Base.FluidInterface;

    outer HydraulicsByFluidon.Media.Environment environment;
    parameter Modelica.SIunits.VolumeFlowRate NominalVolumeFlow = 5e-4 "Nominal volume flow";
    parameter Modelica.SIunits.Pressure NominalPressureDifference = 1000000 "Nominal pressure difference";
    parameter Modelica.SIunits.Density ReferenceDensity = 860 "Reference density for volume flow and pressure difference";
    parameter Modelica.SIunits.Time timeConst(final min = 1e-4) = 0.001 "Response time of valve spool";
    parameter Modelica.SIunits.Volume deadVolume(final min = 1e-9) = 1e-6 "Dead volume at ports";
    Modelica.SIunits.DimensionlessRatio relX(start = 1) "Rel. valve position";
    Modelica.SIunits.AbsolutePressure pP(start = environment.pAmbient, nominal = 100000) "Pressure at port P";
    Modelica.SIunits.AbsolutePressure pT(start = environment.pAmbient, nominal = 100000) "Pressure at port T";
    Modelica.SIunits.AbsolutePressure pA(start = environment.pAmbient, nominal = 100000) "Pressure at port A";
    Modelica.SIunits.VolumeFlowRate volumeFlowP;
    Modelica.SIunits.VolumeFlowRate volumeFlowT;
    Modelica.SIunits.VolumeFlowRate volumeFlowA;
    HydraulicsByFluidon.Components.Volumes.Volume volumeA(capacity = deadVolume) annotation (Placement(
        visible = true,
        transformation(
            origin = {-50, -70},
            extent = {
                {-10, -10}, 
                {10, 10}},
            rotation = 0)));
    HydraulicsByFluidon.Components.Volumes.Volume volumeB(capacity = deadVolume) annotation (Placement(
        visible = true,
        transformation(
            origin = {-50, 70},
            extent = {
                {-10, -10}, 
                {10, 10}},
            rotation = 0)));
    HydraulicsByFluidon.Components.Resistors.IdealResistorVariable ResistorPA(NominalPressureDifference = NominalPressureDifference, NominalVolumeFlow = NominalVolumeFlow, ReferenceDensity = ReferenceDensity, forwardFluidProperties = true) annotation (Placement(
        visible = true,
        transformation(
            origin = {-50, 0},
            extent = {
                {10, -10}, 
                {-10, 10}},
            rotation = 0)));
    HydraulicsByFluidon.Components.Resistors.IdealResistorVariable ResistorAT(NominalPressureDifference = NominalPressureDifference, NominalVolumeFlow = NominalVolumeFlow, ReferenceDensity = ReferenceDensity, forwardFluidProperties = true) annotation (Placement(
        visible = true,
        transformation(
            origin = {50, 0},
            extent = {
                {10, -10}, 
                {-10, 10}},
            rotation = 0)));
    HydraulicsByFluidon.Interfaces.FluidPort portA "Hydraulic port A"
        annotation (Placement(
            transformation(
                origin = {-50, 100},
                extent = {
                    {-10, -10}, 
                    {10, 10}},
                rotation = 0),
            iconTransformation(
                origin = {-20, 100},
                extent = {
                    {-10, -10}, 
                    {10, 10}},
                rotation = 0)));
    HydraulicsByFluidon.Interfaces.FluidPort portP "Hydraulic port P"
        annotation (Placement(
            transformation(
                origin = {-50, -100},
                extent = {
                    {-10, -10}, 
                    {10, 10}},
                rotation = 0),
            iconTransformation(
                origin = {-20, -100},
                extent = {
                    {-10, -10}, 
                    {10, 10}},
                rotation = 0)));
    HydraulicsByFluidon.Interfaces.FluidPort portT "Hydraulic port T"
        annotation (Placement(
            transformation(
                origin = {50, -100},
                extent = {
                    {-10, -10}, 
                    {10, 10}},
                rotation = 0),
            iconTransformation(
                origin = {20, -100},
                extent = {
                    {-10, -10}, 
                    {10, 10}},
                rotation = 0)));
protected
    Modelica.SIunits.DimensionlessRatio ssU "Steady state valve input";
equation
    connect(portP,volumeA.fluidPort) annotation (Line(
        points = {
            {-50, -100}, 
            {-50, -70}},
        color = {0, 93, 152}));
    connect(portT,ResistorAT.fluidPortA) annotation (Line(
        points = {
            {50, -100}, 
            {50, -10}},
        color = {0, 93, 152}));
    connect(volumeA.fluidPort,ResistorPA.fluidPortA) annotation (Line(
        points = {
            {-50, -70}, 
            {-50, -10}},
        color = {0, 93, 152}));
    connect(volumeB.fluidPort,portA) annotation (Line(
        points = {
            {-50, 70}, 
            {-50, 100}},
        color = {0, 93, 152}));
    connect(ResistorAT.fluidPortB,volumeB.fluidPort) annotation (Line(
        points = {
            {50, 10}, 
            {50, 70}, 
            {-50, 70}},
        color = {0, 93, 152}));
    connect(ResistorPA.fluidPortB,volumeB.fluidPort) annotation (Line(
        points = {
            {-50, 10}, 
            {-50, 70}},
        color = {0, 93, 152}));
    der(relX) * timeConst = ssU - relX;
    pA = portA.p;
    pP = portP.p;
    pT = portT.p;
    volumeFlowA = portA.mFlow / FluidInterface.calcRho(portP.fluidId, portA.p, portA.fluidTemperature);
    volumeFlowP = portP.mFlow / FluidInterface.calcRho(portP.fluidId, portP.p, portP.fluidTemperature);
    volumeFlowT = portT.mFlow / FluidInterface.calcRho(portP.fluidId, portT.p, portT.fluidTemperature);
    ResistorAT.u = max(-relX, 0);
    ResistorPA.u = max(relX, 0);

    annotation (
        Icon(
            coordinateSystem(
                extent = {
                    {-100, -100}, 
                    {100, 100}},
                preserveAspectRatio = false),
            graphics = {
                Rectangle(
                    fillColor = {255, 255, 255},
                    fillPattern = FillPattern.Solid,
                    extent = {
                        {-40, 40}, 
                        {40, -40}}), 
                Line(
                    origin = {-19.8113, -9.76693},
                    points = {
                        {0, 30}, 
                        {0, -30}}), 
                Line(
                    origin = {-19.8113, -19.7669},
                    points = {
                        {0, 120}, 
                        {0, -80}}), 
                Line(points = {
                    {20, -100}, 
                    {20, -40}}), 
                Polygon(
                    origin = {-20, 40},
                    fillPattern = FillPattern.Solid,
                    points = {
                        {0, 0}, 
                        {-5, -20}, 
                        {5, -20}, 
                        {0, 0}}), 
                Polygon(
                    origin = {-20, -40},
                    rotation = 180,
                    fillPattern = FillPattern.Solid,
                    points = {
                        {0, 0}, 
                        {-5, -20}, 
                        {5, -20}, 
                        {0, 0}}), 
                Line(
                    origin = {-19.8113, -39.7669},
                    points = {
                        {0, 80}, 
                        {-20, 100}, 
                        {-60, 100}, 
                        {-60, 20}, 
                        {-20, 20}},
                    pattern = LinePattern.Dash)}),
        Documentation(info = "<html>\n            <p>\n                The component PressureReducingValve is a model of a 2-port pressure control valve. \n                It maintains a largely constant outlet pressure even at a variable (higher) inlet pressure.\n            </p>\n            <p>\n                <center><img src=\"modelica://HydraulicsByFluidon/Resources/Images/Components/Valves/PressureValves/PressureReducingValve.png\"></center>\n            </p>\n            <p>\n                If inlet pressure <var>pA</var> is less than <var>Set pressure (relative value)</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>Set pressure (relative value)</var> the valve opens and \n                the flow increases linearly following the slope given by parameters <var>Nominal volume flow</var> and \n                <var>Pressure drop</var>.\n            </p>\n            <p>\n                <center><img src=\"modelica://HydraulicsByFluidon/Resources/Images/Components/Valves/PressureValves/PressureReducingValveReducing.png\"></center>\n            </p>\n            <p>\n                The component PressureReducingValve is not a model of a pressure control valve according to its \n                physical structure. It merely represents the characteristic behavior of a pressure reducing \n                valve. Therefore dynamic effects such as forces due to inertia will not be represented.\n            </p>\n            </html>"));
end PartialPressureValve_32;