aryafallahi / mithra

MITHRA is a full-wave numerical solver for free-electron lasers.
17 stars 7 forks source link

[BUG] Seed amplitude not initialised #59

Closed arnaualba closed 3 years ago

arnaualba commented 3 years ago

Hello Arya, I hope everything is going well. Recently we found an issue in our OPAL-MITHRA simulations:

The member seed.a0_ should be initialised in the constructor Seed::Seed().

Right now, a0_ is only initialised in the Seed::initialize(...) function, which is only called if the Seed{ } option is used in the jobfile.

The problem is that solver.cpp checks several times if a seed has been activated with

 if (seed_.amplitude_ > 1.0e-50) 

but in solver::setSimulationParameters() the amplitude was set as

seed_.amplitude_            = seed_.a0_ * EM * c0_ / EC;  

So if the Seed{ } option is not used in the jobfile, amplitude_ and a0_ are initialised at random, and could potentially be non-zero!

This can easily be fixed by adding a0_ = 0.0 in the constructor.

Furthermore, several classes in MITHRA don't initialise all member variables in the constructor, and I think this could lead to further errors like this one in the future. I would suggest that all member variables be initialised in the constructors, even if they are later modified with an initialise() function

aryafallahi commented 3 years ago

Hi Arnau,

sorry for the long delay. Today I managed to work on the issues. This issue is hopefully resolved and I have not forgotten any parameters. Just note that the parameters in the structures are not initialized. I hope it is fine.

Regards,

Arya