1111
1212#include " initialization/Algorithms.H"
1313#include " particles/wakefields/ChargeBinning.H"
14+ #include " particles/spacecharge/Deposit1D.H"
1415
1516#include < ablastr/particles/NodalFieldGather.H>
1617
@@ -37,6 +38,23 @@ namespace impactx::particles::spacecharge
3738
3839 amrex::ParticleReal const charge = pc.GetRefParticle ().charge ;
3940
41+ // Deposit 1D charge density in cases where it is required.
42+ amrex::Real * beam_profile = nullptr ;
43+ amrex::Real * beam_profile_slope = nullptr ;
44+ int num_bins = 129 ;
45+
46+ [[maybe_unused]] auto const [x_min, y_min, t_min, x_max, y_max, t_max] =
47+ pc.MinAndMaxPositions ();
48+
49+ amrex::Real bin_min = t_min;
50+ amrex::Real bin_max = t_max;
51+ amrex::Real const bin_size = (bin_max - bin_min) / (num_bins - 1 );
52+
53+ if (space_charge == SpaceChargeAlgo::True_2p5D) {
54+
55+ Deposit1D ( pc, beam_profile, beam_profile_slope, bin_min, bin_max, num_bins);
56+ }
57+
4058 // loop over refinement levels
4159 int const nLevel = pc.finestLevel ();
4260 for (int lev = 0 ; lev <= nLevel; ++lev)
@@ -120,43 +138,6 @@ namespace impactx::particles::spacecharge
120138 auto prob_lo_2D = gm.ProbLoArray ();
121139 prob_lo_2D[2 ] = 0 .0_rt;
122140
123- // Calculate z-dependent scaling by current
124- int tp5d_bins = 129 ;
125- amrex::ParmParse pp_algo (" algo.space_charge" );
126- pp_algo.queryAddWithParser (" gauss_charge_z_bins" , tp5d_bins);
127-
128- // Set parameters for charge deposition
129- bool const is_unity_particle_weight = false ;
130- bool const GetNumberDensity = true ;
131-
132- // Measure beam size, extract the min, max of particle positions
133- [[maybe_unused]] auto const [x_min, y_min, t_min, x_max, y_max, t_max] =
134- pc.MinAndMaxPositions ();
135-
136- int const num_bins = tp5d_bins; // Set resolution
137- amrex::Real const bin_min = t_min;
138- amrex::Real const bin_max = t_max;
139- amrex::Real const bin_size = (bin_max - bin_min) / (num_bins - 1 ); // number of evaluation points
140- // Allocate memory for the charge profile
141- amrex::Gpu::DeviceVector<amrex::Real> charge_distribution (num_bins + 1 , 0.0 );
142- // Call charge deposition function
143- impactx::particles::wakefields::DepositCharge1D (pc, charge_distribution, bin_min, bin_size, is_unity_particle_weight);
144-
145- // Sum up all partial charge histograms to each MPI process to calculate
146- // the global charge slope.
147- amrex::ParallelAllReduce::Sum (
148- charge_distribution.data (),
149- charge_distribution.size (),
150- amrex::ParallelDescriptor::Communicator ()
151- );
152-
153- // Call charge density derivative function
154- amrex::Gpu::DeviceVector<amrex::Real> slopes (charge_distribution.size () - 1 , 0.0 );
155- impactx::particles::wakefields::DerivativeCharge1D (charge_distribution, slopes, bin_size,GetNumberDensity);
156-
157- amrex::Real const * const beam_profile_slope = slopes.data ();
158- amrex::Real const * const beam_profile = charge_distribution.data ();
159-
160141 // group together constants for the momentum push
161142 amrex::ParticleReal const chargesign = charge / std::abs (charge);
162143
0 commit comments