19 mConductance = Matrix::Zero(3, 3);
20 mSusceptance = Matrix::Zero(3, 3);
21 SPDLOG_LOGGER_INFO(
mSLog,
"Create {} of type {}", this->
type(), name);
28 mUseSubcomponents = useSubcomponents;
37 mConductance = conductance;
38 mSusceptance = susceptance;
39 SPDLOG_LOGGER_INFO(
mSLog,
"Conductance={} [S] Susceptance={} [Ohm] ",
54 if (std::norm(voltage) <= 0.0)
55 throw std::invalid_argument(
56 "Shunt requires a non-zero terminal voltage when initialized from "
60 const Real conductance = -terminalPower.real() / std::norm(voltage);
61 const Real susceptance = terminalPower.imag() / std::norm(voltage);
66 Real omega = 2. *
PI * frequency;
68 admittance <<
Complex(mConductance(0, 0), mSusceptance(0, 0)), 0, 0, 0,
69 Complex(mConductance(1, 1), mSusceptance(1, 1)), 0, 0, 0,
70 Complex(mConductance(2, 2), mSusceptance(2, 2));
80 if (!mUseSubcomponents) {
83 if (mSusceptance(0, 0) > 0)
84 mCapBranchCurrent = susceptiveAdmittance.real();
85 if (mSusceptance(0, 0) < 0)
86 mIndBranchCurrent = susceptiveAdmittance.real();
91 if (mConductance(0, 0) > 0) {
95 mSubResistor->setParameters(mConductance.inverse());
97 mSubResistor->initializeFromNodesAndTerminals(frequency);
102 if (mSusceptance(0, 0) > 0) {
104 std::make_shared<EMT::Ph3::Capacitor>(**
mName +
"_cap",
mLogLevel);
105 mSubCapacitor->setParameters(mSusceptance * (1 / omega));
108 mSubCapacitor->initializeFromNodesAndTerminals(frequency);
114 if (mSusceptance(0, 0) < 0) {
116 std::make_shared<EMT::Ph3::Inductor>(**
mName +
"_ind",
mLogLevel);
117 mSubInductor->setParameters(-mSusceptance.inverse() * (1 / omega));
120 mSubInductor->initializeFromNodesAndTerminals(frequency);
125 SPDLOG_LOGGER_INFO(
mSLog,
126 "\n--- Initialization from powerflow ---"
127 "\nVoltage across: {:s}"
129 "\nTerminal voltage: {:s}"
130 "\n--- Initialization from powerflow finished ---",
138 if (mUseSubcomponents)
141 if (mSusceptance(0, 0) > 0)
142 mCapEquivalentConductance = (2.0 / (omega * timeStep)) * mSusceptance;
143 if (mSusceptance(0, 0) < 0)
144 mIndEquivalentConductance = (-0.5 * omega * timeStep) * mSusceptance;
145 mCapEquivalentCurrent =
146 -mCapBranchCurrent - mCapEquivalentConductance * **
mIntfVoltage;
147 mIndEquivalentCurrent =
148 mIndEquivalentConductance * **
mIntfVoltage + mIndBranchCurrent;
153 if (mUseSubcomponents)
155 const Matrix conductance =
156 mConductance + mCapEquivalentConductance + mIndEquivalentConductance;
165 for (
Int phase = 0; phase < 3; ++phase) {
167 mCapEquivalentCurrent(phase, 0) +
168 mIndEquivalentCurrent(phase, 0));
180 if (!mUseSubcomponents) {
181 mCapEquivalentCurrent =
182 -mCapBranchCurrent - mCapEquivalentConductance * **
mIntfVoltage;
183 mIndEquivalentCurrent =
184 mIndEquivalentConductance * **
mIntfVoltage + mIndBranchCurrent;
194 attributeDependencies.push_back(leftVector);
206 (**mIntfVoltage)(0, 0) =
208 (**mIntfVoltage)(1, 0) =
210 (**mIntfVoltage)(2, 0) =
215 if (!mUseSubcomponents) {
217 mCapEquivalentConductance * **
mIntfVoltage + mCapEquivalentCurrent;
219 mIndEquivalentConductance * **
mIntfVoltage + mIndEquivalentCurrent;
221 (mConductance + mCapEquivalentConductance + mIndEquivalentConductance) *
223 mCapEquivalentCurrent + mIndEquivalentCurrent);
226 (**mIntfCurrent).setZero();
228 if (mConductance(0, 0) > 0)
230 if (mSusceptance(0, 0) > 0)
232 if (mSusceptance(0, 0) < 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)
void mnaParentPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) final
MNA post-step operations.
void mnaCompUpdateVoltage(const Matrix &leftVector) final
Updates internal voltage variable of the component.
void mnaParentApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
void mnaParentPreStep(Real time, Int timeStepCount) final
MNA pre step operations.
void mnaParentAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) final
Add MNA pre step dependencies.
void mnaParentAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) final
add MNA post-step dependencies
void mnaParentInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
void mnaParentApplyRightSideVectorStamp(Matrix &rightVector) override
void initializeParentFromNodesAndTerminals(Real frequency) final
Initializes component from power flow data.
void setParameters(Real conductance, Real susceptance)
Set shunt specific parameters.
Shunt(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name, component parameters and logging level.
void mnaCompUpdateCurrent(const Matrix &leftVector) final
Updates internal current variable of the component.
const Attribute< String >::Ptr mName
Human readable name.
String uid()
Returns unique id.
String type()
Get component type (cross-platform)
spdlog::level::level_enum Level
static String matrixToString(const Matrix &mat)
static String phasorToString(const Complex &num)
void mnaUpdateCurrent(const Matrix &leftVector) final
void mnaUpdateVoltage(const Matrix &leftVector) final
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.
UInt matrixNodeIndex(UInt nodeIndex)
const Attribute< MatrixVar< Real > >::Ptr mIntfCurrent
SimTerminal< Real >::List mTerminals
const Attribute< MatrixVar< Real > >::Ptr mIntfVoltage
Bool terminalNotGrounded(UInt index)
Complex initialSingleVoltage(UInt index)
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.
#define RMS3PH_TO_PEAK1PH
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > Matrix
Dense matrix for real numbers.
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).