From d00d032df0049251857463e6eeec3fdecca34587 Mon Sep 17 00:00:00 2001 From: Simon Albright <simon.albright@cern.ch> Date: Fri, 22 Mar 2024 17:07:07 +0100 Subject: [PATCH 1/2] made intensity and ratio into properties to allow them to be modified after object creation and each affect the other --- blond/beam/beam.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/blond/beam/beam.py b/blond/beam/beam.py index 26f6a4ae..1c8655e5 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 """ -- GitLab From c1163d7f46761c4a0b104ae449b7b739f843183a Mon Sep 17 00:00:00 2001 From: Simon Albright <simon.albright@cern.ch> Date: Fri, 22 Mar 2024 17:08:35 +0100 Subject: [PATCH 2/2] forcing update of intensity after incrementing the number of macroparticles when adding new beam --- blond/beam/beam.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/blond/beam/beam.py b/blond/beam/beam.py index 1c8655e5..d5f2d786 100644 --- a/blond/beam/beam.py +++ b/blond/beam/beam.py @@ -426,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)) @@ -469,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 -- GitLab