Sunteți pe pagina 1din 346
Third Edition, Version 3.11 http://www.freefem.org/ff++ F. Hecht Laboratoire Jacques-Louis Lions, Universite´ Pierre et

Third Edition, Version 3.11

F. Hecht

Edition, Version 3.11 http://www.freefem.org/ff++ F. Hecht Laboratoire Jacques-Louis Lions, Universite´ Pierre et

Laboratoire Jacques-Louis Lions, Universite´ Pierre et Marie Curie, Paris

FreeFem++

Third Edition, Version 3.11

Fred´ eric´

Hecht 1,4

In collaboration with:

Olivier Pironneau, mailto:olivier.pironneau@upmc.fr, http://www.ann.jussieu. fr/pironneau Olivier Pironneau is a professor of numerical analysis at the university of Paris VI and at LJLL. His scientific contributions are in numerical methods for fluids. He is a member of the Institut Universitaire de France and of the French Academy of Sciences

Jacques Morice, mailto:morice@ann.jussieu.fr. Jacaues Morice is a Post-Doct at LJLL. His doing is Thesis in University of Bordeaux I on fast multipole method (FMM). In this version, he do all three dimensions mesh generation and coupling with medit software.

Antoine Le Hyaric, mailto:lehyaric@ann.jussieu.fr, http://www.ann.jussieu. fr/ ˜ lehyaric/ Antoine Le Hyaric is a research engineer from the ”Centre National de la Recherche Scientifique” (CNRS) at LJLL . He is an expert in software engineering for sci- entific applications. He has applied his skills mainly to electromagnetics simulation, parallel computing and three-dimensional visualization.

Kohji Ohtsuka,mailto:ohtsuka@hkg.ac.jp, http://www.comfos.org/ Kohji Ohtsuka is a professor at the Hiroshima Kokusai Gakuin University, Japan and chairman of the World Scientific and Engineering academy and Society, Japan chapter. His research is in fracture dynamics, modeling and computing.

research is in fracture dynamics, modeling and computing. ´ Acknowledgments We are very grateful to l’
research is in fracture dynamics, modeling and computing. ´ Acknowledgments We are very grateful to l’

´

research is in fracture dynamics, modeling and computing. ´ Acknowledgments We are very grateful to l’

Acknowledgments We are very grateful to l’ Ecole Polytechnique (Palaiseau, France) for printing the second

edition of this manual (http://www.polytechnique.fr ), and to l’Agence Nationale de la Recherche (Paris, France) for funding of the extension of FreeFem++ to a parallel tridimensional version (http:

//www.agence-nationale-recherche.fr) Ref´ erence´ : ANR-07-CIS7-002-01.

iv

Contents

1 Introduction

 

1

1.1 Installation

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

2

 

1.1.1 For everyone: .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

2

1.1.2 For the pros: Installation from sources .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

3

1.2 How to use FreeFem++

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

6

1.3 Environment variables, and the init file

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

8

1.4

History

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

9

2 Getting Started

 

11

 

2.0.1 FEM by FreeFem++ : how does it work?

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

12

2.0.2 Some Features of FreeFem++

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

16

2.1

The Development Cycle: Edit–Run/Visualize–Revise

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

16

3 Learning by Examples

 

19

3.1 Membranes

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

19

3.2 Heat Exchanger

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

23

3.3 Acoustics

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

26

3.4 Thermal Conduction

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

27

 

3.4.1 Axisymmetry: 3D Rod with circular section .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

28

3.4.2 A Nonlinear Problem : Radiation

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

29

3.5 Irrotational Fan Blade Flow and Thermal eects .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

30

 

3.5.1

Heat Convection around the airfoil

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

31

3.6 Pure Convection : The Rotating Hill

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

32

3.7 A Projection Algorithm for the Navier-Stokes equations

.

.

.

.

.

.

.

.

.

.

.

.

.

.

36

3.8 The System of elasticity .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

38

3.9 The System of Stokes for Fluids

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

40

3.10 A Large Fluid Problem

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

41

3.11 An Example with Complex Numbers .

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

45

3.12 Optimal Control .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

46

3.13 A Flow with Shocks .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

48

3.14 Classification of the equations

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

50

4 Syntax

 

53

4.1 Data Types

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

53

4.2 List of major types

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

54

4.3 Global Variables .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

55

4.4 System Commands

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

56

 

i

ii

CONTENTS

4.5 Arithmetics

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

56

4.6 Functions of one Variable

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

59

4.7 Functions of two Variables

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

60

4.7.1

Formula .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

60

4.7.2

FE-functions

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

61

4.8 Arrays .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

62

4.8.1

Arrays with two integer indices versus matrices .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

67

4.8.2

Matrix construction and setting

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

68

4.8.3

Matrix Operations

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

69

Other arrays . 4.9 .

.

4.10 Input/Output .

4.8.4

Loops

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

73

74

75

. Script arguments .

.

.

4.10.1

4.11 preprocessor .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

76

76

4.12 Exception handling

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

78

5

Mesh Generation

81

5.1 Commands for Mesh Generation

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

81

5.1.1 Square

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

81

5.1.2 Border

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

82

5.1.3 Data Structures and Read/Write Statements for a Mesh

.

.

.

.

.

.

.

.

.

.

.

85

5.1.4 Mesh Connectivity

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

87

5.1.5 The keyword ”triangulate”

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

90

5.2 Boundary FEM Spaces Built as Empty Meshes

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

91

5.3 Remeshing

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

92

5.3.1

Movemesh

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

92

5.4 Regular Triangulation: hTriangle .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

94

5.5 Adaptmesh

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

94

5.6 Trunc

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

98

5.7 Splitmesh

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

99

5.8 Meshing Examples

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 100

5.9 How to change the label of elements and border elements of a mesh in FreeFem++ ?105

5.10 Mesh in three dimensions .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 106

5.10.1 Read/Write Statements for a Mesh in 3D

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 106

5.10.2 TeGen: A tetrahedral mesh generator

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 106

5.10.3 Reconstruct/Refine a three dimensional mesh with TetGen

.

.

.

.

.

.

.

.

. 111

5.10.4 Moving mesh in three dimensions

 

.

.

.

.

.

.

.

.

.

.