TableCurrent

model TableCurrent "Current source by linear interpolation in a table"
    parameter Real table[:,:] = [0,0; 1,1; 2,4] "Table matrix (time = first column, current = second column)";

    extends Interfaces.CurrentSource(redeclare Modelica.Blocks.Sources.TimeTable signalSource(final table = table));

    annotation (
        Icon(
            coordinateSystem(
                preserveAspectRatio = true,
                extent = {
                    {-100, -100}, 
                    {100, 100}}),
            graphics = {
                Line(
                    points = {
                        {-66, -36}, 
                        {-66, 84}, 
                        {34, 84}, 
                        {34, -36}, 
                        {-66, -36}, 
                        {-66, -6}, 
                        {34, -6}, 
                        {34, 24}, 
                        {-66, 24}, 
                        {-66, 54}, 
                        {34, 54}, 
                        {34, 84}, 
                        {-16, 84}, 
                        {-16, -37}},
                    color = {192, 192, 192})}),
        Diagram(
            coordinateSystem(
                preserveAspectRatio = true,
                extent = {
                    {-100, -100}, 
                    {100, 100}}),
            graphics = {
                Polygon(
                    points = {
                        {-80, 90}, 
                        {-88, 68}, 
                        {-72, 68}, 
                        {-80, 90}},
                    lineColor = {192, 192, 192},
                    fillColor = {192, 192, 192},
                    fillPattern = FillPattern.Solid), 
                Line(
                    points = {
                        {-80, 68}, 
                        {-80, -80}},
                    color = {192, 192, 192}), 
                Line(
                    points = {
                        {-90, -70}, 
                        {82, -70}},
                    color = {192, 192, 192}), 
                Polygon(
                    points = {
                        {90, -70}, 
                        {68, -62}, 
                        {68, -78}, 
                        {90, -70}},
                    lineColor = {192, 192, 192},
                    fillColor = {192, 192, 192},
                    fillPattern = FillPattern.Solid), 
                Rectangle(
                    extent = {
                        {-20, 90}, 
                        {30, -30}},
                    lineColor = {255, 255, 255},
                    fillColor = {192, 192, 192},
                    fillPattern = FillPattern.Solid), 
                Line(points = {
                    {-20, -30}, 
                    {-20, 90}, 
                    {80, 90}, 
                    {80, -30}, 
                    {-20, -30}, 
                    {-20, 0}, 
                    {80, 0}, 
                    {80, 30}, 
                    {-20, 30}, 
                    {-20, 60}, 
                    {80, 60}, 
                    {80, 90}, 
                    {30, 90}, 
                    {30, -31}}), 
                Text(
                    extent = {
                        {-77, -42}, 
                        {-38, -58}},
                    lineColor = {160, 160, 164},
                    textString = "offset"), 
                Polygon(
                    points = {
                        {-31, -30}, 
                        {-33, -40}, 
                        {-28, -40}, 
                        {-31, -30}},
                    lineColor = {192, 192, 192},
                    fillColor = {192, 192, 192},
                    fillPattern = FillPattern.Solid), 
                Polygon(
                    points = {
                        {-30, -70}, 
                        {-33, -60}, 
                        {-28, -60}, 
                        {-30, -70}, 
                        {-30, -70}},
                    lineColor = {192, 192, 192},
                    fillColor = {192, 192, 192},
                    fillPattern = FillPattern.Solid), 
                Line(
                    points = {
                        {-31, -31}, 
                        {-31, -70}},
                    color = {192, 192, 192}), 
                Line(
                    points = {
                        {-20, -20}, 
                        {-20, -70}},
                    color = {192, 192, 192},
                    pattern = LinePattern.Dash), 
                Text(
                    extent = {
                        {-38, -70}, 
                        {8, -88}},
                    lineColor = {160, 160, 164},
                    textString = "startTime"), 
                Line(
                    points = {
                        {-20, -30}, 
                        {-80, -30}},
                    color = {192, 192, 192},
                    pattern = LinePattern.Dash), 
                Text(
                    extent = {
                        {66, -81}, 
                        {91, -93}},
                    lineColor = {160, 160, 164},
                    textString = "time"), 
                Text(
                    extent = {
                        {-15, 83}, 
                        {24, 68}},
                    textString = "time"), 
                Text(
                    extent = {
                        {33, 83}, 
                        {76, 67}},
                    textString = "i"), 
                Text(
                    extent = {
                        {-73, 75}, 
                        {-53, 95}},
                    lineColor = {192, 192, 192},
                    textString = "i")}),
        Documentation(
            info = "<html>\n<p>This current source uses the corresponding signal source of the Modelica.Blocks.Sources package. Furthermore, an offset parameter is introduced, which is added to the value calculated by the blocks source. The startTime parameter allows to shift the blocks source behavior on the time axis.</p>\n<p><br>This block generates a current source by <strong>linear interpolation</strong> in a table. The time points and current values are stored in a matrix <strong>table[i,j]</strong>, where the first column table[:,1] contains the time points and the second column contains the current to be interpolated. The table interpolation has the following properties:</p>\n<ul>\n<li>The time points need to be <strong>monotonically increasing</strong>.</li>\n<li><strong>Discontinuities</strong> are allowed, by providing the same time point twice in the table.</li>\n<li>Values <strong>outside</strong> of the table range, are computed by <strong>extrapolation</strong> through the last or first two points of the table.</li>\n<li>If the table has only <strong>one row</strong>, no interpolation is performed and the current value is just returned independently of the actual time instant, i.e., this is a constant current source.</li>\n<li>Via parameters <strong>startTime</strong> and <strong>offset</strong> the curve defined by the table can be shifted both in time and in the current.</li>\n<li>The table is implemented in a numerically sound way by generating <strong>time events</strong> at interval boundaries.\n    This generates continuously differentiable values for the integrator.</li>\n</ul>\n<p>Example:</p>\n<pre>   table = [0  0\n            1  0\n            1  1\n            2  4\n            3  9\n            4 16]\nIf, e.g., time = 1.0, the current i =  0.0 (before event), 1.0 (after event)\n    e.g., time = 1.5, the current i =  2.5,\n    e.g., time = 2.0, the current i =  4.0,\n    e.g., time = 5.0, the current i = 23.0 (i.e., extrapolation). </pre>\n<p><br> Furthermore, an offset parameter is introduced, which is added to the value calculated by the blocks source. The startTime parameter allows to shift the blocks source behavior on the time axis.</p>\n</html>",
            revisions = "<html>\n<ul>\n<li><em> 1998   </em>\n       by Christoph Clauss<br> initially implemented<br>\n       </li>\n</ul>\n</html>"));
end TableCurrent;