DPsim
PFSolver.cpp
1 /* Copyright 2017-2021 Institute for Automation of Complex Power Systems,
2  * EONERC, RWTH Aachen University
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at https://mozilla.org/MPL/2.0/.
7  *********************************************************************************/
8 
9 #include <dpsim/PFSolver.h>
10 #include <dpsim/SequentialScheduler.h>
11 #include <iostream>
12 
13 using namespace DPsim;
14 using namespace CPS;
15 
16 PFSolver::PFSolver(CPS::String name, CPS::SystemTopology system,
17  CPS::Real timeStep, CPS::Logger::Level logLevel)
18  : Solver(name + "_PF", logLevel) {
19  mSystem = system;
20  mTimeStep = timeStep;
21 }
22 
24  SPDLOG_LOGGER_INFO(mSLog, "#### INITIALIZATION OF POWERFLOW SOLVER ");
25  for (auto comp : mSystem.mComponents) {
26  if (std::shared_ptr<CPS::SP::Ph1::SynchronGenerator> gen =
27  std::dynamic_pointer_cast<CPS::SP::Ph1::SynchronGenerator>(comp))
28  mSynchronGenerators.push_back(gen);
29  else if (std::shared_ptr<CPS::SP::Ph1::Load> load =
30  std::dynamic_pointer_cast<CPS::SP::Ph1::Load>(comp))
31  mLoads.push_back(load);
32  else if (std::shared_ptr<CPS::SP::Ph1::Transformer> trafo =
33  std::dynamic_pointer_cast<CPS::SP::Ph1::Transformer>(comp))
34  mTransformers.push_back(trafo);
35  else if (std::shared_ptr<CPS::SP::Ph1::PiLine> line =
36  std::dynamic_pointer_cast<CPS::SP::Ph1::PiLine>(comp))
37  mLines.push_back(line);
38  else if (std::shared_ptr<CPS::SP::Ph1::NetworkInjection> extnet =
39  std::dynamic_pointer_cast<CPS::SP::Ph1::NetworkInjection>(
40  comp))
41  mExternalGrids.push_back(extnet);
42  else if (std::shared_ptr<CPS::SP::Ph1::Shunt> shunt =
43  std::dynamic_pointer_cast<CPS::SP::Ph1::Shunt>(comp))
44  mShunts.push_back(shunt);
45  else if (std::shared_ptr<CPS::SP::Ph1::SolidStateTransformer> sst =
46  std::dynamic_pointer_cast<CPS::SP::Ph1::SolidStateTransformer>(
47  comp))
48  mSolidStateTransformers.push_back(sst);
49  else if (std::shared_ptr<CPS::SP::Ph1::AvVoltageSourceInverterDQ> vsi =
50  std::dynamic_pointer_cast<
52  mAverageVoltageSourceInverters.push_back(vsi);
53  }
54  }
55 
62 
63  mJ.setZero(mNumUnknowns, mNumUnknowns);
64  mX.setZero(mNumUnknowns);
65  mF.setZero(mNumUnknowns);
66 }
67 
69  SPDLOG_LOGGER_INFO(mSLog, "Assigning simulation nodes to topology nodes:");
70  UInt matrixNodeIndexIdx = 0;
71  for (UInt idx = 0; idx < mSystem.mNodes.size(); ++idx) {
72  mSystem.mNodes[idx]->setMatrixNodeIndex(0, matrixNodeIndexIdx);
73  SPDLOG_LOGGER_INFO(mSLog, "Node {}: MatrixNodeIndex {}",
74  mSystem.mNodes[idx]->uid(),
75  mSystem.mNodes[idx]->matrixNodeIndex());
76  ++matrixNodeIndexIdx;
77  }
78  SPDLOG_LOGGER_INFO(mSLog, "Number of simulation nodes: {:d}",
79  matrixNodeIndexIdx);
80 }
81 
83  for (auto comp : mSystem.mComponents) {
84  std::dynamic_pointer_cast<SimPowerComp<Complex>>(comp)
85  ->updateMatrixNodeIndices();
86  }
87 
88  SPDLOG_LOGGER_INFO(
89  mSLog, "-- Initialize components from terminals or nodes of topology");
90  for (auto comp : mSystem.mComponents) {
91  auto pComp = std::dynamic_pointer_cast<SimPowerComp<Complex>>(comp);
92  if (!pComp)
93  continue;
95  pComp->initializeFromNodesAndTerminals(mSystem.mSystemFrequency);
96  }
97 
98  SPDLOG_LOGGER_INFO(mSLog,
99  "-- Calculate per unit parameters for all components");
100  for (auto extnet : mExternalGrids) {
101  extnet->calculatePerUnitParameters(mBaseApparentPower,
103  }
104  for (auto line : mLines) {
105  line->calculatePerUnitParameters(mBaseApparentPower, mSystem.mSystemOmega);
106  }
107  for (auto trans : mTransformers) {
108  trans->calculatePerUnitParameters(mBaseApparentPower, mSystem.mSystemOmega);
109  }
110  for (auto shunt : mShunts) {
111  shunt->calculatePerUnitParameters(mBaseApparentPower, mSystem.mSystemOmega);
112  }
113  for (auto load : mLoads) {
114  load->calculatePerUnitParameters(mBaseApparentPower, mSystem.mSystemOmega);
115  }
116  for (auto gen : mSynchronGenerators) {
117  gen->calculatePerUnitParameters(mBaseApparentPower, mSystem.mSystemOmega);
118  }
119  for (auto sst : mSolidStateTransformers) {
120  sst->calculatePerUnitParameters(mBaseApparentPower, mSystem.mSystemOmega);
121  }
122 }
123 
125  Real maxPower = 0.;
126  if (!mSynchronGenerators.empty()) {
127  for (auto gen : mSynchronGenerators)
128  if (std::abs(gen->attributeTyped<Real>("P_set")->get()) > maxPower)
129  maxPower = std::abs(gen->attributeTyped<Real>("P_set")->get());
130  } else if (!mTransformers.empty()) {
131  for (auto trafo : mTransformers)
132  if (trafo->attributeTyped<Real>("S")->get() > maxPower)
133  maxPower = trafo->attributeTyped<Real>("S")->get();
134  }
135  if (maxPower != 0.)
136  mBaseApparentPower = pow(10, 1 + floor(log10(maxPower)));
137  else {
138  mBaseApparentPower = 100000000;
139  SPDLOG_LOGGER_WARN(mSLog,
140  "No suitable quantity found for setting "
141  "mBaseApparentPower. Using {} VA.",
143  }
144  SPDLOG_LOGGER_INFO(mSLog, "Base power = {} VA", mBaseApparentPower);
145 }
146 
148  mPQBusIndices.clear();
149  mPVBusIndices.clear();
150  mVDBusIndices.clear();
151 
152  SPDLOG_LOGGER_INFO(mSLog, "-- Determine powerflow bus type for each node");
153 
154  // Determine powerflow bus type of each node through analysis of system topology
155  for (auto node : mSystem.mNodes) {
156  bool connectedPV = false;
157  bool connectedPQ = false;
158  bool connectedVD = false;
159 
160  for (auto comp : mSystem.mComponentsAtNode[node]) {
161  if (std::shared_ptr<CPS::SP::Ph1::Load> load =
162  std::dynamic_pointer_cast<CPS::SP::Ph1::Load>(comp)) {
163  if (load->mPowerflowBusType == CPS::PowerflowBusType::PQ) {
164  connectedPQ = true;
165  }
166  } else if (std::shared_ptr<CPS::SP::Ph1::SynchronGenerator> gen =
167  std::dynamic_pointer_cast<CPS::SP::Ph1::SynchronGenerator>(
168  comp)) {
169  if (gen->mPowerflowBusType == CPS::PowerflowBusType::PV) {
170  connectedPV = true;
171  } else if (gen->mPowerflowBusType == CPS::PowerflowBusType::VD) {
172  connectedVD = true;
173  }
174  } else if (std::shared_ptr<CPS::SP::Ph1::NetworkInjection> extnet =
175  std::dynamic_pointer_cast<CPS::SP::Ph1::NetworkInjection>(
176  comp)) {
177  if (extnet->mPowerflowBusType == CPS::PowerflowBusType::VD) {
178  connectedVD = true;
179  } else if (extnet->mPowerflowBusType == CPS::PowerflowBusType::PV) {
180  connectedPV = true;
181  }
182  }
183  }
184 
185  // determine powerflow bus types according connected type of connected components
186  // only PQ type component connected -> set as PQ bus
187  if (!connectedPV && connectedPQ && !connectedVD) {
188  SPDLOG_LOGGER_DEBUG(
189  mSLog, "{}: only PQ type component connected -> set as PQ bus",
190  node->name());
191  mPQBusIndices.push_back(node->matrixNodeIndex());
192  mPQBuses.push_back(node);
193  } // no component connected -> set as PQ bus (P & Q will be zero)
194  else if (!connectedPV && !connectedPQ && !connectedVD) {
195  SPDLOG_LOGGER_DEBUG(mSLog, "{}: no component connected -> set as PQ bus",
196  node->name());
197  mPQBusIndices.push_back(node->matrixNodeIndex());
198  mPQBuses.push_back(node);
199  } // only PV type component connected -> set as PV bus
200  else if (connectedPV && !connectedPQ && !connectedVD) {
201  SPDLOG_LOGGER_DEBUG(
202  mSLog, "{}: only PV type component connected -> set as PV bus",
203  node->name());
204  mPVBusIndices.push_back(node->matrixNodeIndex());
205  mPVBuses.push_back(node);
206  } // PV and PQ type component connected -> set as PV bus (TODO: bus type should be modifiable by user afterwards)
207  else if (connectedPV && connectedPQ && !connectedVD) {
208  SPDLOG_LOGGER_DEBUG(
209  mSLog, "{}: PV and PQ type component connected -> set as PV bus",
210  node->name());
211  mPVBusIndices.push_back(node->matrixNodeIndex());
212  mPVBuses.push_back(node);
213  } // only VD type component connected -> set as VD bus
214  else if (!connectedPV && !connectedPQ && connectedVD) {
215  SPDLOG_LOGGER_DEBUG(
216  mSLog, "{}: only VD type component connected -> set as VD bus",
217  node->name());
218  mVDBusIndices.push_back(node->matrixNodeIndex());
219  mVDBuses.push_back(node);
220  } // VD and PV type component connect -> set as VD bus
221  else if (connectedPV && !connectedPQ && connectedVD) {
222  SPDLOG_LOGGER_DEBUG(
223  mSLog, "{}: VD and PV type component connect -> set as VD bus",
224  node->name());
225  mVDBusIndices.push_back(node->matrixNodeIndex());
226  mVDBuses.push_back(node);
227  } // VD, PV and PQ type component connect -> set as VD bus
228  else if (connectedPV && connectedPQ && connectedVD) {
229  SPDLOG_LOGGER_DEBUG(
230  mSLog, "{}: VD, PV and PQ type component connect -> set as VD bus",
231  node->name());
232  mVDBusIndices.push_back(node->matrixNodeIndex());
233  mVDBuses.push_back(node);
234  } else {
235  std::stringstream ss;
236  ss << "Node>>" << node->name()
237  << ": combination of connected components is invalid";
238  throw std::invalid_argument(ss.str());
239  }
240  }
241 
242  mNumPQBuses = mPQBusIndices.size();
243  mNumPVBuses = mPVBusIndices.size();
244  mNumVDBuses = mVDBusIndices.size();
246 
247  // Aggregate PQ bus and PV bus index vectors for easy handling in solver
249  mPQPVBusIndices.insert(mPQPVBusIndices.end(), mPQBusIndices.begin(),
250  mPQBusIndices.end());
251  mPQPVBusIndices.insert(mPQPVBusIndices.end(), mPVBusIndices.begin(),
252  mPVBusIndices.end());
253 
254  SPDLOG_LOGGER_INFO(mSLog, "#### Create index vectors for power flow solver:");
255  SPDLOG_LOGGER_INFO(mSLog, "PQ Buses: {}", logVector(mPQBusIndices));
256  SPDLOG_LOGGER_INFO(mSLog, "PV Buses: {}", logVector(mPVBusIndices));
257  SPDLOG_LOGGER_INFO(mSLog, "VD Buses: {}", logVector(mVDBusIndices));
258 }
259 
261 
262  SPDLOG_LOGGER_INFO(mSLog, "-- Determine base voltages for each node "
263  "according to connected components");
264  mSLog->flush();
265 
266  for (auto node : mSystem.mNodes) {
267  CPS::Real baseVoltage_ = 0;
268  for (auto comp : mSystem.mComponentsAtNode[node]) {
269  if (std::shared_ptr<CPS::SP::Ph1::AvVoltageSourceInverterDQ> vsi =
270  std::dynamic_pointer_cast<
272  baseVoltage_ =
273  Math::abs(vsi->attributeTyped<CPS::Complex>("vnom")->get());
274  SPDLOG_LOGGER_INFO(
275  mSLog,
276  "Choose base voltage {}V of {} to convert pu-solution of {}.",
277  baseVoltage_, vsi->name(), node->name());
278  break;
279  } else if (std::shared_ptr<CPS::SP::Ph1::RXLine> rxline =
280  std::dynamic_pointer_cast<CPS::SP::Ph1::RXLine>(comp)) {
281  baseVoltage_ = rxline->attributeTyped<CPS::Real>("base_Voltage")->get();
282  SPDLOG_LOGGER_INFO(
283  mSLog,
284  "Choose base voltage {}V of {} to convert pu-solution of {}.",
285  baseVoltage_, rxline->name(), node->name());
286  break;
287  } else if (std::shared_ptr<CPS::SP::Ph1::PiLine> line =
288  std::dynamic_pointer_cast<CPS::SP::Ph1::PiLine>(comp)) {
289  baseVoltage_ = line->attributeTyped<CPS::Real>("base_Voltage")->get();
290  SPDLOG_LOGGER_INFO(
291  mSLog,
292  "Choose base voltage {}V of {} to convert pu-solution of {}.",
293  baseVoltage_, line->name(), node->name());
294  break;
295  } else if (std::shared_ptr<CPS::SP::Ph1::Transformer> trans =
296  std::dynamic_pointer_cast<CPS::SP::Ph1::Transformer>(
297  comp)) {
298  if (trans->terminal(0)->node()->name() == node->name()) {
299  baseVoltage_ =
300  trans->attributeTyped<CPS::Real>("nominal_voltage_end1")->get();
301  SPDLOG_LOGGER_INFO(
302  mSLog,
303  "Choose base voltage {}V of {} to convert pu-solution of {}.",
304  baseVoltage_, trans->name(), node->name());
305  break;
306  } else if (trans->terminal(1)->node()->name() == node->name()) {
307  baseVoltage_ =
308  trans->attributeTyped<CPS::Real>("nominal_voltage_end2")->get();
309  SPDLOG_LOGGER_INFO(
310  mSLog,
311  "Choose base voltage {}V of {} to convert pu-solution of {}.",
312  baseVoltage_, trans->name(), node->name());
313  break;
314  }
315  } else if (std::shared_ptr<CPS::SP::Ph1::SynchronGenerator> gen =
316  std::dynamic_pointer_cast<CPS::SP::Ph1::SynchronGenerator>(
317  comp)) {
318  baseVoltage_ = gen->attributeTyped<CPS::Real>("base_Voltage")->get();
319  SPDLOG_LOGGER_INFO(
320  mSLog,
321  "Choose base voltage {}V of {} to convert pu-solution of {}.",
322  baseVoltage_, gen->name(), node->name());
323  break;
324  } else {
325  SPDLOG_LOGGER_WARN(mSLog, "Unable to get base voltage at {}",
326  node->name());
327  }
328  }
329  mBaseVoltageAtNode[node] = baseVoltage_;
330  }
331 }
332 
333 void PFSolver::setVDNode(CPS::String name) {
334  if (!mExternalGrids.empty()) {
335  if (mExternalGrids[0]->node(0)->name() == name) {
336  mExternalGrids[0]->modifyPowerFlowBusType(CPS::PowerflowBusType::VD);
337  }
338  } else {
339  for (auto gen : mSynchronGenerators) {
340  if (gen->node(0)->name() == name) {
341  gen->modifyPowerFlowBusType(CPS::PowerflowBusType::VD);
342  return;
343  }
344  }
345  throw std::invalid_argument("Invalid slack bus, no external grid or "
346  "synchronous generator attached");
347  }
348 }
349 
351  CPS::String name, CPS::PowerflowBusType powerFlowBusType) {
352  for (auto comp : mSystem.mComponents) {
353  if (comp->name() == name) {
354  if (std::shared_ptr<CPS::SP::Ph1::NetworkInjection> extnet =
355  std::dynamic_pointer_cast<CPS::SP::Ph1::NetworkInjection>(comp))
356  extnet->modifyPowerFlowBusType(powerFlowBusType);
357  else if (std::shared_ptr<CPS::SP::Ph1::SynchronGenerator> gen =
358  std::dynamic_pointer_cast<CPS::SP::Ph1::SynchronGenerator>(
359  comp))
360  gen->modifyPowerFlowBusType(powerFlowBusType);
361  }
362  }
363 }
364 
365 void PFSolver::setSolverAndComponentBehaviour(Solver::Behaviour behaviour) {
366  mBehaviour = behaviour;
367  if (mBehaviour == Behaviour::Initialization) {
368  SPDLOG_LOGGER_INFO(mSLog, "-- Set solver behaviour to Initialization");
369  // TODO: solver setting specific to initialization (e.g. one single PF run)
370 
371  SPDLOG_LOGGER_INFO(mSLog, "-- Set component behaviour to Initialization");
372  for (auto comp : mSystem.mComponents) {
373  auto powerComp =
374  std::dynamic_pointer_cast<CPS::TopologicalPowerComp>(comp);
375  if (powerComp)
376  powerComp->setBehaviour(
377  TopologicalPowerComp::Behaviour::Initialization);
378  }
379  } else {
380  SPDLOG_LOGGER_INFO(mSLog, "-- Set solver behaviour to Simulation");
381  // TODO: solver setting specific to simulation
382 
383  SPDLOG_LOGGER_INFO(mSLog, "-- Set component behaviour to PFSimulation");
384  for (auto comp : mSystem.mComponents) {
385  auto powerComp =
386  std::dynamic_pointer_cast<CPS::TopologicalPowerComp>(comp);
387  if (powerComp)
388  powerComp->setBehaviour(TopologicalPowerComp::Behaviour::PFSimulation);
389  }
390  }
391 }
392 
394  int n = mSystem.mNodes.size();
395  if (n > 0) {
396  mY = CPS::SparseMatrixComp(n, n);
397  for (auto line : mLines) {
398  line->pfApplyAdmittanceMatrixStamp(mY);
399  }
400  for (auto trans : mTransformers) {
401  //to check if this transformer could be ignored
402  if (**trans->mResistance == 0 && **trans->mInductance == 0) {
403  SPDLOG_LOGGER_INFO(mSLog, "{} {} ignored for R = 0 and L = 0",
404  trans->type(), trans->name());
405  continue;
406  }
407  trans->pfApplyAdmittanceMatrixStamp(mY);
408  }
409  for (auto shunt : mShunts) {
410  shunt->pfApplyAdmittanceMatrixStamp(mY);
411  }
412  }
413  if (mLines.empty() && mTransformers.empty()) {
414  throw std::invalid_argument("There are no bus");
415  }
416 }
417 
418 CPS::Real PFSolver::G(int i, int j) { return mY.coeff(i, j).real(); }
419 
420 CPS::Real PFSolver::B(int i, int j) { return mY.coeff(i, j).imag(); }
421 
423  // Converged if all mismatches are below the tolerance
424  for (CPS::UInt i = 0; i < mNumUnknowns; i++) {
425  if (abs(mF(i)) > mTolerance)
426  return false;
427  }
428  return true;
429 }
430 
432  // Calculate the mismatch according to the initial solution
434 
435  // Check whether model already converged
437 
438  mIterations = 0;
439  for (unsigned i = 1; i < mMaxIterations && !isConverged; ++i) {
440 
442  auto sparseJ = mJ.sparseView();
443 
444  // Solve system mJ*mX = mF
445  Eigen::SparseLU<SparseMatrix> lu(sparseJ);
446 
447  mX = lu.solve(mF); /* code */
448 
449  // Calculate new solution based on mX increments obtained from equation system
450  updateSolution();
451 
452  // Calculate the mismatch according to the current solution
454 
455  SPDLOG_LOGGER_DEBUG(mSLog, "Mismatch vector at iteration {}: \n {}", i, mF);
456  mSLog->flush();
457 
458  // Check convergence
460  mIterations = i;
461  }
462  return isConverged;
463 }
464 
465 void PFSolver::SolveTask::execute(Real time, Int timeStepCount) {
466  // apply keepLastSolution to save computation time
467  mSolver.generateInitialSolution(time);
468  mSolver.solvePowerflow();
469  mSolver.setSolution();
470 }
471 
472 Task::List PFSolver::getTasks() {
473  return Task::List{std::make_shared<SolveTask>(*this)};
474 }
Real mSystemOmega
System angular frequency - omega.
Real mSystemFrequency
System frequency.
IdentifiedObject::List mComponents
List of network components.
TopologicalNode::List mNodes
List of network nodes.
std::map< TopologicalNode::Ptr, TopologicalPowerComp::List > mComponentsAtNode
Map of network components connected to network nodes.
void determinePFBusType()
Determine bus type for all buses.
Definition: PFSolver.cpp:147
std::vector< std::shared_ptr< CPS::SP::Ph1::Load > > mLoads
Vector of load components.
Definition: PFSolver.h:67
CPS::TopologicalNode::List mPQBuses
Vector of nodes characterized as PQ buses.
Definition: PFSolver.h:32
UInt mNumPQBuses
Number of PQ nodes.
Definition: PFSolver.h:24
UInt mNumVDBuses
Number of PV nodes.
Definition: PFSolver.h:28
Real mTolerance
Solver tolerance.
Definition: PFSolver.h:81
CPS::String logVector(std::vector< CPS::UInt > indexVector)
Logging for integer vectors.
Definition: PFSolver.h:131
std::vector< std::shared_ptr< CPS::SP::Ph1::PiLine > > mLines
Vector of line components.
Definition: PFSolver.h:69
CPS::Task::List getTasks() override
Get tasks for scheduler.
Definition: PFSolver.cpp:472
void assignMatrixNodeIndices()
Assignment of matrix indices for nodes.
Definition: PFSolver.cpp:68
std::vector< CPS::UInt > mVDBusIndices
Vector with indices of VD buses.
Definition: PFSolver.h:42
void initializeComponents()
Initialization of individual components.
Definition: PFSolver.cpp:82
std::vector< std::shared_ptr< CPS::SP::Ph1::SynchronGenerator > > mSynchronGenerators
Vector of synchronous generator components.
Definition: PFSolver.h:65
std::vector< CPS::UInt > mPQBusIndices
Vector with indices of PQ buses.
Definition: PFSolver.h:38
void modifyPowerFlowBusComponent(CPS::String name, CPS::PowerflowBusType powerFlowBusType)
Allows to modify the powerflow bus type of a specific component.
Definition: PFSolver.cpp:350
std::vector< std::shared_ptr< CPS::SP::Ph1::NetworkInjection > > mExternalGrids
Vector of external grid components.
Definition: PFSolver.h:73
std::vector< std::shared_ptr< CPS::SP::Ph1::SolidStateTransformer > > mSolidStateTransformers
Vector of solid state transformer components.
Definition: PFSolver.h:62
std::vector< CPS::UInt > mPVBusIndices
Vector with indices of PV buses.
Definition: PFSolver.h:40
void setVDNode(CPS::String name)
Set a node to VD using its name.
Definition: PFSolver.cpp:333
std::vector< std::shared_ptr< CPS::SP::Ph1::Transformer > > mTransformers
Vector of transformer components.
Definition: PFSolver.h:59
std::vector< std::shared_ptr< CPS::SP::Ph1::Shunt > > mShunts
Vector of shunt components.
Definition: PFSolver.h:71
CPS::Bool checkConvergence()
Check whether below tolerance.
Definition: PFSolver.cpp:422
CPS::Matrix mJ
Jacobian matrix.
Definition: PFSolver.h:50
CPS::UInt mMaxIterations
Maximum number of iterations.
Definition: PFSolver.h:83
CPS::Vector mX
Solution vector.
Definition: PFSolver.h:52
std::vector< std::shared_ptr< CPS::SP::Ph1::AvVoltageSourceInverterDQ > > mAverageVoltageSourceInverters
Vector of average voltage source inverters.
Definition: PFSolver.h:76
CPS::Real mBaseApparentPower
Base power of per-unit system.
Definition: PFSolver.h:87
void setBaseApparentPower()
Set apparent base power of per-unit system.
Definition: PFSolver.cpp:124
virtual void calculateMismatch()=0
Calculate mismatch.
CPS::SparseMatrixCompRow mY
Admittance matrix.
Definition: PFSolver.h:47
UInt mNumPVBuses
Number of PV nodes.
Definition: PFSolver.h:26
CPS::Real B(int i, int j)
Gets the imaginary part of admittance matrix element.
Definition: PFSolver.cpp:420
void composeAdmittanceMatrix()
Compose admittance matrix.
Definition: PFSolver.cpp:393
CPS::Bool isConverged
Convergence flag.
Definition: PFSolver.h:89
CPS::Vector mF
Vector of mismatch values.
Definition: PFSolver.h:54
CPS::UInt mIterations
Actual number of iterations.
Definition: PFSolver.h:85
PFSolver(CPS::String name, CPS::SystemTopology system, Real timeStep, CPS::Logger::Level logLevel)
Constructor to be used in simulation examples.
Definition: PFSolver.cpp:16
CPS::SystemTopology mSystem
System list.
Definition: PFSolver.h:57
virtual void calculateJacobian()=0
Calculate the Jacobian.
void determineNodeBaseVoltages()
Determine base voltages for each node.
Definition: PFSolver.cpp:260
void setSolverAndComponentBehaviour(Solver::Behaviour behaviour) override
set solver and component to initialization or simulation behaviour
Definition: PFSolver.cpp:365
std::map< CPS::TopologicalNode::Ptr, CPS::Real > mBaseVoltageAtNode
Map providing determined base voltages for each node.
Definition: PFSolver.h:78
virtual void setSolution()=0
Set final solution.
void initialize() override
Initialization of the solver.
Definition: PFSolver.cpp:23
virtual void generateInitialSolution(Real time, bool keep_last_solution=false)=0
Generate initial solution for current time step.
virtual void updateSolution()=0
Update solution in each iteration.
Bool solvePowerflow()
Solves the powerflow problem.
Definition: PFSolver.cpp:431
CPS::TopologicalNode::List mVDBuses
Vector of nodes characterized as VD buses.
Definition: PFSolver.h:36
CPS::TopologicalNode::List mPVBuses
Vector of nodes characterized as PV buses.
Definition: PFSolver.h:34
UInt mNumUnknowns
Number of unknowns, defining system dimension.
Definition: PFSolver.h:30
CPS::Real G(int i, int j)
Gets the real part of admittance matrix element.
Definition: PFSolver.cpp:418
std::vector< CPS::UInt > mPQPVBusIndices
Vector with indices of both PQ and PV buses.
Definition: PFSolver.h:44
Base class for more specific solvers such as MNA, ODE or IDA.
Definition: Solver.h:30
Real mTimeStep
Time step for fixed step solvers.
Definition: Solver.h:45
Behaviour mBehaviour
Solver behaviour initialization or simulation.
Definition: Solver.h:65
CPS::Logger::Log mSLog
Logger.
Definition: Solver.h:43
Bool mInitFromNodesAndTerminals
Definition: Solver.h:60