7 Bool isTerminal1NotGrounded,
8 Bool isTerminal2NotGrounded,
10 SPDLOG_LOGGER_DEBUG(mSLog,
"Start stamping conductance...");
12 stampValue(conductance, mat, node1Index, node2Index, isTerminal1NotGrounded,
13 isTerminal2NotGrounded, 1, 0, mSLog);
15 SPDLOG_LOGGER_DEBUG(mSLog,
"Stamping completed.");
20 Bool isTerminal1NotGrounded,
21 Bool isTerminal2NotGrounded,
25 mSLog,
"Start stamping admittance for frequency index {:d}...", freqIdx);
27 stampValue(admittance, mat, node1Index, node2Index, isTerminal1NotGrounded,
28 isTerminal2NotGrounded, maxFreq, freqIdx, mSLog);
30 SPDLOG_LOGGER_DEBUG(mSLog,
"Stamping completed.");
35 UInt node2Index,
Bool isTerminal1NotGrounded,
Bool isTerminal2NotGrounded,
37 if (admittance.rows() != 2 || admittance.cols() != 2)
42 "Start stamping packed real admittance for frequency index {:d}...",
45 stampValue(admittance, mat, node1Index, node2Index, isTerminal1NotGrounded,
46 isTerminal2NotGrounded, maxFreq, freqIdx, mSLog);
48 SPDLOG_LOGGER_DEBUG(mSLog,
"Stamping completed.");
54 Bool isTerminal1NotGrounded,
55 Bool isTerminal2NotGrounded,
57 SPDLOG_LOGGER_DEBUG(mSLog,
"Start stamping conductance matrix...");
59 stampMatrix(conductanceMat, mat, node1Index, node2Index,
60 isTerminal1NotGrounded, isTerminal2NotGrounded, 1, 0, mSLog);
62 SPDLOG_LOGGER_DEBUG(mSLog,
"Stamping completed.");
69 mSLog,
"Start stamping 3x3 conductance matrix between two nodes...");
71 stampMatrixBetween2Nodes(conductanceMat, 3, mat, node1Index, node2Index, 1, 0,
74 SPDLOG_LOGGER_DEBUG(mSLog,
"Stamping completed.");
81 mSLog,
"Start stamping 3x3 conductance matrix from node to ground...");
83 stampMatrixNodeToGround(conductanceMat, 3, mat, nodeIndex, 1, 0, mSLog);
85 SPDLOG_LOGGER_DEBUG(mSLog,
"Stamping completed.");
90 UInt node2Index,
Bool isTerminal1NotGrounded,
Bool isTerminal2NotGrounded,
93 mSLog,
"Start stamping admittance matrix for frequency index {:d}...",
96 stampMatrix(admittanceMat, mat, node1Index, node2Index,
97 isTerminal1NotGrounded, isTerminal2NotGrounded, maxFreq, freqIdx,
100 SPDLOG_LOGGER_DEBUG(mSLog,
"Stamping completed.");
106 Bool isTerminal1NotGrounded,
107 Bool isTerminal2NotGrounded,
110 if (admittanceMat.rows() != 2 * phaseCount ||
111 admittanceMat.cols() != 2 * phaseCount)
114 SPDLOG_LOGGER_DEBUG(mSLog,
115 "Start stamping packed real admittance matrix for "
116 "frequency index {:d}...",
119 for (
UInt row = 0; row < phaseCount; ++row) {
120 for (
UInt col = 0; col < phaseCount; ++col) {
121 const Matrix block = admittanceMat.block(2 * row, 2 * col, 2, 2);
123 if (isTerminal1NotGrounded && isTerminal2NotGrounded) {
124 stampToMatrix(block, mat, node1Index + row, node1Index + col,
125 node2Index + row, node2Index + col, maxFreq, freqIdx,
127 }
else if (isTerminal1NotGrounded) {
128 addToMatrixElement(mat, node1Index + row, node1Index + col, block,
129 maxFreq, freqIdx, mSLog);
130 }
else if (isTerminal2NotGrounded) {
131 addToMatrixElement(mat, node2Index + row, node2Index + col, block,
132 maxFreq, freqIdx, mSLog);
137 SPDLOG_LOGGER_DEBUG(mSLog,
"Stamping completed.");
142 Bool isTerminal1NotGrounded,
Bool isTerminal2NotGrounded,
144 SPDLOG_LOGGER_DEBUG(mSLog,
145 "Start stamping conductance as 3x3 scalar matrix...");
147 stampValueAsScalarMatrix(conductance, 3, mat, node1Index, node2Index,
148 isTerminal1NotGrounded, isTerminal2NotGrounded, 1, 0,
151 SPDLOG_LOGGER_DEBUG(mSLog,
"Stamping completed.");
156 Bool isTerminal1NotGrounded,
Bool isTerminal2NotGrounded,
158 SPDLOG_LOGGER_DEBUG(mSLog,
159 "Start stamping admittance as 3x3 scalar matrix for "
160 "frequency index {:d}...",
163 stampValueAsScalarMatrix(admittance, 3, mat, node1Index, node2Index,
164 isTerminal1NotGrounded, isTerminal2NotGrounded,
165 maxFreq, freqIdx, mSLog);
167 SPDLOG_LOGGER_DEBUG(mSLog,
"Stamping completed.");
172 UInt node2Index,
Bool isTerminal1NotGrounded,
173 Bool isTerminal2NotGrounded,
Int maxFreq,
175 if (isTerminal1NotGrounded && isTerminal2NotGrounded) {
176 stampToMatrix(value, mat, node1Index, node1Index, node2Index, node2Index,
177 maxFreq, freqIdx, mSLog);
178 }
else if (isTerminal1NotGrounded) {
179 addToMatrixElement(mat, node1Index, node1Index, value, maxFreq, freqIdx,
181 }
else if (isTerminal2NotGrounded) {
182 addToMatrixElement(mat, node2Index, node2Index, value, maxFreq, freqIdx,
188void MNAStampUtils::stampMatrix(
const MatrixVar<T> &matrix,
190 UInt node2Index,
Bool isTerminal1NotGrounded,
191 Bool isTerminal2NotGrounded,
Int maxFreq,
193 Int numRows = matrix.rows();
194 Int numCols = matrix.cols();
195 if (numRows != numCols) {
196 throw InvalidArgumentException();
199 if (isTerminal1NotGrounded && isTerminal2NotGrounded) {
200 stampMatrixBetween2Nodes(matrix, numRows, mat, node1Index, node2Index,
201 maxFreq, freqIdx, mSLog);
202 }
else if (isTerminal1NotGrounded) {
203 stampMatrixNodeToGround(matrix, numRows, mat, node1Index, maxFreq, freqIdx,
205 }
else if (isTerminal2NotGrounded) {
206 stampMatrixNodeToGround(matrix, numRows, mat, node2Index, maxFreq, freqIdx,
212void MNAStampUtils::stampMatrixBetween2Nodes(
const MatrixVar<T> &matrix,
218 for (
UInt i = 0; i < sizeOfMatrix; i++) {
219 for (
UInt j = 0; j < sizeOfMatrix; j++) {
220 stampToMatrix(matrix(i, j), mat, node1Index + i, node1Index + j,
221 node2Index + i, node2Index + j, maxFreq, freqIdx, mSLog);
227void MNAStampUtils::stampMatrixNodeToGround(
230 for (
UInt i = 0; i < sizeOfMatrix; i++) {
231 for (
UInt j = 0; j < sizeOfMatrix; j++) {
232 addToMatrixElement(mat, nodeIndex + i, nodeIndex + j, matrix(i, j),
233 maxFreq, freqIdx, mSLog);
239void MNAStampUtils::stampValueAsScalarMatrix(
241 UInt node2Index,
Bool isTerminal1NotGrounded,
Bool isTerminal2NotGrounded,
243 if (isTerminal1NotGrounded && isTerminal2NotGrounded) {
244 for (
UInt i = 0; i < sizeOfScalarMatrix; i++) {
245 stampToMatrix(value, mat, node1Index + i, node1Index + i, node2Index + i,
246 node2Index + i, maxFreq, freqIdx, mSLog);
248 }
else if (isTerminal1NotGrounded) {
249 for (
UInt i = 0; i < sizeOfScalarMatrix; i++) {
250 addToMatrixElement(mat, node1Index + i, node1Index + i, value, maxFreq,
253 }
else if (isTerminal2NotGrounded) {
254 for (
UInt i = 0; i < sizeOfScalarMatrix; i++) {
255 addToMatrixElement(mat, node2Index + i, node2Index + i, value, maxFreq,
266 addToMatrixElement(mat, row1, column1, value, maxFreq, freqIdx, mSLog);
267 addToMatrixElement(mat, row1, column2, -value, maxFreq, freqIdx, mSLog);
268 addToMatrixElement(mat, row2, column1, -value, maxFreq, freqIdx, mSLog);
269 addToMatrixElement(mat, row2, column2, value, maxFreq, freqIdx, mSLog);
274void MNAStampUtils::addToMatrixElement(
SparseMatrixRow &mat, Matrix::Index row,
275 Matrix::Index column,
Real value,
278 SPDLOG_LOGGER_DEBUG(mSLog,
279 "- Adding {:s} to system matrix element ({:d},{:d})",
285void MNAStampUtils::addToMatrixElement(
SparseMatrixRow &mat, Matrix::Index row,
286 Matrix::Index column,
Complex value,
289 SPDLOG_LOGGER_DEBUG(mSLog,
290 "- Adding {:s} to system matrix element ({:d},{:d})",
296void MNAStampUtils::addToMatrixElement(
SparseMatrixRow &mat, Matrix::Index row,
297 Matrix::Index column,
302 "- Adding packed real 2x2 block to system matrix element ({:d},{:d})",
std::shared_ptr< spdlog::logger > Log
static String complexToString(const Complex &num)
static String realToString(const Real &num)
static void stampConductanceAs3x3ScalarMatrix(Real conductance, SparseMatrixRow &mat, UInt node1Index, UInt node2Index, Bool isTerminal1NotGrounded, Bool isTerminal2NotGrounded, const Logger::Log &mSLog)
Stamps conductance as a 3x3 scalar matrix (a diagonal matrix, where all diagonal elements are equal t...
static void stampConductance(Real conductance, SparseMatrixRow &mat, UInt node1Index, UInt node2Index, Bool isTerminal1NotGrounded, Bool isTerminal2NotGrounded, const Logger::Log &mSLog)
static void stampAdmittanceMatrix(const MatrixComp &admittanceMat, SparseMatrixRow &mat, UInt node1Index, UInt node2Index, Bool isTerminal1NotGrounded, Bool isTerminal2NotGrounded, const Logger::Log &mSLog, Int maxFreq=1, Int freqIdx=0)
static void stampAdmittanceAs3x3ScalarMatrix(Complex admittance, SparseMatrixRow &mat, UInt node1Index, UInt node2Index, Bool isTerminal1NotGrounded, Bool isTerminal2NotGrounded, const Logger::Log &mSLog, Int maxFreq=1, Int freqIdx=0)
Stamps admittance as a 3x3 scalar matrix (a diagonal matrix, where all diagonal elements are equal to...
static void stampAdmittance(Complex admittance, SparseMatrixRow &mat, UInt node1Index, UInt node2Index, Bool isTerminal1NotGrounded, Bool isTerminal2NotGrounded, const Logger::Log &mSLog, Int maxFreq=1, Int freqIdx=0)
static void stamp3x3ConductanceMatrixBetween2Nodes(const Matrix &conductanceMat, SparseMatrixRow &mat, UInt node1Index, UInt node2Index, const Logger::Log &mSLog)
static void stampConductanceMatrix(const Matrix &conductanceMat, SparseMatrixRow &mat, UInt node1Index, UInt node2Index, Bool isTerminal1NotGrounded, Bool isTerminal2NotGrounded, const Logger::Log &mSLog)
static void stamp3x3ConductanceMatrixNodeToGround(const Matrix &conductanceMat, SparseMatrixRow &mat, UInt nodeIndex, const Logger::Log &mSLog)
static void addToMatrixElement(SparseMatrixRow &mat, Matrix::Index row, Matrix::Index column, Complex value, Int maxFreq=1, Int freqIdx=0)
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > Matrix
Dense matrix for real numbers.
Eigen::Matrix< VarType, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > MatrixVar
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).