@@ -1063,8 +1063,27 @@ InitRandom (Long icount,
10631063
10641064 if (who == MyProc) {
10651065
1066- if constexpr (!ParticleType::is_soa_particle)
1067- {
1066+ if constexpr (ParticleType::is_soa_particle) {
1067+ for (int i = 0 ; i < AMREX_SPACEDIM; i++) {
1068+ host_real_attribs[pld.m_lev ][ind][i].push_back (pos[j*AMREX_SPACEDIM+i]);
1069+ }
1070+
1071+ host_int_attribs[pld.m_lev ][ind][0 ].push_back (ParticleType::NextID ());
1072+ host_int_attribs[pld.m_lev ][ind][1 ].push_back (MyProc);
1073+
1074+ host_particles[pld.m_lev ][ind];
1075+
1076+ // add the real...
1077+ for (int i = AMREX_SPACEDIM; i < NArrayReal; i++) {
1078+ host_real_attribs[pld.m_lev ][ind][i].push_back (static_cast <ParticleReal>(pdata.real_array_data [i]));
1079+ }
1080+
1081+ // ... and int array data
1082+ for (int i = 2 ; i < NArrayInt; i++) {
1083+ host_int_attribs[pld.m_lev ][ind][i].push_back (pdata.int_array_data [i]);
1084+ }
1085+ }
1086+ else {
10681087 ParticleType p;
10691088 for (int i = 0 ; i < AMREX_SPACEDIM; i++) {
10701089 p.pos (i) = pos[j*AMREX_SPACEDIM + i];
@@ -1094,25 +1113,6 @@ InitRandom (Long icount,
10941113 for (int i = 0 ; i < NArrayInt; i++) {
10951114 host_int_attribs[pld.m_lev ][ind][i].push_back (pdata.int_array_data [i]);
10961115 }
1097- } else {
1098- for (int i = 0 ; i < AMREX_SPACEDIM; i++) {
1099- host_real_attribs[pld.m_lev ][ind][i].push_back (pos[j*AMREX_SPACEDIM+i]);
1100- }
1101-
1102- host_int_attribs[pld.m_lev ][ind][0 ].push_back (ParticleType::NextID ());
1103- host_int_attribs[pld.m_lev ][ind][1 ].push_back (MyProc);
1104-
1105- host_particles[pld.m_lev ][ind];
1106-
1107- // add the real...
1108- for (int i = AMREX_SPACEDIM; i < NArrayReal; i++) {
1109- host_real_attribs[pld.m_lev ][ind][i].push_back (static_cast <ParticleReal>(pdata.real_array_data [i]));
1110- }
1111-
1112- // ... and int array data
1113- for (int i = 2 ; i < NArrayInt; i++) {
1114- host_int_attribs[pld.m_lev ][ind][i].push_back (pdata.int_array_data [i]);
1115- }
11161116 }
11171117 }
11181118 }
@@ -1127,11 +1127,11 @@ InitRandom (Long icount,
11271127 auto & dst_tile = GetParticles (host_lev)[std::make_pair (grid,tile)];
11281128 auto old_size = dst_tile.GetArrayOfStructs ().size ();
11291129 auto new_size = old_size;
1130- if constexpr (! ParticleType::is_soa_particle)
1130+ if constexpr (ParticleType::is_soa_particle)
11311131 {
1132- new_size += src_tile.size ();
1133- } else {
11341132 new_size += host_real_attribs[host_lev][std::make_pair (grid,tile)][0 ].size ();
1133+ } else {
1134+ new_size += src_tile.size ();
11351135 }
11361136 dst_tile.resize (new_size);
11371137
@@ -1362,44 +1362,71 @@ ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator>
13621362 for (Long jcnt = 0 ; jcnt < icount_per_box; jcnt++) {
13631363 for (Long kcnt = 0 ; kcnt < icount_per_box; kcnt++)
13641364 {
1365- p.pos (0 ) = static_cast <ParticleReal>(grid_box.lo (0 ) + (dist (mt) + icnt) / icount_per_box * grid_box.length (0 ));
1366- p.pos (1 ) = static_cast <ParticleReal>(grid_box.lo (1 ) + (dist (mt) + jcnt) / icount_per_box * grid_box.length (1 ));
1367- p.pos (2 ) = static_cast <ParticleReal>(grid_box.lo (2 ) + (dist (mt) + kcnt) / icount_per_box * grid_box.length (2 ));
1365+ // the position data
1366+ for (int d = 0 ; d < AMREX_SPACEDIM; d++) {
1367+ p.pos (d) = static_cast <ParticleReal>(grid_box.lo (d) + (dist (mt) + icnt) / icount_per_box * grid_box.length (d));
1368+ }
13681369
1369- for (int i = 0 ; i < AMREX_SPACEDIM; i ++)
1370- AMREX_ASSERT (p.pos (i ) < grid_box.hi (i ));
1370+ for (int d = 0 ; d < AMREX_SPACEDIM; d ++)
1371+ AMREX_ASSERT (p.pos (d ) < grid_box.hi (d ));
13711372
1372- // the real struct data
1373- for (int i = 0 ; i < NStructReal; i++) {
1374- p.rdata (i) = static_cast <ParticleReal>(pdata.real_struct_data [i]);
1375- }
1373+ if constexpr (ParticleType::is_soa_particle) {
1374+ if (!Where (p, pld)) {
1375+ amrex::Abort (" ParticleContainer::InitRandom(): invalid particle" );
1376+ }
1377+ AMREX_ASSERT (pld.m_lev >= 0 && pld.m_lev <= finestLevel ());
1378+ std::pair<int , int > ind (pld.m_grid , pld.m_tile );
13761379
1377- // the int struct data
1378- p.id () = ParticleType::NextID ();
1379- p.cpu () = ParallelDescriptor::MyProc ();
1380+ // IDs
1381+ p.id () = ParticleType::NextID ();
1382+ p.cpu () = ParallelDescriptor::MyProc ();
13801383
1381- for (int i = 0 ; i < NStructInt; i++) {
1382- p.idata (i) = pdata.int_struct_data [i];
1383- }
1384+ // add the real (after position)
1385+ for (int i = AMREX_SPACEDIM; i < NArrayReal; i++) {
1386+ m_particles[pld.m_lev ][ind].push_back_real (i, static_cast <ParticleReal>(pdata.real_array_data [i]));
1387+ }
13841388
1385- // locate the particle
1386- if (!Where (p, pld)) {
1387- amrex::Abort (" ParticleContainer::InitRandomPerBox(): invalid particle" );
1389+ // add the int array data (after id, cpu)
1390+ for (int i = 2 ; i < NArrayInt; i++) {
1391+ m_particles[pld.m_lev ][ind].push_back_int (i, pdata.int_array_data [i]);
1392+ }
1393+
1394+ // add
1395+ m_particles[pld.m_lev ][ind].push_back (p);
13881396 }
1389- AMREX_ASSERT (pld.m_lev >= 0 && pld.m_lev <= finestLevel ());
1390- std::pair<int , int > ind (pld.m_grid , pld.m_tile );
1397+ else {
1398+ // the real struct data
1399+ for (int i = 0 ; i < NStructReal; i++) {
1400+ p.rdata (i) = static_cast <ParticleReal>(pdata.real_struct_data [i]);
1401+ }
13911402
1392- // add the struct
1393- m_particles[pld.m_lev ][ind].push_back (p);
1403+ // the int struct data
1404+ p.id () = ParticleType::NextID ();
1405+ p.cpu () = ParallelDescriptor::MyProc ();
13941406
1395- // add the real...
1396- for (int i = 0 ; i < NArrayReal; i++) {
1397- m_particles[pld.m_lev ][ind].push_back_real (i, static_cast <ParticleReal>(pdata.real_array_data [i]));
1398- }
1407+ for (int i = 0 ; i < NStructInt; i++) {
1408+ p.idata (i) = pdata.int_struct_data [i];
1409+ }
13991410
1400- // ... and int array data
1401- for (int i = 0 ; i < NArrayInt; i++) {
1402- m_particles[pld.m_lev ][ind].push_back_int (i, pdata.int_array_data [i]);
1411+ // locate the particle
1412+ if (!Where (p, pld)) {
1413+ amrex::Abort (" ParticleContainer::InitRandomPerBox(): invalid particle" );
1414+ }
1415+ AMREX_ASSERT (pld.m_lev >= 0 && pld.m_lev <= finestLevel ());
1416+ std::pair<int , int > ind (pld.m_grid , pld.m_tile );
1417+
1418+ // add the struct
1419+ m_particles[pld.m_lev ][ind].push_back (p);
1420+
1421+ // add the real...
1422+ for (int i = 0 ; i < NArrayReal; i++) {
1423+ m_particles[pld.m_lev ][ind].push_back_real (i, static_cast <ParticleReal>(pdata.real_array_data [i]));
1424+ }
1425+
1426+ // ... and int array data
1427+ for (int i = 0 ; i < NArrayInt; i++) {
1428+ m_particles[pld.m_lev ][ind].push_back_int (i, pdata.int_array_data [i]);
1429+ }
14031430 }
14041431
14051432 } } }
@@ -1438,48 +1465,64 @@ InitOnePerCell (Real x_off, Real y_off, Real z_off, const ParticleInitData& pdat
14381465
14391466 const Real* dx = geom.CellSize ();
14401467
1441- ParticleType p;
1442-
14431468 // We'll generate the particles in parallel -- but no tiling of the grid here.
14441469 for (MFIter mfi (*m_dummy_mf[0 ], false ); mfi.isValid (); ++mfi) {
14451470 Box grid = ParticleBoxArray (0 )[mfi.index ()];
14461471 auto ind = std::make_pair (mfi.index (), mfi.LocalTileIndex ());
14471472 RealBox grid_box (grid,dx,geom.ProbLo ());
1473+
1474+ // tile for one particle
14481475 ParticleTile<ParticleType, NArrayReal, NArrayInt, amrex::PinnedArenaAllocator> ptile_tmp;
1476+ ptile_tmp.resize (1 );
1477+ auto ptd = ptile_tmp.getParticleTileData ();
1478+
14491479 for (IntVect beg = grid.smallEnd (), end=grid.bigEnd (), cell = grid.smallEnd (); cell <= end; grid.next (cell))
14501480 {
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 ]););
1481+ // particle index
1482+ constexpr int i = 0 ;
1483+
1484+ // the position data
1485+ for (int d = 0 ; d < AMREX_SPACEDIM; d++) {
1486+ ptile_tmp.pos (i, d) = static_cast <ParticleReal>(grid_box.lo (d) + (x_off + cell[d]-beg[d])*dx[d]);
1487+ }
14551488
14561489 for (int d = 0 ; d < AMREX_SPACEDIM; ++d) {
1457- AMREX_ASSERT (p .pos (d) < grid_box.hi (d));
1490+ AMREX_ASSERT (ptile_tmp .pos (i, d) < grid_box.hi (d));
14581491 }
14591492
1460- for (int i = 0 ; i < NStructReal; i++) {
1461- p.rdata (i) = static_cast <ParticleReal>(pdata.real_struct_data [i]);
1493+ if constexpr (!ParticleType::is_soa_particle) {
1494+ for (int n = 0 ; n < NStructReal; n++) {
1495+ ptd.rdata (n)[i] = static_cast <ParticleReal>(pdata.real_struct_data [n]);
1496+ }
14621497 }
14631498
14641499 // 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];
1500+ if constexpr (ParticleType::is_soa_particle) {
1501+ ptd.idata (0 )[i] = ParticleType::NextID ();
1502+ ptd.idata (1 )[i] = ParallelDescriptor::MyProc ();
1503+ }
1504+ else {
1505+ auto & p = make_particle<ParticleType>{}(ptd, i);
1506+ p.id () = ParticleType::NextID ();
1507+ p.cpu () = ParallelDescriptor::MyProc ();
14701508 }
14711509
1472- // add the struct
1473- ptile_tmp.push_back (p);
1510+ if constexpr (!ParticleType::is_soa_particle) {
1511+ for (int n = 0 ; n < NStructInt; n++) {
1512+ ptd.idata (n)[i] = pdata.int_struct_data [n];
1513+ }
1514+ }
14741515
14751516 // 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]));
1517+ int n_min_real = ParticleType::is_soa_particle ? AMREX_SPACEDIM : 0 ; // jump over position
1518+ for (int n = n_min_real; n < NArrayReal; n++) {
1519+ ptile_tmp.push_back_real (n, static_cast <ParticleReal>(pdata.real_array_data [n]));
14781520 }
14791521
14801522 // ... and int array data
1481- for (int i = 0 ; i < NArrayInt; i++) {
1482- ptile_tmp.push_back_int (i, pdata.int_array_data [i]);
1523+ int n_min_int = ParticleType::is_soa_particle ? 2 : 0 ; // jump over cpuid
1524+ for (int n = n_min_int; n < NArrayInt; n++) {
1525+ ptile_tmp.push_back_int (n, pdata.int_array_data [n]);
14831526 }
14841527 }
14851528
0 commit comments