Exemplo n.º 1
0
def to_ppc(net, calculate_voltage_angles=False, trafo_model="t", r_switch=0,
           check_connectivity=True):
    """
     This function converts a pandapower net to a pypower case file.

    INPUT:

        **net** - The pandapower net.

    OUTPUT:

        **ppc** - The Pypower casefile for usage with pypower

    EXAMPLE:

        import pandapower.converter as pc

        import pandapower.networks as pn

        net = pn.case9()

        ppc = pc.pp2ppc(net)

    """

    # select elements in service
    net["_options"] = {}
    _add_ppc_options(net, calculate_voltage_angles=calculate_voltage_angles, 
                             trafo_model=trafo_model, check_connectivity=check_connectivity,
                             mode="pf", copy_constraints_to_ppc=True,
                             r_switch=r_switch, init="results", enforce_q_lims=True, recycle=None)
    #  do the conversion
    ppc, ppci = _pd2ppc(net)
    ppc['branch'] = ppc['branch'].real
    ppc.pop('internal')
    return ppc
Exemplo n.º 2
0
def to_ppc(net,
           calculate_voltage_angles=False,
           trafo_model="t",
           switch_rx_ratio=2,
           check_connectivity=True,
           voltage_depend_loads=True,
           init="results",
           mode=None):
    """
     This function converts a pandapower net to a pypower case file.

    INPUT:

        **net** - The pandapower net.

    OPTIONAL:

        **calculate_voltage_angles** (bool, False) - consider voltage angles in loadflow calculation

        If True, voltage angles of ext_grids and transformer shifts are considered in the
        loadflow calculation. Considering the voltage angles is only necessary in meshed
        networks that are usually found in higher networks.

        **trafo_model** (str, "t") - transformer equivalent circuit model
        pandapower provides two equivalent circuit models for the transformer:

            - "t" - transformer is modeled as equivalent with the T-model.
            - "pi" - transformer is modeled as equivalent PI-model. This is not recommended, since \
            it is less exact than the T-model. It is only recommended for validation with other \
            software that uses the pi-model.

        **switch_rx_ratio** (float, 2) - rx_ratio of bus-bus-switches. If impedance is zero, \
        buses connected by a closed bus-bus switch are fused to model an ideal bus. \
        Otherwise, they are modelled as branches with resistance defined as z_ohm column in \
        switch table and this parameter 

        **check_connectivity** (bool, True) - Perform an extra connectivity test after the
        conversion from pandapower to PYPOWER

            If True, an extra connectivity test based on SciPy Compressed Sparse Graph Routines is
            perfomed. If check finds unsupplied buses, they are set out of service in the ppc

        **voltage_depend_loads** (bool, True) - consideration of voltage-dependent loads. \
        If False, net.load.const_z_percent and net.load.const_i_percent are not considered, i.e. \
        net.load.p_mw and net.load.q_mvar are considered as constant-power loads.

        **init** (str, "results") - initialization method of the converter
        pandapower ppc converter supports two methods for initializing the converter:

            - "flat"- flat start with voltage of 1.0pu and angle of 0° at all PQ-buses and 0° for \
            PV buses as initial solution
            - "results" - voltage vector from net.res_bus is used as initial solution.

        **mode** (str, None) - mode of power flow calculation type ("pf" - power flow, "opf" - \
        optimal power flow or "sc" - short circuit). "mode" influences for instance whether opf \
        cost data will be converted or which slack bus voltage limits are respected. If "mode" \
        is None, cost data will be respected via mode="opf" if cost data are existing.

    OUTPUT:

        **ppc** - The Pypower casefile for usage with pypower

    EXAMPLE:

        import pandapower.converter as pc

        import pandapower.networks as pn

        net = pn.case9()

        ppc = pc.to_ppc(net)

    """
    if (not (net["poly_cost"].empty and net["pwl_cost"].empty)
            and mode is None) or mode == "opf":
        mode = "opf"
        _check_necessary_opf_parameters(net, logger)
    else:
        mode = "pf"

    # select elements in service
    net["_options"] = {}
    _add_ppc_options(net,
                     calculate_voltage_angles=calculate_voltage_angles,
                     trafo_model=trafo_model,
                     check_connectivity=check_connectivity,
                     mode=mode,
                     switch_rx_ratio=switch_rx_ratio,
                     init_vm_pu=init,
                     init_va_degree=init,
                     enforce_q_lims=True,
                     recycle=None,
                     voltage_depend_loads=voltage_depend_loads)
    #  do the conversion
    _, ppci = _pd2ppc(net)
    ppci['branch'] = ppci['branch'].real
    #    ppci.pop('internal')
    return ppci
Exemplo n.º 3
0
def to_mpc(net,
           filename=None,
           init="results",
           calculate_voltage_angles=False,
           trafo_model="t",
           mode="pf"):
    """
    This function converts a pandapower net to a matpower case files (.mat) version 2.
    Note: python is 0-based while Matlab is 1-based.

    INPUT:

        **net** - The pandapower net.

    OPTIONAL:

        **filename** (None) - File path + name of the mat file which will be created. If None the mpc will only be returned

        **init** (str, "results") - initialization method of the loadflow
        For the conversion to a mpc, the following options can be chosen:

            - "flat"- flat start with voltage of 1.0pu and angle of 0° at all buses as initial solution
            - "results" - voltage vector of last loadflow from net.res_bus is copied to the mpc

        **calculate_voltage_angles** (bool, False) - copy the voltage angles from pandapower to the mpc

            If True, voltage angles are copied from pandapower to the mpc. In some cases with
            large differences in voltage angles (for example in case of transformers with high
            voltage shift), the difference between starting and end angle value is very large.
            In this case, the loadflow might be slow or it might not converge at all. That is why
            the possibility of neglecting the voltage angles of transformers and ext_grids is
            provided to allow and/or accelarate convergence for networks where calculation of
            voltage angles is not necessary.

            The default value is False because pandapower was developed for distribution networks.
            Please be aware that this parameter has to be set to True in meshed network for correct
            results!

        **trafo_model** (str, "t")  - transformer equivalent circuit model
        pandapower provides two equivalent circuit models for the transformer:

            - "t" - transformer is modelled as equivalent with the T-model. This is consistent with PowerFactory and is also more accurate than the PI-model. We recommend using this transformer model.
            - "pi" - transformer is modelled as equivalent PI-model. This is consistent with Sincal, but the method is questionable since the transformer is physically T-shaped. We therefore recommend the use of the T-model.

    EXAMPLE:

        import pandapower.converter as pc

        import pandapower.networks as pn

        net = pn.case9()

        pc.to_mpc(net)

    """
    # convert to matpower
    net["converged"] = False

    if not init == "results":
        reset_results(net)

    # select elements in service (time consuming, so we do it once)
    _get_std_options(net, init, calculate_voltage_angles, trafo_model)
    net["_options"]["mode"] = mode
    if mode == "opf":
        net["_options"]["copy_constraints_to_ppc"] = True
    # convert pandapower net to ppc
    ppc, ppci = _pd2ppc(net)

    # convert ppc to mpc
    if mode == "opf":
        ppc["gencost"] = ppci["gencost"]

    mpc = _ppc_to_mpc(ppc)
    if filename is not None:
        # savemat
        savemat(filename, mpc)

    return mpc
Exemplo n.º 4
0
def to_ppc(net, calculate_voltage_angles=False, trafo_model="t", r_switch=0.0,
           check_connectivity=True, voltage_depend_loads=True, init="results"):

    """
     This function converts a pandapower net to a pypower case file.

    INPUT:

        **net** - The pandapower net.

    OPTIONAL:

        **calculate_voltage_angles** (bool, False) - consider voltage angles in loadflow calculation

        If True, voltage angles of ext_grids and transformer shifts are considered in the
        loadflow calculation. Considering the voltage angles is only necessary in meshed
        networks that are usually found in higher networks.

        **trafo_model** (str, "t") - transformer equivalent circuit model
        pandapower provides two equivalent circuit models for the transformer:

            - "t" - transformer is modeled as equivalent with the T-model.
            - "pi" - transformer is modeled as equivalent PI-model. This is not recommended, since \
            it is less exact than the T-model. It is only recommended for validation with other \
            software that uses the pi-model.

        **r_switch** (float, 0.0) - resistance of bus-bus-switches. If impedance is zero, buses
        connected by a closed bus-bus switch are fused to model an ideal bus. Otherwise, they are
        modelled as branches with resistance r_switch.

        **check_connectivity** (bool, True) - Perform an extra connectivity test after the
        conversion from pandapower to PYPOWER

            If True, an extra connectivity test based on SciPy Compressed Sparse Graph Routines is
            perfomed. If check finds unsupplied buses, they are set out of service in the ppc

        **voltage_depend_loads** (bool, True) - consideration of voltage-dependent loads. If False, net.load.const_z_percent and net.load.const_i_percent are not considered, i.e. net.load.p_kw and net.load.q_kvar are considered as constant-power loads.

        **init** (str, "results") - initialization method of the converter
        pandapower ppc converter supports two methods for initializing the converter:

            - "flat"- flat start with voltage of 1.0pu and angle of 0° at all PQ-buses and 0° for PV buses as initial solution
            - "results" - voltage vector from net.res_bus is used as initial solution.


    OUTPUT:

        **ppc** - The Pypower casefile for usage with pypower

    EXAMPLE:

        import pandapower.converter as pc

        import pandapower.networks as pn

        net = pn.case9()

        ppc = pc.to_ppc(net)

    """

    # select elements in service
    net["_options"] = {}
    _add_ppc_options(net, calculate_voltage_angles=calculate_voltage_angles,
                     trafo_model=trafo_model, check_connectivity=check_connectivity,
                     mode="pf", copy_constraints_to_ppc=True,
                     r_switch=r_switch, init=init, enforce_q_lims=True, recycle=None,
                     voltage_depend_loads=voltage_depend_loads)
    #  do the conversion
    ppc, _ = _pd2ppc(net)
    ppc['branch'] = ppc['branch'].real
    ppc.pop('internal')
    return ppc