GOMC-WSU / GOMC

GOMC - GPU Optimized Monte Carlo is a parallel molecular simulation code designed for high-performance simulation of large systems
https://gomc-wsu.org
MIT License
76 stars 36 forks source link

Fix logic in ComparePotentials function #470

Closed LSchwiebert closed 2 years ago

LSchwiebert commented 2 years ago

The ComparePotentials function had incorrect logic for checking the energies. And it was not returning a value when the potentials matched. I made three changes to the code. This should be checked carefully to ensure the logic is now correct. The changes are.

  1. Only bond, angle, and dihedral are checked within the if case where the intraBond energies do not match.
  2. The recip, real, self, and correction energies are checked only if the totalElect energies do not match.
  3. The return value is set to false when the totalElect or intraBond energies don't match and not set again when any components don't match.
  4. The code returns the return value, true or false, in all cases.

Note that I don't think this caused any incorrect output, because it doesn't look like this function is actually used in the code. But it should be fixed in any case, as it may be used in the future.

GregorySchwing commented 2 years ago

Could you move the return statement from line 439 returnVal = false; to line 459 and line 486 returnVal = false; to line 512

This way if TotalBonded or TotalElec don't match the components are printed before returning false.

LSchwiebert commented 2 years ago

I changed the code but this isn't an early return from the function. It is just setting the return value, not returning from the function. However, I think it is more clear to set the return value at the end of the nested if statement.

GregorySchwing commented 2 years ago

I changed the code but this isn't an early return from the function. It is just setting the return value, not returning from the function. However, I think it is more clear to set the return value at the end of the nested if statement.

My mistake. Approved.