Admittance

model Admittance "Single phase linear admittance"
    import Modelica.ComplexMath.j;
    import Modelica.ComplexMath.real;
    import Modelica.ComplexMath.imag;
    import Modelica.ComplexMath.conj;

    extends Interfaces.OnePort;

    parameter Modelica.SIunits.ComplexAdmittance Y_ref(re(start = 1), im(start = 0)) "Complex admittance G_ref + j*B_ref";
    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);

    parameter Boolean frequencyDependent = false "Consider frequency dependency, if true"
        annotation (
            Evaluate = true,
            HideResult = true,
            choices(checkBox = true));
    parameter Modelica.SIunits.Frequency f_ref = 1 "Reference frequency, if frequency dependency is considered"
        annotation (Dialog(enable = frequencyDependent));
    Modelica.SIunits.Conductance G_actual "Resistance = R_ref*(1 + alpha_ref*(heatPort.T - T_ref))";
    Modelica.SIunits.Susceptance B_actual "Susceptance considering possible frequency dependency";
    final parameter Modelica.SIunits.Conductance G_ref = real(Y_ref) "Resistive component of conductance";
    final parameter Modelica.SIunits.Susceptance B_ref = imag(Y_ref) "Reactive component of susceptance";
equation
    assert(Modelica.Constants.eps <= 1 + alpha_ref * (T_heatPort - T_ref), "Temperature outside scope of model!");
    i = Complex(G_actual, B_actual) * v;
    B_actual = B_ref * (if not frequencyDependent then 1 else if 0 <= B_ref then omega / (2 * Modelica.Constants.pi * f_ref) else 2 * Modelica.Constants.pi * f_ref / omega);
    G_actual = G_ref / (1 + alpha_ref * (T_heatPort - T_ref));
    LossPower = real(v * conj(i));

    annotation (
        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), 
            Polygon(
                points = {
                    {-70, -30}, 
                    {70, 30}, 
                    {70, -30}, 
                    {-70, -30}},
                lineColor = {85, 170, 255},
                fillColor = {85, 170, 255},
                fillPattern = FillPattern.Solid), 
            Text(
                extent = {
                    {-150, 90}, 
                    {150, 50}},
                textString = "%name",
                lineColor = {0, 0, 255})}),
        Documentation(info = "<html>\n\n<p>The admittance model represents a <strong>parallel</strong> connection of a conductor and either a capacitor or inductor.<br>\n<img src=\"modelica://Modelica/Resources/Images/Electrical/QuasiStationary/SinglePhase/Basic/GB_admittance.png\"></p>\n\n<p>\nThe linear admittance connects the voltage <code><u>v</u></code> with the\ncurrent <code><u>i</u></code> by  <code><u>i</u> = <u>Y</u>*<u>v</u></code>. The resistive\ncomponent is modeled temperature dependent, so the real part <code>G_actual = real(<u>Y</u>)</code> is determined from\nthe actual operating temperature and the reference input conductance <code>real(Y_ref)</code>.\nA <a href=\"modelica://Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort\">conditional heat port</a> is considered.\nThe reactive component <code>B_actual = imag(<u>Y</u>)</code>\nis equal to <code>imag(Y_ref)</code> if <code>frequencyDependent = false</code>.\nFrequency dependency is considered by <code>frequencyDependent = true</code>, distinguishing two cases:\n</p>\n\n<dl>\n<dt>(a) <code>imag(Y_ref) &gt; 0</code>: capacitive case</dt>\n<dd>The actual susceptance <code>B_actual</code> is proportional to <code>f/f_ref</code></dd>\n<dt>(b) <code>imag(Y_ref) &lt; 0</code>: inductive case</dt>\n<dd>The actual susceptance <code>B_actual</code> is proportional to <code>f_ref/f</code></dd>\n</dl>\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.Impedance\">Impedance</a>,\n<a href=\"modelica://Modelica.Electrical.QuasiStationary.SinglePhase.Basic.VariableResistor\">Variable resistor</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 Admittance;