4#include <dpsim/PFSolverPowerPolarSparse.h>
7#include <dpsim/KLUAdapter.h>
8#elif defined(WITH_SPARSE)
9#include <dpsim/SparseLUAdapter.h>
11#include <dpsim/DenseLUAdapter.h>
19 CPS::Logger::Level logLevel)
23 return G(k, j) != 0.0 ||
B(k, j) != 0.0;
28 std::vector<Eigen::Triplet<Real>> triplets;
33 for (UInt a = 0; a < npqpv; ++a) {
35 triplets.emplace_back(a, a, 0.0);
37 triplets.emplace_back(a, a + npqpv, 0.0);
38 for (UInt b = 0; b < npqpv; ++b) {
40 triplets.emplace_back(a, b, 0.0);
44 triplets.emplace_back(a, b + npqpv, 0.0);
49 triplets.emplace_back(a + npqpv, a, 0.0);
50 triplets.emplace_back(a + npqpv, a + npqpv, 0.0);
51 for (UInt b = 0; b < npqpv; ++b) {
53 triplets.emplace_back(a + npqpv, b, 0.0);
57 triplets.emplace_back(a + npqpv, b + npqpv, 0.0);
62 mJsparse.setFromTriplets(triplets.begin(), triplets.end());
74#elif defined(WITH_SPARSE)
93 for (UInt a = 0; a < npqpv; ++a) {
96 for (UInt b = 0; b < npqpv; ++b) {
110 for (UInt a = 0; a < npqpv; ++a) {
124 mJsparse.coeffRef(a, b + npqpv) = val;
133 for (UInt b = 0; b < npqpv; ++b) {
142 mJsparse.coeffRef(a + npqpv, b) = -val;
149 mJsparse.coeffRef(a + npqpv, a + npqpv) =
160 mJsparse.coeffRef(a + npqpv, b + npqpv) = val;
UInt mNumPQBuses
Number of PQ nodes.
CPS::Vector mX
Solution vector.
UInt mNumPVBuses
Number of PV nodes.
CPS::Real B(int i, int j)
Gets the imaginary part of admittance matrix element.
CPS::Vector mF
Vector of mismatch values.
CPS::UInt mIterations
Actual number of iterations.
UInt mNumUnknowns
Number of unknowns, defining system dimension.
CPS::Real G(int i, int j)
Gets the real part of admittance matrix element.
std::vector< CPS::UInt > mPQPVBusIndices
Vector with indices of both PQ and PV buses.
PFSolverPowerPolar(CPS::String name, const CPS::SystemTopology &system, CPS::Real timeStep, CPS::Logger::Level logLevel)
Constructor to be used in simulation examples.
CPS::Vector sol_D
Solution vector of voltage angle.
CPS::Real Q(CPS::UInt k)
Calculate the reactive power at a bus from current solution.
CPS::Real P(CPS::UInt k)
Calculate active power at a bus from current solution.
CPS::Vector sol_V
Solution vector of voltage magnitude.
std::shared_ptr< DirectLinearSolver > mLinearSolver
Direct linear solver reused across iterations (symbolic factorization computed once)
CPS::SparseMatrixRow mJsparse
Sparse Jacobian (row-major, fixed pattern, values updated in place each iteration)
bool isConnected(CPS::UInt k, CPS::UInt j)
Whether buses k and j are connected (off-diagonal Jacobian entry exists)
void setUpJacobianStorage() override
Build the fixed sparsity pattern, create the linear solver and analyze the pattern once.
std::vector< std::pair< CPS::UInt, CPS::UInt > > mVariableSystemMatrixEntries
Empty list: PF uses full refactorization, not partial refactorization.
void calculateJacobian() override
Fill the sparse Jacobian values in place (pattern unchanged)
PFSolverPowerPolarSparse(CPS::String name, const CPS::SystemTopology &system, CPS::Real timeStep, CPS::Logger::Level logLevel)
Constructor to be used in simulation examples.
void solveJacobianSystem() override
Factorize (first iteration of a run) or refactorize, then solve.
void buildJacobianPattern()
Construct the structural sparsity pattern of the Jacobian from the bus admittance matrix.
CPS::Logger::Log mSLog
Logger.