Mesh Mess

Domain Decomposition for Poisson equation in 1D

Posted in Domain Decomposition by Yi Zhang on 05/05/2011

It’s not really Poisson equation, just a second order ODE in that sense. But it serves a good example to demonstrate the idea of domain decomposition.

Using Dirichlet-Neumann method, one of the two subdomains gives out Neumann boundary condition and receives Dirichlet boundary data at the interface, and the other one does the opposite. The Mathematica modul would be somthing like this:

DNDecomp:   Main module;
DBCLaplace: linear FEM module for Dirichlet data ua at xa, and ub at xb;
MBCLaplace: linear FEM module for Mixed data ua at xa, and flux db at xb;
(xi,ui):    interface position and data;
theta:      relaxation coefficient to update ui in each iteration.
DNDecomp[xa_, ua_, xb_, ub_, xi_, ui0_, n1_, n2_, iter_, \[Theta]_] :=
Module[{ui, di, x1, u1, x2, u2, h1, h2, sol},
  f[t_] := 2;
  ui = ui0;
  h1 = (xi - xa)/n1; h2 = (xb - xi)/n2;
  sol = {};
  Do[{
    {x2, u2} = DBCLaplace[xi, ui, xb, ub, n2];
    di = (u2[[2]] - u2[[1]])/h2;
    {x1, u1} = MBCLaplace[xa, ua, xi, di, n1];
    ui = \[Theta] u1[[-1]] + (1 - \[Theta]) u2[[1]];
    AppendTo[sol, {{x1, u1}\[Transpose], {x2, u2}\[Transpose]}]},
   {iter}
   ];
  sol
  ]

In above example force function f=2 gives a parabolic exact solution. The effect of the relaxation coefficient \theta is obvious in plots below.

Above: theta=0.7, below: theta=0.5

Below is another example with exact solution u(x)=-x \sin(x).

Iteration = 6, theta = 0.5

Tagged with: ,

Three faces of FEM

Posted in FEM by Yi Zhang on 08/09/2010

Finite Element Method (FEM) acquires several interpretations through its developments over decades. Assuming we are solving a PDE of form

L(u)=0

where L is partial-differential operator, u=u(x) is unknown function. FEM could be interpreted in the following ways (let me know if you have extra answers):

  • Rayleigh-Ritz
  • Galerkin method
  • Method of Weighted Residuals (MWR)

The first one, Rayleigh-Ritz method, is actually how structure engineers were inspired to devise FEM. The connection of this method and FEM is the two way street of variational formulation of PDE, which gives the Euler equation of certain functional over u(x). The derivation is done through searching for the minimum of the functional (usually some form of energy ). Rayleigh-Ritz method addresses the PDE problem by assuming the form of u as

u(x)=\sum_i^N u_i \Phi_i(x)

then bringing this formulation into PDE’s functional formulation, in which u_i‘s are acquired by solving a minimization problem. Original Rayleigh-Ritz method adopts functions with global support as \Phi_i(x). A textbook example is the boundary value problem of a beam’s modes, in which we can assume \Phi(x) as sinusoidal functions. \Phi_i(x) are called trial functions.

In order to have a PDE’s variational formulation in a general way, and in the same time remove some regularity requirement of the solution, Galerkin method is used. The so called test function are the ones with expected regularity (usually infinitive). By the procedure of Galerkin method, test functions \Psi_i(x) are applied to L(u)=0 and the integral formulation is acquired. If L is linear, this integral formulation is the same as functional formulation in minimization problem by Rayleigh-Ritz method. Here we have introduced two sets of functions, trial functions which define the finite dimensional approximation of u(x), and test functions which defines how close (accurate) the PDE is solved. The name of “test” can be understood in the following way. How close a variable v is close to zero could be measured by test it with other variables:

(v,w)=0

where w is known variable used for testing, and ( , ) is proper inner product. Conceptually, the greater the variable domain consisting of w, the closer to zero v is. And if v can make every w satisfy above equation, it should be zero itself by definition.

So we can see, the space of test function \{\Psi_i\} defines the extension, and in turn, accuracy, the PDE L(u)=0 stands by having

(\Psi_i, L(u))=0

A subcategory of Galerkin method is Bubnov-Galerkin method, where test functions and trial functions are the same. Otherwise, it’s called Petrov-Galerkin method. Historically, trial function is also commonly referred as shape function.

Another abstraction of FEM is by MWR. Since all the numerical methods for solving PDE relies on moving from infinite dimensional solution spaces to finite ones, errors are introduced in all the methods. So instead of having L(u) equal to exact zero, u(x)‘s numerical approximation \tilde{u}(x) introduces residual R(x):

L(\tilde{u}(x))=R(x)

If numerical solution is in the form of trial function’s expansion, the coefficients (coordinates) u_i could be acquired by restricting R. In the light of above philosophy, R could be restricted as to be zero in some sense, specifically,

(R(x),\Psi_i(x))=0

for some \Psi_i and (\cdot,\cdot). This can be looked as putting weight on some locations defined by \Psi_i: the greater \Psi_i is on certain location, the more restricted R is there. By this \Psi_i‘s are also called weighted functions.

Though mathematically Galerkin method and MWR are in the same look, they are actually on different emphasis. In the former, we are specifically looking for integral form, with shifting regularity to test functions in mind, while in MWR we are focusing on minimizing residuals, and following integral form is just the math “trick” played on certain weight functions. In fact, by using different weight function in MWR, we can recover other numerical discretizations. Besides Bubnov/Petrov Galerkin methods, \Psi_i=\delta(x-x_i) gives collocation method, \Psi_i=1 within certain cell and 0 otherwise gives FVM, and \Psi_i=\partial R/\partial u_i gives least squares method.

Tagged with:

Log law at a smooth plate

Posted in FEM, Flows by Yi Zhang on 07/22/2010

Log-law is THE most important and elegant analytical result in turbulence, considering many others are dauntingly complicated,  though justified. What log law says is  the fact that for a turbulent flow over flat plate, there is this section of flow away from the wall, within the turbulent boundary layer,  in which the relation between the distance and mean flow velocity is simply of log function. This conclusion could be drawn by an asymptotic analysis matching outer flow and inner flow.   Any CFD trying tempted to address turbulence models should recover the “law of the wall“, among which log law is a part of, before moving forward to more advanced problems.

The delicacy of the modeling in this case is the boundary condition (shocking!) at the wall, because log law is only valid when y+ is approximately above 30 ( the other cap depends on Reynolds number ), and the boundary conditions there for unknown variables in turbulence models are generally not known a priori, where is all kinds of wall function come into play.

Channel Flow

Plot of CFD result against log law

Tagged with: ,

Linear shape function, mass matrix, and element volume

Posted in FEM, Flows by Yi Zhang on 04/22/2010


In unsteady CFD problem, under certain time integration scheme, L2 inner product of shape functions gives what so called mass matrix, i.e. the matrix with its entries in the form M_{ij}=\int_{\Omega}{N_i N_j}\,d{\Omega}, where N_i is shape function. When shape function is linear, there is a better way to demonstrate M_{ij} is proportional to local element volume (area) than trivially plugging in and calculating or using Gaussian integral. Assume in 2D triangular element ABC whose area is A^{ABC},  and N_i(x,y), i=1,2,3 stands for the shape function whose unit value is reached at A, B, C correspondingly.

If we interpret local mass entry M_{13}^{ABC}=(N_1, N_3) over element ABC shown above as the mass of a piece of wood splinter in the shape of tetrahedron A1-A-B-C, where N_1(x,y) is the thickness function on the element, while N_3(x,y) is the density function, then it’s not difficult to see that M_{13}=(N_1,N_3)=(N_2,N_3)=M_{23}, because they are both the mass of tetrahedron with the same volume and density distribution from bottom (A1-A-B or B1-A-B) to top (C). The next step is to show that the mass of tetrahedron C1-A-B-C (M_{33}) is the half of the total mass of the prism A1-B1-C1-A-B-C with the same density distribution. The argument is based on linearity, which allows us to assign a single parameter for above integrals. Set this single coordinate s as the line parameter from C to line A-B, i.e. s=0 on AB, s=1 at C. Then, for mass of prism and tetrahedron, we both have

mass =\int{L(s) H(s) D(s)}\,ds

where L\times H gives the area for cross section parallel to A1-A-B-B1 at s . H is the thickness of ABC, while D is the density distribution. We have

L\propto (1-s),\quad D\propto s,
and H=1 for prism, H\propto s for tetrahedron. Then we have

M_p\propto \int{(1-s) s}\,ds

M_{33}\propto \int{(1-s) s^2}\,ds

which proves

2 M_{33}=M_p=\frac{1}{3} A_{ABC}

Since M_{33}+M_{13}+M_{23} is nothing but the sum of the mass of three tetrahedrons, which is the mass of the prism. This sum is then \frac{1}{3}A_{ABC}. Using M_{13}=M_{23}, finally we have

M_{11}=M_{22}=M_{33}=\frac{1}{6}A_{ABC}

M_{12}=M_{13}=M_{23}=\frac{1}{12}A_{ABC}

Note: for 3D tetrahedron element, linear shape function gives similar relation, in this case, above ratio over the volume of a tetrahedron would be 1/10 and 1/20:

M_{11}=M_{22}=M_{33}=M_{44}=\frac{1}{10}V_{ABCD}

M_{12}=M_{13}=M_{14}=M_{23}=M_{24}=M_{34}=\frac{1}{20}V_{ABCD}

Tagged with: , ,

What’s the difference?

Posted in FEM by Yi Zhang on 01/04/2010

Today I was asked for a one-sentence comment of the difference between finite difference method and finite element method. What I came up was:

In finite difference method we approximate the differential expression, or the partial derivative, while in finite element method we approximate the space in which the solution lies.

Hopefully this shed some light on the issue.

Follow

Get every new post delivered to your Inbox.