# Freefem language

Hello,

I have a very simple question related to the freefem language.
I have many (up to 1000) thermal conductivities for each region, i’d like to still use in the weak form the following expression

int2d(Th)(lambda * (dx(u) * dx(v) + dy(u) * dy(v)))

As far as i know lambda must be defined using a func, unfortunately “func” must be an inline definition, so i can’t use the += operator to iterate like this

func lambda=0;
for (int i=0;i<N;i++)
{
lambda+= lambdaVal[i]*(region == i)
}
Where lambdaVal is a real[int] object

An other idea would be to iterate in the weak formulation to get something like :

problem therm(u, v,solver=UMFPACK,eps=1e-5)
=
for (int i=0;i<N;i++)
{
int2d(Th)(lambda * (dx(u) * dx(v) + dy(u) * dy(v)));
};

But it’s not correct.

Any idea ?

No, this never works, because a func variable is not a real variable but just the pointeur to the code with defined the variable, so it is impossible to change.

To solve you problem, if you have constant thermal conductivities per region,
and if you region numbering are less (stricly) than the nxregion;

just defined a array of

``````  real[int] lambda(nxregion);
// set the value of lambda
lambda = 1 ; // default value
for(int i=0; i< nxregion; ++i)
lambda[i] ..;
``````

solve Pb(u,v) =int2d(Th)(lambda[region] * (dx(u) * dx(v) + dy(u) * dy(v))) - int2d(Th)( v);

And the way is to defined a function lambda as a finite element function (P0 / triangle)

``````   fespace Ph'Th,P0);
Ph lambdah=1. ;  //  default value

for(int k=0; k<Th.nt; ++k)
lambdah[][k] = 1+k; // you value ..... in triangle k..
plot(lambdah,wailt=1,fill=1);
solve Pb2(u,v) =int2d(Th)(lambdak  * (dx(u) * dx(v) + dy(u) * dy(v))) - int2d(Th)( v);``````