/[escript]/trunk/doc/user/stokesflow.tex
ViewVC logotype

Contents of /trunk/doc/user/stokesflow.tex

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2192 - (show annotations)
Mon Jan 5 02:41:34 2009 UTC (10 years, 8 months ago) by lgraham
File MIME type: application/x-tex
File size: 7787 byte(s)
Edited Stokes flow tutorial

1
2 \section{Stokes Flow}
3 \label{STOKES FLOW CHAP}
4
5 In this section we will look at Computational Fluid Dynamics (CFD) to simulate the flow of fluid under the influence of gravity. The StokesProblemCartesian class will be used to calculate the velocity and pressure of the fluid.
6 The fluid dynamics is governed by the Stokes equation. In geophysical problems the velocity of fluids are low; that is, the inertial forces are small compared with the viscous forces, therefore the inertial terms in the Navier-Stokes equations can be ignored. For a body force, $f$, the governing equations are given by:
7 %
8 \begin{equation}
9 \nabla \cdot (\eta(\nabla \vec{v} + \nabla^{T} \vec{v})) - \nabla p = -f,
10 \label{GENERAL NAVIER STOKES}
11 \end{equation}
12 %
13 with the incompressibility condition
14 %
15 \begin{equation}
16 \nabla \cdot \vec{v} = 0.
17 \label{INCOMPRESSIBILITY}
18 \end{equation}
19 %
20 where $p$, $\eta$ and $f$ are the pressure, viscosity and body forces, respectively.
21 Alternatively, the Stokes equations can be represented in Einstein summation tensor notation (compact notation):
22 %
23 \begin{equation}
24 -(\eta(v\hackscore{i,j} + v\hackscore{j,i})),\hackscore{j} - p,\hackscore{i} = f\hackscore{i},
25 \label{GENERAL NAVIER STOKES COM}
26 \end{equation}
27 %
28 with the incompressibility condition
29 %
30 \begin{equation}
31 -v\hackscore{i,i} = 0.
32 \label{INCOMPRESSIBILITY COM}
33 \end{equation}
34 %
35 The subscript comma $i$ denotes the derivative of the function with respect to $x\hackscore{i}$.
36 %A linear relationship between the deviatoric stress $\sigma^{'}\hackscore{ij}$ and the stretching $D\hackscore{ij} = \frac{1}{2}(v\hackscore{i,j} + v\hackscore{j,i})$ is defined as \cite{GROSS2006}:
37 %
38 %\begin{equation}
39 %\sigma^{'}\hackscore{ij} = 2\eta D^{'}\hackscore{ij},
40 %\label{STRESS}
41 %\end{equation}
42 %
43 %where the deviatoric stretching $D^{'}\hackscore{ij}$ is defined as
44 %
45 %\begin{equation}
46 %D^{'}\hackscore{ij} = D^{'}\hackscore{ij} - \frac{1}{3}D\hackscore{kk}\delta\hackscore{ij}.
47 %\label{DEVIATORIC STRETCHING}
48 %\end{equation}
49 %
50 %where $\delta\hackscore{ij}$ is the Kronecker $\delta$-symbol, which is a matrix with ones for its diagonal entries ($i = j$) and zeros for the remaining entries ($i \neq j$).
51 The body force $f$ in Equation (\ref{GENERAL NAVIER STOKES COM}) is the gravity acting in the $x\hackscore{3}$ direction and is given as $f = -g \rho \delta\hackscore{i3}$.
52 The Stokes equations is a saddle point problem, and can be solved using a Uzawa scheme. A class called StokesProblemCartesian in Escript can be used to solve for velocity and pressure; more detail on the class can be view in Chapter \ref{MODELS CHAPTER}.
53 In order to keep numerical stability, the time-step size needs to be kept below a certain value, to satisfy the Courant condition. The Courant number is defined as:
54 %
55 \begin{equation}
56 C = \frac{v \delta t}{h}.
57 \label{COURANT}
58 \end{equation}
59 %
60 where $\delta t$, $v$, and $h$ are the time-step, velocity, and the width of an element in the mesh, respectively. The velocity $v$ may be chosen as the maximum velocity in the domain. In this problem the time-step size was calculated for a Courant number of 0.4.
61
62 The following PYTHON script is the setup for the simulation. It starts off by importing the classes, such as the StokesProblemCartesian class, for solving the Stokes equation and the incompressibility condition for velocity and pressure. Physical constants are defined for the viscosity and density of the fluid, along with the acceleration due to gravity. Solver settings are set for the maximum iterations and tolerance; the default solver used is PCG. The mesh is defined as a rectangle, to represent the body of fluid. The gravitational force is calculated base on the fluid density and the acceleration due to gravity. The boundary conditions are set for a slip condition at the base of the mesh; fluid movement in the x-direction is free, but fixed in the y-direction. An instance of the StokesProblemCartesian is defined for the given computational mesh, and the solver tolerance set. Inside the while loop, the boundary conditions, viscosity and body force are initialized. The Stokes equation is then solved for velocity and pressure. The time-step size is calculated base on the Courant condition, to ensure stable solutions. The nodes in the mesh are then displaced based on the current velocity and time-step size, to move the body of fluid. The output for the simulation of velocity and pressure is then save to file for visualization.
63 %
64 \begin{python}
65 from esys.escript import *
66 import esys.finley
67 from esys.escript.linearPDEs import LinearPDE
68 from esys.escript.models import StokesProblemCartesian
69
70 #physical constants
71 eta=1.0
72 rho=100.0
73 g=10.0
74
75 #solver settings
76 tolerance=1.0e-4
77 max_iter=200
78 t_end=50
79 t=0.0
80 time=0
81 verbose='TRUE'
82 useUzawa='TRUE'
83
84 #define mesh
85 H=2.0
86 L=1.0
87 W=1.0
88 mesh = esys.finley.Rectangle(l0=L, l1=H, order=2, n0=20, n1=20)
89 coordinates = mesh.getX()
90
91 #gravitational force
92 Y=Vector(0.0, Function(mesh))
93 Y[1]=-rho*g
94
95 #element spacing
96 h=Lsup(mesh.getSize())
97
98 #boundary conditions for slip at base
99 boundary_cond=whereZero(coordinates[1])*[0.0,1.0]
100
101 #velocity and pressure vectors
102 velocity=Vector(0.0, ContinuousFunction(mesh))
103 pressure=Scalar(0.0, ContinuousFunction(mesh))
104
105 #Stokes Cartesian
106 solution=StokesProblemCartesian(mesh)
107 solution.setTolerance(tolerance)
108
109 while t <= t_end:
110
111 print " ----- Time step = %s -----"%( t )
112 print "Time = %s seconds"%( time )
113
114 solution.initialize(fixed_u_mask=boundary_cond,eta=eta,f=Y)
115 velocity,pressure=solution.solve(velocity,pressure,max_iter=max_iter,verbose=verbose,useUzawa=useUzawa)
116
117 print "Max velocity =", Lsup(velocity), "m/s"
118
119 #Courant condition
120 dt=0.4*h/(Lsup(velocity))
121 print "dt", dt
122
123 #displace the mesh
124 displacement = velocity * dt
125 coordinates = mesh.getX()
126 mesh.setX(coordinates + displacement)
127
128 time += dt
129
130 vel_mag = length(velocity)
131
132 #save velocity and pressure output
133 saveVTK("vel.%2.2i.vtu"%(t),vel=vel_mag,vec=velocity,pressure=pressure)
134 t = t+1.0
135
136 \end{python}
137
138 The results from the simulation can be viewed with \mayavi, by executing the following command:
139 %
140 \begin{python}
141 mayavi -d vel.00.vtu -m SurfaceMap
142 \end{python}
143 %
144 Colour coded scalar maps and velocity flow fields can be viewed by selecting them in the menu. The time-steps can be sweeped through to view a movie of the simulation.
145 Figures \ref{FLUID OUTPUT1} and \ref{FLUID OUTPUT2} shows the simulation output. Velocity vectors and a colour map for pressure are shown. As the time progresses the body of fluid falls under the influence of gravity.
146
147 \begin{figure}
148 \center
149 \subfigure[t=1]{\label{FLOW OUTPUT 01}\includegraphics[scale=0.25]{figures/stokes-fluid-t01.eps}}
150 \subfigure[t=20]{\label{FLOW OUTPUT 10}\includegraphics[scale=0.25]{figures/stokes-fluid-t10.eps}}
151 \subfigure[t=30]{\label{FLOW OUTPUT 20}\includegraphics[scale=0.25]{figures/stokes-fluid-t20.eps}}
152 \includegraphics[scale=0.25]{figures/stokes-fluid-colorbar.eps}
153 \caption{Simulation output for Stokes flow. Fluid body starts off as a rectangular shape, then progresses downwards under the influence of gravity. Color coded distribution represents the scalar values for pressure. Velocity vectors are displayed at each node in the mesh to show the flow field. Computational mesh used was 20$\times$20 elements.}
154 \label{FLUID OUTPUT1}
155 \end{figure}
156
157 \begin{figure}
158 \center
159 \subfigure[t=40]{\label{FLOW OUTPUT 30}\includegraphics[scale=0.25]{figures/stokes-fluid-t30.eps}}
160 \subfigure[t=50]{\label{FLOW OUTPUT 40}\includegraphics[scale=0.25]{figures/stokes-fluid-t40.eps}}
161 \subfigure[t=60]{\label{FLOW OUTPUT 40}\includegraphics[scale=0.25]{figures/stokes-fluid-t50.eps}}
162 \includegraphics[scale=0.25]{figures/stokes-fluid-colorbar.eps}
163 \caption{Simulation output for Stokes flow.}
164 \label{FLUID OUTPUT2}
165 \end{figure}

  ViewVC Help
Powered by ViewVC 1.1.26