+ All Categories
Home > Documents > freefem++doc

freefem++doc

Date post: 24-Nov-2014
Category:
Upload: firas-abed-el-nabi
View: 180 times
Download: 4 times
Share this document with a friend
Popular Tags:

If you can't read please download the document

Transcript

Third Edition, Version 3.11-1http://www.freefem.org/ff++F. Hecht,O. PironneauA. Le Hyaric, K. OhtsukaLaboratoire Jacques-Louis Lions, Universit e Pierre et Marie Curie, ParisFreeFem++Third Edition, Version 3.11-1http://www.freefem.org/ff++Fr ed eric Hecht1,4mailto:[email protected]://www.ann.jussieu.fr/hechtIn collaboration with: Olivier Pironneau, mailto:[email protected], http://www.ann.jussieu.fr/pironneau Olivier Pironneau is a professor of numerical analysis at the university ofParis VI and at LJLL. His scientic contributions are in numerical methods for uids. He isa member of the Institut Universitaire de France and of the French Academy of Sciences Jacques Morice, mailto:[email protected]. Jacaues Morice is a Post-Doctat LJLL. His doing is Thesis in University of Bordeaux I on fast multipole method (FMM). Inthis version, he do all three dimensions mesh generation and coupling with medit software. Antoine Le Hyaric, mailto:[email protected], http://www.ann.jussieu.fr/lehyaric/ Antoine Le Hyaric is a research engineer from the Centre National de laRecherche Scientique (CNRS) at LJLL . He is an expert in software engineering for sci-entic applications. He has applied his skills mainly to electromagnetics simulation, parallelcomputing and three-dimensional visualization. KohjiOhtsuka,mailto:[email protected], http://www.comfos.org/KohjiOhtsuka is a professor at the Hiroshima Kokusai Gakuin University, Japan and chairman ofthe World Scientic and Engineering academy and Society, Japan chapter. His research is infracture dynamics, modeling and computing.Acknowledgments We are very grateful to lEcole Polytechnique (Palaiseau, France) for printing the secondedition of this manual (http://www.polytechnique.fr ), and to lAgence Nationale de la Recherche(Paris, France)forfundingoftheextensionof FreeFem++toaparalleltridimensionalversion(http://www.agence-nationale-recherche.fr) R ef erence : ANR-07-CIS7-002-01.ivContents1 Introduction 11.1 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.1.1 For everyone: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.1.2 For the pros: Installation from sources. . . . . . . . . . . . . . . . . . . . 31.2 How to use FreeFem++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81.3 Environment variables, and the init le. . . . . . . . . . . . . . . . . . . . . . . . 81.4 History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 Getting Started 112.0.1 FEM by FreeFem++: how does it work? . . . . . . . . . . . . . . . . . . 122.0.2 Some Features ofFreeFem++ . . . . . . . . . . . . . . . . . . . . . . . 162.1 The Development Cycle: EditRun/VisualizeRevise . . . . . . . . . . . . . . . . 163 Learning by Examples 193.1 Membranes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193.2 Heat Exchanger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243.3 Acoustics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263.4 Thermal Conduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283.4.1 Axisymmetry: 3D Rod with circular section . . . . . . . . . . . . . . . . . 293.4.2 A Nonlinear Problem : Radiation . . . . . . . . . . . . . . . . . . . . . . 303.5 Irrotational Fan Blade Flow and Thermal eects. . . . . . . . . . . . . . . . . . . 303.5.1 Heat Convection around the airfoil . . . . . . . . . . . . . . . . . . . . . . 323.6 Pure Convection : The Rotating Hill . . . . . . . . . . . . . . . . . . . . . . . . . 333.7 A Projection Algorithm for the Navier-Stokes equations . . . . . . . . . . . . . . 373.8 The System of elasticity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393.9 The System of Stokes for Fluids . . . . . . . . . . . . . . . . . . . . . . . . . . . 413.10 A Large Fluid Problem. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433.11 An Example with Complex Numbers . . . . . . . . . . . . . . . . . . . . . . . . . 463.12 Optimal Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 473.13 A Flow with Shocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493.14 Classication of the equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 514 Syntax 554.1 Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 554.2 List of major types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 564.3 Global Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 574.4 System Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58iii CONTENTS4.5 Arithmetics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 584.6 Functions of one Variable. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 614.7 Functions of two Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 634.7.1 Formula . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 634.7.2 FE-functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 634.8 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 644.8.1 Arrays with two integer indices versus matrices . . . . . . . . . . . . . . . 704.8.2 Matrix construction and setting . . . . . . . . . . . . . . . . . . . . . . . 714.8.3 Matrix Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 724.8.4 Other arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 764.9 Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 774.10 Input/Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 784.10.1 Script arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 794.11 preprocessor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 794.12 Exception handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 815 Mesh Generation 855.1 Commands for Mesh Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . 855.1.1 Square . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 855.1.2 Border . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 865.1.3 Data Structures and Read/Write Statements for a Mesh . . . . . . . . . . . 895.1.4 Mesh Connectivity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 915.1.5 The keyword triangulate . . . . . . . . . . . . . . . . . . . . . . . . . . 945.2 Boundary FEM Spaces Built as Empty Meshes . . . . . . . . . . . . . . . . . . . 955.3 Remeshing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 965.3.1 Movemesh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 965.4 Regular Triangulation:hTriangle . . . . . . . . . . . . . . . . . . . . . . . . . . 985.5 Adaptmesh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 985.6 Trunc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1035.7 Splitmesh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1045.8 Meshing Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1045.9 How to change the label of elements and border elements of a mesh in FreeFem++ ?1105.10 Mesh in three dimensions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1115.10.1 Read/Write Statements for a Mesh in 3D . . . . . . . . . . . . . . . . . . 1115.10.2 TeGen: A tetrahedral mesh generator . . . . . . . . . . . . . . . . . . . . 1115.10.3 Reconstruct/Rene a three dimensional mesh with TetGen . . . . . . . . . 1155.10.4 Moving mesh in three dimensions . . . . . . . . . . . . . . . . . . . . . . 1175.10.5 Layer mesh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1175.11 Meshing examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1225.11.1 Build a 3d mesh of a cube with a balloon . . . . . . . . . . . . . . . . . . 1245.12 The output solution formats .sol and .solb . . . . . . . . . . . . . . . . . . . . . . 1255.13 medit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1275.14 Mshmet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1305.15 FreeYams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1325.16 mmg3d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1345.17 A rst 3d isotope mesh adaptation process . . . . . . . . . . . . . . . . . . . . . . 137CONTENTS iii6 Finite Elements 1396.1 Use of fespace in 2d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1416.2 Use of fespace in 3d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1426.3 Lagrangian Finite Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1436.3.1 P0-element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1436.3.2 P1-element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1436.3.3 P2-element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1446.4 P1 Nonconforming Element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1456.5 Other FE-space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1466.6 Vector valued FE-function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1476.6.1 Raviart-Thomas element . . . . . . . . . . . . . . . . . . . . . . . . . . . 1476.7 A Fast Finite Element Interpolator . . . . . . . . . . . . . . . . . . . . . . . . . . 1496.8 Keywords: Problem and Solve . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1516.8.1 Weak form and Boundary Condition. . . . . . . . . . . . . . . . . . . . . 1516.9 Parameters aecting solve and problem . . . . . . . . . . . . . . . . . . . . . . 1536.10 Problem denition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1546.11 Numerical Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1556.12 Variational Form, Sparse Matrix, PDE Data Vector . . . . . . . . . . . . . . . . . 1586.13 Interpolation matrix. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1626.14 Finite elements connectivity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1637 Visualization 1657.1 Plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1657.2 link with gnuplot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1697.3 link with medit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1698 Algorithms 1718.1 conjugate Gradient/GMRES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1718.2 Optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1749 Mathematical Models 1759.1 Static Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1759.1.1 Soap Film . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1759.1.2 Electrostatics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1779.1.3 Aerodynamics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1799.1.4 Error estimation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1819.1.5 Periodic Boundary Conditions . . . . . . . . . . . . . . . . . . . . . . . . 1829.1.6 Poisson Problems with mixed boundary condition . . . . . . . . . . . . . . 1859.1.7 Poisson with mixte nite element . . . . . . . . . . . . . . . . . . . . . . 1879.1.8 Metric Adaptation and residual error indicator . . . . . . . . . . . . . . . . 1889.1.9 Adaptation using residual error indicator . . . . . . . . . . . . . . . . . . 1909.2 Elasticity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1929.2.1 Fracture Mechanics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1959.3 Nonlinear Static Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1999.3.1 Newton-Raphson algorithm . . . . . . . . . . . . . . . . . . . . . . . . . 2009.4 Eigenvalue Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2019.5 Evolution Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204iv CONTENTS9.5.1 Mathematical Theory on Time Dierence Approximations. . . . . . . . . . 2069.5.2 Convection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2089.5.3 2D Black-Scholes equation for an European Put option. . . . . . . . . . . 2109.6 Navier-Stokes Equation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2119.6.1 Stokes and Navier-Stokes . . . . . . . . . . . . . . . . . . . . . . . . . . 2119.6.2 Uzawa Algorithm and Conjugate Gradients . . . . . . . . . . . . . . . . . 2169.6.3 NSUzawaCahouetChabart.edp. . . . . . . . . . . . . . . . . . . . . . . . 2179.7 Variational inequality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2199.8 Domain decomposition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2219.8.1 Schwarz Overlap Scheme . . . . . . . . . . . . . . . . . . . . . . . . . . 2219.8.2 Schwarz non Overlap Scheme . . . . . . . . . . . . . . . . . . . . . . . . 2239.8.3 Schwarz-gc.edp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2259.9 Fluid/Structures Coupled Problem . . . . . . . . . . . . . . . . . . . . . . . . . . 2279.10 Transmission Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2299.11 Free Boundary Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2339.12 Non linear Elasticity (nolinear-elas.edp) . . . . . . . . . . . . . . . . . . . . . . . 2359.13 Compressible Neo-Hookean Materials: Computational Solutions . . . . . . . . . . 2399.13.1 Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2399.13.2 A Neo-Hookean Compressible Material . . . . . . . . . . . . . . . . . . . 2399.13.3 An Approach to Implementation in FreeFem++. . . . . . . . . . . . . . . 24010 MPI Parallel version 24310.1 MPI keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24310.2 MPI constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24310.3 MPI Constructor. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24310.4 MPI functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24410.5 MPI communicator operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24410.6 Schwarz example in parallel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24510.6.1 True parallel Schwarz example . . . . . . . . . . . . . . . . . . . . . . . . 24711Parallel sparse solvers 25311.1 Using parallel sparse solvers in FreeFem++ . . . . . . . . . . . . . . . . . . . . 25311.2 Sparse direct solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25611.2.1 MUMPS solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25611.2.2 SuperLU distributed solver. . . . . . . . . . . . . . . . . . . . . . . . . . 25911.2.3 Pastix solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26111.3 Parallel sparse iterative solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26211.3.1 pARMS solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26311.3.2 Interfacing with HIPS . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26511.3.3 Interfacing with HYPRE. . . . . . . . . . . . . . . . . . . . . . . . . . . 26911.3.4 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27211.4 Domain decomposition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27211.4.1 Communicators and groups . . . . . . . . . . . . . . . . . . . . . . . . . 27511.4.2 Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27611.4.3 Points to Points communicators . . . . . . . . . . . . . . . . . . . . . . . 27611.4.4 Global operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276CONTENTS v12Mesh Files 28112.1 File mesh data structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28112.2 bb File type for Store Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28212.3 BB File Type for Store Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . 28212.4 Metric File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28312.5 List of AM FMT, AMDBA Meshes . . . . . . . . . . . . . . . . . . . . . . . . . 28313Addition of a new nite element 28713.1 Some notations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28713.2 Which class to add?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288A Table of Notations 293A.1 Generalities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293A.2 Sets, Mappings, Matrices, Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . 293A.3 Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294A.4 Dierential Calculus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294A.5 Meshes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295A.6 Finite Element Spaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295B Grammar 297B.1 The bison grammar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297B.2 The Types of the languages, and cast . . . . . . . . . . . . . . . . . . . . . . . . . 301B.3 All the operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301C Dynamical link 307C.1 A rst example myfunction.cpp . . . . . . . . . . . . . . . . . . . . . . . . . . . 307C.2 Example: Discrete Fast Fourier Transform . . . . . . . . . . . . . . . . . . . . . 310C.3 Load Module for Dervieux P0-P1 Finite Volume Method . . . . . . . . . . . . . . 312C.4 More on Adding a new nite element . . . . . . . . . . . . . . . . . . . . . . . . 315C.5 Add a new sparse solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318D Keywords 329vi CONTENTSPrefaceFruit of a long maturing process, freefem, in its last avatar, FreeFem++, is a high level integrateddevelopment environment (IDE) for numerically solving partial dierential equations (PDE). It isthe ideal tool for teaching the nite element method but it is also perfect for research to quicklytest new ideas or multi-physics and complex applications.FreeFem++ has an advanced automatic mesh generator, capable of a posteriori mesh adaptation;it has a general purpose elliptic solver interfaced with fast algorithms such as the multi-frontalmethod UMFPACK, SuperLU . Hyperbolic and parabolic problems are solved by iterative algo-rithms prescribed by the user with the high level language ofFreeFem++. It has several triangularnite elements, including discontinuous elements. Finally everything is there in FreeFem++ to pre-pare research quality reports: color display online with zooming and other features and postscriptprintouts.This manual is meant for students at Master level, for researchers at any level, and for engineers(including nancial engineering) with some understanding of variational methods for partial dif-ferential equations.viiviii CONTENTSChapter 1IntroductionA partial dierential equation is a relation between a function of several variables and its (partial)derivatives. Many problems in physics, engineering, mathematics and even banking are modeledby one or several partial dierential equations.FreeFem++is a software to solve these equations numerically. As its name implies, it is a freesoftware (see the copyrights for full detail) based on the Finite Element Method; it is not a package,it is an integrated product with its own high level programming language. This software runs onall UNIX OS (with g++ 3.3 or later, and X11R6) , on Window 2000, NT, XP, Vista and 7 and onMacOS 10 (powerpc, intel)Moreover FreeFem++is highly adaptive. Many phenomena involve several coupled systems, forexample: uid-structure interactions, Lorentz forces for aluminium casting and ocean-atmosphereproblems are three such systems. These require dierent nite element approximations and poly-nomial degrees, possibly on dierent meshes. Some algorithms like Schwarz domain decompo-sition method also require data interpolation on multiple meshes within one program.FreeFem++can handle these diculties, i.e. arbitrary nite element spaces on arbitrary unstructured andadapted bi-dimensional meshes.The characteristics ofFreeFem++are:Problem description (real or complex valued) by their variational formulations, with accessto the internal vectors and matrices if needed.Multi-variables, multi-equations, bi-dimensionalandthree-dimensionalstaticortimede-pendent, linear or nonlinear coupled systems; however the user is required to describe theiterative procedures which reduce the problem to a set of linear problems.Easy geometric input by analytic description of boundaries by pieces; however this part isnot a CAD system; for instance when two boundaries intersect, the user must specify theintersection points.Automatic mesh generator, based on the Delaunay-Voronoi algorithm; the inner point den-sity is proportional to the density of points on the boundaries [7].12 CHAPTER 1. INTRODUCTIONMetric-based anisotropic mesh adaptation. The metric can be computed automatically fromthe Hessian of any FreeFem++function [9].High level user friendly typed input language with an algebra of analytic and nite elementfunctions.Multiple nite element meshes within one application with automatic interpolation of dataon dierent meshes and possible storage of the interpolation matrices.Alargevarietyoftriangularniteelements: linear, quadraticLagrangianelementsandmore, discontinuous P1 and Raviart-Thomas elements, elements of a non-scalar type, themini-element,. . . (but no quadrangles).ToolstodenediscontinuousGalerkinniteelementformulations P0, P1dc, P2dcandkeywords: jump, mean, intalledges.A large variety of linear direct and iterative solvers (LU, Cholesky, Crout, CG, GMRES,UMFPACK) and eigenvalue and eigenvector solvers.Near optimal execution speed (compared with compiled C++ implementations programmeddirectly).Online graphics, generation of ,.txt,.eps,.gnu, mesh les for further manipulations ofinput and output data.Many examples and tutorials: elliptic, parabolic and hyperbolic problems, Navier-Stokesows, elasticity, Fluid structure interactions, Schwarzs domain decomposition method, eigen-value problem, residual error indicator, ...A parallel version using mpi1.1 Installation1.1.1 For everyone:First open the following web pagehttp://www.freefem.org/ff++/And choose your platform: Linux, Windows, MacOS X, or go to the end of the page to get the fulllist of downloads.Remark 1: Binaries are available for Microsoft Windows, Apple Mac OS X and some Linuxsystems.Install by double click on the appropriate le.1.1. INSTALLATION 3Windows binaries install First download the windows installation executable, then double clickit. to install FreeFem++. In most cases just answer yes (or typr return) to all questions. Otherwisein the Additional Task windows, check the box Add application directory to your system pathyour system path . This is required otherwise the program ffglut.exe will not be found.By now you should have two new icons on your desktop: FreeFem++ (VERSION).exe the FreeFem++application. FreeFem++ (VERSION) Examples a link to the FreeFem++folder of examples.where (VERSION) is the version of the les (for example 3.3-0-P4).By default, the installed les are inC:\Programs Files\FreeFem++In this directory, you have all the .dll les and other applications: FreeFem++-nw.exe,ffglut.exe,... the FreeFem++application without graphic windows.The syntax for the command-line tools are the same as those of FreeFem.exe.MacOS X binaries install Download the MacOS X binary version le, extract all the les witha double click on the icon of the le, go the the directory and put the FreeFem+.app applicationin the /Applications directory. If you want a terminal access to FreeFem++just copy the leFreeFem++ in a directory of your $PATH shell environment variable.If you want to automatically launch theFreeFem++.app, double click on a.edp le icon. Un-der the nder pick a.edp in directoryexamples++-tutorial for example, select menuFile-> Get Info anchange Open with:(choose FreeFem++.app) and click on buttonchangeAll....Where to go from here An integrated environment calledFreeFem++-cs, written by AntoineLe Hyaric, is provided with FreeFem++. Unless you wish to prole now your own developmentenvironment, you may proceed to the next paragraph How to use FreeFem++.1.1.2 For the pros: Installation from sourcesThis section is for those who for some reason do not wish to use the binaries and hence need torecompile FreeFem++or install it from the source code:The documentation archive : The documentation is also open source; to regenerate it you needa LATEX environment capable of compiling a CVS archive; under MS-Windows you will have touse cygwinhttp://www.cygwin.comand under MacOS X we have used Apples Developer Tools Xcode and LATEX fromhttp://www.ctan.org/system/mac/texmac.4 CHAPTER 1. INTRODUCTIONThe C++ archive :FreeFem++must be compiled from the source archive, as indicated inhttp://www.freefem.org/ff++/index.htmTo extract les fromthe compressed archive freefem++-(VERSION).tar.gz to a directory calledfreefem++-(VERSION)enter the following commands in a shell window :tar zxvf freefem++-(VERSION).tar.gzcd freefem++-(VERSION)To compile and installFreeFem++, just follow theINSTALL andREADME les. The followingprograms are produced, depending on the system you are running :1. FreeFem++, standard version, with a graphical interface based on GLUT/OpenGL (use glutvisualization tool) or not just add -nw parameter.2. ffglut the visualization tools through a pipe of freefem++ (remark: ifglut is not in thesystem path, you will have no plot)3. FreeFem++-nw, postscript plot output only (batch version, no graphics windows via ffglut)4. FreeFem++-mpi, parallel version, postscript output only5. /Applications/FreeFem++.app, the Drag and Drop CoCoa MacOSX Application6. bamg , the bamg mesh generator7. cvmsh2 , a mesh le convertor8. drawbdmesh , a mesh le viewer9. ffmedit the freefem++ version of medit software (thanks to P. Frey)The FreeFem++ parameter command:Brochet-2: hecht$ FreeFem++Syntaxe:FreeFem++ [ -v verbosity ] [ -fglut filepath ] [ -glut command ] [ -nw] [ -f] filename-v verbosity : 0 -- 1000000 level of freefem output-fglut filepath : the file name of save all plots (replot with ffglut command )-glut command : change the command ffglut-gff command : change the command ffglut with space quotting-nowait : nowait at the end on window-wait : wait at the end on window-nw : no ffglut (=> no graphics windows)-ne : no edp script output-cd : Change directory to script dirwith default ffglut : ffglut1.1. INSTALLATION 5Remark 2In most cases you can set the level of output (verbosity) to valuenn by adding theparameters -v nn on the command line.As an installation test, under unix: go into the directory examples++-tutorial and run FreeFem++on the example script LaplaceP1.edp with the command :FreeFem++ LaplaceP1.edpIfyouareusingneditasyourtexteditor, doonetimenedit -import edp.nedittohavecoloring syntax for your .edp les.The syntax of tools FreeFem++,FreeFem++-nw on the command-line are FreeFem++ [-?] [-vnn] [-fglut file1] [-glut file2] [-f] edpfilepath where the or FreeFem++-nw -? [-vnn] [-fglut file1] [-glut file2] [-f] edpfilepath wherethe-? show the usage.-fglut filename to store all the data for graphic in le filename, and to replay do ffglut filename.-glut ffglutprogam to change the visualisator programs.-nw no call to glut-v nn set the level of verbosity to nn before execution of the script.if no le path then you get a dialog box to choose the edp le on windows systeme.The notation [] means optional.Link with other text editorsnotepad++at http://notepad-plus.sourceforge.net/uk/site.htmOpen Notepad++ and Enter F5In the new window enter the command FreeFem++ "$(FULL_CURRENT_PATH)"Click on Save, and enter FreeFem++ in the box Name, now choose the short cut keyto launch directly FreeFem++ (for example alt+shift+R)To add Color Syntax Compatible with FreeFem++ In Notepad++,In Menu "Parameters"->"Configuration of the Color Syntax" proceedas follows:In the list "Language" select C++Add edp in the eld "add ext"Select "INSTRUCTION WORD" in the list "Description" and in the eld "supplementary key word", cut and past the following list:P0P1P2P3P4P5P1dcP2dcP3dcP4dcP5dcRT0RT1RT2RT3RT4RT5macro plot int1d int2d solve movemesh adaptmesh trunc checkmovemesh on funcbuildmesh square Eigenvalue min max imag exec LinearCG NLCG Newton BFGSLinearGMRES catch try intalledges jump average mean load savemesh convectabs sin cos tan atan asin acos cotan sinh cosh tanh cotanh atanh asinh acosh powexp log log10 sqrt dx dy endl cout6 CHAPTER 1. INTRODUCTIONSelectTYPEWORDinthelistDescriptionand... supplementarykeyword, cut and past the following listmesh real fespace varf matrix problem string border complex ifstream ofstreamClick on Save & Close. Now nodepad++ is congured.CrimsonEditor availble at http://www.crimsoneditor.com/ and adapted as follows:Go to the Tools/Preferences/File association menu and add the .edp extension setIn the same panel in Tools/User Tools, add a FreeFem++ item (1st line) with the pathtofreefem++.exe on the second line and$(FilePath) and$(FileDir) on thirdand fourth lines. Tick the 8.3 box.for color syntax, extract le fromcrimson-freefem.zip and put les in the corre-sponding sub-folder of Crimson folder (C:\Program Files\Crimson Editor ).winedt for Windows : this is the best but it could be tricky to set up. Download it fromhttp://www.winedt.comthis is a multipurpose text editor with advanced features such as syntax coloring; a macrois available on www.freefem.org to localize winedt to FreeFem++without disturbing thewinedt functional mode for LateX, TeX, C, etc. However winedt is not free after the trialperiod.TeXnicCenterfor Windows: this is the easiest and will be the best once we nd a volunteer toprogram the color syntax. Download it fromhttp://www.texniccenter.org/It is also an editor for TeX/LaTeX. It has a tool menu which can be congured to launchFreeFem++programs as in:Select the Tools/Customize item which will bring up a dialog box.Select the Tools tab and create a new item: call it freefem.in the 3 lines below,1. search for FreeFem++.exe2. select Main le with further option then Full path and click also on the 8.3 box3. select main le full directory path with 8.3nedit on the Mac OS, Cygwin/Xfree and linux, to import the color syntax donedit -import edp.neditSmultronon the Mac, available at http://smultron.sourceforge.net. It comes ready withcolor syntax for .edp le. To teach it to launchFreeFem++les, do a command B (i.e.the menu Tools/Handle Command/new command) and create a command which does/usr/local/bin/FreeFem++-CoCoa %%p1.1. INSTALLATION 7Figure 1.1: Integrated environment for FreeFem++ development with Windows8 CHAPTER 1. INTRODUCTION1.2 How to use FreeFem++Under MacOS X with Graphic Interfaces To test an .edp le, just drag and drop the le iconon the MacOS application icon FreeFem++.app. You can also launch this application and use themenu:File Open.One of the best ways however on the Mac is to use a text editor like Smultron.app (see above).Figure 1.2: The 3 panels of the integrated environment built with theSmultron Editor withFreeFem++in action. The Tools menu has an item to launch FreeFem++by a Ctrl+1 command.In Terminal mode Choose the type of application fromFreeFem++, FreeFem++-nw, FreeFem++-mpi,. . . according to your needs. Add at least the path name; for exampleFreeFem++ your-edp-file-path1.3 Environment variables, and the init leFreeFem++ reads a users init le namedfreefem++.pref to initialize global variables: verbosity,includepath, loadpath.Remark 3Thevariableverbositychangesthelevelofinternalprinting(0, nothing(unlessthere are syntax errors), 1 few, 10 lots, etc. ...), the default value is 2.The include les are searched from theincludepath list and the load les are searched fromloadpath list.1.4. HISTORY 9The syntax of the le is:verbosity= 5loadpath += "/Library/FreeFem++/lib"loadpath += "/Users/hecht/Library/FreeFem++/lib"includepath += "/Library/FreeFem++/edp"includepath += "/Users/hecht/Library/FreeFem++/edp"# commentload += "funcTemplate"load += "myfunction"The possible paths for this le areunder unix and MacOs/etc/freefem++.pref$(HOME)/.freefem++.preffreefem++.prefunder windowsfreefem++.prefWe can also use shell environment variable to change verbosity and the search rule before the initles.export FF_VERBOSITY=50export FF_INCLUDEPATH="dir;;dir2"export FF_LOADPATH="dir;;dir3""Remark: theseparatorbetweendirectoriesmustbe;andnot:because:isusedunderWindows.Remark, to show the list of init offreefem++, doexport FF_VERBOSITY=100; ./FreeFem++-nw-- verbosity is set to 100insert init-files /etc/freefem++.pref $...1.4 HistoryTheprojecthasevolvedfromMacFem, PCfem, writteninPascal. TherstCversionleadtofreefem 3.4; it oered mesh adaptativity on a single mesh only.A thorough rewriting in C++ led tofreefem+ (freefem+ 1.2.10 was its last release), whichincluded interpolation over multiple meshes (functions dened on one mesh can be used on anyother mesh); this software is no longer maintained but still in use because it handles a problem10 CHAPTER 1. INTRODUCTIONdescription using the strong form of the PDEs.Implementing the interpolation from one unstruc-tured mesh to another was not easy because it had to be fast and non-diusive; for each point, onehad to nd the containing triangle. This is one of the basic problems of computational geometry(see Preparata & Shamos[18] for example). Doing it in a minimum number of operations was thechallenge. Our implementation is O(n log n) and based on a quadtree. This version also grew outof hand because of the evolution of the template syntax in C++.We have been working for a few years now on FreeFem++, entirely re-written again in C++ witha thorough usage of template and generic programming for coupled systems of unknown size atcompile time. Like all versions offreefem it has a high level user friendly input language whichis not too far from the mathematical writing of the problems.The freefem language allows for a quick specication of any partial dierential system of equa-tions. The language syntax ofFreeFem++is the result of a new design which makes use of theSTL [26],templates andbison for its implementation; more detail can be found in [12]. Theoutcome is a versatile software in which any new nite element can be included in a few hours; buta recompilation is then necessary. Therefore the library of nite elements available in FreeFem++will grow with the version number and with the number of users who program more new ele-ments. So far we have discontinuous P0 elements,linear P1 and quadratic P2 Lagrangian elements,discontinuous P1 and Raviart-Thomas elements and a few others like bubble elements.Chapter 2Getting StartedTo illustrate with an example, let us explain howFreeFem++solves Poissons equation: for agiven functionf (x, y), nd a function u(x, y) satisfying u(x, y) = f (x, y) for all (x, y) , (2.1)u(x, y) = 0 for all (x, y) on , . (2.2)Here is the boundary of the bounded open set R2and u =2ux2+2uy2.The following is aFreeFem++program which computes u whenf (x, y) =xy and is the unitdisk. The boundary C= isC= (x, y)| x = cos(t), y = sin(t), 0 t 2Note that in FreeFem++the domain is assumed to described by its boundary that is on the leftside of its boundary oriented by the parameter. As illustrated in Fig. 2.2, we can see the isovalueof u by using plot (see line 13 below).Figure 2.1: mesh Th by build(C(50)) Figure 2.2: isovalue by plot(u)Example 2.1// defining the boundary1:borderC(t=0,2*pi){x=cos(t);y=sin(t);}1112 CHAPTER 2. GETTING STARTED// the triangulated domain Th is on the left side of its boundary2:meshTh =buildmesh(C(50));// the finite element space defined over Th is called here Vh3;fespaceVh(Th,P1);4: Vh u,v; // defines u and v as piecewise-P1 continuous functions5:funcf= x*y; // definition of a called f function6:realcpu=clock(); // get the clock in second7:solvePoisson(u,v,solver=LU) = // defines the PDE8: int2d(Th)(dx(u)*dx(v) +dy(u)*dy(v)) // bilinear part9: -int2d(Th)( f*v) // right hand side10: +on(C,u=0) ; // Dirichlet boundary condition11:plot(u);12:cout


Recommended