# Optimizing the program

**URL:** <https://community.freefem.org/t/optimizing-the-program/1017>\
**Category:** General Discussion\
**Created:** [June 6, 2021, 9:18pm UTC](https://community.freefem.org/t/optimizing-the-program/1017 "2021-06-06T21:18:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jamal](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/jamal/32/1527_2.png) [@Jamal](https://community.freefem.org/u/Jamal)\
**Post date:** [June 6, 2021, 9:18pm UTC](https://community.freefem.org/t/optimizing-the-program/1017/1 "2021-06-06T21:18:15Z")

</div>

hello everyone;  
can you help me to optimize my program .  
my programme try to solve an inverse problem using KMF algorithm  
/////////////////////////////// Programme ////////////////////////////////  
////////////////// debut: Mesh /////////////////  
int [int] Labels=[0,1,2,3];  
real x0 = 0.;  
real x1 = 1.;  
real y0 = 0.;  
real y1 = 1.;  
int n = 10;  
int m = 100;  
mesh Th = square(n, m, [x0+(x1-x0)\*x, y0+(y1-y0)\*y],label=Labels,flags=1);  
//plot(Th,wait=true);  
//////////////// Fin: Mesh ////////////////////

//////////////// Data ////////////////////  
int k=20;

//////////////// Definition des probemes ////////////////////  
fespace Vh(Th,P1);  
Vh W0,W1,W2,vW;  
Vh Wex=6.\*(x+y);  
Vh Wguess=0;  
//////////////// Probleme P0 ////////////////////  
problem PW0(W0,vW,solver=sparsesolver)= int2d(Th)(Gradient(W0)’\*Gradient(vW))

```
                                  + on(0,W0=Wex)
                                  + on(2,W0=Wex)
                                  + on(3,W0=Wex)

                                  - int1d(Th,1)(Neumann(Wguess)*vW); // guess q0

```

PW0;  
Wguess=W0;  
//////////////// Probleme P1 ////////////////////

problem PW1(W1,vW,solver=sparsesolver)= int2d(Th)(Gradient(W1)’\*Gradient(vW))

```
                                  + on(0,W1=Wex)
                                  + on(2,W1=Wex)
                                  + on(3,W1=Wex)

                                  - int1d(Th,1)(Neumann(W0)*vW);

```

//////////////// Probleme P2 ////////////////////

problem PW2(W2,vW,solver=sparsesolver)= int2d(Th)(Gradient(W2)’\*Gradient(vW))

```
                                  - int1d(Th,0)(Neumann(W1)*vW)
                                  - int1d(Th,2)(Neumann(W1)*vW)
                                  - int1d(Th,3)(Neumann(W1)*vW)

                                  + on(1,W2=Wex);

```

for (int i=0;i\<k;i++)  
{  
PW1;  
PW2;  
W0=W2;  
}  
plot(Wguess, wait=1,fill=true, cmm=“W0”,value=true,dim=2,boundary=1);  
plot(W1, wait=1,fill=true, cmm=“W1”,value=true,dim=2,boundary=1);  
plot(W2, wait=1,fill=true, cmm=“W2”,value=true,dim=2,boundary=1);  
plot(Wex, wait=1,fill=true, cmm=“Wex”,value=true,dim=2,boundary=1);
