From 2f3e01df31c7ef8150a1f4c8eb4650b7172f2d09 Mon Sep 17 00:00:00 2001 From: moellep Date: Fri, 26 May 2023 22:57:10 +0000 Subject: [PATCH] three switchyard changes - when writing opal input distribution, center particles z at 0, for #47 - when extracting opal total_charge, get value from array, otherwise it appears in GENESIS file as "CHARGE = [...]" - use abs(total_charge) for GENESIS input file, GENESIS doesn't seem to support negative values? --- rsbeams/rsdata/switchyard.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/rsbeams/rsdata/switchyard.py b/rsbeams/rsdata/switchyard.py index ffaaf27..ae27417 100644 --- a/rsbeams/rsdata/switchyard.py +++ b/rsbeams/rsdata/switchyard.py @@ -79,7 +79,7 @@ def read_opal(file_name, step_number=None, species_name='Species'): particle_data = np.empty((mp_count, 6)) for i, coord in enumerate(['x', 'px', 'y', 'py', 'z', 'pz']): particle_data[:, i] = pcdata[loc+'/'+coord] - total_charge = pcdata[loc].attrs['CHARGE'] + total_charge = pcdata[loc].attrs['CHARGE'][0] # TODO: This shouldn't be specific to electrons @@ -185,6 +185,7 @@ def write_opal(self, file_name, species_name): """ coordinates = self.species[species_name].coordinates N = self.species[species_name].macroparticle_count + coordinates[:, 4] -= np.mean(coordinates[:, 4]) np.savetxt(file_name, coordinates, header='{}'.format(N), comments='') return 0 @@ -216,7 +217,7 @@ def write_genesis(self, file_name, species_name, version='2.0'): P = self.species[species_name].pt vers_str = '? VERSION = '+version - charge_str = '? CHARGE = '+str(self.species[species_name].total_charge) + charge_str = '? CHARGE = '+str(abs(self.species[species_name].total_charge)) size_str = '? SIZE = '+str(len(X)) clmns_str = '? COLUMNS X PX Y PY T P' @@ -254,4 +255,4 @@ def write(self, filename, code, species_name=None, **kwargs): def _get_step_number(key, prefix='Step#'): result = key.split(prefix)[-1] - return result \ No newline at end of file + return result