File: a_tutorial.edp

package info (click to toggle)
freefem%2B%2B 3.47%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 132,088 kB
  • ctags: 19,726
  • sloc: cpp: 138,951; ansic: 22,605; sh: 4,951; makefile: 2,935; fortran: 1,147; perl: 768; awk: 282; php: 182
file content (38 lines) | stat: -rw-r--r-- 1,259 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// This test shows some powerful features of freefem++ on a
// simple example: $-\Delta(u)=1$ in the unit cercle with $u=0$ on the
// border of the unit cercle. this problem has an analytical solution
// u = (1-x^2-y^2)/4
real pi=4*atan(1);
border a(t=0,2*pi){ x = cos(t); y = sin(t);label=1;};

mesh disk = buildmesh(a(50));
plot(disk);
fespace femp1(disk,P1);  
femp1 u,v; 

problem laplace(u,v) = 
    int2d(disk)( dx(u)*dx(v) + dy(u)*dy(v) )     //  bilinear form
  + int2d(disk)( -1*v )                          //  linear form
  + on(1,u=0) ;                                // boundary condition 

laplace; 
femp1 err=u-(1-x^2-y^2)/4;

plot (u,value=true,wait=true);
plot(err,value=true,wait=true);

cout << "error L2=" << sqrt(int2d(disk)( (u-(1-x^2-y^2)/4) ^2) )<< endl;
cout << "error H10=" << sqrt(   int2d(disk)((dx(u)+x/2)^2) 
                              + int2d(disk)((dy(u)+y/2)^2))<< endl;

 disk = adaptmesh(disk,u,err=0.01);
plot(disk,wait=1);

laplace; 

plot (u,value=true,wait=true);
err =u-(1-x^2-y^2)/4;
plot(err,value=true,wait=true);
cout << "error L2=" << sqrt(int2d(disk)( (u-(1-x^2-y^2)/4) ^2) )<< endl;
cout << "error H10=" << sqrt(  int2d(disk)((dx(u)+x/2)^2) 
                             + int2d(disk)((dy(u)+y/2)^2))<< endl;