Difference between revisions of "FreeFem++/Example"

From ScientificComputing
Jump to: navigation, search
 
(7 intermediate revisions by the same user not shown)
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 <math>f(x, y)</math>, find a function <math>u(x, y)</math> satisfying
  
−∆u(x, y) = f(x, y) for all (x, y) ∈ Ω
+
<math>
u(x, y) = 0 for all (x, y) on ∂Ω
+
\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}
 +
</math>
  
Here ∂Ω is the boundary of the bounded open set
+
Here <math>\partial\Omega</math> is the boundary of the bounded open set
  
<math>Ω ⊂ R^2 and ∆u = \tfrac{^2u}{∂x^2} + \tfrac{^2u∂y^2}</math>
+
<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 <tt>FreeFem++</tt> program which computes <math>u</math> when <math>f(x, y) = xy</math> and <math>\Omega</math> is the
unit disk. The boundary C = ∂Ω is
+
unit disk. The boundary <math>C = \partial\Omega</math> is
C = {(x, y)| x = cos(t), y = sin(t), 0 ≤ t ≤ 2π}
 
  
[leonhard@euler06 ~]$ ls -ltr test.edp  
+
<math>C = {(x, y)| x = \cos(t)\,, y = \sin(t), 0 \le t \le 2\Pi}</math>
-rw-r--r-- 1 sfux T0000 283 Dec  6 12:56 test.edp
+
 
[leonhard@euler06 ~]$ cat test.edp  
+
[leonhard@euler06 ~]$ '''ls -ltr test.edp'''
border C(t=0,2*pi){x=cos(t); y=sin(t);}
+
-rw-r--r-- 1 leonhard T0000 283 Dec  6 12:56 test.edp
mesh Th = buildmesh (C(50));
+
[leonhard@euler06 ~]$ '''cat test.edp'''
fespace Vh(Th,P1);
+
border C(t=0,2*pi){x=cos(t); y=sin(t);}
Vh u,v;
+
mesh Th = buildmesh (C(50));
func f= x*y;
+
fespace Vh(Th,P1);
real cpu=clock();
+
Vh u,v;
solve Poisson(u,v,solver=LU) = int2d(Th)(dx(u)*dx(v) + dy(u)*dy(v)) - int2d(Th)( f*v) + on(C,u=0) ;
+
func f= x*y;
plot(u);
+
real cpu=clock();
cout << " CPU time = " << clock()-cpu << endl;
+
solve Poisson(u,v,solver=LU) = int2d(Th)(dx(u)*dx(v) + dy(u)*dy(v)) - int2d(Th)( f*v) + on(C,u=0) ;
 +
cout << " CPU time = " << clock()-cpu << endl;
 +
[leonhard@euler06 ~]$ '''module load new gcc/4.8.2 hdf5/1.8.12 open_mpi/1.6.5 fftw/3.3.3 openblas/0.2.8_seq gsl/1.16 scalapack/2.0.2 freefem/3.34'''
 +
[leonhard@euler06 ~]$ '''bsub -n 1 -W 1:00 -R "rusage[mem=2048]" "FreeFem++ test.edp"'''
 +
Generic job.
 +
Job <33651159> is submitted to queue <normal.4h>.
 +
[leonhard@euler06 ~]$ '''bjobs'''
 +
JOBID      USER        STAT  QUEUE      FROM_HOST  EXEC_HOST  JOB_NAME  SUBMIT_TIME
 +
33651159  leonhard    PEND  normal.4h  euler06                * test.edp Dec  6 13:17
 +
[leonhard@euler06 ~]$ '''bjobs'''
 +
JOBID      USER        STAT  QUEUE      FROM_HOST  EXEC_HOST  JOB_NAME  SUBMIT_TIME
 +
33651159  leonhard    RUN  normal.4h  euler06    e3011      * test.edp Dec  6 13:17
 +
[leonhard@euler06 ~]$ '''bjobs'''
 +
No unfinished job found
 +
[leonhard@euler06 ~]$ grep -A1 Solve lsf.o33651159
 +
  -- Solve :
 +
          min -0.0103244  max 0.0102905
 +
[leonhard@euler06 ~]$
 +
 
 +
You can find the resource usage summary in the LSF log file.

Latest revision as of 13:03, 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 \Omega is the unit disk. The boundary C = \partial\Omega is

C = {(x, y)| x = \cos(t)\,, y = \sin(t), 0 \le t \le 2\Pi}

[leonhard@euler06 ~]$ ls -ltr test.edp 
-rw-r--r-- 1 leonhard 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) ;
cout << " CPU time = " << clock()-cpu << endl;
[leonhard@euler06 ~]$ module load new gcc/4.8.2 hdf5/1.8.12 open_mpi/1.6.5 fftw/3.3.3 openblas/0.2.8_seq gsl/1.16 scalapack/2.0.2 freefem/3.34
[leonhard@euler06 ~]$ bsub -n 1 -W 1:00 -R "rusage[mem=2048]" "FreeFem++ test.edp"
Generic job.
Job <33651159> is submitted to queue <normal.4h>.
[leonhard@euler06 ~]$ bjobs
JOBID      USER        STAT  QUEUE      FROM_HOST   EXEC_HOST   JOB_NAME   SUBMIT_TIME
33651159   leonhard    PEND  normal.4h  euler06                 * test.edp Dec  6 13:17
[leonhard@euler06 ~]$ bjobs
JOBID      USER        STAT  QUEUE      FROM_HOST   EXEC_HOST   JOB_NAME   SUBMIT_TIME
33651159   leonhard    RUN   normal.4h  euler06     e3011       * test.edp Dec  6 13:17
[leonhard@euler06 ~]$ bjobs
No unfinished job found
[leonhard@euler06 ~]$ grep -A1 Solve lsf.o33651159 
  -- Solve : 
          min -0.0103244  max 0.0102905
[leonhard@euler06 ~]$

You can find the resource usage summary in the LSF log file.