Difference between revisions of "FreeFem++/Example"

From ScientificComputing
Jump to: navigation, search
Line 1: Line 1:
 
As an example for using FreeFem++, we are going to solve a Poisson equation. For a given function <tt>f(x, y)</tt>, find a function <tt>u(x, y)</tt> satisfying
 
As an example for using FreeFem++, we are going to solve a Poisson equation. For a given function <tt>f(x, y)</tt>, find a function <tt>u(x, y)</tt> satisfying
  
<math> -\Delta u(x,y) = f(x,y) \,\forall\,  (x,y) \in \Omega</math>
+
<math>
+
\begin{align}
<math> u(x,y) = 0 \,\forall\, (x,y) \,\text{on}\, \partial\Omega</math>
+
-\Delta u(x,y) & = & f(x,y) & \quad\forall & (x,y) & \in \Omega \\
 +
u(x,y)         & = & 0     & \quad\forall & (x,y) & \,\text{on}\, \partial\Omega \\
 +
\end{align}
 +
</math>
  
Here ∂Ω is the boundary of the bounded open set
+
Here <math>\partial\Omega</math> is the boundary of the bounded open set
  
Ω ⊂ R^2 and ∆u = \tfrac{^2u}{∂x^2} + \tfrac{^2u∂y^2}
+
<math>\Omega \subset R^2 \text{and} \Delta u = \tfrac{\partial^2u}{\partial x^2} + \tfrac{\partial^2u}{\partial y^2}</math>
  
 
The following is a FreeFem++ program which computes u when f(x, y) = xy and Ω is the
 
The following is a FreeFem++ program which computes u when f(x, y) = xy and Ω is the

Revision as of 12:47, 6 December 2016

As an example for using FreeFem++, we are going to solve a Poisson equation. For a given function f(x, y), find a function u(x, y) satisfying


\begin{align}
-\Delta u(x,y)  & = & f(x,y) & \quad\forall & (x,y) & \in \Omega \\
u(x,y)          & = & 0      & \quad\forall & (x,y) & \,\text{on}\, \partial\Omega \\
\end{align}

Here \partial\Omega is the boundary of the bounded open set

\Omega \subset R^2 \text{and} \Delta u = \tfrac{\partial^2u}{\partial x^2} + \tfrac{\partial^2u}{\partial y^2}

The following is a FreeFem++ program which computes u when f(x, y) = xy and Ω is the unit disk. The boundary C = ∂Ω is C = {(x, y)| x = cos(t), y = sin(t), 0 ≤ t ≤ 2π}

[leonhard@euler06 ~]$ ls -ltr test.edp -rw-r--r-- 1 sfux T0000 283 Dec 6 12:56 test.edp [leonhard@euler06 ~]$ cat test.edp border C(t=0,2*pi){x=cos(t); y=sin(t);} mesh Th = buildmesh (C(50)); fespace Vh(Th,P1); Vh u,v; func f= x*y; real cpu=clock(); solve Poisson(u,v,solver=LU) = int2d(Th)(dx(u)*dx(v) + dy(u)*dy(v)) - int2d(Th)( f*v) + on(C,u=0) ; plot(u); cout << " CPU time = " << clock()-cpu << endl;