VariableResistor

model VariableResistor "Ideal linear electrical resistor with variable resistance"
    parameter SI.Temperature T_ref = 300.15 "Reference temperature";
    parameter SI.LinearTemperatureCoefficient alpha = 0 "Temperature coefficient of resistance (R_actual = R*(1 + alpha*(T_heatPort - T_ref))";

    extends Modelica.Electrical.Analog.Interfaces.OnePort;
    extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort(T = T_ref);

    SI.Resistance R_actual "Actual resistance = R*(1 + alpha*(T_heatPort - T_ref))";
    Modelica.Blocks.Interfaces.RealInput R(unit = "Ohm") annotation (Placement(
        transformation(
            origin = {0, 120},
            extent = {
                {-20, -20}, 
                {20, 20}},
            rotation = 270),
        iconTransformation(
            extent = {
                {-20, -20}, 
                {20, 20}},
            rotation = 270,
            origin = {0, 120})));
equation
    assert(Modelica.Constants.eps <= 1 + alpha * (T_heatPort - T_ref), "Temperature outside scope of model!");
    v = R_actual * i;
    LossPower = v * i;
    R_actual = R * (1 + alpha * (T_heatPort - T_ref));

    annotation (
        defaultComponentName = "resistor",
        Documentation(
            info = "<html>\n<p>The linear resistor connects the branch voltage <em>v</em> with the branch current <em>i</em> by\n<br><em><strong>i*R = v</strong></em>\n<br>The Resistance <em>R</em> is given as input signal.\n<br><br><strong>Attention!!!</strong><br>It is recommended that the R signal should not cross the zero value. Otherwise depending on the surrounding circuit the probability of singularities is high.</p>\n</html>",
            revisions = "<html>\n<ul>\n<li><em> August 07, 2009   </em>\n       by Anton Haumer<br> temperature dependency of resistance added<br>\n       </li>\n<li><em> March 11, 2009   </em>\n       by Christoph Clauss<br> conditional heat port added<br>\n       </li>\n<li><em>June 7, 2004   </em>\n       by Christoph Clauss<br>changed, docu added<br>\n       </li>\n<li><em>April 30, 2004</em>\n       by Anton Haumer<br>implemented.\n       </li>\n</ul>\n</html>"),
        Icon(
            coordinateSystem(
                preserveAspectRatio = true,
                extent = {
                    {-100, -100}, 
                    {100, 100}}),
            graphics = {
                Line(
                    points = {
                        {-90, 0}, 
                        {-70, 0}},
                    color = {0, 0, 255}), 
                Rectangle(
                    extent = {
                        {-70, 30}, 
                        {70, -30}},
                    lineColor = {0, 0, 255},
                    fillColor = {255, 255, 255},
                    fillPattern = FillPattern.Solid), 
                Line(
                    points = {
                        {70, 0}, 
                        {90, 0}},
                    color = {0, 0, 255}), 
                Text(
                    extent = {
                        {-150, 90}, 
                        {150, 50}},
                    textString = "%name",
                    lineColor = {0, 0, 255})}));
end VariableResistor;