21 bool keep_last_solution) {
26 for (
auto comp :
mSystem.mComponents) {
27 if (std::shared_ptr<CPS::SP::Ph1::Load> load =
28 std::dynamic_pointer_cast<CPS::SP::Ph1::Load>(comp)) {
29 if (load->use_profile) {
39 if (!keep_last_solution) {
40 sol_V(pq->matrixNodeIndex()) = 1.0;
41 sol_D(pq->matrixNodeIndex()) = 0.0;
43 sol_V[pq->matrixNodeIndex()],
sol_D[pq->matrixNodeIndex()]);
45 for (
auto comp :
mSystem.mComponentsAtNode[pq]) {
46 if (std::shared_ptr<CPS::SP::Ph1::Load> load =
47 std::dynamic_pointer_cast<CPS::SP::Ph1::Load>(comp)) {
48 sol_P(pq->matrixNodeIndex()) -=
49 load->attributeTyped<CPS::Real>(
"P_pu")->get();
50 sol_Q(pq->matrixNodeIndex()) -=
51 load->attributeTyped<CPS::Real>(
"Q_pu")->get();
52 }
else if (std::shared_ptr<CPS::SP::Ph1::SolidStateTransformer> sst =
53 std::dynamic_pointer_cast<
55 sol_P(pq->matrixNodeIndex()) -= sst->getNodalInjection(pq).real();
56 sol_Q(pq->matrixNodeIndex()) -= sst->getNodalInjection(pq).imag();
57 }
else if (std::shared_ptr<CPS::SP::Ph1::AvVoltageSourceInverterDQ> vsi =
58 std::dynamic_pointer_cast<
61 sol_P(pq->matrixNodeIndex()) +=
63 sol_Q(pq->matrixNodeIndex()) +=
65 }
else if (std::shared_ptr<CPS::SP::Ph1::SynchronGenerator> gen =
66 std::dynamic_pointer_cast<CPS::SP::Ph1::SynchronGenerator>(
68 sol_P(pq->matrixNodeIndex()) +=
69 gen->attributeTyped<CPS::Real>(
"P_set_pu")->get();
70 sol_Q(pq->matrixNodeIndex()) +=
71 gen->attributeTyped<CPS::Real>(
"Q_set_pu")->get();
74 sol_P[pq->matrixNodeIndex()],
sol_Q[pq->matrixNodeIndex()]);
79 if (!keep_last_solution) {
80 sol_Q(pv->matrixNodeIndex()) = 0;
81 sol_D(pv->matrixNodeIndex()) = 0;
83 for (
auto comp :
mSystem.mComponentsAtNode[pv]) {
84 if (std::shared_ptr<CPS::SP::Ph1::SynchronGenerator> gen =
85 std::dynamic_pointer_cast<CPS::SP::Ph1::SynchronGenerator>(
87 sol_P(pv->matrixNodeIndex()) +=
88 gen->attributeTyped<CPS::Real>(
"P_set_pu")->get();
89 sol_V(pv->matrixNodeIndex()) =
90 gen->attributeTyped<CPS::Real>(
"V_set_pu")->get();
91 sol_Q(pv->matrixNodeIndex()) +=
92 gen->attributeTyped<CPS::Real>(
"Q_set_pu")->get();
93 }
else if (std::shared_ptr<CPS::SP::Ph1::Load> load =
94 std::dynamic_pointer_cast<CPS::SP::Ph1::Load>(comp)) {
95 sol_P(pv->matrixNodeIndex()) -=
96 load->attributeTyped<CPS::Real>(
"P_pu")->get();
97 sol_Q(pv->matrixNodeIndex()) -=
98 load->attributeTyped<CPS::Real>(
"Q_pu")->get();
99 }
else if (std::shared_ptr<CPS::SP::Ph1::AvVoltageSourceInverterDQ> vsi =
100 std::dynamic_pointer_cast<
102 sol_P(pv->matrixNodeIndex()) +=
104 }
else if (std::shared_ptr<CPS::SP::Ph1::NetworkInjection> extnet =
105 std::dynamic_pointer_cast<CPS::SP::Ph1::NetworkInjection>(
107 sol_P(pv->matrixNodeIndex()) +=
108 extnet->attributeTyped<CPS::Real>(
"p_inj")->get() /
110 sol_Q(pv->matrixNodeIndex()) +=
111 extnet->attributeTyped<CPS::Real>(
"q_inj")->get() /
113 sol_V(pv->matrixNodeIndex()) =
114 extnet->attributeTyped<CPS::Real>(
"V_set_pu")->get();
117 sol_P[pv->matrixNodeIndex()],
sol_Q[pv->matrixNodeIndex()]);
119 sol_V[pv->matrixNodeIndex()],
sol_D[pv->matrixNodeIndex()]);
124 sol_P(vd->matrixNodeIndex()) = 0.0;
125 sol_Q(vd->matrixNodeIndex()) = 0.0;
126 sol_V(vd->matrixNodeIndex()) = 1.0;
127 sol_D(vd->matrixNodeIndex()) = 0.0;
130 for (
auto comp :
mSystem.mComponentsAtNode[vd]) {
131 if (std::shared_ptr<CPS::SP::Ph1::NetworkInjection> extnet =
132 std::dynamic_pointer_cast<CPS::SP::Ph1::NetworkInjection>(comp)) {
133 sol_V(vd->matrixNodeIndex()) =
134 extnet->attributeTyped<CPS::Real>(
"V_set_pu")->get();
135 sol_P(vd->matrixNodeIndex()) +=
136 extnet->attributeTyped<CPS::Real>(
"p_inj")->get() /
138 sol_Q(vd->matrixNodeIndex()) +=
139 extnet->attributeTyped<CPS::Real>(
"q_inj")->get() /
144 else if (std::shared_ptr<CPS::SP::Ph1::Load> load =
145 std::dynamic_pointer_cast<CPS::SP::Ph1::Load>(comp)) {
146 sol_P(vd->matrixNodeIndex()) -=
147 load->attributeTyped<CPS::Real>(
"P_pu")->get();
148 sol_Q(vd->matrixNodeIndex()) -=
149 load->attributeTyped<CPS::Real>(
"Q_pu")->get();
153 else if (std::shared_ptr<CPS::SP::Ph1::SynchronGenerator> gen =
154 std::dynamic_pointer_cast<CPS::SP::Ph1::SynchronGenerator>(
156 sol_P(vd->matrixNodeIndex()) +=
157 gen->attributeTyped<CPS::Real>(
"P_set_pu")->get();
158 sol_Q(vd->matrixNodeIndex()) +=
159 gen->attributeTyped<CPS::Real>(
"Q_set_pu")->get();
166 if (gen->node(0)->matrixNodeIndex() == vd->matrixNodeIndex())
167 sol_V(vd->matrixNodeIndex()) =
168 gen->attributeTyped<CPS::Real>(
"V_set_pu")->get();
173 sol_P[vd->matrixNodeIndex()],
sol_Q[vd->matrixNodeIndex()]);
175 sol_V[vd->matrixNodeIndex()],
sol_D[vd->matrixNodeIndex()]);
184 SPDLOG_LOGGER_INFO(
mSLog,
"#### Initial solution: ");
185 SPDLOG_LOGGER_INFO(
mSLog,
"P\t\tQ\t\tV\t\tD");
186 for (UInt i = 0; i <
mSystem.mNodes.size(); ++i) {
434 auto node_idx = topoNode->matrixNodeIndex();
437 CPS::Complex I(0.0, 0.0);
438 for (UInt j = 0; j <
mSystem.mNodes.size(); ++j)
440 CPS::Complex S =
sol_Vcx(node_idx) * conj(I);
443 for (
auto comp :
mSystem.mComponentsAtNode[topoNode])
444 if (
auto loadPtr = std::dynamic_pointer_cast<CPS::SP::Ph1::Load>(comp))
445 S += Complex(**(loadPtr->mActivePowerPerUnit),
446 **(loadPtr->mReactivePowerPerUnit));
449 for (
auto comp :
mSystem.mComponentsAtNode[topoNode]) {
451 std::dynamic_pointer_cast<CPS::SP::Ph1::NetworkInjection>(comp)) {
456 std::dynamic_pointer_cast<CPS::SP::Ph1::SynchronGenerator>(
465 CPS::Real V =
sol_V.coeff(node_idx);
466 for (
auto comp :
mSystem.mComponentsAtNode[topoNode])
467 if (
auto shuntPtr = std::dynamic_pointer_cast<CPS::SP::Ph1::Shunt>(comp))
469 S += std::pow(V, 2) * Complex(-**(shuntPtr->mConductancePerUnit),
470 **(shuntPtr->mSusceptancePerUnit));
473 sol_P(node_idx) = S.real();
474 sol_Q(node_idx) = S.imag();