Store all energies in a "dictionary"
I was looking at m_energies.F90 and it seems a bit odd that energies are stored as global variables and can be modified by anyone without any control. Also, given that there are so many different ones, I believe some bookkeeping of the names could be beneficial.
For these reasons I would like to propose that all energies are stored in some kind of "dictionary" that keeps everything organized. The benefits would be:
- Keep energy keys organized.
- Avoid changing subroutine arguments when a new energy term is introduced/avoid passing each energy term separately to a subroutine. One would just pass the object with all energies and the subroutine would pick the ones that it needs.
- Printing/outputing/intializing energies would just be a loop over the keys.
- Avoid things like
use m_energies
and then use global variables without importing them explicitly (harder to debug). - Only allow modifying energies by calling a specific
set
method (perhaps even "add" or something like that if it makes sense). This makes it much easier to understand and debug which parts of the code modify the energies and when are they modified. - In the future, if for some case it is useful, one could have several instances of this dict storing all energies for different structures/steps. Which would make it more modular and friendly.
I could make a MR on this, since it seems it would be just a matter of "grepping" all global variables and refactoring the code.
What are your thoughts on this?
Edited by Pol Febrer