|
| 1 | +// MicrogridNetwork.hpp |
| 2 | + |
| 3 | +#pragma once |
| 4 | + |
| 5 | +#include <cassert> |
| 6 | +#include <cmath> |
| 7 | +#include <cstddef> |
| 8 | +#include <vector> |
| 9 | + |
| 10 | +#include <GridKit/Model/PowerElectronics/Bus/MicrogridBus.hpp> |
| 11 | +#include <GridKit/Model/PowerElectronics/Bus/SignalNode.hpp> |
| 12 | +#include <GridKit/Model/PowerElectronics/DistributedGenerator/DistributedGenerator.hpp> |
| 13 | +#include <GridKit/Model/PowerElectronics/MicrogridBusDQ/MicrogridBusDQ.hpp> |
| 14 | +#include <GridKit/Model/PowerElectronics/MicrogridLine/MicrogridLine.hpp> |
| 15 | +#include <GridKit/Model/PowerElectronics/MicrogridLoad/MicrogridLoad.hpp> |
| 16 | +#include <GridKit/Model/PowerElectronics/SystemModelPowerElectronics.hpp> |
| 17 | + |
| 18 | +/* |
| 19 | + * Contains components and nodes that make up the scaled microgrid network. |
| 20 | + * |
| 21 | + * The network contains 2 * N_size IBRs and stores the physical components |
| 22 | + * that make up the scale microgrid. |
| 23 | + */ |
| 24 | +template <class ScalarT, typename IdxT> |
| 25 | +struct ScaleMicrogridNetwork |
| 26 | +{ |
| 27 | + |
| 28 | + using SignalNode = GridKit::PowerElectronics::SignalNode<ScalarT, IdxT>; |
| 29 | + using Bus = GridKit::PowerElectronics::MicrogridBus<ScalarT, IdxT>; |
| 30 | + using BusDQ = GridKit::MicrogridBusDQ<ScalarT, IdxT>; |
| 31 | + using DGGenerator = GridKit::DistributedGenerator<ScalarT, IdxT>; |
| 32 | + using Line = GridKit::MicrogridLine<ScalarT, IdxT>; |
| 33 | + using Load = GridKit::MicrogridLoad<ScalarT, IdxT>; |
| 34 | + using GenParams = GridKit::DistributedGeneratorParameters<ScalarT, IdxT>; |
| 35 | + |
| 36 | + size_t model_id_next; |
| 37 | + size_t N_size; |
| 38 | + SignalNode dg_signal; |
| 39 | + std::vector<Bus> buses; |
| 40 | + std::vector<BusDQ*> busesDQ; |
| 41 | + std::vector<DGGenerator*> generators; |
| 42 | + std::vector<Line*> lines; |
| 43 | + std::vector<Load*> loads; |
| 44 | + std::vector<GenParams> DGParam_list; |
| 45 | + |
| 46 | + ScaleMicrogridNetwork(size_t n_size) |
| 47 | + : model_id_next(0), |
| 48 | + N_size(n_size), |
| 49 | + buses(2 * n_size), |
| 50 | + busesDQ(2 * n_size, nullptr), |
| 51 | + generators(2 * n_size, nullptr), |
| 52 | + lines(2 * n_size - 1, nullptr), |
| 53 | + loads(2 * n_size, nullptr), |
| 54 | + DGParam_list(2 * n_size) |
| 55 | + { |
| 56 | + buildScaleMicrogridNetwork(); |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * @brief Construct all components of the scaled microgrid network. |
| 61 | + * |
| 62 | + * Builds a microgrid containing @c 2*N_size generators and buses connected |
| 63 | + * in a chain by transmission lines. Loads are connected to every other bus, |
| 64 | + * and a virtual DQ bus is associated with each physical bus. |
| 65 | + * |
| 66 | + * The first two generators use the reference generator parameter set, while |
| 67 | + * all remaining generators use the second parameter set. Line parameters |
| 68 | + * alternate along the network, and the first load uses a different parameter |
| 69 | + * set from the remaining loads. |
| 70 | + * |
| 71 | + * The created components are stored in this network and assigned unique model |
| 72 | + * identifiers using @c model_id_next. |
| 73 | + * |
| 74 | + * @pre @c N_size is greater than zero. |
| 75 | + * |
| 76 | + * @post The network contains @c 2*N_size generators and virtual DQ buses. |
| 77 | + * @post The network contains @c 2*N_size-1 transmission lines connecting |
| 78 | + * consecutive buses. |
| 79 | + * @post The network contains @c N_size loads connected to every other bus. |
| 80 | + * @post @c DGParam_list contains the parameters associated with each generator. |
| 81 | + * @post @c model_id_next is advanced for every component created. |
| 82 | + * |
| 83 | + * @note Components are dynamically allocated and their pointers are stored |
| 84 | + * in the corresponding component vectors. |
| 85 | + */ |
| 86 | + void buildScaleMicrogridNetwork() |
| 87 | + { |
| 88 | + assert(N_size > 0); |
| 89 | + // Every Bus has the same virtual resistance. This is due to numerical stability as mentioned in the paper. |
| 90 | + ScalarT RN = 1.0e4; |
| 91 | + |
| 92 | + // TODO: add this as parameters |
| 93 | + // DG Params Vector |
| 94 | + // All DGs have the same set of parameters except for the first two. |
| 95 | + GenParams DG_parms1; |
| 96 | + DG_parms1.wb_ = 2.0 * M_PI * 50.0; |
| 97 | + DG_parms1.wc_ = 31.41; |
| 98 | + DG_parms1.mp_ = 9.4e-5; |
| 99 | + DG_parms1.Vn_ = 380.0; |
| 100 | + DG_parms1.nq_ = 1.3e-3; |
| 101 | + DG_parms1.F_ = 0.75; |
| 102 | + DG_parms1.Kiv_ = 420.0; |
| 103 | + DG_parms1.Kpv_ = 0.1; |
| 104 | + DG_parms1.Kic_ = 2.0e4; |
| 105 | + DG_parms1.Kpc_ = 15.0; |
| 106 | + DG_parms1.Cf_ = 5.0e-5; |
| 107 | + DG_parms1.rLf_ = 0.1; |
| 108 | + DG_parms1.Lf_ = 1.35e-3; |
| 109 | + DG_parms1.rLc_ = 0.03; |
| 110 | + DG_parms1.Lc_ = 0.35e-3; |
| 111 | + |
| 112 | + GenParams DG_parms2; |
| 113 | + DG_parms2.wb_ = 2.0 * M_PI * 50.0; |
| 114 | + DG_parms2.wc_ = 31.41; |
| 115 | + DG_parms2.mp_ = 12.5e-5; |
| 116 | + DG_parms2.Vn_ = 380.0; |
| 117 | + DG_parms2.nq_ = 1.5e-3; |
| 118 | + DG_parms2.F_ = 0.75; |
| 119 | + DG_parms2.Kiv_ = 390.0; |
| 120 | + DG_parms2.Kpv_ = 0.05; |
| 121 | + DG_parms2.Kic_ = 16.0e3; |
| 122 | + DG_parms2.Kpc_ = 10.5; |
| 123 | + DG_parms2.Cf_ = 50.0e-6; |
| 124 | + DG_parms2.rLf_ = 0.1; |
| 125 | + DG_parms2.Lf_ = 1.35e-3; |
| 126 | + DG_parms2.rLc_ = 0.03; |
| 127 | + DG_parms2.Lc_ = 0.35e-3; |
| 128 | + |
| 129 | + DGParam_list.assign(2 * N_size, DG_parms2); |
| 130 | + |
| 131 | + // First two generators use parameters 1 |
| 132 | + if (DGParam_list.size() >= 1) |
| 133 | + { |
| 134 | + DGParam_list[0] = DG_parms1; |
| 135 | + } |
| 136 | + if (DGParam_list.size() >= 2) |
| 137 | + { |
| 138 | + DGParam_list[1] = DG_parms1; |
| 139 | + } |
| 140 | + |
| 141 | + // line vector params |
| 142 | + // Every odd line has the same parameters and every even line has the same parameters |
| 143 | + ScalarT rline1 = 0.23; |
| 144 | + ScalarT Lline1 = 0.1 / (2.0 * M_PI * 50.0); |
| 145 | + ScalarT rline2 = 0.35; |
| 146 | + ScalarT Lline2 = 0.58 / (2.0 * M_PI * 50.0); |
| 147 | + std::vector<ScalarT> rline_list(2 * N_size - 1, 0.0); |
| 148 | + std::vector<ScalarT> Lline_list(2 * N_size - 1, 0.0); |
| 149 | + for (IdxT i = 0; i < rline_list.size(); i++) |
| 150 | + { |
| 151 | + rline_list[i] = (i % 2) ? rline2 : rline1; |
| 152 | + Lline_list[i] = (i % 2) ? Lline2 : Lline1; |
| 153 | + } |
| 154 | + |
| 155 | + // load parms |
| 156 | + // Only the first load has the same paramaters. |
| 157 | + ScalarT rload1 = 3.0; |
| 158 | + ScalarT Lload1 = 2.0 / (2.0 * M_PI * 50.0); |
| 159 | + ScalarT rload2 = 2.0; |
| 160 | + ScalarT Lload2 = 1.0 / (2.0 * M_PI * 50.0); |
| 161 | + |
| 162 | + std::vector<ScalarT> rload_list(N_size, rload2); |
| 163 | + std::vector<ScalarT> Lload_list(N_size, Lload2); |
| 164 | + if (rload_list.size() >= 1) |
| 165 | + { |
| 166 | + rload_list[0] = rload1; |
| 167 | + Lload_list[0] = Lload1; |
| 168 | + } |
| 169 | + |
| 170 | + // Create the reference generator |
| 171 | + auto* dg_ref = new DGGenerator(model_id_next++, |
| 172 | + DGParam_list[0], |
| 173 | + true, |
| 174 | + &dg_signal, |
| 175 | + &buses[0]); |
| 176 | + |
| 177 | + generators[0] = dg_ref; |
| 178 | + |
| 179 | + // Create the remaining generators. |
| 180 | + for (IdxT i = 1; i < 2 * N_size; i++) |
| 181 | + { |
| 182 | + auto* dg = new DGGenerator(model_id_next++, |
| 183 | + DGParam_list[i], |
| 184 | + false, |
| 185 | + &dg_signal, |
| 186 | + &buses[i]); |
| 187 | + |
| 188 | + generators[i] = dg; |
| 189 | + } |
| 190 | + |
| 191 | + // Create transmission lines between consecutive buses. |
| 192 | + for (IdxT i = 0; i < 2 * N_size - 1; i++) |
| 193 | + { |
| 194 | + auto* line_model = new Line(model_id_next++, |
| 195 | + rline_list[i], |
| 196 | + Lline_list[i], |
| 197 | + &dg_signal, |
| 198 | + &buses[i], |
| 199 | + &buses[i + 1]); |
| 200 | + |
| 201 | + lines[i] = line_model; |
| 202 | + } |
| 203 | + |
| 204 | + // Create loads on every other bus. |
| 205 | + for (IdxT i = 0; i < N_size; i++) |
| 206 | + { |
| 207 | + auto* load_model = new Load(model_id_next++, |
| 208 | + rload_list[i], |
| 209 | + Lload_list[i], |
| 210 | + &dg_signal, |
| 211 | + &buses[2 * i]); |
| 212 | + |
| 213 | + loads[2 * i] = load_model; |
| 214 | + } |
| 215 | + |
| 216 | + // Create and Add all the microgrid Virtual DQ Buses |
| 217 | + for (IdxT i = 0; i < 2 * N_size; i++) |
| 218 | + { |
| 219 | + auto* virDQbus_model = new BusDQ(model_id_next++, |
| 220 | + RN, |
| 221 | + &buses[i]); |
| 222 | + |
| 223 | + busesDQ[i] = virDQbus_model; |
| 224 | + } |
| 225 | + } |
| 226 | +}; |
0 commit comments