예제 #1
0
import numpy as np
import pandas as pd
import scipy.sparse as sp
from typing import List

from GridCal.Engine.basic_structures import Logger
import GridCal.Engine.Core.topology as tp
from GridCal.Engine.Core.multi_circuit import MultiCircuit
from GridCal.Engine.basic_structures import BranchImpedanceMode
from GridCal.Engine.Devices.enumerations import ConverterControlType, TransformerControlType
from GridCal.Engine.Simulations.PowerFlow.jacobian_based_power_flow import Jacobian
from GridCal.Engine.Core.common_functions import compile_types
from GridCal.Engine.Simulations.OPF.opf_results import OptimalPowerFlowResults
from GridCal.Engine.Simulations.sparse_solve import get_sparse_type

sparse_type = get_sparse_type()


class AcDcSnapshotCircuit:
    def __init__(
        self,
        nbus,
        nline,
        ndcline,
        ntr,
        nvsc,
        nload,
        ngen,
        nbatt,
        nshunt,
        nstagen,
예제 #2
0
def calc_connectivity(branch_active, bus_active, C_branch_bus_f,
                      C_branch_bus_t, apply_temperature, R_corrected, R, X, G,
                      B, branch_tolerance_mode: BranchImpedanceMode,
                      impedance_tolerance, tap_mod, tap_ang, tap_t, tap_f,
                      Ysh):
    """
    Build all the admittance related objects
    :param branch_active: array of branch active
    :param bus_active: array of bus active
    :param C_branch_bus_f: branch-bus from connectivity matrix
    :param C_branch_bus_t: branch-bus to connectivity matrix
    :param apply_temperature: apply temperature correction?
    :param R_corrected: Use the corrected resistance?
    :param R: array of resistance
    :param X: array of reactance
    :param G: array of conductance
    :param B: array of susceptance
    :param branch_tolerance_mode: branch tolerance mode (enum: BranchImpedanceMode)
    :param impedance_tolerance: impedance tolerance
    :param tap_mod: tap modules array
    :param tap_ang: tap angles array
    :param tap_t: virtual tap to array
    :param tap_f: virtual tap from array
    :param Ysh: shunt admittance injections
    :return: Ybus: Admittance matrix
             Yf: Admittance matrix of the from buses
             Yt: Admittance matrix of the to buses
             B1: Fast decoupled B' matrix
             B2: Fast decoupled B'' matrix
             Yseries: Admittance matrix of the series elements
             Ys: array of series admittances
             GBc: array of shunt conductances
             Cf: Branch-bus from connectivity matrix
             Ct: Branch-to from connectivity matrix
             C_bus_bus: Adjacency matrix
             C_branch_bus: branch-bus connectivity matrix
             islands: List of islands bus indices (each list element is a list of bus indices of the island)
    """

    sparse = get_sparse_type()

    # form the connectivity matrices with the states applied
    br_states_diag = sp.diags(branch_active)
    Cf = br_states_diag * C_branch_bus_f
    Ct = br_states_diag * C_branch_bus_t

    # use the specified of the temperature-corrected resistance
    if apply_temperature:
        R = R_corrected

    # modify the branches impedance with the lower, upper tolerance values
    if branch_tolerance_mode == BranchImpedanceMode.Lower:
        R *= (1 - impedance_tolerance / 100.0)
    elif branch_tolerance_mode == BranchImpedanceMode.Upper:
        R *= (1 + impedance_tolerance / 100.0)

    Ys = 1.0 / (R + 1.0j * X)
    GBc = G + 1.0j * B
    tap = tap_mod * np.exp(1.0j * tap_ang)

    # branch primitives in vector form for Ybus
    Ytt = (Ys + GBc / 2.0) / (tap_t * tap_t)
    Yff = (Ys + GBc / 2.0) / (tap_f * tap_f * tap * np.conj(tap))
    Yft = -Ys / (tap_f * tap_t * np.conj(tap))
    Ytf = -Ys / (tap_t * tap_f * tap)

    # form the admittance matrices
    Yf = sp.diags(Yff) * Cf + sp.diags(Yft) * Ct
    Yt = sp.diags(Ytf) * Cf + sp.diags(Ytt) * Ct
    Ybus = sparse(Cf.T * Yf + Ct.T * Yt + sp.diags(Ysh))

    # branch primitives in vector form, for Yseries
    Ytts = Ys
    Yffs = Ytts / (tap * np.conj(tap))
    Yfts = -Ys / np.conj(tap)
    Ytfs = -Ys / tap

    # form the admittance matrices of the series elements
    Yfs = sp.diags(Yffs) * Cf + sp.diags(Yfts) * Ct
    Yts = sp.diags(Ytfs) * Cf + sp.diags(Ytts) * Ct
    Yseries = sparse(Cf.T * Yfs + Ct.T * Yts)
    Gsh = GBc / 2.0
    Ysh += Cf.T * Gsh + Ct.T * Gsh

    # Form the matrices for fast decoupled
    b1 = 1.0 / (X + 1e-20)
    b1_tt = sp.diags(b1)
    B1f = b1_tt * Cf - b1_tt * Ct
    B1t = -b1_tt * Cf + b1_tt * Ct
    B1 = sparse(Cf.T * B1f + Ct.T * B1t)

    b2 = b1 + B
    b2_ff = -(b2 / (tap * np.conj(tap))).real
    b2_ft = -(b1 / np.conj(tap)).real
    b2_tf = -(b1 / tap).real
    b2_tt = -b2
    B2f = -sp.diags(b2_ff) * Cf + sp.diags(b2_ft) * Ct
    B2t = sp.diags(b2_tf) * Cf + -sp.diags(b2_tt) * Ct
    B2 = sparse(Cf.T * B2f + Ct.T * B2t)

    ################################################################################################################
    # Bus connectivity
    ################################################################################################################
    # branch - bus connectivity
    C_branch_bus = Cf + Ct

    # Connectivity node - Connectivity node connectivity matrix
    bus_states_diag = sp.diags(bus_active)
    C_bus_bus = bus_states_diag * (C_branch_bus.T * C_branch_bus)

    return Ybus, Yf, Yt, B1, B2, Yseries, Ys, GBc, Cf, Ct, C_bus_bus, C_branch_bus