I have computed a complex solution with the help of a mixed formulation space, i.e. I have a function $p$ in the space $W$, where
V = FiniteElement("Lagrange", triangle, 1)
W = V*V
The two components of $p$ represent real and imaginary part respectively, and I would now compute the modulus on my solution $$\left| p\right| = \sqrt{p_{real}^2 +p_{imag}^2}.$$
So far I have been able to compute $p_{real}^2 +p_{imag}^2$ via the code
Function modulus1(W->sub(0)->collapse());
Function modulus2(W->sub(0)->collapse());
Function modulus(W->sub(0)->collapse());
*modulus1.vector() = *p_real.vector();
*modulus1.vector() *= *p_real.vector();
*modulus2.vector() = *p_imag.vector();
*modulus2.vector() *= *p_imag.vector();
*modulus.vector() = *modulus1.vector();
*modulus.vector() += *modulus2.vector();
but I still have to calculate the square root of modulus.
I tried accessing every element in modulus with a for loop, but it seems like the operator [] is not implemented.