Académique Documents
Professionnel Documents
Culture Documents
discussions, stats, and author profiles for this publication at: https://www.researchgate.net/publication/241866873
Article
CITATIONS READS
0 295
1 author:
Jonas Koko
Université Clermont Auvergne
56 PUBLICATIONS 226 CITATIONS
SEE PROFILE
Some of the authors of this publication are also working on these related projects:
All content following this page was uploaded by Jonas Koko on 19 May 2014.
Jonas Koko
LIMOS, Université Blaise Pascal – CNRS UMR 6158
ISIMA, Campus des Cézeaux – BP 10125, 63173 Aubière cedex, France
koko@isima.fr
Abstract
We propose a detailed Matlab implementation of the Uzawa Conjugate gradient
algorithm for the generalized Stokes problem with a P1 -iso-P2 /P1 finite element dis-
cretization. Vectorized Matlab functions for assembling mass, Laplacian and diver-
gence matrices, required by the Uzawa algorithm, are provided.
Keywords: Stokes equations, Uzawa method, finite element, Matlab.
AMS subject classification: 65N30, 65K10, 76D07
1 Introduction
This paper presents a detailed Matlab implementation of the (preconditioned) Uzawa con-
jugate gradient algorithm for the generalized Stokes problem using the P 1 -iso-P2 /P1 finite
element. The Uzawa scheme is a decomposition coordination method with coordination
by the Lagrange multiplier (the pressure). The decomposition step reduces to uncoupled
scalar Poisson equations. We use the preconditioner advocated by Cahouet and Chabard
[3], well-suited for generalized Stokes problems with high parameters ratio. Then in both
decomposition and coordination steps, the linear systems solved are equivalent to scalar
Poisson equations.
The finite element spaces P1 -iso-P2 /P1 consist of two superimposed P1 meshes Th (the
fine mesh) and T2h (the coarser mesh) in which T2h is twice coarser than Th . Consequently,
the same assembling functions can be used for velocity and pressure matrices. At a first
sight, it seems difficult to use a vectorization techniques for this element for which the
number of unknowns at each node depends on the node position, whether at a vertex or
at a mid-edge. But with a suitable data representation, the calculations can be carried
out using vectorization techniques.
Matlab is a matrix language, that is, Matlab is designed for matrix and vector oper-
ations. For best performance in large scale problems, one should take advantage of this.
That is why all matrix assembling functions proposed are vectorized. Vectorization means
that there is no loop over triangles nor nodes. Our implementation required only Matlab
basic distribution functions and can be easily modified and refined.
The paper is organized as follows. The generalized Stokes problem is presented in
Section 2 followed by the finite element discretization in Section 3. In Section 4 we
1
2 THE STOKES PROBLEM 2
detail the data representation of the P 1 -iso-P2 /P1 triangulation. The Uzawa conjugate
gradient algorithm is presented in Section 5. Matlab assembling functions for matrices
and the right-hand side are presented in Section 6 and 7. In Section 8 we present Matlab
implementation of the Uzawa conjugate gradient algorithm. Some numerical experiments
are carried out in Section 9. In the appendix, we give Matlab programs used for numerical
experiments and a Matlab function which generates a P 1 -iso-P2 /P1 mesh from a P1 mesh.
αu − ν∆u + ∇p = f, in Ω, (2.1)
∇ · u = 0, in Ω, (2.2)
Γ
u = u , on Γ. (2.3)
u = (u1 (x), u2 (x)) is the velocity vector, p = p(x) is the pressure and f = (f 1 (x), f2 (x)) is
the field of external forces. In (2.1), α ≥ 0 is an arbitrary constant. If α = 0, (2.1)-(2.2)
turn to be the classic Stokes problem. The constant ν ≥ 0 is the kinematic viscosity and
if ν = 0, (2.1)-(2.2) turn to be L2 projection encountered in time discretization of Navier-
Stokes equations (see e.g. [4, 5]). In unsteady Navier-Stokes calculations, α ≡ (δt) −1 ,
where δt is the time step. Hence, if δt << 1, then α >> 1.
We need functional spaces
ViD = v ∈ H 1 (Ω) : v = uΓ on Γ , V D = V1D × V2D ,
Z
1 2
Vi = H0 (Ω), V = V1 × V2 , P = p ∈ L (Ω) : p dx = 0 ,
Ω
A
A
A
A
A A
A A
A A
A A
A A
For the discrete velocity-pressure spaces, we use the P 1 -iso-P2 /P1 element. These
spaces are well-known to satisfy the discrete Babuska-Brezzi inf-sup condition. Let P 1 be
the space of polynomials in two variables of degree ≤ 1. We define the following finite
element spaces which approximate V i , V , ViD , V D and P respectively:
Vih = vh ∈ C 0 (Ωh ), vh |T ∈ P1 , ∀T ∈ Th , vh |Γ = 0 , Vh = V1h × V2h
VihD = vh ∈ C 0 (Ωh ), vh |T ∈ P1 , ∀T ∈ Th , vh |Γ = uΓih , VhD = V1hD D
× V2h
Z
0
Ph = ph ∈ C (Ωh ), ph |T ∈ P1 , ∀T ∈ T2h , ph dx = 0 ,
Ωh
In VhD , uΓh is the approximate boundary condition verifying the flux condition
Z
uΓh · ndΓ = 0.
Γ
The discrete version of equations (2.4)-(2.5) is
Find (uh , ph ) ∈ VhD × Ph such that:
a(uh , vh ) − (ph , ∇ · vh ) = (f, vh ), ∀vh ∈ Vh , (3.1)
−(qh , ∇ · uh ) = 0, ∀qh ∈ Ph . (3.2)
On the fine mesh Th , this results on the algebraic system of the form
A1 0 −B1t u1 f1
0 A2 −B2t u2 = f2 , (3.3)
−B1 −B2 0 p 0
where
Ai = αMi + νKi , i = 1, 2
with Mi the mass matrix and Ki the stiffness matrix. Matrices A1 and A2 are symmetric,
positive definite (after incorporating the boundary conditions). With a suitable data
representation of the triangulation T h , the vector p is split as follows
" #
p2h
p=
ph
where p2h consists of all values of the pressure at the coarse mesh, and p h those at the
other nodes.
4 DATA REPRESENTATION OF THE TRIANGULATION 4
To summarize, the P1 -iso-P2 /P1 mesh is stored in four arrays p, th, t2h and e2h. Dirichlet
boundary nodes are provided by arrays ibc1(1:nbc1) and ibc2(1:nbc2).
With the above organization, the pressure vector of nodal values p split as follows
2h
p
p= .
ph
In calculations, we only use the coarse mesh part p 2h . The fine mesh part ph is determined
from p2h .
Matlab supports reading data from files in ASCII format (Matlab function load) and
there exists good P1 mesh generators written in Matlab, see e.g. [6]. Matlab function
given in A.3 returns a P1 -iso-P2 /P1 mesh from an input P1 mesh.
defined over RNh ×RNh ×RN2h . A saddle-point (u, p) of L is characterized by the min-max
problem
L(u, q) ≤ L(v, q) ≤ L(v, p), ∀(v, q) ∈ RNh × RNh × RN2h , (5.3)
5 UZAWA CONJUGATE GRADIENT ALGORITHM 5
Ai ui − Bit p = fi , i = 1, 2, (5.4)
−B1 u1 − B2 u2 = 0. (5.5)
The saddle-point equations (5.4)-(5.5) are precisely the algebraic system (3.3). Eq. (5.4)
stands for the minimization step of the min-max problem (5.3) while Eq. (5.5) stands for
the maximization step.
To derive a Lagrange multiplier algorithm, we assume that u = u(p) is the solution of
the Poisson equation
Ai ui = fi + Bit p, i = 1, 2. (5.6)
Then, multiplying (5.6) by ui and substituting the result in (5.2), we get
1
L(u(p), p) = − (ut1 A1 u1 + ut2 A2 u2 ).
2
Introduce the dual functional
1 t
J ∗ (p) = − min L(u, p) = (u A1 u1 + ut2 A2 u2 ),
u 2 1
where u = u(p) is the solution of (5.6). The saddle-point problem (5.3) now takes the
form
p ∈ RN2h , J ∗ (p) ≤ J ∗ (q), ∀q ∈ RN2h . (5.7)
From (5.6), the mapping p 7→ u(p) is linear and we have u(p + td) = u(p) + tw where
w = (w1 , u2 ) is the solution of the uncoupled sensitivity equation
Ai wi , = Bit d, i = 1, 2. (5.8)
r := ∇J ∗ (p) = B1 u1 + B2 u2 . (5.9)
The value of (5.9) computed on the coarse mesh T 2h will be denoted by rp . With the data
representation of Section 4, we have
2h
r
r=
rh
Then, the gradient rp in the coarse mesh is computed using the formula
1 X h
rpi = r2h
i + rk , i = 1, 2 . . . (5.10)
2
k∈Vi
where Vi is the set of indices of neighbor nodes (in the fine mesh). In our code, (5.10) is
computed efficiently using the Matlab function sparse.
A practical implementation of the algorithm requires the choice of a preconditioner
for computing the derivative (5.9). We use the preconditioner advocated in Cahouet and
5 UZAWA CONJUGATE GRADIENT ALGORITHM 6
Chabard [3]. Let Kp and Mp be the Laplacian and mass matrices assembled on the coarse
mesh T2h . First an auxiliary unknown z is computed as solution of
Kp z = r p (5.11)
zk = erkp
Kpe
gk = αMpe
Mp e zk + νerkp .
With a search direction −dk , the step size tk is computed as a minimizer of the real-
valued function ϕ(t) = J ∗ (pk − tdk ). Since J ∗ is quadratic, it follows that
Algorithm UCG
r0 = B1 u01 + B2 u02
d0 = g 0
Ai wik = Bi dk , i = 1, 2.
gk ∈ RN2h via
Compute e
gk = νerkp + αe
Mp e zk
|ghk |2P
Step size: tk =
(dk ,erk )
Update:
pk+1 = pk − tk dk , uk+1 = uk − tk wk , gk+1 = gk − tk e
gk .
dk+1 = gk+1 + βk dk
|gk+1 |P
We iterate until |gk |2P = (gk , rkp )R is sufficiently small, typically < ε.
|g0 |P
6 Assembly of matrices
We have to assemble, on the fine mesh T h , stiffness and mass matrices
and
x32 y23
x(T ) = x13 y (T ) = y31 . (6.2)
x21 y12
An entry of the element Laplacian matrix K (T ) is given by
Z
(T ) 1 (T ) (T ) (T ) (T )
Kij = ∇φi ∇φj dx = yi yj + x i xj
T 4|T |
and we deduce that
1 (T ) (T ) t
K (T ) = y (y ) + x(T ) (x(T ) )t .
4|T |
(T ) (T )
With Matlab, xi and yi can be computed in a fast way for all triangles using
vectorization. Then assembling the Laplacian matrix reduces to two constant loops for
computing x(T ) (x(T ) )t and y (T ) (y (T ) )t . By taking into account symmetry properties, the
computational cost of the assembling process can be reduced. Matlab vectorized imple-
mentation of the assembly of the stiffness matrix is presented in Function 6.1.
by direct integration. For the global mass matrix, it suffices to compute triangles area.
Matlab vectorized implementation of the assembly of the mass matrix is presented in
Function 6.2.
(T ) 1
B1 = [y (T ) y (T ) y (T ) ]
6
7 ASSEMBLY OF RIGHT-HAND SIDES 9
(T )
In the same way, the element divergence submatrix B 2 is
1
(T )
= [x(T ) x(T ) x(T ) ].
B2
6
Matlab implementation of the assembly of divergence matrices is given in Function 6.3.
The solution to (velocity) linear systems during the iterative process is therefore reduced
to backward/forward substitutions.
9 NUMERICAL EXPERIMENTS 11
9 Numerical experiments
In two-dimensional incompressible fluid problems, it is usual to display the stream-lines. If
the domain Ω is bounded and simply connected, in order to compute the stream-function
ψ, we have to solve the Poisson-Neumann problem
−∆ψ = ω, in Ω, (9.1)
∂n ψ = −u · τ, (9.2)
Function 8.1 Matlab function for the Uzawa conjugate gradient algorithm
function [u1,u2,p,iter]=ucgstokes(R1,R2,RKp,RMp,Mp,B1,B2,e2h,b1,b2,ibc1,ibc2,...
ibcp,p,s,ss,alpha,nu,epscg)
%UCGSTOKES Uzawa Conjugate gradient algorithm for the Stokes Problem
%
nh=length(b1); ne2h=size(e2h,1); n2h=nh-ne2h;
lnh=[1:size(e2h,1)]+n2h;
ie1=e2h(:,1); ie2=e2h(:,2);
% Initial velocity
u1=zeros(nh,1); u1(s)=R1\(R1’\b1(s));
u2=zeros(nh,1); u2(s)=R2\(R2’\b2(s));
% Initial gradient
rh=B1*u1+B2*u2; r2h=rh(1:n2h);
r2h=r2h+full(sparse(ie1,1,rh(lnh)/2,n2h,1)+sparse(ie2,1,rh(lnh)/2,n2h,1));
r2h(ibcp)=0; gz=zeros(n2h,1); gz(ss)=RKp\(RKp’\r2h(ss));
bp=alpha*Mp*gz+nu*r2h; bp(ibcp)=0; g=zeros(n2h,1); g(ss)=RMp\(RMp’\bp(ss));
gg=r2h’*g; gg0=gg;
% Initial direction
d=zeros(nh,1); d(1:n2h)=g;
% Uzawa loop
tol=1; iter=0;
while (tol>epscg & iter<n2h)
iter=iter+1;
% Sensitivity problems
d(lnh)=(d(ie1)+d(ie2))/2;
b1=B1’*d; b1(ibc1)=0; w1=zeros(nh,1); w1(s)=R1\(R1’\b1(s));
b2=B2’*d; b2(ibc2)=0; w2=zeros(nh,1); w2(s)=R2\(R2’\b2(s));
%
rh=B1*w1+B2*w2; r2hk=rh(1:n2h);
r2hk=r2hk+full(sparse(ie1,1,rh(lnh)/2,n2h,1)+sparse(ie2,1,rh(lnh)/2,n2h,1));
r2hk(ibcp)=0; gz=zeros(n2h,1); gz(ss)=RKp\(RKp’\r2hk(ss));
bp=alpha*Mp*gz+nu*r2hk;bp(ibcp)=0; gk=zeros(n2h,1); gk(ss)=RMp\(RMp’\bp(ss));
% Step size
tk=gg/(rh’*d);
% Update
p=p-tk*d; g=g-tk*gk;
u1=u1-tk*w1; u2=u2-tk*w2;
% New conjugate gradient direction
r2h=r2h-tk*r2hk; gg1=r2h’*g; beta=gg1/gg;
d(1:n2h)=g+beta*d(1:n2h);
% Tolerance
tol=min(sqrt(gg1),sqrt(gg1/gg0)); gg=gg1;
end
where Hh is given by
Hh = ϕh ∈ C 0 (Ω̄), ϕ|T ∈ P1 , ∀T ∈ Th .
9 NUMERICAL EXPERIMENTS 13
Kψ = B2t u1 − B1t u2
0
0 1
0.4
0
0 0.25 0.5 0.75 1 1.25 1.5 1.75 2
Figure 4: Geometry and boundary conditions of the flow around cylinder problem.
A APPENDIX 15
The domain is discretized by a non uniform mesh consisting of 6888 nodes and 13440
triangles. Convergence is reached after 17 iterations. Isobar lines and stream lines are
shown in Figures 5-6. Tables 2-4 show the good convergence properties of the precondi-
tioning (5.11)-(5.12) when α/ν 1.
A Appendix
A.1 Main program for test case with exact solution
%%---------- Test case with exact solution
% constants
alpha=0; nu=1;
Pen=10^10; % Penalty for Dirichlet boundary conditions
epscg=10^-6; % Tolerance for Uzawa algorithm
% mesh
load carre289 p th t2h e2h ibc1 ibc2 ibcp
nph=size(p,1); np2h=nph-size(e2h,1); nth=size(th,1);
fprintf(’Mesh : nph=%4d nth=%4d \n’,nph,nth)
A APPENDIX 16
%
% Matrices generation / velocity
K=laplace2d(p,th,nu); [B1,B2]=div2d(p,th);
A1=K; A2=K; s=symamd(A1);
%
% Matrices generation / pressure
Kp=laplace2d(p(1:np2h,:),t2h,1); Mp=mass2d(p(1:np2h,:),t2h);
MMp=Mp; ss=symamd(Kp);
%
% Right hand side/ exact solution
x=p(:,1); y=p(:,2); pi2=2*pi;
pre=pi2*(cos(pi2*y)-cos(pi2*x));
u1e=-cos(pi2*x).*sin(pi2*y)+sin(pi2*y);
u2e= sin(pi2*x).*cos(pi2*y)-sin(pi2*x);
f1=-pi2*pi2*sin(pi2*y).*(2*cos(pi2*x)-1)+pi2*pi2*sin(pi2*x);
f2= pi2*pi2*sin(pi2*x).*(2*cos(pi2*y)-1)-pi2*pi2*sin(pi2*y);
[b1,b2]=stokesrhs(p,th,f1,f2);
% Boundary conditions (Penalization)
A1(ibc1,ibc1)=A1(ibc1,ibc1)+Pen*speye(length(ibc1));
A2(ibc2,ibc2)=A2(ibc2,ibc2)+Pen*speye(length(ibc2));
Kp(ibcp,ibcp)=Kp(ibcp,ibcp)+Pen*speye(length(ibcp));
MMp(ibcp,ibcp)=MMp(ibcp,ibcp)+Pen*speye(length(ibcp));
b1(ibc1)=0; b2(ibc2)=0;
% Choleski factorization
R1=chol(A1(s,s)); R2=chol(A2(s,s));
RKp=chol(Kp(ss,ss)); RMp=chol(MMp(ss,ss));
clear A1 A2 Kp MMp
% Uzawa/CG
pr=zeros(nph,1);
[u1,u2,pr,iter]=ucgstokes(R1,R2,RKp,RMp,Mp,B1,B2,e2h,b1,b2,ibc1,ibc2,ibcp,...
pr,s,ss,alpha,nu,epscg);
% L^2 and H^1 errors
M=masse2d(p,th,1);
du1=u1-u1e; du2=u2-u2e; dp=pr-pre;
errL2u=du1’*M*du1+du2’*M*du2; errL2p=sqrt(dp’*M*dp);
errH1u=errL2u+du1’*K*du1+du2’*K*du2;
fprintf(’iter=%4d Err:u/L2 %15.8e /H1 %15.8e Err:p/L2 %15.8e \n’,iter,...
sqrt(errL2u),sqrt(errH1u),errL2p)
A APPENDIX 17
% New vertices
ph=[p2h;(p2h(e2h(:,1),:)+p2h(e2h(:,2),:))/2];
% Edge mid points
ne=size(e2h,1); lnv=[(np2h+1):(np2h+ne)];
A=sparse(e2h(:,1),e2h(:,2),lnv,np2h,np2h); A=A+A.’;
mp1=zeros(nt2h,1); mp2=mp1; mp3=mp1;
for i=1:nt2h
mp1(i)=A(t2h(i,1),t2h(i,2));
mp2(i)=A(t2h(i,2),t2h(i,3));
mp3(i)=A(t2h(i,3),t2h(i,1));
end
% New triangles
th=zeros(4*nt2h,3);
th(1:nt2h,:)=[t2h(:,1) mp1 mp3];
th((nt2h+1):2*nt2h,:)=[mp1 t2h(:,2) mp2];
th((2*nt2h+1):3*nt2h,:)=[mp2 t2h(:,3) mp3];
th((3*nt2h+1):4*nt2h,:)=[mp1 mp2 mp3];
if (nargin==2)
return
end
% Boundary nodes
ltc=find(ref2h(t2h(:,1))==1 & ref2h(t2h(:,2))==1 & ref2h(t2h(:,3))==1);
ntc=length(ltc);
if (ntc==0)
ibc=find(ref2h(e2h(:,1))==1 & ref2h(e2h(:,2))==1);
refe=zeros(ne,1); refe(ibc)=1; refh=[ref2h;refe];
else % Corner triangle without internal node
ref=ref2h;
d2h=full(sparse(e2h(:,1),1,1,np2h,1)+sparse(e2h(:,2),1,1,np2h,1));
for i=1:ntc
i1=t2h(ltc(i),1); i2=t2h(ltc(i),2); i3=t2h(ltc(i),3);
if (d2h(i1)==2)
ref([i2;i3])=2;
elseif (d2h(i2)==2)
ref([i3;i1])=2;
else
ref([i1;i2])=2;
end
end
ib1=find(ref(e2h(:,1))>=1 & ref(e2h(:,2))>=1);
ib2=find(ref(e2h(:,1))==2 & ref(e2h(:,2))==2);
ibc=setdiff(ib1,ib2); refe=zeros(ne,1); refe(ibc)=1;
refh=[ref2h;refe];
end
References
[1] Alberty J., Carstensen C. and Funken S.A. Remarks around 50 lines of matlab:
short finite element implementation. Numer. Algorithms, 20:117–137, 1999.
REFERENCES 19
[2] Alberty J., Carstensen C., Funken S.A. and Klose R. Matlab implementation
of the finite element method in elasticity. Computing, 69:239–263, 2002.
[3] Cahouet J. and Chabard J. P. . Some fast 3-D solvers for the generalized Stokes
problem. Internat. J. Numer. Methods Fluids, 8:269–295, 1988.
[4] Glowinski R. Numerical methods for fluids (part 3). In Ciarlet P.G. and Li-
ons J.L., editors, Numerical Methods for Fluids (Part 3), volume IX of Handbook of
Numerical Analysis, pages 3–1074. North-Holland, Amsterdam, 2003.
[6] Persson P.-O. and Strang G. A simple mesh generator in Matlab. SIAM Rev.,
42:329–345, 2004.