Skip to content

Commit

Permalink
Merge pull request #774 from PhilipDeegan/float_promote
Browse files Browse the repository at this point in the history
double promotion werror
  • Loading branch information
nicolasaunai authored Nov 14, 2023
2 parents cffbb1e + 9cff7ae commit d183651
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 32 deletions.
1 change: 1 addition & 0 deletions res/cmake/def.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ if(devMode) # -DdevMode=ON
# Having quotes on strings here has lead to quotes being added to the compile string, so avoid.

set (_Werr ${PHARE_WERROR_FLAGS} -Wall -Wextra -pedantic -Werror -Wno-unused-variable -Wno-unused-parameter)
set (_Werr ${_Werr} -Wdouble-promotion)

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set (_Werr ${_Werr} -Wno-gnu-zero-variadic-macro-arguments)
Expand Down
11 changes: 8 additions & 3 deletions src/amr/data/particles/refine/splitter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class PatternDispatcher
template<typename Particle, typename Particles>
void dispatch(Particle const& particle, Particles& particles, size_t idx) const
{
using Weight_t = std::decay_t<decltype(particle.weight)>;
using Delta_t = std::decay_t<decltype(particle.delta[0])>;

constexpr auto dimension = Particle::dimension;
constexpr auto refRatio = PHARE::amr::refinementRatio;
constexpr std::array power{refRatio, refRatio * refRatio, refRatio * refRatio * refRatio};
Expand All @@ -67,16 +70,18 @@ class PatternDispatcher
for (size_t rpIndex = 0; rpIndex < pattern.deltas_.size(); rpIndex++)
{
FineParticle fineParticle = particles[idx++];
fineParticle.weight = particle.weight * pattern.weight_ * power[dimension - 1];
fineParticle.weight = particle.weight * static_cast<Weight_t>(pattern.weight_)
* power[dimension - 1];
fineParticle.charge = particle.charge;
fineParticle.iCell = particle.iCell;
fineParticle.delta = particle.delta;
fineParticle.v = particle.v;

for (size_t iDim = 0; iDim < dimension; iDim++)
{
fineParticle.delta[iDim] += pattern.deltas_[rpIndex][iDim];
float integra = std::floor(fineParticle.delta[iDim]);
fineParticle.delta[iDim]
+= static_cast<Delta_t>(pattern.deltas_[rpIndex][iDim]);
Delta_t integra = std::floor(fineParticle.delta[iDim]);
fineParticle.delta[iDim] -= integra;
fineParticle.iCell[iDim] += static_cast<int32_t>(integra);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/core/data/particles/test_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class AParticle : public ::testing::Test

public:
AParticle()
: part{0.01, 1., {43, 75, 92}, {0.002f, 0.2f, 0.8f}, {1.8, 1.83, 2.28}}
: part{0.01, 1., {43, 75, 92}, {0.002, 0.2, 0.8}, {1.8, 1.83, 2.28}}
{
}
};
Expand Down
30 changes: 15 additions & 15 deletions tests/core/numerics/interpolator/test_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class A1DInterpolator : public ::testing::Test
for (auto& part : particles)
{
part.iCell[0] = 5;
part.delta[0] = 0.32f;
part.delta[0] = 0.32;
}
}
};
Expand Down Expand Up @@ -397,7 +397,7 @@ class A2DInterpolator : public ::testing::Test
for (auto& part : particles)
{
part.iCell[0] = 5;
part.delta[0] = 0.32f;
part.delta[0] = 0.32;
}
}
};
Expand Down Expand Up @@ -525,7 +525,7 @@ class A3DInterpolator : public ::testing::Test
for (auto& part : particles)
{
part.iCell[0] = 5;
part.delta[0] = 0.32f;
part.delta[0] = 0.32;
}
}
};
Expand Down Expand Up @@ -641,23 +641,23 @@ class ACollectionOfParticles_1d : public ::testing::Test
if constexpr (Interpolator::interp_order == 1)
{
part.iCell[0] = 19; // AMR index
part.delta[0] = 0.5f;
part.delta[0] = 0.5;
part.weight = 1.0;
part.v[0] = +2.;
part.v[1] = -1.;
part.v[2] = +1.;
particles.push_back(part);

part.iCell[0] = 20; // AMR index
part.delta[0] = 0.5f;
part.delta[0] = 0.5;
part.weight = 0.4;
part.v[0] = +2.;
part.v[1] = -1.;
part.v[2] = +1.;
particles.push_back(part);

part.iCell[0] = 20; // AMR index
part.delta[0] = 0.5f;
part.delta[0] = 0.5;
part.weight = 0.6;
part.v[0] = +2.;
part.v[1] = -1.;
Expand All @@ -668,31 +668,31 @@ class ACollectionOfParticles_1d : public ::testing::Test
if constexpr (Interpolator::interp_order == 2)
{
part.iCell[0] = 19; // AMR index
part.delta[0] = 0.0f;
part.delta[0] = 0.0;
part.weight = 1.0;
part.v[0] = +2.;
part.v[1] = -1.;
part.v[2] = +1.;
particles.push_back(part);

part.iCell[0] = 20; // AMR index
part.delta[0] = 0.0f;
part.delta[0] = 0.0;
part.weight = 0.2;
part.v[0] = +2.;
part.v[1] = -1.;
part.v[2] = +1.;
particles.push_back(part);

part.iCell[0] = 20; // AMR index
part.delta[0] = 0.0f;
part.delta[0] = 0.0;
part.weight = 0.8;
part.v[0] = +2.;
part.v[1] = -1.;
part.v[2] = +1.;
particles.push_back(part);

part.iCell[0] = 21; // AMR index
part.delta[0] = 0.0f;
part.delta[0] = 0.0;
part.weight = 1.0;
part.v[0] = +2.;
part.v[1] = -1.;
Expand All @@ -703,39 +703,39 @@ class ACollectionOfParticles_1d : public ::testing::Test
if constexpr (Interpolator::interp_order == 3)
{
part.iCell[0] = 18; // AMR index
part.delta[0] = 0.5f;
part.delta[0] = 0.5;
part.weight = 1.0;
part.v[0] = +2.;
part.v[1] = -1.;
part.v[2] = +1.;
particles.push_back(part);

part.iCell[0] = 19; // AMR index
part.delta[0] = 0.5f;
part.delta[0] = 0.5;
part.weight = 1.0;
part.v[0] = +2.;
part.v[1] = -1.;
part.v[2] = +1.;
particles.push_back(part);

part.iCell[0] = 20; // AMR index
part.delta[0] = 0.5f;
part.delta[0] = 0.5;
part.weight = 1.0;
part.v[0] = +2.;
part.v[1] = -1.;
part.v[2] = +1.;
particles.push_back(part);

part.iCell[0] = 21; // AMR index
part.delta[0] = 0.5f;
part.delta[0] = 0.5;
part.weight = 0.1;
part.v[0] = +2.;
part.v[1] = -1.;
part.v[2] = +1.;
particles.push_back(part);

part.iCell[0] = 21; // AMR index
part.delta[0] = 0.5f;
part.delta[0] = 0.5;
part.weight = 0.9;
part.v[0] = +2.;
part.v[1] = -1.;
Expand Down
20 changes: 7 additions & 13 deletions tests/core/numerics/pusher/test_pusher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,9 @@ TEST_F(APusher3D, trajectoryIsOk)

for (decltype(nt) i = 0; i < nt; ++i)
{
actual[0][i]
= (particlesOut[0].iCell[0] + particlesOut[0].delta[0]) * static_cast<float>(dxyz[0]);
actual[1][i]
= (particlesOut[0].iCell[1] + particlesOut[0].delta[1]) * static_cast<float>(dxyz[1]);
actual[2][i]
= (particlesOut[0].iCell[2] + particlesOut[0].delta[2]) * static_cast<float>(dxyz[2]);
actual[0][i] = (particlesOut[0].iCell[0] + particlesOut[0].delta[0]) * dxyz[0];
actual[1][i] = (particlesOut[0].iCell[1] + particlesOut[0].delta[1]) * dxyz[1];
actual[2][i] = (particlesOut[0].iCell[2] + particlesOut[0].delta[2]) * dxyz[2];

pusher->move(
rangeIn, rangeOut, em, mass, interpolator, layout,
Expand All @@ -206,10 +203,8 @@ TEST_F(APusher2D, trajectoryIsOk)

for (decltype(nt) i = 0; i < nt; ++i)
{
actual[0][i]
= (particlesOut[0].iCell[0] + particlesOut[0].delta[0]) * static_cast<float>(dxyz[0]);
actual[1][i]
= (particlesOut[0].iCell[1] + particlesOut[0].delta[1]) * static_cast<float>(dxyz[1]);
actual[0][i] = (particlesOut[0].iCell[0] + particlesOut[0].delta[0]) * dxyz[0];
actual[1][i] = (particlesOut[0].iCell[1] + particlesOut[0].delta[1]) * dxyz[1];

pusher->move(
rangeIn, rangeOut, em, mass, interpolator, layout, [](auto& rge) { return rge; },
Expand All @@ -232,8 +227,7 @@ TEST_F(APusher1D, trajectoryIsOk)

for (decltype(nt) i = 0; i < nt; ++i)
{
actual[0][i]
= (particlesOut[0].iCell[0] + particlesOut[0].delta[0]) * static_cast<float>(dxyz[0]);
actual[0][i] = (particlesOut[0].iCell[0] + particlesOut[0].delta[0]) * dxyz[0];

pusher->move(rangeIn, rangeOut, em, mass, interpolator, layout, selector, selector);

Expand Down Expand Up @@ -270,7 +264,7 @@ class APusherWithLeavingParticles : public ::testing::Test
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> dis(0, 9);
std::uniform_real_distribution<float> delta(0, 1);
std::uniform_real_distribution<double> delta(0, 1);

for (std::size_t iPart = 0; iPart < 1000; ++iPart)
{
Expand Down

0 comments on commit d183651

Please sign in to comment.