# Implementation of a multicomponent mixture model in 3D into the

## Commentaires

## Transcription

Implementation of a multicomponent mixture model in 3D into the

Implementation of a multicomponent mixture model in 3D into the WaLBErla-Framework Zoran Golic June 9, 2009 Bachelor Thesis Aufgabensteller: Prof. Dr. Ulrich Ruede Betreuer: Dipl.-Inf. Christian Feichtinger Bearbeitungszeit: 1. Dezemeber 2008 - 5. Juni 2009 1 Erklaerung: Ich versichere, dass ich die Arbeit ohne fremde Hilfe und ohne Benutzung anderer als der angegebenen Quellen angefertigt habe und das die Arbeit in gleicher oder aehnlicher Form noch keiner anderen Pruefungsbehoerde vorgelegen hat und von dieser als Teil einer Pruefungsleistung angenommen wurde. Alle Ausfuehrungen, die woertlich oder sinngemaess uebernommen wurden, sind als solche gekennzeichnet. Nuernberg, den 5. Juni 2009 ........................... 2 Abstract Simulations of chemical processes are computationally extremly expensive tasks. Especially diffusionprocesses draw attention from industrial usage. The presented work deals with an implementation of a multicomponent mixture model in 3D, based on Ficks’ first law of diffusion, into the WaLBErla Framework by the university of Erlangen-Nurmeberg. The single-fluidapproach uses herefore the substantially more precise High-Order Compact Scheme (HOC), which offers an accuracy of O(h4 ) while mainting a stencil dependent only of directly neighboring cells. The concluding tests primarily serve as verification of the convection- and diffusion-implementation, but also act as an approximation for the diffusioncoefficient- and fluidvelocity-range. Simulationen chemischer Vorgaenge sind extrem rechenaufwendige Prozesse. Insbesondere Diffusionsprozesse ruecken dabei in den Mittelpunkt der Aufmerksamkeit in der Industrie. Diese Arbeit behandelt eine Implementation eines Multikomponenten-Mixtur-Modells in 3D, basierend auf Ficks erstem Gesetz der Diffusion, in das WaLBErla Framework der Universitaet Erlangen-Nuernberg. Der Single-Fluid-Ansatz verwendet dazu den wesentlich genaueren HighOrder Compact Scheme (HOC), der trotz eines nur von direkten Nachbarzellen abhaengigen Stencils eine relative Rechengenauigkeit von O(h4 ) gewaehleistet. Die finalen Test dienen vornehmlich der Verifizierung der Konvektions- und Diffusions-Implementierung, aber auch der Abschaetzung eines Wertebereichs fuer die Parameter des Diffusionskoeffizienten und der Stroemunsgeschwindigkeiten. Contents 1 Lattice-Boltzmann method 1.1 Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.2 Boundary Conditions . . . . . . . . . . . . . . . . . . . . . . . 2 Theory 2.1 Convection-Diffusion Equation . . 2.2 Numerical Approach . . . . . . . 2.2.1 Ficks first law of diffusion 2.2.2 Multi-Fluid-Approach . . 2.3 Boundary Conditions . . . . . . . 2.3.1 Periodic . . . . . . . . . . 2.3.2 Dirichlet . . . . . . . . . . 2.3.3 Neumann . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 3 6 8 8 9 9 10 10 11 11 11 3 Discretization 12 3.1 Temporal Discretization . . . . . . . . . . . . . . . . . . . . . 12 3.2 Spacial Discretization with High-Order-Compact Scheme . . . 13 4 Implementation 4.1 WaLBerla-Framework . . . . . . 4.2 LBM-Algorithm in WaLBErla . 4.3 Solver . . . . . . . . . . . . . . 4.4 Boundary Condition Treatment . . . . . . . . . . . . 5 Results 5.1 Measurement of diffusive behaviour . 5.2 Influence of spacial resolutions . . . . 5.3 Range of diffusion coefficients . . . . 5.4 Measurement of convective behaviour 6 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 19 20 20 23 . . . . 24 25 26 26 28 30 1 7 Acknowledgements 32 2 Chapter 1 Lattice-Boltzmann method 1.1 Algorithm CFD-Applications differ in accuracy, reliability and performance dependent of the point of view on the problem. The microscopic view at first tends to be the most accurat by applying Newtons laws to discrete particles (although brownian motion and other quantum mechanics phenomena are neglegted), it is also the most expensive in computational terms. By averaging particles to ensembles and looking at quantities like density and particle velocity the view shifts to the macroscopic world. Here massand momentum-conservation are regarded as driving forces leading to the well-known Navier-Stokes-Equations (NSE) ∂ui =0 ∂xi ∂uj ∂uj ∂% 1 ∂ 2 uj + ui =− − + gj ∂t ∂xi ∂xj Re ∂x2i (Continuity equation) (Momentum equation) A Change in momentum is forced by the pressure gradient (%), viscousity or gravity (g). The dimensionless Reynoldsnumber (Re) introduced in the momentum equation gives credit to the relation of mechanical to viscous forces. A low value here represents high viscousity of the fluid leading to mainly laminar flow while high Reynoldnumbers yield turbulent flows generated by inertial forces. From statistical analysis inspired, the LBM was designed out of the Lattice Gas-Methode and represents a scheme stationed inbetween the microscopic and macroscopic world. 3 Figure 1.1: Point of view transition [15] Herefore we look at the particle distribution probability in phase space, described by the Boltzmann equation ∂f ∂f +ξ = Q(f, f ) (1.1) ∂t ∂x where f is the particle distribution function, x its spacial position and ξ the particles velocity at timelevel t. The highly complex nonlinear integral collision term Q(f,f) has to be solved. This is done by a kinetic model by Bhatnagar, Gross and Krook (see [14]) which approximates Q(f,f) with −ω(f − f eq ) leading (1.1) to be written as ∂f ∂f +ξ = −ω(f − f eq ) (1.2) ∂t ∂x Here f eq stands for the local equilibrium distribution function and ω denoted the viscousity of the fluid and is called the single step relaxation time. Essentually the LBM states, all driving forces for particle distribution have to act against the fluids ”urge” for equilibrium. Discretizing (1.2) by means of forward Euler along the velocities ci in direction i we get: 1 fi (x + ci ∆t, t + ∆t) − fi (x, t) = − (fi − fieq ) τ This equation the is solved in two steps: 1 f̃i (x, t + ∆t) = fi (x, t) − (fi − fieq ) τ fi (x + ci ∆t, t + ∆t) = f̃i (x, t + ∆t) 4 (1.3) (Collide Step) (Stream Step) (a) Realxation during Collide Step (b) Streaming of PDFs during Stream Step Figure 1.2: Illustration of stream and collide steps [15] Before f eq is stated, we have to introduce a model for the spacial discretization by limiting the freedom variables to a spcified set of directions. In the 3D-case we choose the D3Q19-Model which looks like this Figure 1.3: D3Q19 [15] A model with even more freedom variables in 3D would be the D3Q27 with additional 8 directions TNE, TNW, TSE, TSW, BNE, BNW, BSE, BSW. But for most cases the accuracy of D3Q19 is enough. Now f eq can be calculated as: 3 9 3u2 eq 2 f = tp ρ 1 + 2 ci u + 4 (ci u) − 2 (1.4) c 2c 2c 5 where ci are the lattice velocities in direction i and tp a wheighted factor dependent of the direction 1 f or i = C 4 1 tp = f or i = N, E, S, W, T, B 9 1 tp = f or i = other 36 tp = Finally the algorithm for the Lattice-Boltzmann-Methode can be outlined as followed: Figure 1.4: LBM-Algorithm [15] For further information on LBM see [15]. 1.2 Boundary Conditions A Standard implementation of boundary conditions (BC) in a LBM involve no-slip-walls, which offer a certain amount of friction to the fluid. The idea is to simply invert all distribution functions of a cell pointing at that wall. 6 Figure 1.5: No-Slip Boundary Conditions for LBM [15] An additional feature to no-slip-walls can be introduced by looking at the lid-driven-cavity-problem, see [11]. Here we look at a controlvolume of fluid, where the top wall consists of moving no-slip-cells, which not only apply friction but also induce a current. These BCs are essentially treated the same way as non-moving no-slip-cells, except a scaling term is additionally applied depending on the walls velocity and direction of movement. fᾱ (x, t) = fα (x, t) + 2tp ρ 3 cα uw c2 (1.5) here α denotes the direction towards the cell and ᾱ the inverted direction. 7 Chapter 2 Theory 2.1 Convection-Diffusion Equation Partial differential equations (PDEs) approximate complex behaviour and natural phenomena. For the mixture model we have to look at the convectiondiffusion equation (CDE), that looks in its scalar forms like: ∂Φ ∂t |{z} + u∇Φ | {z } = Convective term D∆Φ | {z } Dif f usive term + s |{z} (2.1) Source term T ransient term Here the transient term is responsible for the evolution in time The convective term is responsible for spreading information in laminar direction The diffusive term is responsible for spreading information through an imbalance in potential and the source term accounts for sources or sinks in the domain The CDE can assume various properties like elliptic, parabolic or hyperbolic, but for most problems it shows a variable behaviour or even different forms in various positions in the domain. A useful means of categorizing the CDE is the Peclet-Number uL (2.2) Pe = Γ which represents the ratio of convectivity to diffusivity. A high Peclet-number means information is spread across the domain mainly through convection and is therefore transported predominantly downstream. A small Pecletnumber (P e 1) means information is spread faster in all directions rather than in laminar direction. More information on the classification of PDEs can be found in [6]. 8 In order to describe chemical transport processes some neccessary quantities have to be introduced mk : M ass of the specie k V : control volume uk : velocityf ield of the specie k By changing the information Φ, transported by the CDE, form mass quantity rather to concentrations mass fraction we get the specie transport equation. 2 ∂C ∂C ∂C ∂C ∂ C ∂ 2C ∂ 2C +u +v +w =D +s (2.3) + + ∂t ∂x ∂y ∂z ∂x2 ∂y 2 ∂z 2 2.2 Numerical Approach There exist several models for multi-component mixtures. One is to look only at the solvent case, where one component is dominantly available, while the others masses are neglectable in comparison mi mj ∀i, j ∈ N ∨ i 6= j (2.4) Here the compound is treated as a binary mixture with the primary and one other component, while the others dont affect them. This approch is called the Single-Fluid-Approach which is the main aspect of this work. 2.2.1 Ficks first law of diffusion In a multi-chemical mixture, each component has its own velocity to account for. But with the assumption of no chemical reaction what so ever the whole fluid mixture has a global mixture velocityfield, the mixture flux J. We now look at a specific scenario involving a fluid filled control volume, devided into two parts. Each part is of unit-size (x = y = z = 1) and is filled exclusivley with molecules of Type 1 respectively Type 2, as shown in figure 2.1. The two parts are devided by a membrane through which both molecules can pass in both directions. By setting the membranearea to A, the fluids total flux eventually is the net amount of molecules passing through A in a given time intervall. This leads in conclusion to Fick’s first law of diffusion, stating the mass diffusion flux is proportional to the mass concentrations gradient in diffusion-direction Jk = −Dk 9 ∂Ck ∂x (2.5) Figure 2.1: Control Volume filled with two different molecules and seperated by membrane [5] Where Jk is the mass diffusion flux in the binary mixture of the dominant fluid and one other. Dk is the constant diffusion coefficent between those two fluids and Ck the species mass concentration compared to the dominant specie. It can be shown that the resulting flux is equal for all binary combinations and results in the total mixture flux. Therefore the whole mixture can be solved by calculating individually each solvent component. For further details look at [5]. 2.2.2 Multi-Fluid-Approach It has to be mentioned that in contrast to the Single-Fluid-Approach shown above there is also a Multi-Fluid-Approach. Here the mixture is computed as whole and velocitiy and quantity of each component actually affect others. But such schemes (e.g. Maxwell-Stefan) preceed extensive math and computational effort. A 2D-test-implementation and more details can be read in [5]. 2.3 Boundary Conditions While the basic theory inside the domain was stated above, the computation on the domains boundary still has to be considered. 10 2.3.1 Periodic Although periodic BC hold no case in real-world-applications, they are a good means to theorize inner mechanisms while the area of effect doesnt reach the domains edge. Here each particle exiting the domain throung periodic walls, enters the domain on the other side. 2.3.2 Dirichlet Dirichlet or constant Boundary Conditions are a more trivial case, since they represent an inlow of new mass or in terms of thermal diffusion a heated or cooled wall. Here a value is simply set at the boundaries. 2.3.3 Neumann This is the nontrivial case representing an outflow of mass or just a solid wall (no-slip-cells). Here the gradient in normal direction is considered to be 0 ∂C =0 ∂n (2.6) This offers some complications since ambiguities are created amoung very small Neumann-Cells showing inconsistent values for different normaldirections. Figure 2.2: Ambiguities for the marked cell for two different gradients 11 Chapter 3 Discretization To solve the PDE the widely spread method of finte differences is used in this work. The contemplated contious domain is discretized by a grid resulting in a discrete approximation of the PDEs solution on the meshed domain with a finite number of gridpoints. The resulting deviation between the contious derivation and the finte difference is the truncation error τ . 3.1 Temporal Discretization In order to extend the discretization to the evolutionary problem lateron, a similar approach to the finite differences is applied to the temporal term. The method of choice in this thesis is the Crank-Nicolson (CN) method which is based on the finite differences method in space but also accomodates the trapezoidal rule in time. Therefore leading to a temporal accuracy of O(δt2 ). As an example the CN method is applied to a CDE in one dimensional space ∂Φ ∂ 2 Φ ∂Φ = F Φ, x, t, , (3.1) ∂t ∂x ∂x2 Where F represents the finite difference discretized steady state CDE. n+1 n By replacing the left-hand side of (3.1) with Φ δt−Φ , the right-hand side can be evaluated at an any desired timestep between tn and tn+1 . Applying these operations leads to Φn+1 − Φn = (1 − µ) F n + µF n+1 δt (3.2) With this implementation a series of time integrators can be induced by changing the parameter µ. A value of µ = 0 respectivly µ = 1 results in the commonly known forward- respectivly backward-Euler scheme while µ = 0.5 12 implements the desired CN. It is clearly obvious that for values µ 6= 0 the PDE changes to an implicit system which has to be considered for the solver of choice lateron. For more information about Crank-Nicolson to [7]. 3.2 Spacial Discretization with High-OrderCompact Scheme For the spacial discretization the method of finte differences is used and here specially the central difference scheme (CDS). This scheme can be derived from Taylor series expansion to gain a discrete approximation for the contious derivations of the PDE. Such an expansion of Φ from node xi to xi±1 looks like this h ∂Φ h2 ∂ 2 Φ h3 ∂ 3 Φ + + + ... 1! ∂x 2! ∂x2 3! ∂x3 h ∂Φ h2 ∂ 2 Φ h3 ∂ 3 Φ = Φi − + − + ... 1! ∂x 2! ∂x2 3! ∂x3 Φi+1 = Φi + (3.3) Φi−1 (3.4) From these two equations it possible to gain a central difference for the first order derivation 2 3 h ∂ Φ Φi+1 − Φi−1 − − ... δx Φi = (3.5) 2h 3! ∂Φ3 | {z } O(h2 ) In order to ease the effort a new operator representing the currently regarded difference will be introduced. The first and second order derivatives’ operators are defined as followed δx Φi,j,k := δx2 Φi,j,k := δy Φi,j,k := δy2 Φi,j,k := δz Φi,j,k := δz2 Φi,j,k := Φi+1,j,k − Φi−1,j,k 2h Φi+1,j,k − 2Φi,j,k + Φi−1,j,k h2 Φi,j+1,k − Φi,j−1,k 2h Φi,j+1,k − 2Φi,j,k + Φi,j−1,k h2 Φi,j,k+1 − Φi,j,k−1 2h Φi,j,k+1 − 2Φi,j,k + Φi,j,k−1 h2 13 (3.6) (3.7) (3.8) (3.9) (3.10) (3.11) Using the presented scheme leads to a linear system of equations which then can be solved by means of a suitable direct or iterative solver. For our specie transport equation this yields to uδx Φi,j + vδy Φi,j + wδzΦi,j = D δx2 Φi,j + δy2 Φi,j + δz2 Φi,j + s − τ (3.12) The CDS is of accuracy O(h2 ) and therefore the truncation error τ of (3.12) is of accuracy O(h2 ), meaning if the number of gridpoints in one direction is doubled, the error drops by a factor of 4. To overcome these problems we introduce the high-order compact scheme (HOC) from [16]. The basic idea is to discretize a part of the truncation error in order to increase the accuracy, while maintaining a compact stencil in the same instance. Since this scheme is highly dependent of the problem itself, it has to be developed individually each time. We start by looking at the steady state CDE 2 ∂Φ ∂Φ ∂ Φ ∂ 2Φ ∂ 2Φ ∂Φ +v +w =D + + 2 +s (3.13) u ∂x ∂y ∂z ∂x2 ∂y 2 ∂z Assuming D > 0 and ∇D = 0 the whole equation can be divided by D, w representing the velocities yielding new coefficients η = Du , κ = Dv , ω = D s and g = D representing the source term. We now discretize (3.13) using CDS: ηδx Φi,j,k + κδy Φi,j,k + ωδz Φi,j,k − δx2 Φi,j,k + δy2 Φi,j,k + δz2 Φi,j,k − τ = g (3.14) with a local truncation error 3 h2 ∂ Φ ∂ 3Φ ∂ 3Φ ∂ 4Φ ∂ 4Φ ∂ 4Φ − − 4 + O(h4 ) τ= 2 3 +2 3 +2 3 − 12 ∂x ∂y ∂z ∂x4 ∂y 4 ∂z (3.15) In order to increase the accuracy, we pull the third and fourth derivative from τ into the equation and discretize them as well. To gain the corresponding CDS we differentiate (3.13) once respectivly twice in each direction. E.g. the third derivative in x-direction looks like this: ∂ 2 Φ ∂κ ∂Φ ∂ 2Φ ∂ω ∂Φ ∂ 2Φ ∂ 3 Φ ∂η ∂Φ = + + η + κ + + ω ∂x3 ∂x ∂x ∂x2 ∂x ∂y ∂x∂y ∂x ∂z ∂x∂z 3 3 ∂ Φ ∂ Φ ∂g − − − 2 2 ∂x∂y ∂x∂z ∂x 14 (3.16) Noticable here are the various cross-derivatives. They can easily be developed by applying CDS from (3.6) - (3.11) to one another. We then get Φi+1,j+1,k − Φi−1,j+1,k − Φi+1,j−1,k + Φi−1,j−1,k 4h2 Φi+1,j,k+1 − Φi−1,j,k+1 − Φi+1,j,k−1 + Φi−1,j,k−1 := 4h2 Φi,j+1,k+1 − Φi,j−1,k+1 − Φi,j+1,k−1 + Φi,j−1,k−1 := 4h2 2Φi,j−1,k − 2Φi,j+1,k + Φi+1,j+1,k + Φi−1,j+1,k − Φi+1,j−1,k − Φi−1,j−1,k := 2h3 2Φi,j,k−1 − 2Φi,j,k+1 + Φi+1,j,k+1 + Φi−1,j,k+1 − Φi+1,j,k−1 − Φi−1,j,k−1 := 2h3 2Φi−1,j,k − 2Φi+1,j,k + Φi+1,j+1,k + Φi+1,j−1,k − Φi−1,j+1,k − Φi−1,j−1,k := 2h3 2Φi,j,k−1 − 2Φi,j,k+1 + Φi,j+1,k+1 + Φi,j−1,k+1 − Φi,j+1,k−1 − Φi,j−1,k−1 := 2h3 2Φi−1,j,k − 2Φi+1,j,k + Φi+1,j,k+1 + Φi+1,j,k−1 − Φi−1,j,k+1 − Φi−1,j,k−1 := 2h3 2Φi,j−1,k − 2Φi,j+1,k + Φi,j+1,k+1 + Φi,j+1,k−1 − Φi,j−1,k+1 − Φi,j−1,k−1 := 2h3 4Φi,j,k − (2Φi+1,j,k + 2Φi−1,j,k + 2Φi,j+1,k + 2Φi,j−1,k ) := + h4 Φi+1,j+1,k + Φi−1,j+1,k + Φi+1,j−1,k + Φi−1,j−1,k h4 4Φi,j,k − 2 (Φi+1,j,k + 2Φi−1,j,k + 2Φi,j,k+1 + 2Φi,j,k−1 ) + := h4 Φi+1,j,k+1 + Φi−1,j,k+1 + Φi+1,j,k−1 + Φi−1,j,k−1 h4 4Φi,j,k − 2 (Φi,j+1,k + 2Φi,j−1,k + 2Φi,j,k+1 + 2Φi,j,k−1 ) + := h4 Φi,j+1,k+1 + Φi,j−1,k+1 + Φi,j+1,k−1 + Φi,j−1,k−1 h4 δx δy Φi,j,k := δx δz Φi,j,k δy δz Φi,j,k δx2 δy Φi,j,k δx2 δz Φi,j,k δx δy2 Φi,j,k δy2 δz Φi,j,k δx δz2 Φi,j,k δy δz2 Φi,j,k δx2 δy2 Φi,j,k δx2 δz2 Φi,j,k δy2 δz2 Φi,j,k The complete HOC-discretized steady-state CDE can be written as followed: −Aδx2 Φ − Bδy2 Φ − Cδz2 Φ + Dδx Φ + Eδy Φ + Fδz Φ− h2 2 2 (δx δy + δx2 δz2 + δy2 δz2 − κδx2 δy − ωδx2 δz − ηδx δy2 − ωδy2 δz − 6 ηδx δz2 − κδy δz2 − Hδx δy − J δx δz − Kδy δz )Φ = 0 15 (3.17) with the coefficents h2 2 η − 2δx η 12 h2 2 κ − 2δy κ B =1+ 12 h2 2 C =1+ ω − 2δz ω 12 h2 2 δx η + δy2 η + δz2 η − ηδx η − κδy η − ωδz η D=η+ 12 h2 2 E =κ+ δx κ + δy2 κ + δz2 κ − ηδx κ − κδy κ − ωδz κ 12 h2 2 δx ω + δy2 ω + δz2 ω − ηδx ω − κδy ω − ωδz ω F =ω+ 12 H = δx κ + δy η − κη J = δx ω + δz η − ωη K = δy ω + δz κ − κω A=1+ (3.18) (3.19) (3.20) (3.21) (3.22) (3.23) (3.24) (3.25) (3.26) To this formulation we now introduce the transient term by writing ∂Φ g = s − ∂t . For more details on how to extend the HOC-scheme to evolutionary problems refer to [20]. The now obtained CDE discretized in space and time read like this: ∂Φ h2 2 1 2 2 1+ δ + δy + δz − ηδx − κδy − ωδz − D 12 x ∂t Aδx2 Φ − Bδy2 Φ − Cδz2 Φ + Dδx Φ + Eδy Φ + Fδz Φ− (3.27) h2 2 2 2 2 2 2 2 2 2 2 (δ δ + δx δz + δy δz − κδx δy − ωδx δz − ηδx δy − ωδy δz − 6 x y ηδx δz2 − κδy δz2 − Hδx δy − J δx δz − Kδy δz )Φ = 0 and is of accuracy O(h2 ). Furthermore it has a compact stencil. In order to ease solving and implementation effort lateron it is good to write (3.27) in its factorized form 1 1 1 X X X lhsi+l1,j+l2,k+l3 Φn+1 i,j,k = l1=−1 l2=−1 l3=−1 1 1 1 X X X rhsi+l1,j+l2,k+l3 Φni,j,k l1=−1 l2=−1 l3=−1 (3.28) with left hand side coefficoents lhsi+l1,j+l2,k+l3 = 12µpi+l1,j+l2,k+l3 + qi+l1,j+l2,k+l3 16 (3.29) and right hand side coefficients rhsi+l1,j+l2,k+l3 = 12(µ − 1)pi+l1,j+l2,k+l3 + qi+l1,j+l2,k+l3 (3.30) The left hand side coefficients are responsible for the system matrix and it is imminently clear, that for any time-variable µ the system is at best weak diagonally dominant but mostly no dominance is present which is of great importance for a suited solver. 17 2A + 2B + 2C − 2 C: p=t h2 A 2 D η E: p=t − 2 + + − h 2h 3h2 3h 2 D η A + + W : p=t − 2 − h 2h 3h2 3h B 2 E κ N : p=t − 2 + + − h 2h 3h2 3h B 2 E κ S: p=t − 2 − + + h 2h 3h2 3h C 2 F ω T : p=t − 2 + + − h 2h 3h2 3h C F 2 ω B: p=t − 2 − + + h 2h 3h2 3h κ η H 1 + + NE : p = t − 2 + 6h 12h 12h 24 κ η H 1 − − NW : p = t − 2 + 6h 12h 12h 24 1 κ η H SE : p = t − 2 − + − 6h 12h 12h 24 κ η H 1 − + SW : p = t − 2 − 6h 12h 12h 24 ω η J 1 TE : p = t − 2 + + + 6h 12h 12h 24 1 ω η J TW : p = t − 2 + − − 6h 12h 12h 24 1 ω η J BE : p = t − 2 − + − 6h 12h 12h 24 1 ω η J BW : p = t − 2 − − + 6h 12h 12h 24 ω 1 κ K TN : p = t − 2 + + + 6h 12h 12h 24 1 ω κ K TS : p = t − 2 + − − 6h 12h 12h 24 1 ω κ K BN : p = t − 2 − + − 6h 12h 12h 24 1 ω κ 18 K BS : p = t − 2 − − + 6h 12h 12h 24 6 D 1 = 1− D 1 = 1+ D 1 = 1− D 1 = 1+ D 1 = 1− D 1 = 1+ D q= q q q q q q (3.31) hη 2 hη 2 hκ 2 hκ 2 hω 2 hω 2 (3.32) (3.33) (3.34) (3.35) (3.36) (3.37) q =0 (3.38) q =0 (3.39) q =0 (3.40) q =0 (3.41) q =0 (3.42) q =0 (3.43) q =0 (3.44) q =0 (3.45) q =0 (3.46) q =0 (3.47) q =0 (3.48) q =0 (3.49) Chapter 4 Implementation This implementation is built upon the WaLBErla-Framework, developed by the chair for simulation and parralel computing of the university of ErlangenNuremberg [2]. Therefore all dataloayout and functions are based on the ones used there. 4.1 WaLBerla-Framework All fields are realized by one-dimensional arrays embeded in different classes of fields. These classes simultate 2-, 3- or multidimensional arrays and provide specific access and maintenance-functions. E.g. the velocity-field class stores a 3-dimensional vector, representing the velocity-component in each direction, for a set of coordinates x,y and z. The values can be accessed via GET-functions of the type <Type T> Get(int x, int y, int z, DIR) Here the return-value is realized by use of templates to easily alter the type. x,y and z represent the current position in the domain and DIR stands for the directional component which will be retrieved. Whereas the density-field stores only one scalar value for a certain position. In the following a basic overview of the LBM-Algorithm in the WaLBErlaFramework is given, followed by the implementation of the specie transport equation solver for the single-fluid approach. Finally the boundary condition treatment and its implementation are outlined. 19 4.2 LBM-Algorithm in WaLBErla The WaLBErla-project not only provides datalayout but also solver-layouts, called Sweeps. Basically a sweep represents one pass through the domain with some special computation. Additionally sweeps can be run iterativly, reducing the overhead in code and presenting a further method of parallelization. Different sweeps therefore can perform different tasks and independant issues can be performed in parallel easily. The main task of WaLBErla first loads all neccessary data into the project and then starts the sweep-run. The basic LBM-sweep solves the LatticeBoltzmann-Equation, calculates the particle distribution functions, velocity and density of the fluid. The resulting velocity-field can be assumed as the overall mixture velocity and will later be used to solve the specie transport equation. For further insights into LBM and WaLBErla refer to [2]. Essentially the LBM-sweep looks as followed Listing 4.1: Main loop of LBM Init (); // I n i t i a t e parameters , fields f o r ( i n t t =0; t<sim . t i m e s t e p s ; ++t ) { //PDF Sweep treatBoundaries ( ) ; and b o u n d a r i e s // s t a r t timeloop // i m p o s e b o u n d a r y conditions streamStep ( ) ; // p e r f o r m LBM s t r e a m collideStep (); // p e r f o r m LBM c o l l i d e swapGrids ( ) ; // swap PDF f i e l d s // o t h e r S w e e p s switch ( sim . t a s k s ) { case m i x t u r e : case r i g i d B o d y : // c h o o s e additional step step tasks SolveSpecieTransport ( ) ; SolveRigidBodyDynamics ( ) ; ... } } 4.3 // end t i m e l o o p Solver As outlined in chapter 3.2 the prime task of the solver-sweep is to calculate an approximation for the problem Ax = b. Since the system matrix is a non-diagonal-dominant matrix, the use of iterative solvers, such as Gauss-Seidel, is limited. Another class of solver, more suited for the problem are the Krylow-Subspace-Solvers. These approximate a solution by correcting the residual in each iteration to be orthogonal to the previous iteration. From this class the BiCGStab-Methode was implemented. A methode capable of solving thin unstructured systems within a few steps and with improved convergence-stability. The basic algorithm looks like fig20 Figure 4.1: BiCGStab-Algorithm [1] 21 ure 4.1. More details on Krylow-Subspace-Class-Solvers and especially on BiCGStab can be found in [1]. In order to store the neccessary concentration of each specie, a density-field is used since it stores one scalar data per position, which is sufficient. All concentration fields are gathered in a wrapper-class that represents all species in the mixture. As mentioned in chapter 4.2 walberla-sweeps can be run iterativly. This feature is used as the initiation process of BiCGStab is performed in a single step sweep to calculate the rhs and residual. After that a second Advect-Sweep is started that solves the equation iterativly. Listing 4.2: Right-hand-side SWEEP bool C a l c P a t c h : : HybridAdvectRHSsweep ( SimData &sim , // i n i t i a l i z e f i e l d s and v a r i a b l e s Uint t ) { f o r ( U i n t s =0; s<n u m S p e c i e s ; ++s ) { f o r ( U i n t z =0; z<z ; ++z ) f o r ( U i n t y =0; y<y ; ++y ) f o r ( U i n t x =0; x<x ; ++x ) { b ( x , y , z ) = Calc RHS ( ) ; // n e a r B o u n d a r i e s i f ( f l a g ( x , y , z ) == NEAR OBSTACLE&FLUID ) // c o l l e c t c o n c e n t r a t i o n s f r o m n e i g h b o r s and a p p l y BC nb = b u i l d N e i g h b o r D a t a ( x , y , z ) ; r ( x , y , z ) = b ( x , y , z ) − A ∗ nb ( x , y , z ) ; // i n n e r c e l l s i f ( f l a g ( x , y , z ) == FLUID ) r (x , y , z ) = b(x , y , z ) − A ∗ c [ s ] ( x , y , z ) ; } } } r0 = r ; // v e r y first residual needs to be stored f o r BiCGStab Listing 4.3: MixtureSWEEP bool C a l c P a t c h : : HybridAdvectSweep ( SimData &sim , \\ i n i t i a l i z e f i e l d s and v a r i a b l e s Uint t , f o r ( U i n t s =0; s<n u m S p e c i e s ; ++s ) { // r u n t h e s o l v e r and s t o r e i n c [ s ] r e s = runBiCGStab ( c [ s ] , f l a g s , sim , } i f ( r e s < sim . e p s ) return f a l s e ; e l s e return true ; t, const U i n t iteration ) { iteration ); } The pseudo-code from the listings 4.2 and 4.3 shows the basic implementation into the waLBErla project. At first the function Calc RHS() is called upon which calculates the rhs-value from 3.30 for the current position in the domain. This is then stored to a densityfield b. The variable nb is from the container-class neighborData. In case the current position during the sweep is a near-obstacle-cell the container has to be filled first by the function buildNeighborData() before calculating the starting residual. In case of inner cells with no adjacent obstacles or boundaries, the computation of the residual is directly implemented, saving the neccessary bandwidth of copying values to the container nb. The second sweep is iterativly called upon by waLBErla and returns true in case another iteration has to be done 22 respectivly false if computation is complete and the next timestep should be started. Here the function runBiCGSTab() is the main aspect, requiring the concentration c[s], the flag-field flags for evaluation of the current position, Simdata sim for all simulation-parameters and t and iteration for the current timestep. The return value represents the current residual from the solving step that is taken into account as breaking operation. If the residual falls beneath a predefined the current timestep is complete, else the next iteration is being called upon. 4.4 Boundary Condition Treatment The essential work is the implementation of the boundary treatment. Herefore the container-class neighborData will be introduced. The container gathers at the current position all the neccessary information from the surrounding cells, stores it and implements the actual boundary condition. Now all needed computations can be conducted inside the container as if inside the domain itself. Figure 4.2 illustrates neighborData. To decrease overhead due to inner Figure 4.2: Collect data from adjacent cells cells that don’t need to use boundary treatment, the neighborData-class is only called upon, when the current position is in direct range of a boundary cell. Herefore a already existing feature of WaLBErla was used, which is an additional flag-status for cells called NEAR OBST (Near Obstacle), indicating that the actual cell is a neighbor of an obstacle. 23 Chapter 5 Results Int his chapter the implementation is tested for its accurat results and lastly the range of valid starting parameters is outlined. Herefore the theoretically assumed diffusion coefficient (DiCo) is investigated during simulation and compared with the resulting DiCo. The simulation domain is initialized with a gaussion distribution in order to track its decay characteristics. To gain a discrete initial distribution for the species concentration the following equation is used: 2 ! 1 xi − µ (5.1) f (xi ) = pv · exp − 2 σ By using the one-dimensional probability density function 5.1 the desired initial concentration distribution will also show diffusive behaviour in only one dimension because all gradients pointing in different directions are 0. The DiCo now can be tracked by investigating the change of the variance over time 1 ∂(V ar) (5.2) D= 2 ∂t The Variance Var is calculated by Nx X 2 V ar = (xi − x̄) h · i=1 xi √ pv · σ · 2π (5.3) Here xi denotes the displacement, σ controlls the initial width of the curve and x̄ is its mean value given by x̄ = Nx X i=1 xi √ xi · h · pv · σ · 2π 24 (5.4) Now the resulting DiCo can be investigated by checking the variance after a few timesteps of simulation by approximating 1 V arn − V arn−1 D= (5.5) 2 δt By checking the DiCo after only a few timesteps it can be ensured that the initial distribution does not reach any of the domains boundaries, which could distort the results. This method will be used to both determine the correct diffusive and convective behaviour in the next part. 5.1 Measurement of diffusive behaviour For this test the simulated species is assumed at total rest, which mathematically reduces the CDE to a pure diffusion equation. The initial distributions are created according to (5.1) using parameters D = 0.05, µ = 100, σ = 10 and pv = 0.5. The domain consists of 200, 20, 20 gridpoints. The LBM ensures that the meshsize h and timestep δt are of size 1. The simulation runs for 10000 timesteps. Figure 5.1 illustrates the one- Figure 5.1: Decay characteristics of initial distribution dimensional initial distribution and shows the decay of the initial gaussian. Finally as can be seen in figure 5.2, in a logarithmic scale, the preset DiCo is recreated constantly over time with only slight fluctuations near the end 25 Figure 5.2: measured D over time of the simulation after approximatly 7000 timesteps. This can be explained as the distributions part thats significantly different from 0 reaches the domains boundaries and that the imposed nonslip boundary conditions donnot recreate the DiCo 100%ly accurate. 5.2 Influence of spacial resolutions In this scenario it will be investigated what the minimal number of gridpoints are to correctly recreate a DiCo of 0.01. As in the previous scenario the domain consists of 200, 20, 20 nodes but will be consecutivly shortened in one dimension until deviations are revealed. The variance measurement will be taken after 20 timesteps. Figure 5.3 shows that for big domainsizes the DiCo is constantly correctly reproduced, but starting from a size of x = 70 slight deviations occure which are strengthend even more by further decrease. 5.3 Range of diffusion coefficients The aim of this test is to determine a range of diffusion coefficients that are correctly recreated. The testsetup from the previous scenarios concerning initial gaussian distribution and fluid velocity will be used again. The starting DiCo-parameter will be ranged from 10−9 to 1. While assuming that most 26 Figure 5.3: Reproduced DiCo over a decresing set of domainsizes commonly used DiCos will range from around 10−4 to 10−1 , this range will be examined with a finer stepping than the smaller ones. The measurement will take place after 20 timesteps. Figure 5.4: Range of diffusion coefficients Figure 5.4 shows the resulting comparisson of measured parameter and expected theoretical DiCo and it is clearly visible that the whole range is covered by the implenetation accuratly. 27 5.4 Measurement of convective behaviour To test the convective behaviour of the implementation, first a new value for classification of the problem will be introduced. The dimensionless Pecletnumber Pe already introduced in chapter 2.1 has to be taken into account It is especially important for miniature CFD models that the Peclet-numbers are equal. (a) P e = 0.001 (b) P e = 0.01 (c) P e = 0.1 (d) P e = 1 (e) P e = 10 (f) P e = 100 Figure 5.5: Measured D over time with various Peclet-numbers For this scenario the setup of the previous test will be adopted except for a 28 initial displacement of µ = 50 and the measured DiCo will be investigated. To stress the realtion between diffusion coefficient and mean fluid velocity the results are sorted by their Pe using L = 1 and a velocity ranging from 10−4 to 10−1 . The results from figures 5.5 (a)-(f) show a constant reproduction rate of the DiCo for P e ≤ 1 and starting deviations for greater values. 29 Chapter 6 Conclusion This thesis deals with the implementation of a multicomponent mixture model into the WaLBErla framework in 3D. The implementation is based upon Fick’s first law of diffusion and using finite difference scheme, especially High-order compact stencil scheme to get an accurat approximation. Herefore the commonly known Convection-Diffusion-Equation was discretized by means of the HOC-scheme in space and with a Crank-NicolsonImplementaion in time, resulting in a implicit system of equations. In order to solve this system a solver was implemented using the BiCGStab methode form [1]. To implement the whole scheme into the WaLBErla framework, two new Sweeps where created that, independently from WaLBErlas PDF and Rigid-Body computations, computed the right- and left-hand-side of the system for each specie. The final numerical experiments serve as verfication of the correctness of the implementation and as builing a first range for the set of initial parameters. Ficks first law of diffusion proved to be easily understandable since it invited the single-fluid-approach to the mixture model which allowed to compute each specie in the fluid independently. But it should not be forgotten, that Ficks law was only stated for binary mixtures and that maybe other, more complex approaches are more suited for mulitcomponent mixtures. The HOC-scheme at first showed a treamendous amount of mathematical effort prior to the implementation, since the many derivations of the CDE in 3D had to be discretized. But after that, the implementation was nearly one-to-one with the paperwork. In conclusion HOC proved to be extremely well fit for this problem, since it has generated such a big accuracy despite the slight occurance of numerical diffusion. But different implementations in 2D like in [5] showed for a finite difference implementation using only operators of O(h2 ) accuracy suffer from even more effects of numerical diffusion arising from up- and 30 down-winding schemes. But the most troublesome part apearred to be the time-discretization, since a first step to extending the problem from stedystate to evolutionary, failed on a explicit time discretization. Therefore CN with its unconditional stability feature was used. But despite all the benefits of the mixture model presented, there is still much reasearch needed until it can be used in numerical engineering. The next step should be optimizing datalayout ([8]) and maybe optimizing the used solver. One idea could be the use of hybrid CG solvers that can adopt both BiCG and QMR features. Another idea would be to try and merge the ideas of HOC with the field of finite volumes. 31 Chapter 7 Acknowledgements I would like to say thank you firstly to my tutor Dipl.-Inf. Christian Feichtinger, who always was able to help me and support me during this thesis. To Prof. Dr. Ulrich Rde for giving me the chance to do this really interesting work and get a small insight of this engineering field. And to Dominik Geuss whose Master Thesis [5] helped me alot since mine was merely an extension of his previous work. I thank my girlfriend Alexandra for always encouraging me to never quit even when it was tough and for giving me the free time to finish this thesis. 32 List of Figures 1.1 1.2 1.3 1.4 1.5 Point of view transition [15] . . . . . . . . Illustration of stream and collide steps [15] D3Q19 [15] . . . . . . . . . . . . . . . . . LBM-Algorithm [15] . . . . . . . . . . . . No-Slip Boundary Conditions for LBM [15] 2.1 2.2 Control Volume filled with two different molecules and seperated by membrane [5] . . . . . . . . . . . . . . . . . . . . . . . 10 Ambiguities for the marked cell for two different gradients . . 11 4.1 4.2 BiCGStab-Algorithm [1] . . . . . . . . . . . . . . . . . . . . . 21 Collect data from adjacent cells . . . . . . . . . . . . . . . . . 23 5.1 5.2 5.3 5.4 5.5 Decay characteristics of initial distribution . . . . . . measured D over time . . . . . . . . . . . . . . . . . Reproduced DiCo over a decresing set of domainsizes Range of diffusion coefficients . . . . . . . . . . . . . Measured D over time with various Peclet-numbers . 33 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 5 5 6 7 25 26 27 27 28 [19][21][3][10][9][4][13][18][17][12] 34 Bibliography [1] Benjamin Bihler. Bicgstab als iterativer lser fuer grosse lineare gleichungssysteme. 2003. [2] University of Erlangen-Nuernberg Chair for system simulation. widely applicable lattice boltzmann from erlangen. http://www10.informatik.unierlangen.de/Research/Projects/walberla/walberla.shtml. [3] Stefan Donath. On optimized implementations of the lattice boltzmann method on contemporary high performance architectures. Master’s thesis, University of Erlangen-Nuernberg, 2004. [4] W. F. Spotz G. F. Carey. High-order compact mixed methods. Communications in Numerical Methods in Engineering, 13:553–564, 1997. [5] Dominik Geuss. Investigation of mixture modelling for the lattice boltzmann methode. Master’s thesis, University of Erlangen-Nuernberg, 2008. [6] Wolfgang Hackbusch. Theorie und Numerik elliptische Differentialgleichungen. Teubner Studienbuecher, 2003. [7] http://en.wikipedia.org/wiki/Crank Nicolson. Crank-nicolson method. [8] Klaus Iglberger. Cache optimizations for the lattice boltzmann method in 3d, 2003. [9] Klaus Iglberger. Lecture notes for simulation and scientific computing 2/assignment 4, 2007. [10] Anoop K. Dass Jiten C. Kalita, D. C. Dalal. A class of higher order compact schemes for the unstedy two-dimensional convection-diffusion equation with variable convection coefficients. International Journal for Numerical Methods in Fluids, 38:1111–1131, 2002. 35 [11] Pep Espanol Marco Ellero, Mar Serrano. Incompressible smoothed particle hydrodynamics. Journal of computational physics, 226:1731–1752, 2007. [12] Tilman Neunhoeffer Michael Griebel, Thomas Dornseifer. Numerical Simulation in Fluid Dynamics. SIAM, 1998. [13] Aditya Nitsure. Implementation and optimization of a cache oblivious lattice boltzmann algorithm. Master’s thesis, University of ErlangenNuernberg, 2006. [14] M. Krook P. L. Bathnagar, E. P. Gross. A model for collision process in gases. Phys. Rev., 94:511–525, 1954. [15] Christoph Pflaum. Lecturenotes simulation and scientific computation 2. [16] G. F. Carey W. F. Spotz. High-order compact finite difference methods. [17] G. F. Carey W. F. Spotz. High-order compact finite difference methods with applications to viscous flows. Master’s thesis, University of Texas, Austin, 1994. [18] G. F. Carey W. F. Spotz. High-order compact scheme for the steady stream-function vorticity equations. International Journal for Numerical Methods in Engineering, 38:3497–3512, 1995. [19] G. F. Carey W. F. Spotz. A high-order compact formulation for the 3d poisson equation. Numerical Methods for Partial Differetial Equations, 12:235–243, 1996. [20] G. F. Carey W. F. Spotz. Extension of high-order compact schemes to time dependent problems. Numerical Methods for Partial Differential Equations, 2000. [21] Jun Zhang. An explicit fourth-order compact finite difference scheme for the three dimensional convection-diffusion equation. Communications in Numerical Methods in Engineering, 14:263–280, 1998. 36