blond-org / blond_common

Collection of common functions and interfaces
GNU General Public License v3.0
3 stars 5 forks source link

Empty delta_E array if ring.momentum single valued #49

Open scpalbright opened 4 years ago

scpalbright commented 4 years ago

If the ring is created with a single value for momentum the ring.delta_E array is empty. This causes problems anywhere that delta_E is used. I would propose that in this case it should also be single valued and 0.

It's caused by the calculating of delta_E, which for 0 turns enters the else statement in this block (lines 369-373):

if (self.n_turns+1) > len(self.use_turns):
    self.delta_E = np.zeros(self.energy.shape)
    self._recalc_delta_E()
else:
    self.delta_E = np.diff(self.energy, axis=1)

I would propose the changing this block to:

if (self.n_turns+1) > len(self.use_turns):
    self.delta_E = np.zeros(self.energy.shape)
    self._recalc_delta_E()
elif self.n_turns > 0:
    self.delta_E = np.diff(self.energy, axis=1)
else:
    self.delta_E = np.zeros(self.energy.shape)
alasheen commented 4 years ago

For me this would be fine.

In BLonD the default behavior for single valued momentum would be:

I would maybe ask what should be the general rule for len(delta_E) when a 'single valued vs. turn based vs. time based' momentum program is passed ? And how do we expect it to be calculated when the program is time based ?

scpalbright commented 4 years ago

As in momentum = [[0], [2E9]], so time based but single valued?