Creates the matrax for a base transformation from nodal voltages and branches currents to common-mode and differential-mode equivalents.
(instr)
| 1344 | return instr |
| 1345 | |
| 1346 | def _createConversionMatrices(instr): |
| 1347 | """ |
| 1348 | Creates the matrax for a base transformation from nodal voltages and branches |
| 1349 | currents to common-mode and differential-mode equivalents. |
| 1350 | """ |
| 1351 | pairs, unPaired, dmVars, cmVars = _pairVariables(instr) |
| 1352 | depVars = [var for var in instr.depVars()] |
| 1353 | dim = len(depVars) |
| 1354 | A = sp.zeros(dim) |
| 1355 | n = len(pairs) |
| 1356 | m = len(unPaired) |
| 1357 | # Create conversion matrix: express nodal voltages and branch currents in |
| 1358 | # corresponding differential-mode and common-mode quantities. |
| 1359 | for i in range(n): |
| 1360 | row0 = depVars.index(pairs[i][0]) # nodal voltage or branch current |
| 1361 | row1 = depVars.index(pairs[i][1]) # nodal voltage or branch current |
| 1362 | if pairs[i][0][0] == 'V': |
| 1363 | # transform pair DM and CM voltages into node voltages |
| 1364 | A[row0, i] = 1/2 |
| 1365 | A[row1, i] = -1/2 |
| 1366 | A[row0, i+n] = 1 |
| 1367 | A[row1, i+n] = 1 |
| 1368 | elif pairs[i][0][0] == 'I': |
| 1369 | # transform pair of DM and CM currents into branch currents |
| 1370 | A[row0, i] = 1 |
| 1371 | A[row1, i] = -1 |
| 1372 | A[row0, i+n] = 1/2 |
| 1373 | A[row1, i+n] = 1/2 |
| 1374 | for i in range(m): |
| 1375 | # Unpaired variable, no transformation |
| 1376 | row = depVars.index(unPaired[i]) |
| 1377 | col = 2*n + i |
| 1378 | A[row, col] = 1 |
| 1379 | return pairs, unPaired, dmVars, cmVars, A |
| 1380 | |
| 1381 | def _pairVariables(instr): |
| 1382 | """ |
no test coverage detected