⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 manual-full.tex

📁 FreeFem++可以生成高质量的有限元网格。可以用于流体力学
💻 TEX
📖 第 1 页 / 共 5 页
字号:
\begin{array}{rrrrrr}
0 &1  &1.2\times 10^{-16}& 0 & 1 & 1.2\times 10^{-16}
\end{array}
\right)^T\\
\texttt{A*f[]}&=&
\left(
\begin{array}{rrrrrr}
-1.25 &  -2.25 &  0.5   & 0 & 5\times 10^{29} & 10^{30}
\end{array}
\right)^T\quad (=A\{v\})\\
\texttt{A'*f[]}&=&
\left(
\begin{array}{rrrrrr}
-1.25 &  -2.25 &  0  & 0.25 & 5\times 10^{29} & 10^{30}
\end{array}
\right)^T\quad (=A^T\{v\})\\
\texttt{f[].*g[]}&=&
\left(
\begin{array}{rrrrrr}
0 & 0 & 0 & 0 & 0.5 & 1.2\times 10^{-16}
\end{array}
\right)^T\quad =(v_1w_1\quad\cdots\quad v_Mw_M)^T\\
\texttt{f[]./g[]}&=&
\left(
\begin{array}{rrrrrr}
-nan & 0  & 0  & -nan  & 0.5 & 8.1\times 10^{15}
\end{array}
\right)^T\quad =(v_1/w_1\,\cdots\, v_M/w_M)^T\\
\texttt{f[]'*g[]}&=&0.5\quad
(=\{v\}\{w\}^T=\{v\}\cdot\{w\})
\end{eqnarray*}
\end{example}
\begin{note}
The operators \verb|^-1| cannot create the matrix by themselves.
Indeed, the following occur errors
\bT
@matrix AAA = A^-1;
\eT
\end{note}

%%%  modif FH july 2005----
\subsection{Block matrix}
\bFF
  matrix A=[[A11,0,B1],[0,A11,0,B1],[B1',B2',0]];
  set(A,solver=UMFPACK); //  by default no solver is defined
  real[int] b=[b1[],b2[],b3[]];
  [b1[],b2[],b3[]]= A^-1*b;
\eFF
%%%  fin modif FH july 2005

\subsection{\setS{Modeling}--Edit--Run--Visualize--Revise}
\bigskip
\freefempp provide many examples and its documentation, so you can easily calculate
mathematical models by FEM (finite element method) and study them.
Explanations for these examples are given in this book. If you are a
beginner of FEM, you start from Quick Tour of
\freefempp. The numerical simulation of scientific problem will be done as follows.

\begin{description}
\item[Modeling:] Make a mathematical model describing scientific problems.
Mathematical modeling is a deep and fruitful one, with many important
implications for scientific problems
(refer to Chapter \ref{sec:MathModels}).

\item[Programming:] Translate the mathematical model to
\freefempp source code, which is easy because \freefempp
includes many clever techniques in FEM with mathematical writing.

\item[Run:] Next step is to run it to see if it works. If we provisionally
give the name of the source code to ``something.edp'', we can execute it by
the typing\newline
\newline
\texttt{\% freefem++ something.edp}

An important part in programming is to keep aware of collections of
programs that are available, and this manual contains many examples you
can use freely. So we hope you to run these examples and their
representing mathematical models, which are contained in the package in
\freefempp.

\item[Visualization:] The numerical calculation by FEM make huge data, so
the easy way to check the obtained result is their visualization. \freefempp
can display the mesh and the contour lines of obtained functions. If
you want to use these visualization after execution, you add the filename of
PostScript to the commands ``plot'' (see \refSec{Plot}).

\item[Debugging:] If the boolean value of ``wait'' is true (default is `false'), then
\freefempp will stop at the information in visual form.
Write the following, execute it and make a change the line
``\ttCC{@wait=@true}'' to ``\ttCC{@wait=@false}''.
\bT
@bool wait = true;  // set "true" if you want see each plotting
mesh Th = @square(10,10,[-1+2*x,-1+2*y]); // $]-1,1[^2$
@plot(Th);  // plot the mesh
@fespace Vh(Th,P2);
Vh f = @sin(pi*x)*@cos(pi*y);
plot(f,wait=wait);  // plot the function f
Vh g = @sin(@pi*x + @cos(@pi*y));
@plot(g,wait=wait);  // plot the function g
\eT
If there is a fatal error in your
source code, \freefempp will end and cause an error message to appear. In MS-Windows, \freefempp will open the message file by notepad.
For example, if you forget parenthesis as in
\bT
@mesh Th = @square(10,10;
@plot(Th);
\eT
then you will get the following message from \texttt{freefem++},
\bT
mesh Th = square(10,10;
 Error line number 0, in file xxxxxx.edp, before  token ;
parse error
Compile error : parse error
        line number :0, ;
 at exec line  0
error Compile error : parse error
        line number :0, ;
\eT
If you use the same symbol twice as in
\bT
@real aaa =1;
@real aaa;
\eT
then you will get the message
\bT
real aaa =1;
    1 : real aaa; The identifier aaa exist
\eT
Notice that the line number start from 0.
If you find that the program isn't doing what you want it
to do, then you check the line number and try to figure out
what's wrong.
We give two techniques; One is \emph{trace} by \ttCC{@plot}
for \emph{meshes} and (FE-)functions with \ttCC{@wait=@true},
and by \ttCC{@cout} for scalar, vectors and matrices.
Another is to \emph{comment out} by ``\ttCC{//}''.
If you find a doubtful line in your source code, you comment out
as follows,
\bT
@real aaa =1;
// real aaa;
\eT
\end{description}

\bigskip

\subsection{Installation}

There are binary packages available for Microsoft Windows and Apple
Mac OS. For all other platforms, \freefempp must be compiled and
installed from the source archive. This archive is available from:

\url{http://www.ann.jussieu.fr/~hecht/ftp/freefem/freefem++.tgz}.

 To
extract files from the compressed archive \texttt{freefem++.tgz} into
a directory called \texttt{freefem++-X.XX} (where X.XX is the version number)
enter the following commands in a shell window~:

\bFF
tar zxvf freefem++.tgz
cd freefem++-X.XX
\eFF

To compile and install \freefempp, just follow the \texttt{INSTALL}
and \texttt{README} files. The following programs are produced,
depending on the system you are running (Linux, Windows, MacOS)~:

\begin{enumerate}
\item \texttt{FreeFem++}, standard version, with a graphical interface
based on X11, Win32 or MacOS
\item \texttt{FreeFem++-nw}, postscript plot output only (batch version, no windows)
\item \texttt{FreeFem++-mpi}, parallel version, postscript output only
\item \texttt{FreeFem++-glx}, graphics using OpenGL and X11
\item \texttt{FreeFem++-cs}, integrated development environment
(please see chapter ``Graphical User Interface'' for more details).
\item \texttt{/Applications/FreeFem++.app}, Drag and Drop CoCoa MacOs
Application
\item \texttt{FreeFem++-CoCoa}, MacOS Shell script for MacOS OpenGL
version (MacOS 10.2 or better) (note: it uses
/Applications/FreeFem++.app)
\end{enumerate}

As an installation test, go into the directory
\texttt{examples++-tutorial} and run \freefempp on the example script
\texttt{LaplaceP1.edp} with the command~:

\bFF
FreeFem++ LaplaceP1.edp
\eFF

\textBlack
\section{Syntax}
\subsection{Data Types}
Basically \freefempp  is a \index{compiler} compiler,
  the language is typed, polymorphic and reentrant.
Every variable must be typed, declared in a  statement;
each statement separated
from the next by a semicolon `\texttt{;}'.
The language allows the manipulation of basic types
integers (\texttt{int}), reals (\texttt{real}), strings (\texttt{string}),
arrays (example: \texttt{real[int]}),
 bidimensional (2D) finite element meshes (\texttt{mesh}),
2D finite element spaces (\texttt{fespace}) , definition of functions
(\texttt{func}), arrays of
finite element functions (\texttt{func$[basic\_type]$}),
linear and bilinear operators, sparse matrices, vectors , etc. For instance

\bFF
  @int i,n=20;               //  $ i,n$ are integer.
  @real[@int] xx(n),yy(n);    //  two array of size n
  @for (i=0;i<=20;i++)       // which can be used in statements such as
   { xx[i]= cos(i*pi/10); yy[i]= sin(i*pi/10); }
\eFF
The life of a variable is the current block $\{\ldots \}$, except the \texttt{fespace} variable, and the in variables local to a block are destroyed at the end of the block as follows.
\begin{example}~~
\bT
@real r= 0.01;
@mesh Th=@square(10,10); // unit square mesh
@fespace Vh(Th,@P1);     // P1 lagrange finite  element space
Vh u = x+ exp(y);
@func f = z * x + r * log(y);
@plot(u,wait=true);
{  // new block
  @real r = 2; // not the same r
  @fespace Vh(Th,@P1);//  error because Vh is a global name
}  // end of block
//  here r back to 0.01
\eT
\end{example}
The type declarations are  compulsory in \freefempp  because it is easy
to make bugs in a language with many types. \index{variable} The
variable name is just an alphanumeric \index{alphanumeric} string, the
underscore character  ``\texttt{\_}'' is not allowed, because
it will be used as an operator in the future.\index{\_}

\subsection{List of major types}
\begin{description}
\item[bool]   is used for logical expression and flow-control.
\index{bool}\index{true}\index{false}
\item[int]
  declare an integer.
\item[string] declare the varible to store
a text enclosed within double quates, such as:
\bT
"This is a string in double quotes."
\eT
\index{string}
\item[real] declare the variable to store a number such as ``12.345''. \index{real}
\item[complex]  Complex numbers, such as
$1+2i,\, i=\sqrt{-1}$.
\bT
@complex a =  1@i, b = 2 + 3@i;
@cout << "a + b = " << a + b << @endl;
@cout << "a - b = " << a + b << @endl;
@cout << "a * b = " << a * b << @endl;
@cout << "a / b = " << a / b << @endl;
\eT
Here's the output;
\bT
a + b = (2,4)
a - b = (-2,-2)
a * b = (-3,2)
a / b = (0.230769,0.153846)
\eT
\item[ofstream]  make a output file and its functions.
\item[ifstream]   make a input file and its functions.

\item[real[int]]  declare a variable that store multiple
real numbers with integer index.
\index{array}
\bT
@real[@int] a(5);
a[0] = 1; a[1] = 2; a[2] = 3.3333333; a[3] = 4; a[4] = 5;
@cout << "a = " << a  << @endl;
\eT
This produces the output;
\bT
a = 5   :
  1       2     3.33333   4       5
\eT
\item[real[string]]  declare a variable that store multiple
real numbers with string index.
\item[string[string]]  declare a variable that store multiple
strings with string index.
\index{array}
\itemtt[func] define a function without argument,
if independent variables are \ttCC{x, y}.
For example
\bT
@func f=cos(x)+sin(y) ;
\eT
\index{func}
Remark the function's type is given by the expression's type.
The power of functions are given in \freefempp such as
\ttCC{x\^{}1}, \ttCC{y\^{}0.23}.

\itemtt[mesh]  \index{mesh}
create the triangulation, see \refSec{Mesh Generation}.
\itemtt[fespace]
define a new type of finite element space, see Section \refSec{Finite Elements}.
\itemtt[problem]  declare the weak form of a partial differential problem without solving. \index{problem}
\itemtt[solve]  declare a problem and solve it.\index{solve}
\itemtt[varf]   define a full variational form. \index{varf}
\itemtt[matrix] define a sparse matrix. \index{matrix}
\end{description}

\subsection{Global Variables}\label{sec:Global}
 The names \ttCC{x,y,z,label,region,P,N,nu\_triangle} are used to link
the language to the finite element tools:
\begin{description}
    \itemtt[x]  expresses $x$ coordinate of current point (real value) \index{x}
    \itemtt[y]  expresses $y$ coordinate  of current point (real value) \index{y}
    \itemtt[z]  expresses $z$ coordinate of current point (real value) \index{z}, but is reserved for future use.
\itemtt[label] show the label number of boundary if the  current point is
on a boundary, otherwise 0 (int value). \index{label}
    \item[region]   returns the region number of  the current point (x,y) (int value). \index{region}
\itemtt[P]  give the  current point  ($\R^{2}$ value. \index{P}).
By \texttt{P.x}, \texttt{P.y}, we can get the $x,\, y$ components of \texttt{P} .
Also \texttt{P.z} is reserved.
    \itemtt[N]  give the outward unit normal vector at the  current point is on the curve define by \texttt{border} ($\R^{3}$ value).
\texttt{N.x} and \texttt{N.y} are $x$ and $y$ components of the normal vector.
\texttt{N.z} is reserved. \index{N}.
    \itemtt[lenEdge] give the length of the current edge\index{lenEdge}\\
    \[
    \texttt{lenEdge} = |q^i-q^j|\quad \textrm{if the current edge is }[q^i,q^j]
    \]

    \itemtt[hTriangle] give the size of the current triangle \index{hTriangle}

    \itemtt[nuTriangle] give the index of the current triangle (integer).
    \index{nuTriangle}

    \itemtt[nuEdge]  give the index of the current edge in the triangle (integer).
    \index{nuEdge}

    \itemtt[nTonEdge] give the number of adjacent triangle of the current
    edge (integer ).\index{nTonEdge}

    \itemtt[area] give the area of the current triangle (real). \index{area}

\itemtt[cout]  is the standard output device (default is console).
On MS-Windows, the standard output is only to console, in this time.
  \Ostream
\itemtt[cin]  is the standard input device (default is keyboard). (\Istream).
On MS-Windows, this don't work.
\itemtt[endl] give the end of line in the input/output devices.
\itemtt[true]   means ``true'' in  \Bool\  value.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -