def stepByStepTrans(circuit, branch, mnaVector): #TODO explanation tmpcirc = deepcopy(circuit) tmpcirc.branches.remove(branch) tmpcirc.updNodeCnt() tmpcirc.mnaVector = mna(tmpcirc)['x'] #initial conditions calculated. #create another tmpcirc1 = deepcopy(circuit) for b in tmpcirc.branches: if b.comp.ctype == 'L': ...
def stepByStepNorton(circuit, branch, mnaVector): #TODO explanation #$thv=stepByStepThevenin(circuit,branch,mnaVector)[0] #return ([thv[0]/thv[1],thv[1]],'') tmpcirc = deepcopy(circuit) tmpbranch = Branch(branch.node2, branch.node1, Component('TestV', symbols('x'), 'V')) tmpcirc.addBranch(tmpbranch) #hack tmpcirc.updNodeCnt() tmpcirc.mnaVector = mna(tmpcirc)['x'] Ires = currentInBranch_value(tmpcirc, tmpbranch, tmpbranch.node2, tmpcirc.mnaVector) print(Ires) In = -Ires.subs(symbols('x'), 0) Rn = 1 / (Ires.subs(symbols('x'), 1) + In) print(In, Rn) return ([In, Rn], '')
def stepByStepThevenin(circuit, branch, mnaVector): #TODO explanation """ res='<p>To obtain the Thevenin equivelent circuit, we need to calculate the Vt and the Rt. Lets start with Vt. Vt is the tension between the nodes in open circuit:</p>\n\n' res+=stepByStepCurrent(circuit,branch,mnaVector) """ #Add current source to circuit, and recalculate mna tmpcirc = deepcopy(circuit) tmpbranch = Branch(branch.node2, branch.node1, Component('TestI', symbols('x'), 'I')) tmpcirc.addBranch(tmpbranch) #hack tmpcirc.updNodeCnt() tmpcirc.mnaVector = mna(tmpcirc)['x'] Vres = voltageInBranch_value(tmpbranch, tmpbranch.node2, tmpcirc.mnaVector) print(Vres) Vt = Vres.subs(symbols('x'), 0) Rt = Vres.subs(symbols('x'), 1) - Vt print(Vt, Rt) return ([Vt, Rt], '')
def general_ressol(circuit): circuit.mnaVector = mna(circuit)['x'] return general_classic(circuit, circuit.mnaVector)
from os.path import abspath, realpath, relpath, dirname, join import sys from sympy import * #Get project dir project_path = dirname(realpath(__file__)) sys.path += [join(project_path, '../')] from datastructure import Circuit, Branch, Component sys.path += [join(project_path, '../parser/')] from spiceProcessor import run_parser sys.path += [join(project_path, '../mna/')] from mnaModule import mna from randSol import randomWrongs circ = run_parser(abspath('example1.cir')) circ.calcImpedances(0) print(mna(circ)['x']) circ.getBranchCompName('R1').getComponent().value *= symbols('x') * 20 circ.getBranchCompName('V1').getComponent().value *= symbols('y') circ.calcImpedances(0) print(mna(circ)['x'].subs(symbols('x'), 1 / 20).subs(symbols('y'), 1)) print('', mna(circ))