Skip to content

Commit

Permalink
Dist None: Set to Zero (#465)
Browse files Browse the repository at this point in the history
With GCC 12, compiling the `None` distribution throws warnings in
compilation of `add_particles`. Originally, this was added so that
the `std::variant` for `impactx::distribution::KnownDistributions`
creates a default constructor for the variant.

Adding an assert that the distribution cannot be used in
`add_particles` does not silence the warning diagnostics.
Thus, we simply make it a distribution that sets the values to
zero.
  • Loading branch information
ax3l authored Nov 15, 2023
1 parent 495c7d3 commit c8a165a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/source/usage/python.rst
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ This module provides particle beam distributions that can be used to initialize

.. py:class:: impactx.distribution.None
This distribution does nothing.
This distribution sets all values to zero.

.. py:class:: impactx.distribution.Semigaussian(sigx, sigy, sigt, sigpx, sigpy, sigpt, muxpx=0.0, muypy=0.0, mutpt=0.0)
Expand Down
1 change: 1 addition & 0 deletions src/initialization/InitDistribution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <AMReX_Print.H>

#include <string>
#include <variant>


namespace impactx
Expand Down
25 changes: 16 additions & 9 deletions src/particles/distribution/None.H
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ namespace impactx::distribution
{
struct None
{
/** This distribution does nothing
/** This distribution sets all values to zero.
*/
None()
{
}

/** Return 1 6D particle coordinate
*
* Does nothing to the parameters.
* Sets all values to zero.
*
* @param x particle position in x
* @param y particle position in y
Expand All @@ -38,15 +38,22 @@ namespace impactx::distribution
*/
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
void operator() (
[[maybe_unused]] amrex::ParticleReal & x,
[[maybe_unused]] amrex::ParticleReal & y,
[[maybe_unused]] amrex::ParticleReal & t,
[[maybe_unused]] amrex::ParticleReal & px,
[[maybe_unused]] amrex::ParticleReal & py,
[[maybe_unused]] amrex::ParticleReal & pt,
amrex::ParticleReal & x,
amrex::ParticleReal & y,
amrex::ParticleReal & t,
amrex::ParticleReal & px,
amrex::ParticleReal & py,
amrex::ParticleReal & pt,
[[maybe_unused]] amrex::RandomEngine const& engine) const
{
/* nothing to do */
using namespace amrex::literals;

x = 0_prt;
y = 0_prt;
t = 0_prt;
px = 0_prt;
py = 0_prt;
pt = 0_prt;
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/python/distribution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void init_distribution(py::module& m)

py::class_<distribution::None>(md, "None")
.def(py::init<>(),
"This distribution does nothing"
"Sets all values to zero."
);

py::class_<distribution::Semigaussian>(md, "Semigaussian")
Expand Down

0 comments on commit c8a165a

Please sign in to comment.