File: Laplace-lagrange-mult.edp

package info (click to toggle)
freefem%2B%2B 3.61.1%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 17,108 kB
  • sloc: cpp: 141,214; ansic: 28,664; sh: 4,925; makefile: 3,142; fortran: 1,171; perl: 844; awk: 290; php: 199; pascal: 41; f90: 32
file content (47 lines) | stat: -rw-r--r-- 1,097 bytes parent folder | download | duplicates (4)
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
39
40
41
42
43
44
45
46
47
/*
   solving   Laplace operator with Neumann boundary condition
   with 1D lagrange multiplier
   
   The variational form is
   find (u,l) such that

   $\forall (v,m)   a(u,v) + b(u,m) + b(v,l) = L(v) $
   where $b(u,m) = int u*m dx$
   
*/
 mesh Th=square(10,10);
 fespace Vh(Th,P1);     // P1 FE space
int n = Vh.ndof;
int n1 = n+1;

 Vh uh,vh;              // unknown and test function. 
 func f=1+x-y;                 //  right hand side function 
  
varf va(uh,vh) =                    //  definition of  the problem 
    int2d(Th)( dx(uh)*dx(vh) + dy(uh)*dy(vh) ) //  bilinear form
;
varf vL(uh,vh)=  int2d(Th)( f*vh )  ;
varf vb(uh,vh)= int2d(Th)(1.*vh);

matrix A=va(Vh,Vh);

real[int] b(n);
b = vL(0,Vh);

real[int]  B = vb(0,Vh); 	
// the block matrix

matrix AA = [ [ A ,  B ] ,
              [ B', 0 ] ] ;

real[int]  bb(n+1),xx(n+1),b1(1),l(1);
b1=0;
// build the block rhs 
bb = [ b, b1];
set(AA,solver=sparsesolver);
xx = AA^-1*bb; // solve the linear system

[uh[],l] = xx;  // set the value 
cout << " l = " << l(0) <<  " ,  b(u,1)  =" << B'*uh[]  << endl;  
plot(uh,wait=1);