14bool isFiniteMatrix(
const Matrix &matrix) {
15 for (Matrix::Index idx = 0; idx < matrix.size(); ++idx) {
39 SPDLOG_LOGGER_INFO(
mSLog,
"Create {} {}", this->
type(), name);
47 :
PQLoad(
name,
name, activePower, reactivePower, nominalVoltage, logLevel) {
51 Real reactivePower,
Real nominalVoltage,
59 Real minimumVoltagePerUnit) {
61 throw std::invalid_argument(
"PQLoad power set points must be finite.");
63 throw std::invalid_argument(
"PQLoad nominal voltage must be positive.");
64 if (!
Math::isFinite(minimumVoltagePerUnit) || minimumVoltagePerUnit <= 0.0)
65 throw std::invalid_argument(
66 "PQLoad minimum per-unit voltage must be positive.");
74 SPDLOG_LOGGER_INFO(
mSLog,
75 "\nActive power={} [W]"
76 "\nReactive power={} [var]"
77 "\nNominal line-to-line voltage={} [V]"
78 "\nMinimum voltage={} [pu]",
97 Matrix voltageQuadrature = Matrix::Zero(3, 1);
98 voltageQuadrature << (voltage(1, 0) - voltage(2, 0)) / std::sqrt(3.0),
99 (voltage(2, 0) - voltage(0, 0)) / std::sqrt(3.0),
100 (voltage(0, 0) - voltage(1, 0)) / std::sqrt(3.0);
101 return voltageQuadrature;
105 if (!isFiniteMatrix(voltage))
106 return Matrix::Zero(3, 1);
108 Matrix voltageNoZeroSequence = voltage;
109 voltageNoZeroSequence.array() -= voltageNoZeroSequence.mean();
113 const Real denominator = std::max(voltageNoZeroSequence.squaredNorm(),
114 minimumVoltage * minimumVoltage);
123 voltageNoZeroSequence.array() -= voltageNoZeroSequence.mean();
127 voltageNoZeroSequence.cwiseProduct(**mIntfCurrent).sum();
129 voltageQuadrature.cwiseProduct(**mIntfCurrent).sum();
139 throw std::invalid_argument(
140 "PQLoad requires a positive nominal voltage when initialized from "
145 MatrixComp initialVoltageABC = MatrixComp::Zero(3, 1);
146 initialVoltageABC(0, 0) =
155 SPDLOG_LOGGER_INFO(
mSLog,
156 "\n--- Initialization ---"
159 "\nActive-power set point: {} [W]"
160 "\nReactive-power set point: {} [var]"
161 "\n--- Initialization finished ---",
182 for (
UInt phase = 0; phase < 3; ++phase) {
195 for (
UInt phase = 0; phase < 3; ++phase) {
196 (**mIntfVoltage)(phase, 0) =
204 (**mRightVector).setZero();
224 modifiedAttributes.push_back(
mNumIter);
233 attributeDependencies.push_back(leftVector);
243 (**mRightVector).setZero();
258 const Real currentScale =
259 std::max({targetCurrent.norm(), currentBase, 1e-12});
260 const Real relativeError =
267 SPDLOG_LOGGER_WARN(
mSLog,
268 "PQLoad corrector reached its iteration limit ({}): "
269 "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 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.
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
Matrix calculateCurrent(const Matrix &voltage) const
Calculates the load current for a given instantaneous abc voltage.
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 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< 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).