Skip to content

Commit

Permalink
float -> double promotion #556
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipDeegan committed Mar 14, 2022
1 parent a215bda commit 771dbca
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
19 changes: 12 additions & 7 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 @@ -64,19 +67,21 @@ class PatternDispatcher
using FineParticle = decltype(particles[0]); // may be a reference

core::apply(patterns, [&](auto const& pattern) {
auto weight = static_cast<Weight_t>(pattern.weight_);
for (size_t rpIndex = 0; rpIndex < pattern.deltas_.size(); rpIndex++)
{
FineParticle fineParticle = particles[idx++];
fineParticle.weight = particle.weight * pattern.weight_ * power[dimension - 1];
fineParticle.charge = particle.charge;
fineParticle.iCell = particle.iCell;
fineParticle.delta = particle.delta;
fineParticle.v = particle.v;
fineParticle.weight = particle.weight * 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: 2 additions & 0 deletions src/core/utilities/meta/meta_utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ namespace core
SimulatorOption<DimConst<2>, InterpConst<2>, 4, 5, 8, 9, 16>,
SimulatorOption<DimConst<2>, InterpConst<3>, 4, 5, 8, 9, 25>,

// TODO add in the rest of 3d nbrParticles permutations
// possibly consider compile time activation for uncommon cases
SimulatorOption<DimConst<3>, InterpConst<1>, 6, 12 /*, 27*/>,
SimulatorOption<DimConst<3>, InterpConst<2>, 6, 12>,
SimulatorOption<DimConst<3>, InterpConst<3>, 6, 12>>{};
Expand Down
18 changes: 6 additions & 12 deletions tests/core/numerics/pusher/test_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,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, selector, layout);

Expand All @@ -203,10 +200,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, selector, layout);

Expand All @@ -227,8 +222,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, selector, layout);

Expand Down

0 comments on commit 771dbca

Please sign in to comment.