Variational formulation involving partial derivative and complex fields

Dear all,
I have some issues involing complex functions in combination with gradients, i.e. dx() and dy(). I have a prepared a MWE (since I just registered, I can’t upload it as a file… sorry).

int numnode = 50;				
mesh Th = square(numnode,numnode);	

fespace Vh(Th,P1);				
Vh<complex> uh,vh; 						
uh = sin(pi*sqrt(x))*sin(pi*y*y) + 1i*sin(pi*x*x)*sin(pi*sqrt(y));

cout << "--> Var assembly of uh'*C*uh: " << int2d(Th)( 1i*dx(uh)'*uh ) << endl;

varf c(uh,vh)= int2d(Th)( 1i*dx(uh)*vh  );	
matrix<complex> C = c(Vh,Vh); 			//# Assemble matrix C
complex[int] aux = C*uh[];
complex uCu = uh[]'*aux;
cout << "--> lin alg assembly of uh'*C*uh: " << uCu << endl;

and I get the following output:
→ Var assembly of uh’Cuh: (0.400063,-1.95872e-17)
→ lin alg assembly of uh’Cuh: (-0.400063,-9.02158e-17)

In my understanding, I should get the same value (which I do for example if I replace ‘dx(uh)’ by ‘uh’ in both expressions).

Does anyone understand what is going on?
Best regards,
Benjamin Stamm

The line
complex uCu = uh[]'*aux;
corresponds to calculating
int2d(Th)( 1i*dx(uh)*uh' )
The difference is whether the conjugation acting on the derivative or not.

Dear aszaboa,
Thanks for your quick answer! Yes, indeed… I was blind towards this option, but now it seems obvious that the conjugation must be with the test and not trial function. Thanks for this helpful comment.
Please find below the corrected MWE.
Best, Ben

int numnode = 50;
mesh Th = square(numnode,numnode);

fespace Vh(Th,P1);
Vh<complex> uh,vh;
uh = sin(pi*sqrt(x))*sin(pi*y*y) + 1i*sin(pi*x*x)*sin(pi*sqrt(y));

cout << "--> Var assembly of uh'*C*uh: " << int2d(Th)( 1i*dx(uh)'*uh ) << endl;

varf c(uh,vh)= int2d(Th)( 1i*dx(vh)*uh  );
matrix<complex> C = c(Vh,Vh); 			//# Assemble matrix C
complex[int] aux = C*uh[];
complex uCu = uh[]'*aux;
cout << "--> lin alg assembly of uh'*C*uh: " << uCu << endl;