Based on GeneratorInit.m from MatDyn by Stijn Cole, developed at
        Katholieke Universiteit Leuven. See U{http://www.esat.kuleuven.be/
        electa/teaching/matdyn/} for more information.

        @rtype: tuple
        @return: Initial generator conditions.

def generatorInit(self, U0):
        """ Based on GeneratorInit.m from MatDyn by Stijn Cole, developed at
        Katholieke Universiteit Leuven. See U{http://www.esat.kuleuven.be/
        electa/teaching/matdyn/} for more information.

        @rtype: tuple
        @return: Initial generator conditions.
        """
        j = 0 + 1j
        generators = self.dyn_generators

        Efd0 = zeros(len(generators))
        Xgen0 = zeros((len(generators), 4))

        typ1 = [g._i for g in generators if g.model == CLASSICAL]
        typ2 = [g._i for g in generators if g.model == FOURTH_ORDER]

        # Generator type 1: classical model
        x_tr = array([g.x_tr for g in generators])

        omega0 = ones(len(typ1)) * 2 * pi * self.freq

        # Initial machine armature currents.
        Sg = array([g.p + j * g.q for g in generators])
        Ia0 = conj(Sg[typ1]) / conj(U0) / self.base_mva

        # Initial Steady-state internal EMF.
        Eq_tr0 = U0[typ1] + j * x_tr * Ia0
        delta0 = angle(Eq_tr0)
        Eq_tr0 = abs(Eq_tr0)

        Xgen0[typ1, :] = c_[delta0, omega0, Eq_tr0]

        # Generator type 2: 4th order model
        xd = array([g.xd for g in generators])
        xq = array([g.xq for g in generators])
        xd_tr = array([g.xd_tr for g in generators])
        xq_tr = array([g.xq_tr for g in generators])

        omega0 = ones(len(typ2)) * 2 * pi * self.freq

        # Initial machine armature currents.
        Ia0 = conj(Sg[typ2]) / conj(U0[typ2]) / self.base_mva
        phi0 = angle(Ia0)

        # Initial Steady-state internal EMF.
        Eq0 = U0[typ2] + j * xq * Ia0
        delta0 = angle(Eq0)

        # Machine currents in dq frame.
        Id0 = -abs(Ia0) * sin(delta0 - phi0)
        Iq0 =  abs(Ia0) * cos(delta0 - phi0)

        # Field voltage.
        Efd0[typ2] = abs(Eq0) - (xd - xq) * Id0

        # Initial Transient internal EMF.
        Eq_tr0 = Efd0[typ2] + (xd - xd_tr) * Id0
        Ed_tr0 = -(xq - xq_tr) * Iq0

        Xgen0[typ2, :] = c_[delta0, omega0, Eq_tr0, Ed_tr0]

        # Generator type 3:

        # Generator type 4:

        return Efd0, Xgen0