Full text
Universitat Polit`ecnica de Catalunya. UPC The School of Industrial, Aerospace and Audiovisual Engineering of Terrassa. ESEIAAT Master’s degree in Aerospace Engineering Incompressible Navier-Stokes solver in Python Document: Report Author: Jordi Gal´ı Gimeno Director: Manel Soria Guerrero Date: 22 June 2021 Call: Spring
[This page intentionally left blank]
Jordi Gal´ı Gimeno Incompressible Navier-Stokes solver in Python 1 Resum L’´us de m`etodes num`erics per resoldre problemes de din`amica de fluids ha estat un camp d’investigaci´o des dels anys cinquanta del segle passat. La necessitat de desenvolupar avions militars d’alt rendiment va produir el descobriment d’una eina molt ´util pel sector de l’enginyeria. Des d’aleshores, l’´us de la mec`anica de fluids ´es un dels principals temes a tractar al m`aster d’enginyeria aeroespacial. Amb to aix`o, aquesta tesina es centra en desenvolupar un codi per motius educatius capa¸c de resoldre casos incompressibles amb un programari de codi obert. S’ha dit desenvolupament d’un codi educatiu perqu`e el principal objectiu ´es construir un procediment per validar cada funci´o implementada en el codi. Un cop les funcions principals queden validades, es desenvolupar`a un codi per resoldre casos peri`odics i casos on els l´ımits es formen per parets. Queda clar, doncs, que el primer objectiu ´es validar les diferents funcions que formaran part del codi principal. Un cop es compleix el primer objectiu, el seg¨uent ´es desenvolupar un codi capa¸c de resoldre els casos comentats. Tant el cas peri`odic com el de parets als l´ımits tenen diferents m`etodes per validar els resultats. Un cop aix`o s’ha fet, es podr`a dir que el solver estar`a correctament desenvolupat. En aquest estudi s’ha utilitzat el Fractional Step Method amb el teorema de descomposici´o de Ladyzhenskaya, tamb´e conegut com el teorema de Helmholtz–Hodge. Per l’estudi s’utilitzar`a una malla staggered, on les variables escalars com la pressi´o es trobaran al centre de les cel·les mentre que els vectors de velocitats es localitzen a les cares de la cel·la. Aquest m`etode ´es molt ´util per casos incompressibles per motius acad`emics per la seva senzillesa. 2 Abstract The use of numerical methods to solve flow dynamics problems has been a major issue of study since the fifties of the last century. The need of developing high performance military planes produced the discovery of a very powerful tool for the engineering sector. Since then, the use on computational fluids dynamics is one of the fundamental topics of study in the Aerospace engineering master’s degrees. With that, this thesis is focused on developing an educational code able to solve incompressible cases with an open source programming language. It is said that the code developed is for educational purposes because the main objective is to build a procedure to validate each function added at the code. Once the main functions are validated, a code will be build to solve periodic and wall bounded cases. It is clear then that the first objective is to validate all the different functions that will be part 2
Jordi Gal´ı Gimeno Incompressible Navier-Stokes solver in Python of the main code. Once this objective is achieved, the second one is to solve a periodic case and a wall bounded case. Both studies must have a way of validating the results, when this is done, the solver will be developed correctly. The flow dynamics method used is the fractional step method that will need the Ladyzhenskaya decomposition theorem, also known as the Helmholtz–Hodge theorem. For the study a staggered mesh is used, this means that it contains the scalar variables at the center of the cells and the velocity vectors are located at the face of the cells. This method is very useful for incompressible cases with educational purposes because of its simplicity. 3
Jordi Gal´ı Gimeno Incompressible Navier-Stokes solver in Python Contents 1 Resum 2 2 Abstract 2 List of Figures 6 List of Tables 7 3 Introduction 8 3.1 Aim ................................ 8 3.2 Scope ............................... 8 3.3 Requirements ........................... 8 3.4 Background ............................ 9 3.5 Acknowledgments......................... 9 4 Theoretical introduction 10 4.1 General description of the problem . . . . . . . . . . . . . . . 10 4.2 Navier-Stokes equations . . . . . . . . . . . . . . . . . . . . . 10 4.3 Divergence theorem . . . . . . . . . . . . . . . . . . . . . . . . 13 4.4 Mesh arrangement . . . . . . . . . . . . . . . . . . . . . . . . 13 5 Code validation 16 5.1 Part A: convective and diffusive terms . . . . . . . . . . . . . 16 5.1.1 Convective term discretization . . . . . . . . . . . . . . 17 5.1.2 Diffusive term discretization . . . . . . . . . . . . . . . 18 5.1.3 PartAresults....................... 18 5.2 Part B: Pressure-velocity coupling . . . . . . . . . . . . . . . . 19 5.2.1 Code implementation . . . . . . . . . . . . . . . . . . . 20 5.2.2 Part B1: Periodic case . . . . . . . . . . . . . . . . . . 25 5.2.3 Part B2: Wall case . . . . . . . . . . . . . . . . . . . . 27 5.2.4 Part B3: Inlet and outlet case . . . . . . . . . . . . . . 30 5.3 Part C: Time integration . . . . . . . . . . . . . . . . . . . . . 31 5.3.1 Code implementation . . . . . . . . . . . . . . . . . . . 32 5.3.2 PartCresults....................... 33 6 Boundary conditions implementation 36 6.1 Convectiveterm.......................... 37 6.1.1 VelocityU......................... 37 6.1.2 VelocityV......................... 39 6.2 Diffusiveterm........................... 40 4
Jordi Gal´ı Gimeno Incompressible Navier-Stokes solver in Python 6.2.1 VelocityU......................... 41 6.2.2 VelocityV......................... 42 7 Periodic Case 43 8 Case study: Driven cavity case 45 8.1 Resultsvalidation......................... 45 8.2 Meshstudy ............................ 46 8.2.1 Uniform mesh study . . . . . . . . . . . . . . . . . . . 46 8.2.2 Concentrated mesh study . . . . . . . . . . . . . . . . 48 8.3 Reynolds number study . . . . . . . . . . . . . . . . . . . . . . 51 8.4 Streamlines comparison . . . . . . . . . . . . . . . . . . . . . . 53 8.5 Qualitative results . . . . . . . . . . . . . . . . . . . . . . . . 54 9 Performance study 56 10 Future improvements 58 10.1 Three dimension domain . . . . . . . . . . . . . . . . . . . . . 58 10.2 Neumann boundary conditions . . . . . . . . . . . . . . . . . . 58 10.3 Suspended object . . . . . . . . . . . . . . . . . . . . . . . . . 59 10.4 Higher number of elements simulations . . . . . . . . . . . . . 60 11 Conclusions 61 11.1 Results discussion . . . . . . . . . . . . . . . . . . . . . . . . . 61 11.2 Continuation of the study . . . . . . . . . . . . . . . . . . . . 62 References 63 5
Jordi Gal´ı Gimeno Incompressible Navier-Stokes solver in Python List of Figures 1 Divergence theorem . . . . . . . . . . . . . . . . . . . . . . . . 13 2 Meshdescription ......................... 14 3 Coordinates nomenclature of an element . . . . . . . . . . . . 15 4 View of the control volume in the Xand Ydirection . . . . . 15 5 Velocity and flow terms in the Ucontrol volume . . . . . . . . 17 6 Convective and diffusive terms error versus element height . . 19 7 Coefficient Cegeometry ..................... 23 8 Node positions for the building of the matrix A........ 24 9 Picture of the command window with the divergence values . . 25 10 Velocity field before and after the step . . . . . . . . . . . . . 25 11 Streamlines of the velocity . . . . . . . . . . . . . . . . . . . . 26 12 Aand A−1matrixforN=5................... 26 13 Aand A−1matrix for N = 20 . . . . . . . . . . . . . . . . . . 27 14 Picture of the command window with the divergence values . . 28 15 Velocity field before and after the step . . . . . . . . . . . . . 29 16 Streamlines of the velocity . . . . . . . . . . . . . . . . . . . . 29 17 Picture of the command window with the divergence values . . 30 18 Velocity field before and after the step . . . . . . . . . . . . . 30 19 Streamlines of the velocity . . . . . . . . . . . . . . . . . . . . 31 20 Velocity error versus element height for N = 10, 55 and 100 . . 33 21 Velocities comparison for 200 steps . . . . . . . . . . . . . . . 34 22 Velocities comparison for 25 steps . . . . . . . . . . . . . . . . 34 23 Top and bottom wall elements . . . . . . . . . . . . . . . . . . 36 24 Left and right wall elements . . . . . . . . . . . . . . . . . . . 37 25 Top and bottom wall for U velocity . . . . . . . . . . . . . . . 38 26 Left and Right wall for U velocity . . . . . . . . . . . . . . . . 39 27 Top and bottom wall for V velocity . . . . . . . . . . . . . . . 39 28 Left and Right wall for V velocity . . . . . . . . . . . . . . . . 40 29 Velocity vectors and velocity streamlines for the periodic case 43 30 Velocity vectors and velocity streamlines for the periodic case 44 31 Velocity vectors and velocity streamlines for the periodic case 44 32 Geometry of the driven cavity case . . . . . . . . . . . . . . . 45 33 U velocity for different number of elements . . . . . . . . . . . 47 34 V velocity for different number of elements . . . . . . . . . . . 47 35 Mesh for concentration factors of γ= 0.5 and γ= 1 . . . . . . 49 36 Mesh for concentration factors of γ= 1.5 and γ= 2 . . . . . . 49 37 U velocity for different concentration factors [1] [2] [3] . . . . . 50 38 V velocity for different concentration factors [1] [2] [3] . . . . . 51 39 U velocity for different Reynolds number [1] . . . . . . . . . . 52 6
Jordi Gal´ı Gimeno Incompressible Navier-Stokes solver in Python 40 V velocity for different Reynolds number [1] . . . . . . . . . . 52 41 Streamlines comparison for a Reynolds number of Re = 100 [4] 53 42 Streamlines comparison for a Reynolds number of Re = 1000 [5] 54 43 Pressure and velocity module for Reynolds = 1000 . . . . . . . 55 44 Horizontal and vertical velocity for Reynolds = 1000 . . . . . 55 45 Picture obtained from the command window . . . . . . . . . . 56 46 Mapoftheairfoil......................... 59 List of Tables 1 Mesh size and number of elements for each Reynolds number . 46 2 Element size at the wall for different values of γ........ 50 3 Mesh size and number of elements for each Reynolds number . 56 7
Jordi Gal´ı Gimeno Incompressible Navier-Stokes solver in Python 3 Introduction 3.1 Aim The main objective of the project is the implementation of the Navier- Stokes equations for incompressible flow in a python code for educational purposes. With this, a secondary objective will be set in order to achieve the main one that is validating the main functions correctly. The method of manufactured solutions will be used to do so and three different codes will be developed in order to validate the Poisson solver, the time-step integration and the functions that evaluate the convective and diffusive terms. Once this is reached, the aim is to implement boundary conditions and validate them. 3.2 Scope In order to reach the main objective of the project it will be necessary for the student to understand the Navier-Stokes equations and the mathematical theory to implement them in the code. Developing skills in numerical methods and understand and dominate the Python programming language. As explained, it will be necessary for the student to dominate the method of manufactured solutions in order to validate the different functions during the implementation of the equations. 3.3 Requirements At the beginning of the project some requirements are stated and it must be said by the student if they have been fulfilled or not. If they are not well reached or not reached at all, the student must justify the reason why this has happened. The requirements are placed chronologically so that one is reached the next one can be developed. The first requirement is understanding the Navier-Stokes equations and the different methods to implement them in the code. The following three requirements consist of the first validation part of the code. First, it will be necessary to implement and validate the diffusive and convective functions. Then, the Poisson equation will also be implemented and validated. And finally, the time integration function will be implemented and validated by the method of manufactured solutions. These three parts will be called part A, B and C respectively. Once this is reached, a periodic case can be solved by the code. The next requirement consist of implementing the boundary 8
Jordi Gal´ı Gimeno Incompressible Navier-Stokes solver in Python Figure 3: Coordinates nomenclature of an element As this study is working with a staggered mesh, the control volumes used will be placed as in the figure 4. There, it can be seen that the control volume for a certain element in the Xdirection in green and in the Ydirection in blue. Figure 4: View of the control volume in the Xand Ydirection 15
Jordi Gal´ı Gimeno Incompressible Navier-Stokes solver in Python 5 Code validation As explained, the validation of the code is divided in three parts, the implementation of the convective and diffusive terms, the coupling of the pressure and velocity and the time integration. Each one must be explained differently [7]. The results of the validation are plotted with the same Python code that has performed the study. The study cases like the periodic and driven cavity will plot the results using a Matlab code as is explained later. So, for the validation case, the pictures of the velocity field are plotted using a Python function matplotlib.pyplot.quiver and the streamliner with the function matplotlib.pyplot.streamplot. 5.1 Part A: convective and diffusive terms In order to validate the convective and diffusive terms, the method of manufactured solutions (MMS) will be used. For this case, a velocity field will be set and it must be solved analytically and numerically. Then, the error between the solutions must be compared in function of the element size. It is obvious that the smaller the element size, the smaller the error should be. The velocity field chosen is the following: U= cos(2πx) sin(2πy) V=−cos(2πy) sin(2πx) The symbolic evaluation has been performed using the differentiation Python function sympy.diff. 16
Jordi Gal´ı Gimeno Incompressible Navier-Stokes solver in Python Figure 5: Velocity and flow terms in the Ucontrol volume The numerical evaluation is more complex because each term must be discretized correctly. In order to understand the location of the control volume and the positions and directions of the velocities and flow terms, the figure 5 shows the case for the Xdirection. 5.1.1 Convective term discretization Starting from the convective term and applying the divergence theorem for the Xdirection the equation can be derived as follows: ZV ∇ · (u1u)dV =ZS (u1u)n dS = Ze u1u1dS −Zw u1u1dS +Zn u1u2dS −Zs u1u2dS ≃ Which can be written as: ≃ueFe−uwFw+unFn−usFs Where uis the velocity term and Fis the flow term. They are discretized as: ue=u(i+1,j)+u(i,j) 2Fe=u(i+1,j)∆y+u(i,j)∆y 2 17
Jordi Gal´ı Gimeno Incompressible Navier-Stokes solver in Python For the surface east (e) and Xdirection. As can be seen, the derivation of the convective term is performed for each direction of the velocity, for a two dimensional case, for Xand Ydirections. It also requires the velocity at each direction independently of the direction that is being calculated. 5.1.2 Diffusive term discretization From the diffusive term it can be developed as follows applying the divergence theorem. ZV ∇ · (∇ · u1)dV =ZS ∇ · u1n dS = Ze ∂u1 ∂x dS −Zw ∂u1 ∂x dS +Zn ∂u1 ∂y dS −Zs ∂u1 ∂y dS ≃ Which can be written like: ≃∆y∂u1 ∂x e −∆y∂u1 ∂x w + ∆x∂u1 ∂y n −∆x∂u1 ∂y s Where each term are discretized as: ∂u1 ∂x e ≃u1(i+1,j)−u1(i,j) sx(i+1) −sx(i) Using a second order Taylor’s expansion and for the east (e) surface at X direction. It is observed that for the diffusive term it must also computed for each velocity direction. However, for this case each calculation only requires the velocity at the direction that is being calculated. 5.1.3 Part A results After the implementation of the code explained before, it has been possible to validate the two functions that compute the convective and diffusive terms. 18
Jordi Gal´ı Gimeno Incompressible Navier-Stokes solver in Python Figure 6: Convective and diffusive terms error versus element height In the figure 6 it can be observed that the error decreases with the element size. This means that the numerical discretization is well performed because the higher the number of elements, the diffusive and convective calculation is performed with more precision. It can be seen that the error found for the diffusive term is higher than for the convective term. This can be because a second order Taylor’s approximation must be used to discretize the velocity derivative at each face of the control volume. 5.2 Part B: Pressure-velocity coupling The second part consist of coupling the pressure and the velocity. This part of the code will be divided in three sub-codes to validate three cases. The first case, and the most simple one will consist of building the pressure-velocity coupling for a periodic case. The second one will consist of a case where the domain is surrounded by solid walls and the third one a wall case but with inlets and outlets in the wall. All three cases are going to be validated with the same procedure. First, a non divergence-free field will be set. It will consist of a zero velocity field 19
Jordi Gal´ı Gimeno Incompressible Navier-Stokes solver in Python with an imposed velocity at a certain point of the domain. Then, from this velocity field the Poisson equation must be solved as will be explained to compute the new velocity step. It must be said that the boundary conditions must be taken into account for each three cases. Then, the new velocity field computed must be divergence-free in order to validate the code. If this is achieved, the Poisson solver and the boundary conditions will be well implemented. 5.2.1 Code implementation In order to understand the pressure-velocity coupling, the code will be explained for a periodic case and at the following sections the modifications performed will be explained. As can be seen from the momentum equation, the velocity and pressure are related: ∂ui ∂t +uj ∂ui ∂xj =−1 ρ ∂p ∂xi +ν∂2ui ∂xj∂xj The momentum equation can be derived and expressed as follows: du dt V+C(u) = −V ρ∇ · p+D(u) Where uis the velocity vector with both components, Cand Dare the convective and diffusive terms, respectively. Then pis the pressure and Vis the volume of the control volume at the corresponding direction. Now, the velocity in function of time has to be isolated. du dt =R−1 ρ∇ · p Where Ris defined like: R=−C/V +D/V Now, the velocity must be discretized along time to be able to compute the next velocity step from the previous one. In order to solve this case, the Adams-Bashforth explicit method for ordinary differential equations is used [11]. The discretization can be observed in the equation 12. un+1 −un ∆t=3 2Rn−1 2Rn−1−1 ρ∇ · pn+1 (12) 20
Jordi Gal´ı Gimeno Incompressible Navier-Stokes solver in Python The velocity and Rterms use an explicit method and the pressure gradient uses an implicit method. Now, the velocity of the next step must be isolated. un+1 =un+ ∆t3 2Rn−1 2Rn−1−∆t ρ∇ · pn+1 Now, the equation will be grouped into three terms. The left term is the unknown velocity (velocity of the next step), the right term is the effect of the pressure and the rest of the equation: un+∆t3 2Rn−1 2Rn−1will be the predictor velocity. up=un+ ∆t3 2Rn−1 2Rn−1 As can be seen, the predictor velocity can be obtained from the known velocity and the convective and diffusive terms. Then, rewriting the equation it stays as: un+1 =up−∆t ρ∇ · pn+1 Now, the mass conservation equation will be imposed to the velocity of the next step. 0 = ∇ · un+1 =∇ · up−∆t ρ∇2·pn+1 With this, it is obtained that: ∇ · up=∇2∆t ρpn+1 Where the right term is the divergence of a gradient, which will be the laplacian. This will be called the pseudo-pressure and will be expressed as follows. ˜p=∆t ρpn+1 From this, it is easy to obtain the Poisson equation. ∇2˜p=∇ · up From the predictor velocity the pseudo-pressure can be found. with this, it will be easy to obtain the pressure and then the new velocity step. 21
Jordi Gal´ı Gimeno Incompressible Navier-Stokes solver in Python un+1 =up−∇·˜p It is known that from a given vector field wdefined in a bounded domain Ω with smooth domain ∂Ω is uniquely decomposed in a pure gradient field and a divergence-free vector parallel to ∂Ω [12]. w=a+∇ · φ For this case: un+1 =up−∇·˜p If un+1 is divergence-free, the scalar field has to be the pseudo-pressure. Discretization of the Poisson equation From the Poisson equation described previously, it is clear that the velocity is known and the objective is to find the pressure [13]. ∇2˜p=∇ · up To do so, for a certain point of the centered mesh and assuming that the mesh is uniform. ∆pe−pp ∆−∆pp−pw ∆+∆pn−pp ∆−∆pp−ps ∆= ∆vp−∆vs+∆up−∆uw(13) Where the velocities are located in the staggered mesh and the ∆ is the distance of the control volume and between centered nodes because the mesh is considered uniform. pe+pw+pn+ps−4pp= ∆(vp−vs+up−uw) (14) Which can be expressed in a matrix way. Ap =b Where the pressure is the unknown and the vector band the matrix A are known. If the mesh is not uniform, the coefficients at the pressure shown in the equation 14 will depend on the distances of the element. So for a mesh that is not uniform, the equation 13 will be written as: 22
Jordi Gal´ı Gimeno Incompressible Navier-Stokes solver in Python Cepe+Cwpw+Cnpn+Csps−Cppp= ∆(vp−vs+up−uw) (15) Where as said, the coefficients Ce,Cw,Cn,Csand Cpnow must be computed. Ce=Dy/dxp Cw=Dy/dxn Cn=Dx/dyp Cs=Dx/dyn Cp=Ce+Cw+Cn+Cs For the case of the coefficient Ce, each distance is observed in the figure 7. If the element of the center of the figure is the one that is being studied, the coefficient Cewill use the seen distances. It is clear that for a non uniform mesh, the distances will be affected changing the corresponding coefficients. Figure 7: Coefficient Cegeometry Matrix Aimplementation As said, the pressure will be found from the known velocity and the matrix Athat will be square, singular and symmetric. It will have a shape of Nx*Ny by Nx*Ny. As seen before in the equation 14, the matrix Awill be composed by the coefficients that multiply the pressure and relate them with the corresponding nodes. 23
Jordi Gal´ı Gimeno Incompressible Navier-Stokes solver in Python Figure 8: Node positions for the building of the matrix A From this, it is easy to see that each row of the matrix Awill have the −4 coefficient in the corresponding node and a coefficient of value one in the four nodes of the surroundings. For the nodes in the borders, it will be necessary to use the halo nodes to set the correct position in the matrix. With this, it is easy to see that the sum of each row and column of the matrix is zero. As long as the boundary conditions are consistent, the sum of the vector balso has to be zero. For this reason, the matrix Ahas to be perturbed in order to be able to solve the system. In this case, in the nodes A(1,1) is will be set the value −5. In the figure 8 it is represented with red a certain node and the nodes in their boundaries. It is clear that the node at the east position is located in the halo so the node taken must be the orange one. To obtain the pressure vector a very high computational power will be needed because of the dimensions of the matrix A. To solve this, the matrix has been set as a scattered matrix to save the locations of the zeros. And the pressure vector has been obtained with a solve function from the Python code. With this, a big amount of time is saved. 24
Jordi Gal´ı Gimeno Incompressible Navier-Stokes solver in Python Figure 19: Streamlines of the velocity In order to obey mass conservation, the sum of the inlet and outlet velocities must be zero. For example, if is set inlet velocity of 1 and an outlet velocity of 2, the mass conservation will not be fulfilled and the divergence of the next step field will not be zero. This is also valid for more than two inlet and outlets. If the inlet velocity is 1 and two outlets have a velocity of 0.5, the step will be performed correctly. As said before, the sum of the vector bmust be zero as the columns of the matrix A. In this case, this can be used to see if the step is performed correctly. 5.3 Part C: Time integration The main objective of the part C is to implement a code that can perform a flow simulation by applying an iterative process where each step is the velocity computation seen in the previous section. It must be taken into account that each time step must be evaluated before calculating the next velocity field. To validate the code, this part consist of taking a flow field that can be solved analytically and compare the results with the numerical solution. The flow chosen is the following: 31
Jordi Gal´ı Gimeno Incompressible Navier-Stokes solver in Python u v=Fcos(2πx)sin(2πy) −cos(2πy)sin(2πx) Where Fcontains the time variable. F=e−8π2νt In this part, it will be obtained as a result the comparison between numerical and analytical velocity. A certain point will be chosen and the velocity will be obtained at each step. 5.3.1 Code implementation The implementation of the code consist of the iterative process, the time step evaluation and saving the data. The time step evaluation is very important, since the mesh dimensions are constant and the velocity is constantly changing, the time is the parameter that relate both previous variables. Considering one control volume, if the time step is very big, the velocity of the flow will span more than one control volume, making it impossible for the code to converge. For this reason, the time step must be below the convective and diffusive time limit. ∆tc≤Min ∆ |u| ∆td≤1 2Min ∆2 ν ∆t=f∗Min(∆tc,∆td) Where fmust be between 0.2 to 0.5. Of course, this evaluation is easy if the mesh is constant but if the mesh is changed, this must be taken into account in the time evaluation. In order to compare the analytical and numerical flow evolution, the velocities will be evaluated from the starting point to the moment that the velocity has been faded. And for each step, the error from both velocity field will be saved. This computation is performed for different numbers of elements to observe if the error between both field is lower or higher. It is assumed that the lower the element size, the numerical computed velocity field must be closer to the analytical one. 32
Jordi Gal´ı Gimeno Incompressible Navier-Stokes solver in Python 5.3.2 Part C results The results of this part can be observed in the following figures. This code validates the function that iterates the problem until the convergence is reached. Figure 20: Velocity error versus element height for N = 10, 55 and 100 As expected, the error between velocity field becomes lower when the number of elements increases. This means that a lower element size will be able to compute better the real flow field. 33
Jordi Gal´ı Gimeno Incompressible Navier-Stokes solver in Python Figure 21: Velocities comparison for 200 steps Figure 22: Velocities comparison for 25 steps Two things must be observed from the figures 21 and 22. The first one is that is very well represented how the velocity fades into a zero value along with time. Is is also very clear that the numerical calculations are very precise, which can also be concluded from the figure 20. Both figures show 34
Jordi Gal´ı Gimeno Incompressible Navier-Stokes solver in Python the same tendency but it has been plotted for different number of steps in order to see more details. 35
Jordi Gal´ı Gimeno Incompressible Navier-Stokes solver in Python 6 Boundary conditions implementation Depending on the case that is studied, different boundary conditions must be applied to the domain. The most used ones are the inlet, outlet and nonslip condition. And to implement them, Dirichlet or Neumann boundary conditions are used. The Dirichlet method consist on imposing a certain value, for example the velocity. And Neumann imposes the value of the derivative at the boundary. For this thesis, the Dirichlet boundary conditions are used [14]. The code will be able to set a non slip condition and a moving wall. This means the case where the velocity is zero at each direction and the case where the normal velocity is zero while the tangential has a certain value. The figures 23 and 24 show how the velocities are distributed in each of the four walls. As can be seen, each one must be treated differently in function of the velocity direction because of its location in the staggered mesh. It is important to say that when the boundary conditions are implemented, the calculation of the matrix Amust be changed as in the second case of the part B of the validation. The modification explained in this section must be added in order to implement correctly the boundary conditions. Figure 23: Top and bottom wall elements 36
Jordi Gal´ı Gimeno Incompressible Navier-Stokes solver in Python Figure 24: Left and right wall elements In order to set the boundary conditions, the velocities in the halo will be modified in order to obtain the desired value when computing the convective and diffusive terms. Then, a different modification must be performed before the calculation of the convective and diffusive terms. Each modification will take into account the velocity direction and the boundary. In order to perform the mathematical explanation, it must be said that the ∆y+and ∆y−distances must be equal and the same will happen with the ∆x+and ∆x−distances. This will be reached for a uniform mesh, but if the code works with a concentrated mesh at the walls, it is very important to impose that the elements of the halo have the same size than the element next to them. 6.1 Convective term As explained previously, the convective term calculation is reached once the velocity and flow terms are obtained. The main objective of the boundary conditions implementation is modifying the velocity terms to obtain the desired value of the face velocities. 6.1.1 Velocity U Top and bottom walls : The top and bottom walls will be analysed in this paragraph. If the objective is to impose a certain value of the Utand Ubvelocities shown in the figure 25, it must be observed how the convective term computes this velocity term. 37
Jordi Gal´ı Gimeno Incompressible Navier-Stokes solver in Python Figure 25: Top and bottom wall for U velocity The convective term finds the mentioned Utand Ubvelocities interpolating from the known velocities of the staggered mesh. Ut=Ui,Ny+2 +Ui,Ny+1 2Ub=Ui,2+Ui,1 2 If Utand Ubare the top and bottom velocities at the face that must be found when computing the convective term, it is imposed then (top and bottom respectively): Ui,Ny+2 = 2Ut−Ui,Ny+1 Ui,1= 2Ub−Ui,2 It is clear then, that the velocities Ui,Ny+2 and Ui,1are the ones that will be modified previous to the convective calculation for the top and bottom case. Left and right walls The left and right walls have a different geometry due to the staggered mesh so the case must be treated differently. In the figure 26 it is easy to see that the velocities that must be imposed are the ones at the face of the wall. 38
Jordi Gal´ı Gimeno Incompressible Navier-Stokes solver in Python Figure 26: Left and Right wall for U velocity It is imposed then (left and right respectively): U1,j =UlUNx+1,j =Ur For the case of the right wall, the velocity UNx+2,j is neglected as it will not affect the velocities around the wall. 6.1.2 Velocity V Top and bottom wall The procedure to find the imposed velocity for the top and bottom walls for the velocity in Ydirection is analogous to the left and right walls for velocity in Xdirection. Figure 27: Top and bottom wall for V velocity 39
Jordi Gal´ı Gimeno Incompressible Navier-Stokes solver in Python It is imposed (top and bottom respectively): Ui,Ny+1 =UtUi,1=Ub Left and right walls And the same for the left and right walls in Y direction. Figure 28: Left and Right wall for V velocity Vl=V1,j +V2,j 2Vr=VNx+2,j +VNx+1,j 2 It is imposed then (top and bottom respectively): V1,j = 2Vl−V2,j VNx+2,j = 2Vr−VNx+1,j 6.2 Diffusive term In the diffusive term the same procedure is used than in the convective one. A previous modification of the velocities at the halo are going to be used in order to obtain the desired values of the velocities at the walls once the evaluation of the diffusive term is performed. 40
Jordi Gal´ı Gimeno Incompressible Navier-Stokes solver in Python Figure 33: U velocity for different number of elements Figure 34: V velocity for different number of elements As can be seen in the figures 33 and 34, the number of elements must be 47
Jordi Gal´ı Gimeno Incompressible Navier-Stokes solver in Python higher than 20 and if possible closer to 50 in order to obtain a good result for this Reynolds number. This study also shows that the discretization method is correct because as the number of elements gets higher, the results converge to the correct solution. It is clear in the images 33 and 34 that from 50 to 100 elements, the change of results are very small. Once the Reynolds number is increased, it is clear that the number of elements needed are higher. This must be taken into account when performing simulations at higher Reynolds number. 8.2.2 Concentrated mesh study In this section, it will be studied how the concentration of the mesh at the walls affect the result of the simulation. As said before, the Reynolds number chosen is Re = 1000 and number of elements 20. In order to create a concentrated mesh an hyperbolic tangential function has been used. f(x) = tanh γ2x N−1−tanh γ2(x−1) N−1 2 tanh(γ) Where N is the number of elements and γis the concentration factor to the walls. For a γvalue close to zero the mesh is uniform and for a γvalue higher, the mesh is more concentrated to the walls. 48
Jordi Gal´ı Gimeno Incompressible Navier-Stokes solver in Python Figure 35: Mesh for concentration factors of γ= 0.5 and γ= 1 Figure 36: Mesh for concentration factors of γ= 1.5 and γ= 2 49
Jordi Gal´ı Gimeno Incompressible Navier-Stokes solver in Python γvalue ∆y at the wall [m] 0.00001 0.025 0.5 0.022 1 0.015 1.5 0.009 2 0.004 Table 2: Element size at the wall for different values of γ Comparing the table 2 with the theoretical results of the element size, it is clear that for a γvalue of 1.5 and 2, the mesh will be fine enough to solve the case correctly. Figure 37: U velocity for different concentration factors [1] [2] [3] 50
Jordi Gal´ı Gimeno Incompressible Navier-Stokes solver in Python Figure 38: V velocity for different concentration factors [1] [2] [3] Once the case is solved, it is clear that as the concentration to the walls get higher, the result is closer to the correct value: 37, 38. It is also clear that the number of elements is still a bit small for the number of Reynolds chosen because the case is not well solved. But in this study, the most important conclusion is to observe that as the concentration to the walls gets higher, the flow will be better computed in the wall region. In the figures 37 and 38 it is clear the point made previously which said that the [1] results are coincident with high number of elements simulations. 8.3 Reynolds number study Once the mesh study is performed, the case can be solved for different Reynolds numbers: 100, 400 and 1000. The Reynolds used are small because of the computational power that must be used to solve the cases. 51
Jordi Gal´ı Gimeno Incompressible Navier-Stokes solver in Python Figure 39: U velocity for different Reynolds number [1] Figure 40: V velocity for different Reynolds number [1] The figures 39 and 40 show how the velocity will be modified as the 52
Jordi Gal´ı Gimeno Incompressible Navier-Stokes solver in Python Reynolds number increases. It is clear that the velocity will increase near the walls when the Reynolds number increases. This study shows the the code implemented is able to compute the case for different numbers of Reynolds. This means that it is able to adapt to the different turbulence values of the flow. 8.4 Streamlines comparison In this section the streamlines of different articles are going to be compared with the obtained in the study. Two different articles are going to be used for the simulations with fine meshes [4] [5]. Figure 41: Streamlines comparison for a Reynolds number of Re = 100 [4] 53
Jordi Gal´ı Gimeno Incompressible Navier-Stokes solver in Python Figure 42: Streamlines comparison for a Reynolds number of Re = 1000 [5] As seen in the figure 41 and 42 the streamlines of both cases match with the corresponding simulation. Some aspects of the flow can be observed comparing both images. First of all, as the Reynolds number increases, the main eddy of the flow is located closer to the center of the domain. And it can also be observed that the two eddies at the bottom corners of the domain are greater as the Reynolds number increases. It is obvious that as the flow is more turbulent, those two eddies will stay at a certain size but then more small eddies will appear in both regions. 8.5 Qualitative results In this section, the picture of the final step of the case for Reynolds number of 1000 is taken to observe the behaviour of the flow in the different regions. This pictures 43 and 44 are very useful to observe the behaviour of the flow as said, but is also very important to observe the transitory state. When the simulation starts, the flow of the domain is at zero velocity, and the different steps saved from the simulation can show its evolution to the steady flow velocity domain. 54
Jordi Gal´ı Gimeno Incompressible Navier-Stokes solver in Python Figure 43: Pressure and velocity module for Reynolds = 1000 Figure 44: Horizontal and vertical velocity for Reynolds = 1000 55
Jordi Gal´ı Gimeno Incompressible Navier-Stokes solver in Python 9 Performance study In this section a brief study of the code performance is done. The computational effort of the code is very important in order to be optimized for future cases. In this study, the main function to be studied is the one that implements the time step integration because a single simulation can have a huge amount of steps so each calculation that is placed inside it will be performed so many times. So in order to obtain the computational effort, the time that each part of the function will be obtained. Then, the most critical parts have to be analysed. Figure 45: Picture obtained from the command window In order to perform the study, a driven cavity case is run with a uniform mesh of 200x200. In the figure 45 the time that each part of the step last is observed. Part of the step Computational time [seconds] Percentage of time [%] First calculations 0.001 0.02 Convective term function 2.773 45.5 Diffusive term function 1.517 21.7 Calculations between Diffusive and Poisson 0.280 4.6 Poisson function 1.242 20.4 Last calculations 0.285 4.7 Table 3: Mesh size and number of elements for each Reynolds number 56
Jordi Gal´ı Gimeno Incompressible Navier-Stokes solver in Python References [1] U. GHIA K. N. GHIA and C. T. SHIN. High-re solutions for incompressible flow using the navier-stokes equations and a multigrid method. JOURNAL OF COMPUTATIONAL PHYSICS, 48:387–411, 1982. [2] Mazen Saad Charles-Henri Bruneau. The 2d lid-driven cavity problem revisited. Computers & Fluids, 35:326–348, 2006. [3] R. PEYRET O. BOTELLA. Benchmark spectral results on the liddriven cavity flow. Computers & Fluids, 27(4):421–433, 1998. [4] S. P. VANKA. Block-implicit multigrid solution of navier-stokes equations in primitive variables. JOURNAL OF COMPUTATIONAL PHYSICS, 65:138–158, 1986. [5] K. Yapici and Y. Uludag. Finite volume simulation of 2-d steady square lid driven cavity flow at high reynolds numbers. Brazilian Journal of Chemical Engineering, 30(4):923–937, 2013. [6] Lajos T. Vad J. and Schilling R. Modelling Fluid Flow. Springer, 2004. [7] Manel Soria Guerrero. Numerical solution of the incompressible ns equations, February 2021. [8] C. Foias, O. Manley, R. Rosa, and R.Temam. Navier-Stokes equations and turbulence. Cambridge university press, 2004. [9] R. Aris. Vectors, Tensors, and the basic Equations of Fluid Mechanics. Dover Publications, 1989. [10] George B. Arfken. Mathematical Methods for Physicists 3rd ed. Orlando, FL: Academic Press, 1985. [11] SAJAL K. KAR. An explicit time-difference scheme with an adams–bashforth predictor and a trapezoidal corrector. I. M. Systems Group, Inc., Rockville, Maryland, 140:307–322, 2012. [12] O. A. Ladyzhenskaya A. Krzywicki. A grid method for the navier-stokes equations. Soviet Physics Dokl., 11:212–213, 1966. [13] R. R. Rosales D. Shirokoff. An effcient method for the incompressible navier-stokes equations on irregular domains with no-slip boundary conditions, high order up to the boundary., 2013. 63
Jordi Gal´ı Gimeno Incompressible Navier-Stokes solver in Python [14] Marc Andr´es Carcasona. Study: Simulation of planetary atmospheres, 2020. [15] Steven Allmaras, Venkat Venkatakrishnan, and Forrester Johnson. Farfield boundary conditions for 2-d airfoils. 43th AIAA Aerospace Sciences Meeting, AIAA., 2005. 64