e2nIEE / pandapipes

A pipeflow calculation tool that complements pandapower in the simulation of multi energy grids
https://www.pandapipes.org
Other
147 stars 62 forks source link

Time Series Simulation Calculates Constant Temperatures in heating network #576

Closed JonasPfeiffer123 closed 11 months ago

JonasPfeiffer123 commented 11 months ago

Describe the bug I'm quite new to pandapipes and recently started creating heating networks with pandapipes. I created a net containing pipes, heat exchangers and a constant pressure circulation pump. First of, running "pipeflow(net, mode="all")" works fine. The results show, that the flow temperature at the pump is set correctly and due to heat losses the temperature is reduced from junction to junction. Also a temperature drop happens at the heat exchangers as intended. This can be checked with res_junctions, res_circ_pump_pressure, and res_heat_exchanger.

In the time series simulation of the heating network, the calculated temperatures in the network remain constant. I expect the temperatures to change according to the variations in the input data, but instead, they remain constant. My Controler changes "qext_w" of the heat exchangers so a difference in flow and temperature is expected.

Here are some outputs which show the problem. Issue.txt

Here the output of the temperature in a matplotlib plot. Issue

To Reproduce

My net is currently generated from gis data, so the code I created is quite long and requires geoJSON input files. But as the "normal" calculation works fine, I think the problem come with the time series function.

Edit: I created a new smaller network manually to further test the problem. The following net also creates the problem.

def initialize_test_net():
    net = pp.create_empty_network(fluid="water")

    # Junctions for pump
    j1 = pp.create_junction(net, pn_bar=1.05, tfluid_k=293.15, name="Junction 1")
    j2 = pp.create_junction(net, pn_bar=1.05, tfluid_k=293.15, name="Junction 2")

    # Junctions for connection pipes forward line
    j3 = pp.create_junction(net, pn_bar=1.05, tfluid_k=293.15, name="Junction 3")
    j4 = pp.create_junction(net, pn_bar=1.05, tfluid_k=293.15, name="Junction 4")

    # Junctions for heat exchangers
    j5 = pp.create_junction(net, pn_bar=1.05, tfluid_k=293.15, name="Junction 5")
    j6 = pp.create_junction(net, pn_bar=1.05, tfluid_k=293.15, name="Junction 6")

    # Junctions for connection pipes 
    j7 = pp.create_junction(net, pn_bar=1.05, tfluid_k=293.15, name="Junction 7")
    j8 = pp.create_junction(net, pn_bar=1.05, tfluid_k=293.15, name="Junction 8")

    pump1 = pp.create_circ_pump_const_pressure(net, j1, j2, p_flow_bar=4,
                                               plift_bar=1.5, t_flow_k=273.15 + 90,
                                               type="auto", name="pump1")

    pipe1 = pp.create_pipe(net, j2, j3, std_type="110_PE_100_SDR_17", length_km=0.01,
                           k_mm=.1, alpha_w_per_m2k=10, name="pipe1", sections=5,
                           text_k=283)
    pipe2 = pp.create_pipe(net, j3, j4, std_type="110_PE_100_SDR_17", length_km=0.5,
                           k_mm=.1, alpha_w_per_m2k=10, name="pipe2", sections=5,
                           text_k=283)
    pipe3 = pp.create_pipe(net, j4, j5, std_type="110_PE_100_SDR_17", length_km=0.01,
                           k_mm=.1, alpha_w_per_m2k=10, name="pipe3", sections=5,
                           text_k=283)

    heat_exchanger1 = pp.create_heat_exchanger(net, j5, j6, diameter_m=0.02,
                                               loss_coefficient=100, qext_w=50000,
                                               name="heat_exchanger1")

    pipe4 = pp.create_pipe(net, j6, j7, std_type="110_PE_100_SDR_17", length_km=0.01,
                           k_mm=.1, alpha_w_per_m2k=10, name="pipe4", sections=5,
                           text_k=283)
    pipe5 = pp.create_pipe(net, j7, j8, std_type="110_PE_100_SDR_17", length_km=0.5,
                           k_mm=.1, alpha_w_per_m2k=10, name="pipe5", sections=5,
                           text_k=283)
    pipe6 = pp.create_pipe(net, j8, j1, std_type="110_PE_100_SDR_17", length_km=0.01,
                           k_mm=.1, alpha_w_per_m2k=10, name="pipe6", sections=5,
                           text_k=283)

    pp.pipeflow(net, mode="all")
    return net

My time series function:

import pandapipes as pp
from pandapipes.timeseries import run_time_series
from pandapower.control.controller.const_control import ConstControl
from pandapower.timeseries import OutputWriter
from pandapower.timeseries import DFData
import pandas as pd
import matplotlib.pyplot as plt

def time_series_net(net):

    time_steps = range(0, 24)  # hourly time steps

    df = pd.DataFrame(index=time_steps)

    qext_w_profile = [50000] * 3 + [60000] * 6 + [70000] * 9 + [80000] * 6

    for i in range(8):

        df = pd.DataFrame(index=time_steps, data={'qext_w_'+str(i): qext_w_profile})

        data_source = DFData(df)
        ConstControl(net, element='heat_exchanger', variable='qext_w', element_index=[i], data_source=data_source, profile_name='qext_w_'+str(i))

    log_variables = [('res_junction', 'p_bar'), ('res_pipe', 'v_mean_m_per_s'),
                     ('res_pipe', 'reynolds'), ('res_pipe', 'lambda'), ('heat_exchanger', 'qext_w'),
                     ('res_heat_exchanger', 'v_mean_m_per_s'), ('res_heat_exchanger', 't_from_k'),
                     ('res_heat_exchanger', 't_to_k'), ('circ_pump_pressure', 't_flow_k'), ('res_junction', 't_k')]

    ow = OutputWriter(net, time_steps, output_path=None, log_variables=log_variables)

    run_time_series.run_timeseries(net, time_steps)

    print("temperature:")
    print(ow.np_results["res_junction.t_k"])

    x = time_steps
    y1 = ow.np_results["res_heat_exchanger.t_from_k"]
    y2 = ow.np_results["res_heat_exchanger.t_to_k"]

    plt.xlabel("time step")
    plt.ylabel("temperature [K]")
    plt.title("temperature profile heat exchangers")
    plt.plot(x, y1[:,0], "g-o")
    plt.plot(x, y2[:,0], "b-o")
    plt.legend(["heat exchanger 1 from", "heat exchanger 1 to"], loc='lower left')
    plt.grid()
    plt.show()

I would like to know, if there is something wrong with my time series calculation or if there is a problem in the run_timeseries function.

Python environment:

This is my first issue ever. If I should add anything else, please tell me.

dlohmeier commented 11 months ago

Hi @JonasPfeiffer123, I think this problem has been addressed in other issues, I think we should create a small introduction to time series simulation with different setups, e.g. heating networks. Please try to run the time series with mode="all" keyword argument. It is then handed down to the pipeflow. Hope that all works fine. Best regards

JonasPfeiffer123 commented 11 months ago

Yes, adding the keyword argument mode="all" solves the problem. Thank you very much. I also think it would be useful to add this information to the docs and/or the time series example.