@@ -1063,8 +1063,27 @@ InitRandom (Long icount,
1063
1063
1064
1064
if (who == MyProc) {
1065
1065
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 {
1068
1087
ParticleType p;
1069
1088
for (int i = 0 ; i < AMREX_SPACEDIM; i++) {
1070
1089
p.pos (i) = pos[j*AMREX_SPACEDIM + i];
@@ -1094,25 +1113,6 @@ InitRandom (Long icount,
1094
1113
for (int i = 0 ; i < NArrayInt; i++) {
1095
1114
host_int_attribs[pld.m_lev ][ind][i].push_back (pdata.int_array_data [i]);
1096
1115
}
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
- }
1116
1116
}
1117
1117
}
1118
1118
}
@@ -1127,11 +1127,11 @@ InitRandom (Long icount,
1127
1127
auto & dst_tile = GetParticles (host_lev)[std::make_pair (grid,tile)];
1128
1128
auto old_size = dst_tile.GetArrayOfStructs ().size ();
1129
1129
auto new_size = old_size;
1130
- if constexpr (! ParticleType::is_soa_particle)
1130
+ if constexpr (ParticleType::is_soa_particle)
1131
1131
{
1132
- new_size += src_tile.size ();
1133
- } else {
1134
1132
new_size += host_real_attribs[host_lev][std::make_pair (grid,tile)][0 ].size ();
1133
+ } else {
1134
+ new_size += src_tile.size ();
1135
1135
}
1136
1136
dst_tile.resize (new_size);
1137
1137
@@ -1362,44 +1362,71 @@ ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator>
1362
1362
for (Long jcnt = 0 ; jcnt < icount_per_box; jcnt++) {
1363
1363
for (Long kcnt = 0 ; kcnt < icount_per_box; kcnt++)
1364
1364
{
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
+ }
1368
1369
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 ));
1371
1372
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 );
1376
1379
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 ();
1380
1383
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
+ }
1384
1388
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);
1388
1396
}
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
+ }
1391
1402
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 ();
1394
1406
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
+ }
1399
1410
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
+ }
1403
1430
}
1404
1431
1405
1432
} } }
@@ -1438,48 +1465,64 @@ InitOnePerCell (Real x_off, Real y_off, Real z_off, const ParticleInitData& pdat
1438
1465
1439
1466
const Real* dx = geom.CellSize ();
1440
1467
1441
- ParticleType p;
1442
-
1443
1468
// We'll generate the particles in parallel -- but no tiling of the grid here.
1444
1469
for (MFIter mfi (*m_dummy_mf[0 ], false ); mfi.isValid (); ++mfi) {
1445
1470
Box grid = ParticleBoxArray (0 )[mfi.index ()];
1446
1471
auto ind = std::make_pair (mfi.index (), mfi.LocalTileIndex ());
1447
1472
RealBox grid_box (grid,dx,geom.ProbLo ());
1473
+
1474
+ // tile for one particle
1448
1475
ParticleTile<ParticleType, NArrayReal, NArrayInt, amrex::PinnedArenaAllocator> ptile_tmp;
1476
+ ptile_tmp.resize (1 );
1477
+ auto ptd = ptile_tmp.getParticleTileData ();
1478
+
1449
1479
for (IntVect beg = grid.smallEnd (), end=grid.bigEnd (), cell = grid.smallEnd (); cell <= end; grid.next (cell))
1450
1480
{
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
+ }
1455
1488
1456
1489
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));
1458
1491
}
1459
1492
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
+ }
1462
1497
}
1463
1498
1464
1499
// 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 ();
1470
1508
}
1471
1509
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
+ }
1474
1515
1475
1516
// 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]));
1478
1520
}
1479
1521
1480
1522
// ... 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]);
1483
1526
}
1484
1527
}
1485
1528
0 commit comments