DPsim
Loading...
Searching...
No Matches
DPsim::PFSolverPowerPolar Class Reference

Powerflow solver class considering power mismatch and voltages in polar coordinates. More...

#include <PFSolverPowerPolar.h>

Inheritance diagram for DPsim::PFSolverPowerPolar:
[legend]
Collaboration diagram for DPsim::PFSolverPowerPolar:
[legend]

Public Member Functions

 PFSolverPowerPolar (CPS::String name, const CPS::SystemTopology &system, CPS::Real timeStep, CPS::Logger::Level logLevel)
 Constructor to be used in simulation examples.
 
virtual ~PFSolverPowerPolar ()
 
- Public Member Functions inherited from DPsim::PFSolver
 PFSolver (CPS::String name, CPS::SystemTopology system, Real timeStep, CPS::Logger::Level logLevel)
 Constructor to be used in simulation examples.
 
virtual ~PFSolver ()
 
void setVDNode (CPS::String name)
 Set a node to VD using its name.
 
void modifyPowerFlowBusComponent (CPS::String name, CPS::PowerflowBusType powerFlowBusType)
 Allows to modify the powerflow bus type of a specific component.
 
void setSolverAndComponentBehaviour (Solver::Behaviour behaviour) override
 set solver and component to initialization or simulation behaviour
 
void setKeepLastSolution (CPS::Bool keepLastSolution)
 
void setEnforceReactiveLimits (CPS::Bool value)
 Enable generator reactive-limit enforcement (PV<->PQ outer loop)
 
void setBaseVoltageLooseTolerance (CPS::Real tolerance)
 Raise for grids with legitimate large voltage drop (e.g. untapped feeders)
 
void setBaseVoltageStrictTolerance (CPS::Real tolerance)
 Override the tolerance between authoritative base-voltage sources within a zone.
 
CPS::Bool getKeepLastSolution () const
 
void setBaseApparentPowerFallback (CPS::Real baseApparentPowerFallback)
 
CPS::Real getBaseApparentPowerFallback () const
 
void setMaxIterations (CPS::UInt maxIterations)
 
CPS::UInt getMaxIterations () const
 
- Public Member Functions inherited from DPsim::Solver
 Solver (String name, CPS::Logger::Level logLevel)
 
virtual ~Solver ()
 
void setTimeStep (Real timeStep)
 
void doFrequencyParallelization (Bool freqParallel)
 
virtual void setSystem (const CPS::SystemTopology &system)
 
void setSystemMatrixRecomputationMode (SystemMatrixRecomputationMode mode)
 Set the system-matrix recomputation mode.
 
void doSystemMatrixRecomputation (Bool value)
 
void setLogSolveTimes (Bool value)
 
void doSteadyStateInit (Bool f)
 activate steady state initialization
 
void setSteadStIniTimeLimit (Real v)
 set steady state initialization time limit
 
void setSteadStIniAccLimit (Real v)
 set steady state initialization accuracy limit
 
void doInitFromNodesAndTerminals (Bool f)
 activate powerflow initialization
 
virtual void setDirectLinearSolverConfiguration (DirectLinearSolverConfiguration &)
 set direct linear solver configuration (only available in MNA for now)
 
virtual void logLUTimes ()
 log LU decomposition times, if applicable
 
virtual void log (Real time, Int timeStepCount)
 Log results.
 
void setMaxNumberOfIterations (int maxIterations)
 

Protected Member Functions

void generateInitialSolution (Real time, bool keep_last_solution=false) override
 Generate initial solution for current time step.
 
void calculateJacobian () override
 Calculate the Jacobian.
 
void updateSolution () override
 Update solution in each iteration.
 
void setSolution () override
 Set final solution.
 
void calculateMismatch () override
 Calculate mismatch.
 
void resize_sol (CPS::Int n)
 Resize solution vector.
 
void resize_complex_sol (CPS::Int n)
 Resize complex solution vector.
 
CPS::Real sol_Vr (CPS::UInt k)
 Calculate real part of voltage from sol_V and sol_D.
 
CPS::Real sol_Vi (CPS::UInt k)
 Calculate imaginary part of voltage from sol_V and sol_D.
 
CPS::Complex sol_Vcx (CPS::UInt k)
 Calculate complex voltage from sol_V and sol_D.
 
CPS::Real P (CPS::UInt k)
 Calculate active power at a bus from current solution.
 
CPS::Real Q (CPS::UInt k)
 Calculate the reactive power at a bus from current solution.
 
void calculatePAndQAtSlackBus ()
 Calculate P and Q at slack bus from current solution.
 
void calculateQAtPVBuses ()
 Calculate the reactive power at all PV buses from current solution.
 
CPS::Real generatorReactivePowerPerUnit (CPS::TopologicalNode::Ptr node)
 Generator reactive-power injection at a bus [pu], used by the Q-limit check.
 
CPS::Real loadReactivePowerPerUnit (CPS::TopologicalNode::Ptr node)
 Total local load reactive power at a bus [pu].
 
CPS::Bool enforceReactiveLimits () override
 Q-limit PV<->PQ switching pass (overrides the base no-op)
 
void clearReactiveLimitState () override
 Clear the Q-limit conversion bookkeeping between solves.
 
void calculatePAndQInjectionPQBuses ()
 Calculate complex power flowing from this node to the other nodes.
 
void calculateBranchFlow ()
 Calculate branch flows from current solution and store them in line and transformer components.
 
void calculateNodalInjection ()
 Calculate nodal power injections and store them in first line or transformer (in case no line is connected), so that lower level classes (Node, TopologicalTerminal) can stay untouched.
 
- Protected Member Functions inherited from DPsim::PFSolver
void initialize () override
 Initialization of the solver.
 
void initializeComponents ()
 Initialization of individual components.
 
void assignMatrixNodeIndices ()
 Assignment of matrix indices for nodes.
 
void setBaseApparentPower ()
 Set apparent base power of per-unit system.
 
void determinePFBusType ()
 Determine bus type for all buses.
 
void rebuildBusIndexAggregates ()
 Rebuild index vectors + counts from the PQ/PV/VD node lists.
 
void reclassifyBuses ()
 Re-derive index vectors and resize the system after PV<->PQ switching.
 
void resetToOriginalClassification ()
 Restore the original PV/PQ classification before a fresh solve.
 
CPS::Real componentBaseVoltage (CPS::TopologicalPowerComp::Ptr comp, CPS::TopologicalNode::Ptr node)
 Base voltage a single component reports for node, or 0 if unknown.
 
void propagateAndVerifyBaseVoltage ()
 Determine, verify and propagate each node's base voltage per electrical zone.
 
void composeAdmittanceMatrix ()
 Compose admittance matrix.
 
CPS::Real G (int i, int j)
 Gets the real part of admittance matrix element.
 
CPS::Real B (int i, int j)
 Gets the imaginary part of admittance matrix element.
 
Bool solvePowerflow ()
 Solves the powerflow problem.
 
Bool runNewtonRaphson ()
 Run a single Newton-Raphson solve with the current bus classification.
 
virtual void setUpJacobianStorage ()
 Allocate Jacobian storage; dense by default, sparse subclass overrides.
 
virtual void solveJacobianSystem ()
 Solve the linearized system mJ*mX = mF into mX; sparse subclass overrides.
 
CPS::Bool checkConvergence ()
 Check whether below tolerance.
 
CPS::String logVector (std::vector< CPS::UInt > indexVector)
 Logging for integer vectors.
 
CPS::Task::List getTasks () override
 Get tasks for scheduler.
 

Protected Attributes

CPS::Vector sol_P
 Solution vector of active power.
 
CPS::Vector sol_Q
 Solution vector of reactive power.
 
CPS::Vector sol_V
 Solution vector of voltage magnitude.
 
CPS::Vector sol_D
 Solution vector of voltage angle.
 
CPS::VectorComp sol_V_complex
 Solution vector of representing sol_V and sol_D as complex quantity.
 
CPS::VectorComp sol_S_complex
 Solution vector of representing sol_P and sol_Q as complex quantity.
 
CPS::Vector Pesp
 
CPS::Vector Qesp
 
CPS::Vector mLastConvergedV
 
CPS::Vector mLastConvergedD
 
bool mHasLastConvergedSolution = false
 
std::map< CPS::TopologicalNode::Ptr, bool > mQLimitConvertedAtMax
 Buses switched PV->PQ by the Q-limit loop -> pinned at Qmax (true) or Qmin (false)
 
std::map< CPS::TopologicalNode::Ptr, CPS::UIntmQLimitSwitchCount
 Total PV<->PQ switches per bus over the solve (anti-oscillation cap)
 
- Protected Attributes inherited from DPsim::PFSolver
UInt mNumPQBuses = 0
 Number of PQ nodes.
 
UInt mNumPVBuses = 0
 Number of PV nodes.
 
UInt mNumVDBuses = 0
 Number of PV nodes.
 
UInt mNumUnknowns = 0
 Number of unknowns, defining system dimension.
 
CPS::TopologicalNode::List mPQBuses
 Vector of nodes characterized as PQ buses.
 
CPS::TopologicalNode::List mPVBuses
 Vector of nodes characterized as PV buses.
 
CPS::TopologicalNode::List mVDBuses
 Vector of nodes characterized as VD buses.
 
CPS::TopologicalNode::List mPQBusesOrig
 Original PQ/PV classification (snapshot before Q-limit switching)
 
CPS::TopologicalNode::List mPVBusesOrig
 
std::vector< CPS::UIntmPQBusIndices
 Vector with indices of PQ buses.
 
std::vector< CPS::UIntmPVBusIndices
 Vector with indices of PV buses.
 
std::vector< CPS::UIntmVDBusIndices
 Vector with indices of VD buses.
 
std::vector< CPS::UIntmPQPVBusIndices
 Vector with indices of both PQ and PV buses.
 
CPS::SparseMatrixCompRow mY
 Admittance matrix.
 
CPS::Matrix mJ
 Jacobian matrix.
 
CPS::Vector mX
 Solution vector.
 
CPS::Vector mF
 Vector of mismatch values.
 
CPS::SystemTopology mSystem
 System list.
 
std::vector< std::shared_ptr< CPS::SP::Ph1::Transformer > > mTransformers
 Vector of transformer components.
 
std::vector< std::shared_ptr< CPS::SP::Ph1::SolidStateTransformer > > mSolidStateTransformers
 Vector of solid state transformer components.
 
std::vector< std::shared_ptr< CPS::SP::Ph1::SynchronGenerator > > mSynchronGenerators
 Vector of synchronous generator components.
 
std::vector< std::shared_ptr< CPS::SP::Ph1::Load > > mLoads
 Vector of load components.
 
std::vector< std::shared_ptr< CPS::SP::Ph1::PiLine > > mLines
 Vector of line components.
 
std::vector< std::shared_ptr< CPS::SP::Ph1::Shunt > > mShunts
 Vector of shunt components.
 
std::vector< std::shared_ptr< CPS::SP::Ph1::NetworkInjection > > mExternalGrids
 Vector of external grid components.
 
std::vector< std::shared_ptr< CPS::SP::Ph1::AvVoltageSourceInverterDQ > > mAverageVoltageSourceInverters
 Vector of average voltage source inverters.
 
std::map< CPS::TopologicalNode::Ptr, CPS::RealmBaseVoltageAtNode
 Map providing determined base voltages for each node.
 
Real mTolerance = 1e-8
 Solver tolerance.
 
CPS::UInt mMaxIterations = 20
 Maximum number of iterations.
 
CPS::UInt mIterations
 Actual number of iterations.
 
CPS::Bool mEnforceReactiveLimits = false
 Enforce generator reactive-power limits via PV<->PQ outer-loop switching.
 
CPS::UInt mMaxOuterIterations = 10
 Maximum number of Q-limit outer iterations.
 
CPS::UInt mMaxQLimitSwitchesPerBus = 2
 Maximum number of PV<->PQ switches per bus before it is frozen (anti-oscillation)
 
CPS::Real mBaseVoltageLooseTolerance = 0.1
 Relative tolerance for non-authoritative (e.g. Load) base-voltage candidates vs. the zone's rating.
 
CPS::Real mBaseVoltageStrictTolerance = 0.01
 Relative tolerance between authoritative base-voltage sources (generator/transformer/network-injection/VSI) within a zone.
 
CPS::Real mBaseApparentPower
 Base power of per-unit system.
 
CPS::Real mBaseApparentPowerFallback = 100e6
 Fallback base apparent power if no generator or transformer rating is found.
 
CPS::Bool isConverged = false
 Convergence flag.
 
CPS::Bool solutionInitialized = false
 Flag whether solution vectors are initialized.
 
CPS::Bool solutionComplexInitialized = false
 Flag whether complex solution vectors are initialized.
 
CPS::Bool mKeepLastSolution = false
 Use last converged solution as initial guess.
 
- Protected Attributes inherited from DPsim::Solver
String mName
 Name for logging.
 
CPS::Logger::Level mLogLevel
 Logging level.
 
Bool mLogSolveTimes = true
 Collect step time for logging.
 
CPS::Logger::Log mSLog
 Logger.
 
Real mTimeStep
 Time step for fixed step solvers.
 
Bool mFrequencyParallel = false
 Activates parallelized computation of frequencies.
 
Real mSteadStIniTimeLimit = 10
 steady state initialization time limit
 
Real mSteadStIniAccLimit = 0.0001
 steady state initialization accuracy limit
 
Bool mSteadyStateInit = false
 Activates steady state initialization.
 
Bool mIsInInitialization = false
 Determines if solver is in initialization phase, which requires different behavior.
 
Bool mInitFromNodesAndTerminals = true
 
SystemMatrixRecomputationMode mSystemMatrixRecomputationMode
 Requested system-matrix recomputation mode.
 
Bool mSystemMatrixRecomputationEnabled = false
 Effective system-matrix recomputation setting used by the solver.
 
Behaviour mBehaviour = Solver::Behaviour::Simulation
 Solver behaviour initialization or simulation.
 

Additional Inherited Members

- Public Types inherited from DPsim::Solver
enum  Behaviour { Initialization , Simulation }
 
enum class  SystemMatrixRecomputationMode { Auto , Enabled , Disabled }
 System-matrix recomputation mode for MNA solvers. More...
 
enum class  Type { MNA , DAE , NRP }
 
typedef std::shared_ptr< SolverPtr
 
typedef std::vector< PtrList
 
- Public Attributes inherited from DPsim::Solver
int mMaxIterations = 10
 

Detailed Description

Powerflow solver class considering power mismatch and voltages in polar coordinates.

Definition at line 17 of file PFSolverPowerPolar.h.

Constructor & Destructor Documentation

◆ PFSolverPowerPolar()

PFSolverPowerPolar::PFSolverPowerPolar ( CPS::String name,
const CPS::SystemTopology & system,
CPS::Real timeStep,
CPS::Logger::Level logLevel )

Constructor to be used in simulation examples.

Definition at line 17 of file PFSolverPowerPolar.cpp.

◆ ~PFSolverPowerPolar()

virtual DPsim::PFSolverPowerPolar::~PFSolverPowerPolar ( )
inlinevirtual

Definition at line 96 of file PFSolverPowerPolar.h.

Member Function Documentation

◆ calculateBranchFlow()

void PFSolverPowerPolar::calculateBranchFlow ( )
protected

Calculate branch flows from current solution and store them in line and transformer components.

I = Y * V

pf on branch [S_01; S_10] = [V_0 * conj(I_0); V_1 * conj(I_1)]

I = Y * V

pf on branch [S_01; S_10] = [V_0 * conj(I_0); V_1 * conj(I_1)]

Definition at line 381 of file PFSolverPowerPolar.cpp.

◆ calculateJacobian()

void PFSolverPowerPolar::calculateJacobian ( )
overrideprotectedvirtual

Calculate the Jacobian.

Implements DPsim::PFSolver.

Reimplemented in DPsim::PFSolverPowerPolarSparse.

Definition at line 191 of file PFSolverPowerPolar.cpp.

◆ calculateMismatch()

void PFSolverPowerPolar::calculateMismatch ( )
overrideprotectedvirtual

Calculate mismatch.

Implements DPsim::PFSolver.

Definition at line 175 of file PFSolverPowerPolar.cpp.

◆ calculateNodalInjection()

void PFSolverPowerPolar::calculateNodalInjection ( )
protected

Calculate nodal power injections and store them in first line or transformer (in case no line is connected), so that lower level classes (Node, TopologicalTerminal) can stay untouched.

Definition at line 406 of file PFSolverPowerPolar.cpp.

◆ calculatePAndQAtSlackBus()

void PFSolverPowerPolar::calculatePAndQAtSlackBus ( )
protected

Calculate P and Q at slack bus from current solution.

Definition at line 448 of file PFSolverPowerPolar.cpp.

◆ calculatePAndQInjectionPQBuses()

void PFSolverPowerPolar::calculatePAndQInjectionPQBuses ( )
protected

Calculate complex power flowing from this node to the other nodes.

Definition at line 651 of file PFSolverPowerPolar.cpp.

◆ calculateQAtPVBuses()

void PFSolverPowerPolar::calculateQAtPVBuses ( )
protected

Calculate the reactive power at all PV buses from current solution.

Definition at line 489 of file PFSolverPowerPolar.cpp.

◆ clearReactiveLimitState()

void PFSolverPowerPolar::clearReactiveLimitState ( )
overrideprotectedvirtual

Clear the Q-limit conversion bookkeeping between solves.

Reimplemented from DPsim::PFSolver.

Definition at line 646 of file PFSolverPowerPolar.cpp.

◆ enforceReactiveLimits()

CPS::Bool PFSolverPowerPolar::enforceReactiveLimits ( )
overrideprotectedvirtual

Q-limit PV<->PQ switching pass (overrides the base no-op)

Reimplemented from DPsim::PFSolver.

Definition at line 544 of file PFSolverPowerPolar.cpp.

◆ generateInitialSolution()

void PFSolverPowerPolar::generateInitialSolution ( Real time,
bool keep_last_solution = false )
overrideprotectedvirtual

Generate initial solution for current time step.

Implements DPsim::PFSolver.

Definition at line 23 of file PFSolverPowerPolar.cpp.

◆ generatorReactivePowerPerUnit()

CPS::Real PFSolverPowerPolar::generatorReactivePowerPerUnit ( CPS::TopologicalNode::Ptr node)
protected

Generator reactive-power injection at a bus [pu], used by the Q-limit check.

Definition at line 533 of file PFSolverPowerPolar.cpp.

◆ loadReactivePowerPerUnit()

CPS::Real PFSolverPowerPolar::loadReactivePowerPerUnit ( CPS::TopologicalNode::Ptr node)
protected

Total local load reactive power at a bus [pu].

Definition at line 525 of file PFSolverPowerPolar.cpp.

◆ P()

Real PFSolverPowerPolar::P ( CPS::UInt k)
protected

Calculate active power at a bus from current solution.

Definition at line 430 of file PFSolverPowerPolar.cpp.

◆ Q()

Real PFSolverPowerPolar::Q ( CPS::UInt k)
protected

Calculate the reactive power at a bus from current solution.

Definition at line 439 of file PFSolverPowerPolar.cpp.

◆ resize_complex_sol()

void PFSolverPowerPolar::resize_complex_sol ( CPS::Int n)
protected

Resize complex solution vector.

Definition at line 687 of file PFSolverPowerPolar.cpp.

◆ resize_sol()

void PFSolverPowerPolar::resize_sol ( CPS::Int n)
protected

Resize solution vector.

Definition at line 676 of file PFSolverPowerPolar.cpp.

◆ setSolution()

void PFSolverPowerPolar::setSolution ( )
overrideprotectedvirtual

Set final solution.

Implements DPsim::PFSolver.

Definition at line 327 of file PFSolverPowerPolar.cpp.

◆ sol_Vcx()

CPS::Complex PFSolverPowerPolar::sol_Vcx ( CPS::UInt k)
protected

Calculate complex voltage from sol_V and sol_D.

Definition at line 702 of file PFSolverPowerPolar.cpp.

◆ sol_Vi()

CPS::Real PFSolverPowerPolar::sol_Vi ( CPS::UInt k)
protected

Calculate imaginary part of voltage from sol_V and sol_D.

Definition at line 698 of file PFSolverPowerPolar.cpp.

◆ sol_Vr()

CPS::Real PFSolverPowerPolar::sol_Vr ( CPS::UInt k)
protected

Calculate real part of voltage from sol_V and sol_D.

Definition at line 694 of file PFSolverPowerPolar.cpp.

◆ updateSolution()

void PFSolverPowerPolar::updateSolution ( )
overrideprotectedvirtual

Update solution in each iteration.

Implements DPsim::PFSolver.

Definition at line 293 of file PFSolverPowerPolar.cpp.

Member Data Documentation

◆ mHasLastConvergedSolution

bool DPsim::PFSolverPowerPolar::mHasLastConvergedSolution = false
protected

Definition at line 38 of file PFSolverPowerPolar.h.

◆ mLastConvergedD

CPS::Vector DPsim::PFSolverPowerPolar::mLastConvergedD
protected

Definition at line 37 of file PFSolverPowerPolar.h.

◆ mLastConvergedV

CPS::Vector DPsim::PFSolverPowerPolar::mLastConvergedV
protected

Definition at line 36 of file PFSolverPowerPolar.h.

◆ mQLimitConvertedAtMax

std::map<CPS::TopologicalNode::Ptr, bool> DPsim::PFSolverPowerPolar::mQLimitConvertedAtMax
protected

Buses switched PV->PQ by the Q-limit loop -> pinned at Qmax (true) or Qmin (false)

Definition at line 81 of file PFSolverPowerPolar.h.

◆ mQLimitSwitchCount

std::map<CPS::TopologicalNode::Ptr, CPS::UInt> DPsim::PFSolverPowerPolar::mQLimitSwitchCount
protected

Total PV<->PQ switches per bus over the solve (anti-oscillation cap)

Definition at line 83 of file PFSolverPowerPolar.h.

◆ Pesp

CPS::Vector DPsim::PFSolverPowerPolar::Pesp
protected

Definition at line 32 of file PFSolverPowerPolar.h.

◆ Qesp

CPS::Vector DPsim::PFSolverPowerPolar::Qesp
protected

Definition at line 33 of file PFSolverPowerPolar.h.

◆ sol_D

CPS::Vector DPsim::PFSolverPowerPolar::sol_D
protected

Solution vector of voltage angle.

Definition at line 26 of file PFSolverPowerPolar.h.

◆ sol_P

CPS::Vector DPsim::PFSolverPowerPolar::sol_P
protected

Solution vector of active power.

Definition at line 20 of file PFSolverPowerPolar.h.

◆ sol_Q

CPS::Vector DPsim::PFSolverPowerPolar::sol_Q
protected

Solution vector of reactive power.

Definition at line 22 of file PFSolverPowerPolar.h.

◆ sol_S_complex

CPS::VectorComp DPsim::PFSolverPowerPolar::sol_S_complex
protected

Solution vector of representing sol_P and sol_Q as complex quantity.

Definition at line 30 of file PFSolverPowerPolar.h.

◆ sol_V

CPS::Vector DPsim::PFSolverPowerPolar::sol_V
protected

Solution vector of voltage magnitude.

Definition at line 24 of file PFSolverPowerPolar.h.

◆ sol_V_complex

CPS::VectorComp DPsim::PFSolverPowerPolar::sol_V_complex
protected

Solution vector of representing sol_V and sol_D as complex quantity.

Definition at line 28 of file PFSolverPowerPolar.h.


The documentation for this class was generated from the following files: