Several problem with complex number

Hello everyone, I have encountered several problems in the computing of complex numbers.

  1. The definition of inner product in my question is as follows.
    QQ20250113-003006
    My question is whether my program needs to add conjugate when using the problem/solve/varf like this?
problem Test1(u,v) = int2d(Th)(u*conj(v))

After completing the variation, if the test function of the inner product contains complex numbers, is it possible to do :

problem Test1(u,v) = int2d(Th)(1i*u*conj(1i*v))

2.The second problem is that I noticed that when two complex vectors are multiplied, Freefem will calculate like this :

conj(A)'*A

which means that when I do not need to calculate in this way, it is a better choice to split the vector multiplication. When I write variables [ux, uy] as such a complex function, is the second method more appropriate ?

problem Test2([ux,uy],[vx,vy]) 
= int2d(Th)([ux,uy]'*[vx,vy])
problem Test2([ux,uy],[vx,vy]) 
= int2d(Th)(dx(ux)*dx(vx)+dy(uy)+dy(vy))

3.My third problem is that this expression appears in the GL equation:
QQ20250113-012323

When calculating in the Freefem, A is real vector and Psi is complex number. But various operations of complex Psi are involved in the calculation of A, which will generate errors:

Compile error : Error: Problem a complex problem with no complex FE function

My solution is to also set the variable type of A as a complex vector, and A will not have any complex value in the calculation. Is this appropriate ?

Any help/suggestion would be greatly appreciated ! :blush:

Hello,
For question (1), your proposal problem Test1(u,v) = int2d(Th)(u*conj(v)) is correct for u,v scalar complex valued (not vector of complex).
Your second proposal with 1i in it is also correct, this is just standard rules for complex numbers!

For question (2), the important thing is that ' (prime) applied to a vector or a matrix of complex numbers gives the transpose of the conjugate:

complex[int,int] a(2,2),b(2,2);
a=[[1+2i,3+4i],[5+6i,7+8i]];
b=a';
cout << "a " << a << endl;
cout << "b " << b << endl;

gives

a 2 2
(1,2) (3,4)
(5,6) (7,8)
b 2 2
(1,-2) (5,-6)
(3,-4) (7,-8)

However the * operator for complex numbers never puts conjugates.
If you prefer, as you suggest you can always replace a complex number by two real numbers (standing for real and imaginary part).

For your question (3), I suggest you to represent \psi by two real numbers (real and imaginary parts), and keep A real.

Thank you so much for your suggestions and for your time !

At present, my equation is divided into two parts where Psi is complex scalar and A is real vector :


Should I define Psi as you suggest :

Wh<complex> psi;
Wh psii,psir;
psir = real(psi); psii = imag(psi);

and bring in two equations for calculation ? Or I can only use Psi itself when calculating Psi, and then use real and imaginary parts when calculating A.

There is no unique way of doing it. You can try and see what you prefer!

Okay, I’ll choose a way to do it. Thank you again for your suggestion

You solve Time-dependent Ginzburg-Landau equations.

  • first of all you can work with complex fields, but in my experience it is always much better to separate the gap \psi into real and imaginary parts. In any case modulus and phase in never an option as they are not continuous and differentiable
  • now your fe-space (in 2d) will be [RePsi, ImPsi,Ax,Ay]
  • to evolve TDGL, you can do naive implementation with all degrees of freedom P2, this should work. If you want something better I recommend Crank-Nicolson algorithm and deal with nonlinearity with richardson extrapolation. An alternative is Semi-implicit (Backward)-Euler Galerkin-mixed FEM… If necessary I have references …
1 Like

Thank you for your suggestion, but I have one question.

If Psi is divided into real and imaginary parts, how should the problem be expressed? I am now using P1 element and second-order time difference scheme. I intend to finish the program to see the results.

If you have any reference, I’d be grateful if you could share them. And here is my email: 894494510@qq.com