@@ -1438,48 +1438,64 @@ InitOnePerCell (Real x_off, Real y_off, Real z_off, const ParticleInitData& pdat
1438
1438
1439
1439
const Real* dx = geom.CellSize ();
1440
1440
1441
- ParticleType p;
1442
-
1443
1441
// We'll generate the particles in parallel -- but no tiling of the grid here.
1444
1442
for (MFIter mfi (*m_dummy_mf[0 ], false ); mfi.isValid (); ++mfi) {
1445
1443
Box grid = ParticleBoxArray (0 )[mfi.index ()];
1446
1444
auto ind = std::make_pair (mfi.index (), mfi.LocalTileIndex ());
1447
1445
RealBox grid_box (grid,dx,geom.ProbLo ());
1446
+
1447
+ // tile for one particle
1448
1448
ParticleTile<ParticleType, NArrayReal, NArrayInt, amrex::PinnedArenaAllocator> ptile_tmp;
1449
+ ptile_tmp.resize (1 );
1450
+ auto ptd = ptile_tmp.getParticleTileData ();
1451
+
1449
1452
for (IntVect beg = grid.smallEnd (), end=grid.bigEnd (), cell = grid.smallEnd (); cell <= end; grid.next (cell))
1450
1453
{
1451
- // the real struct data
1452
- AMREX_D_TERM (p.pos (0 ) = static_cast <ParticleReal>(grid_box.lo (0 ) + (x_off + cell[0 ]-beg[0 ])*dx[0 ]);,
1453
- p.pos (1 ) = static_cast <ParticleReal>(grid_box.lo (1 ) + (y_off + cell[1 ]-beg[1 ])*dx[1 ]);,
1454
- p.pos (2 ) = static_cast <ParticleReal>(grid_box.lo (2 ) + (z_off + cell[2 ]-beg[2 ])*dx[2 ]););
1454
+ // particle index
1455
+ constexpr int i = 0 ;
1456
+
1457
+ // the position data
1458
+ for (int d = 0 ; d < AMREX_SPACEDIM; d++) {
1459
+ ptile_tmp.pos (i, d) = static_cast <ParticleReal>(grid_box.lo (d) + (x_off + cell[d]-beg[d])*dx[d]);
1460
+ }
1455
1461
1456
1462
for (int d = 0 ; d < AMREX_SPACEDIM; ++d) {
1457
- AMREX_ASSERT (p .pos (d) < grid_box.hi (d));
1463
+ AMREX_ASSERT (ptile_tmp .pos (i, d) < grid_box.hi (d));
1458
1464
}
1459
1465
1460
- for (int i = 0 ; i < NStructReal; i++) {
1461
- p.rdata (i) = static_cast <ParticleReal>(pdata.real_struct_data [i]);
1466
+ if constexpr (!ParticleType::is_soa_particle) {
1467
+ for (int n = 0 ; n < NStructReal; n++) {
1468
+ ptd.rdata (n)[i] = static_cast <ParticleReal>(pdata.real_struct_data [n]);
1469
+ }
1462
1470
}
1463
1471
1464
1472
// the int struct data
1465
- p.id () = ParticleType::NextID ();
1466
- p.cpu () = ParallelDescriptor::MyProc ();
1467
-
1468
- for (int i = 0 ; i < NStructInt; i++) {
1469
- p.idata (i) = pdata.int_struct_data [i];
1473
+ if constexpr (ParticleType::is_soa_particle) {
1474
+ ptd.idata (0 )[i] = ParticleType::NextID ();
1475
+ ptd.idata (1 )[i] = ParallelDescriptor::MyProc ();
1476
+ }
1477
+ else {
1478
+ auto & p = make_particle<ParticleType>{}(ptd, i);
1479
+ p.id () = ParticleType::NextID ();
1480
+ p.cpu () = ParallelDescriptor::MyProc ();
1470
1481
}
1471
1482
1472
- // add the struct
1473
- ptile_tmp.push_back (p);
1483
+ if constexpr (!ParticleType::is_soa_particle) {
1484
+ for (int n = 0 ; n < NStructInt; n++) {
1485
+ ptd.idata (n)[i] = pdata.int_struct_data [n];
1486
+ }
1487
+ }
1474
1488
1475
1489
// add the real...
1476
- for (int i = 0 ; i < NArrayReal; i++) {
1477
- ptile_tmp.push_back_real (i, static_cast <ParticleReal>(pdata.real_array_data [i]));
1490
+ int n_min_real = ParticleType::is_soa_particle ? AMREX_SPACEDIM : 0 ; // jump over position
1491
+ for (int n = n_min_real; n < NArrayReal; n++) {
1492
+ ptile_tmp.push_back_real (n, static_cast <ParticleReal>(pdata.real_array_data [n]));
1478
1493
}
1479
1494
1480
1495
// ... and int array data
1481
- for (int i = 0 ; i < NArrayInt; i++) {
1482
- ptile_tmp.push_back_int (i, pdata.int_array_data [i]);
1496
+ int n_min_int = ParticleType::is_soa_particle ? 2 : 0 ; // jump over cpuid
1497
+ for (int n = n_min_int; n < NArrayInt; n++) {
1498
+ ptile_tmp.push_back_int (n, pdata.int_array_data [n]);
1483
1499
}
1484
1500
}
1485
1501
0 commit comments