1 Introduction

Over the past decades, mathematical programming has become a widely used tool in the design of chemical or energy conversion processes [10, 24]. Flowsheet optimization, where the operating conditions and sizes of the units of a process are to be optimized with respect to economic or other (e.g., ecological) objectives, has been drawing particular interest because of the scale of the potential savings. If the flowsheet configuration itself, i.e., the selection of the units and their interconnections, is to be optimized as well, superstructure formulations are employed that in general result in mixed integer nonlinear programs (MINLP) including nonconvex functions [11, 35]. However, even the nonlinear programs (NLP) obtained when optimizing the design of processes with fixed configurations can be difficult to solve and are often multimodal.

Local methods have long become state of the art in flowsheet optimization and they are implemented in many commercial process simulators. Solvers have been developed that treat the equations describing the process either in the equation-oriented mode or the sequential modular mode of flowsheet simulation (as well as some intermediate approaches) [11, 24]. In the former approach, all variables are handled by the optimizer and all equations are enforced as equality constraints. The latter approach subdivides the process into a number of separate modules that can be evaluated in a specified order to compute all quantities of interest, with the optimizer operating on a subset of the variables corresponding to the degrees of freedom and variables introduced to decouple the equations [12, 22, 47]. In this case, only few equations are left as equality constraints, while the majority is treated within the modules using specialized solvers, which is a known advantage of this approach. Both methods have been applied successfully to very large process flowsheets.

Methods for deterministic global optimization have also seen increasing interest in process engineering, both for special sub-problems such as heat exchanger network synthesis (see, e.g., [42, 46]) and for flowsheet optimization for fixed process configurations or superstructures [1, 3, 4, 8, 35, 53, 64]. However, almost all of these approaches are based on the equation-oriented mode of flowsheet simulation, because the solvers used require direct access to the nonconvex model equations in order to supply convex relaxations for providing lower bounds to the branch-and-bound (B&B) [26, 29] and related algorithms [41, 55, 56]. This can result in very large optimization problems for complex flowsheets that can easily involve several thousand model variables [24], which is problematic because of the exponential worst-case runtime of B&B-based solvers. In general, it also requires the user to provide bounds for a large number of variables, which may be hard to guess (cf., e.g., [3, 4]). Therefore, methods that operate in a reduced space of variables seem particularly interesting for global optimization.

Several approaches have been suggested for operating in a reduced space by means of selective branching, but these are only applicable to problems containing certain types of equations [25, 54], and while they reduce the dimensionality of the space to branch on, the size of the subproblems to be solved remains unchanged and so does the number of variables for which bounds need to be provided [43]. Therefore, it is desirable to eliminate variables from the optimization problem instead. The extreme is to consider a method in which only the degrees of freedom are optimization variables. However, providing relaxations is challenging in this case because in general, the evaluation of the objective function and constraints involves the solution of a nonlinear equation system [54, 63]. Byrne and Bogle [19] first introduced the idea of using a sequential modular approach for global flowsheet optimization by implementing modules as template functions that can be called with different data types to supply the required bounds for a B&B algorithm. They particularly stressed the advantages of a modular approach from a modeling perspective. However, using interval methods to obtain bounds, they found this approach to be less computationally efficient than equation-oriented formulations [6, 7, 13, 18, 19].

In this work, we present an approach for deterministic global flowsheet optimization that is similar to that of Byrne and Bogle [19] in the sense that it exploits problem structure at the modeling level in analogy to the sequential modular infeasible path method in local optimization. However, instead of interval methods, we rely on the automatic propagation of McCormick relaxations and their subgradients [43], which have been shown to have favorable convergence properties [14, 44].

In the following, we first provide some background on McCormick relaxations in Sect. 2 before summarizing different formulations for deterministic global flowsheet optimization and discussing their suitability for the automatic propagation of McCormick relaxations and subgradients in Sect. 3. In Sect. 4, the implementation of a basic B&B solver is presented that can handle the suggested reduced-space formulation using external function definitions. Since it is meant for demonstration purposes, it relies on further affine relaxation at a single point and thus does not fully exploit the tight McCormick relaxations obtained from the external functions. Finally, in Sect. 5 three case studies for flowsheets of increasing complexity (specifically, steam power cycles for use in combined cycle power plants) are considered in order to demonstrate the significant savings in computational time enabled by the reduced-space formulation in comparison to the conventional equation-oriented formulation because of the reduction in problem size. The latter formulation is solved both with the same basic solver and with the state-of-the-art solver BARON [56]. The models used in the case studies are available as Online Resources.

2 Background material

Global optimization using B&B-based approaches requires convex and concave relaxations of the nonconvex functions involved.

Definition 1

(Relaxation of functions) Given a convex set \(Z \subset {\mathbb {R}}^{n_z}\) and a function \(f:Z\rightarrow {\mathbb {R}}\), a convex function \(f^\text {cv}:Z\rightarrow {\mathbb {R}}\) is called a convex relaxation of f on Z if \(f^\text {cv}(\mathbf {z}) \le f(\mathbf {z})\) for all \(\mathbf {z} \in Z\), and similarly a concave function \(f^\text {cc}:Z\rightarrow {\mathbb {R}}\) is called a concave relaxation of f on Z if \( f^\text {cc}(\mathbf {z}) \ge f(\mathbf {z})\) for all \(\mathbf {z} \in Z\).

McCormick [40] introduced a method for the construction of convex and concave relaxations of factorable functions, i.e., functions defined by a finite recursive composition using binary sums, binary products, and a library of univariate intrinsic functions. Tsoukalas and Mitsos [57] extended the composition theorem to multivariate intrinsic functions. Being a generalization of the univariate composition theorem of McCormick [40], the multivariate composition theorem also allows deriving the known relaxations for binary sums, as well as tighter relaxations for binary products. Therefore, we only repeat the multivariate composition here for the sake of completeness.

Theorem 1

(McCormick relaxation of multivariate composition [57]) Let \(Z\subset {\mathbb {R}}^{n_z}\) and \(X\subset {\mathbb {R}}^{n_x}\) be nonempty compact convex sets. Consider the composite function defined as \(g=F\left( \mathbf {f}(\mathbf {z})\right) \), where \(F:X\rightarrow {\mathbb {R}}\) and for \(i \in I=\{1,\dots ,n_x\}, f_i:Z\rightarrow {\mathbb {R}}\) are continuous functions, and let

$$\begin{aligned} \left\{ \left( f_1(\mathbf {z}),\dots ,{f_{n_i}}(\mathbf {z})\right) \mid \mathbf {z} \in Z\right\} \subset X. \end{aligned}$$

Suppose that convex and concave relaxations \(f^{cv}_i,f^{cc}_i:Z\rightarrow {\mathbb {R}}\) of \(f_i\) on Z are known for every \(i\in I\). Let \(F^{cv},F^{cc}:X\rightarrow {\mathbb {R}}\) be convex and concave relaxations of F on X. Then the functions \(g^{cv},g^{cc}:Z\rightarrow {\mathbb {R}}\) defined as

$$\begin{aligned} g^{cv}(\mathbf {z})=\min \limits _{\mathbf {x}\in X} \left\{ F^{cv}(\mathbf {x}) \mid f^{cv}_i(\mathbf {z}) \le x_i \le f^{cc}_i(\mathbf {z}), ~ \forall i \in I \right\} \\ g^{cc}(\mathbf {z})=\max \limits _{\mathbf {x}\in X} \left\{ F^{cc}(\mathbf {x}) \mid f^{cv}_i(\mathbf {z})\le x_i \le f^{cc}_i(\mathbf {z}), ~ \forall i \in I \right\} \end{aligned}$$

are convex and concave relaxations, respectively, of g on Z.

Mitsos et al. [43] demonstrated how the propagation of McCormick relaxations can be automated to compute relaxations for functions defined by computer codes (similar to the calculation of derivatives via automatic differentiation) implementing factorable functions. This includes a broad class of algorithms with the main restriction that they are either a sequence of explicit function evaluations or involve a finite number of iterations known a priori (such as, e.g., the solution of a system of linear equations or numerical integration using an explicit scheme with fixed step length).

Unlike the auxiliary variable method (AVM) [52, 53, 55, 56], which is also used in the state-of-the-art solver BARON, the recursive application of the composition rules yields relaxations in the original space of variables. However, these relaxations can be weaker than those generated in AVM in case the latter recognizes terms occurring repeatedly [57], and they are known to be nonsmooth. Methods for propagating subgradients of the McCormick relaxations can be found in [43, 57] and are not repeated here for brevity. These subgradients can be used either directly for solving the resulting lower bounding problems using nonsmooth optimization methods, or for deriving affine relaxations.

Definition 2

(Subgradient) Given a nonempty convex set \(Z \subset {\mathbb {R}}^{n_z}\), a convex function \(f^\text {cv}:Z\rightarrow {\mathbb {R}}\), and a concave function \(f^\text {cc}:Z\rightarrow {\mathbb {R}}\), a vector \(\nabla _s f^\text {cv}\in {\mathbb {R}}^{n_z}\) is called a subgradient of \(f^\text {cv}\) at \(\bar{\mathbf {z}}\in Z\) if \(f^\text {cv}(\mathbf {z}) \ge \bar{\mathbf {z}} + (\nabla _s f^\text {cv})^\intercal (\mathbf {z}-\bar{\mathbf {z}})\) for all \(\mathbf {z} \in Z\), and a vector \(\nabla _s f^\text {cc}\in {\mathbb {R}}^{n_z}\) is called a subgradient of \(f^\text {cc}\) at \(\bar{\mathbf {z}}\in Z\) if \(f^\text {cc}(\mathbf {z}) \le \bar{\mathbf {z}} + (\nabla _s f^\text {cc})^\intercal (\mathbf {z}-\bar{\mathbf {z}})\) for all \(\mathbf {z} \in Z\).

Further recent extensions that are beyond the scope of the present work include methods for computing relaxations of bounded functions with discontinuities [62], and for providing relaxations for the solution of ordinary differential equations and nonlinear equation systems [50, 54, 63]. Recently, a differentiable modification of McCormick relaxations was also introduced [34].

3 Optimization formulations

Flowsheets of chemical processes or energy systems typically contain a large number of variables that describe, for example, pressures, temperatures, mass flow rates, and compositions of the process streams, heat and work transfer occurring in different units of the process, or quantities related to the size and cost of the units. When designing (and operating) a process, one or more of these variables are degrees of freedom or design variables \(\mathbf {d} \in D \subset {\mathbb {R}}^{n_d}\) that can be chosen within certain bounds (i.e., \(D=[\mathbf {d}_\text {L},\mathbf {d}_\text {U}]\), where \(\mathbf {d}_\text {L}\) and \(\mathbf {d}_\text {U}\) denote the vectors of lower and upper bounds, respectively, on the components of \(\mathbf {d}\)). These may, for example, include sizes of components, split fractions, but also pressures or temperatures at certain points in the process. Once these design variables have been fixed, the values of the remaining dependent model variables \(\mathbf {x} \in X \subset {\mathbb {R}}^{n_x}\) can be determined by solving the corresponding nonlinear model equations \(\mathbf {h}(\mathbf {d},\mathbf {x})=\mathbf {0},~\mathbf {h}: D \times X \rightarrow {\mathbb {R}}^{n_x}\) (assuming such a solution exists for that particular \(\mathbf {d}\)), which typically consist of the physical relationships describing the different units and the flowsheet connectivity, of cost correlations, as well as design specifications (cf., e.g., [11, 24]). The division of variables into design and dependent model variables is usually not unique but can be chosen to facilitate the solution of the design problem.

In general, the objective function (e.g., production cost of a chemical, or net power output of a power plant) \(f(\mathbf {d},\mathbf {x}),~f: D \times X \rightarrow {\mathbb {R}}\) depends on the design and model variables. Additional inequality constraints \(\mathbf {g}(\mathbf {d},\mathbf {x})\le \mathbf {0},~\mathbf {g}: D \times X \rightarrow {\mathbb {R}}^{n_g}\) can arise from limitations that the design needs to fulfill, such as, e.g., material limits on pressures and temperatures or required product purities, from physical constraints, e.g., for ensuring a positive temperature difference in heat transfer, or from limitations on model validity. From this information, there are several ways to formulate the desired optimization problem for deterministic global optimization.

3.1 Full-space formulation

A natural way of formulating a flowsheet optimization problem is to treat both design variables and dependent model variables as decision variables, and interpret the model equations as equality constraints:

figure a

This full-space formulation is conceptually similar to the equation-oriented mode of flowsheet simulation, in which all model equations are solved simultaneously [11, 24]. It has become increasingly popular for local optimization and can, at least in principle, also be solved with available deterministic global solvers such as BARON [49, 55, 56] or ANTIGONE [41]. For lower bounding, these solvers substitute the functions f, \(\mathbf {h}\), and \(\mathbf {g}\) by convex relaxations by means of, e.g., McCormick relaxations [40] or \(\alpha \)BB relaxations [2, 5], possibly introducing auxiliary variables. For this reason, they require direct access to all equations and variables. However, as discussed above, this leads to very large optimization problems that can result in long if not prohibitive run times of global solvers, as well as pose difficulties in providing sufficiently tight bounds on variables without excluding potential solutions.

3.2 Reduced-space formulations

The fact that typically \(n_d \ll n_x\) motivates alternative formulations that operate in a reduced space of variables.

3.2.1 Implicit function formulation

Since the model equations \(\mathbf {h}(\mathbf {d},\mathbf {x})=\mathbf {0}\) can be solved for the dependent model variables \(\mathbf {x}\) for given values of \(\mathbf {d}\), they define an implicit function \(\hat{\mathbf {x}}: \mathbf {d} \mapsto \hat{\mathbf {x}}(\mathbf {d})\) with the property \(\mathbf {h}(\mathbf {d},\hat{\mathbf {x}}(\mathbf {d}))=\mathbf {0} ~\forall \mathbf {d} \in D\), assuming a unique solution exists for all \(\mathbf {d} \in D\). In this case, the dependent model variables can be eliminated from problem (FS) to obtain (cf. [54, 63])

$$\begin{aligned} \min _{\mathbf {d} \in D} ~~&f(\mathbf {d},\hat{\mathbf {x}}(\mathbf {d}))\\ \text {s.t.} ~~&\mathbf {g}(\mathbf {d},\hat{\mathbf {x}}(\mathbf {d}))\le \mathbf {0}. \end{aligned}$$

This leads to a significant reduction in the dimensionality of the space of decision variables while also eliminating all equality constraints. In local optimization, similar approaches have been known as feasible path methods that fully converge a flowsheet simulation at each iteration of the NLP solver (i.e., they solve for \(\mathbf {x}\) given the current values of \(\mathbf {d}\) in that iteration) [24]. An obvious advantage of this approach is that operation only in the degrees of freedom leads to the smallest possible problems in terms of number of optimization variables. However, since in general the functional form of \(\hat{\mathbf {x}}(\mathbf {d})\) is not known (i.e., it is truly implicit), providing relaxations for \(f(\mathbf {d},\hat{\mathbf {x}}(\mathbf {d}))\) and \(\mathbf {g}(\mathbf {d},\hat{\mathbf {x}}(\mathbf {d}))\) on D is challenging and it is not clear that these will be as tight as in explicit formulations. Additional questions arise when there are multiple solution branches to \(\mathbf {h}(\mathbf {d},\mathbf {x})=\mathbf {0}\) [54, 63]. While methods for providing relaxations of implicit functions recently have been introduced [50, 54, 63], no implementation of these methods is publicly available, and this formulation is thus beyond the scope of this work.

3.2.2 Sequential modular formulations

An alternative is to make use of the fact that the equation systems arising from process modeling are known to be highly structured. In flowsheet simulation, this is exploited in the so-called sequential modular mode, where the equations are grouped into modules that describe single units (or groups of units) of a flowsheet and define a specific input-output relationship [11, 19, 24]. The remaining equations mainly describe the connectivity between the modules. Typically, both the equation systems within the modules and the equations describing flowsheet connectivity are only coupled via few equations that need to be solved iteratively. On the flowsheet level, iterative solution can be required because of loops in the flowsheet, or for satisfying design specifications that prescribe a value for a variable that is part of the output of a module rather than its input, which is to be achieved by varying a variable belonging to a different module. Within the modules, typical examples include flash calculations that are solved by iterating on one or few variables, depending on the property model employed and the specified variables (see, e.g., [11]).

When simulating a flowsheet in sequential modular mode, the latter cases are treated with specialized solution procedures within the modules as part of their input-output relationship. To treat loops in the flowsheet, certain streams (so-called tear streams) within the loops are selected and the equations are decoupled by introducing tear variables \(\mathbf {x}_t \in X_t \subset {\mathbb {R}}^{n_t}\) that are duplicates of the model variables associated with the tear streams. The equations that need to be solved iteratively at the flowsheet level then reduce to the fixed point equations \(\mathbf {x}_t=\hat{\mathbf {h}}_t(\mathbf {d},\mathbf {x}_t), \hat{\mathbf {h}}: D \times X_t \rightarrow X_t\) that enforce the actual connectivity of the tear streams, where \(\hat{\mathbf {h}}_t\) returns the values for the variables in the tear stream calculated by sequentially evaluating the modules given values for the design and tear variables in an order that usually corresponds to the flow of material through the process.

In analogy, flowsheet optimization in sequential modular mode can be formulated as

figure b

Here, the objective function and inequality constraints have been reformulated in a similar manner as the model equations. This way, most of the original model variables \(\mathbf {x}\) and model equations \(\mathbf {h}(\mathbf {d},\mathbf {x})=\mathbf {0}\) have been moved to the modules and are effectively hidden from the optimizer, which only controls the design and tear variables (note that usually \(n_t \ll n_x\)). This approach is widely used in local optimization of flowsheets (termed infeasible path method, since convergence of the flowsheet simulation is only enforced as the optimizer converges) and is implemented in commercial flowsheet simulators [11, 12, 24]. Compared to a fully implicit approach, this leads to larger optimization problems that do contain equality constraints. However, in local optimization it avoids the computational effort required for conducting full flowsheet simulations at each iteration, and is therefore often considered a good compromise [10, 24]. In global optimization, it avoids having to treat the entire model as an implicit function as discussed in Sect. 3.2.1. Nevertheless, some method is still needed for providing relaxations of the functions \(\hat{f}\), \(\hat{\mathbf {h}}_t\) and \(\hat{\mathbf {g}}\) that are defined by some computer code that sequentially evaluates the modules involved. While Byrne and Bogle [19] used interval methods, we choose to utilize McCormick relaxations [40] that can be automatically propagated through such codes along with their subgradients [43], as long as the codes implement factorable functionsFootnote 1 (cf. Sect. 2). An additional advantage of this approach is that bounds on intermediate variables (i.e., those not visible to the optimizer) are not required, since they are propagated along with the relaxations. In case no equations within the modules and no design specifications require iterative solution, problem)(RS) can be solved with a B&B solver by using these methods to propagate relaxations through the module implementations and deriving the required bounding information.

In case some modules do contain equation systems that need to be solved iteratively, the equations coupling these systems along with the corresponding variables can be handed to the optimizer in addition to the ones contained in problem)(RS). Since by assumption the remaining module equations can be solved explicitly for the remaining module variables, this ensures the applicability of the propagation of McCormick relaxations without resorting to implicit functions. The resulting problem is

figure c

where \(\mathbf {x}_m \in X_m \subset {\mathbb {R}}^{n_{x_m}}\) are the additional module variables handled by the optimizer and \(\tilde{\mathbf {h}}_m(\mathbf {d},\mathbf {x}_t,\mathbf {x}_m)=\mathbf {0}, \tilde{\mathbf {h}}_m: D \times X_t \times X_m \rightarrow X_m\) are the corresponding module equations (i.e., only the residual of the equation coupling the system within the module is returned to the optimizer as a component of \(\tilde{\mathbf {h}}_m\)). Such additional equations and variables can also serve to satisfy design specifications, which in some infeasible path methods of local optimization are also left to the optimizer [11]. To achieve this, the deviation of the calculated value (by sequentially solving the modules) from the specified target value is added as a component of \(\tilde{\mathbf {h}}_m\), and the variable to be varied to satisfy this constraint is added as a component of \(\mathbf {x}_m\). Note that (RS*) does not introduce additional multimodality compared to (FS) as is shown in “Appendix A”.

While these formulations were motivated with a modular implementation of the model in mind (c.f. also [19]), this is neither a prerequisite nor is it specific to this formulation. From a solution point of view, the essential feature of formulation (RS*) is that it collects all explicit parts in externally defined functions that the optimizer has no direct access to. These functions can internally have a modular structure in the sense that they utilize sub-models that have been implemented separately, but they can also just contain the model equations arranged to allow sequential explicit evaluation. On the other hand, a modular implementation could also be utilized for the full-space formulation (FS) given a suitable implementation of the external functions.

4 Implementation

Since available deterministic global solvers to our knowledge do not currently support the use of external function definitions, a simple solver was implemented to compare formulations (FS) and (RS*) . Consider the NLP

figure d

where \(\bar{f}: P \rightarrow {\mathbb {R}}\), \(\bar{\mathbf {h}}: P \rightarrow {\mathbb {R}}^{n_{\bar{h}}}\), and \(\bar{\mathbf {g}}: P \rightarrow {\mathbb {R}}^{n_{\bar{\text {g}}}}\) are bounded factorable functions (also including multivariate outer functions, cf. [57]) that can be defined by some computer code not visible to the optimizer. In this sense, to the solver they act as a black box, very similar to the use of external equations in modeling systems like GAMS [27]. The full-space formulation (FS) can be achieved by letting the vector of optimization variables be \(\mathbf {p}=(\mathbf {d}^\intercal ,\mathbf {x}^\intercal )^\intercal \) and implementing the external functions to return the desired values for f, \(\mathbf {h}\) (i.e., the residuals of all model equations), and \(\mathbf {g}\). The reduced-space formulation (RS*) can be achieved by letting \(\mathbf {p}=(\mathbf {d}^\intercal ,\mathbf {x}^\intercal _t,\mathbf {x}^\intercal _m)^\intercal \) and implementing the functions to return \(\tilde{f}\), \(\tilde{\mathbf {h}}_t-\mathbf {x}_t\), \(\tilde{\mathbf {h}}_m\), and \(\tilde{\mathbf {g}}\). In this case, the calculations in the functions can include a multitude of operations conducted sequentially.

The external functions are implemented in C++ as template functions and can thus be called with different data types. In the present implementation, they are called either using floating point types to obtain function values of the objective function and all constraints, using the types defined in FADBAD++  [9] to obtain their gradients with respect to \(\mathbf {p}\) via automatic differentiation (in case the functions involved are differentiable), or using the types defined in the MC++ library [20] to evaluate their convex (cv) and concave (cc) relaxations along with the corresponding subgradients (denoted by \(\nabla _s\)). The latter implements the automatic propagation of McCormick relaxations and extensions [40, 43, 50, 57, 62].

Since the propagation of relaxations and subgradients (as well as gradients) is automated, the implementation of the model itself is not more involved than that of a regular simulation model, with the exception that care has to be taken not to violate the assumptions required for ensuring the applicability of the propagation (cf. Sect. 2). The main restriction is that the models do not involve an iterative solution procedure with unknown number of iterations (i.e., general loops with a conditional statement for termination), which would require the use of specialized methods [54, 63] that are not included in the current implementation (cf. Sect. 3.2.1). Instead, such implicit modules need to be made explicit by leaving appropriate module variables and equations to the optimizer (cf. Sect. 3.2.2). Additionally, the calculations must also not involve conditional statements that give nonsmooth or discontinuous functions, since computing valid relaxations always requires information on the entire domain. Such statements can however be reformulated, either through the use of implemented nonsmooth functions like the maximum of two functions, or using the methods for relaxation of discontinuous functions introduced by Wechsung et al. [62]. However, in this case appropriate care has to be taken for upper bounding since the problem itself is in general nonsmooth. Possible solutions include the use of bundle methods, gradient free methods, or simple function evaluation for upper bounding. As an alternative, one could also resort to mixed integer formulations.

The implemented solver is based on the basic B&B algorithm in C++ employed in [43] using a best-first heuristic and bisection along the longest edge (relative to the initial width) for branching (cf. [29, 38]). Each node k, defined by its lower and upper bounds \(\mathbf {p}^k_\text {L}\) and \(\mathbf {p}^k_\text {U}\) on the optimization variables \(\mathbf {p}\), is successively handed to wrappers for lower and upper bounding that return the respective lower and upper bounds \(\text {LBD}^k\) and \(\text {UBD}^k\), as well as the optimal solution points \(\mathbf {p}^k_\text {LBD}\) and \(\mathbf {p}^k_\text {UBD}\) (see Fig. 1). The node is fathomed if the lower bounding problem is infeasible, or if its lower bound \(\text {LBD}^k\) is not lower than the incumbent objective value by more than the specified optimality tolerance.

Fig. 1
figure 1

Structure of the implemented solver for solving (NLP). To the solver, the model is effectively a black box from which function values and gradients or convex and concave relaxations and the corresponding subgradients can be queried for the objective function and constraints

To obtain a lower bound, a relaxation of (NLP) on the current node can be constructed by replacing equalities by two inequalities each, and using the relaxations of the objective function and constraints returned by the external functions. However, in general the McCormick relaxations obtained are nonsmooth, and therefore a further affine relaxation based on the subgradients is conducted to obtain a linear program (LP) and thus allow the use of robust LP solvers. Examples illustrating the construction of affine relaxations derived from McCormick relaxations and their subgradients can be found in [43]. For simplicity, we evaluate relaxations and subgradients at a single linearization point (\(\mathbf {p}^k_\text {lin}\)) equal to the centerpoint of node k, and thus get the following LP relaxation:

figure e

Tighter relaxations could be obtained by linearizing at multiple points (cf., e.g., [55]), at the expense of increasing the size of the LP and requiring more function evaluations, which may be expensive for large models. Problem (\(\text {LP}^k\)) is solved using CPLEX v12.5 via the C++ API [30]. Optionally, simple range reduction (RR) can be conducted by successively maximizing and minimizing each component of \(\mathbf {p}\) subject to the relaxed constraints in (\(\text {LP}^k\)) and the constraint that the relaxed objective be better than the current upper bound (termed standard range reduction by Locatelli and Schoen [38]), as well as employing bound tightening based on the dual multipliers returned by CPLEX [48]. While other techniques might also be applicable in this case, including probing [48, 55] or the methods introduced in [63], these are beyond the scope of this work.

For upper bounding, the original problem (NLP) subject to \(\mathbf {p} \in [\mathbf {p}^k_\text {L}\), \(\mathbf {p}^k_\text {U}]\) is handed to a local NLP solver, using the optimal solution of the lower bounding problem as initial point. The current implementation uses IPOPT [61] initially. Once a feasible point has been found, few iterations (typically 2–5) of the SLSQP algorithm [36, 37] implemented in the NLopt library v2.4.2 [31] are conducted instead at each node. This is often sufficient to find feasible or even locally optimal solutions as the bounds on \(\mathbf {p}\) within the nodes get tighter through branching, while avoiding excessive computational effort for upper bounding at every node.

5 Case studies

In order to compare the formulations (FS) and (RS*), we consider the bottoming cycle of a combined-cycle power plant (CCPP) as an example. Combined-cycle plants running on natural gas already account for more than 10% of the world electricity production and enjoy increasing popularity due to their high efficiency and low emissions [33]. In a CCPP, the exhaust gas of a gas turbine is run through a heat recovery steam generator (HRSG) that powers a steam (Rankine) cycle. The optimal design of the steam cycle for a given stream of hot exhaust gas is subject of ongoing research. Previous studies have employed different local and heuristic global optimization methods, some using mixed-integer formulations to account for different cycle configurations [3, 16, 32, 39, 60]. With respect to formulation (RS*), steam power cycles represent a special type of flowsheet because in many cases they can be modeled in a completely sequential manner, i.e., they do not require the introduction of tear streams (but possibly handing other equations and variables to the optimizer as described in Sect. 3.2.2).

In the following, we consider three versions of bottoming cycles for CCPP of increasing complexity for a given stream of hot gas turbine exhaust G (characterized by a heat capacity flow rate \((\dot{m} \cdot c_\text {p})_\text {G}\) and an inlet temperature \(T_\text {G,in}\)) and fixed cycle configurations. As objective function, we consider either the maximization of the net power output (\(\dot{W}_\text {net}\)) of the steam cycle, or the minimization of the levelized cost of electricity (LCOE) of the CCPP. Even for a fixed configuration and with the simplest thermodynamic models, the NLPs resulting from the optimization of, e.g., operating pressures, temperatures, and mass flow rates with respect to such thermodynamic or economic objectives are usually nonconvex [39], and can be multimodal, as will also be shown in the following.

5.1 Case Study I: basic Rankine cycle

To demonstrate the multimodality, we first consider a simple single pressure cycle with a fixed outlet temperature of the gas stream \(T_\text {G4}=T_\text {G,out}\) (see Fig. 2), as might be the case, e.g., when burning a sulfur-containing fuel [33]. A stream of water in the saturated liquid state leaves the condenser and is pumped to the upper cycle pressure \(p_2\). In the HRSG, it is first preheated in the economizer to a temperature slightly below its saturation temperature before entering the steam drum of the evaporator. It is then fully evaporated and superheated to the live steam temperature \(T_5\) before entering the turbine, where it is expanded back to the condenser pressure. Since the condenser pressure \(p_1\) and the gas outlet temperature \(T_\text {G,out}\) are assumed to be fixed, the problem has only two degrees of freedom, namely the upper cycle pressure \(p_2\) and the cycle mass flow rate \(\dot{m}\) (cf. Table 1; other choices are also possible).

Fig. 2
figure 2

Case Study I: basic Rankine cycle for extracting work from a given gas stream G. In formulation (RS*), only the variables shown in circles and the constraints shown in boxes are handled by the optimizer in order to either maximize \(\dot{W}_\text {net}\) or minimize LCOE. The problem thus has two degrees of freedom

Table 1 Optimal objective values and ranges and optimal solutions for the optimization variables of formulation (RS*) for Case Study I
Table 2 Problem size and solution times for Case Study I maximizing \(\dot{W}_\text {net}\)
Table 3 Problem size and solution times for Case Study I minimizing LCOE and a time limit of \(10^{5} \, \hbox {s}\)

In the sense of the reduced-space formulation (RS*), the cycle can be simulated sequentially to evaluate the objective function and the constraints without requiring tear streams. The model equations and the calculation sequence for the maximization of \(\dot{W}_{\text {net}}\) along with the fixed parameter values can be found in “Appendix B.1”. The LCOE is calculated based on fuel cost, operating cost and capital investment estimated using sizing data derived from the cycle simulation. Details on the economic evaluation are given in “Appendix C”. Note that if the cycle is modeled in an equation-oriented way, the optimization problem contains more than 44 variables (cf. Tables 2 and 3).

Four inequality constraints arise from physical limitations (cf. Fig. 2). First, the live steam leaving the HRSG needs to be at least fully evaporated (i.e., its enthalpy \(h_5\) must be equal to or greater than the corresponding saturated vapor enthalpy \(h_\text {sat,vap,p5}\)), and its temperature must not exceed the maximum allowable temperature \(T_\text {max}\) for the materials used. Second, there is a minimum temperature difference \(\Delta T_\text {min}\) between exhaust gas and water that must be maintained throughout the HRSG. In this example, the only potential pinch point where this could be violated is in the evaporator at point G3 (here the gas temperature is \(T_\text {G3}\) and the water temperature equals the saturation temperature \(T_\text {sat,p4}\)). Finally, the vapor quality \(x_6\) at the turbine outlet must be higher than a minimum value \(x_\text {min}\) to avoid erosion due to droplet formation [33]. To ensure the validity of the chosen model, an additional constraint is introduced that requires the turbine outlet state 6 to be in the two-phase region, i.e., its vapor quality should be at most unity.

The feasible region of this problem is shown in Fig. 3 along with two level sets of the objective function \(\dot{W}_\text {net}\). The problem exhibits two local optima. The pinch constraint in the HRSG is active for both of them, but one of them exhibits a live steam temperature at its maximum allowable value, whereas for the other the vapor quality at the turbine outlet reaches its minimum allowable value. While the existence of multiple local optima is an open question for more complicated cycles, this example shows that this can be the case even for simple processes.

Fig. 3
figure 3

The basic Rankine cycle (Case Study I) exhibits two local optima shown as circles when maximizing the net power output (\(\dot{W}_\text {net}\), red level sets). The only degrees of freedom are the upper cycle pressure (\(p_2\)) and the cycle mass flow rate (\(\dot{m}\)). The gray areas denote regions that are infeasible (at least one inequality constraint is violated), while the blue lines represent the points where the respective constraints are active

The problem was solved using the implementation described in Sect. 4 both in the reduced-space formulation (RS*) and in the full-space formulation (FS). For the latter, reasonable bounds had to be provided for all variables while ensuring not to cut off potential solutions. These bounds were derived manually using physical insight and partially exploiting the model equations. The full-space formulation was also implemented in GAMS 24.8.4 [27] and solved with BARON v17.4.1 [56]. To improve comparability, we confined the modeling to those features available in GAMS/BARON. This excludes some interesting features of the proposed framework. For example, since the standard definition of the logarithmic mean temperature difference (LMTD) can result in a division by zero, Chen’s approximation [21] was used instead (cf. “Appendix C”), although a well-defined formulation of the actual LMTD with tighter relaxations is available within the present framework [42, 45]. The relative optimality tolerance as well as all constraint feasibility tolerances were set to \(10^{-6}\). The calculations were conducted on a \(\mathrm{{Intel}}^{\circledR }\) \(\mathrm{{Core^{TM}}}\) i3-3240 with 3.4GHz and 16 GB RAM.

Figure 4 shows the incidence matrices for the problem of maximizing \(\dot{W}_\text {net}\) using formulations (FS) and (RS*) . It can be seen that while the incidence matrix of (FS) is sparse, this structure is exploited in (RS*) to achieve a much smaller problem (cf. also Table 2) with a dense incidence matrix. It should be emphasized again that herein this reduction in problem size is achieved at the modeling level through physical insight in the system at hand and in analogy to established strategies for flowsheet simulation and local optimization. A possible alternative could be to derive it from the full-space structure automatically. However, this is beyond the scope of the present work.

Fig. 4
figure 4

Incidence matrix for Case Study I maximizing \(\dot{W}_\text {net}\) using (a) formulation (FS) and (b) formulation (RS*) . The columns correspond to the optimization variables, while the rows correspond to equality constraints, inequality constraints, and objective (in that order). ‘X’ indicates a variable is present in the respective equation, while ‘.’ indicates it is not. Variable and equation names are omitted for better readability

Using the present simple B&B solver without any range reduction for maximizing \(\dot{W}_{net}\), formulation (RS*) is solved orders of magnitude faster than formulation (FS), obviously because of the much smaller problem size (see Table 2). Note that in formulation (FS), some inequalities from formulation (RS*) can be omitted because they can be enforced as part of the variable bounds. The simple range reduction techniques described in Sect. 4 enable significant savings both in the number of iterations and computational time, particularly for (FS). In this example, BARON with its sophisticated branch-and-reduce algorithm can solve (FS) in a single iteration, i.e., without any branching, and it is almost as fast in solving (FS) as the present solver can solve (RS*) . To confirm the importance of the multimodality, the problem was also solved with the local solvers CONOPT [23], IPOPT [61], and KNITRO [17], all of which do converge to the suboptimal local solution (cf. Fig. 3) for certain initial guesses.

When minimizing LCOE, the problem gets more computationally challenging, since the equations used for estimating heat exchanger areas and equipment cost contain many highly nonlinear terms (cf. “Appendix C”). In case of formulation (FS), the problem also increases in size because of the added variables and equations. In formulation (RS*), only some inequalities have to be added to ensure the validity of the cost correlations employed by ensuring a minimum area of the heat exchangers, which in (FS) is again part of the variable boundsFootnote 2. In this case, the present simple solver is not able to solve formulation (FS) within the time limit of \(10^{5}\mathrm{{s}}\thickapprox 28h\) when relying on pure B&B (no feasible point is found, and the lower bound is almost 40% below the optimal objective value), while it can solve (RS*) in less than half a second (cf. Table 3).

BARON takes significantly longer for solving (FS) when minimizing LCOE than the present solver. This suggests that when minimizing LCOE, the problems contain some expressions for which the relaxations in BARON are relatively weak. Both the number of branch-and-reduce iterations and the CPU time needed by BARON can be reduced significantly by means of selective branching (cf. [25, 43, 54]), i.e., setting the branching priorities to force BARON to branch only on \(p_2\) and \(\dot{m}\). However, although branching is only performed on the two degrees of freedom, the subproblems involved still have the large number of variables and constraints of formulation (FS), and the reductions in computational time are by far not as pronounced as when changing from (FS) to (RS*) with the present solver.

The solution with the present solver was also repeated without using the multivariate McCormick relaxations (MV) introduced by Tsoukalas and Mitsos [57] by disabling the corresponding option in MC++ , which implements the multivariate composition rules for binary products, divisions, and the minimum or maximum of two variables (cf. Table 3). The multivariate relaxations do reduce the number of iterations for the present example, since the resulting relaxations are tighter [44, 57]. Because they are also more expensive to compute, the CPU time does not decrease for all cases.

To provide some first insight into the influence of more complex thermodynamic models, Case Study I was also repeated using temperature-dependent sub-models, namely a quadratic model for the ideal gas heat capacity and the Watson equation for the enthalpy of vaporization. In this case, the expressions for enthalpy and entropy of gaseous or liquid streams cannot be solved analytically for temperature any more, which makes both the pump and boiler models implicit. To treat these in the context of formulation (RS*), their outlet temperatures \(T_2\) and \(T_5\) are added as additional optimization variables and the corresponding energy balances are added as equality constraints. The model formulation and results are summarized in “Appendix B.4”.

The optimal solution points and objective values for maximum power output and minimum LCOE are given in Table 4. The maximum power output differs from that predicted with the simpler model by 13%, and both for maximum power output and minimum LCOE the upper bound is now reached for the upper cycle pressure. Note also that the upper bound on the steam temperature \(T_5\) can now be enforced as part of the variable bounds, while it had to be added as an actual inequality constraint for the simpler model.

Table 4 Optimal objective values and ranges and optimal solutions for the optimization variables of formulation (RS*) for Case Study I with temperature dependent thermodynamic sub-models

The main observations in terms of computational performance are similar to the ones made with the simple thermodynamic model used above. Formulation (RS*) is solved faster with the present solver than (FS) is solved in BARON, especially for minimizing LCOE (cf. Tables 5 and 6). Interestingly, when minimizing LCOE BARON can solve the model with the more complex thermodynamics faster than the one with the simple thermodynamics. However, it is still slower than the present solver solving (RS*) by a factor of 880 and 5480 for pure B&B and with simple range reduction in the latter, respectively.

Table 5 Problem size and solution times for maximizing \(\dot{W}_\mathrm{{net}}\) in Case Study I with temperature dependent thermodynamic sub-models
Table 6 Problem size and solution times for minimizing LCOE in Case Study I with temperature dependent thermodynamic sub-models
Fig. 5
figure 5

Case Study II: regenerative Rankine cycle. In formulation (RS*), only the variables shown in circles and the constraints shown in boxes are handled by the optimizer in order to either maximize \(\dot{W}_\text {net}\) or minimize LCOE. Since there is one equality constraint in this formulation, the problem has four degrees of freedom

5.2 Case Study II: regenerative Rankine cycle

A slightly more complex example is considered next (see Fig. 5), where the gas outlet temperature \(T_\text {G4}\) is not fixed any more [33]. Instead, the outlet enthalpy of the superheater \(h_7\) is added as a degree of freedom for formulation (RS*) . An inequality constraint is added to prevent temperature crossover at the economizer inlet. Furthermore, the cycle now contains a deaerator for removing non-condensable gases, which allows operation of the condenser at lower pressure for increased cycle efficiency. In the deaerator, the water is mixed with a two-phase bleed stream extracted from the turbine. The pressure of the turbine bleed is equal to that of the deaerator [65]. This pressure \(p_2\) along with the fraction \(k_\text {Bl}\) of the cycle mass flow rate that is extracted from the turbine are also added as optimization variables (cf. Table 7). The requirement that the liquid leaving the deaerator be in the saturated liquid state to enable the removal of gases is enforced as an equality constraint. From a flowsheet point of view, this corresponds to a design specification. A description of the calculation sequence can be found in “Appendix B.2”.

Table 7 Optimal objective values and ranges and optimal solutions for the optimization variables of formulation (RS*) for Case Study II

When maximizing \(\dot{W}_\text {net}\), the present solver is again not able to solve (FS) with pure B&B within the time limit, while it can solve (RS*) in a similarly short time (or even faster when using simple range reduction) as BARON needs for solving (FS) (cf. Table 8). Interestingly, in this example selective branching on the variables of formulation (RS*) when solving (FS) with BARON increases both the number of iterations and CPU time. We currently do not know why this is the case.Footnote 3 When minimizing LCOE, (RS*) is solved in 7.5 min, or less than 3 min when using simple range reduction (cf. Table 9). BARON still has 6% gap remaining after reaching the time limit when solving (FS) with default settings, while in this case selective branching reduces the gap to 1% when reaching the time limit (cf. Figure 6).

Table 8 Problem size and solution times for Case Study II maximizing \(\dot{W}_\mathrm{{net}}\) and a time limit of \(10^{5}\)s
Table 9 Problem size and solution times for Case Study II minimizing LCOE and a time limit of \(10^5\)s

5.3 Case Study III: two-pressure cycle

Finally, a more sophisticated cycle configuration using two pressure levels in the HRSG is considered, which is one of the preferred layouts for newly installed CCPP [33, 39, 60] (see Fig. 7). After the deaerator, the water is pumped to an intermediate pressure level in the low-pressure (LP) pump and is preheated close to saturation in the LP economizer. Part of the water is then further pumped to a higher pressure level in the high-pressure (HP) pump and again preheated, evaporated, and superheated before entering the HP turbine, which expands the fluid back to the LP pressure level. The remaining water is evaporated and superheated at the LP pressure level and mixed with the HP turbine outlet before entering the LP turbine, which corresponds to the turbines in the previous case studies. In this case, additional degrees of freedom are the outlet pressure \(p_8\) of the HP pump, the outlet enthalpy \(h_{11}\) of the HP superheater, and the fraction \(k_\text {LP}\) of the cycle mass flow rate that is sent through the LP rather than the HP part of the HRSG (cf. Table 10). Additional inequalities are required to ensure a minimum temperature difference in the HRSG, full evaporation in both the LP and HP part of the HRSG, and for ensuring validity of the selected model at the HP turbine outlet (in this case, the enthalpy of the hypothetical isentropic turbine outlet state 12s is required to be above the saturated vapor enthalpy). A description of the calculation sequence can be found in “Appendix B.3”.

Fig. 6
figure 6

Convergence (indicated by the ratio of lower (LBD) and upper (UBD) bounds on the objective) of Case Study II minimizing LCOE. While the reduced-space formulation (RS*) can be solved with a simple solver within a few minutes, the solution of the full-space formulation (FS) takes several hours. In each case, the optimal solution (i.e., optimal UBD) is found relatively quickly, but it takes long for LBD to converge

Fig. 7
figure 7

Case Study III: Two-pressure cycle. In formulation (RS*), only the variables shown in circles and the constraints shown in boxes are handled by the optimizer in order to either maximize \(\dot{W}_\text {net}\) or minimize LCOE. Since there is one equality constraint in this formulation, the problem has seven degrees of freedom

Table 10 Optimal objective values and ranges and optimal solutions for the optimization variables of (RS*) for Case Study III. Since for the minimization of LCOE the solutions returned by BARON and the present solver differ (substantially in the variables, insignificantly in the objective), the latter are given in parentheses
Table 11 Problem size and solution times for Case Study III maximizing \(\dot{W}_{\mathrm{{net}}}\)
Table 12 Problem size and solution progress for Case Study III minimizing LCOE and a time limit of \(10^{5}\)s

For this more complex case study, the relative optimality tolerance was set to \(10^{-2}\), which is still well below the model uncertainty given the simplicity of the thermodynamic models and the inherent uncertainty of the investment cost correlations [58]. In this case, BARON is considerably faster solving (FS) than the present solver solving (RS*) when maximizing \(\dot{W}_\text {net}\) (see Table 11). A solution of (FS) with the present solver was not attempted given the long solution times for (RS*). When minimizing LCOE, the solution of both formulations with the respective solvers takes longer than \(10^{5}\)s (cf. Table 12). However, in the solution of (RS*) with the present solver, the optimality gap is closed faster after the first 0.5 to 3h, leading to a remaining gap of around 6% (or less than 5% with simple range reduction) as compared to 15% (or 13% with selective branching) for solving (FS) with BARON when reaching the time limit (see Fig. 8).

Interestingly, the best solution found by the present solver is 0.4% better than that found by BARON (cf. Table 10). The fact that the values of the optimization variables differ significantly between the two solutions suggest the existence of multiple local optima. In fact, solving (FS) from different starting points with the local solvers CONOPT [23], IPOPT [61], and KNITRO [17] returned several different solutions declared as locally optimal with objective values ranging from 49.6 to 56.3 $/MWh.

Finally it should be noted that in many cases the present solver requires more iterations and also holds more nodes in memory than BARON. When minimizing LCOE for the present case study, it fully utilizes the available RAM towards the end of the runtime. This is a known possible drawback of pure best-first heuristics in B&B [38], and it is probably exacerbated for the present solver by the extremely simple relaxation technique using linearization at a single point (cf. Sect. 4).

Fig. 8
figure 8

Convergence of Case Study III minimizing LCOE. After the first 0.5 to 3h, the optimality gap is closed faster when solving the reduced-space formulation (RS*) with a simple solver than when solving the full-space formulation (FS) with the state-of-the-art solver BARON

6 Conclusions

A problem formulation for deterministic global optimization of process flowsheets analogous to the sequential modular mode of flowsheet simulation was presented that ensures the applicability of the automatic propagation of McCormick relaxations and their subgradients. This formulation operates in a reduced space containing only the design variables and those variables that are required for decoupling the model equations that would require iterative solution. Only the equations coupling the systems are left to the optimizer as equality constraints, while all others are hidden in externally defined functions. Depending on the process considered, this approach leads to significantly smaller problems compared to the conventional full-space formulation. Furthermore, the number of variables for which bounds need to be provided is reduced significantly, while some additional inequalities may be required instead to enforce physically important restrictions on intermediate variables that are not controlled directly by the optimizer. While not necessarily linked to a reduced-space formulation, the approach of providing model equations externally is also attractive from a modeling perspective since it facilitates the construction of model libraries for process units or thermodynamics calculations.

The two formulations were tested on three steam power cycles of increasing complexity. It was shown that the reduced-space formulation can enable deterministic global flowsheet optimization even with a simple B&B algorithm without any range reduction. Both the number of iterations and the CPU time are significantly lower than for solving the full-space formulation with the same solver. In several examples, the solution of the reduced-space formulation with a simple solver can be as fast as or even faster than the solution of the full-space formulation in the state-of-the-art solver BARON, which uses a much more sophisticated branch-and-reduce scheme. The observed differences in performance are greater when minimizing LCOE than when maximizing power output for the given cycles. This can be attributed to the increased complexity and nonlinearity when adding component sizing and investment cost calculation, and apparently some of the added equations are particularly difficult for the current version of BARON, probably resulting in loose relaxations. Since the cycles considered as case studies herein occur in similar form in many more complex systems such as, e.g., advanced zero emission power cycles [28], the present calculations show that this reduced-space approach can be used in these cases as a fast and robust way to globally solve these subproblems.

It should be emphasized that the relaxations used in the present simple solver are relatively weak because of the linearization at a single point. Further improvements could thus likely be achieved in this framework by making better use of the propagated relaxations, e.g., by linearizing at multiple points chosen in a suitable way, or using the nonsmooth relaxations returned from the external functions directly in a nonsmooth NLP solver. However, while tighter relaxations will reduce the number of iterations, it remains to be shown how it affects the solution time, since in the former case the lower bounding problems become larger (in case of multiple linearization points) and in the latter case more challenging due to their nonlinearity. One could also rely on the recently developed smooth modifications of McCormick relaxations [34] in order to utilize regular NLP solvers for lower bounding. A nonsmooth NLP solver could also be used for upper bounding to extend the applicability of the present solver to nonsmooth unit operations. The present approach could also be integrated with more sophisticated branch-and-reduce solvers as soon as they allow the use of external functions for supplying relaxations. However, in this case it would have to be evaluated which of the features for range reduction are still applicable when there is no direct access to all equations and which are not.

Future work should investigate to what extent the advantages of the reduced-space formulation still hold for larger flowsheets, in particular if the difference in problem size to the full space formulation decreases, i.e., for flowsheets requiring many tear streams and containing many implicit unit operations. A first study based on the present work indicates that in such cases careful selection of tear locations as well as variables and equations to be left to the optimizer is required to fully exploit the benefits of the reduced-space formulation [15]. The implications of such decisions should be clarified in order to identify suitable approaches for model formulation. This is expected to be particularly relevant when applying the present approach to chemical processes that exhibit complex recycle structures as well as challenging unit operations because the mixtures involved often require iterative solution to calculate phase equilibria. It might also be possible to automate the construction of such reduced-space formulations from the structure of the full-space problem, thus avoiding the effort of having to find a calculation sequence manually at the modeling level. Finally, it would be interesting to compare the present approach to a fully implicit treatment of the model equations, as well as explore ways of incorporating the methods for handling implicit functions [50, 54, 63] into similar approaches. Since one could choose which equations to eliminate by treating them as an implicit function within the external functions and which to leave to the optimizer, this opens up even more interesting alternatives.