PartialCheckValvePT1

model PartialCheckValvePT1
    replaceable HydraulicsByFluidon.Components.Valves.Base.ValveEdge valveEdge1(forwardFluidProperties = false, idealResistorVariable1(resistorType = resistorType), NominalVolumeFlow = NominalVolumeFlow, NominalPressureDifference = NominalPressureDifference, ReferenceDensity = ReferenceDensity) annotation (Placement(
        visible = true,
        transformation(
            origin = {0, 0},
            extent = {
                {-10, -10}, 
                {10, 10}},
            rotation = 0)));
    parameter Modelica.SIunits.Pressure OpeningPressure = 100000 "Opening pressure difference";
    parameter Modelica.SIunits.Pressure MaxOpeningPressure = 200000 "Max. opening pressure difference";
    parameter Modelica.SIunits.VolumeFlowRate NominalVolumeFlow = 5e-4 "Nominal volume flow";
    parameter Modelica.SIunits.Pressure NominalPressureDifference = 500000 "Nominal pressure difference";
    parameter HydraulicsByFluidon.Types.TResistorTypes resistorType = HydraulicsByFluidon.Types.TResistorTypes.Orifice "Type of the resistor";
    parameter Modelica.SIunits.Density ReferenceDensity = 860 "Reference density for volume flow and pressure difference";
    parameter Modelica.SIunits.Time TimeConstant = 0.001 "Time constant of the first order delay";
    parameter Modelica.SIunits.Volume deadVolume(final min = 1e-9) = 1e-6 "Dead volume at ports"
        annotation (Dialog(group = "Geometry"));

    extends HydraulicsByFluidon.Components.Base.HydTwoPortVerticalExt;

    Modelica.Blocks.Continuous.FirstOrder firstOrder1(k = 1, T = TimeConstant, y_start = 0) annotation (Placement(
        visible = true,
        transformation(
            origin = {-50, 8},
            extent = {
                {-10, -10}, 
                {10, 10}},
            rotation = 0)));
    HydraulicsByFluidon.Components.Volumes.Volume VolumeA(capacity = deadVolume) annotation (Placement(
        visible = true,
        transformation(
            origin = {0, -50},
            extent = {
                {-10, -10}, 
                {10, 10}},
            rotation = 0)));
    HydraulicsByFluidon.Components.Volumes.Volume VolumeB(capacity = deadVolume) annotation (Placement(
        visible = true,
        transformation(
            origin = {0, 50},
            extent = {
                {-10, -10}, 
                {10, 10}},
            rotation = 0)));
protected
    Real deltap(start = 0) "Initial opening pressure difference (relative value)";
    Real pPilot(start = 0);
initial equation
    firstOrder1.y = max(0, deltap);
equation
    connect(fluidPortA,VolumeA.fluidPort) annotation (Line(
        points = {
            {0, -100}, 
            {0, -50}},
        color = {0, 93, 152}));
    connect(fluidPortB,VolumeB.fluidPort) annotation (Line(
        points = {
            {0, 100}, 
            {0, 50}},
        color = {0, 93, 152}));
    connect(firstOrder1.y,valveEdge1.Input) annotation (Line(
        points = {
            {-38, 8}, 
            {-8, 8}, 
            {-8, 8}, 
            {-8, 8}},
        color = {0, 0, 127}));
    connect(valveEdge1.portA,VolumeA.fluidPort) annotation (Line(
        points = {
            {0, -8}, 
            {0, -50}},
        color = {0, 93, 152}));
    connect(valveEdge1.portB,VolumeB.fluidPort) annotation (Line(
        points = {
            {0, 10}, 
            {0, 50}},
        color = {0, 93, 152}));
    deltap = fluidPortA.p - OpeningPressure - fluidPortB.p + pPilot;
    firstOrder1.u = max(0, deltap);
    valveEdge1.InputMax = MaxOpeningPressure - OpeningPressure;
    valveEdge1.Offset = 0;

    annotation (Icon(graphics = {
        Line(points = {
            {0, -100}, 
            {0, -36}}), 
        Line(points = {
            {0, -12}, 
            {0, 100}}), 
        Ellipse(
            origin = {0, -22},
            fillColor = {255, 255, 255},
            fillPattern = FillPattern.Solid,
            extent = {
                {-10, -10}, 
                {10, 10}},
            endAngle = 360), 
        Line(
            origin = {0, -36},
            points = {
                {-20, 20}, 
                {0, 0}, 
                {20, 20}}), 
        Line(
            origin = {0, -12},
            rotation = 90,
            points = {
                {0, 0}, 
                {4, -20}, 
                {12, 20}, 
                {20, -20}, 
                {28, 20}, 
                {36, -20}, 
                {44, 20}, 
                {48, 0}})}));
end PartialCheckValvePT1;