Skip to content

Commit 9544dfa

Browse files
committed
test_mparticles: +RandomOffsets
1 parent d108d7d commit 9544dfa

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

src/libpsc/tests/test_mparticles.cxx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
#include <gtest/gtest.h>
3+
#include <gtensor/reductions.h>
34

45
#include "test_common.hxx"
56

@@ -8,6 +9,7 @@
89
#include "../libpsc/vpic/PscParticlesBase.h"
910
#include "../libpsc/vpic/mparticles_vpic.hxx"
1011
#include "../libpsc/vpic/vpic_config.h"
12+
#include "../libpsc/psc_output_fields/fields_item_moments_1st.hxx"
1113
#include "psc_particles_double.h"
1214
#include "psc_particles_single.h"
1315
#include "particle_with_id.h"
@@ -543,6 +545,35 @@ TEST(TestSetupParticles, Tag)
543545
}
544546
}
545547

548+
TEST(TestSetupParticles, RandomOffsets)
549+
{
550+
using Mparticles = MparticlesDouble;
551+
using a = Mfields<double>;
552+
using MomentRho =
553+
psc::moment::moment_rho<psc::deposit::code::Deposit1stNc, dim_yz>;
554+
555+
auto domain = Grid_t::Domain{{1, 2, 2}, {10., 20., 20.}, {}, {1, 1, 1}};
556+
auto kinds = Grid_t::Kinds{{1., 100., "i"}, {-1., 1., "e"}};
557+
auto prm = Grid_t::NormalizationParams::dimensionless();
558+
prm.nicell = 10;
559+
Grid_t grid{domain, {}, kinds, {prm}, .1};
560+
Mparticles mprts{grid};
561+
562+
SetupParticles<Mparticles> setup_particles(grid);
563+
setup_particles.random_offsets = true;
564+
setup_particles.setupParticles(
565+
mprts, [&](int kind, Double3 crd, psc_particle_npt& npt) { npt.n = 1; });
566+
567+
auto n_cells =
568+
grid.domain.gdims[0] * grid.domain.gdims[1] * grid.domain.gdims[2];
569+
EXPECT_EQ(mprts.size(), n_cells * kinds.size() * prm.nicell);
570+
571+
auto rho =
572+
psc::mflds::zeros<double, gt::space::host>(mprts.grid(), 1, -grid.ibn);
573+
MomentRho{}(rho, -grid.ibn, mprts);
574+
ASSERT_LT(gt::norm_linf(rho), 1e-16);
575+
}
576+
546577
int main(int argc, char** argv)
547578
{
548579
MPI_Init(&argc, &argv);

0 commit comments

Comments
 (0)