在好例子网,分享、交流、成长!
您当前所在位置:首页Others 开发实例一般编程问题 → FreeFEM手册

FreeFEM手册

一般编程问题

下载此实例
  • 开发语言:Others
  • 实例大小:9.14M
  • 下载次数:5
  • 浏览次数:126
  • 发布时间:2022-04-13
  • 实例类别:一般编程问题
  • 发 布 人:TOHKA233
  • 文件格式:.pdf
  • 所需积分:2
 相关标签: freefem++ 实例 手册

实例介绍

【实例简介】FreeFEM手册

【实例截图】

【核心代码】

Contents
1 Introduction 13
1.1 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
1.1.1 For everyone: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
1.1.2 For the pros: Installation from sources . . . . . . . . . . . . . . . . . 15
1.2 How to use FreeFem . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
1.3 Environment variables, and the init file . . . . . . . . . . . . . . . . . . . . . 20
1.4 History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2 Getting Started 23
2.0.1 FEM by FreeFem : how does it work? . . . . . . . . . . . . . . . 24
2.0.2 Some Features of FreeFem . . . . . . . . . . . . . . . . . . . . . 29
2.1 The Development Cycle: Edit–Run/Visualize–Revise . . . . . . . . . . . . . 29
3 Learning by Examples 31
3.1 Membranes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
3.2 Heat Exchanger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
3.3 Acoustics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
3.4 Thermal Conduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
3.4.1 Axisymmetry: 3D Rod with circular section . . . . . . . . . . . . . . 41
3.4.2 A Nonlinear Problem : Radiation . . . . . . . . . . . . . . . . . . . . 42
3.5 Irrotational Fan Blade Flow and Thermal effects . . . . . . . . . . . . . . . . 42
3.5.1 Heat Convection around the airfoil . . . . . . . . . . . . . . . . . . . 44
3.6 Pure Convection : The Rotating Hill . . . . . . . . . . . . . . . . . . . . . . 45
3.7 The System of elasticity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
3.8 The System of Stokes for Fluids . . . . . . . . . . . . . . . . . . . . . . . . . 51
3.9 A Projection Algorithm for the Navier-Stokes equations . . . . . . . . . . . 52
3.10 Newton Method for the Steady Navier-Stokes equations . . . . . . . . . . . . 56
3.11 A Large Fluid Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
3.12 An Example with Complex Numbers . . . . . . . . . . . . . . . . . . . . . . 62
3.13 Optimal Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
3.14 A Flow with Shocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
3.15 Classification of the equations . . . . . . . . . . . . . . . . . . . . . . . . . . 67
4 Syntax 71
4.1 Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
4.2 List of major types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
4.3 Global Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
5
6 CONTENTS
4.4 System Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
4.5 Arithmetics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
4.6 string expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
4.7 Functions of one Variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
4.8 Functions of two Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
4.8.1 Formula . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
4.8.2 FE-functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
4.9 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
4.9.1 Arrays with two integer indices versus matrices . . . . . . . . . . . . 87
4.9.2 Matrix construction and setting . . . . . . . . . . . . . . . . . . . . . 88
4.9.3 Matrix Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
4.9.4 Other arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
4.10 Map arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
4.11 Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
4.12 Input/Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
4.12.1 Script arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
4.13 preprocessor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
4.14 Exception handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
5 Mesh Generation 103
5.1 Commands for Mesh Generation . . . . . . . . . . . . . . . . . . . . . . . . . 103
5.1.1 Square . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
5.1.2 Border . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
5.1.3 Multy Border . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
5.1.4 Data Structures and Read/Write Statements for a Mesh . . . . . . . 108
5.1.5 Mesh Connectivity . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
5.1.6 The keyword ”triangulate” . . . . . . . . . . . . . . . . . . . . . . . . 113
5.2 Boundary FEM Spaces Built as Empty Meshes . . . . . . . . . . . . . . . . 114
5.3 Remeshing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
5.3.1 Movemesh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
5.4 Regular Triangulation: hTriangle . . . . . . . . . . . . . . . . . . . . . . . 117
5.5 Adaptmesh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
5.6 Trunc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
5.7 Splitmesh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
5.8 Meshing Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
5.9 How to change the label of elements and border elements of a mesh . . . . . 128
5.10 Mesh in three dimensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
5.10.1 Read/Write Statements for a Mesh in 3D . . . . . . . . . . . . . . . . 130
5.10.2 TeGen: A tetrahedral mesh generator . . . . . . . . . . . . . . . . . 131
5.10.3 Reconstruct/Refine a three dimensional mesh with TetGen . . . . . . 135
5.10.4 Moving mesh in three dimensions . . . . . . . . . . . . . . . . . . . . 136
5.10.5 Layer mesh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
5.11 Meshing examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
5.11.1 Build a 3d mesh of a cube with a balloon . . . . . . . . . . . . . . . . 143
5.12 The output solution formats .sol and .solb . . . . . . . . . . . . . . . . . . . 145
5.13 medit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
5.14 Mshmet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
CONTENTS 7
5.15 FreeYams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
5.16 mmg3d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
5.17 A first 3d isotope mesh adaptation process . . . . . . . . . . . . . . . . . . . 156
5.18 Build a 2d mesh from a isoline . . . . . . . . . . . . . . . . . . . . . . . . . . 157
6 Finite Elements 161
6.1 Use of “fespace” in 2d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
6.2 Use of fespace in 3d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
6.3 Lagrangian Finite Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
6.3.1 P0-element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
6.3.2 P1-element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
6.3.3 P2-element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
6.4 P1 Nonconforming Element . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
6.5 Other FE-space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
6.6 Vector valued FE-function . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
6.6.1 Raviart-Thomas element . . . . . . . . . . . . . . . . . . . . . . . . . 171
6.7 A Fast Finite Element Interpolator . . . . . . . . . . . . . . . . . . . . . . . 173
6.8 Keywords: Problem and Solve . . . . . . . . . . . . . . . . . . . . . . . . . . 175
6.8.1 Weak form and Boundary Condition . . . . . . . . . . . . . . . . . . 176
6.9 Parameters affecting solve and problem . . . . . . . . . . . . . . . . . . . 177
6.10 Problem definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
6.11 Numerical Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
6.12 Variational Form, Sparse Matrix, PDE Data Vector . . . . . . . . . . . . . . 185
6.13 Interpolation matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
6.14 Finite elements connectivity . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
7 Visualization 193
7.1 Plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
7.2 link with gnuplot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
7.3 link with medit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
8 Algorithms and Optimization 201
8.1 conjugate Gradient/GMRES . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
8.2 Algorithms for Unconstrained Optimization . . . . . . . . . . . . . . . . . . 204
8.2.1 Example of utilization for BFGS or CMAES . . . . . . . . . . . . . . 204
8.3 IPOPT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
8.3.1 Short description of the algorithm . . . . . . . . . . . . . . . . . . . . 206
8.3.2 IPOPT in FreeFem . . . . . . . . . . . . . . . . . . . . . . . . . 207
8.4 Some short examples using IPOPT . . . . . . . . . . . . . . . . . . . . . . . 212
8.5 3D constrained minimal surface with IPOPT . . . . . . . . . . . . . . . . . . 214
8.5.1 Area and volume expressions . . . . . . . . . . . . . . . . . . . . . . . 214
8.5.2 Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
8.5.3 The problem and its script : . . . . . . . . . . . . . . . . . . . . . . . 215
8.6 The nlOpt optimizers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
8.7 Optimization with MPI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
8 CONTENTS
9 Mathematical Models 225
9.1 Static Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
9.1.1 Soap Film . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
9.1.2 Electrostatics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
9.1.3 Aerodynamics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
9.1.4 Error estimation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
9.1.5 Periodic Boundary Conditions . . . . . . . . . . . . . . . . . . . . . 232
9.1.6 Poisson Problems with mixed boundary condition . . . . . . . . . . . 235
9.1.7 Poisson with mixted finite element . . . . . . . . . . . . . . . . . . . 237
9.1.8 Metric Adaptation and residual error indicator . . . . . . . . . . . . . 238
9.1.9 Adaptation using residual error indicator . . . . . . . . . . . . . . . . 240
9.2 Elasticity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
9.2.1 Fracture Mechanics . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
9.3 Nonlinear Static Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
9.3.1 Newton-Raphson algorithm . . . . . . . . . . . . . . . . . . . . . . . 250
9.4 Eigenvalue Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
9.5 Evolution Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
9.5.1 Mathematical Theory on Time Difference Approximations. . . . . . . 256
9.5.2 Convection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
9.5.3 2D Black-Scholes equation for an European Put option . . . . . . . . 260
9.6 Navier-Stokes Equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
9.6.1 Stokes and Navier-Stokes . . . . . . . . . . . . . . . . . . . . . . . . . 262
9.6.2 Uzawa Algorithm and Conjugate Gradients . . . . . . . . . . . . . . . 267
9.6.3 NSUzawaCahouetChabart.edp . . . . . . . . . . . . . . . . . . . . . . 268
9.7 Variational inequality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
9.8 Domain decomposition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
9.8.1 Schwarz Overlap Scheme . . . . . . . . . . . . . . . . . . . . . . . . . 273
9.8.2 Schwarz non Overlap Scheme . . . . . . . . . . . . . . . . . . . . . . 274
9.8.3 Schwarz-gc.edp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276
9.9 Fluid/Structures Coupled Problem . . . . . . . . . . . . . . . . . . . . . . . 278
9.10 Transmission Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
9.11 Free Boundary Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284
9.12 Non linear Elasticity (nolinear-elas.edp) . . . . . . . . . . . . . . . . . . . . . 287
9.13 Compressible Neo-Hookean Materials: Computational Solutions . . . . . . . 290
9.13.1 Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
9.13.2 A Neo-Hookean Compressible Material . . . . . . . . . . . . . . . . . 291
9.13.3 An Approach to Implementation in FreeFem . . . . . . . . . . . 292
9.14 Whispering gallery modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293
9.14.1 Wave equation for the WGMs . . . . . . . . . . . . . . . . . . . . . . 293
9.15 Weak formulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294
9.15.1 A dielectric sphere example with FreeFem . . . . . . . . . . . . 294
10 MPI Parallel version 295
10.1 MPI keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
10.2 MPI constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
10.3 MPI Constructor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
10.4 MPI functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
CONTENTS 9
10.5 MPI communicator operator . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
10.6 Schwarz example in parallel . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
10.6.1 True parallel Schwarz example . . . . . . . . . . . . . . . . . . . . . . 299
11 Parallel sparse solvers 305
11.1 Using parallel sparse solvers in FreeFem . . . . . . . . . . . . . . . . . 305
11.2 Sparse direct solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308
11.2.1 MUMPS solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308
11.2.2 SuperLU distributed solver . . . . . . . . . . . . . . . . . . . . . . . . 311
11.2.3 Pastix solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
11.3 Parallel sparse iterative solver . . . . . . . . . . . . . . . . . . . . . . . . . . 315
11.3.1 pARMS solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315
11.3.2 Interfacing with HIPS . . . . . . . . . . . . . . . . . . . . . . . . . . 320
11.3.3 Interfacing with HYPRE . . . . . . . . . . . . . . . . . . . . . . . . . 322
11.3.4 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325
11.4 Domain decomposition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325
11.4.1 Communicators and groups . . . . . . . . . . . . . . . . . . . . . . . 328
11.4.2 Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329
11.4.3 Points to Points communicators . . . . . . . . . . . . . . . . . . . . . 329
11.4.4 Global operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329
12 Mesh Files 335
12.1 File mesh data structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335
12.2 bb File type for Store Solutions . . . . . . . . . . . . . . . . . . . . . . . . . 336
12.3 BB File Type for Store Solutions . . . . . . . . . . . . . . . . . . . . . . . . 336
12.4 Metric File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337
12.5 List of AM FMT, AMDBA Meshes . . . . . . . . . . . . . . . . . . . . . . . 337
13 Addition of a new finite element 341
13.1 Some notations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341
13.2 Which class to add? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342
A Table of Notations 347
A.1 Generalities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347
A.2 Sets, Mappings, Matrices, Vectors . . . . . . . . . . . . . . . . . . . . . . . . 347
A.3 Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348
A.4 Differential Calculus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348
A.5 Meshes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349
A.6 Finite Element Spaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349
B Grammar 351
B.1 The bison grammar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
B.2 The Types of the languages, and cast . . . . . . . . . . . . . . . . . . . . . . 355
B.3 All the operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355
10 CONTENTS
C Dynamical link 361
C.1 A first example myfunction.cpp . . . . . . . . . . . . . . . . . . . . . . . . . 361
C.2 Example: Discrete Fast Fourier Transform . . . . . . . . . . . . . . . . . . . 364
C.3 Load Module for Dervieux’ P0-P1 Finite Volume Method . . . . . . . . . . . 366
C.4 More on Adding a new finite element . . . . . . . . . . . . . . . . . . . . . . 369
C.5 Add a new sparse solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372
D Keywords 383

标签: freefem++ 实例 手册

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警