VariableAdmittance

model VariableAdmittance "Single phase variable admittance"
    import Modelica.ComplexMath.real;
    import Modelica.ComplexMath.imag;
    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.ComplexBlocks.Interfaces.ComplexInput Y_ref "Variable complex admittance"
        annotation (Placement(
            transformation(
                origin = {0, 120},
                extent = {
                    {-20, -20}, 
                    {20, 20}},
                rotation = 270),
            iconTransformation(
                extent = {
                    {-20, -20}, 
                    {20, 20}},
                rotation = 270,
                origin = {0, 120})));
    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";
    Modelica.SIunits.Conductance G_ref = real(Y_ref) "Resistive component of conductance";
    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 (
        defaultComponentName = "admittance",
        Icon(
            coordinateSystem(
                preserveAspectRatio = false,
                extent = {
                    {-100, -100}, 
                    {100, 100}}),
            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 complex voltage <code><u>v</u></code> with the\ncomplex current <code><u>i</u></code> by <code><u>v</u>*<u>Y</u> = <u>i</u></code>.\nThe admittance <code>Y_ref = G_ref + j*B_ref</code> is given as complex input signal, representing the\nresistive and reactive component of the input admittance. 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>.\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>Note</h4>\n<p>\nA zero crossing of the real or imaginary part of the admittance signal <code>Y_ref</code> could cause\nsingularities 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.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</p>\n</html>"));
end VariableAdmittance;