8#include <Eigen/Eigenvalues>
80 return {
"psi_sd",
"psi_sq",
"psi_dr",
81 "psi_qr",
"mechanical_speed",
"electrical_angle"};
85 Real nominalFrequency,
Int polePairs,
Real statorResistance,
86 Real rotorResistance,
Real statorInductance,
Real rotorInductance,
87 Real mutualInductance,
Real rotorInertia,
Real mechanicalDamping,
88 Real mechanicalTorque,
Real initialElectricalAngle,
89 Bool autoInitializeMechanicalTorque) {
91 if (nominalFrequency <= 0.0)
92 throw std::invalid_argument(
"Nominal frequency must be positive.");
94 throw std::invalid_argument(
"The number of pole pairs must be positive.");
96 if (statorResistance < 0.0)
97 throw std::invalid_argument(
"Stator resistance is invalid.");
98 if (rotorResistance < 0.0)
99 throw std::invalid_argument(
"Rotor resistance is invalid.");
101 if (statorInductance <= 0.0 || rotorInductance <= 0.0 ||
102 mutualInductance <= 0.0)
103 throw std::invalid_argument(
"Motor winding inductances must be positive.");
105 if (statorInductance <= mutualInductance ||
106 rotorInductance <= mutualInductance)
107 throw std::invalid_argument(
108 "Each total winding inductance must exceed its mutual inductance.");
110 if (rotorInertia <= 0.0)
111 throw std::invalid_argument(
"Rotor inertia must be positive.");
112 if (mechanicalDamping < 0.0)
113 throw std::invalid_argument(
"Mechanical damping must be non-negative.");
120 mLm = mutualInductance;
121 mLs = statorInductance;
150 throw std::invalid_argument(
151 "The induction motor inductance matrix is singular.");
160 if (!decomposition.isInvertible())
161 throw std::invalid_argument(
162 "The induction motor inverse inductance matrix is singular.");
167 if (eigenSolver.info() != Eigen::Success ||
168 eigenSolver.eigenvalues().minCoeff() <= 0.0)
169 throw std::invalid_argument(
170 "The induction motor inductance matrix is not positive definite.");
185 Real relativeStep,
Real absoluteStep) {
186 if (relativeStep <= 0.0)
187 throw std::invalid_argument(
188 "Relative finite-difference step must be positive.");
189 if (absoluteStep <= 0.0)
190 throw std::invalid_argument(
191 "Absolute finite-difference step must be positive.");
198 Real electricalAngle)
const {
199 electricalAngle = std::remainder(electricalAngle, 2.0 *
PI);
202 const Real scale = std::sqrt(2.0 / 3.0);
204 transform.row(0) << scale * std::cos(electricalAngle),
205 scale * std::cos(electricalAngle - 2.0 *
PI / 3.0),
206 scale * std::cos(electricalAngle + 2.0 *
PI / 3.0);
208 transform.row(1) << -scale * std::sin(electricalAngle),
209 -scale * std::sin(electricalAngle - 2.0 *
PI / 3.0),
210 -scale * std::sin(electricalAngle + 2.0 *
PI / 3.0);
217 Real electricalAngle)
const {
226 throw std::invalid_argument(
227 "Induction motor state vector has an invalid dimension.");
229 throw std::invalid_argument(
230 "Induction motor input vector has an invalid dimension.");
239 const Real statorCurrentD = current(0, 0);
240 const Real statorCurrentQ = current(1, 0);
246 windingVoltage(0, 0) = voltageDq(0, 0);
247 windingVoltage(1, 0) = voltageDq(1, 0);
248 windingVoltage(2, 0) = 0.0;
249 windingVoltage(3, 0) = 0.0;
253 fluxDerivative += windingVoltage;
254 fluxDerivative(2, 0) -= electricalSpeed * flux(3, 0);
255 fluxDerivative(3, 0) += electricalSpeed * flux(2, 0);
257 const Real electricalTorque =
259 (flux(
PsiSd, 0) * statorCurrentQ - flux(
PsiSq, 0) * statorCurrentD);
280 throw std::invalid_argument(
281 "Induction motor state vector has an invalid dimension.");
287 statorCurrentDq << current(0, 0), current(1, 0);
370 statorCurrentDq << current(0, 0), current(1, 0);
372 const Real electricalTorque =
374 (flux(
PsiSd, 0) * current(1, 0) - flux(
PsiSq, 0) * current(0, 0));
376 const Real electricalPower = voltageDq(0, 0) * statorCurrentDq(0, 0) +
377 voltageDq(1, 0) * statorCurrentDq(1, 0);
378 const Real reactivePower = voltageDq(1, 0) * statorCurrentDq(0, 0) -
379 voltageDq(0, 0) * statorCurrentDq(1, 0);
380 const Real mechanicalLoadTorque =
404 throw std::logic_error(
405 "setParameters() must be called before initialization.");
408 const Matrix initialVoltageAbc = initialVoltagePhasor.real();
415 const Complex voltageSpacePhasor = voltageDq(0, 0);
419 !std::isfinite(terminalPower.real()) ||
420 !std::isfinite(terminalPower.imag()))
421 throw std::logic_error(
422 "Cannot derive induction-motor steady state from empty or invalid "
427 const Complex statorCurrentPhasor =
428 std::conj(terminalPower / voltageSpacePhasor);
434 const Real synchronousElectricalSpeed = 2.0 *
PI * frequency;
435 const Complex statorFluxPhasor =
437 Complex(0.0, synchronousElectricalSpeed);
438 const Complex rotorCurrentPhasor =
439 (statorFluxPhasor -
mLs * statorCurrentPhasor) /
mLm;
440 const Complex rotorFluxPhasor =
441 mLm * statorCurrentPhasor +
mLr_dash * rotorCurrentPhasor;
444 throw std::logic_error(
445 "Cannot derive induction-motor slip: rotor flux is zero.");
449 const Complex slipCoefficient =
Complex(0.0, 1.0) * rotorFluxPhasor;
450 const Real slipElectricalSpeed =
451 -std::real(std::conj(slipCoefficient) *
453 std::norm(slipCoefficient);
454 const Complex rotorEquationResidual =
456 Complex(0.0, slipElectricalSpeed) * rotorFluxPhasor;
457 if (std::abs(rotorEquationResidual) >
459 throw std::logic_error(
460 "Power-flow operating point is inconsistent with the configured "
461 "induction-motor parameters.");
463 const Real mechanicalSpeed =
464 (synchronousElectricalSpeed - slipElectricalSpeed) /
466 if (!std::isfinite(mechanicalSpeed) || mechanicalSpeed <= 0.0)
467 throw std::logic_error(
468 "Power-flow operating point implies a non-positive induction-motor "
473 x0(
PsiSd, 0) = statorFluxPhasor.real();
474 x0(
PsiSq, 0) = statorFluxPhasor.imag();
475 x0(
PsiRotorD, 0) = rotorFluxPhasor.real();
476 x0(
PsiRotorQ, 0) = rotorFluxPhasor.imag();
480 const Matrix initialCurrent =
482 const Real initialTorque =
484 x0(
PsiSq, 0) * initialCurrent(0, 0));
505 "Initialized induction motor at the PF operating point: "
506 "P={:.6g} W, Q={:.6g} var, speed={:.6g} rad/s, slip={:.6g}, "
507 "shaft torque={:.6g} Nm.",
517 return stateDerivative;
Real mJacobianRelativeStep
Attribute< Real >::Ptr mSlip
void rebuildMachineMatrices()
Bool mAutoInitializeMechanicalTorque
Matrix mStateOffsetScratch
void evaluateOutput(const Matrix &x, const Matrix &u, Matrix &output) const
static constexpr Int mElectricalStateSize
Real mJacobianAbsoluteStep
static constexpr Int mStateSize
Attribute< Real >::Ptr mMechanicalSpeedPu
Attribute< Real >::Ptr mStatorVoltageMagnitude
Real mInitialElectricalAngle
std::vector< String > getLocalStateNames() const override
Attribute< Real >::Ptr mMechanicalSpeedLog
Attribute< Real >::Ptr mElectricalPower
Matrix mInverseInductanceMatrix
Matrix mOutputOffsetScratch
void initializeFromNodesAndTerminals(Real frequency) override
Initializes Component variables according to power flow data stored in Nodes.
Bool updateComponentParameters() override
Attribute< Real >::Ptr mReactivePower
Attribute< Real >::Ptr mStatorCurrentD
void evaluateStateDerivative(const Matrix &x, const Matrix &u, Matrix &stateDerivative) const
Attribute< Real >::Ptr mElectricalAngleLog
Attribute< Real >::Ptr mMechanicalLoadTorque
void setParameters(Real nominalFrequency, Int polePairs, Real statorResistance, Real rotorResistance, Real statorInductance, Real rotorInductance, Real mutualInductance, Real rotorInertia, Real mechanicalDamping, Real mechanicalTorque, Real initialElectricalAngle=0.0, Bool autoInitializeMechanicalTorque=true)
Configure the sixth-order machine.
Matrix mJacobianOutputMinus
Real mNominalMechanicalSpeed
Matrix mResistiveFluxMatrix
Attribute< Real >::Ptr mStatorCurrentMagnitude
Matrix getInterfaceVoltage() const
SSN_InductionMotor(String uid, String name, Logger::Level logLevel=Logger::Level::off)
void updateLogAttributes(const Matrix &u) const override
Update derived attributes used for logging/inspection.
Matrix mJacobianPerturbation
Pre-sized scratch storage for the per-step finite-difference Jacobian.
void setMechanicalTorque(Real mechanicalTorque)
Matrix mJacobianOutputPlus
Matrix getInterfaceCurrent() const
Matrix mJacobianDerivativeMinus
static constexpr Int mOutputSize
Attribute< Real >::Ptr mStatorVoltageQ
Matrix getStateDerivative() const
void buildStateSpaceModel(const Matrix &x, const Matrix &u, Matrix &A, Matrix &B, Matrix &C, Matrix &D, Matrix &E, Matrix &F) const
Matrix mJacobianInputPerturbation
Attribute< Real >::Ptr mElectricalTorque
Matrix mStateDerivativeScratch
MatrixFixedSize< 3, 2 > getInverseParkTransformMatrix(Real electricalAngle) const
Attribute< Real >::Ptr mStatorVoltageD
MatrixFixedSize< 2, 3 > getParkTransformMatrix(Real electricalAngle) const
void setNumericalLinearizationParameters(Real relativeStep, Real absoluteStep)
static constexpr Int mInputSize
void calculateNumericalJacobians(const Matrix &x, const Matrix &u, Matrix &A, Matrix &B, Matrix &C, Matrix &D) const
Attribute< Real >::Ptr mStatorCurrentQ
Matrix mJacobianDerivativePlus
TwoTerminalVTypeVariableSSNComp(String uid, String name, Logger::Level logLevel=Logger::Level::off)
MatrixComp buildInitialInputFromNodes(Real frequency) override final
const Attribute< Matrix >::Ptr mX
void calculateHistoryVector(Matrix &history) const override final
void setStateOffset(const Matrix &E)
void setParameters(const Matrix &A, const Matrix &B, const Matrix &C, const Matrix &D)
void updateStateSpaceModel() override final
Hook for variable/time-varying SSN components.
void setOutputOffset(const Matrix &F)
String uid()
Returns unique id.
AttributeList::Ptr mAttributes
Attribute List.
spdlog::level::level_enum Level
const Attribute< MatrixVar< Real > >::Ptr mIntfCurrent
SimTerminal< Real >::Ptr terminal(UInt index)
const Attribute< MatrixVar< Real > >::Ptr mIntfVoltage
bool mParametersSet
Flag indicating that parameters are set via setParameters() function.
Logger::Log mSLog
Component logger.
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.