I have a question that has me pulling my hair out (but is probably something pretty simple for Fenics gurus). I have a solution to the frequency-domain electromagnetic wave equation in 3D in terms of a real and imaginary vector. I would like to use these two vectors to generate a time-evolving animation of the form E(t) = E_real * cos wt - E_imag * sin wt.The pertinent code is:

`u1 = Function(V2)`

`solve(a == L, u1, bcs, solver_parameters = {'linear_solver' : 'mumps'})`

`u1_r, u1_i = u1.split()`

`fp = File("EField_r.pvd")`

`fp << u1_r`

`fp = File("EField_i.pvd")`

`fp << u1_ifp = File('WaveFile.pvd')`

`ut = u1_r.copy(True)`

`for i in range(50):`

`ut.vector().zero()`

`ut.vector().axpy(math.cos(pi * i / 25.0 + pi / 2.0), u1_i.vector())`

`ut.vector().axpy(math.cos(pi * i / 25.0), u1_r.vector())`

`fp << (ut, i)`

The output of the time dependent weighted sum `ut`

looks like it is only using one component. I should see a traveling wave, not a standing wave. When I plot the real and imaginary components (non-time dependent), I see the correct 90 degree phase shift between real and imaginary component vectors and power on the input and output ports is conserved (indicating correct solution behavor), but the time evolution of `ut`

is not correct. My question: What is wrong with the lines in the for-loop such that the traveling wave behavior is not observed? Am I using the axpy functionality correctly?

I have attached the full code and example mesh (that is known to generate solutions) in a zip file found here.

Fenics version: 2019.1.0 on Ubuntu 18

Cheers!

EDIT - Real and imaginary solutions of electric fields visualized with ParaView 5.4.1 show correct phase shift:

Imaginary -

Real -

But animation does not exhibit the expected traveling wave behavior in time after using the above vector manipulations.

Link to animation

Edit 27/9/2019 -

I found the problem. There is strange behavior in the “split” constructor. Instead of using

`u1_r, u1_i = u1.split()`

,

one needs to use

`u1_r, u1_i = u1.split(True)`

,

otherwise the vector structure seems to be corrupted. I happened by chance on an obscure discussion thread that touched on this (here) once I realized that the problem most likely existed in the “split” function. Documentation seems to be pretty scarce on this and I wonder if it is a bug (or some undocumented feature).

The animation now works correctly. (See correct animation here.)