MCPcopy Create free account
hub / github.com/SLiCAP/SLiCAP_python / _makeMatrices

Function _makeMatrices

SLiCAP/SLiCAPmatrices.py:105–328  ·  view source on GitHub ↗

Returns the MNA matrix and the vector with dependent variables of a circuit. The entries in the matrix depend on the instruction type. :param cir: Circuit of which the matrices need to be returned. :type cir: SLiCAPprotos.circuit :param instr: SLiCAP instruction object

(instr)

Source from the content-addressed store, hash-verified

103
104
105def _makeMatrices(instr):
106 """
107 Returns the MNA matrix and the vector with dependent variables of a circuit.
108 The entries in the matrix depend on the instruction type.
109
110 :param cir: Circuit of which the matrices need to be returned.
111 :type cir: SLiCAPprotos.circuit
112
113 :param instr: SLiCAP instruction object
114
115 - key : parameter name (sympy.Symbol)
116 - value: numeric value of sympy expression
117
118 :type instr: SLiCAPinstruction.instruction()
119
120 :return: tuple with two sympy matrices:
121
122 #. MNA matrix M
123 #. Vector with dependent variables Dv
124 :return type: tuple
125 """
126 cir = instr.circuit
127 parDefs = instr.parDefs
128 numeric = instr.numeric
129 substitute = instr.substitute
130 varIndex = _createDepVarIndex(cir)
131 dim = len(list(varIndex.keys()))
132 Dv = sp.Matrix([0 for i in range(dim)])
133 M = sp.zeros(dim)
134 for i in range(len(cir.dep_vars)):
135 Dv[i] = sp.Symbol(cir.dep_vars[i])
136 for el in list(cir.elements.keys()):
137 elmt = cir.elements[el]
138 if elmt.model == 'C':
139 pos0 = varIndex[elmt.nodes[0]]
140 pos1 = varIndex[elmt.nodes[1]]
141 value = _getValue(elmt, 'value', numeric, parDefs, substitute)
142 M[pos0, pos0] += value * ini.laplace
143 M[pos0, pos1] -= value * ini.laplace
144 M[pos1, pos0] -= value * ini.laplace
145 M[pos1, pos1] += value * ini.laplace
146 elif elmt.model == 'L':
147 dVarPos = varIndex['I_' + elmt.refDes]
148 pos0 = varIndex[elmt.nodes[0]]
149 pos1 = varIndex[elmt.nodes[1]]
150 value = _getValue(elmt, 'value', numeric, parDefs, substitute)
151 M[pos0, dVarPos] += 1
152 M[pos1, dVarPos] -= 1
153 M[dVarPos, pos0] += 1
154 M[dVarPos, pos1] -= 1
155 M[dVarPos, dVarPos] -= value * ini.laplace
156 elif elmt.model == 'R':
157 pos0 = varIndex[elmt.nodes[0]]
158 pos1 = varIndex[elmt.nodes[1]]
159 value = float2rational(
160 1/_getValue(elmt, 'value', numeric, parDefs, substitute))
161 M[pos0, pos0] += value
162 M[pos0, pos1] -= value

Callers 1

_makeAllMatricesFunction · 0.90

Calls 4

float2rationalFunction · 0.90
_createDepVarIndexFunction · 0.85
_getValueFunction · 0.85
_getValuesFunction · 0.85

Tested by

no test coverage detected