def test_2bus_2dev(self): """Solve a single-branch 2-bus AC load flow.""" # Network definition. network = { 'baseMVA': self.baseMVA, 'bus': np.array([[0, 0, 50, 1., 1.], [1, 1, 50, 1.1, 0.9]]), 'branch': np.array([[0, 1, 0.01, 0.1, 0., 32, 1, 0]]), 'device': np.array([ [0, 0, 0, None, 200, -200, 200, -200, None, None, None, None, None, None, None], # slack [1, 1, -1, 0.2, 0, -10, None, None, None, None, None, None, None, None, None] # load ]) } simulator = Simulator(network, self.delta_t, self.lamb) # Set device fixed power injections. N = 50 for i, pq in enumerate(np.random.uniform(-1, 0, size=(N, 2))): simulator.devices[1].p = pq[0] simulator.devices[1].q = pq[1] # Set bus injections (same as device injections). simulator.buses[1].p = simulator.devices[1].p simulator.buses[1].q = simulator.devices[1].q # My own implementation. solve_pfe_newton_raphson(simulator) self._check_pfe_solution(simulator)
def test_reset(self): """Test reset() (and transition()) methods.""" # Network definition. baseMVA = 10 network = { 'baseMVA': baseMVA, 'bus': np.array([[0, 0, 50, 1., 1.], [1, 1, 50, 1.1, 0.9], [2, 1, 50, 1.1, 0.9]]), 'branch': np.array([[0, 1, 0.01, 0.1, 0., 30, 1, 0], [1, 2, 0.02, 0.3, 0.2, 30, 1, 0], [2, 0, 0.05, 0.2, 0.1, 30, 1, 0]]), 'device': np.array([ [0, 0, 0, None, 200, -200, 200, -200, None, None, None, None, None, None, None], # slack [1, 1, -1, 0.2, 0, -10, None, None, None, None, None, None, None, None, None], # load [2, 1, 1, None, 100, 0, 100, -100, None, None, None, None, None, None, None], # gen [3, 2, 2, None, 100, 0, 100, -100, None, None, None, None, None, None, None], # renewable [4, 2, 3, None, 100, -100, 100, -100, None, None, None, None, 100, 0, 0.9] # storage ]) } simulator = Simulator(network, self.delta_t, self.lamb) ps = [5, -5, 3, 6, -7] qs = [1, -1, 1, 2, -2] soc = [40] p_max = [4, 6] aux = [None, None] s0 = np.array(ps + qs + soc + p_max + aux) simulator.reset(s0) # Check results satisfy power flow equations. self._check_pfe_solution(simulator) # Check device power injections. for i in range(1, 5): self.assertAlmostEqual(simulator.devices[i].p, ps[i] / baseMVA) self.assertAlmostEqual(simulator.devices[i].q, qs[i] / baseMVA) # Check DES final SoC. self.assertAlmostEqual(simulator.devices[4].soc, soc[0] / baseMVA)
def test_3bus_4dev_1transformer(self): """Solve load flow with a off-nominal transformer.""" N_runs = 10 for i in range(N_runs): tap = np.random.uniform(0.9, 1.1) shift = np.random.uniform(0, 50) # Network definition. network = { 'baseMVA': self.baseMVA, 'bus': np.array([[0, 0, 50, 1., 1.], [1, 1, 50, 1.1, 0.9], [2, 1, 50, 1.1, 0.9]]), 'branch': np.array([[0, 1, 0.01, 0.1, 0., 30, 1, 0], [1, 2, 0.02, 0.3, 0.2, 30, tap, shift], [2, 0, 0.05, 0.2, 0.1, 30, 1, 0]]), 'device': np.array([ [0, 0, 0, None, 200, -200, 200, -200, None, None, None, None, None, None, None], # slack [1, 1, -1, 0.2, 0, -10, None, None, None, None, None, None, None, None, None], # load [2, 1, 1, None, 200, 0, 200, -200, None, None, None, None, None, None, None], # gen [3, 2, 2, None, 200, 0, 200, -200, None, None, None, None, None, None, None], # renewable [4, 2, 3, None, 200, -200, 200, -200, None, None, None, None, 100, 0, 0.9] # storage ]) } simulator = Simulator(network, self.delta_t, self.lamb) # Set device fixed power injections. N = 10 pq_load = np.random.uniform(-1, 0, (N, 2)) pq_gen = np.random.uniform(0, 1, (N, 2)) pq_ren = np.random.uniform(0, 1, (N, 2)) pq_des = np.random.uniform(-1, 1, (N, 2)) for i in range(N): for j, pq in zip(range(1, 5), [pq_load[i], pq_gen[i], pq_ren[i], pq_des[i]]): simulator.devices[j].p = pq[0] simulator.devices[j].q = pq[1] # Set bus power injections. simulator.buses[1].p = pq_load[i, 0] + pq_gen[i, 0] simulator.buses[1].q = pq_load[i, 1] + pq_gen[i, 1] simulator.buses[2].p = pq_ren[i, 0] + pq_des[i, 0] simulator.buses[2].q = pq_ren[i, 1] + pq_des[i, 1] # Solve power flow equations. solve_pfe_newton_raphson(simulator) # Check the solution. self._check_pfe_solution(simulator)
def test_slack_dev_not_at_slack_bus(self): network = { 'baseMVA': 100, 'bus': np.array([[0, 0, 50, 1.1, 0.9], [1, 1, 50, 1.1, 0.9]]), 'branch': np.array([[0, 1, 0.1, 0.2, 0.3, 20, 1, 90]]), 'device': np.array([[ 0, 1, 0, 0.2, 0, -10, None, None, None, None, None, None, None, None, None ]]) } with self.assertRaises(DeviceSpecError): Simulator(network, 1, 100)
def test_dev_id_duplicates(self): network = { 'baseMVA': 100, 'bus': np.array([[0, 0, 50, 1.1, 0.9], [1, 1, 100, 1., 1.]]), 'branch': np.array([[0, 1, 0.1, 0.2, 0.3, 20, 1, 90]]), 'device': np.array([[ 0, 0, 0, 0.2, 0, -10, None, None, None, None, None, None, None, None, None ], [ 0, 1, -1, None, 200, -200, 200, -200, None, None, None, None, None, None, None ]]) } with self.assertRaises(DeviceSpecError): Simulator(network, 1, 100)
def test_non_existing_bus_in_branch(self): network = { 'baseMVA': 100, 'bus': np.array([[0, 0, 50, 1.1, 0.9], [1, 1, 100, 1., 1.]]), 'branch': np.array([[0, 1, 0.1, 0.2, 0.3, 20, 1, 90], [1, 2, 0.4, 0.5, 0.6, 20, 2, 0]]), 'device': np.array([[ 0, 0, 0, 0.2, 0, -10, None, None, None, None, None, None, None, None, None ], [ 1, 1, -1, None, 200, -200, 200, -200, None, None, None, None, None, None, None ]]) } with self.assertRaises(BranchSpecError): Simulator(network, 1, 100)
def test_baseMVA(self): for baseMVA in [-1, 0]: network = { 'baseMVA': baseMVA, 'bus': np.array([[0, 0, 50, 1.1, 0.9], [1, 1, 100, 1., 1.]]), 'branch': np.array([[0, 1, 0.1, 0.2, 0.3, 20, 1, 90]]), 'device': np.array([[ 1, 0, -1, 0.2, 0, -10, None, None, None, None, None, None, None, None, None ], [ 0, 1, 0, None, 200, -200, 200, -200, None, None, None, None, None, None, None ]]) } with self.assertRaises(BaseMVAError): Simulator(network, 1, 100)