|
1 | 1 |
|
2 | 2 | #include <gtest/gtest.h> |
| 3 | +#include <gtensor/reductions.h> |
3 | 4 |
|
4 | 5 | #include "test_common.hxx" |
5 | 6 |
|
|
8 | 9 | #include "../libpsc/vpic/PscParticlesBase.h" |
9 | 10 | #include "../libpsc/vpic/mparticles_vpic.hxx" |
10 | 11 | #include "../libpsc/vpic/vpic_config.h" |
| 12 | +#include "../libpsc/psc_output_fields/fields_item_moments_1st.hxx" |
11 | 13 | #include "psc_particles_double.h" |
12 | 14 | #include "psc_particles_single.h" |
13 | 15 | #include "particle_with_id.h" |
@@ -543,6 +545,35 @@ TEST(TestSetupParticles, Tag) |
543 | 545 | } |
544 | 546 | } |
545 | 547 |
|
| 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 | + |
546 | 577 | int main(int argc, char** argv) |
547 | 578 | { |
548 | 579 | MPI_Init(&argc, &argv); |
|
0 commit comments