Skip to content

Commit d16803f

Browse files
committed
Simplify implementation and fix bugs
1 parent 86e5af0 commit d16803f

10 files changed

+77
-108
lines changed

Source/Evolve/WarpXEvolve.cpp

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -504,29 +504,48 @@ WarpX::OneStep_nosub (
504504
ExecutePythonCallback("particlescraper");
505505
ExecutePythonCallback("beforedeposition");
506506

507-
// push particles (half position and full momentum)
508-
PushParticlesandDeposit(
509-
a_cur_time,
510-
/*skip_current=*/true,
511-
PositionPushType::FirstHalf,
512-
MomentumPushType::Full
513-
);
507+
// with collisions placed in the middle of the position push and after the momentum push
508+
if (m_collisions_split_position_push) {
509+
// push particles (half position and full momentum)
510+
PushParticlesandDeposit(
511+
a_cur_time,
512+
/*skip_current=*/true,
513+
PositionPushType::FirstHalf,
514+
MomentumPushType::Full
515+
);
514516

515-
// communicate particle data
516-
mypc->Redistribute();
517+
// communicate particle data
518+
// FIXME Copy local communication from WarpX::HandleParticlesAtBoundaries
519+
mypc->Redistribute();
517520

518-
// perform particle collisions
519-
ExecutePythonCallback("beforecollisions");
520-
mypc->doCollisions(a_step, a_cur_time, a_dt);
521-
ExecutePythonCallback("aftercollisions");
521+
// perform particle collisions
522+
ExecutePythonCallback("beforecollisions");
523+
mypc->doCollisions(a_step, a_cur_time, a_dt);
524+
ExecutePythonCallback("aftercollisions");
522525

523-
// push particles (half position)
524-
PushParticlesandDeposit(
525-
a_cur_time,
526-
/*skip_current=*/false,
527-
PositionPushType::SecondHalf,
528-
MomentumPushType::None
529-
);
526+
// push particles (half position)
527+
PushParticlesandDeposit(
528+
a_cur_time,
529+
/*skip_current=*/false,
530+
PositionPushType::SecondHalf,
531+
MomentumPushType::None
532+
);
533+
}
534+
// with collisions placed before the position and momentum push, or without collisions
535+
else {
536+
// perform particle collisions
537+
ExecutePythonCallback("beforecollisions");
538+
mypc->doCollisions(a_step, a_cur_time, a_dt);
539+
ExecutePythonCallback("aftercollisions");
540+
541+
// push particles (half position)
542+
PushParticlesandDeposit(
543+
a_cur_time,
544+
/*skip_current=*/false,
545+
PositionPushType::Full,
546+
MomentumPushType::Full
547+
);
548+
}
530549

531550
ExecutePythonCallback("afterdeposition");
532551

Source/Particles/MultiParticleContainer.H

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,7 @@ class MultiParticleContainer
6969

7070
public:
7171

72-
MultiParticleContainer (
73-
amrex::AmrCore* amr_core,
74-
bool const collisions_split_position_push
75-
);
72+
MultiParticleContainer (amrex::AmrCore* amr_core);
7673

7774
~MultiParticleContainer() = default;
7875

Source/Particles/MultiParticleContainer.cpp

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,9 @@ namespace
9292
};
9393
}
9494

95-
MultiParticleContainer::MultiParticleContainer (
96-
AmrCore* amr_core,
97-
bool const collisions_split_position_push
98-
)
95+
MultiParticleContainer::MultiParticleContainer (AmrCore* amr_core)
9996
{
97+
10098
ReadParameters();
10199

102100
auto const nspecies = static_cast<int>(species_names.size());
@@ -105,28 +103,13 @@ MultiParticleContainer::MultiParticleContainer (
105103
allcontainers.resize(nspecies + nlasers);
106104
for (int i = 0; i < nspecies; ++i) {
107105
if (species_types[i] == PCTypes::Physical) {
108-
allcontainers[i] = std::make_unique<PhysicalParticleContainer>(
109-
amr_core,
110-
/*ispecies=*/i,
111-
/*name=*/species_names[i],
112-
collisions_split_position_push
113-
);
106+
allcontainers[i] = std::make_unique<PhysicalParticleContainer>(amr_core, i, species_names[i]);
114107
}
115108
else if (species_types[i] == PCTypes::RigidInjected) {
116-
allcontainers[i] = std::make_unique<RigidInjectedParticleContainer>(
117-
amr_core,
118-
/*ispecies=*/i,
119-
/*name=*/species_names[i],
120-
collisions_split_position_push
121-
);
109+
allcontainers[i] = std::make_unique<RigidInjectedParticleContainer>(amr_core, i, species_names[i]);
122110
}
123111
else if (species_types[i] == PCTypes::Photon) {
124-
allcontainers[i] = std::make_unique<PhotonParticleContainer>(
125-
amr_core,
126-
/*ispecies=*/i,
127-
/*name=*/species_names[i],
128-
collisions_split_position_push
129-
);
112+
allcontainers[i] = std::make_unique<PhotonParticleContainer>(amr_core, i, species_names[i]);
130113
}
131114
allcontainers[i]->m_deposit_on_main_grid = m_deposit_on_main_grid[i];
132115
allcontainers[i]->m_gather_from_main_grid = m_gather_from_main_grid[i];

Source/Particles/PhotonParticleContainer.H

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,9 @@ class PhotonParticleContainer
3333
: public PhysicalParticleContainer
3434
{
3535
public:
36-
PhotonParticleContainer (
37-
amrex::AmrCore* amr_core,
38-
int ispecies,
39-
const std::string& name,
40-
bool const collisions_split_position_push
41-
);
42-
36+
PhotonParticleContainer (amrex::AmrCore* amr_core,
37+
int ispecies,
38+
const std::string& name);
4339
~PhotonParticleContainer () override = default;
4440

4541
PhotonParticleContainer ( PhotonParticleContainer const &) = delete;

Source/Particles/PhotonParticleContainer.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,9 @@
4343

4444
using namespace amrex;
4545

46-
PhotonParticleContainer::PhotonParticleContainer (
47-
AmrCore* amr_core,
48-
int ispecies,
49-
const std::string& name,
50-
bool const collisions_split_position_push
51-
) : PhysicalParticleContainer(amr_core, ispecies, name, collisions_split_position_push)
46+
PhotonParticleContainer::PhotonParticleContainer (AmrCore* amr_core, int ispecies,
47+
const std::string& name)
48+
: PhysicalParticleContainer(amr_core, ispecies, name)
5249
{
5350
const ParmParse pp_species_name(species_name);
5451

Source/Particles/PhysicalParticleContainer.H

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,9 @@ class PhysicalParticleContainer
4949
{
5050
public:
5151

52-
PhysicalParticleContainer (
53-
amrex::AmrCore* amr_core,
54-
int ispecies,
55-
const std::string& name,
56-
bool const collisions_split_position_push
57-
);
52+
PhysicalParticleContainer (amrex::AmrCore* amr_core,
53+
int ispecies,
54+
const std::string& name);
5855

5956
PhysicalParticleContainer (amrex::AmrCore* amr_core);
6057

@@ -498,13 +495,6 @@ protected:
498495
/* Vector of user-defined parser for initializing user-defined real attributes */
499496
amrex::Vector< std::unique_ptr<amrex::Parser> > m_user_real_attrib_parser;
500497

501-
/**
502-
* \brief Local copy of the WarpX class attribute that controls whether collisions
503-
* are placed in the middle of the position push and after the momentum push,
504-
* or before both the position and momentum push. The default value
505-
* is set in WarpX::ReadParameters().
506-
*/
507-
bool m_collisions_split_position_push;
508498
};
509499

510500
#endif

Source/Particles/PhysicalParticleContainer.cpp

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,10 @@
116116

117117
using namespace amrex;
118118

119-
PhysicalParticleContainer::PhysicalParticleContainer (
120-
AmrCore* amr_core,
121-
int ispecies,
122-
const std::string& name,
123-
bool const collisions_split_position_push
124-
) : WarpXParticleContainer(amr_core, ispecies),
125-
species_name(name),
126-
m_collisions_split_position_push(collisions_split_position_push)
119+
PhysicalParticleContainer::PhysicalParticleContainer (AmrCore* amr_core, int ispecies,
120+
const std::string& name)
121+
: WarpXParticleContainer(amr_core, ispecies),
122+
species_name(name)
127123
{
128124
BackwardCompatibility();
129125

@@ -341,13 +337,11 @@ PhysicalParticleContainer::PhysicalParticleContainer (
341337
m_boundary_conditions.SetThermalVelocity(boundary_uth);
342338
}
343339

344-
// If the position push is split to perform collisions, add the
345-
// average momentum components to deposit the current correctly
346-
if (m_collisions_split_position_push) {
347-
this->AddRealComp("ux_avg", /*communicate=*/0);
348-
this->AddRealComp("uy_avg", /*communicate=*/0);
349-
this->AddRealComp("uz_avg", /*communicate=*/0);
350-
}
340+
// Add the average momentum components to deposit the current correctly
341+
// if the position push is split to perform collisions
342+
this->AddRealComp("ux_avg", /*communicate=*/0);
343+
this->AddRealComp("uy_avg", /*communicate=*/0);
344+
this->AddRealComp("uz_avg", /*communicate=*/0);
351345
}
352346

353347
void
@@ -477,7 +471,6 @@ PhysicalParticleContainer::Evolve (ablastr::fields::MultiFabRegister& fields,
477471
!do_not_deposit &&
478472
(position_push_type == PositionPushType::Full || position_push_type == PositionPushType::FirstHalf)
479473
);
480-
// FIXME Check the logic here
481474
bool const deposit_current = (
482475
!skip_deposition &&
483476
!do_not_deposit &&
@@ -516,9 +509,9 @@ PhysicalParticleContainer::Evolve (ablastr::fields::MultiFabRegister& fields,
516509
// Extract particle data
517510
auto& attribs = pti.GetAttribs();
518511
auto& wp = attribs[PIdx::w];
519-
auto& uxp = (m_collisions_split_position_push) ? pti.GetAttribs("ux_avg") : attribs[PIdx::ux];
520-
auto& uyp = (m_collisions_split_position_push) ? pti.GetAttribs("uy_avg") : attribs[PIdx::uy];
521-
auto& uzp = (m_collisions_split_position_push) ? pti.GetAttribs("uz_avg") : attribs[PIdx::uz];
512+
auto& uxp = pti.GetAttribs("ux_avg");
513+
auto& uyp = pti.GetAttribs("uy_avg");
514+
auto& uzp = pti.GetAttribs("uz_avg");
522515

523516
const long np = pti.numParticles();
524517

@@ -1347,9 +1340,9 @@ PhysicalParticleContainer::PushPX (WarpXParIter& pti,
13471340
ParticleReal* const AMREX_RESTRICT uz = attribs[PIdx::uz].dataPtr() + offset;
13481341

13491342
// Average momentum
1350-
amrex::ParticleReal* const AMREX_RESTRICT ux_avg = pti.GetAttribs("ux_avg").dataPtr() + offset;
1351-
amrex::ParticleReal* const AMREX_RESTRICT uy_avg = pti.GetAttribs("uy_avg").dataPtr() + offset;
1352-
amrex::ParticleReal* const AMREX_RESTRICT uz_avg = pti.GetAttribs("uz_avg").dataPtr() + offset;
1343+
amrex::ParticleReal* AMREX_RESTRICT ux_avg = pti.GetAttribs("ux_avg").dataPtr() + offset;
1344+
amrex::ParticleReal* AMREX_RESTRICT uy_avg = pti.GetAttribs("uy_avg").dataPtr() + offset;
1345+
amrex::ParticleReal* AMREX_RESTRICT uz_avg = pti.GetAttribs("uz_avg").dataPtr() + offset;
13531346

13541347
CopyParticleAttribs copyAttribs;
13551348
if (copy_particle_attribs) {
@@ -1491,6 +1484,7 @@ PhysicalParticleContainer::PushPX (WarpXParIter& pti,
14911484
}
14921485
#endif
14931486
// Update average momentum
1487+
// FIXME Improve the logic here
14941488
if (momentum_push_type != MomentumPushType::None) {
14951489
ux_avg[ip] = ux[ip];
14961490
uy_avg[ip] = uy[ip];

Source/Particles/RigidInjectedParticleContainer.H

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,9 @@ class RigidInjectedParticleContainer
4848
: public PhysicalParticleContainer
4949
{
5050
public:
51-
RigidInjectedParticleContainer (
52-
amrex::AmrCore* amr_core,
53-
int ispecies,
54-
const std::string& name,
55-
bool const collisions_split_position_push
56-
);
57-
51+
RigidInjectedParticleContainer (amrex::AmrCore* amr_core,
52+
int ispecies,
53+
const std::string& name);
5854
~RigidInjectedParticleContainer () override = default;
5955

6056
RigidInjectedParticleContainer ( RigidInjectedParticleContainer const &) = delete;

Source/Particles/RigidInjectedParticleContainer.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,9 @@
5656

5757
using namespace amrex;
5858

59-
RigidInjectedParticleContainer::RigidInjectedParticleContainer (
60-
AmrCore* amr_core,
61-
int ispecies,
62-
const std::string& name,
63-
bool const collisions_split_position_push
64-
) : PhysicalParticleContainer(amr_core, ispecies, name, collisions_split_position_push)
59+
RigidInjectedParticleContainer::RigidInjectedParticleContainer (AmrCore* amr_core, int ispecies,
60+
const std::string& name)
61+
: PhysicalParticleContainer(amr_core, ispecies, name)
6562
{
6663

6764
#if defined(WARPX_DIM_RCYLINDER) || defined(WARPX_DIM_RSPHERE)

Source/WarpX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ WarpX::WarpX ()
346346
t_old.resize(nlevs_max, std::numeric_limits<Real>::lowest());
347347
dt.resize(nlevs_max, std::numeric_limits<Real>::max());
348348

349-
mypc = std::make_unique<MultiParticleContainer>(this, m_collisions_split_position_push);
349+
mypc = std::make_unique<MultiParticleContainer>(this);
350350

351351
// Loop over species (particles and lasers)
352352
// and set current injection position per species

0 commit comments

Comments
 (0)