Resistor

model Resistor "Ideal linear electrical resistor"
    parameter SI.Resistance R(start = 1) "Resistance at temperature T_ref";
    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))";
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 (
        Documentation(
            info = "<html>\n<p>The linear resistor connects the branch voltage <em>v</em> with the branch current <em>i</em> by <em>i*R = v</em>. The Resistance <em>R</em> is allowed to be positive, zero, or negative.</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> 1998   </em>\n       by Christoph Clauss<br> initially implemented<br>\n       </li>\n</ul>\n</html>"),
        Icon(
            coordinateSystem(
                preserveAspectRatio = true,
                extent = {
                    {-100, -100}, 
                    {100, 100}}),
            graphics = {
                Rectangle(
                    extent = {
                        {-70, 30}, 
                        {70, -30}},
                    lineColor = {0, 0, 255},
                    fillColor = {255, 255, 255},
                    fillPattern = FillPattern.Solid), 
                Line(
                    points = {
                        {-90, 0}, 
                        {-70, 0}},
                    color = {0, 0, 255}), 
                Line(
                    points = {
                        {70, 0}, 
                        {90, 0}},
                    color = {0, 0, 255}), 
                Text(
                    extent = {
                        {-150, -40}, 
                        {150, -80}},
                    textString = "R=%R"), 
                Line(
                    visible = useHeatPort,
                    points = {
                        {0, -100}, 
                        {0, -30}},
                    color = {127, 0, 0},
                    pattern = LinePattern.Dot), 
                Text(
                    extent = {
                        {-150, 90}, 
                        {150, 50}},
                    textString = "%name",
                    lineColor = {0, 0, 255})}));
end Resistor;