|
Harmony
HARMONic stabilitY assessment of PE-penetrated power systems
|
Combined AC/DC optimal power flow solver. More...
#include <Powerflow.h>
Public Member Functions | |
| PowerFlow () | |
| Default constructor. | |
| std::unordered_map< std::string, Eigen::MatrixXd > | create_ac (const std::string &case_name) |
| Loads AC grid case data from bundled CSV files. | |
| std::unordered_map< std::string, Eigen::MatrixXd > | create_dc (const std::string &case_name) |
| Loads DC grid case data from bundled CSV files. | |
| void | addBusAC (std::vector< std::vector< std::string > > &dict_ac, Bus *bus, std::map< std::string, double > &global_params, bool print_info=false) |
| Appends an AC bus row to the OPF bus dictionary. | |
| void | addBusDC (std::vector< std::vector< std::string > > &dict_dc, Bus *bus, std::map< std::string, double > &global_params, bool print_info=false) |
| Appends a DC bus row to the OPF bus dictionary. | |
| void | make_BranchAC (Element *element, std::map< std::string, double > &global_params, bool print_info=false) |
| Adds an AC branch (line/transformer) entry to the OPF data. | |
| void | make_BranchDC (Element *element, std::map< std::string, double > &global_params, bool print_info=false) |
| Adds a DC branch entry to the OPF data. | |
| void | make_Generator (Element *element, std::map< std::string, double > &global_params, bool print_info=false) |
| Adds a synchronous generator entry to the OPF data. | |
| void | make_RES (Element *element, std::map< std::string, double > &global_params, bool print_info=false) |
| Adds a renewable energy source (RES) entry to the OPF data. | |
| void | make_Load (Element *element, std::map< std::string, double > &global_params, bool print_info=false) |
| Adds a load entry to the OPF data. | |
| void | make_Converter (Element *element, std::map< std::string, double > &global_params, bool print_info=false) |
| Adds a VSC/MMC converter entry to the OPF data. | |
| void | make_OPF (Network *net, std::map< std::string, double > &global_params, bool vscControl=true, bool writeTxt=false, bool plotResult=false, bool print_info=false, bool include_dc=true) |
| Builds OPF data structures from a Harmony network and runs the solver. | |
| void | make_AC_OPF (Network *net, std::map< std::string, double > &global_params, bool writeTxt=false, bool plotResult=false, bool print_info=false) |
| Builds AC-only OPF data from a Harmony network and runs the solver. | |
| void | load_params_ac (const std::string &acgrid_name, const std::unordered_map< std::string, Eigen::MatrixXd > &dataOPF) |
| Applies solved AC OPF parameters back to a named AC grid. | |
| void | load_params_dc (const std::string &dcgrid_name, const std::unordered_map< std::string, Eigen::MatrixXd > &dataOPF) |
| Applies solved DC OPF parameters back to a named DC grid. | |
| void | solve_opf (const std::string &dc_name, const std::string &ac_name, std::unordered_map< std::string, Eigen::MatrixXd > *dataOPF, bool vscControl, bool writeTxt, bool plotResult, bool print_info) |
| Runs the combined AC/DC OPF optimization. | |
| const auto & | getNetData () const |
| Returns the nested OPF result dictionary (read-only). | |
| auto & | getNetData () |
| Returns the nested OPF result dictionary (mutable). | |
| DCBusResult | getDCBusResult (const std::string &dcBusName, const std::map< std::string, double > &global_params) const |
| Retrieves solved DC bus quantities by name. | |
| bool | opfSolved () const |
| True when the most recent solve_opf completed with a usable solution. | |
Combined AC/DC optimal power flow solver.
Manages case-data loading, network parameter extraction from Harmony elements, OPF optimization, result storage, and optional visualization.
|
inline |
Default constructor.
| void PowerFlow::addBusAC | ( | std::vector< std::vector< std::string > > & | dict_ac, |
| Bus * | bus, | ||
| std::map< std::string, double > & | global_params, | ||
| bool | print_info = false |
||
| ) |
Appends an AC bus row to the OPF bus dictionary.
Add an AC bus entry to the system data table.
| dict_ac | AC bus table being assembled. |
| bus | Harmony bus object. |
| global_params | Shared network parameters (base MVA, etc.). |
| print_info | If true, prints diagnostic information. |
Creates a new AC bus in data["busAC"], initializes default parameters, and updates the bus dictionary dict_ac and mapping busName2Id_.
| dict_ac | AC bus dictionary. |
| bus | Pointer to the Bus object. |
| global_params | Global parameters. |
| print_info | If true, print formatted bus data. |
References Bus::computePowerFlowAC(), and Bus::getBusName().
Referenced by make_OPF().
| void PowerFlow::addBusDC | ( | std::vector< std::vector< std::string > > & | dict_dc, |
| Bus * | bus, | ||
| std::map< std::string, double > & | global_params, | ||
| bool | print_info = false |
||
| ) |
Appends a DC bus row to the OPF bus dictionary.
Add a DC bus entry to the system data table.
| dict_dc | DC bus table being assembled. |
| bus | Harmony bus object. |
| global_params | Shared network parameters. |
| print_info | If true, prints diagnostic information. |
Creates and initializes a new DC bus in data["busDC"] with default parameters, The function also updates the DC bus dictionary dict_dc and mapping busName2Id_.
| dict_dc | DC bus dictionary. |
| bus | Pointer to the Bus object. |
| global_params | Global parameters. |
| print_info | If true, print formatted DC bus data. |
References Bus::computePowerFlowDC(), and Bus::getBusName().
Referenced by make_OPF().
| std::unordered_map< std::string, Eigen::MatrixXd > PowerFlow::create_ac | ( | const std::string & | case_name | ) |
Loads AC grid case data from bundled CSV files.
| case_name | Case identifier (e.g. "case57"). |
Referenced by load_params_ac().
| std::unordered_map< std::string, Eigen::MatrixXd > PowerFlow::create_dc | ( | const std::string & | case_name | ) |
Loads DC grid case data from bundled CSV files.
| case_name | Case identifier. |
Referenced by load_params_dc().
| DCBusResult PowerFlow::getDCBusResult | ( | const std::string & | dcBusName, |
| const std::map< std::string, double > & | global_params | ||
| ) | const |
Retrieves solved DC bus quantities by name.
| dcBusName | Name of the DC bus. |
| global_params | Shared network parameters (base values, polarity). |
References DCBusResult::busIndex, DCBusResult::busName, DCBusResult::pc, DCBusResult::pn, DCBusResult::ps, DCBusResult::qc, DCBusResult::qs, DCBusResult::thetac, DCBusResult::thetas, DCBusResult::vc, DCBusResult::vn, and DCBusResult::vs.
|
inline |
Returns the nested OPF result dictionary (mutable).
|
inline |
Returns the nested OPF result dictionary (read-only).
| void PowerFlow::load_params_ac | ( | const std::string & | acgrid_name, |
| const std::unordered_map< std::string, Eigen::MatrixXd > & | dataOPF | ||
| ) |
Applies solved AC OPF parameters back to a named AC grid.
========================================== debug end
| acgrid_name | Name of the AC sub-grid. |
| dataOPF | Solved OPF data matrices. |
Load and preprocess AC network parameters for OPF formulation.
This function loads AC-side network data either from a predefined AC test case or from an externally constructed OPF data map. The loaded data include AC bus, branch, generator, generator cost, and renewable energy source (RES) information.
After loading the data, the function identifies the number of AC grids based on the grid identifier stored in the bus data. It then partitions the full AC network dataset into individual AC subsystems and initializes the corresponding member variables used by the OPF model.
For each AC grid, the function extracts local buses, branches, generators, generation costs, RES units, active/reactive loads, branch terminal indices, reference bus information, and bus-index mapping. It also builds the AC bus admittance matrix and stores its real and imaginary parts for later use in the OPF constraints.
| acgrid_name | Name of the predefined AC grid case to be loaded when dataOPF is empty. |
| dataOPF | Optional OPF input data map. If non-empty, AC data are loaded directly from this map instead of external files. |
busAC and branchAC stores the AC grid identifier, that column 21 of genAC stores the generator grid identifier, and that column 11 of resAC stores the RES grid identifier.baseMVA_ac. References create_ac().
Referenced by solve_opf().
| void PowerFlow::load_params_dc | ( | const std::string & | dcgrid_name, |
| const std::unordered_map< std::string, Eigen::MatrixXd > & | dataOPF | ||
| ) |
Applies solved DC OPF parameters back to a named DC grid.
Load and preprocess DC network parameters for OPF formulation.
| dcgrid_name | Name of the DC sub-grid. |
| dataOPF | Solved OPF data matrices. |
This function loads the DC-side network data either from a predefined DC test case or from an externally constructed OPF data map. The loaded data include DC buses, DC branches, and converter information.
After loading the data, the function initializes the fundamental network dimensions and extracts key converter parameters, including transformer impedance, converter impedance, filter susceptance, and converter loss coefficients. It also constructs the DC bus admittance matrix and computes the corresponding conductance matrix used in the OPF formulation.
Furthermore, the function determines the operating direction of each converter (rectifier or inverter) according to its active power injection and selects the corresponding converter loss coefficients. Finally, all converter loss parameters are normalized into the per-unit system.
| dcgrid_name | Name of the predefined DC grid case to be loaded when dataOPF is empty. |
| dataOPF | Optional OPF input data map. If dcgrid_name is empty, the DC data are loaded directly from this map. |
convState_dc) is determined from the sign of the active power injection (P_g), where a non-negative value denotes rectifier operation and a negative value denotes inverter operation.aloss_dc, bloss_dc, and closs_dc) are converted into the per-unit system using the system base power and converter base voltage. debug
References absoluteSparseMatrix(), and create_dc().
Referenced by solve_opf().
| void PowerFlow::make_AC_OPF | ( | Network * | net, |
| std::map< std::string, double > & | global_params, | ||
| bool | writeTxt = false, |
||
| bool | plotResult = false, |
||
| bool | print_info = false |
||
| ) |
Builds AC-only OPF data from a Harmony network and runs the solver.
Same as make_OPF with include_dc=false; DC buses, branches, and converters are excluded from the optimization (hybrid elements in the network are ignored).
References make_OPF().
| void PowerFlow::make_BranchAC | ( | Element * | element, |
| std::map< std::string, double > & | global_params, | ||
| bool | print_info = false |
||
| ) |
Adds an AC branch (line/transformer) entry to the OPF data.
Add an AC branch entry to the system data table.
| element | Branch element (Line, Transformer, etc.). |
| global_params | Shared network parameters. |
| print_info | If true, prints diagnostic information. |
Creates and initializes one new AC branch row in data["branchAC"] with default values, then fills branch electrical parameters by calling element->computePowerFlow(...). The function identifies the from-bus and to-bus IDs using busName2Id_ based on the two terminal buses returned by element->getBuses().
If print_info is true, the function prints the formatted data["branchAC"] table.
| element | Pointer to the branch element object (should connect exactly two buses). |
| global_params | Global parameters used in power flow calculations (e.g., baseMVA, baseKV). |
| print_info | If true, print the formatted AC branch data table. |
| std::runtime_error | If the element is not connected to exactly two buses. |
References Element::computePowerFlow(), Element::getBuses(), and Element::getElementSymbol().
Referenced by make_OPF().
| void PowerFlow::make_BranchDC | ( | Element * | element, |
| std::map< std::string, double > & | global_params, | ||
| bool | print_info = false |
||
| ) |
Adds a DC branch entry to the OPF data.
Add a DC branch entry to the system data table.
| element | DC branch element. |
| global_params | Shared network parameters. |
| print_info | If true, prints diagnostic information. |
Creates and initializes one new DC branch row in data["branchDC"] with default values, then computes the branch electrical parameters by calling element->computePowerFlow(...).
The function assumes that the DC branch element connects exactly two DC buses. The from-bus and to-bus indices are obtained via busName2Id_ using the bus names returned by element->getBuses().
If print_info is enabled, the formatted DC branch data table is printed to stdout.
| element | Pointer to the DC branch element object (must connect exactly two DC buses). |
| global_params | Global parameters used in DC power flow calculations. |
| print_info | If true, print the formatted DC branch data table. |
| std::runtime_error | If the branch element is not connected to exactly two buses. |
References Element::computePowerFlow(), Element::getBuses(), and Element::getElementSymbol().
Referenced by make_OPF().
| void PowerFlow::make_Converter | ( | Element * | element, |
| std::map< std::string, double > & | global_params, | ||
| bool | print_info = false |
||
| ) |
Adds a VSC/MMC converter entry to the OPF data.
Add a converter entry to the system data table.
| element | Converter element. |
| global_params | Shared network parameters. |
| print_info | If true, prints diagnostic information. |
Creates and initializes one new converter row in data["conv"] with default parameters, then updates converter electrical parameters by calling element->computePowerFlow(...).
The function requires the converter element to connect exactly two buses: one AC bus and one DC bus. It identifies the AC/DC bus by Bus::getPinNumber() (pin = 3 treated as AC bus in current logic), maps bus names to indices using busName2Id_, and writes busac_i / busdc_i into the converter row.
The converter element pointer is also stored in conv_point for later use. If print_info is enabled, the function prints the formatted data["conv"] table.
| element | Pointer to the converter element object (must connect exactly one AC bus and one DC bus). |
| global_params | Global parameters used in converter power flow calculations (e.g., baseKV, baseMVA). |
| print_info | If true, print the formatted converter data table. |
| std::runtime_error | If the converter is not connected to exactly two buses. |
| std::runtime_error | If the two buses cannot be identified as one AC bus and one DC bus. |
References Element::computePowerFlow(), Element::getBuses(), and Bus::getBusName().
Referenced by make_OPF().
| void PowerFlow::make_Generator | ( | Element * | element, |
| std::map< std::string, double > & | global_params, | ||
| bool | print_info = false |
||
| ) |
Adds a synchronous generator entry to the OPF data.
Add a generator entry and its cost entry to the system data tables.
| element | Generator element. |
| global_params | Shared network parameters. |
| print_info | If true, prints diagnostic information. |
Creates and initializes one generator row in data["genAC"] and one cost row in data["genCostAC"], then updates parameters using element->computePowerFlow(...) and OPF data from element->getOPFInfo().
The generator is assumed to be connected to one AC bus and ground. The non-ground bus is mapped to an internal bus index via busName2Id_. Bus voltage limits and bus type (PV or SLACK) may be updated according to OPF information.
| element | Pointer to the generator element object. |
| global_params | Global parameters used in power flow and OPF data construction. |
| print_info | If true, print the formatted generator and cost tables. |
| std::runtime_error | If the generator is not properly connected to a bus. |
| std::invalid_argument | If generator power limits are inconsistent. |
References Element::computePowerFlow(), Element::getBuses(), Bus::getBusName(), Element::getElementSymbol(), and Element::getOPFInfo().
Referenced by make_OPF().
| void PowerFlow::make_Load | ( | Element * | element, |
| std::map< std::string, double > & | global_params, | ||
| bool | print_info = false |
||
| ) |
Adds a load entry to the OPF data.
Register an AC load by updating the corresponding busAC entry.
| element | Load element. |
| global_params | Shared network parameters. |
| print_info | If true, prints diagnostic information. |
Identifies the non-ground bus connected to the load element and updates its load parameters in the busAC table via power flow computation.
| element | Pointer to the load element. |
| global_params | Global parameters used in power flow calculation. |
| print_info | If true, print the updated busAC table. |
| std::runtime_error | If no valid AC bus is connected or the bus entry is not found. |
References Element::computePowerFlow(), Element::getBuses(), and Bus::getBusName().
Referenced by make_OPF().
| void PowerFlow::make_OPF | ( | Network * | net, |
| std::map< std::string, double > & | global_params, | ||
| bool | vscControl = true, |
||
| bool | writeTxt = false, |
||
| bool | plotResult = false, |
||
| bool | print_info = false, |
||
| bool | include_dc = true |
||
| ) |
Builds OPF data structures from a Harmony network and runs the solver.
| net | Network to optimize. |
| global_params | Shared network parameters. |
| vscControl | Enable VSC droop/control constraints (default true). |
| writeTxt | Write text output files (default false). |
| plotResult | Open OPF visualization (default false). |
| print_info | Print diagnostic information (default false). |
References addBusAC(), addBusDC(), ensureRESGen(), extendBranchAC(), extendBusAC(), extendGenAC(), Network::getBuses(), Bus::getBusName(), Network::getElements(), Element::getElementSymbol(), Bus::getPinNumber(), make_BranchAC(), make_BranchDC(), make_Converter(), make_Generator(), make_Load(), make_RES(), map2dense(), reNumberBusAC(), and solve_opf().
Referenced by example_OPF_double_area(), example_OPF_PV(), example_OPF_single_area(), example_OPF_WT(), example_point2point_case(), example_stability_check(), and make_AC_OPF().
| void PowerFlow::make_RES | ( | Element * | element, |
| std::map< std::string, double > & | global_params, | ||
| bool | print_info = false |
||
| ) |
Adds a renewable energy source (RES) entry to the OPF data.
Add a renewable energy source entry to the system data table.
| element | RES element. |
| global_params | Shared network parameters. |
| print_info | If true, prints diagnostic information. |
This function registers a renewable energy source (RES), such as a PV plant or a type-3/type-4 wind turbine, in data["resAC"]. The RES is assumed to be connected to one AC bus and ground. The non-ground bus is identified and mapped to its internal bus index through busName2Id_.
The function first obtains the grid ID from the corresponding busAC entry, then determines the rated active power of the RES according to its specific component type. If multiple RES units are connected to the same bus, their maximum active power capacities are aggregated into a single resAC row. Otherwise, a new RES row is created with default cost and capacity parameters.
| element | Pointer to the RES element object. |
| global_params | Global parameters used in power flow and OPF data construction. |
| print_info | If true, print the formatted RES data table. |
| std::runtime_error | If the RES is not connected to any bus. |
| std::runtime_error | If the connected bus cannot be found in data["busAC"]. |
| std::runtime_error | If the RES type is not supported. |
References Element::getBuses(), Bus::getBusName(), and Element::getElementSymbol().
Referenced by make_OPF().
|
inline |
True when the most recent solve_opf completed with a usable solution.
| void PowerFlow::solve_opf | ( | const std::string & | dc_name, |
| const std::string & | ac_name, | ||
| std::unordered_map< std::string, Eigen::MatrixXd > * | dataOPF, | ||
| bool | vscControl, | ||
| bool | writeTxt, | ||
| bool | plotResult, | ||
| bool | print_info | ||
| ) |
Runs the combined AC/DC OPF optimization.
| dc_name | DC grid case name. |
| ac_name | AC grid case name. |
| dataOPF | Optional pointer to store/load case data; may be nullptr. |
| vscControl | Enable VSC control constraints. |
| writeTxt | Write text output files. |
| plotResult | Open OPF visualization. |
| print_info | Print diagnostic information. |
References OPFVisualData::baseMVA_ac, OPFVisualData::baseMW_dc, OPFVisualData::branch_dc, OPFVisualData::branch_entire_ac, OPFVisualData::bus_dc, OPFVisualData::bus_entire_ac, OPFVisualData::conv_dc, OPFVisualData::gen_entire_ac, j, load_params_ac(), load_params_dc(), OPFVisualData::nbuses_ac, OPFVisualData::nbuses_dc, OPFVisualData::nconvs_dc, OPFVisualData::ngens_ac, OPFVisualData::ngrids, OPF_OUT, OPFVisualData::pgen_ac_k, OPFVisualData::pij_ac_k, OPFVisualData::pij_dc_k, OPFVisualData::pol_dc, OPFVisualData::ps_dc_k, OPFVisualData::qgen_ac_k, OPFVisualData::qij_ac_k, OPFVisualData::qs_dc_k, viz_opf(), OPFVisualData::vn2_ac_k, and OPFVisualData::vn2_dc_k.
Referenced by example_OPF_ac(), example_OPF_csv(), example_OPF_csv_1(), and make_OPF().