Skip to main content
Log in

A detailed introduction to density-based topology optimisation of fluid flow problems with implementation in MATLAB

  • Educational Paper
  • Published:
Structural and Multidisciplinary Optimization Aims and scope Submit manuscript

Abstract

This article presents a detailed introduction to density-based topology optimisation of fluid flow problems. The goal is to allow new students and researchers to quickly get started in the research area and to skip many of the initial steps, often consuming unnecessarily long time from the scientific advancement of the field. This is achieved by providing a step-by-step guide to the components necessary to understand and implement the theory, as well as extending the supplied MATLAB code. The continuous design representation used and how it is connected to the Brinkman penalty approach, for simulating an immersed solid in a fluid domain, are illustrated. The different interpretations of the Brinkman penalty term and how to chose the penalty parameters are explained. The accuracy of the Brinkman penalty approach is analysed through parametric simulations of a reference geometry. The chosen finite element formulation and the solution method are explained. The minimum dissipated energy optimisation problem is defined and how to solve it using an optimality criteria solver and a continuation scheme is discussed. The included MATLAB implementation is documented, with details on the mesh, pre-processing, optimisation and post-processing. The code has two benchmark examples implemented and the application of the code to these is reviewed. Subsequently, several modifications to the code for more complicated examples are presented through provided code modifications and explanations. Lastly, the computational performance of the code is examined through studies of the computational time and memory usage, along with recommendations to decrease computational time through approximations.

This is a preview of subscription content, log in via an institution to check access.

Access this article

Price excludes VAT (USA)
Tax calculation will be finalised during checkout.

Instant access to the full article PDF.

Fig. 1
Fig. 2
Fig. 3
Fig. 4
Fig. 5
Fig. 6
Fig. 7
Fig. 8
Fig. 9
Fig. 10
Fig. 11
Fig. 12
Fig. 13
Fig. 14
Fig. 15
Fig. 16
Fig. 17
Fig. 18
Fig. 19
Fig. 20
Fig. 21
Fig. 22
Fig. 23
Fig. 24
Fig. 25
Fig. 26
Fig. 27

Notes

  1. This is very similar to stress constraints in structural topology optimisation, where a maximum stress limit becomes meaningless, unless the stresses and aggregated maximum is accurate (Le et al. 2010; da Silva et al. 2019).

  2. The lower bound is chosen to avoid stagnation.

  3. The constraint is not formulated explicitly anywhere in the paper.

  4. \(\tau _{2}\) is for the transient case, which is traditionally numbered as number 2, and left out since steady-state flow is treated herein.

References

Download references

Acknowledgements

This paper is dedicated to my former supervisor and colleague Ole Sigmund, the pioneer of educational topology optimisation codes and so much more. The author would like to acknowledge Yupeng Sun, for providing feedback on a close-to-finished manuscript, and Christian Lundgaard, for providing feedback on a very early draft. The author also wishes to thank the DTU TopOpt group for discussions over the many years it has taken to form the experience embodied in this article.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Joe Alexandersen.

Ethics declarations

Conflict of interest

The author has no conflict of interest.

Reproduction of results

The code to reproduce all results is either directly provided (as supplementary material and appendices) or the required modifications are explained thoroughly in the paper. Furthermore, a detailed description of all files of the code is given as supplementary material. Upon proof-of-attempt, the code for the examples not provided directly can be obtained from the author. Manual derivations of the analytical sensitivities can be provided upon request.

Additional information

Responsible Editor: by Kurt Maute

Publisher’s note

Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Topical Collection: Flow-driven Multiphysics

Guest Editors: J Alexandersen, C S Andreasen, K Giannakoglou, K Maute, K Yaji

Supplementary Information

Appendices

Appendix A: Alternative scaling of Brinkman penalty factor

The order of magnitude of the convective term is constant due to the non-dimensional formulation of Eq. 2. Thus, the Brinkman penalty factor should no longer become smaller with increasing Reynolds number. Kondoh et al. (2012) suggested the following scaling:

$$\begin{aligned} \alpha _\mathrm{{max}} = \left( 1 + \frac{1}{Re} \right) \frac{1}{Da} \end{aligned}$$
(46)

which aims to ensure that the Brinkman penalty factor is large enough even for increasing Reynolds numbers. From a scaling point of view, it can be argued that \(\frac{1}{Da}\) makes sense for purely convective flow, which is recovered from the above for \(Re \longrightarrow \infty\).

Fig. 28
figure 28

Error measures, when penalising using Eq. 46, as a function of Reynolds number for a Darcy number of \(Da=10^{-6}\) and \(Re\in \{ 0.01,0.1,1,5,10,50,100,150 \}\)

Figure 28 shows the error measures as a function of Reynolds number when using Eq. 46. In practise, it is seen that the error decreases for increasing Reynolds number over 1, meaning the flow in the solid is penalised increasingly hard. It appears that the error is beginning to stagnate. However, the flow becomes non-steady for \(Re>150\) and, thus, the limit cannot be investigated presently. This is an area worth more investigation, as the community transitions to treating larger Reynolds number flows.

Appendix B: Finite element formulation

The weak form of the momentum conservation equations is derived by multiplying the strong form by the test function \(w_i\) for the velocity field, integrating over the volume, applying integration-by-parts and introducing a zero normal stress natural boundary condition:

$$\begin{aligned}&\int _\Omega \rho w_{i} u_{j}\dfrac{\partial u_i}{\partial x_j} \,dV + \int _\Omega \mu \dfrac{\partial w_{i}}{\partial x_j}\left( \dfrac{\partial u_i}{\partial x_j} + \dfrac{\partial u_j}{\partial x_i} \right) \,dV \nonumber \\&\quad - \int _\Omega \dfrac{\partial w_{i}}{\partial x_i} p \,dV + \int _\Omega \alpha w_{i} u_{i} \,dV \nonumber \\&\quad + \sum _{e=1}^{n_e} \int _{\Omega _{e}} \tau w_{k}\dfrac{\partial u_i}{\partial x_k} \left( \rho u_{j}\dfrac{\partial u_i}{\partial x_j} + \dfrac{\partial p}{\partial x_i} + \alpha u_{i} \right) \,dV= 0\end{aligned}$$
(47)

where the last integral is the additional SUPG stabilisation terms with \(\tau\) as the stabilisation parameter. Likewise, the weak form of the mass conservation equation is derived by multiplying the strong form with the test function q for the pressure field:

$$\begin{aligned}&\int _\Omega q \dfrac{\partial u_i}{\partial x_i} \,dV \nonumber \\&\quad + \sum _{e=1}^{n_e} \int _{\Omega _{e}} \dfrac{\tau }{\rho } \dfrac{\partial q}{\partial x_i} \left( u_{j}\dfrac{\partial u_i}{\partial x_j} + \dfrac{\partial p}{\partial x_i} + \alpha u_{i} \right) \,dV = 0\end{aligned}$$
(48)

where the last integral is the additional PSPG stabilisation terms with \(\tau\) as the stabilisation parameter. The diffusive term has been left out of the SUPG and PSPG stabilisation, since it is negligible for bilinear interpolation functions due to the second-order derivative.

The stabilisation parameter is computed using an approximate minimum function:

$$\begin{aligned} \tau = \left( {\tau _{1}}^{-2} + {\tau _{3}}^{-2} + {\tau _{4}}^{-2} \right) ^{-1/2}\end{aligned}$$
(49)

based on three limit cases:

$$\begin{aligned} \tau _{1}&= \frac{h}{2\sqrt{u_{i}u_{i}}} \end{aligned}$$
(50a)
$$\begin{aligned} \tau _{3}&= \frac{\rho h^{2}}{12\mu }\end{aligned}$$
(50b)
$$\begin{aligned} \tau _{4}&= \frac{\rho }{\alpha }\end{aligned}$$
(50c)

where \(\tau _{1}\) is the convective limit, \(\tau _{3}\) is the diffusive limit and \(\tau _{4}\) is the reactive limitFootnote 4. The reactive limit \(\tau _{4}\) is very important to ensure stability in the solid domain and at the interface, especially for large Brinkman penalty parameters. The stabilisation parameters are assumed to be constant within each element and \(\tau _{1}\) is, thus, computed based on the velocity components evaluated in the element centroid.

Appendix C: Adjoint sensitivity analysis

Adjoint sensitivity analysis need not be difficult or especially derived for every type of problem. The derivation is very simply by posing the system of equations (be they uncoupled, weakly coupled or strongly coupled) as a common residual:

$$\begin{aligned} {\mathbf {r}} = {\mathbf {A}} \, {\mathbf {s}} - {\mathbf {b}} = {\mathbf {0}}\end{aligned}$$
(51)

where \({\mathbf {A}}\) is the system coefficient matrix, \({\mathbf {s}}\) is the vector of all state variables and \({\mathbf {b}}\) is the forcing vector. To find the derivatives of a given functional f, the Lagrangian \({\mathcal {L}}\) is defined as

$$\begin{aligned} {\mathcal {L}}= f - {\varvec{\lambda }}^T{\mathbf {r}}\end{aligned}$$
(52)

where \({\varvec{\lambda }}\) is the vector of adjoint variables. The total derivative with respect to a design variable \(\gamma _{e}\) is then taken of the Lagrangian:

$$\begin{aligned} \frac{d{\mathcal {L}}}{d\gamma _{e}} = \frac{d f}{d\gamma _{e}} - {\varvec{\lambda }}^T \frac{d{\mathbf {r}}}{d\gamma _{e}}\end{aligned}$$
(53)

where the total derivative is given by

$$\begin{aligned} \frac{df}{d\gamma _{e}} = \frac{\partial f}{\partial \gamma _{e}} + \frac{\partial f}{\partial {\mathbf {s}}} \frac{\partial {\mathbf {s}}}{\partial \gamma _{e}}\end{aligned}$$
(54)

due to the implicit dependence of f on the state field. Expanding the total derivative of the Lagrangian gives

$$\begin{aligned} \frac{d{\mathcal {L}}}{d\gamma _{e}} = \frac{\partial f}{\partial \gamma _{e}} + \frac{\partial f}{\partial {\mathbf {s}}}\frac{\partial {\mathbf {s}}}{\partial \gamma _{e}} - {\varvec{\lambda }}^T \left( \frac{\partial {\mathbf {r}}}{\partial \gamma _{e}} + \frac{\partial {\mathbf {r}}}{\partial {\mathbf {s}}} \frac{\partial {\mathbf {s}}}{\partial \gamma _{e}} \right)\end{aligned}$$
(55)

which can be rewritten to

$$\begin{aligned} \frac{d{\mathcal {L}}}{d\gamma _{e}} = \frac{\partial f}{\partial \gamma _{e}} - {\varvec{\lambda }}^T \frac{\partial {\mathbf {r}}}{\partial \gamma _{e}} + \left( \frac{\partial f}{\partial {\mathbf {s}}} - {\varvec{\lambda }}^T \frac{\partial {\mathbf {r}}}{\partial {\mathbf {s}}} \right) \frac{\partial {\mathbf {s}}}{\partial \gamma _{e}}\end{aligned}$$
(56)

by collecting the terms multiplied by the derivative of the state field. The adjoint problem is then defined as what is inside the brackets:

$$\begin{aligned} \frac{\partial {\mathbf {r}}}{\partial {\mathbf {s}}}^{T} {\varvec{\lambda }} = \frac{\partial f}{\partial {\mathbf {s}}}^{T}\end{aligned}$$
(57)

When \({\varvec{\lambda }}\) is the solution to the adjoint problem, the terms inside the brackets become zero and it is avoided to compute the design sensitivities of the state field:

$$\begin{aligned} \frac{d{\mathcal {L}}}{d\gamma _{e}} = \frac{\partial f}{\partial \gamma _{e}} - {\varvec{\lambda }}^T \frac{\partial {\mathbf {r}}}{\partial \gamma _{e}} \end{aligned}$$
(58)

Since the state solution will be updated after a design change to make the residual equal to zero, the total derivative of the residual with respect to the design variable is equal to zero. Thus, the total derivative of the Lagrangian will be equal to that of the functional and Equation 53 gives

$$\begin{aligned} \frac{d{\mathcal {L}}}{d\gamma _{e}} = \frac{d f}{d\gamma _{e}} \end{aligned}$$
(59)

Thus, the final sensitivities of the given functional become

$$\begin{aligned} \frac{df}{d\gamma _{e}} = \frac{\partial f}{\partial \gamma _{e}} - \mathbf {\lambda }^T \frac{\partial {\mathbf {r}}}{\partial \gamma _{e}}\end{aligned}$$
(60)

The above result is valid for ALL systems of equations, be they linear/non-linear or un/weakly/strongly coupled. This is the methodology laid forth in various textbooks, e.g. the “Structural Sensitivity Analysis and Optimization” series by Choi and Kim (2005a, 2005b), and papers from the 1990s Michaleris et al. (1994).

Appendix D: MATLAB code: topFlow.m

figure ae
figure af
figure ag

Appendix E: MATLAB code: problems.m

figure ah

Appendix F: MATLAB code: postproc.m

figure ai

Appendix G: MATLAB code: export.m

figure aj

Appendix H: MATLAB code: analyticalElement.m

figure ak
figure al

Rights and permissions

Reprints and permissions

About this article

Check for updates. Verify currency and authenticity via CrossMark

Cite this article

Alexandersen, J. A detailed introduction to density-based topology optimisation of fluid flow problems with implementation in MATLAB. Struct Multidisc Optim 66, 12 (2023). https://doi.org/10.1007/s00158-022-03420-9

Download citation

  • Received:

  • Revised:

  • Accepted:

  • Published:

  • DOI: https://doi.org/10.1007/s00158-022-03420-9

Keywords

Navigation