Casting Computational Fluid Mechanics into a Convex Quadratic Optimization Framework
Abstract
We employ the principle of minimum pressure gradient to transform problems in unsteady computational fluid dynamics (CFD) into a convex optimization framework subject to linear constraints. This formulation permits solving, for the first time, CFD problems efficiently using well-established quadratic programming tools or using the well-known Karush-Kuhn-Tucker (KKT) condition. The proposed approach is demonstrated using three benchmark examples. In particular, it is shown through comparison with traditional CFD tools that the proposed framework is capable of predicting the flow field in a lid-driven cavity, in a uniform pipe (Poiseuille flow), and that past a backward facing step. The results highlight the potential of the method as a simple, robust, and potentially transformative alternative to traditional CFD approaches.
keywords:
Computational Methods; Convex Optimization; Variational Methods; Principle of Minimum Pressure Gradient1 Introduction
Although variational methods have demonstrated success in many fields of mechanics (Lanczos, 2012), their implementation in fluid mechanics remains relatively limited (Penfield Jr, 1966). This stems from the difficulty of incorporating dissipative force such as viscosity using the standard Hamiltonian formulation (Bretherton, 1970; Salmon, 1988; Morrison, 1998; Morrison et al., 2020). As a result, traditional computational methods in fluid mechanics remain predominantly confined to Newtonian mechanics where the primary focus is on the solution of the Navier-Stokes equation (NSE) or one of its derivatives (Gresho & Sani, 1987).
In a departure from traditional variational principles that are based on least action, Taha et al. (Gonzalez & Taha, 2022; Taha et al., 2023) used Gauss’ principle of least constraint (Gauß, 1829; Papastavridis, 2014; Udwadia & Kalaba, 1992, 2002, 1996; Udwadia, 2023) to develop a new variational principle in fluid mechanics known as the principle of minimum pressure gradient (PMPG). This principle asserts that an incompressible flow evolves from one instant in time to another such that the total magnitude of the pressure gradient over the domain is minimized. Taha et al. (Taha et al., 2023) proved that the necessary condition to minimize the cost of the pressure gradient is guaranteed to satisfy the NSE, which transforms a fluid mechanics problem into an optimization problem. Taha et al. (Taha et al., 2023) employed PMPG to find analytical solutions to some classical problems in fluid mechanics, including unsteady laminar flow in a channel and Stokes’ second problem. The attained solutions provided additional insights that are otherwise difficult to infer using traditional approaches (Gonzalez & Taha, 2022; Shorbagy & Taha, 2024).
The development of computational frameworks based on PMPG remains limited and is still in its early stages. Recent work has utilized Physics-Informed Neural Networks (PINNs) to solve the optimization problem resulting from PMPG (Sababha et al., 2024; Alhussein & Daqaq, 2024; Atallah et al., 2024). The proposed method, validated against benchmark examples, demonstrated two key advantages. First, it eliminates the pressure-velocity coupling, thereby alleviating the computationally expensive step of solving the Poisson equation at every time step, which often dominates the runtime in traditional algorithms. Second, it removes the need to impose nonphysical outflow boundary conditions, allowing for a reduction in the computational domain required for most fluid mechanics problems. Despite their advantages, the use of PINN for optimization presents several challenges. First, accurately capturing the complexity of fluid flows often necessitates large neural networks, significantly increasing the number of trainable parameters, such as weights and biases. Second, constraints are typically enforced in a soft manner, making it challenging to guarantee their satisfaction throughout the entire domain. Finally, the optimization process remains inherently non-convex, which can result in multiple, potentially inconsistent solutions, as highlighted in previous studies (He et al., 2023; Wang et al., 2023).
In this work, we transform the PMPG computational framework into a quadratic optimization framework. By focusing on the local acceleration as the primary variable, we reformulate the minimization problem into a convex structure subject to linear constraints. This permits the implementation of well-established quadratic programming tools for optimization or a direct solution through the well-known Karush-Kuhn-Tucker (KKT) condition. We demonstrate the effectiveness of this approach and highlight its simplicity using three benchmark examples; namely the flow in a led-driven cavity, the Poiseuille flow, and the flow past a backward step.
The remainder of this paper is organized as follows. Section 2 provides a review of the theoretical foundation of the PMPG. Section 3 presents the formulation of the problem. Section 4 presents the results. Section 5 presents concluding remarks that discuss the advantages and limitations of the current approach, as well as potential extensions.
2 Fluid Mechanics as a Convex Minimization Problem
In the context of the constrained motion of particles, Gauss’ principle of least constraint states that the constrained system accelerates so that it minimizes, in a weighted least-squares sense, the deviation between its current acceleration and that of the free motion (Gauß, 1829). Thus, a particle adjusts its path only to the extent necessary to meet the constraints, ensuring the least possible deviation from the unconstrained trajectory; i.e., its free/natural motion.
In mathematical terms, for -constrained particles, each of mass, , whose motion is described by q generalized coordinates, Gauss’ principle asserts that the quantity
(1) |
also known as the Gaussian cost, is a minimum with respect to the generalized accelerations, , at every instant of time. Here, and are, respectively, the acceleration of the particle, and the net (non-constraint) force acting on it. Gauss’ principle, therefore, turns the mechanics problem governed by Newton’s Equation into the instantaneous minimization problem.
Using the NSE and the definition of the Gaussian cost, Taha et al. (Taha et al., 2023) extended Gauss’ principle of least constraint to a continuum of fluid particles forming an incompressible fluid. They showed that, in the case of some fluid domain, , the Gaussian cost can be written in Eulerian coordinates as:
(2) |
where, , is the density of the fluid, is the fluid velocity vector, and is the kinematic viscosity.
Taha et al. (Taha et al., 2023) further demonstrated that the solution, u, which satisfies NSE and the continuity, , subject to any boundary conditions, is the same as the one that minimizes the functional, , in Equation (2) with respect to the local acceleration, subject to and the same boundary conditions. Thus, for an incompressible fluid domain, , bounded by the surface, , the problem of finding , which satisfies continuity and NSE can be cast in the following form:
Find such that
(3) | ||||||
subject to: | (4) | |||||
(5) |
A fundamental advantage of this formulation is that the expression in Equation (2) is quadratic in , and the constraints are linear. Thus, the solution scheme lends itself naturally to the quadratic optimization family whose solution can be obtained using standard optimization techniques that are straightforward to implement and computationally efficient.
3 Problem Formulation
To solve the minimization problem, we consider a structured domain with equispaced collocation points arranged in an grid. At each node, the optimization variables are , representing the local accelerations in the and directions, respectively. Thus, the total number of optimization variables is . The optimization vector, here denoted as , is constructed by first flattening the and components from the grid, and then concatenating them; transforming the representation from a structured grid into a single optimization vector as:
(6) |
Using the mean rule and the definition of the vector , the integral of the objective function can be re-written in a quadratic form as
(7) |
where is an positive definite matrix often referred to as the Hessian matrix, and is a vector representing external forces arising from the convective and viscous terms. It is worth noting that the objective function in this form excludes constant terms, as they do not influence the optimization process.
Next, we rewrite the continuity constraint (Equation (2.4)) in terms of the vector using the finite difference method. In particular, we approximate the continuity equation at an interior point by using the forward difference formula:
(8) |
Using Equation (8), the continuity equation can be expressed as , where the elements of the matrix at each interior point have non-zero entries at , and . The rest of the elements are zero making the system extremely sparse.
Finally, the boundary conditions are represented by the condition , where the matrix is chosen to ensure that vanishes along the four boundaries. By combining the continuity and boundary constraint matrices, the augmented system of constraints becomes:
(9) |
Equations (7) and (9) represent the standard form of a quadratic optimization problem, which can be solved in a finite amount of computational time (Nocedal & Wright, 2006b). The computational effort required to find a solution is influenced by the characteristics of the objective function. In this case, the matrix is positive definite, making the problem strictly convex. Strictly convex problems are computationally similar to linear programming problems, which are well-known for their efficient solution methods (Nocedal & Wright, 2006a).The solution methodology is outlined in the flowchart 1.

4 Results
To demonstrate the effectiveness of the proposed approach, we consider three benchmark examples in fluid mechanics: the unsteady flow inside a lid-driven cavity (Koseff & Street, 1984), the Poiseuille flow (the unsteady laminar flow in a channel of uniform cross-section), and the unsteady flow in a backward facing step (Biswas et al., 2004). As illustrated in Fig. 2, the characteristic diameter, , is normalized to 1, the inlet velocity, , is set to 1, and the kinematic viscosity, , is chosen such that the Reynolds number is 100 for all examples.

.
The optimization can be carried utilizing well-established quadratic programming. Here we use MATLAB’s quadratic programming toolbox, employing the interior-point-convex algorithm. This algorithm is tailored for large-scale optimization problems, utilizing an advanced sparse linear solver to efficiently address the substantial computational demands. The reliance on sparse solvers is particularly beneficial for problems of this nature, where the number of variables is high, but the matrices and exhibit significant sparsity (Nocedal & Wright, 2006a).
Alternatively, the vector which minimizes Equation (7) subject to Equation (9) is given by:
(10) |
where is positive definite111For an equispaced grid similar to the one considered in this analysis, turns out to be the identity matrix and is therefore guaranteed to be positive definite., and is the vector of Lagrange multipliers. Equation (10) is a consequence of the general result of the first-order optimality condition commonly referred to as the Karush-Kuhn-Tucker (KKT) condition (Nocedal & Wright, 2006b).
Simulations for the lid-driven cavity were performed over the time range . The minimized cost objective was compared with the values obtained from a traditional high-fidelity CFD model (see ref. (Sababha et al., 2024)), revealing excellent agreement between the two approaches. As shown in Fig. 3(a), initially decreases sharply, then increases at a diminishing rate, eventually stabilizing to indicate the steady-state condition, where the local acceleration approaches zero. To further validate the proposed method, we compared the predicted flow field at focusing on the middle cross-section, namely (a-a) as highlighted in Fig. 2. A comparison between the values of as obtained using the proposed optimization framework (solid line) and those obtained using the high-fidelity model (dashed lines) demonstrates excellent agreement as shown in Fig. 3(b).

.
Results for the 2D Poiseuille flow are presented in Fig.4. Simulations were conducted over the time range , showcasing the evolution of the developing flow at various time intervals. The transition from an initially uniform profile to a fully developed state is clearly observed, with boundary layer growth along the walls. Additionally, the predicted flow field at the outlet is shown, demonstrating a parabolic profile that aligns closely with the analytical solution derived from the Navier-Stokes equations (White & Xue, 2003).

.
Finally, the results for the backward-facing step are presented, with simulations conducted over the time interval . The temporal evolution of the streamlines is illustrated in Fig. 5, showcasing the transition from an initially uniform velocity profile to a fully developed flow state. The extent of the primary recirculation region is clearly evident, and its measured length is in excellent agreement with the numerical results reported in reference (Biswas et al., 2004).

.
5 Concluding Remarks
This study presents a new approach to solving incompressible fluid mechanics problems. In particular, using PMPG, we transform the CFD problem into a convex optimization framework subject to linear constraints and solve it using well-established quadratic programming tools. A direct solution can also be obtained using the well-known Karush-Kuhn-Tucker condition. The approach is implemented using the well-known unsteady lid-driven cavity problem requiring only a few lines of MATLAB code (see Appendix B), in contrast to the lengthy and complex codes often required by conventional finite volume methods, such as those used in Ansys or OpenFOAM. The results are compared to high-fidelity CFD simulations, demonstrating excellent agreement and showcasing the potential of this framework as an efficient and robust alternative to traditional CFD tools. The simplicity of the proposed method not only makes modeling fluid mechanics more accessible but also expands the potential user base, eliminating the need for custom computational frameworks.
In addition, using PMPG to cast CFD problems into a convex optimization framework offers two key advantages. First, by eliminating the pressure from the formulation, the need for pressure-velocity coupling is removed, thus avoiding the computationally expensive step of solving the Poisson equation after every time step. Second, the convexity of the problem guarantees a solution in finite time.
Compared to the previous work of the authors (Sababha et al., 2024), which employed an optimization framework based on physics-informed neural networks (PINNs), this approach offers distinct advantages. First, it preserves the convexity of the problem, avoiding the challenges of non-convex training procedures in PINNs that often lead to sub-optimal performance due to the presence of local minima. Second, it ensures accurate enforcement of constraints, which are critical for obtaining physically valid solutions. PINN-based methods frequently exhibit constraint violations in certain regions, resulting in approximate but not exact solutions.
Despite these advantages, this formulation has certain limitations, as it is currently limited to square domains. Extending the method to handle irregular domains and/or domains with unstructured collocation points is a critical next step in broadening its utility. Moreover, although the advantages of the method are evident, a rigorous comparison with traditional solvers, such as finite-volume methods, is essential to fully assess the performance and applicability of the method. Benchmarking against these established tools will provide valuable information on the accuracy, computational cost, and scalability of the solution, enabling a clearer understanding of the advantages and limitations of this approach. Additionally, exploring the performance of different optimization algorithms within our framework, such as active set methods or gradient projection methods, could uncover further potential that is yet to be fully explored.
Finally, we believe that this work represents a notable step forward in addressing CFD problems. It illustrates that minimizing the pressure gradient transforms them into a convex optimization framework with guaranteed global minima that can be tackled efficiently using a wide array of well-established robust optimization tools. Furthermore, it appears that this new formulation provides a more natural approach to solving incompressible fluid mechanics. For instance, removing pressure from the formulation inherently eliminates several challenges commonly encountered in computational fluid mechanics. These include the need to solve the pressure Poisson equation (Chorin, 1997; Toutant, 2018), the complexity of prescribing appropriate boundary conditions (Papanastasiou et al., 1992), and issues such as spurious oscillations that arise from interpolation in collocated grids (Zhang et al., 2014). Nevertheless, while pressure is removed from the formulation, it can still be recovered from the Lagrange multipliers in Equation (10), since the pressure serves as a Lagrange multiplier enforcing the continuity constraint (Gresho & Sani, 1987).
Appendix A Code Implementation
The MATLAB code for solving the lid-driven cavity problem using quadratic programming is presented below. It is evident that this approach is more concise and straightforward compared to traditional methods.
References
- Alhussein & Daqaq (2024) Alhussein, Hussam & Daqaq, Mohammed 2024 The principle of minimum pressure gradient: An alternative basis for physics-informed learning of incompressible fluid mechanics. AIP Advances 14 (4).
- Atallah et al. (2024) Atallah, Ahmed, Elmaradny, Abdelrahman & Taha, Haithem E 2024 A novel approach for data-free, physics-informed neural networks in fluid mechanics using the principle of minimum pressure gradient. In AIAA SCITECH 2024 Forum, p. 2742.
- Biswas et al. (2004) Biswas, Gautam, Breuer, Michael & Durst, Franz 2004 Backward-facing step flows for various expansion ratios at low and moderate reynolds numbers. J. Fluids Eng. 126 (3), 362–374.
- Bretherton (1970) Bretherton, Francis P 1970 A note on hamilton’s principle for perfect fluids. Journal of Fluid Mechanics 44 (1), 19–31.
- Chorin (1997) Chorin, Alexandre Joel 1997 A numerical method for solving incompressible viscous flow problems. Journal of computational physics 135 (2), 118–125.
- Gauß (1829) Gauß, C. F. 1829 Über ein neues allgemeines grundgesetz der mechanik. Journal für die reine und angewandte Mathematik 1829 (4), 232–235.
- Gonzalez & Taha (2022) Gonzalez, Cody & Taha, Haithem E 2022 A variational theory of lift. Journal of Fluid Mechanics 941, A58.
- Gresho & Sani (1987) Gresho, Philip M & Sani, Robert L 1987 On pressure boundary conditions for the incompressible navier-stokes equations. International Journal for Numerical Methods in Fluids 7 (10), 1111–1145.
- He et al. (2023) He, Yichuan, Wang, Zhicheng, Xiang, Hui, Jiang, Xiaomo & Tang, Dawei 2023 An artificial viscosity augmented physics-informed neural network for incompressible flow. Applied Mathematics and Mechanics 44 (7), 1101–1110.
- Koseff & Street (1984) Koseff, JR & Street, RL 1984 The lid-driven cavity flow: a synthesis of qualitative and quantitative observations .
- Lanczos (2012) Lanczos, Cornelius 2012 The variational principles of mechanics. Courier Corporation.
- Morrison (1998) Morrison, Philip J 1998 Hamiltonian description of the ideal fluid. Reviews of modern physics 70 (2), 467.
- Morrison et al. (2020) Morrison, P. J., Andreussi, T. & Pegoraro, F. 2020 Lagrangian and dirac constraints for the ideal incompressible fluid and magnetohydrodynamics. Journal of Plasma Physics 86 (3), 835860301.
- Nocedal & Wright (2006a) Nocedal, Jorge & Wright, Stephen J 2006a Penalty and augmented lagrangian methods. Numerical Optimization pp. 497–528.
- Nocedal & Wright (2006b) Nocedal, Jorge & Wright, Stephen J 2006b Quadratic programming. Numerical optimization pp. 448–492.
- Papanastasiou et al. (1992) Papanastasiou, Tasos C, Malamataris, Nikos & Ellwood, Kevin 1992 A new outflow boundary condition. International journal for numerical methods in fluids 14 (5), 587–608.
- Papastavridis (2014) Papastavridis, J.G. 2014 Analytical mechanics: a comprehensive treatise on the dynamics of constrained systems – Reprint edition.. Word Scientific Publishing Company.
- Penfield Jr (1966) Penfield Jr, P. 1966 Hamilton’s principle for fluids. The Physics of Fluids 9 (6), 1184–1194.
- Sababha et al. (2024) Sababha, H, Elmaradny, A, Taha, H & Daqaq, M 2024 A variational computational-based framework for unsteady incompressible flows. arXiv preprint arXiv:2412.05525 .
- Salmon (1988) Salmon, Rick 1988 Hamiltonian fluid mechanics. Annual review of fluid mechanics 20 (1), 225–256.
- Shorbagy & Taha (2024) Shorbagy, Mohamed & Taha, Haithem 2024 Magnus force estimation using gauss’s principle of least constraint. AIAA Journal 62 (5), 1962–1969.
- Taha et al. (2023) Taha, Haithem, Gonzalez, Cody & Shorbagy, Mohamed 2023 A minimization principle for incompressible fluid mechanics. Physics of Fluids 35 (12).
- Toutant (2018) Toutant, Adrien 2018 Numerical simulations of unsteady viscous incompressible flows using general pressure equation. Journal of Computational Physics 374, 822–842.
- Udwadia (2023) Udwadia, Firdaus E 2023 The general gauss principle of least constraint. Journal of Applied Mechanics 90 (11).
- Udwadia & Kalaba (1992) Udwadia, F. E. & Kalaba, R. E. 1992 A new perspective on constrained motion. Proceedings of the Royal Society of London. Series A: Mathematical and Physical Sciences 439 (1906), 407–410.
- Udwadia & Kalaba (1996) Udwadia, F. E. & Kalaba, R. E. 1996 Analytical dynamics.
- Udwadia & Kalaba (2002) Udwadia, Firdaus E & Kalaba, Robert E 2002 On the foundations of analytical dynamics. International Journal of non-linear mechanics 37 (6), 1079–1090.
- Wang et al. (2023) Wang, Zhicheng, Meng, Xuhui, Jiang, Xiaomo, Xiang, Hui & Karniadakis, George Em 2023 Solution multiplicity and effects of data and eddy viscosity on navier-stokes solutions inferred by physics-informed neural networks. arXiv preprint arXiv:2309.06010 .
- White & Xue (2003) White, Frank M & Xue, Henry 2003 Fluid mechanics, , vol. 3. McGraw-hill New York.
- Zhang et al. (2014) Zhang, Sijun, Zhao, Xiang & Bayyuk, Sami 2014 Generalized formulations for the rhie–chow interpolation. Journal of Computational Physics 258, 880–914.