30 "direct_source_voltage",
Matrix::Zero(3, 1))),
112 copy->setFilterParameters(
mLf,
mCf,
mRf);
130 throw std::invalid_argument(
"GFL parameters must be finite.");
133 throw std::invalid_argument(
134 "GFL nominal angular frequency must be positive.");
136 if (sysVoltNom <= 0.0)
137 throw std::invalid_argument(
"GFL nominal voltage must be positive.");
148 SPDLOG_LOGGER_INFO(
mSLog,
149 "GFL general parameters:"
151 "\n omega_nom = {} rad/s"
163 throw std::logic_error(
"GFL::setParameters() must be called before "
164 "setControllerParameters().");
170 throw std::invalid_argument(
"GFL controller parameters must be finite.");
173 throw std::invalid_argument(
"GFL PLL integral gain must be non-zero.");
175 if (kiPowerCtrl == 0.0)
176 throw std::invalid_argument(
177 "GFL power-controller integral gain must be non-zero.");
179 if (kiCurrCtrl == 0.0)
180 throw std::invalid_argument(
181 "GFL current-controller integral gain must be non-zero.");
183 if (omegaCutoff <= 0.0)
184 throw std::invalid_argument(
185 "GFL power-filter cutoff frequency must be positive.");
201 mPLL->composeStateSpaceMatrices();
212 throw std::invalid_argument(
"GFL filter parameters must be finite.");
215 throw std::invalid_argument(
"GFL filter inductance Lf must be positive.");
218 throw std::invalid_argument(
"GFL filter capacitance Cf must be positive.");
221 throw std::invalid_argument(
222 "GFL filter resistance Rf must be non-negative.");
236 SPDLOG_LOGGER_INFO(
mSLog,
237 "GFL filter parameters:"
252 throw std::invalid_argument(
"GFL initial state values must be finite.");
264 gammaDInit, gammaQInit);
272 const Real k = std::sqrt(2.0 / 3.0);
273 const Real c = std::cos(theta);
274 const Real s = std::sin(theta);
275 const Real c120 = 0.5 * std::sqrt(3.0);
277 transform << k * c, k * (-0.5 * c + c120 * s), k * (-0.5 * c - c120 * s),
279 -k * s, k * (0.5 * s + c120 * c), k * (0.5 * s - c120 * c);
289 const Real k = std::sqrt(2.0 / 3.0);
290 const Real c = std::cos(theta);
291 const Real s = std::sin(theta);
292 const Real c120 = 0.5 * std::sqrt(3.0);
294 transform << k * c, -k * s,
296 k * (-0.5 * c + c120 * s), k * (0.5 * s + c120 * c),
298 k * (-0.5 * c - c120 * s), k * (0.5 * s - c120 * c);
305 const Matrix &fabc)
const {
313 const Matrix &fdq)
const {
349 const Real phiPLL = (**mPllOutput)(1, 0);
357 throw std::logic_error(
358 "GFL::setParameters() must be called before initialization.");
361 throw std::logic_error(
362 "GFL::setFilterParameters() must be called before initialization.");
365 throw std::logic_error(
366 "GFL::setControllerParameters() must be called before initialization.");
368 const Real omega = 2.0 *
PI * frequency;
383 if (std::abs(vPcc(0, 0)) < 1e-12)
384 throw std::runtime_error(
"GFL cannot initialize from zero PCC voltage.");
391 const Complex iGridA = std::conj((2.0 / 3.0) * sRef / vPcc(0, 0));
395 iGrid(0, 0) = iGridA;
404 const MatrixComp vInductorInput = vPcc + j * omega *
mLf * iF;
448 const Real theta0 = std::arg(vPcc(0, 0));
450 const Matrix vPccAbc0 = vPcc.real();
452 const Matrix iGridAbc0 = iGrid.real();
454 const Matrix vSourceAbc0 = vSource.real();
475 Matrix pllStateInit = Matrix::Zero(2, 1);
477 Matrix pllOutputInit = Matrix::Zero(2, 1);
479 pllStateInit(0, 0) = theta0;
483 pllOutputInit = pllStateInit;
485 mPLL->setInitialValues(**
mVcq, pllStateInit, pllOutputInit);
491 const Real phiDInit =
494 const Real phiQInit =
501 const Real gammaDInit =
504 const Real gammaQInit =
508 gammaDInit, gammaQInit);
518 "\n--- EMT_Ph3_GFL initialization ---"
519 "\nPCC voltage abc: {:s}"
520 "\nGrid injection abc: {:s}"
521 "\nFilter current abc: {:s}"
522 "\nSource voltage abc: {:s}"
523 "\nP/Q init: [{:.6e}, {:.6e}]"
524 "\nVc dq: [{:.6e}, {:.6e}]"
525 "\nIgrid dq: [{:.6e}, {:.6e}]"
526 "\n--- Initialization finished ---",
540 (timeStep / (2. *
mLf)) * Matrix::Identity(3, 3);
542 (2. *
mCf / timeStep) * Matrix::Identity(3, 3);
561 mPLL->setSimulationParameters(timeStep);
566 mMnaTasks.push_back(std::make_shared<ControlPreStep>(*
this));
568 mMnaTasks.push_back(std::make_shared<ControlStep>(*
this));
581 systemMatrix, sourceNode, filterNode,
589 for (
UInt phase = 0; phase < 3; ++phase) {
591 sourceCurrent + phase, 1.);
593 sourceNode + phase, 1.);
603 for (
UInt phase = 0; phase < 3; ++phase) {
622 mPLL->signalAddPreStepDependencies(prevStepDependencies,
623 attributeDependencies, modifiedAttributes);
626 prevStepDependencies, attributeDependencies, modifiedAttributes);
631 mPLL->signalPreStep(time, timeStepCount);
642 mPLL->signalAddStepDependencies(prevStepDependencies, attributeDependencies,
646 prevStepDependencies, attributeDependencies, modifiedAttributes);
655 modifiedAttributes.push_back(
mVsref);
661 Real thetaMeasurement =
mPLL->mOutputPrev->get()(0, 0);
663 if (timeStepCount > 0) {
664 const Real phiPLLPrev =
mPLL->mOutputPrev->get()(1, 0);
668 thetaMeasurement +=
mTimeStep * omegaPLLPrev;
674 mPLL->signalStep(time, timeStepCount);
679 const Real thetaPLL = (**mPllOutput)(0, 0);
681 const Real phiPLL = (**mPllOutput)(1, 0);
698 prevStepDependencies.push_back(
mVsref);
706 attributeDependencies.push_back(
mPLL->mOutputPrev);
721 ->mnaPreStep(time, timeStepCount);
742 attributeDependencies.push_back(leftVector);
769 Matrix terminalVoltage = Matrix::Zero(3, 1);
771 for (
UInt phase = 0; phase < 3; ++phase)
772 terminalVoltage(phase, 0) =
780 for (
UInt phase = 0; phase < 3; ++phase)
801 (**mIntfVoltage).setZero();
804 (**mIntfVoltage)(0, 0) =
807 (**mIntfVoltage)(1, 0) =
810 (**mIntfVoltage)(2, 0) =
AttributePointer< Attribute< T > > Ptr
void addMNASubComponent(typename SimPowerComp< Real >::Ptr subc, MNA_SUBCOMP_TASK_ORDER preStepOrder, MNA_SUBCOMP_TASK_ORDER postStepOrder, Bool contributeToRightVector)
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override
CompositePowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
Bool mManualInitialStatesSet
Matrix mDirectCapacitorCurrent
void setInitialStateValues(Real pInit, Real qInit, Real phiDInit, Real phiQInit, Real gammaDInit, Real gammaQInit)
const Attribute< Real >::Ptr mIgridQ
MatrixFixedSize< 2, 1 > parkTransformPowerInvariant(Real theta, const Matrix &fabc) const
const Attribute< Matrix >::Ptr mPowerctrlStates
const Attribute< Matrix >::Ptr mPowerctrlInputs
Power-controller logging vectors.
void controlPreStep(Real time, Int timeStepCount)
void mnaParentPreStep(Real time, Int timeStepCount) override
void updateMeasurementAttributes(Real theta)
void addControlStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes)
Matrix mDirectInductorVoltage
SimPowerComp< Real >::Ptr clone(String name) override
Returns a modified copy of the component with the given suffix added to the name and without.
void mnaCompUpdateCurrent(const Matrix &leftVector) override
void mnaCompUpdateVoltage(const Matrix &leftVector) override
std::shared_ptr< EMT::Ph3::Capacitor > mSubCapacitorF
void addControlPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes)
const Attribute< Matrix >::Ptr mPowerctrlOutputs
void setFilterParameters(Real lf, Real cf, Real rf)
Filter parameters. No Rc exists in this model.
Matrix mDirectInductorConductance
const Attribute< Real >::Ptr mVcd
PCC voltage in controller dq frame.
const Attribute< Real >::Ptr mVcq
Matrix mDirectInductorCurrent
void setControllerParameters(Real kpPLL, Real kiPLL, Real kpPowerCtrl, Real kiPowerCtrl, Real kpCurrCtrl, Real kiCurrCtrl, Real omegaCutoff)
Controller parameters.
const Attribute< Real >::Ptr mPInst
Instantaneous controller-frame active/reactive power.
Bool mControllerParametersSet
Matrix mDirectCapacitorHistory
void setParameters(Real sysOmega, Real sysVoltNom, Real pRef, Real qRef)
General operating parameters.
const Attribute< Matrix >::Ptr mPllOutput
PLL output [theta, phi_pll].
void mnaParentPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
std::shared_ptr< Signal::PLL > mPLL
std::shared_ptr< EMT::Ph3::Inductor > mSubInductorF
const Attribute< Real >::Ptr mOmegaPLL
Estimated PLL angular frequency [rad/s].
Matrix mDirectSourceVoltage
void mnaParentApplyRightSideVectorStamp(Matrix &rightVector) override
void initializeParentFromNodesAndTerminals(Real frequency) override
const Attribute< Matrix >::Ptr mVs
Actual controlled source voltage.
std::shared_ptr< Signal::PowerControllerVSI > mPowerControllerVSI
const Attribute< Matrix >::Ptr mVsref
Controlled source voltage reference in abc instantaneous peak values.
std::shared_ptr< EMT::Ph3::VoltageSource > mSubControlledVoltageSource
const Attribute< Real >::Ptr mIgridD
Positive converter-to-grid current in controller dq frame.
void mnaParentAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
MatrixFixedSize< 3, 1 > inverseParkTransformPowerInvariant(Real theta, const Matrix &fdq) const
void controlStep(Real time, Int timeStepCount)
std::shared_ptr< EMT::Ph3::Resistor > mSubResistorF
Matrix mDirectCapacitorConductance
const Attribute< Matrix >::Ptr mDirectSourceVoltageAttr
Storage for the source voltage in direct mode, exposed through mVs.
void mnaParentApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
MatrixFixedSize< 2, 3 > getParkTransformMatrixPowerInvariant(Real theta) const
void updatePowerAndFrequencyAttributes()
Matrix mDirectInductorHistory
Matrix mDirectResistorConductance
MatrixFixedSize< 3, 2 > getInverseParkTransformMatrixPowerInvariant(Real theta) const
void mnaParentInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
void mnaParentAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
const Attribute< Real >::Ptr mQInst
Bool mFilterParametersSet
GFL(String uid, String name, Logger::Level logLevel=Logger::Level::off)
const Attribute< String >::Ptr mName
Human readable name.
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)
Attribute< Matrix >::Ptr mRightVector
static void stampConductanceMatrix(const Matrix &conductanceMat, SparseMatrixRow &mat, UInt node1Index, UInt node2Index, Bool isTerminal1NotGrounded, Bool isTerminal2NotGrounded, const Logger::Log &mSLog)
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 Matrix singlePhaseParameterToThreePhase(Real parameter)
To convert single phase parameters to symmetrical three phase ones.
static bool isFinite(Real value)
static void addToMatrixElement(SparseMatrixRow &mat, Matrix::Index row, Matrix::Index column, Complex value, Int maxFreq=1, Int freqIdx=0)
UInt matrixNodeIndex(UInt nodeIndex)
const Attribute< MatrixVar< Real > >::Ptr mIntfCurrent
SimTerminal< Real >::List mTerminals
void setVirtualNodeNumber(UInt num)
const Attribute< MatrixVar< Real > >::Ptr mIntfVoltage
MatrixComp initialVoltage(UInt index)
SimNode< Real >::Ptr virtualNode(UInt index)
std::shared_ptr< SimPowerComp< VarType > > Ptr
SimNode< Real >::List mVirtualNodes
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< VoltageSource > make(Args &&...args)
#define RMS3PH_TO_PEAK1PH
#define PEAK1PH_TO_RMS3PH
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.
std::complex< Real > Complex
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).