aboutsummaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/Diagnostics/FlushFormats/FlushFormatPlotfile.cpp10
-rw-r--r--Source/Particles/Filter/FilterFunctors.H29
2 files changed, 29 insertions, 10 deletions
diff --git a/Source/Diagnostics/FlushFormats/FlushFormatPlotfile.cpp b/Source/Diagnostics/FlushFormats/FlushFormatPlotfile.cpp
index 6b5f94ac8..6676841b2 100644
--- a/Source/Diagnostics/FlushFormats/FlushFormatPlotfile.cpp
+++ b/Source/Diagnostics/FlushFormats/FlushFormatPlotfile.cpp
@@ -268,7 +268,7 @@ FlushFormatPlotfile::WriteParticles(const std::string& dir,
for (unsigned i = 0, n = particle_diags.size(); i < n; ++i) {
WarpXParticleContainer* pc = particle_diags[i].getParticleContainer();
- amrex::ParticleContainer<0, 0, PIdx::nattribs> tmp(pc->GetParGDB());
+ PhysicalParticleContainer tmp(&WarpX::GetInstance());
Vector<std::string> real_names;
Vector<std::string> int_names;
Vector<int> int_flags;
@@ -304,15 +304,16 @@ FlushFormatPlotfile::WriteParticles(const std::string& dir,
}
#endif
- // Convert momentum to SI
pc->ConvertUnits(ConvertDirection::WarpX_to_SI);
RandomFilter const random_filter(particle_diags[i].m_do_random_filter,
particle_diags[i].m_random_fraction);
UniformFilter const uniform_filter(particle_diags[i].m_do_uniform_filter,
particle_diags[i].m_uniform_stride);
- ParserFilter const parser_filter(particle_diags[i].m_do_parser_filter,
- getParser(particle_diags[i].m_particle_filter_parser));
+ ParserFilter parser_filter(particle_diags[i].m_do_parser_filter,
+ getParser(particle_diags[i].m_particle_filter_parser),
+ pc->getMass());
+ parser_filter.m_units = InputUnits::SI;
GeometryFilter const geometry_filter(particle_diags[i].m_do_geom_filter,
particle_diags[i].m_diag_domain);
@@ -332,7 +333,6 @@ FlushFormatPlotfile::WriteParticles(const std::string& dir,
particle_diags[i].plot_flags, int_flags,
real_names, int_names);
- // Convert momentum back to WarpX units
pc->ConvertUnits(ConvertDirection::SI_to_WarpX);
}
}
diff --git a/Source/Particles/Filter/FilterFunctors.H b/Source/Particles/Filter/FilterFunctors.H
index 5b6a3f323..02db6a2a2 100644
--- a/Source/Particles/Filter/FilterFunctors.H
+++ b/Source/Particles/Filter/FilterFunctors.H
@@ -17,6 +17,13 @@
using SuperParticleType = typename WarpXParticleContainer::SuperParticleType;
/**
+ * \brief Used to keep track of what inputs units a filter function should expect.
+ * "WarpX units" means the momentum is "gamma*v" (aka proper velocity)
+ * "SI" means the momentum is mass*gamma*v.
+ */
+enum struct InputUnits{WarpX, SI};
+
+/**
* \brief Functor that returns 0 or 1 depending on a random draw per particle
*/
struct RandomFilter
@@ -82,10 +89,11 @@ struct ParserFilter
/** constructor
* \param a_is_active whether the test is active
*/
- ParserFilter(bool a_is_active, HostDeviceParser<7> const& a_filter_parser)
- : m_is_active(a_is_active), m_function_partparser(a_filter_parser)
+ ParserFilter(bool a_is_active, HostDeviceParser<7> const& a_filter_parser, amrex::Real a_mass)
+ : m_is_active(a_is_active), m_function_partparser(a_filter_parser), m_mass(a_mass)
{
m_t = WarpX::GetInstance().gett_new(0);
+ m_units = InputUnits::WarpX;
}
/**
@@ -100,9 +108,16 @@ struct ParserFilter
amrex::Real const x = p.pos(0);
amrex::Real const y = p.pos(1);
amrex::Real const z = p.pos(2);
- amrex::Real const ux = p.rdata(PIdx::ux)/PhysConst::c;
- amrex::Real const uy = p.rdata(PIdx::uy)/PhysConst::c;
- amrex::Real const uz = p.rdata(PIdx::uz)/PhysConst::c;
+ amrex::Real ux = p.rdata(PIdx::ux)/PhysConst::c;
+ amrex::Real uy = p.rdata(PIdx::uy)/PhysConst::c;
+ amrex::Real uz = p.rdata(PIdx::uz)/PhysConst::c;
+ if (m_units == InputUnits::SI)
+ {
+ ux /= m_mass;
+ uy /= m_mass;
+ uz /= m_mass;
+ }
+ // ux, uy, uz are now in beta*gamma
if ( m_function_partparser(m_t,x,y,z,ux,uy,uz) > 0.5 ) return 1;
else return 0;
}
@@ -114,6 +129,10 @@ public:
HostDeviceParser<7> const m_function_partparser;
/** Store physical time. */
amrex::Real m_t;
+ /** Mass of particle species */
+ amrex::Real m_mass;
+ /** keep track of momentum units particles will come in with **/
+ InputUnits m_units;
};