IdealResistorVariable

model IdealResistorVariable
    extends HydraulicsByFluidon.Components.Base.PartialResistorVariable;

    parameter Boolean tableFromFile = false "Table is provided by file"
        annotation (Dialog(group = "Look-up table definition"));
    parameter String fileName = "NoFile" "File where look-up table is stored"
        annotation (Dialog(
            group = "Look-up table definition",
            loadSelector(
                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"));
    parameter Real manualTable[:,:] = [0,0; 1,1] "Manually provided look-up table"
        annotation (Dialog(
            group = "Look-up table definition",
            enable = not tableFromFile));
    Modelica.Blocks.Interfaces.RealInput u annotation (Placement(
        visible = true,
        transformation(
            origin = {-100, 0},
            extent = {
                {-20, -20}, 
                {20, 20}},
            rotation = 0),
        iconTransformation(
            origin = {-80, 0},
            extent = {
                {-20, -20}, 
                {20, 20}},
            rotation = 0)));
    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,
        transformation(
            origin = {-50, 0},
            extent = {
                {-10, -10}, 
                {10, 10}},
            rotation = 0)));
    Modelica.Blocks.Nonlinear.Limiter limiterU(limitsAtInit = true, uMax = 1, uMin = inputMin, strict = true);
    Modelica.Blocks.Nonlinear.Limiter limiterTable(limitsAtInit = true, uMax = 1, uMin = 0, strict = true);
protected
    parameter Real inputMin = 0;
equation
    InputSignal = limiterTable.y;
    limiterU.u = u;
    inputTable.u = limiterU.y;
    limiterTable.u = inputTable.y[1];

    annotation (
        Icon(
            coordinateSystem(initialScale = 0.1),
            graphics = {
                Line(points = {
                    {-26, -13}, 
                    {26, 13}}), 
                Polygon(
                    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 IdealResistorVariable is a model of a flow resistance that behaves either\n                as an orifice or a throttle, depending on the parameter setting.\n            </p>\n            <p>\n                Flow is adjusted via the input signal with nominal flow (as given by <var>Nominal volume flow</var> at \n                <var>Nominal pressure difference</var>) corresponding to an input value of 1 (relative adjustment).\n            </p>\n            </p>\n                Both are parameterized by the parameters <var>Nominal volume flow</var> at <var>Nominal pressure difference</var>, \n                measured with a fluid with <var>Reference density</var>.\n            </p>\n            <p>\n                <b>Throttle</b>\n            </p>\n            <p>\n                <center><img align=\"middle\" src=\"modelica://HydraulicsByFluidon/Resources/Images/Components/Resistors/LaminarFlowIQp.png\"></center>\n            </p>\n            <p>\n                <center><img align=\"middle\" src=\"modelica://HydraulicsByFluidon/Resources/Images/Components/Resistors/LaminarIGraph.png\"></center>\n            </p>\n            <p>\n                <b>Orifice</b>\n            </p>\n            <p>\n                <center><img align=\"middle\" src=\"modelica://HydraulicsByFluidon/Resources/Images/Components/Resistors/TurbulentFlowIQp.png\"></center>\n            </p>\n            <p>\n                <center><img align=\"middle\" src=\"modelica://HydraulicsByFluidon/Resources/Images/Components/Resistors/TurbulentIGraph.png\"></center>\n            </p>\n            <p>\n                The default relationship between input signal and flow rate of the resistor is linear, but can be changed through the use of a 1D look-up table. \n                The look-up table is provided either manually or by importing a text file. If the parameter <var>Table is provided by file</var> is set to <i>false</i>, the \n                manually entered datapoints from <var>Manually provided look-up table</var> will be used. If it is set to <i>true</i>, the table <var>Table name on file</var> \n                from the file <var>File where look-up table is stored</var> will be utilized. \n            </p> \n            <p>\n                The text file must follow a specific syntax such that it can be read by Modelica. The input values as well as the output values must lie within \n                the range from 0 to 1. An output value of 1 (100 %) corresponds to a fully-opened resistor. An example for a properly formatted text file with \n                two tables is given in the figure below: \n            </p>\n            <p>\n                <center><img src=\"modelica://HydraulicsByFluidon/Resources/Images/Components/Resistors/ModelicaTableIdealResistorVariable.png\" width=\"300\"></center>\n            </p>\n            <p>\n                A table is declared by its datatype (e. g. double), followed by the table name (e. g. tab1) and its dimensions in brackets (e. g. (5,2)). As can \n                be seen, multiple tables can be defined in the same text file. The table declaration is followed by the actual data. The first column of the table \n                represents the input of the 1D table, whereas the second column lists the corresponding output values. The input values of the table must be in \n                increasing order. The component interpolates linearly between the listed input values. More information regarding the format of tables can be found \n                at <a href=\"modelica://Modelica.Blocks.Tables.CombiTable1Ds\">CombiTable1Ds</a>.\n            </p>\n        </html>"));
end IdealResistorVariable;