Harmony
HARMONic stabilitY assessment of PE-penetrated power systems
Loading...
Searching...
No Matches
Powerflow_network_params.cpp File Reference

Implementation of PowerFlow network parameter assembly. More...

#include "Powerflow.h"
#include "../Helper_Functions/Helper_Functions.h"
#include "../../network.h"
#include "../../Bus.h"
#include "../../Include_components.h"
#include "../../Elements/Converter/MMC.h"
#include "../../Elements/RES/PV_plant.h"
#include "../../Elements/RES/WT_type_3.h"
#include "../../Elements/RES/WT_type_4.h"
#include <map>
#include <unordered_map>
#include <vector>
#include <iostream>
Include dependency graph for Powerflow_network_params.cpp:

Functions

static void reNumberBusAC (Eigen::MatrixXd &busAC, Eigen::MatrixXd &branchAC, Eigen::MatrixXd &genAC, Eigen::MatrixXd &gencostAC, Eigen::MatrixXd &convDC)
 Renumber AC buses to ensure consistent indexing across all components.
 
static void extendBusAC (std::map< std::string, std::map< std::string, std::map< std::string, double > > > &data, Network *net, std::map< std::string, double > &global_params)
 Extend AC bus data from the input map into the network structure.
 
static void extendBranchAC (std::map< std::string, std::map< std::string, std::map< std::string, double > > > &data, Network *net, std::map< std::string, double > &global_params)
 Extend the AC branch dataset by adding new lines that connect newly created buses or converter terminals.
 
static void extendGenAC (std::map< std::string, std::map< std::string, std::map< std::string, double > > > &data, Network *net, std::map< std::string, double > &global_params)
 Extend the AC generator dataset by adding generation units or converter-linked power sources associated with new buses.
 
static void ensureRESGen (std::map< std::string, std::map< std::string, std::map< std::string, double > > > &data)
 Ensure generator availability when only RES units exist.
 

Detailed Description

Implementation of PowerFlow network parameter assembly.

Function Documentation

◆ ensureRESGen()

static void ensureRESGen ( std::map< std::string, std::map< std::string, std::map< std::string, double > > > &  data)
static

Ensure generator availability when only RES units exist.

Ensure the existence of at least one generator for OPF formulation.

This function checks whether the AC generator dataset (data["genAC"]) is empty. If no generator exists but RES units are available (data["resAC"]), a virtual zero-output generator is automatically created at the RES- connected bus.

The virtual generator is introduced only to satisfy OPF formulation requirements (e.g., generator data structure, generation cost data structure, and reference bus assignment). The generated unit has zero active and reactive power limits and therefore does not participate in optimization dispatch.

Parameters
dataNested map containing parsed AC network data.

This function checks whether the AC generator dataset (data["genAC"]) is empty. If no generator exists but renewable energy source (RES) information is available in data["resAC"], a virtual zero-output generator is automatically created at the first RES-connected bus.

The virtual generator is introduced solely to satisfy the structural requirements of the OPF formulation, which assumes the existence of at least one generator and one reference (slack) bus. The generated unit has zero active and reactive power capability and zero generation cost, and therefore does not participate in the optimization dispatch.

The corresponding RES-connected bus is assigned as the slack bus (type = 3), and a matching zero-cost entry is added to data["genCostAC"].

Parameters
dataNested map containing AC network, generator, and RES data.
Exceptions
std::runtime_errorIf neither generators nor RES units exist in the network.
std::runtime_errorIf the RES-connected bus cannot be found in data["busAC"].

Referenced by PowerFlow::make_OPF().

◆ extendBranchAC()

static void extendBranchAC ( std::map< std::string, std::map< std::string, std::map< std::string, double > > > &  data,
Network net,
std::map< std::string, double > &  global_params 
)
static

Extend the AC branch dataset by adding new lines that connect newly created buses or converter terminals.

Extend the AC branch dataset by adding equivalent source impedance branches.

This function processes the hierarchical AC data map (data["branchAC"]) and extends the branch list based on network topology changes introduced by extendBusAC(). The function ensures proper connectivity between new and existing buses and may assign default line parameters (resistance, reactance, susceptance, rate limits).

Parameters
dataNested map containing parsed AC network data.
netPointer to the Network object to be extended.
global_paramsMap of global parameters for base values or scaling.

This function appends additional AC branches associated with AC_source elements. The required information, including the original bus index, the newly created internal bus index, the grid identifier, and the source impedance (Zsrc), is retrieved from data["acsrcMeta"], which is generated by extendBusAC().

For each AC_source, an equivalent branch is created between the original network bus and the newly added internal bus. The branch reactance is obtained by converting the source impedance into the per-unit system using ACZbase, while the branch resistance is assumed to be zero. Default thermal limits, tap ratio, phase shift, and operating status are also assigned.

The generated branches explicitly model the internal impedance of AC sources and are appended to data["branchAC"] for subsequent OPF formulation.

Parameters
dataNested map containing AC network data.
netPointer to the network object (currently reserved for interface consistency and future extensions).
global_paramsMap of global parameters used for per-unit conversion and branch initialization.

Referenced by PowerFlow::make_OPF().

◆ extendBusAC()

static void extendBusAC ( std::map< std::string, std::map< std::string, std::map< std::string, double > > > &  data,
Network net,
std::map< std::string, double > &  global_params 
)
static

Extend AC bus data from the input map into the network structure.

Extend the AC bus dataset by creating additional buses for AC sources.

This function parses AC bus-related parameters from the hierarchical data structure and appends or initializes corresponding bus elements within the network model net. Global parameters may be used to fill missing fields or apply scaling factors.

Parameters
dataNested map containing parsed AC data.
netPointer to the Network object to be extended.
global_paramsMap of global system parameters.

This function scans the network for AC_source elements and creates an additional internal AC bus for each detected source. The newly created bus represents the internal terminal of the voltage source, while the original bus remains as the external network connection point.

The function first determines the maximum existing bus index within each grid area and assigns a new local bus index accordingly. The newly created bus is initialized with default electrical parameters and inherits the grid information from the original bus.

In addition, metadata describing the relationship between the original bus and the newly created bus, together with the source impedance (Zsrc), is stored in data["acsrcMeta"]. This metadata is subsequently used by extendBranchAC() to create the equivalent source impedance branch and by extendGenAC() to relocate generators to the newly created buses.

Parameters
dataNested map containing AC network data.
netPointer to the network object.
global_paramsGlobal parameters used to initialize bus attributes (e.g., base voltage).

References Bus::getBusName(), Element::getConnections(), and Network::getElements().

Referenced by PowerFlow::make_OPF().

◆ extendGenAC()

static void extendGenAC ( std::map< std::string, std::map< std::string, std::map< std::string, double > > > &  data,
Network net,
std::map< std::string, double > &  global_params 
)
static

Extend the AC generator dataset by adding generation units or converter-linked power sources associated with new buses.

Relocate generators to the newly created internal AC source buses.

This function reads and augments the generator-related data (data["genAC"]) to include generation units associated with newly added AC buses. It ensures that generator attributes (e.g., active/reactive power limits, cost coefficients, grid ID) are properly initialized and consistent with the extended network topology.

Parameters
dataNested map containing parsed AC generation data.
netPointer to the Network object to be extended.
global_paramsMap of global parameters used for initialization.

This function updates the generator connection buses after the AC bus extension process. For each AC_source element, the original network bus is identified and matched with the corresponding newly created internal bus generated by extendBusAC().

The function then scans the generator dataset (data["genAC"]) and replaces the bus index of any generator connected to the original bus with the newly created bus index within the same grid. This effectively moves the generator behind the equivalent source impedance branch introduced by extendBranchAC(), resulting in a physically consistent network model for OPF analysis.

Parameters
dataNested map containing AC network data.
netPointer to the network object used to identify AC_source elements and their connections.
global_paramsMap of global parameters (currently unused, reserved for interface consistency and future extensions).

Referenced by PowerFlow::make_OPF().

◆ reNumberBusAC()

static void reNumberBusAC ( Eigen::MatrixXd &  busAC,
Eigen::MatrixXd &  branchAC,
Eigen::MatrixXd &  genAC,
Eigen::MatrixXd &  gencostAC,
Eigen::MatrixXd &  convDC 
)
static

Renumber AC buses to ensure consistent indexing across all components.

========================================== debug start

This function renumbers the AC bus indices so that the busAC, branchAC, genAC, gencostAC, and convDC matrices share consistent and continuous bus numbering for subsequent optimal power flow.

Parameters
busACMatrix of AC bus data.
branchACMatrix of AC branch data.
genACMatrix of AC generator data.
gencostACMatrix of generator cost data.
convDCMatrix of DC converter data associated with AC buses.

Renumber AC buses within each grid and update associated data tables.

This function renumbers the AC bus indices independently for each grid area so that the bus numbering becomes continuous and starts from one.

A mapping from the original bus indices to the new local indices is first constructed for every grid. The mapping is then applied consistently to all related data structures, including:

  • busAC (bus indices),
  • branchAC (from-bus and to-bus indices),
  • genAC (generator connection buses), and
  • convDC (AC-side converter connection buses).

This preprocessing step ensures that each AC subsystem has contiguous local bus numbering, which simplifies subsequent OPF model construction and matrix indexing operations.

Parameters
busACMatrix containing AC bus data.
branchACMatrix containing AC branch data.
genACMatrix containing AC generator data.
gencostACMatrix containing AC generator cost data (kept for interface consistency).
convDCMatrix containing converter data whose AC-side bus indices need to be updated.

Referenced by PowerFlow::make_OPF().