model ValveIncompressible "Valve for (almost) incompressible fluids"
    import Modelica.Fluid.Types.CvTypes;
    import Modelica.Constants.pi;

    extends BaseClasses.PartialValve;

    constant SI.ReynoldsNumber Re_turbulent = 4000 "cf. straight pipe for fully open valve -- dp_turbulent increases for closing valve";
    parameter Boolean use_Re = system.use_eps_Re "= true, if turbulent region is defined by Re, otherwise by m_flow_small"
        annotation (
            Dialog(tab = "Advanced"),
            Evaluate = true);
    SI.AbsolutePressure dp_turbulent = if not use_Re then dp_small else max(dp_small, 0.125 * ((Medium.dynamicViscosity(state_a) + Medium.dynamicViscosity(state_b)) ^ 2 * pi) * Re_turbulent ^ 2 / (max(relativeFlowCoefficient, 0.001) * Av * (Medium.density(state_a) + Medium.density(state_b))));
    Real relativeFlowCoefficient;
initial equation
    if CvData == CvTypes.OpPoint then 
        m_flow_nominal = valveCharacteristic(opening_nominal) * Av * sqrt(rho_nominal) * Utilities.regRoot(dp_nominal, dp_small) "Determination of Av by the operating point";
    end if;
    if checkValve then 
        m_flow = homotopy(relativeFlowCoefficient * Av * sqrt(Medium.density(state_a)) * Utilities.regRoot2(dp, dp_turbulent, 1, 0, use_yd0 = true, yd0 = 0), relativeFlowCoefficient * m_flow_nominal * dp / dp_nominal);
    elseif not allowFlowReversal then 
        m_flow = homotopy(relativeFlowCoefficient * Av * sqrt(Medium.density(state_a)) * Utilities.regRoot(dp, dp_turbulent), relativeFlowCoefficient * m_flow_nominal * dp / dp_nominal);
        m_flow = homotopy(relativeFlowCoefficient * Av * Utilities.regRoot2(dp, dp_turbulent, Medium.density(state_a), Medium.density(state_b)), relativeFlowCoefficient * m_flow_nominal * dp / dp_nominal);
    end if;
    relativeFlowCoefficient = valveCharacteristic(opening_actual);

    annotation (Documentation(
        info = "<html>\n<p>\nValve model according to the IEC 534/ISA S.75 standards for valve sizing, incompressible fluids.</p>\n\n<p>\nThe parameters of this model are explained in detail in\n<a href=\"modelica://Modelica.Fluid.Valves.BaseClasses.PartialValve\">PartialValve</a>\n(the base model for valves).\n</p>\n\n<p>\nThis model assumes that the fluid has a low compressibility, which is always the case for liquids.\nIt can also be used with gases, provided that the pressure drop is lower than 0.2 times the absolute pressure at the inlet, so that the fluid density does not change much inside the valve.</p>\n\n<p>\nIf <code>checkValve</code> is false, the valve supports reverse flow, with a symmetric flow characteristic curve. Otherwise, reverse flow is stopped (check valve behaviour).\n</p>\n\n<p>\nThe treatment of parameters <strong>Kv</strong> and <strong>Cv</strong> is\nexplained in detail in the\n<a href=\"modelica://Modelica.Fluid.UsersGuide.ComponentDefinition.ValveCharacteristics\">User's Guide</a>.\n</p>\n\n</html>",
        revisions = "<html>\n<ul>\n<li><em>2 Nov 2005</em>\n    by <a href=\"\">Francesco Casella</a>:<br>\n       Adapted from the ThermoPower library.</li>\n</ul>\n</html>"));
end ValveIncompressible;