Middle East Technical University Department of Mechanical Engineering ME 43 Introction to Finite Element Analysis Chapter 2 Introction to FEM These notes are prepared by Dr. Cüneyt Sert http://www.me.metu.e.tr/people/cuneyt csert@metu.e.tr These notes are prepared with the hope to be useful to those who want to learn and teach FEM. You are free to use them. Please send feedbacks to the above email address. 2-
Disadvantages of Ritz and MWR They provide global solutions, i.e. a single approximate solution is valid over the whole problem domain. Difficult to capture complicated 2D and 3D solutions on complex domains. Not suitable to solve problems with multiple materials. Approximation function selection is problem (DE, BC, domain size) dependent. Difficult to automate. practically impossible for complex 2D and 3D geometries. See the problem below. NOT unique. y Top : Convection heat loss with h, T Materials with two different conctivities Left: 2 o C T(x, y) =? Bottom: Heat coming in Right: Insulated x 2-2
FEM vs. Ritz Finite Element Method (FEM) does NOT seek a global solution divides the problem domain into elements of simple shapes works with simple polynomial type approximate solutions over each element y Simple, low-order polynomial solution over each element T y x x FEM is similar to Ritz method uses weak form weight function selection is the same Simple shaped elements 2-3
Our First FE Solution e.g. Example 2. Solve the following problem using FEM d2 u 2 u = x2, < x < u =, u = This was already solved in Chapter. Exact solution is Exact solution of Example 2. u exact = sin x + 2sin( x) sin() + x 2 2 -. -.2 -.3 -.4 -.5.2.4.6.8 2-4
Our First FE Solution (Example 2.) (cont d) This solution will be very similar to previous Ritz solutions. In Chapter 3 we'll make it more algorithmic and easy to program. This will allow us to write our first FE code. Following 5 node (NN = 5) and 4 element (NE = 4) mesh (grid) will be used. e = e = 2 e = 3 e = 4 2 3 4 5 x h e Element Node Global node number This is a mesh of linear elements (elements that are defined by 2 nodes). This mesh is uniform, i.e. element length h e =.25 is constant. 2-5
Our First FE Solution (Example 2.) (cont d) With linear elements we ll obtain a piecewise linear solution u 2 u 3 u 4 u h : Approximate FE solution u = u 5 = x x 2 x 3 x 4 x 5 x e = e = 2 e = 3 e = 4 FE solution is linear over each linear element. This solution is C continuous, i.e. it is continuous at element interfaces, but its st derivative is not. u j s are the nodal unknown values. The ultimate task is to calculate them. u and u 5 are specified as EBCs. They are actually known. 2-6
Our First FE Solution (Example 2.) (cont d) FE solution of the previous slide can be written as NN NN : Number of nodes u h = u j φ j u j : Nodal unknowns j= φ j (x) : Approximation functions Same form as Ritz. But now unknowns are not just arbitrary numbers. They have a physical meaning, they are the unknown values (e.g. temperatures) at the mesh nodes. In FEM φ is not necessary. To have a piecewise linear u h each φ j should be linear. The above sum should provide nodal unknown values at the nodes. This is satisfied if the following Kronecker-Delta property holds φ j x i = if i = j if i j, i, j =,2,, NN 2-7
Our First FE Solution (Example 2.) (cont d) Following approximation functions will work φ e= e=2 e=3 e=4 x φ φ 2 φ 3 φ 4 φ 5 φ 2 e= e=2 e=3 e=4 x φ 3 These are Lagrange type approximation functions. φ 4 They make sure that the solution is continuous across elements, but not its first derivative. They have Kronecker-Delta property. φ 5 They have local support, i.e. nonzero only over at most two elements. 2-8
Our First FE Solution (Example 2.) (cont d) u 3 u 3 φ 3 u 4 φ 4 Each φ j is multiplied by u j u 4 u 2 φ 2 u 2 u = u 5 u φ u 5 φ 5 e= e=2 e=3 e=4 x NN u h = u j φ j j= u 3 u 4 u 2 u u 5 x 2-9
Our First FE Solution (Example 2.) (cont d) FEM uses weak form of the DE (same as Ritz) (u is used instead of u h for clarity) R = d2 u u + x2 2 wr = w d2 u 2 wu + wx2 x= dw IBP w = Weak form : dw wu + wx2 w = 2-
Our First FE Solution (Example 2.) (cont d) We need to write the weak form NN times with NN different w s. In Galerkin FEM (GFEM) weight function selection is the same as Ritz w i = φ i, i =,2,, NN st eqn (w = φ ) : dφ φ u + φ x 2 φ x= + φ x= = 2 nd eqn (w = φ 2 ) : dφ 2 φ 2u + φ 2 x 2 φ 2 x= + φ 2 x= = 3 rd eqn (w = φ 3 ) : dφ 3 φ 3u + φ 3 x 2 φ 3 x= + φ 3 x= = 4 th eqn (w = φ 4 ) : dφ 4 φ 4u + φ 4 x 2 φ 4 x= + φ 4 x= = 5 th eqn (w = φ 5 ) : dφ 5 φ 5u + φ 5 x 2 φ 5 x= + φ 5 x= = 2-
Our First FE Solution (Example 2.) (cont d) Integrals are easier to evaluate over each element separately. are nonzero only over certain elements For example 3 rd eqn s integral is I 3 = dφ 3 φ 3u + φ 3 x 2 2 4x 4x 3 4x 4x 2 which is nonzero only over e=2 and e=3 because φ 3 is nonzero only over e=2 and e=3. I 3 = + Ω 2 Ω 3 e= e=2 e=3 e=4 x w = φ 3 = 4x u = u j φ j = u 2 (2 4x) + u 3 (4x ) w = φ 3 = 3 4x u = u j φ j = u 3 (3 4x) + u 4 (4x 2) Simplified sum over e=2 Simplified sum over e=3 2-2
Our First FE Solution (Example 2.) (cont d) I 3 can be evaluated in MATLAB as syms x u u2 u3 u4 u5; Part of Example2_.m code % First calculate the part of the integral over the 2nd element. w = 4*x-; % w = Phi3 and it is equal to 4x- over e=2. dw = diff(w, x); u = u2*(2-4*x) + u3*(4*x-); % This is what u is over e=2 = diff(u, x); part = int(dw* - w*u + w*x^2, x,.25,.5); % Now calculate the part over the 3rd element. w = 3-4*x; % w = Phi3 and it is equal to 3-4x over e=3. dw = diff(w, x); u = u3*(3-4*x) + u4*(4*x-2); % This is what u is over e=3 = diff(u, x); part2 = int(dw* - w*u + w*x^2, x,.5,.75); % Add two parts to get the integral of the 3rd equation. I3 = part + part2 2-3
The result for I 3 is : Our First FE Solution (Example 2.) (cont d) Other integrals are calculated in Example2.v2.m MATLAB code (see the next slide). The resultant 5 equations are 47 2 97 24 97 24 47 6 97 24 97 24 u 2 + 47 6 u 3 97 24 u 4 + 25 384 97 24 47 6 97 24 97 24 47 6 97 24 97 24 47 2 u u 2 u 3 u 4 u 5 = 768 7 384 25 384 55 384 27 256 + [K] {u} {F} {Q} x= x= Q Q 5 2-4
Our First FE Solution (Example 2.) (cont d) syms x u u2 u3 u4 u5 Phi I; % Phi(i,j) is the i-th approx. funct. over element j Phi(,) = -4*x; Phi(2,) = 4*x; Phi(2,2) = 2-4*x; Phi(3,2) = 4*x-; Phi(3,3) = 3-4*x; Phi(4,3) = 4*x-2; Phi(4,4) = 4-4*x; Phi(5,4) = 4*x-3; Example2_v2.m code (2 nd & simpler version) coord = [,.25,.5,.75, ]; for i=:5 % Integral loop I(i) = ; % Initialize the i-th integral to zero. for e=:4 % Element loop w = Phi(i,e); dw = diff(w, x); u = u*phi(,e) + u2*phi(2,e) + u3*phi(3,e) + u4*phi(4,e) + u5*phi(5,e); = diff(u, x); I(i) = I(i) + int(dw* - w*u + w*x^2, x, coord(e), coord(e+)); end end 2-5
Our First FE Solution (Example 2.) (cont d) Stiffness matrix NN NN Nodal unknown vector NN K u = F + Q Force vector NN Boundary term vector NN This system has 5 equations for 5 unknowns. u and u 5 are known, but Q and Q 5 are unknown. As a rule, if the PV is known at a boundary, corresponding SV is unknown, and vice versa. Note that Q includes a minus sign, which can be thought as an indicator for boundary normal direction. At x =, boundary outward normal is in x direction Q = At x =, boundary outward normal is in +x direction Q 5 = + x= x= 2-6
Our First FE Solution (Example 2.) (cont d) In practice we first want to solve for the unknown u s, but not Q s. For this we apply rection to the NN NN system and drop the st and 5 th equations, because u and u 5 are known. K K 2 K 3 K 4 K 5 K 2 K 22 K 23 K 24 K 25 K 3 K 32 K 33 K 34 K 25 K 4 K 42 K 43 K 44 K 45 K 5 K 52 K 53 K 54 K 55 u u 2 u 3 u 4 u 5 = F F 2 F 3 F 4 F 5 + Q Q 2 Q 3 Q 4 Q 5 The reced system is 3x3 K 22 K 23 K 24 K 32 K 33 K 34 K 42 K 43 K 44 u 2 u 3 u 4 = F 2 K 2 u K 25 u 5 F 3 K 3 u K 35 u 5 F 4 K 4 u K 45 u 5 + Q 2 Q 3 Q 4 2-7
Our First FE Solution (Example 2.) (cont d) Reced system for this problem is 47 6 97 24 97 24 47 6 97 24 97 24 47 6 u 2 u 3 u 4 = 7 384 25 384 55 384 + Solving this system gives u 2 u 3 u 4 =.232.45.392 Because u = u 5 = Exact values are u 2 u 3 u 4 exact =.234.48.394 2-8
Our First FE Solution (Example 2.) (cont d) coord = [.25.5.75 ]; u = [ -.232 -.45 -.392 ]; plot(coord, u, 'o-b', 'LineWidth', 2) hold x = :.:; uexact = (sin(x) + 2*sin(-x)) / sin() + x.*x - 2; plot(x, uexact, 'r', 'LineWidth', 2) grid on -. FEM Exact -.2 -.3 4 element FE solution vs. exact solution -.4 -.5.25.5.75 2-9
Our First FE Solution (Example 2.) (cont d) Q and Q 5 values generally have physical meaning, such as heat flux or reaction force. After calculating PVs, these SVs can be calculated in two ways. First way : Use the st and 5 th eqns of slide 2-4 Q = 47 2 u 97 24 u 2 + 768 =.95 Good match Q 5 = 97 24 u 4 + 47 2 u 5 + 27 256 =.2639 Second way : Use the derivatives of the FE solution at the boundaries Q = h x= = u 2 u h e =.232.25 =.928 Q 5 = h x= = u 5 u 4 h e = (.392).25 =.568 No match Why? Which one is better? 2-2
Our First FE Solution (Example 2.) (cont d) FEM provides very good nodal values, but what about the first derivative? coord = [.25.5.75 ]; u = [ -.232 -.45 -.392 ]; for i = :4 end slope(i) = (u(i+)-u(i)) /.25; figure; hold for i = :4 end plot([coord(i) coord(i+)],... syms x; [slope(i) slope(i)],... '-b', 'LineWidth', 2) Exact = diff((sin(x) + 2*sin(-x)) / sin() + x.*x - 2, x); X = :.:; plot(x, subs(exact,x,x), 'r', 'LineWidth', 2) grid on.3.2. st derivative comparison -..2.4.6.8 2-2
Remarks About Our First FEM Solution The procere is not suitable to computer programming. Approximation function selection must be made mesh independent. Symbolic integration is costly and not readily available for many prog. languages. Numerical integration is used in FEM codes. For real problems non-uniform meshes are preferred. Generating a good mesh is not easy. Adaptive Mesh Refinement (AMR) is helpful here. u exact Larger elements (coarser mesh) in low gradient regions Smaller elements (finer mesh) in high gradient regions x 2-22
Remarks (cont d) 2D elements can be triangular or quadrilateral. In 3D they can be tetrahedral, triangular prism (wedge) or hexahedral (brick). Triangular Quadrilateral Tetrahedron Triangular prism Hexahedron (Pyramid) (Wedge) (Brick) 2-23
Remarks (cont d) In our first FE solution we used linear (2-node) elements. It is possible to use higher order elements, which make use of more nodes. When we use quadratic (3-node) elements we can have quadratic polynomial solutions over each element. The following sample solution makes use of 3 quadratic elements (NE = 3) with a total node number of 7 (NN = 7). u 6 u 5 u 2 u 3 u 4 u 7 u e= e=2 e=3 x 2-24
Remarks (cont d) Our first FE solution was piecewise continuous. It was continuous across element interfaces, however its first deriative was not. This is known as a C continuous solution, i.e. only the th derivative of the unknown (which is the unknown itself) is continuous. For 2 nd order DEs, the weak form contains first derivative of the unknown and the use of C continuous solution is enough. For higher order DEs, for example the 4 th order one used for beam bending, C continuity is not enough and a C continuous solution is necessary. FEM results in a sparse stiffness matrix, i.e. a matrix with lots of zero entries. This is e to the compact support property of the approximation functions. For 2D and especially for 3D problems this feature is important to decrease memory usage of the code. 2-25
Remarks (cont d) The structure of the final linear algebraic equation system depends on how we number the mesh nodes globally. When we do a different numbering, the final equation system does NOT change mathematically, however the [K] matrix changes. In certain linear system solution techniques [K] is stored as a banded matrix and bandwidth of [K] is tried to be minimized to decrease memory usage. Bandwith of K is directly related to how we number the mesh nodes. Commercial FE software use bandwidth rection algorithms to minimize the bandwidth of [K]. In the problem we solved, [K] turns out to be symmetric. This is a e to the solved DE and the use of GFEM. The following DE with the additional st derivative will not result in a symmetric [K]. d2 u 2 + u = x2 2-26
The DE we solved was linear. Remarks (cont d) For a nonlinear DE, such as the following one, an extra linearization step is necessary to obtain the system of linear algebraic equations. u d2 u u = x2 2 2-27