20 mUseSubcomponents = useSubcomponents;
22 **mDirectState = Matrix::Zero(6, 1);
39 Real seriesInductance,
40 Real parallelCapacitance,
41 Real parallelConductance,
42 Real initialCurrent) {
43 const Real epsilon = std::numeric_limits<Real>::epsilon();
45 throw std::invalid_argument(
46 "DC pi-line series resistance must be finite and positive.");
48 throw std::invalid_argument(
49 "DC pi-line series inductance must be finite and positive.");
50 if (!
Math::isFinite(parallelCapacitance) || parallelCapacitance < 0.0 ||
51 (parallelCapacitance > 0.0 &&
53 throw std::invalid_argument(
54 "DC pi-line shunt capacitance must be zero or safely positive.");
55 if (!
Math::isFinite(parallelConductance) || parallelConductance < 0.0 ||
56 (parallelConductance > 0.0 && parallelConductance <=
DOUBLE_EPSILON))
57 throw std::invalid_argument(
58 "DC pi-line shunt conductance must be zero or safely positive.");
60 throw std::invalid_argument(
"DC pi-line initial current must be finite.");
70void EMT::DC::PiLine::validateDCTerminals()
const {
71 for (
UInt terminalIdx = 0; terminalIdx < 2; ++terminalIdx) {
72 const auto terminalNode =
const_cast<PiLine *
>(
this)->node(terminalIdx);
73 if (!terminalNode->isGround() && terminalNode->phaseType() !=
PhaseType::DC)
74 throw std::invalid_argument(
75 "DC pi-line requires DC nodes or ground at both terminals.");
83 throw std::logic_error(
84 "setParameters() must be called before pi-line construction.");
85 validateDCTerminals();
88 if (!mUseSubcomponents)
108 throw std::invalid_argument(
"DC pi-line shunt resistance is non-finite.");
111 mShuntResistor0->setParameters(halfShuntResistance);
118 mShuntResistor1->setParameters(halfShuntResistance);
128 mShuntCapacitor0->setParameters(halfCapacitance);
135 mShuntCapacitor1->setParameters(halfCapacitance);
144 validateDCTerminals();
148 std::abs(voltage0.imag()) > std::numeric_limits<Real>::epsilon() ||
149 std::abs(voltage1.imag()) > std::numeric_limits<Real>::epsilon())
150 throw std::invalid_argument(
151 "DC pi-line initial node voltages must be finite real values.");
153 (**mIntfVoltage)(0, 0) = voltage1.real() - voltage0.real();
156 if (!mUseSubcomponents) {
157 (**mDirectState).setZero();
159 (**mDirectState)(1, 0) = voltage1.real() - voltage0.real() -
161 (**mDirectState)(2, 0) = voltage0.real();
162 (**mDirectState)(4, 0) = voltage1.real();
164 const Real virtualVoltage =
172 if (mUseSubcomponents)
175 mDirectSeriesAdmittance =
176 mDirectInductorAdmittance /
180 mDirectSeriesHistory = (mDirectInductorAdmittance * (**mDirectState)(1, 0) +
181 (**mDirectState)(0, 0)) /
187 if (mUseSubcomponents)
193 mDirectSeriesAdmittance, systemMatrix, mDirectTerminalRows[0],
194 mDirectTerminalRows[1], mDirectTerminalNotGrounded[0],
195 mDirectTerminalNotGrounded[1],
mSLog);
196 const Real shuntAdmittance =
205 if (mUseSubcomponents)
207 if (mDirectTerminalNotGrounded[0])
209 mDirectSeriesHistory - mDirectCapHistory0);
210 if (mDirectTerminalNotGrounded[1])
212 -mDirectSeriesHistory - mDirectCapHistory1);
216 return !mUseSubcomponents ||
221 if (mUseSubcomponents) {
226 if (mDirectTerminalNotGrounded[
terminal]) {
235 (**mIntfVoltage)(0, 0) = 0.0;
237 (**mIntfVoltage)(0, 0) =
240 (**mIntfVoltage)(0, 0) -=
243 throw std::runtime_error(
244 "DC pi-line voltage update produced a non-finite value.");
248 if (!mUseSubcomponents) {
249 (**mIntfCurrent)(0, 0) =
250 mDirectSeriesAdmittance * (**
mIntfVoltage)(0, 0) + mDirectSeriesHistory;
254 if (!(**mIntfCurrent).allFinite())
255 throw std::runtime_error(
256 "DC pi-line current update produced a non-finite value.");
260 if (!mUseSubcomponents) {
261 const Real denominator =
263 mDirectSeriesHistory = (mDirectInductorAdmittance * (**mDirectState)(1, 0) +
264 (**mDirectState)(0, 0)) /
266 mDirectCapHistory0 = -((**mDirectState)(3, 0) +
267 mDirectCapAdmittance * (**mDirectState)(2, 0));
268 mDirectCapHistory1 = -((**mDirectState)(5, 0) +
269 mDirectCapAdmittance * (**mDirectState)(4, 0));
276 if (mUseSubcomponents) {
282 const Real voltage0 =
283 mDirectTerminalNotGrounded[0]
286 const Real voltage1 =
287 mDirectTerminalNotGrounded[1]
290 (**mIntfVoltage)(0, 0) = voltage1;
291 (**mIntfVoltage)(0, 0) -= voltage0;
293 throw std::runtime_error(
294 "DC pi-line voltage update produced a non-finite value.");
297 (**mDirectState)(1, 0) =
299 (**mDirectState)(2, 0) = voltage0;
300 (**mDirectState)(3, 0) = mDirectCapAdmittance * voltage0 + mDirectCapHistory0;
301 (**mDirectState)(4, 0) = voltage1;
302 (**mDirectState)(5, 0) = mDirectCapAdmittance * voltage1 + mDirectCapHistory1;
308 if (!mUseSubcomponents)
309 prevStepDependencies.push_back(mDirectState);
317 attributeDependencies.push_back(leftVector);
320 if (!mUseSubcomponents)
321 modifiedAttributes.push_back(mDirectState);
AttributePointer< Attribute< T > > Ptr
void addMNASubComponent(typename SimPowerComp< Real >::Ptr subc, MNA_SUBCOMP_TASK_ORDER preStepOrder, MNA_SUBCOMP_TASK_ORDER postStepOrder, Bool contributeToRightVector)
Bool mnaHasCompactRightSideVectorStamp() const override
Composite stamps touch only their cached terminal and virtual-node rows.
void mnaAddCompactRightSideVectorStamp(Matrix &rightVector) override
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override
CompositePowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
const Attribute< Real >::Ptr mSeriesResistance
Series resistance [ohm].
Bool mnaHasCompactRightSideVectorStamp() const override final
Composite stamps touch only their cached terminal and virtual-node rows.
void initializeParentFromNodesAndTerminals(Real frequency) override final
void mnaParentAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override final
const Attribute< Real >::Ptr mInitialCurrent
Initial series current from terminal 1 to terminal 0 [A].
void mnaCompUpdateVoltage(const Matrix &leftVector) override final
void mnaParentPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override final
void mnaParentInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override final
void mnaParentApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override final
const Attribute< Real >::Ptr mParallelCapacitance
Total terminal-to-ground shunt capacitance [F].
const Attribute< Real >::Ptr mSeriesInductance
Series inductance [H].
void mnaAddCompactRightSideVectorStamp(Matrix &rightVector) override final
void createSubComponents() override final
Constructs and registers MNA subcomponents; called before collectVirtualNodes so virtual nodes exist ...
void mnaParentPreStep(Real time, Int timeStepCount) override final
void setParameters(Real seriesResistance, Real seriesInductance, Real parallelCapacitance=0.0, Real parallelConductance=0.0, Real initialCurrent=0.0)
void mnaCompUpdateCurrent(const Matrix &leftVector) override final
const Attribute< Real >::Ptr mParallelConductance
Total terminal-to-ground shunt conductance [S].
SimPowerComp< Real >::Ptr clone(String name) override final
Returns a modified copy of the component with the given suffix added to the name and without.
void mnaParentAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override final
void mnaParentApplyRightSideVectorStamp(Matrix &rightVector) override final
PiLine(String uid, String name, Logger::Level logLevel=Logger::Level::off)
const Attribute< String >::Ptr mName
Human readable name.
String uid()
Returns unique id.
AttributeList::Ptr mAttributes
Attribute List.
spdlog::level::level_enum Level
Attribute< Matrix >::Ptr mRightVector
static void stampConductance(Real conductance, 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 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
SimTerminal< Real >::Ptr terminal(UInt index)
void setVirtualNodeNumber(UInt num)
const Attribute< MatrixVar< Real > >::Ptr mIntfVoltage
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< PiLine > make(Args &&...args)
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > Matrix
Dense matrix for real numbers.
std::complex< Real > Complex
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).