142int main(
int argc,
char* argv[]) {
145 Inform msg(
"LandauDamping");
148 auto start = std::chrono::high_resolution_clock::now();
152 for (
unsigned d = 0; d <
Dim; d++) {
153 nr[d] = std::atoi(argv[arg++]);
168 const size_type totalP = std::atoll(argv[arg++]);
169 const unsigned int nt = std::atoi(argv[arg++]);
171 msg <<
"Landau damping" <<
endl
172 <<
"nt " << nt <<
" Np= " << totalP <<
" grid = " << nr <<
endl;
176 std::unique_ptr<bunch_type> P;
179 for (
unsigned i = 0; i <
Dim; i++) {
183 std::array<bool, Dim> isParallel;
184 isParallel.fill(
true);
194 double Q = std::reduce(rmax.
begin(), rmax.
end(), -1., std::multiplies<double>());
196 const double dt = 0.5 * hr[0];
198 const bool isAllPeriodic =
true;
203 std::string solver = argv[arg++];
204 P = std::make_unique<bunch_type>(PL, hr, rmin, rmax, isParallel, Q, solver);
208 P->initializeFields(mesh, FL);
212 P->loadbalancethreshold_m = std::atof(argv[arg++]);
214 bool isFirstRepartition;
216 if ((P->loadbalancethreshold_m != 1.0) && (
ippl::Comm->size() > 1)) {
217 msg <<
"Starting first repartition" <<
endl;
219 isFirstRepartition =
true;
221 const int nghost = P->rho_m.getNghost();
222 auto rhoview = P->rho_m.getView();
227 KOKKOS_LAMBDA(
const index_array_type& args) {
238 P->initializeORB(FL, mesh);
239 P->repartition(FL, mesh, isFirstRepartition);
243 msg <<
"First domain decomposition done" <<
endl;
247 const RegionLayout_t& RLayout = PL.getRegionLayout();
248 const typename RegionLayout_t::host_mirror_type Regions = RLayout.
gethLocalRegions();
252 for (
unsigned d = 0; d <
Dim; ++d) {
253 Nr[d] =
CDF(Regions(myRank)[d].max(), alpha, kw[d])
254 -
CDF(Regions(myRank)[d].min(), alpha, kw[d]);
255 Dr[d] =
CDF(rmax[d], alpha, kw[d]) -
CDF(rmin[d], alpha, kw[d]);
256 minU[d] =
CDF(Regions(myRank)[d].min(), alpha, kw[d]);
257 maxU[d] =
CDF(Regions(myRank)[d].max(), alpha, kw[d]);
258 factor *= Nr[d] / Dr[d];
264 MPI_Allreduce(&nloc, &Total_particles, 1, MPI_UNSIGNED_LONG, MPI_SUM,
267 int rest = (int)(totalP - Total_particles);
275 Kokkos::parallel_for(
277 P->R.getView(), P->P.getView(), rand_pool64, alpha, kw, minU, maxU));
283 P->q = P->Q_m / totalP;
284 msg <<
"particles created and initial conditions assigned " <<
endl;
285 isFirstRepartition =
false;
294 P->scatterCIC(totalP, 0, hr);
300 auto Eview = P->getEMirror();
306 P->dumpLandau(Eview);
307 P->gatherStatistics(totalP);
312 msg <<
"Starting iterations ..." <<
endl;
313 for (
unsigned int it = 0; it < nt; it++) {
321 P->P = P->P - 0.5 * dt * P->E;
326 P->R = P->R + dt * P->P;
335 if (P->balance(totalP, it + 1)) {
336 msg <<
"Starting repartition" <<
endl;
338 P->repartition(FL, mesh, isFirstRepartition);
346 P->scatterCIC(totalP, it + 1, hr);
353 P->updateEMirror(Eview);
360 P->P = P->P - 0.5 * dt * P->E;
365 P->dumpLandau(Eview);
366 P->gatherStatistics(totalP);
368 msg <<
"Finished time step: " << it + 1 <<
" time: " << P->time_m <<
endl;
371 msg <<
"LandauDamping: End." <<
endl;
375 auto end = std::chrono::high_resolution_clock::now();
377 std::chrono::duration<double> time_chrono =
378 std::chrono::duration_cast<std::chrono::duration<double>>(end - start);
379 std::cout <<
"Elapsed time: " << time_chrono.count() << std::endl;