Finite element method, Matlab implementation

Similar documents
Contents. I The Basic Framework for Stationary Problems 1

Puffin User Manual. March 1, Johan Hoffman and Anders Logg.

The numerical simulation of complex PDE problems. A numerical simulation project The finite element method for solving a boundary-value problem in R 2

AMS527: Numerical Analysis II

1 Exercise: Heat equation in 2-D with FE

1. Represent each of these relations on {1, 2, 3} with a matrix (with the elements of this set listed in increasing order).

Lab - Introduction to Finite Element Methods and MATLAB s PDEtoolbox

Real-Time Shape Editing using Radial Basis Functions

AMS526: Numerical Analysis I (Numerical Linear Algebra)

Chapter 8. Computer Implementation of 2D, Incompressible N-S Solver

AMS526: Numerical Analysis I (Numerical Linear Algebra)

Finite Element Implementation

Lecture 23: Starting to put it all together #2... More 2-Point Boundary value problems

Microprocessor Thermal Analysis using the Finite Element Method

INTRODUCTION TO MATLAB (MATrix LABoratory): INTUITIVE APPROACH

Uppsala University Department of Information technology. Hands-on 1: Ill-conditioning = x 2

Basic programming with Elmer

Using Periodic Boundary Conditions

Computational Fluid Dynamics - Incompressible Flows

COMSOL Model Report. 1. Table of Contents. 2. Model Properties. 3. Constants

Automated Finite Element Computations in the FEniCS Framework using GPUs

Computational Methods CMSC/AMSC/MAPL 460. Vectors, Matrices, Linear Systems, LU Decomposition, Ramani Duraiswami, Dept. of Computer Science

High Performance Computing: Tools and Applications

Transfinite Interpolation Based Analysis

Math background. 2D Geometric Transformations. Implicit representations. Explicit representations. Read: CS 4620 Lecture 6

Techniques for Optimizing FEM/MoM Codes

THE MORTAR FINITE ELEMENT METHOD IN 2D: IMPLEMENTATION IN MATLAB

Geometric Transformations

Documentation for Numerical Derivative on Discontinuous Galerkin Space

Numerical Methods to Solve 2-D and 3-D Elliptic Partial Differential Equations Using Matlab on the Cluster maya

Image Warping, Linear Algebra CIS581

Isoparametric Constant Strain Triangle, CST

(Sparse) Linear Solvers

Finite Element Convergence for Time-Dependent PDEs with a Point Source in COMSOL 4.2

Finite Element Analysis Prof. Dr. B. N. Rao Department of Civil Engineering Indian Institute of Technology, Madras. Lecture - 36

(Sparse) Linear Solvers

3D Geometry and Camera Calibration

Assignment 4: Mesh Parametrization

PROGRAMMING OF MULTIGRID METHODS

Assignment in The Finite Element Method, 2017

Matlab Plane Stress Example

Sparse Matrices. sparse many elements are zero dense few elements are zero

1 Exercise: 1-D heat conduction with finite elements

Elmer Programmer s Tutorial

Haar Wavelet Image Compression

CHAPTER 5 NUMERICAL INTEGRATION METHODS OVER N- DIMENSIONAL REGIONS USING GENERALIZED GAUSSIAN QUADRATURE

EFFICIENT SOLVER FOR LINEAR ALGEBRAIC EQUATIONS ON PARALLEL ARCHITECTURE USING MPI

Image warping , , Computational Photography Fall 2017, Lecture 10

10/26/ Solving Systems of Linear Equations Using Matrices. Objectives. Matrices

Basic Programming with Elmer Mikko Lyly Spring 2010

ECE Lesson Plan - Class 1 Fall, 2001

Linear Algebra and Image Processing: Additional Theory regarding Computer Graphics and Image Processing not covered by David C.

Numerical Methods for PDEs : Video 9: 2D Finite Difference February 14, Equations / 29

Graphics Pipeline 2D Geometric Transformations

Finite Math - J-term Homework. Section Inverse of a Square Matrix

Introduction: Objectives:

Sparse matrices, graphs, and tree elimination

Netgen/NGSolve Tutorial Part 3 - Programming with Netgen/NGSolve

Quick Start Guide to midas NFX

High Performance Computing Programming Paradigms and Scalability Part 6: Examples of Parallel Algorithms

Netgen/NGSolve Tutorial Part 3 - Programming with Netgen/NGSolve

What is Multigrid? They have been extended to solve a wide variety of other problems, linear and nonlinear.

Solid and shell elements

3D Transformations. CS 4620 Lecture 10. Cornell CS4620 Fall 2014 Lecture Steve Marschner (with previous instructors James/Bala)

Today. Today. Introduction. Matrices. Matrices. Computergrafik. Transformations & matrices Introduction Matrices

Multiple View Geometry in Computer Vision

Computer Graphics with OpenGL ES (J. Han) Chapter IV Spaces and Transforms

Def De orma f tion orma Disney/Pixar

How TMG Uses Elements and Nodes

MATH 5520 Basics of MATLAB

ME 582 Handout 11 1D Unsteady Code and Sample Input File

A High-Order Accurate Unstructured GMRES Solver for Poisson s Equation

Finite Element Methods for the Poisson Equation and its Applications

XPM 2D Transformations Week 2, Lecture 3

Image Warping. Computational Photography Derek Hoiem, University of Illinois 09/28/17. Photo by Sean Carroll

Parallel algorithms for Scientific Computing May 28, Hands-on and assignment solving numerical PDEs: experience with PETSc, deal.

Structure from Motion

NIA CFD Seminar, October 4, 2011 Hyperbolic Seminar, NASA Langley, October 17, 2011

Parallel Performance Studies for COMSOL Multiphysics Using Scripting and Batch Processing

Computer Vision CSCI-GA Assignment 1.

Ch 09 Multidimensional arrays & Linear Systems. Andrea Mignone Physics Department, University of Torino AA

Robot Mapping. Least Squares Approach to SLAM. Cyrill Stachniss

Graphbased. Kalman filter. Particle filter. Three Main SLAM Paradigms. Robot Mapping. Least Squares Approach to SLAM. Least Squares in General

Digests from his work is presented in this chapter partly rewritten/restructured

Lecture 3.2 Methods for Structured Mesh Generation

Finite element methods in scientific computing. Wolfgang Bangerth, Texas A&M University

Chapter 4. Matrix and Vector Operations

Masters Projects in Scientific Computing. By Jan Nordström

Vector Algebra Transformations. Lecture 4

TUTORIAL 1 Introduction to Matrix Calculation using MATLAB TUTORIAL 1 INTRODUCTION TO MATRIX CALCULATION USING MATLAB

Single-view 3D Reconstruction

XPM 2D Transformations Week 2, Lecture 3

Topology Optimization and 3D Printing of the MBB Structure Using the 3D SIMP Method

Geometric Modeling in Graphics

Revision of the SolidWorks Variable Pressure Simulation Tutorial J.E. Akin, Rice University, Mechanical Engineering. Introduction

Accelerating Finite Element Analysis in MATLAB with Parallel Computing

Numerical Algorithms

ANSYS Element. elearning. Peter Barrett October CAE Associates Inc. and ANSYS Inc. All rights reserved.

Contents. F10: Parallel Sparse Matrix Computations. Parallel algorithms for sparse systems Ax = b. Discretized domain a metal sheet

0_PreCNotes17 18.notebook May 16, Chapter 12

Transcription:

TIES594 PDE-solvers Lecture 6, 2016 Olli Mali Finite element method, Matlab implementation Main program The main program is the actual finite element solver for the Poisson problem. In general, a finite element solver includes the following typical steps: 1. Define the problem geometry and boundary conditions, mesh generation. In this example, we download a precomputed mesh. 2. Assemble the required global matrices and implement the boundary conditions 3. Solve the resulting linear system of equations 4. Visualize and/or post-process the approximate solution In more advanced finite element software packages the user interface varies, but these are the core features that the solver must have. In FreeFem++ and FEniCS finite element packages, the user is only required to insert the weak forms of equations. Our example code below does not consist any problem definition interface, but is restricted to solve the Poisson problem on a given mesh. Moreover, the homogeneous Dirichlet boundary condition is fixed on the entire boundary. Olli Mali 3.2.2015 Computes the finite element approximation of the Poisson problem. clear all Load a pregenerated mesh data, generated by Matlab pdetoolbox p 2 x N nodes of the mesh e 7 x E boundary edges of the mesh t 4 x M triangles of the mesh (bottom row extra label) load mesh_morko N = size(p,2);

Assemble global matrices and vector f = @(x) ones(1,size(x,2)); define right hand side ord = 3; order of integration quadrature [S,M,b] = AssembleGlobalMatrices(t,p,f,ord); Apply homogeneous Dirichlet boundary condition and solve bnodes2nodes = unique([e(1,:),e(2,:)]); locate boundary nodes dofs = setdiff(1:n,bnodes2nodes); create indeces of nonboundary nodes u_h = zeros(n,1); initialize solution to zeros u_h(dofs) = S(dofs,dofs) \ b(dofs); solve for nonzero values Plot triangular solution figure(1); clf; trisurf(t(1:3,:),p(1,:),p(2,:),u_h) Matrix assembly The heart of the finite element code is the matrix assembly. It is often even more time consuming than solving the respective linear system. function [St,Ma,b] = AssembleGlobalMatrices(t,p,f,ord) Assembles the global stifness matrix a_ji = (nabla psi_i, nabla psi_j) and the right hand side b_j = (f,psi_j). Olli Mali 20.1.2015 IN: t 3 x M M triangles p 2 x N N nodes (1st row x-coord, 2nd row y-coord) f fhandle handle to a function ord integration quadrature OUT: S N x N stiffness matrix K N x N mass matrix b N x 1 right hand side load First we define from the inputted mesh data the amount of nodes and elements. Note that we make no different treatment for the boundary nodes.

They are handled later, when defining the system of linear equations. M = size(t,2); N = size(p,2); NOF elements NOF nodes For the sake of performance we allocate the memory for the global matrices. This is practically necessary, since otherwise Matlab reconstructs matrices every time new elements are added. Moreover, the matrices are defined as sparse, i.e., zeros are not stored. Instead, matrix elements and their coordinates (in one representation or another) are stored. St = sparse(n,n); Ma = sparse(n,n); b = zeros(n,1); Initialize sparse matrices We obtain the integration points and weights on the reference element. They can be precomputed and dep only on the respective integration order. Compute quadrature on the reference element [iw,ip] = RefElemQuad(ord); The values of basis functions and their gradients are computed at the integration points on the reference element. Note that if one would change the basis functions, this would be the only place where the change had to be implemented (if the amount of local basis functions changes, then the size of local matrices has to be changed). Compute basis functions and their gradients values at the integration points of the reference element [basis_ip,grad_basis_ip] = basis_linear(ip); Initialize local matrices Local_M_matr = zeros(3,3); Local_S_matr = zeros(3,3); Local_load = zeros(3,1); Go trough all elements to constructs the inner products of global basis functions using the local basis functions (restrictions of global basis functions on an element). for k = 1:M go trough all elements

Construct the elementwise affine mapping using the coordinates of the nodes (corners of the triangle). Compute also the determinant and the inverse of the transpose required for the change of variables. corners of the k th element nodes = p(:,t(1:3,k)); Compute the affine mapping F(x) = C*x+cv and its determinant C = [ nodes(:,2)-nodes(:,1), nodes(:,3)-nodes(:,1) ]; cv = nodes(:,1); Cdet = C(1,1)*C(2,2)-C(1,2)*C(2,1); Compute the transpose of the inverse of C CinvT = (1/Cdet) * [ C(2,2), -C(2,1) ; -C(1,2), C(1,1) ]; Use the affine mapping to map the integration points on the reference element to the current element, i.e., compute the local integration points. Then compute the value of f at these points Map the integration points to local element ip_local = C * ip + kron(cv,ones(1,length(ip))); Calculate values at local points f_at_ip = f( ip_local ); Compute the inner products of local basis functions, products of the gradients, and the product with f, using the change of variables and the integration quadrature. Assemble the local matrices for i = 1 : 3 Local_load( i ) = (f_at_ip.* basis_ip(i,:)) * iw * Cdet; for j = 1 : 3 Local_M_matr(i,j) = basis_ip(i,:).*basis_ip(j,:)*iw *Cdet; Local_S_matr(i,j) = (CinvT * grad_basis_ip(:,1,i)) *... (CinvT * grad_basis_ip(:,1,j)) * Cdet; Selecting gradient value at first ip is enough since

gradient is constant at each element. Add the contributions of the local basis functions to the global matrix. In other words, the elementwise contributions of the inner products (integrals) of global basis functions are added to the corresponding element in the global matrix. Add the contribution of local matrices to the global. b( t(1:3,k) ) = b( t(1:3,k) ) + Local_load; St( t(1:3,k), t(1:3,k) ) = St( t(1:3,k), t(1:3,k) ) + Local_S_matr; Ma( t(1:3,k), t(1:3,k) ) = Ma( t(1:3,k), t(1:3,k) ) + Local_M_matr; Linear basis functions This function computes the value of the linear local basis functions on a reference triangle at given points. Moreover, it returns the respective values of gradients. function [value,d_value] = basis_linear(x) Evaluates the basis functions for 2D triangular linear element i function node 1 1-x-y (0,0) 2 x (1,0) 3 y (0,1) IN: x, (2 X M) Set of points OUT: value, (3 X M) values of basis functions on points x. d_value, (2 x 3 x M) values of gradients on points x

M = size(x,2); value = zeros( 3, M ); value(1,:) = ones(1,m) - x(1,:) - x(2,:); value(2,:) = x(1,:); value(3,:) = x(2,:); d_value=zeros(2,m,3); v = ones(1,m); d_value(:,:,1) = [-v ; -v]; d_value(:,:,2) = [ v ; zeros(1,m) ]; d_value(:,:,3) = [ zeros(1,m) ; v ]; Integration quadrature on a reference element function [ w,p ] = RefElemQuad( order ) Return symmetric Gaussian integration quadrature on the reference element (0,0)-(1,0-(0,1). Olli Mali 20.1.2015 IN: order integer order of the quadrature OUT: w 1XN weights of the quadrature p 2xN points of the quadrature switch order case 1 w = 1/2; p = [ 1/3 ; 1/3 ]; case 2 w = (1/6)*[1,1,1]; p = [ 0, 0.5, 0.5; 0.5, 0, 0.5]; case 3 w = (1/48)*[-27, 25, 25, 25]; p = [ 1/3, 2/15, 2/15, 11/15 ;... 1/3, 11/15, 2/15, 2/15 ]; case 4 w1 = 0.22338158967801;

w2 = 0.10995174365532; w = [ w1, w1, w1, w2, w2, w2 ]; a = 0.44594849091597; b = 0.10810301816807; c = 0.09157621350977; d = 0.81684757298046; p = [ a, a, b, c, c, d ; a, b, a, c, d, c]; case 5 w2 = 0.13239415278851; w3 = 0.12593918054483; w = [ 0.225, w2, w2, w2, w3, w3, w3 ]; a = 0.47014206410511; b = 0.05971587178977; c = 0.10128650732346; d = 0.79742698535309; p = [ 1/3, a, a, b, c, c, d;... 1/3 a, b, a, c, d, c]; otherwise error([ RefElemQuad: input parameter order wrongly defined.... Should be integer from 1 to 5. ]);