def test_ctrl_unconverged(net): output_writer = OutputWriter(net, time_steps=[0, 1]) class DivergentController(Controller): def __init__(self, net): super().__init__(net) def time_step(self, time): self.convergent = True if time % 2 == 0 else False def is_converged(self): return self.convergent DivergentController(net) with pytest.raises(ct.ControllerNotConverged): run_timeseries(net, time_steps=range(0, 3), output_writer=output_writer, max_iter=3) # assert no exceptions but appropriate output in outputwriter run_timeseries(net, time_steps=range(0, 3), output_writer=output_writer, max_iter=3, continue_on_divergence=True) for i, out in enumerate( output_writer.output["Parameters"].controller_unstable): if i % 2 == 0: assert not out else: assert out
def init_default_outputwriter(net, time_steps, **kwargs): """ Initializes the output writer. If output_writer is None, default output_writer is created INPUT: **net** - The pandapower format network **time_steps** (list) - time steps to be calculated """ output_writer = kwargs.get("output_writer", None) if output_writer is not None: # write the output_writer to net logger.warning("deprecated: output_writer should not be given to run_timeseries(). " "This overwrites the stored one in net.output_writer.") net.output_writer.iat[0, 0] = output_writer if "output_writer" not in net or net.output_writer.iat[0, 0] is None: # create a default output writer for this net ow = OutputWriter(net, time_steps, output_path=tempfile.gettempdir()) logger.info("No output writer specified. Using default:") logger.info(ow)
def init_default_outputwriter(net, time_steps, **kwargs): """ Creates a default output writer for the time series calculation. :param net: The pandapipes format network :type net: pandapipesNet :param time_steps: Time steps to calculate as list :type time_steps: list :return: ow - The default output writer :rtype: pandapower.timeseries.output_writer.OutputWriter """ output_writer = kwargs.get("output_writer", None) if output_writer is not None: # write the output_writer to net logger.warning( "deprecated: output_writer should not be given to run_timeseries(). " "This overwrites the stored one in net.output_writer.") net.output_writer.iat[0, 0] = output_writer if "output_writer" not in net or net.output_writer.iat[0, 0] is None: ow = OutputWriter(net, time_steps, output_path=tempfile.gettempdir(), log_variables=[]) ow.log_variable('res_sink', 'mdot_kg_per_s') ow.log_variable('res_source', 'mdot_kg_per_s') ow.log_variable('res_ext_grid', 'mdot_kg_per_s') ow.log_variable('res_pipe', 'v_mean_m_per_s') ow.log_variable('res_junction', 'p_bar') ow.log_variable('res_junction', 't_k') logger.info("No output writer specified. Using default:") logger.info(ow)
def get_default_output_writer_ppipe(net, timesteps): """ Creates a default output writer for the time series calculation. :param net: The pandapipes format network :type net: pandapipesNet :param timesteps: timesteps to calculate as list :type timesteps: list :return: output_writer - The default output_writer :rtype: ? """ ow = OutputWriter(net, timesteps, output_path=tempfile.gettempdir(), log_variables=[]) ow.log_variable('res_sink', 'mdot_kg_per_s') ow.log_variable('res_source', 'mdot_kg_per_s') ow.log_variable('res_ext_grid', 'mdot_kg_per_s') ow.log_variable('res_pipe', 'v_mean_m_per_s') ow.log_variable('res_junction', 'p_bar') ow.log_variable('res_junction', 't_k') return ow
def test_time_series_p2g_control(get_gas_example, get_power_example_simple): net_gas = get_gas_example net_power = get_power_example_simple pandapipes.create_source(net_gas, 5, 0.003) pandapipes.create_sink(net_gas, 3, 0.003) pandapipes.create_sink(net_gas, 4, 0.003) pandapower.create_load(net_power, 6, 0.004) pandapower.create_load(net_power, 5, 0.004) pandapower.create_sgen(net_power, 4, 0.004) mn = create_empty_multinet('coupled net') add_nets_to_multinet(mn, power=net_power, gas=net_gas) data_p2g_power = pd.DataFrame(np.concatenate( [np.array([1.0] * 5), np.array([0.75] * 2), np.array([1.0] * 3)]), columns=['load_p2g_power']) data_const_load = pd.DataFrame(np.concatenate( [np.array([1.2] * 5), np.array([1.75] * 2), np.array([1.2] * 3)]), columns=['load_const']) data_const_sgen = pd.DataFrame(np.concatenate( [np.array([0.8] * 5), np.array([0.9] * 2), np.array([0.8] * 3)]), columns=['sgen_const']) data_const_sink = np.zeros([10, 2]) data_const_sink[:5, :] = [0.6, 0.4] data_const_sink[5:7, :] = [1.2, 0.3] data_const_sink[7:, :] = [0.6, 0.4] data_const_sink = pd.DataFrame(data_const_sink, columns=['sink_const_0', 'sink_const_1']) ds = DFData(data_p2g_power) _, p2g = coupled_p2g_const_control(mn, 0, 0, 0.6, initial_run=True, profile_name='load_p2g_power', data_source=ds) ds = DFData(data_const_sink) ConstControl(net_gas, 'sink', 'mdot_kg_per_s', [0, 1], profile_name=['sink_const_0', 'sink_const_1'], data_source=ds) ds = DFData(data_const_load) ConstControl(net_power, 'load', 'p_mw', 1, profile_name=['load_const'], data_source=ds) ds = DFData(data_const_sgen) ConstControl(net_power, 'sgen', 'p_mw', 0, profile_name=['sgen_const'], data_source=ds) log_variables = [('res_source', 'mdot_kg_per_s'), ('res_sink', 'mdot_kg_per_s')] ow_gas = OutputWriter(net_gas, range(10), log_variables=log_variables) log_variables = [('res_load', 'p_mw'), ('res_sgen', 'p_mw')] ow_power = OutputWriter(net_power, range(10), log_variables=log_variables) run_timeseries(mn, range(10)) gas_res = ow_gas.np_results power_res = ow_power.np_results assert np.all(gas_res['res_sink.mdot_kg_per_s'] == data_const_sink.values) assert np.all(gas_res['res_source.mdot_kg_per_s'] == data_p2g_power.values * \ p2g.conversion_factor_mw_to_kgps() * p2g.efficiency) assert np.all(power_res['res_load.p_mw'][:, 1] == data_const_load.values.T) assert np.all(power_res['res_sgen.p_mw'] == data_const_sgen.values)