14bool isFinitePhaseVector(
const Matrix &matrix) {
15 return matrix.rows() == 3 && matrix.cols() == 1 &&
37 SPDLOG_LOGGER_INFO(
mSLog,
"Create {} {}", this->
type(), name);
45 :
PQLoad(
name,
name, activePower, reactivePower, nominalVoltage, logLevel) {
49 Real reactivePower,
Real nominalVoltage,
57 Real minimumVoltagePerUnit) {
59 throw std::invalid_argument(
"PQLoad power set points must be finite.");
61 throw std::invalid_argument(
"PQLoad nominal voltage must be positive.");
62 if (!
Math::isFinite(minimumVoltagePerUnit) || minimumVoltagePerUnit <= 0.0)
63 throw std::invalid_argument(
64 "PQLoad minimum per-unit voltage must be positive.");
72 SPDLOG_LOGGER_INFO(
mSLog,
73 "\nActive power={} [W]"
74 "\nReactive power={} [var]"
75 "\nNominal line-to-line voltage={} [V]"
76 "\nMinimum voltage={} [pu]",
95 Matrix voltageQuadrature = Matrix::Zero(3, 1);
96 voltageQuadrature << (voltage(1, 0) - voltage(2, 0)) / std::sqrt(3.0),
97 (voltage(2, 0) - voltage(0, 0)) / std::sqrt(3.0),
98 (voltage(0, 0) - voltage(1, 0)) / std::sqrt(3.0);
99 return voltageQuadrature;
104 if (!isFinitePhaseVector(voltage))
107 const Real phaseA = voltage(0, 0);
108 const Real phaseB = voltage(1, 0);
109 const Real phaseC = voltage(2, 0);
110 const Real meanVoltage = (phaseA + phaseB + phaseC) / 3.0;
111 const Real voltageA = phaseA - meanVoltage;
112 const Real voltageB = phaseB - meanVoltage;
113 const Real voltageC = phaseC - meanVoltage;
114 constexpr Real inverseSqrtThree = 0.57735026918962576451;
115 const Real quadratureA = (voltageB - voltageC) * inverseSqrtThree;
116 const Real quadratureB = (voltageC - voltageA) * inverseSqrtThree;
117 const Real quadratureC = (voltageA - voltageB) * inverseSqrtThree;
121 const Real denominator =
122 std::max(voltageA * voltageA + voltageB * voltageB + voltageC * voltageC,
123 minimumVoltage * minimumVoltage);
127 (activePower * voltageA + reactivePower * quadratureA) / denominator;
129 (activePower * voltageB + reactivePower * quadratureB) / denominator;
131 (activePower * voltageC + reactivePower * quadratureC) / denominator;
138 const Real meanVoltage = voltage.mean();
139 const Real voltageA = voltage(0, 0) - meanVoltage;
140 const Real voltageB = voltage(1, 0) - meanVoltage;
141 const Real voltageC = voltage(2, 0) - meanVoltage;
142 constexpr Real inverseSqrtThree = 0.57735026918962576451;
143 const Real quadratureA = (voltageB - voltageC) * inverseSqrtThree;
144 const Real quadratureB = (voltageC - voltageA) * inverseSqrtThree;
145 const Real quadratureC = (voltageA - voltageB) * inverseSqrtThree;
148 voltageC * current(2, 0);
150 quadratureB * current(1, 0) +
151 quadratureC * current(2, 0);
161 throw std::invalid_argument(
162 "PQLoad requires a positive nominal voltage when initialized from "
167 MatrixComp initialVoltageABC = MatrixComp::Zero(3, 1);
168 initialVoltageABC(0, 0) =
177 SPDLOG_LOGGER_INFO(
mSLog,
178 "\n--- Initialization ---"
181 "\nActive-power set point: {} [W]"
182 "\nReactive-power set point: {} [var]"
183 "\n--- Initialization finished ---",
204 for (
UInt phase = 0; phase < 3; ++phase) {
216 for (
UInt phase = 0; phase < 3; ++phase)
222 (**mIntfVoltage).setZero();
226 for (
UInt phase = 0; phase < 3; ++phase) {
227 (**mIntfVoltage)(phase, 0) =
253 modifiedAttributes.push_back(
mNumIter);
262 attributeDependencies.push_back(leftVector);
272 (**mRightVector).setZero();
288 const Real currentScale =
289 std::max({targetCurrent.norm(), currentBase, 1e-12});
291 const Real currentError =
292 std::hypot(targetCurrent(0, 0) - current(0, 0),
293 std::hypot(targetCurrent(1, 0) - current(1, 0),
294 targetCurrent(2, 0) - current(2, 0)));
295 const Real relativeError = currentError / currentScale;
301 SPDLOG_LOGGER_WARN(
mSLog,
302 "PQLoad corrector reached its iteration limit ({}): "
303 "relative current residual={} (tolerance={}).",
AttributePointer< Attribute< T > > Ptr
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
const Attribute< Real >::Ptr mActivePower
Three-phase total active-power set point [W], positive for consumption.
void mnaAddCompactRightSideVectorStamp(Matrix &rightVector) override
void correctorStep() override
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override
void updateVoltage(const Matrix &leftVector) override
void mnaCompPreStep(Real time, Int timeStepCount) override
void updateMeasuredPower()
Updates the instantaneous measured powers.
void setParameters(Real activePower, Real reactivePower, Real nominalVoltage, Real minimumVoltagePerUnit=0.1)
Sets total three-phase P/Q, nominal line-to-line voltage and voltage floor.
const Attribute< Real >::Ptr mMeasuredReactivePower
Instantaneous measured three-phase reactive power [var].
PQLoad(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name and logging level.
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
SimPowerComp< Real >::Ptr clone(String name) override
Returns a modified copy of the component with the given suffix added to the name and without.
static Matrix quadratureVoltage(const Matrix &voltage)
Calculates the voltage vector shifted by 90 degrees for positive sequence.
void mnaCompUpdateVoltage(const Matrix &leftVector) override
const Attribute< Real >::Ptr mReactivePower
bool requiresIteration() override
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
void initializeFromNodesAndTerminals(Real frequency) override
Initializes set points and instantaneous values from terminal data.
const Attribute< Real >::Ptr mNomVoltage
Nominal line-to-line RMS voltage [V].
const Attribute< Real >::Ptr mMeasuredActivePower
Instantaneous measured three-phase active power [W].
void mnaCompAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
const Attribute< Real >::Ptr mMinimumVoltagePerUnit
Minimum line-to-line voltage in per unit of mNomVoltage.
MatrixFixedSize< 3, 1 > calculateCurrent(const Matrix &voltage) const
Calculates the load current for a given instantaneous abc voltage.
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
String uid()
Returns unique id.
String type()
Get component type (cross-platform)
AttributeList::Ptr mAttributes
Attribute List.
spdlog::level::level_enum Level
static String matrixToString(const Matrix &mat)
MNASimPowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
Attribute< Matrix >::Ptr mRightVector
Attribute< Int >::Ptr mNumIter
static Real realFromVectorElement(const Matrix &mat, Matrix::Index row)
static void setVectorElement(Matrix &mat, Matrix::Index row, Complex value, Int maxFreq=1, Int freqIdx=0, Matrix::Index colOffset=0)
static void addToVectorElement(Matrix &mat, Matrix::Index row, Complex value, Int maxFreq=1, Int freqIdx=0)
static bool isFinite(Real value)
UInt matrixNodeIndex(UInt nodeIndex)
const Attribute< MatrixVar< Real > >::Ptr mIntfCurrent
SimTerminal< Real >::List mTerminals
const Attribute< MatrixVar< Real > >::Ptr mIntfVoltage
std::shared_ptr< SimPowerComp< VarType > > Ptr
Bool terminalNotGrounded(UInt index)
Complex initialSingleVoltage(UInt index)
void updateMatrixNodeIndices()
void setTerminalNumber(UInt num)
Logger::Level mLogLevel
Component logger control for internal variables.
bool mParametersSet
Flag indicating that parameters are set via setParameters() function.
Logger::Log mSLog
Component logger.
static std::shared_ptr< PQLoad > make(Args &&...args)
#define RMS3PH_TO_PEAK1PH
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > Matrix
Dense matrix for real numbers.
Eigen::Matrix< Real, rows, cols, Eigen::ColMajor > MatrixFixedSize
Dense matrix for real numbers with fixed dimension.
Eigen::Matrix< Complex, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > MatrixComp
Dense matrix for complex numbers.
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).