@@ -88,6 +88,62 @@ using namespace amrex;
8888
8989namespace
9090{
91+ /* * Return the number of particles per cell as specified by the user
92+ *
93+ * This provides the user input parameters for particles per cell to
94+ * initialize, before applying profile functions for individual cells
95+ * (which might set the real nppc of a cell to zero).
96+ *
97+ * TODO: this does not yet support multiple injection sources from
98+ * <species_name>.injection_sources
99+ * \see PlasmaInjector::PlasmaInjector
100+ */
101+ amrex::Real
102+ get_nppc (ParmParse & pp_spec)
103+ {
104+ amrex::Real nppc = 0 ;
105+
106+ std::string injection_style = " none" ;
107+ pp_spec.query (" injection_style" , injection_style);
108+ std::transform (injection_style.begin (),
109+ injection_style.end (),
110+ injection_style.begin (),
111+ ::tolower);
112+
113+ if (injection_style == " singleparticle" ) {
114+ nppc = 1 ;
115+ } else if (injection_style == " multipleparticles" ) {
116+ std::vector<int > multiple_particles_pos_x;
117+ utils::parser::getArrWithParser (pp_spec, " multiple_particles_pos_x" , multiple_particles_pos_x);
118+ nppc = multiple_particles_pos_x.size ();
119+ } else if (injection_style == " gaussian_beam" ) {
120+ // TODO: hard to estimate well
121+ // Possible way: take the npart parameter, normalize by rms scale to nppc via cell size on level 0.
122+ nppc = 1 ;
123+ } else if (injection_style == " nrandompercell" ) {
124+ amrex::Real num_particles_per_cell = 0 ;
125+ utils::parser::getWithParser (pp_spec, " num_particles_per_cell" , num_particles_per_cell);
126+ nppc = num_particles_per_cell;
127+ } else if (injection_style == " nfluxpercell" ) {
128+ amrex::Real num_particles_per_cell = 0 ;
129+ utils::parser::getWithParser (pp_spec, " num_particles_per_cell" , num_particles_per_cell);
130+ nppc = num_particles_per_cell;
131+ } else if (injection_style == " nuniformpercell" ) {
132+ std::vector<int > nppc_v (3 ,1 );
133+ utils::parser::getArrWithParser (pp_spec, " num_particles_per_cell_each_dim" , nppc_v);
134+ nppc = AMREX_D_TERM (Real (nppc_v[0 ]),*Real (nppc_v[1 ]),*Real (nppc_v[2 ]));
135+ } else if (injection_style == " external_file" ) {
136+ // TODO
137+ } else if (injection_style != " none" ) {
138+ nppc = 0 ;
139+ }
140+
141+ // TODO: <species_name>.read_from_file
142+ // https://github.com/BLAST-WarpX/warpx/issues/6157
143+
144+ return nppc;
145+ }
146+
91147
92148 /* * Print dt and dx,dy,dz */
93149 void PrintDtDxDyDz (
@@ -340,9 +396,7 @@ WarpX::PostProcessBaseGrids (BoxArray& ba0) const
340396 {
341397 split_using_this_species = true ;
342398 utils::parser::queryWithParser (pp_spec, " density_min" , density_min);
343- std::vector<int > nppc_v (3 ,1 );
344- utils::parser::getArrWithParser (pp_spec, " num_particles_per_cell_each_dim" , nppc_v);
345- nppc = AMREX_D_TERM (Real (nppc_v[0 ]),*Real (nppc_v[1 ]),*Real (nppc_v[2 ]));
399+ nppc = get_nppc (pp_spec);
346400 }
347401
348402 // If this species is not initialized by parse_density_function,
0 commit comments