Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] FieldReduction.H : make volume calculation more compact using std::reduce over dx vector #5691

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions Source/Diagnostics/ReducedDiags/FieldReduction.H
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <AMReX_Tuple.H>

#include <memory>
#include <numeric>
#include <string>
#include <type_traits>
#include <vector>
Expand Down Expand Up @@ -225,15 +226,10 @@ public:
if (std::is_same_v<ReduceOp, amrex::ReduceOpSum>)
{
amrex::ParallelDescriptor::ReduceRealSum(reduce_value);
// If reduction operation is a sum, multiply the value by the cell volume so that the
// result is the integral of the function over the simulation domain.
#if defined(WARPX_DIM_1D_Z)
reduce_value *= dx[0];
#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
reduce_value *= dx[0]*dx[1];
#else
reduce_value *= dx[0]*dx[1]*dx[2];
#endif
// If reduction operation is a sum, multiply the value by the cell volume so that the
// result is the integral of the function over the simulation domain.
const auto cell_volume = std::reduce(std::begin(dx), std::end(dx), 1.0_rt, std::multiplies<>());
reduce_value *= cell_volume;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've done things like this, which is also compact

reduce_value *= AMREX_D_TERM(dx[0], *dx[1], *dx[2]);

In fact, I already make this change in PR #5189.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see... sorry! Then, this PR has no reason to exist. I will close it immediately!


// Fill output array
Expand Down
Loading