14#include "dpsim-models/Components.h"
15#include "dpsim-models/SystemTopology.h"
16#include <dpsim/Scheduler.h>
17#include <dpsim/Solver.h>
39 CPS::TopologicalNode::List mPVBusesOrig;
50 CPS::SparseMatrixCompRow
mY;
64 std::vector<std::shared_ptr<CPS::SP::Ph1::SolidStateTransformer>>
67 std::vector<std::shared_ptr<CPS::SP::Ph1::SynchronGenerator>>
70 std::vector<std::shared_ptr<CPS::SP::Ph1::Load>>
mLoads;
72 std::vector<std::shared_ptr<CPS::SP::Ph1::PiLine>>
mLines;
74 std::vector<std::shared_ptr<CPS::SP::Ph1::Shunt>>
mShunts;
78 std::vector<std::shared_ptr<CPS::SP::Ph1::AvVoltageSourceInverterDQ>>
115 bool keep_last_solution =
false) = 0;
145 CPS::TopologicalNode::Ptr node);
152 CPS::Real
G(
int i,
int j);
154 CPS::Real
B(
int i,
int j);
168 CPS::String
logVector(std::vector<CPS::UInt> indexVector) {
169 std::stringstream result;
170 std::copy(indexVector.begin(), indexVector.end(),
171 std::ostream_iterator<CPS::UInt>(result,
" "));
175 CPS::Task::List
getTasks()
override;
180 CPS::Logger::Level logLevel);
188 CPS::PowerflowBusType powerFlowBusType);
192 void setKeepLastSolution(CPS::Bool keepLastSolution) {
213 void setBaseApparentPowerFallback(CPS::Real baseApparentPowerFallback) {
217 CPS::Real getBaseApparentPowerFallback()
const {
221 void setMaxIterations(CPS::UInt maxIterations) {
230 : Task(solver.
mName +
".Solve"), mSolver(solver) {
231 mModifiedAttributes.push_back(Scheduler::external);
234 void execute(Real time, Int timeStepCount);
Tasks to be defined by every component.
Solver class using the nonlinear powerflow (PF) formulation.
void determinePFBusType()
Determine bus type for all buses.
void reclassifyBuses()
Re-derive index vectors and resize the system after PV<->PQ switching.
CPS::Real mBaseApparentPowerFallback
Fallback base apparent power if no generator or transformer rating is found.
Bool runNewtonRaphson()
Run a single Newton-Raphson solve with the current bus classification.
void resetToOriginalClassification()
Restore the original PV/PQ classification before a fresh solve.
std::vector< std::shared_ptr< CPS::SP::Ph1::Load > > mLoads
Vector of load components.
CPS::Bool mKeepLastSolution
Use last converged solution as initial guess.
CPS::TopologicalNode::List mPQBuses
Vector of nodes characterized as PQ buses.
UInt mNumPQBuses
Number of PQ nodes.
virtual void solveJacobianSystem()
Solve the linearized system mJ*mX = mF into mX; sparse subclass overrides.
void setBaseVoltageStrictTolerance(CPS::Real tolerance)
Override the tolerance between authoritative base-voltage sources within a zone.
UInt mNumVDBuses
Number of PV nodes.
Real mTolerance
Solver tolerance.
CPS::String logVector(std::vector< CPS::UInt > indexVector)
Logging for integer vectors.
std::vector< std::shared_ptr< CPS::SP::Ph1::PiLine > > mLines
Vector of line components.
CPS::Task::List getTasks() override
Get tasks for scheduler.
void assignMatrixNodeIndices()
Assignment of matrix indices for nodes.
std::vector< CPS::UInt > mVDBusIndices
Vector with indices of VD buses.
virtual void setUpJacobianStorage()
Allocate Jacobian storage; dense by default, sparse subclass overrides.
void initializeComponents()
Initialization of individual components.
std::vector< std::shared_ptr< CPS::SP::Ph1::SynchronGenerator > > mSynchronGenerators
Vector of synchronous generator components.
void propagateAndVerifyBaseVoltage()
Determine, verify and propagate each node's base voltage per electrical zone.
std::vector< CPS::UInt > mPQBusIndices
Vector with indices of PQ buses.
void modifyPowerFlowBusComponent(CPS::String name, CPS::PowerflowBusType powerFlowBusType)
Allows to modify the powerflow bus type of a specific component.
std::vector< std::shared_ptr< CPS::SP::Ph1::NetworkInjection > > mExternalGrids
Vector of external grid components.
std::vector< std::shared_ptr< CPS::SP::Ph1::SolidStateTransformer > > mSolidStateTransformers
Vector of solid state transformer components.
std::vector< CPS::UInt > mPVBusIndices
Vector with indices of PV buses.
void setVDNode(CPS::String name)
Set a node to VD using its name.
std::vector< std::shared_ptr< CPS::SP::Ph1::Transformer > > mTransformers
Vector of transformer components.
std::vector< std::shared_ptr< CPS::SP::Ph1::Shunt > > mShunts
Vector of shunt components.
CPS::Bool checkConvergence()
Check whether below tolerance.
CPS::Matrix mJ
Jacobian matrix.
CPS::UInt mMaxIterations
Maximum number of iterations.
CPS::Real componentBaseVoltage(CPS::TopologicalPowerComp::Ptr comp, CPS::TopologicalNode::Ptr node)
Base voltage a single component reports for node, or 0 if unknown.
CPS::Vector mX
Solution vector.
std::vector< std::shared_ptr< CPS::SP::Ph1::AvVoltageSourceInverterDQ > > mAverageVoltageSourceInverters
Vector of average voltage source inverters.
void rebuildBusIndexAggregates()
Rebuild index vectors + counts from the PQ/PV/VD node lists.
CPS::Bool solutionInitialized
Flag whether solution vectors are initialized.
void setEnforceReactiveLimits(CPS::Bool value)
Enable generator reactive-limit enforcement (PV<->PQ outer loop)
CPS::Real mBaseApparentPower
Base power of per-unit system.
void setBaseApparentPower()
Set apparent base power of per-unit system.
virtual void calculateMismatch()=0
Calculate mismatch.
CPS::SparseMatrixCompRow mY
Admittance matrix.
void setBaseVoltageLooseTolerance(CPS::Real tolerance)
Raise for grids with legitimate large voltage drop (e.g. untapped feeders)
CPS::UInt mMaxQLimitSwitchesPerBus
Maximum number of PV<->PQ switches per bus before it is frozen (anti-oscillation)
CPS::Bool solutionComplexInitialized
Flag whether complex solution vectors are initialized.
UInt mNumPVBuses
Number of PV nodes.
CPS::Real B(int i, int j)
Gets the imaginary part of admittance matrix element.
void composeAdmittanceMatrix()
Compose admittance matrix.
CPS::TopologicalNode::List mPQBusesOrig
Original PQ/PV classification (snapshot before Q-limit switching)
CPS::Bool isConverged
Convergence flag.
CPS::Vector mF
Vector of mismatch values.
CPS::UInt mIterations
Actual number of iterations.
CPS::UInt mMaxOuterIterations
Maximum number of Q-limit outer iterations.
virtual CPS::Bool enforceReactiveLimits()
Switch generators violating their Q limits between PV/PQ; base impl is a no-op.
PFSolver(CPS::String name, CPS::SystemTopology system, Real timeStep, CPS::Logger::Level logLevel)
Constructor to be used in simulation examples.
CPS::SystemTopology mSystem
System list.
virtual void calculateJacobian()=0
Calculate the Jacobian.
void setSolverAndComponentBehaviour(Solver::Behaviour behaviour) override
set solver and component to initialization or simulation behaviour
std::map< CPS::TopologicalNode::Ptr, CPS::Real > mBaseVoltageAtNode
Map providing determined base voltages for each node.
virtual void setSolution()=0
Set final solution.
void initialize() override
Initialization of the solver.
CPS::Real mBaseVoltageLooseTolerance
Relative tolerance for non-authoritative (e.g. Load) base-voltage candidates vs. the zone's rating.
virtual void generateInitialSolution(Real time, bool keep_last_solution=false)=0
Generate initial solution for current time step.
CPS::Real mBaseVoltageStrictTolerance
Relative tolerance between authoritative base-voltage sources (generator/transformer/network-injectio...
virtual void updateSolution()=0
Update solution in each iteration.
Bool solvePowerflow()
Solves the powerflow problem.
CPS::Bool mEnforceReactiveLimits
Enforce generator reactive-power limits via PV<->PQ outer-loop switching.
CPS::TopologicalNode::List mVDBuses
Vector of nodes characterized as VD buses.
CPS::TopologicalNode::List mPVBuses
Vector of nodes characterized as PV buses.
UInt mNumUnknowns
Number of unknowns, defining system dimension.
virtual void clearReactiveLimitState()
Clear Q-limit bookkeeping; overridden by PFSolverPowerPolar.
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.
String mName
Name for logging.