1 Introduction

An efficient and sustainable energy sector is at the core of the fight against the climate crisis. Thus, many countries around the world strive towards an energy turnaround with the overarching goal to replace fossil fuels with energy from renewable resources such as wind and solar power. However, one then faces issues with the high volatility of the fluctuating renewable resources. To overcome this fluctuating nature of wind and solar power, two main approaches are currently seen as the most promising ones: (i) the development and usage of large-scale energy storage systems as well as (ii) sector-coupling.

In this paper, we consider the computation of optimal operation strategies for district heating networks. These networks are used to provide customers with hot water in order to satisfy their heat demand. Thus, a district heating network can be seen both as a large-scale energy storage as well as a key element of successful sector-coupling. The hot water in the pipes of a district heating network is heated in so-called depots in which, usually, waste incineration is used as the primary heat source. If, however, waste incineration is not sufficient for heating the water, gas turbines are used as well. The hot water in the pipeline system can thus be seen as an energy storage that could, for instance, also be filled using power-to-heat technologies in time periods with surplus production of renewables. On the other hand, heat-to-power can be used to smooth the fluctuating nature of renewables in time periods with only small renewable production. Consequently, district heating networks can be seen as sector-coupling entities with inherent storage capabilities.

To make such operational strategies for district heating networks possible, an efficient control of the network is required that does not compromise the heat demand of the households that are connected to the network. However, a rigorous physical and technical modeling of hot water flow in pipes leads to hard mathematical optimization problems. At the core of these problems are partial differential equations for modeling both water and heat transport. Additionally, proper models of the depot and the households further increase the level of nonlinearity in the overall model. Finally, the tracking of water temperatures across nodes of the network leads to nonconvex and nonsmooth mixing models that put a significant burden on today’s state-of-the-art optimization techniques.

In this paper, we consider the simplified setting of a stationary flow regime. For closed-loop control strategies for instationary variants of the problem we refer to [1, 28, 35] and to [15] for open-loop optimization approaches. Interestingly, the literature on mathematical optimization for district heating networks is rather sparse. An applied case study for a specific district heating network in South Wales is done in [20] and [26] provides more a general discussion of technological aspects and the potentials of district heating networks. In [30], the authors follow a first-discretize-then-optimize approach for the underlying PDE-constrained problem. For the relation between district heating networks and energy storage aspects we refer to [5, 12, 33] and the references therein. Stationary models of hot water flow are also considered in studies on the design and expansion of networks as, e.g., in [2, 7, 27]. Numerical simulation of district heating networks using a local time stepping method is studied in [3] and model order reduction techniques for the hyperbolic equations in district heating networks are discussed in [23] or [24, 25]. Finally, a port-Hamiltonian modeling approach for district heating networks is presented and discussed in [13].

Despite the mentioned simplification of considering stationary flow regimes, the optimization problems at hand are still large-scale and highly nonlinear mathematical programs with complementarity constraints (MPCCs) that are constrained by ordinary differential equations (ODEs). It turns out that these models are extremely hard to solve for realistic or even real-world district heating networks if they are presented to state-of-the-art optimization solvers. Our contribution is the development of an adaptive optimization algorithm that controls the modeling and the discretization of the hot water flow equations in the network. A similar approach has already been developed and tested for natural gas networks in [16]. The main rationale is that simplified (and thus computationally cheaper) models can lead to satisfactory (w.r.t. their physical accuracy) results for some parts of the network whereas other parts require a highly accurate modeling to obtain the required physical accuracy. The problem, however, is that it is not known up-front where which kind of modeling is appropriate. Our adaptive algorithm is based on (i) a catalog of different models of hot water flow and on (ii) different discretization grids for the underlying differential equations. The proposed method then controls the choice of the model and the discretization grid separately for every pipe in the network. The switching between different models and discretization grids is based on rigorous error measures so that we obtain a finite termination proof stating that the method computes a locally optimal point that is feasible w.r.t. the most accurate modeling level and a prescribed tolerance. Besides these theoretical contributions, we also show the effectiveness of our approach in practice and, in particular, illustrate that instances on realistic networks can be solved with the newly proposed method that have been unsolvable before.

The remainder of the paper is structured as follows. In Sect. 2 we present our modeling of district heating networks and derive the modeling catalog for hot water flow as well as the discretizations of the respective differential equations. After this, we derive exact error measures and error measure estimators in Sect. 3 both for modeling as well as discretization error measures. These are then used in Sect. 4 to set up the adaptive optimization algorithm and to prove its finite termination. The algorithm is numerically tested in Sect. 5 before we close the paper with some concluding remarks and some aspects of potential future work in Sect. 6.

2 Modeling

We model the district heating network as a directed and connected graph \(G = ({V}, {A})\), which has a special structure. First, we have a so-called forward-flow part of the network, which is used to provide the consumers with hot water. Second, the cooled water is transported back to the depot in the so-called backward-flow part. These two parts are connected via the depot in which the cooled water is heated again, and via the consumers who use the temperature difference to satisfy the thermal energy demand in the corresponding household. The set of nodes of the forward-flow part is denoted by \({V}_{\text {ff}}\) and the set of arcs of this part is denoted by \({A}_{\text {ff}}\), i.e., \(a= (u, v) \in {A}_{\text {ff}}\) implies \(u, v\in {V}_{\text {ff}}\). In analogy, the set of nodes of the backward-flow part is denoted by \({V}_{\text {bf}}\) and the set of arcs of this part is denoted by \({A}_{\text {bf}}\), i.e., \(a= (u, v) \in {A}_{\text {bf}}\) implies \(u, v\in {V}_{\text {bf}}\). The depot arc is denoted by \(a_\text {d}= (u, v)\) with \(u\in {V}_{\text {bf}}\) and \(v\in {V}_{\text {ff}}\). The consumers are modeled with arcs \(a= (u, v)\) with \(u\in {V}_{\text {ff}}\) and \(v\in {V}_{\text {bf}}\). Finally, all pipes of the forward and the backward flow part are contained in the set of pipes \( {A}_{\text {p}}= {A}_{\text {ff}}\cup {A}_{\text {bf}}\).

In the next subsection we present the model for all components of the network, i.e., for pipes, consumers, and the depot.

2.1 Pipes

We now derive an approximation for the stationary water flow in cylindrical pipes. This derivation is based on the 1-dimensional compressible Euler equations  [3, 13, 24]

$$\begin{aligned} 0&= \frac{\partial \rho _a}{ \partial t} + v_a\frac{\partial \rho _a}{ \partial x} + \rho _a\frac{\partial v_a}{ \partial x}, \end{aligned}$$
(1a)
$$\begin{aligned} 0&= \frac{\partial (\rho _av_a)}{\partial t} + v_a\frac{\partial (\rho _av_a)}{\partial x} + \frac{\partial p_a}{\partial x} + \frac{\lambda _a}{2 D_a} \rho _a|v_a| v_a+ g\rho _ah_a'. \end{aligned}$$
(1b)

Equation (1a) is the continuity equation and models mass balance, whereas the pressure gradient is described by the momentum equation (1b). Here and in what follows, \(\rho \) denotes the density of water, \(v\) its velocity, and \(p\) its pressure. In (1), the quantities are to be seen as functions in space (x) and time (t), i.e., for instance, \(p= p(x,t)\). The diameter of a pipe \(a\) is denoted by \(D_a\), \(\lambda _a\) is the pipe’s friction coefficient, and \(h_a'\) denotes the slope of the pipe. Finally, g is the gravitational acceleration.

The incompressibility of water is modeled as \( 0 = \rho _{a} \frac{\partial v_a}{\partial x}\), cf. [13], which implies

$$\begin{aligned} 0 = \frac{\partial \rho _a}{ \partial t} + v_a\frac{\partial \rho _a}{ \partial x}. \end{aligned}$$
(2)

Moreover, the additional PDEs

$$\begin{aligned} 0&= \frac{\partial e_a}{\partial t} + v_a\frac{\partial e_a}{\partial x} +p_a\frac{\partial v_a}{\partial x} - \frac{\lambda _a}{2 D_a} \rho _a|v_a| v_a^2 + \frac{4 k_W}{D_a}(T_a- T_\text {W}), \end{aligned}$$
(3a)
$$\begin{aligned} 0&= \frac{\partial s_a}{\partial t} + v_a\frac{\partial s_a}{\partial x} + \frac{\lambda _a\rho _a}{2 D_aT_a} |v_a| v_a^2 + \frac{4 k_W}{D_a}\frac{(T_a- T_\text {W})}{T_a} \end{aligned}$$
(3b)

model conservation of internal energy density \(e\) and entropy density \(s\), respectively; see [13]. The water’s temperature is denoted by \(T_a\). The parameters \(k_W\) and \(T_\text {W}\) are the heat transfer coefficient and the soil or pipe wall temperature.

Since we expect the change (in time) of the pressure energy and the term of energy and power loss due to dissipation work to be small, we neglect these terms. However, if these terms are taken into account, then it is possible to reformulate these equations in a port-Hamiltonian form (see, e.g., [13]), which is more appropriate for sector coupling [17]. Finally, we are interested in the stationary state of the network. This is modeled by setting all partial derivatives w.r.t. time to zero. Hence, the System (1)–(3) simplifies to the stationary, incompressible, and 1-dimensional Euler equations for hot water pipe flow, i.e.,

$$\begin{aligned} 0&= \rho _a\frac{ \,\textrm{d}v_a}{ \,\textrm{d}x}, \end{aligned}$$
(4a)
$$\begin{aligned} 0&=v_a\frac{ \,\textrm{d}\rho _a}{ \,\textrm{d}x} + \rho _a\frac{ \,\textrm{d}v_a}{ \,\textrm{d}x}, \end{aligned}$$
(4b)
$$\begin{aligned} 0&= v_a\frac{ \,\textrm{d}(\rho _av_a)}{ \,\textrm{d}x} + \frac{ \,\textrm{d}p_a}{ \,\textrm{d}x} + \frac{\lambda _a}{2 D_a} \rho _a|v_a| v_a+ g\rho _ah_a', \end{aligned}$$
(4c)
$$\begin{aligned} 0&= v_a\frac{ \,\textrm{d}e_a}{ \,\textrm{d}x} +p_a\frac{ \,\textrm{d}v_a}{ \,\textrm{d}x} - \frac{\lambda _a}{2 D_a} \rho _a|v_a| v_a^2 + \frac{4 k_W}{D_a}(T_a- T_\text {W}), \end{aligned}$$
(4d)
$$\begin{aligned} 0&= v_a\frac{ \,\textrm{d}s_a}{ \,\textrm{d}x} + \frac{\lambda _a\rho _a}{2 D_aT_a} |v_a| v_a^2 + \frac{4 k_W}{D_a}\frac{(T_a- T_\text {W})}{T_a}. \end{aligned}$$
(4e)

Since \(\rho _a> 0\) holds, Eq. (4a) implies that \(v_a(x) = v_a\) is constant for all pipes. Using this, (4b) implies that the density \(\rho _a(x) = \rho _a\) is constant as well. In addition, we set \(\rho _a= \rho \) for all arcs \(a\) of the network. With the mass flow

$$\begin{aligned} q_a= A_a\rho v_a\end{aligned}$$
(5)

and constant velocities and densities we also have that \(q_a(x) = q_a\) is constant for all pipes. In (5), \(A_a\) denotes the cross-sectional area of pipe \(a\). By subsuming the discussed simplifications we get the system

$$\begin{aligned} 0&= \frac{ \,\textrm{d}p_a}{ \,\textrm{d}x} + \frac{\lambda _a}{2 D_a} \rho |v_a| v_a+ g\rho h_a', \end{aligned}$$
(6a)
$$\begin{aligned} 0&= v_a\frac{ \,\textrm{d}e_a}{ \,\textrm{d}x} - \frac{\lambda _a}{2 D_a} \rho |v_a| v_a^2 + \frac{4 k_W}{D_a}(T_a- T_\text {W}), \end{aligned}$$
(6b)
$$\begin{aligned} 0&= v_a\frac{ \,\textrm{d}s_a}{ \,\textrm{d}x} + \frac{\lambda _a\rho }{2 D_aT_a} |v_a| v_a^2 + \frac{4 k_W}{D_a}\frac{(T_a- T_\text {W})}{T_a}. \end{aligned}$$
(6c)

In Eq. (6a), the pressure gradient term is the only term that depends on the spatial position x. Hence, we obtain the stationary momentum and energy equation

$$\begin{aligned} 0&= \frac{p_a(L_a) - p_a(0)}{L_a} + \frac{\lambda _a}{2 D_a} \rho |v_a| v_a+ g\rho h_a', \end{aligned}$$
(M1a)
$$\begin{aligned} 0&= v_a\frac{ \,\textrm{d}e_a}{ \,\textrm{d}x} - \frac{\lambda _a}{2 D_a} \rho |v_a| v_a^2 + \frac{4 k_W}{D_a}(T_a- T_\text {W}). \end{aligned}$$
(M1b)

In the following, for our optimization framework, we do not consider the entropy equation, which can be solved in a post-processing step once the optimal pressure and internal energy values have been determined.

The system is closed by the state equations

$$\begin{aligned} \rho&= {997}{{\mathrm{kg\,m}}^{-3}} , \end{aligned}$$
(7a)
$$\begin{aligned} T_a&= \theta _2(e_a^*)^2 + \theta _1e^*_a+ \theta _0, \end{aligned}$$
(7b)

in which we set

$$\begin{aligned}{} & {} e_a^* \mathrel {{\mathop :}{=}}\frac{e_a}{e_0}, \quad e_0 \mathrel {{\mathop :}{=}}{10^{9}}{\text {J\,m}^{-3}}, \\{} & {} \theta _2 = {59.2453}\hbox {K}, \quad \theta _1 = {220.536}\hbox {K}, \quad \theta _0 = {274.93729}\hbox {K}. \end{aligned}$$

Equation (7b) is known to be a reasonable approximation for \(e_a\in [0.2,0.5]\)  GJ m\(^{-3}\), \(T_a\in [323,403]\) K, and \(p_a\in [5,25]\) bar; see, e.g., [13].

2.1.1 Model catalog

For the adaptive optimization method developed in this work we employ a catalog of models. In this catalog, System (M1a) represents the highest or first modeling level, i.e., the most accurate one.

To derive the second modeling level, we neglect the (small) term \(\lambda _a/ (2 D_a) \rho v_a^2 |v_a|\) and get

$$\begin{aligned} 0&= \frac{p_a(L_a) - p_a(0)}{L_a} + \frac{\lambda _a}{2 D_a} \rho |v_a| v_a+ g\rho h_a', \end{aligned}$$
(M2a)
$$\begin{aligned} 0&= v_a\frac{ \,\textrm{d}e_a}{ \,\textrm{d}x} + \frac{4 k_W}{D_a}(T_a- T_\text {W}). \end{aligned}$$
(M2b)

By further assuming that the first term in (M2b) dominates the second one, we can neglect the term \(4 k_W/ D_a(T_a- T_\text {W})\) and simplify System (M2) to obtain the third level as

$$\begin{aligned} 0&= \frac{p_a(L_a) - p_a(0)}{L_a} + \frac{\lambda _a}{2 D_a} \rho |v_a| v_a+ g\rho h_a',\\ 0&= e_a(L_a) - e_a(0). \end{aligned}$$
(M3)

Considering model catalogs such as the one just developed is a standard procedure in order to cope with challenging optimization models; see, e.g., [6] in the context of gas networks. Under sufficient regularity assumptions that allow for Taylor expansions, a detailed perturbation analysis and the dropping of higher-order terms would lead to a similar catalog.

2.1.2 Exact solution of the energy equation

The Eqs. (M1b) and (M2b) can be solved analytically. This is done in the following lemma and will be used later to compute exact error measures in our adaptive algorithm.

Lemma 1

The differential equation (M1b), i.e.,

$$\begin{aligned} 0 = v_a\frac{ \,\textrm{d}e_a}{ \,\textrm{d}x} - \frac{\lambda _a}{2 D_a} \rho |v_a| v_a^2 + \frac{4 k_W}{D_a}(T_a- T_\text {W}), \end{aligned}$$

with initial condition

$$\begin{aligned} e_a(0) = e_a^0 > 0 \end{aligned}$$

and state Eq. (7b) has the exact solution

$$\begin{aligned} e_a(x) =\frac{\sqrt{\beta ^2-4 \alpha \gamma }}{2\alpha }\frac{1+\exp \left( \frac{x\sqrt{\beta ^2-4 \alpha \gamma }}{\zeta }\right) \left( \frac{2\alpha e_a^0+\beta -\sqrt{\beta ^2-4 \alpha \gamma }}{2\alpha e_a^0+\beta +\sqrt{\beta ^2-4 \alpha \gamma }}\right) }{1- \exp \left( \frac{x\sqrt{\beta ^2-4 \alpha \gamma }}{\zeta }\right) \left( \frac{2\alpha e_a^0+\beta - \sqrt{\beta ^2-4 \alpha \gamma }}{2\alpha e_a^0+\beta +\sqrt{\beta ^2-4 \alpha \gamma }}\right) }- \frac{\beta }{2\alpha } \end{aligned}$$

with

$$\begin{aligned} \begin{aligned} \alpha&\mathrel {{\mathop :}{=}}- \frac{4 k_W\theta _2 }{D_a(e_0)^2}, \quad \beta \mathrel {{\mathop :}{=}}- \frac{4 k_W\theta _1 }{D_ae_0}, \quad \zeta \mathrel {{\mathop :}{=}}v_a,\\ \gamma&\mathrel {{\mathop :}{=}}\frac{\lambda _a}{2 D_a} \rho |v_a| v_a^2 - \frac{4 k_W}{D_a} (\theta _0 - T_\text {W}), \end{aligned} \end{aligned}$$
(8)

if \(4\alpha \gamma -\beta ^2 < 0\) is satisfied.

Proof

We combine (M1b) and (7b) to obtain

$$\begin{aligned} 0 = v_a\frac{ \,\textrm{d}e_a}{ \,\textrm{d}x} - \frac{\lambda _a}{2 D_a} \rho |v_a| v_a^2 + \frac{4 k_W}{D_a}(\theta _2(e_a^*)^2 + \theta _1e^*_a+ \theta _0 - T_\text {W}). \end{aligned}$$

After re-organizing and replacing \(e_a^*\) by its definition, the equation reads

$$\begin{aligned} - \frac{4 k_W\theta _2}{D_a(e_0)^2}(e_a)^2 - \frac{4 k_W\theta _1}{D_ae_0} e_a- \frac{4 k_W}{D_a} (\theta _0 - T_\text {W}) + \frac{\lambda _a}{2 D_a} \rho |v_a| v_a^2 = v_a\frac{ \,\textrm{d}e_a}{ \,\textrm{d}x}. \end{aligned}$$
(9)

We combine Eq. (9) with the definitions in (8) and get

$$\begin{aligned} \alpha e_a^2 + \beta e_a+ \gamma = \zeta \frac{ \,\textrm{d}e_a}{ \,\textrm{d}x}. \end{aligned}$$
(10)

Equation (10) is a special type of Riccati equation with constant coefficients; see, e.g., [22]. Because \(\alpha ,\beta ,\gamma \), and \(\zeta \) do not depend on x, they can be seen as constants when integrating over x. We re-organize and integrate both sides over x, yielding

$$\begin{aligned} \int 1 \,\textrm{d}x=\int \frac{\zeta \frac{ \,\textrm{d}e_a}{ \,\textrm{d}x}}{\alpha (e_a)^2 + \beta e_a+ \gamma } \,\textrm{d}x. \end{aligned}$$
(11)

Applying a variable change in the right-hand side of (11) leads to

$$\begin{aligned} \frac{x}{\zeta }=\int \frac{1}{\alpha (e_a)^2 + \beta e_a+ \gamma } \,\textrm{d}e_a. \end{aligned}$$
(12)

We may rewrite

$$\begin{aligned} \alpha (e_a)^2 + \beta e_a+ \gamma&= \left( (e_a)^2 + \frac{\beta }{\alpha }e_a+ \frac{\beta ^2}{4\alpha ^2}\right) + \frac{4\alpha \gamma - \beta ^2}{4\alpha }\\&= \alpha \left( \left( e_a+ \frac{\beta }{2\alpha } \right) ^2 + \frac{4\alpha \gamma - \beta ^2}{4\alpha ^2} \right) , \end{aligned}$$

since \(4\alpha \gamma -\beta ^2 < 0\) holds by assumption. Therefore, we have

$$\begin{aligned} \alpha \left( \left( e_a+ \frac{\beta }{2\alpha } \right) ^2 + \frac{4\alpha \gamma - \beta ^2}{4\alpha ^2} \right) = \alpha \left( \left( e_a+ \frac{\beta }{2\alpha } \right) ^2 - \left( \frac{\sqrt{\beta ^2- 4\alpha \gamma }}{2\alpha }\right) ^2 \right) . \end{aligned}$$

Going back to (12) we have (see also Section 8.1 in [4])

$$\begin{aligned} \int \frac{1}{\alpha (e_a)^2 + \beta e_a+ \gamma } \,\textrm{d}e_a&= \int \frac{1}{\alpha \left( \left( e_a+ \frac{\beta }{2\alpha } \right) ^2- \left( \frac{\sqrt{\beta ^2-4\alpha \gamma }}{2\alpha }\right) ^2 \right) } \,\textrm{d}e_a,\\&= C_1 \int \frac{ \frac{\sqrt{\beta ^2- 4\alpha \gamma }}{\alpha } }{ \left( e_a+ \frac{\beta }{2\alpha } \right) ^2 - \left( \frac{\sqrt{\beta ^2- 4 \alpha \gamma }}{2\alpha }\right) ^2 } \,\textrm{d}e_a, \\&= C_1 \int \frac{\frac{\sqrt{\beta ^2- 4 \alpha \gamma }}{2\alpha } + \frac{\sqrt{\beta ^2- 4 \alpha \gamma }}{2\alpha } +e_a+ \frac{\beta }{2\alpha } - e_a- \frac{\beta }{2\alpha }}{ \left( e_a+ \frac{\beta }{2\alpha } \right) ^2 - \left( \frac{\sqrt{\beta ^2- 4 \alpha \gamma }}{2\alpha }\right) ^2 } \,\textrm{d}e_a,\\&= C_1 \int \left( \left( e_a+ \frac{\beta }{2\alpha }-\frac{\sqrt{\beta ^2- 4 \alpha \gamma }}{2\alpha } \right) ^{-1}\right. \\ {}&\quad \left. - \left( e_a+ \frac{\beta }{2\alpha }+\frac{\sqrt{\beta ^2- 4 \alpha \gamma }}{2\alpha } \right) ^{-1} \right) \,\textrm{d}e_a,\\&= C_1 \ln \left| \frac{2\alpha e_a+ \beta -\sqrt{\beta ^2- 4 \alpha \gamma }}{2\alpha e_a+ \beta +\sqrt{\beta ^2- 4 \alpha \gamma }} \right| + C_2, \end{aligned}$$

where we set

$$\begin{aligned} C_1 \mathrel {{\mathop :}{=}}\frac{1}{\sqrt{\beta ^2- 4\alpha \gamma }}. \end{aligned}$$

The internal energy equation thus reduces to

$$\begin{aligned} \frac{x}{\zeta }= C_1 \ln \left| \frac{2\alpha e_a(x) + \beta -\sqrt{\beta ^2- 4 \alpha \gamma }}{2ae_a(x) + \beta +\sqrt{\beta ^2-4 \alpha \gamma }} \right| + C_2. \end{aligned}$$

By re-substituting the definition of \(C_1\) we may write

$$\begin{aligned} \sqrt{\beta ^2- 4 \alpha \gamma } \left( \frac{x}{\zeta } - C_2 \right) = \ln \left| \frac{2\alpha e_a(x) + \beta -\sqrt{\beta ^2- 4 \alpha \gamma }}{2ae_a(x) + \beta +\sqrt{\beta ^2-4 \alpha \gamma }} \right|. \end{aligned}$$
(13)

We define \(C_3 \mathrel {{\mathop :}{=}}\exp \left( -C_2\sqrt{\beta ^2- 4 \alpha \gamma }\right) \). Then, (13) leads to

$$\begin{aligned} C_3\exp \left( \frac{x \sqrt{\beta ^2- 4 \alpha \gamma }}{\zeta }\right) = \left| \frac{2\alpha e_a(x) + \beta -\sqrt{\beta ^2- 4 \alpha \gamma }}{2ae_a(x) + \beta + \sqrt{\beta ^2-4 \alpha \gamma }} \right|. \end{aligned}$$

The constant \(C_3\) then absorbs the ± sign such that we can write

$$\begin{aligned} C_3\exp \left( \frac{x \sqrt{\beta ^2- 4 \alpha \gamma }}{\zeta }\right) = \left( \frac{2\alpha e_a(x) + \beta -\sqrt{\beta ^2- 4 \alpha \gamma }}{2ae_a(x) + \beta + \sqrt{\beta ^2-4 \alpha \gamma }} \right) . \end{aligned}$$
(14)

We compute \(C_2\) using the initial condition at \(x=0\) and obtain

$$\begin{aligned} C_3 = \left( \frac{2\alpha e_a^0 + \beta -\sqrt{\beta ^2- 4 \alpha \gamma }}{2ae_a^0 + \beta + \sqrt{\beta ^2-4 \alpha \gamma }} \right) . \end{aligned}$$
(15)

Finally, we combine Eqs. (14) and (15), yielding

$$\begin{aligned} e_a(x) =\frac{\sqrt{\beta ^2-4 \alpha \gamma }}{2\alpha }\frac{1+\exp \left( \frac{x\sqrt{\beta ^2-4 \alpha \gamma }}{\zeta }\right) \left( \frac{2\alpha e_a^0+\beta -\sqrt{\beta ^2-4 \alpha \gamma }}{2\alpha e_a^0+\beta +\sqrt{\beta ^2-4 \alpha \gamma }}\right) }{1- \exp \left( \frac{x\sqrt{\beta ^2-4 \alpha \gamma }}{\zeta }\right) \left( \frac{2\alpha e_a^0+\beta - \sqrt{\beta ^2-4 \alpha \gamma }}{2\alpha e_a^0+\beta +\sqrt{\beta ^2-4 \alpha \gamma }}\right) }- \frac{\beta }{2\alpha }. \end{aligned}$$

\(\square \)

Let us further note that the condition \(4 \alpha \gamma - \beta ^2 < 0\) of the last lemma is satisfied for usual pipe parameters.

Corollary 1

The differential equation (M2b), i.e.,

$$\begin{aligned} 0 = v_a\frac{ \,\textrm{d}e_a}{ \,\textrm{d}x} + \frac{4 k_W}{D_a}(T_a- T_\text {W}), \end{aligned}$$

with initial condition

$$\begin{aligned} e_a(0) = e_a^0 > 0 \end{aligned}$$

and state Eq. (7b) has the solution

$$\begin{aligned} e_a(x) =\frac{\sqrt{\beta ^2-4 \alpha \gamma }}{2\alpha }\frac{1+\exp \left( \frac{x\sqrt{\beta ^2-4 \alpha \gamma }}{\zeta }\right) \left( \frac{2\alpha e_a^0+\beta -\sqrt{\beta ^2-4 \alpha \gamma }}{2\alpha e_a^0+\beta +\sqrt{\beta ^2-4 \alpha \gamma }}\right) }{1- \exp \left( \frac{x\sqrt{\beta ^2-4 \alpha \gamma }}{\zeta }\right) \left( \frac{2\alpha e_a^0+\beta - \sqrt{\beta ^2-4 \alpha \gamma }}{2\alpha e_a^0+\beta +\sqrt{\beta ^2-4 \alpha \gamma }}\right) }- \frac{\beta }{2\alpha } \end{aligned}$$

with

$$\begin{aligned} \alpha \mathrel {{\mathop :}{=}}- \frac{4 k_W\theta _2 }{D_a(e_0)^2}, \quad \beta \mathrel {{\mathop :}{=}}- \frac{4 k_W\theta _1 }{D_ae_0}, \quad \gamma \mathrel {{\mathop :}{=}}- \frac{4 k_W}{D_a} (\theta _0 - T_\text {W}), \quad \zeta \mathrel {{\mathop :}{=}}v_a, \end{aligned}$$

if \(4\alpha \gamma -\beta ^2 < 0\) is satisfied.

The proof is analogous to the one of Lemma 1. Figure 1 shows the exact solution of (M1b) for a specific pipe.

The exact solutions derived in the last lemma and corollary could, in principle, be used as constraints in a nonlinear optimization model. However, the fractions, square roots, and exponential functions would lead to a very badly posed problem resulting in an extreme numerical challenge even for state-of-the-art solvers.

Fig. 1
figure 1

Solution of Eq. (M1b) for positive velocities and the parameters \(k_W= {0.5}{\text {W\,m}^{-2}} {\hbox {K}^{-1}}\), \(\lambda _a= 0.017\), \(D_a= {0.107}\,\,\hbox {m}\), \(L_a= {100 0}\,\hbox {m}\), and \(T_\text {W}= {278}\hbox {K}\). The units of the internal energy density \(e_a\) and the velocity \(v_a\) are \({\hbox {GJ\, m}^{-3}}\) and \({\hbox {m\,s}^{-1}}\), respectively

2.1.3 Discretization

In order to solve the optimization problem, we follow the first-discretize-then-optimize approach and introduce an equidistant discretization

$$\begin{aligned} \varGamma _a= \left\{ x_k = k \Delta x_a:k = 0, \dotsc , n_a\right\} \quad \text {with} \quad \Delta x_a = L_a / n_a \end{aligned}$$

of the spatial domain \([0, L_a]\) using the discretization points \( x_k \in \varGamma _a\) with \(0 = x_0< x_1< \cdots < x_{n_a} = L_a\) and step size \(\Delta x_a = L_a / n_a = x_{k+1} - x_k\) for \( k = 0,1, \dotsc , n_a - 1\). We use the implicit mid-point rule to discretize the separate levels of the catalog, i.e., Systems (M1a)–(M3), as well as the state Eq. (7b). Using the abbreviation \(e_a^k \mathrel {{\mathop :}{=}}e_a(x_k)\), we obtain the discretized system

$$\begin{aligned} \begin{aligned} 0&= \frac{p_a(L_a) - p_a(0)}{L_a} + \frac{\lambda _a\rho }{2 D_a} |v_a| v_a+ g\rho h_a', \\ 0&= v_a\left( \frac{e_a^k - e_a^{k-1}}{\Delta x_a} \right) - \frac{\lambda _a\rho }{2 D_a} |v_a| v_a^2 + \frac{4k_W}{D_a} \left( T_a(e_a^k,e_a^{k-1}) - T_\text {W}\right) \end{aligned} \end{aligned}$$
(D1)

for all \(k = 1, \dotsc , n_a\). Discretizing (M2a) analogously leads to

$$\begin{aligned} \begin{aligned} 0&= \frac{p_a(L_a) - p_a(0)}{L_a} + \frac{\lambda _a\rho }{2 D_a} |v_a| v_a+ g\rho h_a',\\ 0&= v_a\left( \frac{e_a^k - e_a^{k-1}}{\Delta x_a} \right) + \frac{4k_W}{D_a} \left( T_a(e_a^k,e_a^{k-1}) -T_\text {W}\right) \end{aligned} \end{aligned}$$
(D2)

for all \(k = 1, \dotsc , n_a\). The discretized systems (D1) and (D2) are closed by the discretized version of the state Eq. (7b), i.e., by

$$\begin{aligned} T_a(e_a^k,e_a^{k-1}) \mathrel {{\mathop :}{=}}\frac{\theta _2}{4 e_0^2} \left( e_a^k + e_a^{k-1}\right) ^2 + \frac{\theta _1}{2e_0} \left( e_a^k + e_a^{k-1}\right) + \theta _0 \end{aligned}$$
(16)

for all \(k = 1, \dotsc , n_a\). For System (M3), we get

$$\begin{aligned} \begin{aligned} 0&= \frac{p_a(L_a) - p_a(0)}{L_a} + \frac{\lambda _a\rho }{2 D_a} |v_a| v_a+ g\rho h_a',\\ 0&= e_a^k - e_a^{k-1}, \end{aligned} \end{aligned}$$
(D3)

for all \(k = 1, \dotsc , n_a\). In our actual computations, we replace the \(n_a\) equations for \(e\) by the single constraint \(e_a(L_a) = e_a(0)\), since a two-point discretization is always exact for this model level.

Fig. 2
figure 2

Model catalog for hot water flow in a pipe

The model catalog (both for the original and the discretized version) is depicted in Fig. 2.

2.2 Nodes

In this section, we discuss the modeling of nodes in the district heating network. To this end, we mainly follow the modeling approach presented in [15]. We model mass conservation via

$$\begin{aligned} \sum _{a\in \delta ^{\text {in}}(u)} q_{a} = \sum _{a\in \delta ^{\text {out}}(u)} q_{a}, \quad u\in {V}, \end{aligned}$$
(17)

where \(\delta ^{\text {in}}(u)\) and \(\delta ^{\text {out}}(u)\) model the set of in- and outgoing arcs of node \(u\), respectively. We assume continuity of pressure at the nodes and obtain

$$\begin{aligned} \begin{aligned} p_u&= p_a(0), \quad u\in {V}, \ a\in \delta ^{\text {out}}(u),\\ p_u&= p_a(L_a), \quad u\in {V}, \ a\in \delta ^{\text {in}}(u), \end{aligned} \end{aligned}$$
(18)

where \(p_u\) is the pressure at node \(u\).

Finally, we have to model how the internal energy is mixed at the nodes of the network. To describe this, we use the perfect mixing model

$$\begin{aligned} \sum _{a\in \delta ^{\text {in}}(u)} \frac{e_{a:u}q_{a}}{\rho }&= \sum _{a\in \delta ^{\text {out}}(u)} \frac{e_{a:u}q_{a}}{\rho }, \end{aligned}$$
(19a)
$$\begin{aligned} 0&= \beta _{a}(e_{a:u} - e_u) , \quad a\in \delta ^{\text {out}}(u), \end{aligned}$$
(19b)
$$\begin{aligned} 0&= \gamma _{a}(e_{a:u} - e_u) , \quad a\in \delta ^{\text {in}}(u), \end{aligned}$$
(19c)

with

$$\begin{aligned} q_{a} = \beta _{a} - \gamma _{a}, \quad \beta _{a} \ge 0, \quad \gamma _{a} \ge 0, \quad \beta _{a} \gamma _{a} = 0 \end{aligned}$$
(20)

for \(a\in \delta (u) = \delta ^{\text {in}}(u) \cup \delta ^{\text {out}}(u)\). Here and in what follows, we denote with \(e_{a:u}\) the internal energy in pipe a at its end node u. For more details and a derivation of this model we refer to [9, 13, 15, 29].

2.3 Depot and consumers

Following [15, 27], for the depot \(a_\text {d}= (u, v)\) we have the constraints

$$\begin{aligned} p_{u}&= p_\textrm{s}, \end{aligned}$$
(21a)
$$\begin{aligned} P_{\textrm{p}}&= \frac{q_{a_\text {d}}}{\rho } \left( p_{a_\text {d}:v} - p_{a_\text {d}:u}\right) , \end{aligned}$$
(21b)
$$\begin{aligned} P_{\textrm{w}}+ P_{\textrm{g}}&= \frac{q_{a_\text {d}}}{\rho } \left( e_{a_\text {d}:v} - e_{a_\text {d}:u}\right) , \end{aligned}$$
(21c)

where \(p_\textrm{s}\) is the so-called stagnation pressure that is used to make the overall pressure profile in the network unique. Moreover, \(P_{\textrm{p}}\) is the power required for the pressure increase realized at the depot, \(P_{\textrm{w}}\) is the power obtained by waste incineration and \(P_{\textrm{g}}\) is the power obtained by burning natural gas. The latter two quantities are used in the depot to increase the internal energy density or, equivalently, the temperature of the water.

In order to model the consumers \(a= (u, v) \in {A}_{\text {c}}\), we use the constraints

$$\begin{aligned} P_a&= \frac{q_{a}}{\rho } \left( e_{a:v} - e_{a:u}\right) , \end{aligned}$$
(22a)
$$\begin{aligned} e_{a:u}&\ge e^{\text {ff}}_a, \end{aligned}$$
(22b)
$$\begin{aligned} e_{a:v}&= e^{\text {bf}}, \end{aligned}$$
(22c)
$$\begin{aligned} p_{v}&\le p_{u}. \end{aligned}$$
(22d)

The first constraint models how the required thermal energy \(P_a\) is obtained in dependence on the mass flow \(q_{a}\) at the consumer and the difference \(e_{a:v} - e_{a:u}\) of the internal energy density. The internal energy density at inflow conditions (\(e_{a:u}\)) needs to be larger than the given threshold \(e^{\text {ff}}_a\) and, at outflow conditions, it is fixed to the network-wide constant \(e^{\text {bf}}\). Finally, the fourth constraint states that the pressure cannot be increased at the household of a consumer.

2.4 Bounds, objective function, and model summary

To complete the model we need to incorporate some technical and physical bounds on the variables of the model and to define a proper objective function. First, we have bounds on the mass flow, i.e.,

$$\begin{aligned} q_a^- \le q_a\le q_a^+, \quad a\in {A}_{\text {ff}}\cup {A}_{\text {bf}}\cup {A}_{\text {c}}, \end{aligned}$$
(23)

on the nodal pressures,

$$\begin{aligned} 0 \le p_u\le p_u^+, \quad u\in {V}, \end{aligned}$$
(24)

and on the nodal water temperatures, i.e.,

$$\begin{aligned} T_u\in [T_u^-,T_u^+], \quad u\in {V}. \end{aligned}$$
(25)

Lastly, we incorporate bounds on power consumption, i.e.,

$$\begin{aligned} P_{\textrm{p}}\in [0,P_{\textrm{p}}^+], \quad P_{\textrm{w}}\in [0,P_{\textrm{w}}^+], \quad P_{\textrm{g}}\in [0,P_{\textrm{g}}^+] \end{aligned}$$
(26)

for given upper bounds \(P_{\textrm{p}}^+\), \(P_{\textrm{w}}^+\), and \(P_{\textrm{g}}^+\).

Our goal is to minimize the overall costs required to satisfy the heat demand of all the consumers. Thus, the objective function is given by

$$\begin{aligned} C_{\text {p}}P_{\textrm{p}}+ C_{\text {w}}P_{\textrm{w}}+ C_{\text {g}}P_{\textrm{g}}, \end{aligned}$$
(27)

where \(C_{\text {p}},C_{\text {w}}\), and \(C_{\text {g}}\), respectively, correspond to the cost of pressure increase, waste incineration, and burning gas.

Taking this all together leads to the discretized and thus finite-dimensional optimization problem

$$\begin{aligned} \begin{aligned} \min \quad&\text {objective: } (27),\\ \text {s.t.}\quad&\text {pipe flow and thermal modeling: } (16) \text { and } (D1), (D2), \text { or } (D3),\\&\text {mass conservation: } (17),\\&\text {pressure continuity: } (18),\\&\text {temperature mixing: } (19), (20),\\&\text {depot constraints: } (21),\\&\text {consumer constraints: } (22),\\&\text {bounds: } (23){-}(26). \end{aligned} \end{aligned}$$
(NLP)

This is a highly nonlinear and, depending on the chosen grids, large-scale optimization problem. Moreover, it only possesses very few degrees of freedom since almost all variables are determined by our physical modeling. Both aspects already make the problem very challenging to solve. In addition, however, the model also contains the complementarity constraints (20), which makes it an ODE-constrained mathematical program with complementarity constraints (MPCC). Solving it for real-world networks is very challenging, which is the motivation of the error measure-based adaptive algorithm that we develop in the two following sections.

3 Error measures

In this section, we introduce the error measures for the adaptive optimization algorithm that is presented in Sect. 4. Our approach is based on the work of [16] and adapted for the problem at hand. The algorithm developed here is designed to iteratively solve the nonlinear program (NLP) until its solution \( y\) is deemed to be feasible w.r.t. a prescribed tolerance. The algorithm iteratively switches the model level and the step sizes of the discretization grids for each pipe according to a switching strategy presented later on. Both the switching strategy and the feasibility check utilize the error measures in this section.

For the (NLP), four error sources can be identified: errors as introduced by the solver of the optimization problem, round-off errors, errors from switching between Systems (D1)–(D3), and errors due to selecting different step sizes of the discretization of the systems. In this work we will only consider the latter two error sources, which we refer to as model (level) errors and discretization (level) errors, respectively. For a discussion of the neglected solver and round-off errors we refer to Remark 1 below. By investigating the Systems (D1)–(D3) one finds that the only difference between them, and hence the resulting error source, is the energy equation and its discretization. This is why we base the definition of the error in each pipe a on its internal energy density \( e_a\).

In general, utilizing estimates of the error of a system allows for the assessment of the quality of their solution if an exact solution is not available. Hence, this section is used to introduce error measure estimates for the model and discretization error. However, since we have the analytic solution of the energy equations of Systems (M1a)–(M3) at hand, we can compute exact errors for the model and discretization error. Having the exact errors available allows us to compare them to the error estimates presented in this work and, hence, determine their quality.

This section is structured as follows. We start by providing the required notation in Sect. 3.1. Furthermore, the rules that are used to refine and coarsen the grids in the discretization of Systems (D1)–(D3) are introduced. In Sect. 3.2, we continue by deriving exact and estimated error measures. We then close this section by proving that the error measure estimates form upper bounds of the exact error measures in a first-order approximation.

Remark 1

Since we want to be able to employ different third-party optimization software packages in our adaptive error control we do not incorporate the errors introduced by the solvers for the optimization problem. However, if error estimates and error control for these errors are available then these can be incorporated as well. It has been observed in the application of adaptive methods for gas networks [16, 32] that round-off errors typically do not contribute much to the global error. For this reason, we also do not consider round-off errors in our adaptive procedure for district heating networks.

3.1 Notation

We start this section by introducing the required quantities and notation. In order to keep the notation lucid, we omit the usage of the subscript \( a\) as much as possible in this section. In particular, we drop the subscript \( a\) for the model level (\( \ell _a\rightarrow \ell \)), the grid size (\( \Delta x_a\rightarrow \Delta x\)), and for the set of gridpoints (\( \varGamma _a\rightarrow \varGamma \)), if not stated otherwise.

Let \( y\) denote the solution of the optimization problem (NLP). For all pipes \( a\in {A}_{\text {p}}\) it contains the approximate solution \( e_a^\ell (x_k; \Delta x) \) for model level \( \ell \) (of pipe model (D\(\ell \))) and step size \( \Delta x\) (of discretization grid \( \varGamma \)) at every grid point \( x_k \in \varGamma \), \( k = 1,\ldots , n \). In addition, for a given pipe \( a\) we denote the exact solution of model (M\(\ell \)), evaluated at \( x_k \in \varGamma \) as \( e_a^\ell (x_k) \). Furthermore, for the approximate and exact solutions we also utilize the notion of \( e_a^\ell (\varGamma ; \Delta x) \mathrel {{\mathop :}{=}}(e_a^\ell (x_1; \Delta x), \ldots , e_a^\ell (x_n; \Delta x))^\top \) and \( e_a^\ell (\varGamma ) \mathrel {{\mathop :}{=}}(e_a^\ell (x_1), \ldots , e_a^\ell (x_n))^\top \), respectively.

We continue by defining the grid refinement and coarsening rules. For a given pipe \( a\), consider a sequence of grids \( \{ \varGamma _i \} \), \( i = 0,1,2,\ldots \), with \( \varGamma _i \mathrel {{\mathop :}{=}}\{x_{k_i}\}_{k_i={0}}^{n_i} \) and \( \Delta x_{i} = x_{k_{i+1}} - x_{k_i} \) for \( k_i = {0},\ldots , n_i \). Moreover, we refer to \( \varGamma _0 \) as the reference or evaluation grid. It is defined by a given number of grid points \( n_0 \) and the corresponding step size \( \Delta x_{0} \mathrel {{\mathop :}{=}}L_a/(n_0 - 1) \). Given an arbitrary grid \( \varGamma _i \), \( i = 0,1,2, \ldots \), we perform a grid refinement step by halving its step size \( \Delta x_i \) to get \( \Delta x_{i+1} = \Delta x_i/2 \) of the refined grid \( \varGamma _{i+1} \). Conversely, we perform a grid coarsening step by doubling \( \Delta x_{i} \) of grid \( \varGamma _{i} \) to obtain the coarsened grid \( \varGamma _{i-1} \) with step size \( \Delta x_{i-1} = 2 \Delta x_{i} \). Performing grid refinement and coarsening this way ensures that for every \( i = 1, 2, \ldots \) it holds that \( \varGamma _0 \subset \varGamma _i \). Therefore, providing a fixed number of grid points \( n_0 \) enables us to use the reference grid \( \varGamma _0 \) as a common evaluation grid for every refinement and coarsening step.

3.2 Derivation of error measures

Since we want to be able to compare the errors of a solution we measure the model and discretization errors by applying the maximum norm to them, which yields the associated model and discretization error measures, respectively.

In the following, we introduce two error measures: exact error measures and error measure estimates. To this end, we consider a single pipe \( a \in {A}_{\text {p}}\). We start by defining the total exact error measure as

$$\begin{aligned} \nu _a(y) \mathrel {{\mathop :}{=}}\Vert e_a^1(\varGamma _0) - e_a^\ell (\varGamma _0; \Delta x_i) \Vert _\infty , \end{aligned}$$
(28)

where we compare the approximate solution of Model (D\(\ell \)) with grid size \( \Delta x_i \) to the exact solution of Model (M1a). Note that \(e_a^\ell (\varGamma _0; \Delta x_i)\) is part of the considered solution \(y\) and that the exact error measure \(e_a^1(\varGamma _0)\) can be, e.g., computed by using the exact formulas given in Sect. 2.1.2. Second, we introduce the exact model error measure via

$$\begin{aligned} \nu ^{\text {m}}_a(y) \mathrel {{\mathop :}{=}}\Vert e_a^1(\varGamma _0) - e_a^\ell (\varGamma _0) \Vert _\infty , \end{aligned}$$
(29)

where we compare the solutions of models (M\(\ell \)) and (M1a). Next, we define the exact discretization error measure as

$$\begin{aligned} \nu ^{\text {d}}_a(y) \mathrel {{\mathop :}{=}}\Vert e_a^\ell (\varGamma _0) - e_a^\ell (\varGamma _0; \Delta x_i) \Vert _\infty , \end{aligned}$$
(30)

for which we compare the solution of Model (D\(\ell \)) with grid size \( \Delta x_i \) to the exact solution of Model (M\(\ell \)). We continue by introducing error measure estimates. The (total) error measure estimate is defined as the sum of a model error measure estimate and a discretization error measure estimate. That is,

$$\begin{aligned} \eta _a(y) \mathrel {{\mathop :}{=}}\eta ^{\text {m}}_a(y) + \eta ^{\text {d}}_a(y) \end{aligned}$$
(31)

with the model error measure estimate

$$\begin{aligned} \eta ^{\text {m}}_a(y) \mathrel {{\mathop :}{=}}\Vert e_a^1(\varGamma _0; \Delta x_i) - e_a^\ell (\varGamma _0; \Delta x_i) \Vert _\infty \end{aligned}$$
(32)

and the discretization error measure estimate

$$\begin{aligned} \eta ^{\text {d}}_a(y) \mathrel {{\mathop :}{=}}\Vert e_a^\ell (\varGamma _0; \Delta x_i) - e_a^\ell (\varGamma _0; \Delta x_{i-1}) \Vert _\infty . \end{aligned}$$
(33)

The model error measure estimate compares two solutions with the same discretization scheme but different pipe models (D1) and (D\(\ell \)). On the other hand, the discretization error measure estimate compares two solutions of the same model but with different discretization schemes as given by the step sizes \( \Delta x_i \) and \( \Delta x_{i-1} \).

By considering the definitions (28)–(33) one finds the relation

$$\begin{aligned} \nu _a(y)&= \Vert e_a^1(\varGamma _0) - e_a^\ell (\varGamma _0; \Delta x_i) + e_a^\ell (\varGamma _0) - e_a^\ell (\varGamma _0) \Vert _\infty \nonumber \\&\le \Vert e_a^1(\varGamma _0) - e_a^\ell (\varGamma _0) \Vert _\infty \, + \Vert e_a^\ell (\varGamma _0) - e_a^\ell (\varGamma _0; \Delta x_i) \Vert _\infty \nonumber \\&= \nu ^{\text {m}}_a(y) + \nu ^{\text {d}}_a(y) \mathrel {{\dot{\le }}}\eta ^{\text {m}}_a(y) + \eta ^{\text {d}}_a(y) = \eta _a(y) \end{aligned}$$
(34)

for \( \Delta x_{i} \rightarrow 0 \).

In the following, we show that the relation (34) holds for \( \Delta x_{i} \rightarrow 0 \). In particular, we need to show that \( \nu ^{\text {d}}_a(y) \mathrel {{\dot{\le }}}\eta ^{\text {d}}_a(y) \) and \( \nu ^{\text {m}}_a(y) \mathrel {{\dot{\le }}}\eta ^{\text {m}}_a(y) \) hold, where the relation \( f_1(x) \mathrel {{\dot{\le }}}f_2(x) \) states that a function \( f_2 \) is a first-order upper bound of the function \( f_1 \) if and only if \( f_1(x) \le f_2(x) + \phi (x) \) for \( x \rightarrow 0 \) and any function \( \phi \in o(\Vert f_2\Vert _{\infty })\). The use of first-order error measure bounds that are obtained by omitting higher-order terms is standard practice in adaptive refinement methods; see, e.g., [34]. In many instances one can also obtain exact upper bounds [14], but these are typically far too pessimistic to be of practical use.

We first proceed by showing that \( \nu ^{\text {d}}_a(y) \mathrel {{\dot{\le }}}\eta ^{\text {d}}_a(y) \) holds for \( \Delta x_{i} \rightarrow 0 \). Since we utilize the implicit mid-point rule to get Systems (D1)–(D3) and the fact that its discretization error measure is of convergence order 2 (see, e.g., [21]) we can write that

$$\begin{aligned} e_a^\ell (x_k) - e_a^\ell (x_k; \Delta x_i)&= c^\ell (x_k) \Delta x_i^2 + {\mathcal {O}}(\Delta x_i^3) \,, \end{aligned}$$
(35)
$$\begin{aligned} e_a^\ell (x_k) - e_a^\ell (x_k; \Delta x_{i-1})&= 4 c^\ell (x_k) \Delta x_i^2 + {\mathcal {O}}(\Delta x_i^3) \,, \end{aligned}$$
(36)

where we use \( \Delta x_{i-1} = 2 \Delta x_i \). Here, the function \( c^\ell (x) \), that arises from the Taylor series expansion of the local discretization error measure, is independent of \( \Delta x_i \); see, e.g., [31]. Computing the difference between (35) and (36) yields

$$\begin{aligned} e_a^\ell (x_k; \Delta x_i) - e_a^\ell (x_k; \Delta x_{i-1}) = 3 c^\ell (x_k) \Delta x_i^2 + {\mathcal {O}}(\Delta x_i^3), \end{aligned}$$
(37)

and, thus,

$$\begin{aligned} c^\ell (x_k) \Delta x_i^2 = \frac{e_a^\ell (x_k; \Delta x_i) - e_a^\ell (x_k; \Delta x_{i-1})}{3} + {\mathcal {O}}(\Delta x_i^3). \end{aligned}$$
(38)

By replacing \(c^\ell (x_k) \Delta x_i^2\) in (35) with the result of (38), applying the \( \infty \)-norm over \(\varGamma _0\) on both sides, and using the triangle inequality, we find

$$\begin{aligned} \nu ^{\text {d}}_a(y) = \Vert \frac{e_a^\ell (x_k; \Delta x_i) - e_a^\ell (x_k; \Delta x_{i-1})}{3} + {\mathcal {O}}(\Delta x_i^3)\Vert _{\infty } \le \frac{1}{3}\eta ^{\text {d}}_a(y) + \Vert {\mathcal {O}}(\Delta x_i^3)\Vert _{\infty }. \end{aligned}$$

Since \(\eta ^{\text {d}}_a(y) \in {\mathcal {O}}(\Delta x_i^2)\) holds as shown in (37), we get that \(\nu ^{\text {d}}_a(y) \mathrel {{\dot{\le }}}\eta ^{\text {d}}_a(y)\) holds for \( \Delta x_{i} \rightarrow 0\).

Finally, we show that \( \nu ^{\text {m}}_a(y) \mathrel {{\dot{\le }}}\eta ^{\text {m}}_a(y) \). The ideas are rather similar. By applying the \(\infty \)-norm over \(\varGamma _0\) and the triangle inequality to the difference between (35) with (M1a) and current model level \(\ell \in \{(M1),(M2),(M3)\}\) we get

$$\begin{aligned} \nu ^{\text {m}}_a(y)&= \Vert e_a^\ell (x_k; \Delta x_i) - e_a^1(x_k; \Delta x_i) + (c^\ell (x_k) - c^1(x_k)) \Delta x_i^2 + {\mathcal {O}}(\Delta x_i^3) \Vert _{\infty }\\&\le \eta ^{\text {m}}_a(y) + \Vert {\mathcal {O}}(\Delta x_i^2)\Vert _{\infty }. \end{aligned}$$

Since \(\eta ^{\text {m}}_a(y) \in {\mathcal {O}}(1)\), we get that \(\nu ^{\text {m}}_a(y) \mathrel {{\dot{\le }}}\eta ^{\text {m}}_a(y)\) holds for \( \Delta x_{i} \rightarrow 0\).

Remark 3

(Computing error measure estimates) Observing the definitions of the error measure estimates (31)–(33) yields that not only the energy \( e_a^\ell (\varGamma _0; \Delta x_i)\), as a part of the solution \(y\), is required to compute the estimates but also the values \( e_a^1(\varGamma _0; \Delta x_i) \) and \( e_a^\ell (\varGamma _0; \Delta x_{i-1}) \), which are not given in terms of the solution \( y\). One could compute these values by recomputing the (NLP) with appropriately modified pipe levels and step sizes. However, this is computationally very costly. An alternative approach is to explicitly solve the modified (w.r.t. appropriately modified model levels and step sizes) energy equations of the Systems (D1)–(D3) by means of implicit numerical integration. Fortunately, this is not required in this work since the energy equations of the Systems (D1)–(D3) together with Eq. (16) allow for solving them algebraically for the energies \( e_a^k \), \( k = 0, 1, \ldots , n \) in linear time.

In the following section we present the algorithm that adaptively switches the previously introduced models and their discretizations by means of a switching strategy.

4 Adaptive algorithm

In this section, we present and analyze the adaptive optimization algorithm. This algorithm is based on the work in [16] and adapted for the district heating network problem studied in this paper. The algorithm iteratively solves the (NLP) while adaptively switching the pipe model levels and discretization step sizes to achieve a locally optimal solution that is feasible w.r.t. to some prescribed tolerance. The adaptive switching is implemented via marking and switching strategies, which are based on the error measures presented in the previous section.

Given an a-priori error measure tolerance \(\varepsilon > 0 \), our method aims at computing a finite sequence of solutions of the nonlinear problem (NLP) in order to achieve a solution \(y\) with an estimated average error measure less or equal to \(\varepsilon \). This motivates the following definition.

Definition 1

Let \(\varepsilon > 0 \) be a given tolerance. The solution \(y\) of the (NLP) is called \(\varepsilon \)-feasible if

$$\begin{aligned} {\bar{\eta }}(y) \mathrel {{\mathop :}{=}}\frac{1}{ |{A}_{\text {p}}| } \sum \limits _{a\in {A}_{\text {p}}} \eta _a(y) \le \varepsilon , \end{aligned}$$

where \({{\bar{\eta }}} (y) \) is called the total average error measure estimate.

The remainder of this section is structured as follows. We first provide the switching and marking strategies used by our algorithm in Sect. 4.1. Then, we present the adaptive algorithm and prove its convergence in Sect. 4.2.

4.1 Switching and marking strategies

In a nutshell, the overall algorithm follows the standard principles of adaptive refinement methods: a problem is solved, an error measure is computed, elements (here pipes) are marked to be refined, the refinement is carried out, and the new problem is solved; see, e.g., [18, 34]. In this section, we describe both the rules that are used to carry out the refinements and the strategies that are used to mark the pipes to be refined.

We now define switching strategies to compute new pipe levels \(\ell _a^\text {new}\) and new step sizes \( \Delta x_a^\text {new}\). Let \(\varepsilon > 0\) be a tolerance and \( \tau \ge 1 \) be a tuning parameter. First, we introduce the model level switching rules. Consider the pipe sets

$$\begin{aligned} {A}_{\text {p}}^{>\varepsilon } {:}{=}\left\{ a\in {A}_{\text {p}}: \eta ^{\text {m}}_a(y; \ell _a) - \eta ^{\text {m}}_a(y; \ell _a^\text {new}) > \varepsilon \right\} \end{aligned}$$
(39)

and

$$\begin{aligned} {A}_{\text {p}}^{<\tau \varepsilon } {:}{=}\left\{ a\in {A}_{\text {p}}: \eta ^{\text {m}}_a(y; \ell _a^\text {new}) - \eta ^{\text {m}}_a(y; \ell _a) < \tau \varepsilon \right\} . \end{aligned}$$
(40)

The set \({A}_{\text {p}}^{>\varepsilon }\) (\({A}_{\text {p}}^{<\tau \varepsilon }\)) contains all the pipes for which the new model level \( \ell _a^\text {new}\) decreases (increases) the model error measure estimate compared to the current model level \( \ell _a\) w.r.t. the error measure tolerance \( \varepsilon \). In order to switch-up the model level (\( \ell _a^\text {new}< \ell _a\)), we apply the rule

$$\begin{aligned} \ell _a^\text {new}= {\left\{ \begin{array}{ll} \ell _a- 1, &{} \quad \ell _a> 1 \ \wedge \ \eta ^{\text {m}}_a(y; \ell _a) - \eta ^{\text {m}}_a(y; \ell _a- 1) > \varepsilon ,\\ 1, &{} \quad \text {otherwise}. \end{array}\right. } \end{aligned}$$
(41)

Similarly, for down-switching of the model level (\( \ell _a^\text {new}> \ell _a\)), we apply the rule

$$\begin{aligned} \ell _a^\text {new}= \min \left\{ \ell _a+ 1, \ell _{\text {max}}\right\} \end{aligned}$$
(42)

with \(\ell _{\text {max}} = 3\) in our setting. According to the rules defined in Sect. 3.1, we apply the following grid refinement and coarsening rule:

$$\begin{aligned} \Delta x_a^\text {new}= {\left\{ \begin{array}{ll} 1/2 \, \Delta x_a, &{} \quad \text {for a grid refinement},\\ 2 \, \Delta x_a, &{} \quad \text {for a grid coarsening}. \end{array}\right. } \end{aligned}$$
(43)

Based on the switching strategies defined in (39)–(43) we can now present our marking strategies that decide for which pipes we switch up or down the model level and for which pipes we refine or coarsen the step size. Let the sets \( {\mathcal {R}}, {\mathcal {U}}\subseteq {A}_{\text {p}}\) represent all pipes marked for grid refinement and model level up-switching, respectively. Furthermore, let the sets \( {\mathcal {C}}, {\mathcal {D}}\subseteq {A}_{\text {p}}\) represent all pipes marked for grid coarsening and model level down-switching, respectively. To avoid unnecessary switching we use threshold parameters \(\varTheta _{\mathcal {R}}\), \(\varTheta _{\mathcal {U}}\), \(\varTheta _{\mathcal {C}}\), \(\varTheta _{\mathcal {D}}\in (0,1)\). We determine \( {\mathcal {R}}\) and \( {\mathcal {U}}\) by finding the minimum subset of pipes \( a\in {A}_{\text {p}}\) such that

$$\begin{aligned} \varTheta _{\mathcal {R}}\sum _{a\in {A}_{\text {p}}} \eta ^{\text {d}}_a(y) \le \sum _{a\in {\mathcal {R}}} \eta ^{\text {d}}_a(y) \end{aligned}$$
(44)

and

$$\begin{aligned} \varTheta _{\mathcal {U}}\sum _{a\in {A}_{\text {p}}^{> \varepsilon }} \big (\eta ^{\text {m}}_a(y; \ell _a) - \eta ^{\text {m}}_a(y; \ell _a^\text {new}) \big ) \le \sum _{a\in {\mathcal {U}}} \big ( \eta ^{\text {m}}_a(y; \ell _a) - \eta ^{\text {m}}_a(y; \ell _a^\text {new}) \big ) \end{aligned}$$
(45)

are satisfied, where in (45), the rule in (41) is applied. Similarly, in order to determine \( {\mathcal {C}}\) and \( {\mathcal {D}}\), we have to find the maximum subset of all pipes \( a\in {A}_{\text {p}}\) such that

$$\begin{aligned} \varTheta _{\mathcal {C}}\sum _{a\in {A}_{\text {p}}} \eta ^{\text {d}}_a(y) \ge \sum _{a\in {\mathcal {C}}} \eta ^{\text {d}}_a(y) \end{aligned}$$
(46)

and

$$\begin{aligned} \varTheta _{\mathcal {D}}\sum _{a\in {A}_{\text {p}}^{<\tau \varepsilon }} \big (\eta ^{\text {m}}_a(y; \ell _a^\text {new}) - \eta ^{\text {m}}_a(y; \ell _a) \big ) \ge \sum _{a\in {\mathcal {D}}} \big (\eta ^{\text {m}}_a(y; \ell _a^\text {new}) - \eta ^{\text {m}}_a(y; \ell _a) \big ) \end{aligned}$$
(47)

hold, where in (47), the rule in (42) is applied.

Remark 3 Note that Definition 1 is based on the total error measure estimate as introduced in the previous section. Since the total exact error measure is upper bounded by the total error measure estimate via (34) one also has that the solution \( y\) of the (NLP) is \( \varepsilon \)-feasible w.r.t. the total average exact error measure \( \bar{\nu }(y) \), i.e., \( {{\bar{\nu }}}(y) \le \varepsilon \) holds with

$$\begin{aligned} {{\bar{\nu }}} (y) \mathrel {{\mathop :}{=}}\frac{1}{|{A}_{\text {p}}|} \sum \limits _{a\in {A}_{\text {p}}} \nu _a(y). \end{aligned}$$

Thus, whenever error measure estimates are used for the switching and marking strategies, the exact error measures can be used as well.

As used before in Sect. 3.2, the first-order approximation of the discretization error measure estimator in \(x \in [0,L_a]\) of a discretization scheme of order \(\beta \) reads \(\eta ^{\text {d}}_a(x) \doteq c(x) \Delta x_a^\beta \), where c(x) is independent of \(\Delta x_a\). This allows us to write

$$\begin{aligned} \eta _a^{\text {d,new}}(x) = \left( \frac{\Delta x_a^{\text {new}}}{\Delta x_a}\right) ^\beta \eta _a^{\text {d}}(x) \end{aligned}$$

for the new discretization error measure estimator after a grid refinement or coarsening. Since the implicit mid-point rule is used in our case, \(\beta = 2\) holds, leading to

$$\begin{aligned} \eta _a^{\text {d,new}}(x) = {\left\{ \begin{array}{ll} \eta _a^{\text {d}}(x)/4, &{}\quad \text {for a grid refinement},\\ 4 \, \eta _a^{\text {d}}(x), &{}\quad \text {for a grid coarsening}. \end{array}\right. } \end{aligned}$$
(48)

This also naturally holds for the exact discretization error measure estimator \(\nu ^{\text {d}}_a(x)\).

Alternative to the error measure estimates that we present, one could use Richardson extrapolation based on errors on different grids to generate error measure estimates. Since our estimates are straightforward, we have not proceeded in this way.

4.2 Adaptive algorithm

In this section we present the adaptive optimization algorithm. The algorithm is formally given in Algorithm 4.2 and described in the following.

The input of the algorithm comprise of a complete description of the network, including initial and boundary conditions, the error tolerance \( \varepsilon > 0 \) as well as initial values for the parameters \( \varTheta _{\mathcal {R}}^0, \varTheta _{\mathcal {U}}^0, \varTheta _{\mathcal {C}}^0, \varTheta _{\mathcal {D}}^0 \in (0,1) \), \( \tau ^0 \le 1 \), \( \mu ^0 \in {\mathbb {N}}_+ \). The output of the algorithm is an \( \varepsilon \)-feasible solution \( y\) of the nonlinear problem (NLP) according to Definition 1.

The algorithm starts by initializing model levels and grid sizes for each pipe. It then solves the (NLP) for the first time and checks for \(\varepsilon \)-feasibility. Since it is likely that after the first iteration the feasibility check fails, the algorithm enters two nested loops: the outer loop for down-switching and coarsening and the inner loop for up-switching and refinement. In this description we will also refer to the outer loop as the k-loop and to the inner loop as the j-loop.

Next, the inner loop is entered and the up-switching and refinement sets \({\mathcal {U}}\) and \({\mathcal {R}}\) are determined. This step is followed by up-switching and refining of each pipe accordingly. Each j-loop finishes by re-solving the (NLP) with the new configuration w.r.t. pipe model levels and grid sizes and it checks for feasibility. The inner loop continues until either a feasible solution \( y\) is found or a maximum number of inner loop iterations \( \mu ^k \) is reached.

What follows in the outer loop is the computation of the coarsening and down-switching sets \( {\mathcal {C}}\) and \( {\mathcal {D}}\), respectively. This step is succeeded by updating the pipe model levels and step sizes. Similar to the inner loop, the outer loop finishes by re-solving the (NLP) and checking for feasibility.

figure a

We first show that the algorithm is finite if we only apply changes to the discretization step sizes while fixing the model levels for all pipes.

Lemma 2

Suppose that the model level \(\ell _a\in \{1, 2, 3\}\) is fixed for every pipe \(a\in {A}_{\text {p}}\). Let the resulting set of model levels be denoted by \({\mathcal {M}}\). Suppose further that \(\eta _a(y) = \eta ^d_a(y) \) holds in (31) and that every (NLP) is solved to local optimality. Consider Algorithm 4.2 without applying the model switching steps in Lines 13 and 25. Then, the algorithm terminates after a finite number of refinements in Line 16 and coarsenings in Line 28 with an \(\varepsilon \)-feasible solution w.r.t. model level set \({\mathcal {M}}\) if there exists a constant C > 0 such that

$$\begin{aligned} \frac{1}{4} \varTheta _{\mathcal {R}}^k \mu ^k \ge \varTheta _{\mathcal {C}}^k + C \end{aligned}$$
(49)

holds and if the step sizes of the initial discretizations are chosen sufficiently small.

Proof

We focus on the total discretization error measure defined as

$$\begin{aligned} \eta ^{\text {d}}(y^j) \mathrel {{\mathop :}{=}}\sum _{a\in {A}_{\text {p}}} \eta ^{\text {d}}_a(y^j) \end{aligned}$$

and show that this quantity is positively bounded away from zero for one outer-loop iteration k containing \(\mu \) inner refinement steps and one coarsening step. For the sake of simplicity we drop the k index.

Hence, we first look at the influence of one inner refinement for-loop iteration \(j \in \{1,\dots ,\mu \}\) on \(\eta ^{\text {d}}(y^j)\). Thus,

$$\begin{aligned} \begin{aligned}&\sum _{a\in {A}_{\text {p}}} \eta ^{\text {d}}_a(y^{j-1}) - \sum _{a\in {A}_{\text {p}}} \eta ^{\text {d}}_a(y^{j}) \\&\quad = \sum _{a\in {A}_{\text {p}}\setminus {\mathcal {R}}^j} \eta ^{\text {d}}_a(y^{j-1}) + \sum _{a\in {\mathcal {R}}^j} \eta ^{\text {d}}_a(y^{j-1}) - \sum _{a\in {A}_{\text {p}}\setminus {\mathcal {R}}^j} \eta ^{\text {d}}_a(y^{j}) - \sum _{a\in {\mathcal {R}}^j} \eta ^{\text {d}}_a(y^{j}) \\&\quad = \sum _{a\in {\mathcal {R}}^j} \eta ^{\text {d}}_a(y^{j-1}) - \sum _{a\in {\mathcal {R}}^j} \frac{1}{4} \eta ^{\text {d}}_a(y^{j-1}) \\&\quad = \frac{3}{4} \sum _{a\in {\mathcal {R}}^j}\eta ^{\text {d}}_a(y^{j-1}), \end{aligned} \end{aligned}$$
(50)

where we use that \(\eta ^{\text {d}}_a(y^{j})\) equals 1/4 of \(\eta ^{\text {d}}_a(y^{j-1})\) if \(\Delta x_a\) is chosen small enough.

Summing up Eq. (50) over all \(j \in \{1,\dots ,\mu \} \) gives the total error measure decrease in the inner for-loop:

$$\begin{aligned}&\sum _{j = 1}^\mu \left( \sum _{a\in {A}_{\text {p}}} \eta ^{\text {d}}_a(y^{j-1}) - \sum _{a\in {A}_{\text {p}}} \eta ^{\text {d}}_a(y^{j}) \right) \\&\quad = \sum _{a\in {A}_{\text {p}}} \eta ^{\text {d}}_a(y^{0}) - \sum _{a\in {A}_{\text {p}}} \eta ^{\text {d}}_a(y^{\mu })\\&\quad = \frac{3}{4} \sum _{j = 1}^\mu \sum _{a\in {\mathcal {R}}^j}\eta ^{\text {d}}_a(y^{j-1}). \end{aligned}$$

We now focus on the final coarsening step of the outer for-loop. For the sake of simplicity we say that \(y^{\mu +1}\) corresponds to the solution of the (NLP) after the coarsening step. Thus,

$$\begin{aligned}&\sum _{a\in {A}_{\text {p}}} \eta ^{\text {d}}_a(y^{\mu +1}) - \sum _{a\in {A}_{\text {p}}} \eta ^{\text {d}}_a(y^{\mu }) \\&\quad = \sum _{a\in {A}_{\text {p}}\setminus {\mathcal {C}}} \eta ^{\text {d}}_a(y^{\mu +1}) + \sum _{a\in {\mathcal {C}}} \eta ^{\text {d}}_a(y^{\mu +1}) - \sum _{a\in {A}_{\text {p}}\setminus {\mathcal {C}}} \eta ^{\text {d}}_a(y^{\mu }) - \sum _{a\in {\mathcal {C}}} \eta ^{\text {d}}_a(y^{\mu }) \\&\quad = 4 \sum _{a\in {\mathcal {C}}} \eta ^{\text {d}}_a(y^{\mu }) - \sum _{a\in {\mathcal {C}}} \eta ^{\text {d}}_a(y^{\mu })\\&\quad = 3\sum _{a\in {\mathcal {C}}} \eta ^{\text {d}}_a(y^{\mu }) \end{aligned}$$

holds, where we again use that \(\eta ^{\text {d}}_a( y^{\mu +1})\) equals \(4 \eta ^{\text {d}}_a(y^{\mu })\) if \(\Delta x_a\) is chosen small enough.

We now prove that the total error measure decrease in each iteration of the outer for loop of Algorithm 4.2 is positive and uniformly bounded away from zero. Hence, we consider

$$\begin{aligned} \sum _{a\in {A}_{\text {p}}} \eta ^{\text {d}}_a(y^{0}) - \sum _{a\in {A}_{\text {p}}} \eta ^{\text {d}}_a(y^{\mu + 1}) = \frac{3}{4} \sum _{j = 1}^\mu \sum _{a\in {\mathcal {R}}^j}\eta ^{\text {d}}_a(y^{j-1}) - 3\sum _{a\in {\mathcal {C}}} \eta ^{\text {d}}_a(y^{\mu }). \end{aligned}$$

Then, using

$$\begin{aligned} \eta ^{\text {d}}_a(y^{j}) \ge \eta ^{\text {d}}_a(y^{\mu }) \quad \text {for all} \quad j = 1, \dots , \mu , \end{aligned}$$

(44), (49), and (46), we obtain

$$\begin{aligned}&\frac{3}{4} \sum _{j = 1}^\mu \sum _{a\in {\mathcal {R}}^j}\eta ^{\text {d}}_a(y^{j-1}) \ge \frac{3}{4} \varTheta _{\mathcal {R}}\sum _{j = 1}^\mu \sum _{a\in {A}_{\text {p}}}\eta ^{\text {d}}_a(y^{j-1}) \ge \frac{3}{4} \varTheta _{\mathcal {R}}\sum _{j = 1}^\mu \sum _{a\in {A}_{\text {p}}}\eta ^{\text {d}}_a(y^{\mu }) \\&\quad = \frac{3}{4} \varTheta _{\mathcal {R}}\mu \sum _{a\in {A}_{\text {p}}}\eta ^{\text {d}}_a(y^{\mu }) \ge 3( \varTheta _{\mathcal {C}}+ C) \sum _{a\in {A}_{\text {p}}}\eta ^{\text {d}}_a(y^{\mu }) \ge 3 \varTheta _{\mathcal {C}}\sum _{a\in {A}_{\text {p}}}\eta ^{\text {d}}_a(y^{\mu }) + C |{A}_{\text {p}}|\varepsilon \\&\quad \ge 3 \sum _{a\in {\mathcal {C}}}\eta ^{\text {d}}_a(y^{\mu }) + C |{A}_{\text {p}}|\varepsilon , \end{aligned}$$

which completes the proof. \(\square \)

Next, we show that the algorithm is finite if we only apply model level changes while the discretization step sizes are kept fixed.

Lemma 3

Suppose that the discretization stepsize \(\Delta x_a\) is fixed for every pipe \(a\in {A}_{\text {p}}\). Suppose further that \(\eta _a(y) = \eta ^{\text {m}}_a(y) \) holds in (31) and that every (NLP) is solved to local optimality. Consider Algorithm 4.2 without applying the discretization refinements in Line 16 and the coarsening step in Line 28. Then, the algorithm terminates after a finite number of model switches in Lines 13 and 25 with an \(\varepsilon \)-feasible solution with respect to the step sizes \(\Delta x_a\), \(a\in {A}_{\text {p}}\), if there exists a constant C > 0 such that

$$\begin{aligned} \varTheta _{\mathcal {U}}^k\mu ^k \ge \tau ^k\varTheta _{\mathcal {D}}^k|{A}_{\text {p}}| + C. \end{aligned}$$
(51)

The proof of this lemma is the same as in [16], which is why we omit it here.

Lemma 4

Let \(y^\mu \) and \(y^{\mu +1}\) be the solution of the optimization problem before and after a refinement or coarsening step, respectively. Let \(\eta ^{\text {d}}_a(y)\) and \(\eta ^{\text {m}}_a(y)\) be the discretization and model error measure estimator for a given solution y of (NLP) as defined in (33) and (32). Then, if

$$\begin{aligned} \eta ^{\text {d}}_a(y^\mu ) \ll \eta ^{\text {m}}_a(y^\mu ) \end{aligned}$$

is satisfied, it holds that

$$\begin{aligned} \eta ^{\text {m}}_a(y^{\mu +1}) = \eta ^{\text {m}}_a(y^{\mu }). \end{aligned}$$
(52)

Proof

For \(x \in \Gamma _{0}\) we introduce \(\eta ^{\text {d}}_a(x;\ell _a,\Delta x_{i})\) and \(\eta ^{\text {m}}_a(x;\ell _a,\Delta x_{i})\) as the local discretization error measure estimator and the local model error measure estimator evaluated at x using the model level \(\ell _a\) and the step size \(\Delta x_{i}\) such that

$$\begin{aligned} \eta ^{\text {d}}_a(x;\ell _a,\Delta x_{i})&\mathrel {{\mathop :}{=}}e^{\ell _a}_a(x; \Delta x_{i}) - e^{\ell _a}_a(x; \Delta x_{i-1}),\\ \eta ^{\text {m}}_a(x;\ell _a,\Delta x_{i})&\mathrel {{\mathop :}{=}}e^{1}_a(x; \Delta x_{i}) - e^{\ell _a}_a(x; \Delta x_{i}) \end{aligned}$$

holds. Since \(\eta ^{\text {d}}_a(x;\ell _a,\Delta x_{i})\) uses the same step sizes \(\Delta x_i\) and \(\Delta x_{i-1}\) for all \(\ell _a\), we have

$$\begin{aligned} |\eta ^{\text {d}}_a(x;\ell _a,\Delta x_{i})| \ll |\eta ^{\text {m}}_a(x;\ell _a,\Delta x_{i})| \iff |\eta ^{\text {d}}_a(x;1,\Delta x_{i})| \ll |\eta ^{\text {m}}_a(x;\ell _a,\Delta x_{i})|. \end{aligned}$$
(53)

We now focus on the coarsening step and prove Eq. (52). The proof for the refinement step is analogous to the coarsening step and is therefore not presented. By definition and due to the coarsening step, we have

$$\begin{aligned} \eta ^{\text {m}}_a(y^{\mu +1})&= \max _{x \in \Gamma _0} \ |e_a^1(x; \Delta x_{i-1}) - e_a^{\ell _a}(x; \Delta x_{i-1}) |\\&= \max _{x \in \Gamma _0} \ |e_a^1(x; \Delta x_{i-1}) - e_a^{\ell _a}(x; \Delta x_{i-1}) + e_a^1(x; \Delta x_{i})\\&\quad - e_a^1(x; \Delta x_{i}) + e_a^{\ell _a}(x; \Delta x_{i}) - e_a^{\ell _a}(x; \Delta x_{i}) |\\&= \max _{x \in \Gamma _0} \ |\eta ^{\text {m}}_a(x;\ell _a,\Delta x_{i}) - \eta ^{\text {d}}_a(x;1,\Delta x_{i}) + \eta ^{\text {d}}_a(x;\ell _a,\Delta x_{i}) |. \end{aligned}$$

Using (53), we finally obtain

$$\begin{aligned} \eta ^{\text {m}}_a(y^{\mu +1}) = \max _{x \in \Gamma _0} \ |\eta ^{\text {m}}_a(x;\ell _a,\Delta x_{i}) |\mathrel {{=}{\mathop :}}\eta ^{\text {m}}_a(y^{\mu }). \end{aligned}$$

\(\square \)

We also have a corresponding result for the estimators of the discretization error measure. For this result, we make the following assumption.

Assumption 1

Let \(y^\mu \) and \(y^{\mu +1}\) be the solution of the optimization problem before and after a model up- or down-switching step, respectively. Moreover, let us denote with \(\lambda ^\mu \) and \(\lambda ^{\mu +1}\) the corresponding sensitivities. Then, there exists a constant \(C > 0\) with \(\Vert \lambda ^\mu - \lambda ^{\mu +1} \Vert \le C\).

Before we now state the next lemma, we briefly discuss this assumption. Informally speaking, it states that the difference of the sensitivities (i.e., of the dual variables) of the optimization problems before and after a model up- or down-switching step is bounded by a constant. We are convinced that this assumption holds for the different models in our catalog.

Lemma 5

Let \(y^\mu \) and \(y^{\mu +1}\) respectively be the solution of the optimization problem before and after a model up or down switching step. Let \(\eta ^{\text {d}}_a(y)\) and \(\eta ^{\text {m}}_a(y)\) be the discretization and model error measure estimator for a given solution y of (NLP) as defined in (33) and (32). Finally, suppose that Assumption 1 holds. Then,

$$\begin{aligned} \eta ^{\text {d}}_a(y^{\mu +1}) = \eta ^{\text {d}}_a(y^{\mu }) \end{aligned}$$
(54)

holds.

Proof

As long as Assumption 1 holds, the error measure estimate for the discretization error measure is independent of the used model and we immediately get the desired result. \(\square \)

We are now ready to prove our main theorem on the finiteness of the proposed algorithm.

Theorem 1

(Finite termination) Suppose that \( \eta ^{\text {d}}_a\ll \eta ^{\text {m}}_a\) for every \(a\in {A}_{\text {p}}\) and that every (NLP) is solved to local optimality. Moreover, suppose that Assumption 1 holds. Then, Algorithm 4.2 terminates after a finite number of refinements, coarsenings, and model switches in Lines 13, 16, 25, and 28 with an \(\varepsilon \)-feasible solution w.r.t. the reference problem if there exist constants \(C_1, C_2 > 0\) such that

$$\begin{aligned} \frac{1}{4} \varTheta _{\mathcal {R}}^k \mu ^k \ge \varTheta _{\mathcal {C}}^k + C_1 \quad \text {and} \quad \varTheta _{\mathcal {U}}^k\mu ^k \ge \tau ^k\varTheta _{\mathcal {D}}^k|{A}_{\text {p}}| + C_2 \end{aligned}$$

hold for all k.

Proof

We first focus on the average total error measure estimator decrease between two subsequent inner loop iterations of Algorithm 4.2. Hence,

$$\begin{aligned} {\bar{\eta }} (y^{j-1}) - {\bar{\eta }} (y^{j})&= \sum _{a\in {A}_{\text {p}}} \eta _a(y^{j-1}) - \sum _{a\in {A}_{\text {p}}} \eta _a(y^{j}) \\&= \sum _{a\in {A}_{\text {p}}} \eta ^{\text {m}}_a(y^{j-1}) + \sum _{a\in {A}_{\text {p}}} \eta ^{\text {d}}_a(y^{j-1}) - \sum _{a\in {A}_{\text {p}}} \eta ^{\text {m}}_a(y^{j}) - \sum _{a\in {A}_{\text {p}}} \eta ^{\text {d}}_a(y^{j}) \\&= \sum _{a\in {A}_{\text {p}}\setminus ( {\mathcal {R}}_j \cup {\mathcal {U}}_j)} \eta ^{\text {m}}_a(y^{j-1}) + \sum _{a\in {\mathcal {U}}_j} \eta ^{\text {m}}_a(y^{j-1}) + \sum _{a\in {\mathcal {R}}_j \setminus {\mathcal {U}}_j }\eta ^{\text {m}}_a(y^{j-1})\\&\quad - \sum _{a\in {A}_{\text {p}}\setminus ( {\mathcal {R}}_j \cup {\mathcal {U}}_j)} \eta ^{\text {m}}_a(y^{j}) - \sum _{a\in {\mathcal {U}}_j} \eta ^{\text {m}}_a(y^{j}) - \sum _{a\in {\mathcal {R}}_j \setminus {\mathcal {U}}_j }\eta ^{\text {m}}_a(y^{j})\\&\quad + \sum _{a\in {A}_{\text {p}}\setminus ( {\mathcal {R}}_j \cup {\mathcal {U}}_j)} \eta ^{\text {d}}_a(y^{j-1}) + \sum _{a\in {\mathcal {R}}_j} \eta ^{\text {d}}_a(y^{j-1}) + \sum _{a\in {\mathcal {U}}_j \setminus {\mathcal {R}}_j} \eta ^{\text {d}}_a(y^{j-1})\\&\quad - \sum _{a\in {A}_{\text {p}}\setminus ( {\mathcal {R}}_j \cup {\mathcal {U}}_j)} \eta ^{\text {d}}_a(y^{j}) - \sum _{a\in {\mathcal {R}}_j} \eta ^{\text {d}}_a(y^{j}) - \sum _{a\in {\mathcal {U}}_j \setminus {\mathcal {R}}_j}\eta ^{\text {d}}_a(y^{j})\\&= \sum _{a\in {\mathcal {U}}_j} \eta ^{\text {m}}_a(y^{j-1}) - \sum _{a\in {\mathcal {U}}_j} \eta ^{\text {m}}_a(y^{j}) + \sum _{a\in {\mathcal {R}}_j} \eta ^{\text {d}}_a(y^{j-1}) - \sum _{a\in {\mathcal {R}}_j} \eta ^{\text {d}}_a(y^{j})\\&= \sum _{a\in {\mathcal {U}}_j} \eta ^{\text {m}}_a(y^{j-1}) - \sum _{a\in {\mathcal {U}}_j} \eta ^{\text {m}}_a(y^{j}) + \sum _{a\in {\mathcal {R}}_j}\frac{3}{4} \eta ^{\text {d}}_a(y^{j-1}) \end{aligned}$$

holds, where we use Lemma 4, Lemma 5, and Eq. (48). Taking the sum over all \(j = 1, \dots , \mu \) inner loop iterations gives

$$\begin{aligned}&\sum _{j = 1}^{\mu }{\bar{\eta }} (y^{j-1}) - {\bar{\eta }} (y^{j}) \\&\quad = {\bar{\eta }} (y^{0}) - {\bar{\eta }} (y^{\mu })\\&\quad = \sum _{j = 1}^{\mu } \left( \sum _{a\in {\mathcal {U}}_j} \eta ^{\text {m}}_a(y^{j-1}) - \sum _{a\in {\mathcal {U}}_j} \eta ^{\text {m}}_a(y^{j}) + \sum _{a\in {\mathcal {R}}_j}\frac{3}{4} \eta ^{\text {d}}_a(y^{j-1}) \right) . \end{aligned}$$

Next, we focus on the outer loop iterations of Algorithm 4.2. We evaluate the average total error measure increase due to the coarsening and down-switching. Hence,

$$\begin{aligned} {\bar{\eta }} (y^{\mu + 1}) - {\bar{\eta }} (y^{\mu })&= \sum _{a\in {A}_{\text {p}}} \eta ^{\text {m}}_a(y^{\mu +1}) + \sum _{a\in {A}_{\text {p}}} \eta ^{\text {d}}_a(y^{\mu +1}) - \sum _{a\in {A}_{\text {p}}} \eta ^{\text {m}}_a(y^{\mu }) - \sum _{a\in {A}_{\text {p}}} \eta ^{\text {d}}_a(y^{\mu }) \\&= \sum _{a\in {A}_{\text {p}}\setminus ( {\mathcal {C}}\cup {\mathcal {D}})} \eta ^{\text {m}}_a(y^{\mu + 1}) + \sum _{a\in {\mathcal {D}}} \eta ^{\text {m}}_a(y^{\mu + 1}) + \sum _{a\in {\mathcal {C}}\setminus {\mathcal {D}}}\eta ^{\text {m}}_a(y^{\mu + 1})\\&\quad - \sum _{a\in {A}_{\text {p}}\setminus ( {\mathcal {C}}\cup {\mathcal {D}})} \eta ^{\text {m}}_a(y^{\mu }) - \sum _{a\in {\mathcal {D}}} \eta ^{\text {m}}_a(y^{\mu }) - \sum _{a\in {\mathcal {C}}\setminus {\mathcal {D}}}\eta ^{\text {m}}_a(y^{\mu })\\&\quad + \sum _{a\in {A}_{\text {p}}\setminus ( {\mathcal {C}}\cup {\mathcal {D}})} \eta ^{\text {d}}_a(y^{\mu + 1}) + \sum _{a\in {\mathcal {C}}} \eta ^{\text {d}}_a(y^{\mu + 1}) + \sum _{a\in {\mathcal {D}}\setminus {\mathcal {C}}}\eta ^{\text {d}}_a(y^{\mu + 1})\\&\quad - \sum _{a\in {A}_{\text {p}}\setminus ( {\mathcal {C}}\cup {\mathcal {D}})} \eta ^{\text {d}}_a(y^{\mu }) - \sum _{a\in {\mathcal {C}}} \eta ^{\text {d}}_a(y^{\mu }) - \sum _{a\in {\mathcal {D}}\setminus {\mathcal {C}}}\eta ^{\text {d}}_a(y^{\mu })\\&= \sum _{a\in {\mathcal {D}}} \eta ^{\text {m}}_a(y^{\mu + 1}) - \sum _{a\in {\mathcal {D}}} \eta ^{\text {m}}_a(y^{\mu }) + \sum _{a\in {\mathcal {C}}} \eta ^{\text {d}}_a(y^{\mu + 1}) - \sum _{a\in {\mathcal {C}}} \eta ^{\text {d}}_a(y^{\mu }) \\&= \sum _{a\in {\mathcal {D}}} \eta ^{\text {m}}_a(y^{\mu + 1}) - \sum _{a\in {\mathcal {D}}} \eta ^{\text {m}}_a(y^{\mu }) + 3 \sum _{a\in {\mathcal {C}}} \eta ^{\text {d}}_a(y^{\mu }), \end{aligned}$$

where we use Lemma 4, Lemma 5, and Eq. (48).

It suffices to prove that the inner loop average total error measure decrease is always greater than the outer loop average total error measure increase, i.e.,

$$\begin{aligned}&\sum _{j = 1}^{\mu } \left( \sum _{a\in {\mathcal {U}}_j} \eta ^{\text {m}}_a(y^{j-1}) - \sum _{a\in {\mathcal {U}}_j} \eta ^{\text {m}}_a(y^{j}) + \sum _{a\in {\mathcal {R}}_j}\frac{3}{4} \eta ^{\text {d}}_a(y^{j-1}) \right) \\&\quad > \sum _{a\in {\mathcal {D}}} \eta ^{\text {m}}_a(y^{\mu + 1}) - \sum _{a\in {\mathcal {D}}} \eta ^{\text {m}}_a(y^{\mu }) + 3 \sum _{a\in {\mathcal {C}}} \eta ^{\text {d}}_a(y^{\mu }). \end{aligned}$$

Using the proofs of Lemmas 2 and 3, we obtain

$$\begin{aligned}&\sum _{j = 1}^{\mu } \left( \sum _{a\in {\mathcal {U}}_j} \eta ^{\text {m}}_a(y^{j-1}) - \sum _{a\in {\mathcal {U}}_j} \eta ^{\text {m}}_a(y^{j}) + \sum _{a\in {\mathcal {R}}_j}\frac{3}{4} \eta ^{\text {d}}_a(y^{j-1}) \right) \\&\quad \ge \varTheta _{\mathcal {U}}\mu \varepsilon + \frac{3}{4} \varTheta _{\mathcal {R}}\mu \sum _{a\in {A}_{\text {p}}}\eta ^{\text {d}}_a(y^{\mu }) \\&\quad \ge (\tau \varTheta _{\mathcal {D}}|{A}_{\text {p}}| + C_2)\varepsilon + 3 (\varTheta _{\mathcal {C}}+ C_1) \sum _{a\in {A}_{\text {p}}}\eta ^{\text {d}}_a(y^{\mu }) \\&\quad \ge \sum _{a\in {\mathcal {D}}} (\eta ^{\text {m}}_a(y^{\mu + 1}) - \eta ^{\text {m}}_a(y^{\mu })) + C_2 \varepsilon + 3 \sum _{a\in {\mathcal {C}}}\eta ^{\text {d}}_a(y^{\mu }) + C_1 |{A}_{\text {p}}|\varepsilon . \end{aligned}$$

This concludes the proof. \(\square \)

5 Numerical results

In this section we present numerical results and for this we first discuss the software and hardware setup. Then, the considered instances are presented and, afterward, the parameterization of the adaptive algorithm is explained.

5.1 Software and hardware setup

We implemented the models in Python  3.7.4 using the Pyomo  6.2 package [10, 11] and solve the resulting NLPs using the NLP solver CONOPT4  4.24 [8], which is interfaced via the Pyomo-GAMS interface. We also tested other solvers and concluded that CONOPT4 is the most reliable solver that performs best for our application. We used the default GAMS settings. The computations were executed on a computer with an Intel(R) Core(TM) i7-8550U processor with eight threads at 1.90GHz and 16GB RAM.

5.2 Test instances

Table 1 Characteristics of the test networks

The two networks considered in this section are the so-called AROMA and STREET networks; see also [15] where they have been used as well. AROMA is an academic test network, whereas STREET is a part of an existing real-world district heating network. Both networks contain cycles but the much larger STREET network only contains a single cycle so that the overall network is almost tree-shaped. Table 1 shows the main characteristics of these networks.

The cost of waste incineration, of natural gas, and of increasing the pressure of the water in the depot are taken from [19] and are set to , , and . Additionally, the gas and pressure power variables \(P_{\textrm{g}}\) and \(P_{\textrm{p}}\) are left unbounded above, whereas the waste power variable \(P_{\textrm{w}}\) is bounded above by 10 kW. Scarce waste incineration power \(P_{\textrm{w}}\) implies an increased consumption of costly power (\(P_{\textrm{p}}\) and \(P_{\textrm{g}}\)) to satisfy the total customer demand and thus yields a non-trivial optimization problem.

5.3 Parameterization of the algorithm

Table 2 Parameters used for the numerical results

Table 2 shows the parameters used for obtaining the numerical results. These parameters are kept constant over the course of the iterations of the algorithm to simplify the interpretation of the results. It should be noted that the parameters do not satisfy the second inequality in Theorem 1. We choose this parameterization despite this fact because the algorithm still converges using these settings and allows for switching down the model level of more pipes and, hence, keeps the optimization model more tractable over the course of the iterations. One could, e.g., by increasing \(\mu \), easily satisfy both inequalities of Theorem 1. For the first iteration of the adaptive algorithm we use \(\Delta x_a= L_a/2\) and \(\ell _a= 3\) for all \(a\in {A}_{\text {p}}\). This forces us to take the reference grid \(\varGamma _0 = \{0,L_a\}\) for all \(a\in {A}_{\text {p}}\). The assumption that the initial granularity of the discretization is sufficiently fine is not satisfied here but does (in practice) not harm the overall convergence of the algorithm and is therefore kept large.

5.4 Discussion of the results obtained by using error measure estimators

Let us first note that none of the tested optimization solvers converges to a feasible point for both the AROMA and the STREET network when using (M1a) and \(\Delta x_a= L_a/ 10\) for all \(a\in {A}_{\text {p}}\), since this spatial discretization already leads to a highly nonlinear problem of a size that is very hard to be tackled by state-of-the-art NLP solvers.

Fig. 3
figure 3

Error measure estimator values (top) and computation times (bottom) over the course of the iterations of the adaptive algorithm using error measure estimators; AROMA network (left) and STREET network (right)

The two upper plots in Fig. 3 show a steady decrease of the values of the error measure estimators over the course of the iterations of the adaptive algorithm. Small increases in the error measure can be observed every five iterations of the algorithm. These arise from the increase of the model level and the coarsening of the discretizations (outer loop) that is carried out after four refinement steps in which we increase the model’s accuracy (inner loop). The error measure plots thus confirm that the algorithm steadily decreases the total error measure over the course of one outer loop iteration.

The results show that the algorithm works as expected and that it terminates after a finite number of iterations with a locally optimal solution of a model that has a physical accuracy for which state-of-the-art solvers are not able to compute a solution from scratch. This is one of the most important contributions of this paper: We can solve realistic instances that have not been solvable before. Additionally, the two lower plots in Fig. 3 show the computation times for the separate models of Type (NLP) that we solve in every iteration. Although we warmstart every new problem with the solution of the previous one, we observe an increase of solution times due to the higher complexity of the successive models that we solve.

Fig. 4
figure 4

Proportion of pipes inside sets \({\mathcal {U}},{\mathcal {R}},{\mathcal {D}}\), and \({\mathcal {C}}\) over the course of iterations of the adaptive algorithm using the error measure estimators; AROMA (left) and STREET (right)

Next, Fig. 4 shows the proportion of pipes inside the sets \({\mathcal {U}}\), \({\mathcal {R}}\), \({\mathcal {D}}\), and \({\mathcal {C}}\) before solving (NLP) for every iteration of the algorithm. The discretization sets represent a larger proportion of pipes when compared to the sets for switching between the model levels. This originates from the parameter selection that favors changes of the discretization and is explained by the fact that the model level of a specific pipe can only be increased twice—unlike the discretization step size that may need to be halved more often. The right plot of Fig. 5 shows violin plots for the amount of grid points in the pipes over the iterations of the algorithm applied to the STREET network. The plot confirms the idea behind the parameter selection. Besides this, Fig. 4 illustrates that the down-switching set \({\mathcal {D}}\) stays empty until the last outer loop iteration for both networks. This is a result of the set \({A}_{\text {p}}^{<\tau \varepsilon }\) being empty for the first outer-loop iterations of the algorithm, which forces \({\mathcal {D}}\) to be empty. The amount of pipes in each model level is shown in the left plot of Fig. 5. Roughly 90% of all pipes end up in the most accurate model level whereas the remaining stay in the intermediate level.

Fig. 5
figure 5

Proportion of pipes inside each model level set (left) and violin plots of the quantity of grid points (right) over the iterations of our adaptive algorithm using the error measure estimators applied on the STREET network

Overall, we see that the behavior of the algorithm is comparable when applied to the two different networks, which indicates that the algorithm is robust.

5.5 Discussion of the results obtained by using exact error measures

We now compare the impact of using the error measure estimators defined in (31)–(33) when employing the exact error measures as defined in (28)–(30). To this end, we only consider the larger STREET network. Figure 6 shows the previously discussed plots using exact error measures. Both approaches need 19 iterations to reach the desired tolerance. However, when looking at the distribution of model levels, we see that in the case of using error measure estimators, a much higher proportion of pipes are modeled using the most accurate model (M1a), which is not the case for any pipe in the exact error measure case; see the bottom-left plot in Fig. 6. Thus, it seems that the error measure estimators overestimate the importance of switching to the most accurate model level. Consequently, using the error measure estimators instead of the exact error measures introduces a larger amount of nonlinearities to the models that are solved in each iteration. This is an interesting aspect and shows that it might be beneficial to use exact error measures if they are available like for the ODEs that we consider in this paper. Nevertheless, the computation times show very similar behavior for both approaches, which makes clear that using error measure estimators (especially in cases in which exact error measure formulas are not available) also leads to an effective method.

Fig. 6
figure 6

Exact error measure values (top-left), computation time (top-right), proportion of pipes inside each model level set (bottom-left), and violin plots of the quantity of grid points (bottom-right) over the course of the iterations of the adaptive algorithm using the exact error measures applied on the STREET network

5.6 Is physical accuracy worth the effort?

Let us close this section with a brief analysis of whether the physical accuracy guaranteed by our adaptive method is worth the computational effort. The answer is a clear “Yes”. To illustrate this, Fig. 7  shows the values of some forward flow variables (pressures, temperatures, and mass flows) that are part of the (NLP) of the AROMA network solved in the first iteration as well as in the last iteration of the adaptive algorithm. The parameter setup used in this test case is the same as presented in Sect. 5.2. Note that the solution of the first iteration (top figure) corresponds to a rather coarse physical modeling whereas the solution of the last iteration (bottom figure) satisfies the prescribed tolerance and is very accurate.

The difference of the solution values are obvious. The first solution has no temperature losses at all (see (M3)) and all temperature values are at the upper bound. Moreover, the mass flow values are comparably small. This changes completely in the final solution. The temperatures have decreased around 50K and mass flows have increased by up to a factor of 3. The pressures have also changed by around 10%. It is clearly visible that the physical solution and the control of the network changes significantly if the physical accuracy is increased. Thus, there is a strong need for computing highly accurate solutions if the resulting controls shall be practically useful.

Fig. 7
figure 7

Forward flow solution of the AROMA network using the error measure estimators after the first (top figure) and last (bottom figure) iteration of the adaptive algorithm. Temperatures in K, pressures in bar, and mass flows in kg s\(^{-1}\)

6 Conclusion

In this paper, we set up a catalog of models for the hot water flow in pipes of district heating networks. For all entries of this catalog, we also derived suitable discretizations to obtain finite-dimensional optimization problems for the energy-efficient control of these networks that still ensures that the demand of all customers are satisfied. Based on these different models, we designed an iterative and adaptive optimization method that automatically adapts the model level in the catalog as well as the granularity of the discretization to finally obtain a local optimal control that is feasible w.r.t. a user-specified tolerance. We show finite termination of this algorithm and present very convincing numerical results that particularly show that we can now solve realistic instances that are not solvable with state-of-the-art commercial NLP solvers.

For our future work, we plan to extend our modeling and solution approach to the case of instationary hot water flow modeling. While we are confident that the overall ideas can be carried over to this PDE-setting, this will most likely require some more technical derivations compared to the ODE-case considered in this paper.