model ResistorTableQp
    parameter Boolean tableFromFile = false "Table is provided by file"
        annotation (Dialog(group = "Look-up table definition Q(pA - pB)"));
    parameter String fileName = "NoFile" "File where look-up table is stored"
        annotation (Dialog(
            group = "Look-up table definition Q(pA - pB)",
                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)"));
    parameter Real manualTable[:,:] = [-2e+7,-5e-4; 0,0; 2e+7,5e-4] "Manually provided look-up table"
        annotation (Dialog(
            group = "Look-up table definition Q(pA - pB)",
            enable = not tableFromFile));
    parameter Modelica.SIunits.Density ReferenceDensity = 860 "Reference density"
        annotation (Dialog(group = "Flow parameters"));

    extends HydraulicsByFluidon.Components.Base.PartialResistorBase;

    Modelica.Blocks.Tables.CombiTable1Ds inputTable(table = manualTable, tableOnFile = tableFromFile, 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[1];
    inputTable.u = -dp;

    annotation (Documentation(info = "<html>\n            <p>\n                The component ResistorTableQp is a model of a flow resistance.\n                It is parameterized by a 1D look-up 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). The component is predestined for\n                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                <var>Reference density</var> 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 or can be given manually in the dialog. If the parameter\n                <var>Table is provided by file</var> is set to <var>false</var>, the datapoints from <var>Manually provided look-up table</var>\n                will be used. If it is set to <var>true</var>, the table from the text file will be utilized. The text file must follow a specific\n                syntax such that it can be read by Modelica. The 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. 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 figure below: \n            </p>\n            <p>\n                <center><img src=\"modelica://HydraulicsByFluidon/Resources/Images/Components/Resistors/ResistorTableQp.png\"></center>\n            </p>\n            <p>\n                A table is declared by its datatype (e. g. double), followed by the table name (e. g. table1D) and its dimensions in brackets \n                (e. g. (9,2)). Multiple tables can be defined in the same text file. The table declaration is followed by the actual data.\n                The first column of the table represents the input of the 1D table, whereas the second column lists the corresponding \n                output values. The input values of the table must be arranged in increasing order. The component interpolates linearly \n                between the listed input values. More information regarding the format of tables can be found at \n                <a href=\"modelica://Modelica.Blocks.Tables.CombiTable1Ds\">CombiTable1Ds</a>.\n            </p>\n        </html>"));
end ResistorTableQp;