VariableResistor

model VariableResistor "Single phase variable resistor"
    import Modelica.ComplexMath.real;
    import Modelica.ComplexMath.conj;

    extends Interfaces.OnePort;

    parameter Modelica.SIunits.Temperature T_ref = 293.15 "Reference temperature";
    parameter Modelica.SIunits.LinearTemperatureCoefficient alpha_ref = 0 "Temperature coefficient of resistance (R_actual = R_ref*(1 + alpha_ref*(heatPort.T - T_ref))";

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

    Modelica.SIunits.Resistance R_actual "Resistance = R_ref*(1 + alpha_ref*(heatPort.T - T_ref))";
    Modelica.Blocks.Interfaces.RealInput R_ref(unit = "Ohm") "Variable resistance"
        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_ref * (T_heatPort - T_ref), "Temperature outside scope of model!");
    v = R_actual * i;
    LossPower = real(v * conj(i));
    R_actual = R_ref * (1 + alpha_ref * (T_heatPort - T_ref));

    annotation (
        defaultComponentName = "resistor",
        Icon(graphics = {
            Line(
                points = {
                    {60, 0}, 
                    {90, 0}},
                color = {85, 170, 255}), 
            Line(
                points = {
                    {-90, 0}, 
                    {-60, 0}},
                color = {85, 170, 255}), 
            Rectangle(
                extent = {
                    {-70, 30}, 
                    {70, -30}},
                lineColor = {85, 170, 255},
                fillColor = {255, 255, 255},
                fillPattern = FillPattern.Solid), 
            Text(
                extent = {
                    {-150, 90}, 
                    {150, 50}},
                textString = "%name",
                lineColor = {0, 0, 255})}),
        Documentation(info = "<html>\n\n<p>\nThe linear resistor connects the voltage <code><u>v</u></code> with the\ncurrent <code><u>i</u></code> by <code><u>i</u>*R = <u>v</u></code>.\nThe resistance <code>R</code> is given as input signal.\n</p>\n\n<p>\nThe variable resistor model also has an optional\n<a href=\"modelica://Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort\">conditional heat port</a>.\nA linear temperature dependency of the resistance is also taken into account.\n</p>\n\n<h4>Note</h4>\n<p>\nA zero crossing of the R signal could cause singularities due to the actual structure of the connected network.\n</p>\n\n<h4>See also</h4>\n<p>\n<a href=\"modelica://Modelica.Electrical.QuasiStationary.SinglePhase.Basic.Resistor\">Resistor</a>,\n<a href=\"modelica://Modelica.Electrical.QuasiStationary.SinglePhase.Basic.Conductor\">Conductor</a>,\n<a href=\"modelica://Modelica.Electrical.QuasiStationary.SinglePhase.Basic.Capacitor\">Capacitor</a>,\n<a href=\"modelica://Modelica.Electrical.QuasiStationary.SinglePhase.Basic.Inductor\">Inductor</a>,\n<a href=\"modelica://Modelica.Electrical.QuasiStationary.SinglePhase.Basic.Impedance\">Impedance</a>,\n<a href=\"modelica://Modelica.Electrical.QuasiStationary.SinglePhase.Basic.Admittance\">Admittance</a>,\n<a href=\"modelica://Modelica.Electrical.QuasiStationary.SinglePhase.Basic.VariableConductor\">Variable conductor</a>,\n<a href=\"modelica://Modelica.Electrical.QuasiStationary.SinglePhase.Basic.VariableCapacitor\">Variable capacitor</a>,\n<a href=\"modelica://Modelica.Electrical.QuasiStationary.SinglePhase.Basic.VariableInductor\">Variable inductor</a>,\n<a href=\"modelica://Modelica.Electrical.QuasiStationary.SinglePhase.Basic.VariableImpedance\">Variable impedance</a>,\n<a href=\"modelica://Modelica.Electrical.QuasiStationary.SinglePhase.Basic.VariableAdmittance\">Variable admittance</a>\n</p>\n</html>"));
end VariableResistor;