Example #1
0
 def test_06(self):
     """ Cube """
     #self.loadAndRun('Cube')
     junctions = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'}
     wires = {('B', 'F'): ('B', 'F'), ('A', 'B'): ('A', 'B'),
              ('B', 'C'): ('B', 'C'), ('E', 'F'): ('E', 'F'),
              ('D', 'H'): ('D', 'H'), ('G', 'H'): ('G', 'H'),
              ('C', 'D'): ('C', 'D'), ('D', 'A'): ('D', 'A'),
              ('H', 'E'): ('H', 'E'), ('C', 'G'): ('C', 'G'),
              ('F', 'G'): ('F', 'G'), ('A', 'E'): ('A', 'E'),
              'battery': ('A', 'G')}
     resistances = {('B', 'F'): 30, ('A', 'B'): 30, ('B', 'C'): 30,
                    ('E', 'F'): 30, ('D', 'H'): 30, ('G', 'H'): 30,
                    ('C', 'D'): 30, ('D', 'A'): 30, ('H', 'E'): 30,
                    ('C', 'G'): 30, ('F', 'G'): 30, ('A', 'E'): 30,
                    'battery': 0}
     voltages = {('B', 'F'): 0, ('A', 'B'): 0, ('B', 'C'): 0,
                 ('E', 'F'): 0, ('D', 'H'): 0, ('G', 'H'): 0,
                 ('C', 'D'): 0, ('D', 'A'): 0, ('H', 'E'): 0,
                 ('C', 'G'): 0, ('F', 'G'): 0, ('A', 'E'): 0,
                 'battery': -300}
     soln = {('A', 'B'): 4.0, ('B', 'C'): 2.0, ('C', 'D'): -2.0, ('D', 'A'): -4.0,
             ('E', 'F'): 2.0, ('F', 'G'): 4.0, ('G', 'H'): -4.0, ('H', 'E'): -2.0,
             ('A', 'E'): 4.0, ('B', 'F'): 2.0, ('C', 'G'): 4.0, ('D', 'H'): 2.0,
             'battery': -12.0}
     sub = lab.solveCircuit(junctions, wires, resistances, voltages)
     self.validateEqual(soln, sub)
     
     junctions = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'}
     wires = {('D', 'H'): ('D', 'H'), ('A', 'E'): ('A', 'E'),
              ('C', 'D'): ('C', 'D'), ('E', 'F'): ('E', 'F'),
              ('G', 'H'): ('G', 'H'), ('B', 'F'): ('B', 'F'),
              ('C', 'G'): ('C', 'G'), ('F', 'G'): ('F', 'G'),
              ('H', 'E'): ('H', 'E'), ('B', 'C'): ('B', 'C'),
              ('D', 'A'): ('D', 'A'), ('A', 'B'): ('A', 'B'),
              'battery': ('A', 'G')}
     resistances = {('D', 'H'): 60, ('A', 'E'): 9, ('C', 'D'): 60, ('E', 'F'): 60,
                    ('G', 'H'): 36, ('B', 'F'): 60, ('C', 'G'): 36, ('F', 'G'): 36,
                    ('H', 'E'): 60, ('B', 'C'): 60, ('D', 'A'): 9, ('A', 'B'): 9,
                    'battery': 0}
     voltages = {('D', 'H'): 0, ('A', 'E'): 0, ('C', 'D'): 0, ('E', 'F'): 0,
                 ('G', 'H'): 0, ('B', 'F'): 0, ('C', 'G'): 0, ('F', 'G'): 0,
                 ('H', 'E'): 0, ('B', 'C'): 0, ('D', 'A'): 0, ('A', 'B'): 0,
                 'battery': -300}
     soln = {('A', 'B'): 4.0, ('B', 'C'): 2.0, ('C', 'D'): -2.0, ('D', 'A'): -4.0,
             ('E', 'F'): 2.0, ('F', 'G'): 4.0, ('G', 'H'): -4.0, ('H', 'E'): -2.0,
             ('A', 'E'): 4.0, ('B', 'F'): 2.0, ('C', 'G'): 4.0, ('D', 'H'): 2.0,
             'battery': -12.0}
     sub = lab.solveCircuit(junctions, wires, resistances, voltages)
     self.validateEqual(soln, sub)
 def loadAndRun(self, file):
     num = 0
     print()
     for testCase in loadData('SolveCircuit_' + file + '.pickle'):
         num += 1
         print("Running sub-test", num)
         sub = lab.solveCircuit(testCase['junctions'], testCase['wires'], testCase['resistances'], testCase['voltages'])
         self.validateEqual(testCase['soln'], sub)
 def test_03(self):
     """ Parallel with multiple batteries """
     #self.loadAndRun('MultiBatteryParallel')
     junctions = {'A', 'B'}
     wires = {'0': ('A', 'B'), '1': ('A', 'B'), '2': ('A', 'B')}
     resistances = {'0': 2, '1': 4, '2': 4}
     voltages = {'0': 6, '1': 12, '2': 16}
     soln = {'0': -2, '1': 0.5, '2': 1.5}
     sub = lab.solveCircuit(junctions, wires, resistances, voltages)
     self.validateEqual(soln, sub)
 def test_02(self):
     """ Parallel with single battery """
     #self.loadAndRun('SingleBatteryParallel')
     junctions = {'A', 'B'}
     wires = {'0': ('A', 'B'), '1': ('A', 'B'), '2': ('A', 'B')}
     resistances = {'0': 2, '1': 4, '2': 4}
     voltages = {'0': 5, '1': 0, '2': 0}
     soln = {'0': 1.25, '1': -0.625, '2': -0.625}
     sub = lab.solveCircuit(junctions, wires, resistances, voltages)
     self.validateEqual(soln, sub)
 def test_01(self):
     """ Series triangle """
     #self.loadAndRun('SeriesTriangle')
     junctions = {'A', 'B', 'C'}
     wires = {'0': ('A', 'B'), '1': ('B', 'C'), '2': ('C', 'A')}
     resistances = {'0': 0, '1': 2, '2': 3}
     voltages = {'0': 5, '1': 0, '2': 0}
     soln = {'0': 1, '1': 1, '2': 1}
     sub = lab.solveCircuit(junctions, wires, resistances, voltages)
     self.validateEqual(soln, sub)
Example #6
0
 def test_05(self):
     """ Short circuit """
     #self.loadAndRun('ShortCircuit')
     junctions = {'A', 'B'}
     wires = {'0': ('A', 'B'), '1': ('A', 'B'), '2': ('A', 'B'), '3': ('B', 'A')}
     resistances = {'0': 7, '1': 17.34348, '2': 420.6921, '3': 0}
     voltages = {'0': 21, '1': 0, '2': 0, '3': 0}
     soln = {'0': 3.0, '1': 0.0, '2': 0.0, '3': 3.0}
     sub = lab.solveCircuit(junctions, wires, resistances, voltages)
     self.validateEqual(soln, sub)
Example #7
0
 def test_04(self):
     """ Wire sticking out of triangle """
     #self.loadAndRun('StrayWire')
     junctions = {'A', 'B', 'C', 'D'}
     wires = {'0': ('A', 'B'), '1': ('B', 'C'), '2': ('C', 'A'), '3': ('C', 'D')}
     resistances = {'0': 1.5, '1': 2.0, '2': 0, '3': 0}
     voltages = {'0': 30, '1': 20, '2': 20, '3': 1000000}
     soln = {'0': 20.0, '1': 20.0, '2': 20.0, '3': 0.0}
     sub = lab.solveCircuit(junctions, wires, resistances, voltages)
     self.validateEqual(soln, sub)