model CustomLiquid
    import HydraulicsByFluidon.Media.Base.FluidInterface;

    extends Modelica.Blocks.Icons.Block;
    extends HydraulicsByFluidon.Media.Base.BaseFluid;

    parameter Modelica.SIunits.Temperature fluidTemperature = 293;
    parameter Real proportionUndissolvedAir = 0.001 "Proportion of undissolved air";
    parameter Real polytropicExponent = 1.1 "Polytropic exponent";
    parameter Modelica.SIunits.Pressure p0 = 101325 "Reference pressure for density calculation";
    parameter Modelica.SIunits.Temperature T0 = 288.15 "Reference temperature for density calculation";
    parameter Modelica.SIunits.Density rho0 = 870 "Density of fluid at reference temperature and pressure";
    parameter Modelica.SIunits.BulkModulus Kt = 1.7e+9 "Isothermal bulk modulus";
    parameter Modelica.SIunits.CubicExpansionCoefficient Gammap = 7e-4 "Thermal expansion coefficient";
    parameter Modelica.SIunits.SpecificHeatCapacityAtConstantPressure cp = 2000 "Specific heat capacity at constant pressure";
    parameter Modelica.SIunits.Temperature T1 = 313.15 "First reference temperature for viscosity calculation";
    parameter Modelica.SIunits.KinematicViscosity nu1 = 4.6e-5 "Kinematic viscosity at T1 and ambient pressure";
    parameter Modelica.SIunits.Temperature T2 = 373.15 "Second reference temperature for viscosity calculation";
    parameter Modelica.SIunits.KinematicViscosity nu2 = 7e-6 "Kinematic viscosity at T2 and ambient pressure";
    HydraulicsByFluidon.Interfaces.FluidPort fluidPort "Hydraulic port"
        annotation (Placement(transformation(extent = {
            {100, -10}, 
            {120, 10}})));
    Integer fluidID;
initial equation
    fluidID = FluidInterface.registerFluid(0, p0, T0, rho0, Kt, Gammap, cp, nu1, nu2, T1, T2);
    fluidPort.fluidId = fluidID;
    fluidPort.mFlow = 0;
    fluidPort.fluidTemperature = fluidTemperature;
    fluidPort.polytropicExponent = polytropicExponent;
    fluidPort.proportionUndissolvedAir = proportionUndissolvedAir;

    annotation (
                preserveAspectRatio = true,
                extent = {
                    {-100, -100}, 
                    {100, 100}}),
            graphics = {
                    lineColor = {0, 93, 152},
                    fillColor = {0, 93, 152},
                    fillPattern = FillPattern.Solid,
                    extent = {
                        {-40, 30}, 
                        {40, -55}},
                    endAngle = 360), 
                    lineColor = {0, 93, 152},
                    fillColor = {0, 93, 152},
                    fillPattern = FillPattern.Solid,
                    points = {
                        {-37, 5}, 
                        {37, 5}, 
                        {0, 75}, 
                        {-37, 5}}), 
                    fillPattern = FillPattern.VerticalCylinder,
                    extent = {
                        {-100, -55}, 
                        {100, -95}},
                    textString = "Custom")}),
        Documentation(info = "<html>\n            <p>\n                Model of a custom hydraulic liquid. The model provides the other components (e.g. pipes) with user-defined temperature- and pressure-dependent fluid properties. In order for the fluid properties to reach the other components, the liquid model must be connected to the hydraulic circuit.\n            </p>\n            <p>\n                The underlying model is based on the following assumptions:\n                <ul>\n                    <li>\n                        In the vicinity of the <var>Reference pressure</var> p0 and <var>Reference temperature</var> T0, the density changes linearly with pressure p and temperature T. Hence, the <var>Isothermal bulk modulus</var> and the <var>Thermal expansion coefficient</var> are constants.\n                    </li>\n                    <li>\n                        The change of kinematic viscosity with respect to temperature follows the law proposed by Ubbelohde and Walther (DIN 51563).\n                    </li>\n                    <li>\n                        The kinematic viscosity is not affected by the pressure level.\n                    </li>\n                    <li>\n                        The specific thermal capacity at constant pressure is a constant.\n                    </li>\n                </ul>\n            </p>\n            <p>\n                The density is calculated by the following equation:\n                <center><img src=\"modelica://HydraulicsByFluidon/Resources/Images/Media/CustomLiquid/EqCustomLiquidRho.gif\"></center>\n            </p>\n            <p>\n                The isentropic bulk modulus is given by:\n                <center><img src=\"modelica://HydraulicsByFluidon/Resources/Images/Media/CustomLiquid/EqCustomLiquidKs.gif\"></center>\n            </p>\n            <p>\n                In order to use the component, the following parameters have to be provided by the user:\n                <ul>\n                    <li>\n                        <var>Reference pressure</var> p0 and <var>temperature</var> T0 to calculate the density\n                    </li>\n                    <li>\n                        <var>Density</var> rho0 at <var>Reference pressure</var> and <var>temperature</var>\n                    </li>\n                    <li>\n                        <var>Isothermal bulk modulus</var> Kt and <var>Thermal expansion coefficient</var> Gammap\n                    </li>\n                    <li>\n                        <var>Specific heat capacity</var> cp at constant pressure\n                    </li>                                \n                    <li>\n                        <var>Kinematic viscosities</var> nu1 and nu2 at ambient pressure for two different temperatures T1 and T2\n                    </li>\n                </ul>\n                Because the <var>Isothermal bulk modulus</var> is assumed to be constant, the stiffening of the hydraulic fluid with respect to pressure is not taken into account by the employed model. Therefore, the custom liquid should only be used for pressures and temperatures in the vicinity of the reference values p0 and T0.\n            </p>\n            <p>\n                If the effects of undissolved air are to be considered during the simulation, the user can provide the fraction of undissolved air at ambient pressure through the parameter <var>Proportion of undissolved air</var>. The stiffness of the gas bubbles is calculated based on the parameter <var>Polytropic exponent</var> which can assume values between 1.0 (isothermal change of state, slow compression/expansion) and 1.4 (isentropic change of state, fast compression/expansion).\n            </p></html>"));
end CustomLiquid;