@@ -1354,48 +1354,64 @@ InitOnePerCell (Real x_off, Real y_off, Real z_off, const ParticleInitData& pdat
1354
1354
1355
1355
const Real* dx = geom.CellSize ();
1356
1356
1357
- ParticleType p;
1358
-
1359
1357
// We'll generate the particles in parallel -- but no tiling of the grid here.
1360
1358
for (MFIter mfi (*m_dummy_mf[0 ], false ); mfi.isValid (); ++mfi) {
1361
1359
Box grid = ParticleBoxArray (0 )[mfi.index ()];
1362
1360
auto ind = std::make_pair (mfi.index (), mfi.LocalTileIndex ());
1363
1361
RealBox grid_box (grid,dx,geom.ProbLo ());
1362
+
1363
+ // tile for one particle
1364
1364
ParticleTile<ParticleType, NArrayReal, NArrayInt, amrex::PinnedArenaAllocator> ptile_tmp;
1365
+ ptile_tmp.resize (1 );
1366
+ auto ptd = ptile_tmp.getParticleTileData ();
1367
+
1365
1368
for (IntVect beg = grid.smallEnd (), end=grid.bigEnd (), cell = grid.smallEnd (); cell <= end; grid.next (cell))
1366
1369
{
1367
- // the real struct data
1368
- AMREX_D_TERM (p.pos (0 ) = static_cast <ParticleReal>(grid_box.lo (0 ) + (x_off + cell[0 ]-beg[0 ])*dx[0 ]);,
1369
- p.pos (1 ) = static_cast <ParticleReal>(grid_box.lo (1 ) + (y_off + cell[1 ]-beg[1 ])*dx[1 ]);,
1370
- p.pos (2 ) = static_cast <ParticleReal>(grid_box.lo (2 ) + (z_off + cell[2 ]-beg[2 ])*dx[2 ]););
1370
+ // particle index
1371
+ constexpr int i = 0 ;
1372
+
1373
+ // the position data
1374
+ for (int d = 0 ; d < AMREX_SPACEDIM; d++) {
1375
+ ptile_tmp.pos (i, d) = static_cast <ParticleReal>(grid_box.lo (d) + (x_off + cell[d]-beg[d])*dx[d]);
1376
+ }
1371
1377
1372
1378
for (int d = 0 ; d < AMREX_SPACEDIM; ++d) {
1373
- AMREX_ASSERT (p .pos (d) < grid_box.hi (d));
1379
+ AMREX_ASSERT (ptile_tmp .pos (i, d) < grid_box.hi (d));
1374
1380
}
1375
1381
1376
- for (int i = 0 ; i < NStructReal; i++) {
1377
- p.rdata (i) = static_cast <ParticleReal>(pdata.real_struct_data [i]);
1382
+ if constexpr (!ParticleType::is_soa_particle) {
1383
+ for (int n = 0 ; n < NStructReal; n++) {
1384
+ ptd.rdata (n)[i] = static_cast <ParticleReal>(pdata.real_struct_data [n]);
1385
+ }
1378
1386
}
1379
1387
1380
1388
// the int struct data
1381
- p.id () = ParticleType::NextID ();
1382
- p.cpu () = ParallelDescriptor::MyProc ();
1383
-
1384
- for (int i = 0 ; i < NStructInt; i++) {
1385
- p.idata (i) = pdata.int_struct_data [i];
1389
+ if constexpr (ParticleType::is_soa_particle) {
1390
+ ptd.idata (0 )[i] = ParticleType::NextID ();
1391
+ ptd.idata (1 )[i] = ParallelDescriptor::MyProc ();
1392
+ }
1393
+ else {
1394
+ auto & p = make_particle<ParticleType>{}(ptd, i);
1395
+ p.id () = ParticleType::NextID ();
1396
+ p.cpu () = ParallelDescriptor::MyProc ();
1386
1397
}
1387
1398
1388
- // add the struct
1389
- ptile_tmp.push_back (p);
1399
+ if constexpr (!ParticleType::is_soa_particle) {
1400
+ for (int n = 0 ; n < NStructInt; n++) {
1401
+ ptd.idata (n)[i] = pdata.int_struct_data [n];
1402
+ }
1403
+ }
1390
1404
1391
1405
// add the real...
1392
- for (int i = 0 ; i < NArrayReal; i++) {
1393
- ptile_tmp.push_back_real (i, static_cast <ParticleReal>(pdata.real_array_data [i]));
1406
+ int n_min_real = ParticleType::is_soa_particle ? AMREX_SPACEDIM : 0 ; // jump over position
1407
+ for (int n = n_min_real; n < NArrayReal; n++) {
1408
+ ptile_tmp.push_back_real (n, static_cast <ParticleReal>(pdata.real_array_data [n]));
1394
1409
}
1395
1410
1396
1411
// ... and int array data
1397
- for (int i = 0 ; i < NArrayInt; i++) {
1398
- ptile_tmp.push_back_int (i, pdata.int_array_data [i]);
1412
+ int n_min_int = ParticleType::is_soa_particle ? 2 : 0 ; // jump over cpuid
1413
+ for (int n = n_min_int; n < NArrayInt; n++) {
1414
+ ptile_tmp.push_back_int (n, pdata.int_array_data [n]);
1399
1415
}
1400
1416
}
1401
1417
0 commit comments