Hi all! I am a beginner to freefem, please excuse any gaps in my knowledge. So as part of my research I am doing numerical simulations of the (vector) Helmholz equation in the time domain:

The weak form that I obtained was:

Where \nabla_J is the Jacobian. I wanted to verify that my code for my numerical simulations worked correctly by verifying against a simple case with a known analytical solution, that of the unit square. For simplicity I am using the scalar variant of the Helmholz equation -\nabla^2 E - k^2 E = 0, where for the vector-valued solution I would have \mathbf{E}_x = E, \mathbf{E}_y = E.

It is known that the Helmholz equation solved on a unit square with Dirichlet BC E \big|_{\partial \Omega} = 0 has the analytical solution:

Where k^2 = \pi^2(m^2 + n^2). I believe there is a uniqueness theorem that says that for Dirichlet boundary conditions E \big|_{\partial \Omega} = 0 over all the boundaries of the domain, if an eigenvalue is specified and satisfies the Helmholtz equation, then the solution is guaranteed to be both unique and non-trivial (nonzero). So I substituted this in, started the simulation, and gotâ€¦nothing but zeroes. Here is my (simplified) code for reference:

```
int squaren = 80;
mesh Th = square(squaren, squaren);
plot(Th, value=1, wait=1);
/*
For values of k^2 = (n^2 + m^2) pi^2
then the homogenous Dirichlet problem
yields a solution even with
E = 0 at the boundaries.
For all other values of k, the Dirichlet
problem (E = 0 at boundaries) yields a
null solution, different boundary conditions
are necessary instead.
*/
int m = 1;
int n = 1;
real ksquared = (m^2 + n^2) * pi^2;
func AnalyticalMag = sin(pi*x) * sin(pi*y);
fespace Vh(Th, P1);
Vh TestPhi;
Vh Emag;
Vh ExactEmag=AnalyticalMag;
macro grad(u) [dx(u), dy(u)] //
solve ElectricField(Emag, TestPhi, solver=sparsesolver)
= int2d(Th)(
grad(Emag)' * grad(TestPhi)
)
+ int2d(Th)(
ksquared * Emag * TestPhi
)
+ on(1, 2, 3, 4, Emag=0);
plot(Emag, value=true, fill=true, dim=3, cmm="Electric field (spatial components)", wait=1);
plot(ExactEmag, value=true, fill=true, dim=3, cmm="Electric field (analytical solution)", wait=1);
```

The best I could do was to set E \big|_{\partial \Omega} = \epsilon where \epsilon \approx 0 which FreeFEM returns a nontrivial but still incorrect solution. Even more confusingly, after using FreeFEMâ€™s `EigenValue()`

in a separate validation script, no matter what I tried, I couldnâ€™t get the analytical values of the eigenvalue k^2.

At this point I am thinking that perhaps the elliptic nature of the PDE is to blame. Maybe I should try some sort of Newton method? Some advice on this problem would be greatly appreciated.