On defining functions with func

Hello everyone
In the following example, some optimization algorithms in NLOPT are called to solve the extreme value problem. There is a piece of code that I don’t understand.
int NN = 6;
load"medit"
mesh Th = square(NN,NN);
func f1=1.;
func f2=-1.;
func g1=0.;
func g2=0.1;
int iter=0;
int nadapt=10;
real starttol=1e-6,bctol=6.e-12;
fespace Vh(Th,P1);
Vh oldu1,oldu2;
varf BVF(v,w) = int2d(Th)(0.5dx(v)dx(w) + 0.5dy(v)dy(w));
varf LVF1(v,w) = int2d(Th)(f1
w);
varf LVF2(v,w) = int2d(Th)(f2
w);
matrix A = BVF(Vh,Vh);
real[int] b1 = LVF1(0,Vh),b2 = LVF2(0,Vh);

varf Vbord(v,w) = on(1,2,3,4,v=1);
Vh In,Bord;
Bord = Vbord(0,Vh,tgv=1);
In = Bord ? 0:1;
Vh gh1=Bordg1,gh2=Bordg2;
func real J(real[int] &X)
{
Vh u1,u2;
u1 = X(0:Vh.ndof-1);
u2 = X(Vh.ndof:2Vh.ndof-1);
iter++;
real[int] Au1 = A
u1, Au2 = A*u2;
Au1 -= b1;
Au2 -= b2;
real val = u1‘*Au1 + u2’*Au2;
if(iter %10==9)
plot(u1,u2,nbiso=30,fill=1,dim=3,cmm="adapt level " + al + " - iteration " + iter + " - J = " + val,value=1);
cout<<“a=”<<u1<<endl;
}

I don’t understand the X in line 24. I hope someone can give me some answers.

                                                                                                                                                     thank you

What is your question precisely? I suppose the reason for the coding is that nlopt needs a real[int] as an input.

Thank you very much.This is an official example. FreeFEM++is used to call the optimization algorithm in NLOPT to solve the problem. This example is used to solve the maximum value of a function, and J is the target function to be minimized. The complete tutorial is here:

X is just a pointer to the real[int] that is used as an argument to the J function.