model ResistorTableQpx
    parameter String fileName = "NoFile" "File where look-up table is stored"
        annotation (Dialog(
            group = "Look-up table definition Q(pA - pB, x)",
                filter = "Text files (*.txt);;MATLAB MAT-files (*.mat)",
                caption = "Open file in which table is present")));
    parameter String tableName = "NoName" "Table name on file"
        annotation (Dialog(group = "Look-up table definition Q(pA - pB, x)"));
    parameter Modelica.SIunits.Density ReferenceDensity = 860 "Reference density"
        annotation (Dialog(group = "Flow parameters"));

    extends HydraulicsByFluidon.Components.Base.PartialResistorBase;

    Modelica.Blocks.Interfaces.RealInput u annotation (Placement(
        visible = true,
            origin = {-100, 0},
            extent = {
                {-20, -20}, 
                {20, 20}},
            rotation = 0),
            origin = {-80, 0},
            extent = {
                {-20, -20}, 
                {20, 20}},
            rotation = 0)));
    Modelica.Blocks.Tables.CombiTable2D inputTable(tableOnFile = true, tableName = tableName, fileName = fileName, smoothness = Modelica.Blocks.Types.Smoothness.LinearSegments, extrapolation = Modelica.Blocks.Types.Extrapolation.HoldLastPoint) annotation (Placement(
        visible = true,
            origin = {-50, 0},
            extent = {
                {-10, -10}, 
                {10, 10}},
            rotation = 0)));
    fluidPortA.mFlow = ReferenceDensity * inputTable.y;
    inputTable.u1 = -dp;
    inputTable.u2 = u;

    annotation (
            coordinateSystem(initialScale = 0.1),
            graphics = {
                Line(points = {
                    {-26, -13}, 
                    {26, 13}}), 
                    origin = {40, 20},
                    rotation = 297,
                    fillPattern = FillPattern.Solid,
                    points = {
                        {0, 0}, 
                        {-5, -20}, 
                        {5, -20}, 
                        {0, 0}})}),
        Documentation(info = "<html>\n            <p>\n                The component ResistorTableQpx is a model of an adjustable flow resistance.\n                It is parameterized by a 2D table which provides the volumetric\n                flow rate (counted positive for flow from port A to port B) as a function\n                of pressure drop (difference between pressures ports A and B) and input signal.\n                The component is predestined for integration of measured data into a simulation model.\n            </p>\n            <p>\n                Since the component calculates a mass flow rate, the user has to enter a\n                <i>Reference density</i> which matches the density at which the flow rate was\n                determined.\n            </p>\n            <p>\n                The look-up table is provided by importing a text file. The text file\n                must follow a specific syntax such that it can be read by Modelica. The\n                input pressure difference (provided in Pa) must cover negative as well as\n                positive values if the resistor should be used for both flow directions.\n                Both the input pressure difference and the input signal must\n                be arranged in increasing order. The resulting flow rate has to be provided in m&sup3;/s.\n                An example for a properly formatted text file with two tables is given in the\n                figure below: \n            </p>\n            <p>\n                <center><img src=\"modelica://HydraulicsByFluidon/Resources/Images/Components/Resistors/ResistorTableQpx.png\"></center>\n            </p>\n            <p>\n                A table is declared by its datatype (e. g. double), followed by the table name\n                (e. g. table2D) and its dimensions in brackets (e. g. (4,4)). Multiple tables\n                can be defined in the same text file. The table declaration is followed by the\n                actual data. Except for the first matrix element which has to be equal to 0, \n                the first column of the table represents the pressure drop, whereas the first\n                row corresponds to the input signal. All pressure drop and input values must\n                be arranged in increasing order. The component interpolates linearly between\n                the listed values. More information regarding the formatting of tables can be\n                found at <a href=\"modelica://Modelica.Blocks.Tables.CombiTable2D\">CombiTable2D</a>.\n            </p></html>"));
end ResistorTableQpx;