TableVoltage

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

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

    annotation (
        Icon(
            coordinateSystem(
                preserveAspectRatio = true,
                extent = {
                    {-100, -100}, 
                    {100, 100}}),
            graphics = {
                Line(
                    points = {
                        {-58, -36}, 
                        {-58, 84}, 
                        {42, 84}, 
                        {42, -36}, 
                        {-58, -36}, 
                        {-58, -6}, 
                        {42, -6}, 
                        {42, 24}, 
                        {-58, 24}, 
                        {-58, 54}, 
                        {42, 54}, 
                        {42, 84}, 
                        {-8, 84}, 
                        {-8, -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}, 
                        {-29, -40}, 
                        {-31, -30}},
                    lineColor = {192, 192, 192},
                    fillColor = {192, 192, 192},
                    fillPattern = FillPattern.Solid), 
                Polygon(
                    points = {
                        {-31, -70}, 
                        {-33, -60}, 
                        {-29, -60}, 
                        {-31, -70}, 
                        {-31, -70}},
                    lineColor = {192, 192, 192},
                    fillColor = {192, 192, 192},
                    fillPattern = FillPattern.Solid), 
                Line(
                    points = {
                        {-31, -30}, 
                        {-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 = "v"), 
                Text(
                    extent = {
                        {-81, 98}, 
                        {-31, 85}},
                    lineColor = {160, 160, 164},
                    textString = "v = p.v - n.v")}),
        Documentation(
            info = "<html>\n<p>This voltage 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 voltage source by <strong>linear interpolation</strong> in a table. The time points and voltage 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 voltage 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 voltage value is just returned independently of the actual time instant, i.e., this is a constant voltage 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 voltage.</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 voltage v =  0.0 (before event), 1.0 (after event)\n    e.g., time = 1.5, the voltage v =  2.5,\n    e.g., time = 2.0, the voltage v =  4.0,\n    e.g., time = 5.0, the voltage v = 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 TableVoltage;