diff --git a/blond/beam/beam.py b/blond/beam/beam.py index 26f6a4ae5c21c95d95bf5862cbb74d55ae1edfd2..d5f2d786ad7bbe4a9bc487e673a6bd7371b67799 100644 --- a/blond/beam/beam.py +++ b/blond/beam/beam.py @@ -211,9 +211,9 @@ class Beam: self.mean_dE = 0. self.sigma_dt = 0. self.sigma_dE = 0. - self.intensity = float(intensity) self.n_macroparticles = int(n_macroparticles) - self.ratio = self.intensity / self.n_macroparticles + self.intensity = float(intensity) + self.id = np.arange(1, self.n_macroparticles + 1, dtype=int) self.epsn_rms_l = 0. # For MPI @@ -267,6 +267,24 @@ class Beam: return bm.count_nonzero(self.id) + @property + def ratio(self) -> float: + return self._ratio + + @ratio.setter + def ratio(self, value: float): + self._ratio = value + self._intensity = self._ratio * self.n_macroparticles + + @property + def intensity(self) -> float: + return self._intensity + + @intensity.setter + def intensity(self, value: float): + self._intensity = value + self._ratio = self._intensity / self.n_macroparticles + def eliminate_lost_particles(self): """Eliminate lost particles from the beam coordinate arrays """ @@ -408,6 +426,8 @@ class Beam: + nNew + 1, dtype=int))) self.n_macroparticles += nNew + self.ratio = self.ratio + self.dt = bm.concatenate((self.dt, newdt)) self.dE = bm.concatenate((self.dE, newdE)) @@ -451,6 +471,8 @@ class Beam: self.id = bm.concatenate((self.id, newids)) self.n_macroparticles += other_beam.n_macroparticles + self.ratio = self.ratio + def split(self, random: bool=False, fast: bool=False): ''' MPI ONLY ROUTINE: Splits the beam equally among the workers for