-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathtest_main.cpp
733 lines (573 loc) · 22.9 KB
/
test_main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <algorithm>
#include <array>
#include <cmath>
#include <cstddef>
#include <fstream>
#include <list>
#include <random>
#include "core/utilities/box/box.hpp"
#include "core/utilities/range/range.hpp"
#include "phare_core.hpp"
#include "core/data/electromag/electromag.hpp"
#include "core/data/field/field.hpp"
#include "core/data/grid/gridlayout.hpp"
#include "core/data/grid/gridlayout_impl.hpp"
#include "core/data/ndarray/ndarray_vector.hpp"
#include "core/data/particles/particle.hpp"
#include "core/data/particles/particle_array.hpp"
#include "core/data/vecfield/vecfield.hpp"
#include "core/hybrid/hybrid_quantities.hpp"
#include "core/numerics/interpolator/interpolator.hpp"
#include "tests/core/data/vecfield/test_vecfield_fixtures.hpp"
using namespace PHARE::core;
template<typename Weighter>
class AWeighter : public ::testing::Test
{
public:
// All tests using this class are 1D and should remain that way or update this.
auto static constexpr dimension = 1;
auto static constexpr interp_order = Weighter::interp_order;
using GridLayout_t = GridLayout<GridLayoutImplYee<dimension, interp_order>>;
using Interpolator_t = Interpolator<dimension, interp_order>;
AWeighter()
{
std::random_device rd; // Will be used to obtain a seed for the random number engine
std::mt19937 gen(rd()); // Standard mersenne_twister_engine seeded with rd()
std::uniform_real_distribution<> dis(5, 10);
// generate the nbr_tests random (normalized) particle position
std::generate(std::begin(normalizedPositions), std::end(normalizedPositions),
[&dis, &gen]() { return dis(gen); });
// now for each random position, calculate
// the start index and the N(interp_order) weights
for (auto i = 0u; i < nbr_tests; ++i)
{
auto icell = static_cast<int>(normalizedPositions[i]);
auto delta = normalizedPositions[i] - icell;
auto startIndex
= icell
- Interpolator_t::template computeStartLeftShift<QtyCentering,
QtyCentering::primal>(delta);
this->weighter.computeWeight(normalizedPositions[i], startIndex, weights_[i]);
}
// for each particle, we have N(interp_order) weights
// the sum of these N(interp_order) weights for each particle is stored in weightsSum
std::transform(std::begin(weights_), std::end(weights_), std::begin(weightsSums),
[](auto const& weight_list) {
return std::accumulate(std::begin(weight_list), std::end(weight_list),
0.);
});
}
protected:
Weighter weighter;
static const int nbr_tests = 100000;
std::array<double, nbr_tests> normalizedPositions;
std::array<double, nbr_tests> weightsSums;
std::array<std::array<double, nbrPointsSupport(Weighter::interp_order)>, nbr_tests> weights_;
};
using Weighters = ::testing::Types<Weighter<1>, Weighter<2>, Weighter<3>>;
TYPED_TEST_SUITE(AWeighter, Weighters);
TYPED_TEST(AWeighter, ComputesWeightThatSumIsOne)
{
auto equalsOne = [](double sum) { return std::abs(sum - 1.) < 1e-10; };
EXPECT_TRUE(std::all_of(std::begin(this->weightsSums), std::end(this->weightsSums), equalsOne));
}
TEST(Weights, NbrPointsInBSplineSupportIsCorrect)
{
EXPECT_EQ(2, nbrPointsSupport(1));
EXPECT_EQ(3, nbrPointsSupport(2));
EXPECT_EQ(4, nbrPointsSupport(3));
}
struct BSpline
{
std::vector<std::vector<double>> weights;
std::vector<std::vector<int>> indexes;
};
// this function reads the indices and weights
// from the file generated by the python script interpolator_test.py
BSpline readFromFile(std::string centering, std::size_t order)
{
std::ostringstream oss;
oss << "bsplines_" << order << "_" << centering << ".dat";
std::ifstream file{oss.str()};
if (!file)
{
std::cout << "file not found\n";
}
BSpline bs;
bs.indexes.resize(10);
bs.weights.resize(10);
for (auto ipos = 0u; ipos < 10; ++ipos)
{
bs.indexes[ipos].resize(order + 1);
bs.weights[ipos].resize(order + 1);
file.read(reinterpret_cast<char*>(bs.indexes[ipos].data()),
static_cast<std::streamsize>(bs.indexes[ipos].size() * sizeof(int)));
file.read(reinterpret_cast<char*>(bs.weights[ipos].data()),
static_cast<std::streamsize>(bs.weights[ipos].size() * sizeof(double)));
}
return bs;
}
template<typename AWeighter_t, typename Centering, Centering centering, typename Weighter>
void check_bspline(Weighter& weighter, std::string centering_id)
{
using Interpolator_t = typename AWeighter_t::Interpolator_t;
constexpr auto interp_order = AWeighter_t::interp_order;
auto data = readFromFile(centering_id, interp_order);
std::array<double, nbrPointsSupport(interp_order)> weights;
// python file hard-codes 10 particle positions
// that start at x = 3 every 0.1
std::size_t const n_particles = 10;
double const icell = 3;
double const dx = 0.1;
for (auto ipos = 0u; ipos < n_particles; ++ipos)
{
auto delta = static_cast<double>(ipos) * dx;
auto startIndex
= icell - Interpolator_t::template computeStartLeftShift<Centering, centering>(delta);
double normalizedPosition = icell + delta;
if constexpr (centering == QtyCentering::dual)
normalizedPosition -= .5;
weighter.computeWeight(normalizedPosition, startIndex, weights);
for (auto inode = 0u; inode < weights.size(); ++inode)
{
std::cout << inode << " " << ipos << " " << data.weights[ipos][inode] << " =? "
<< weights[inode] << "\n";
EXPECT_DOUBLE_EQ(data.weights[ipos][inode], weights[inode]);
}
}
}
TYPED_TEST(AWeighter, computesPrimalBSplineWeightsForAnyParticlePosition)
{
using AWeighter_t = TestFixture;
using Interpolator_t = typename AWeighter_t::Interpolator_t;
using GridLayout_t = typename AWeighter_t::GridLayout_t;
static_assert(Interpolator_t::interp_order == GridLayout_t::interp_order);
assert(GridLayout_t::nbrGhosts() == Interpolator_t::interp_order + 1);
check_bspline<AWeighter_t, QtyCentering, QtyCentering::primal>(this->weighter, "primal");
}
TYPED_TEST(AWeighter, computesDualBSplineWeightsForAnyParticlePosition)
{
using AWeighter_t = TestFixture;
using Interpolator_t = typename AWeighter_t::Interpolator_t;
using GridLayout_t = typename AWeighter_t::GridLayout_t;
static_assert(Interpolator_t::interp_order == GridLayout_t::interp_order);
assert(GridLayout_t::nbrGhosts() == Interpolator_t::interp_order + 1);
check_bspline<AWeighter_t, QtyCentering, QtyCentering::dual>(this->weighter, "dual");
}
template<typename InterpolatorT>
class A1DInterpolator : public ::testing::Test
{
public:
static constexpr auto dimension = InterpolatorT::dimension;
static constexpr auto interp_order = InterpolatorT::interp_order;
// arbitrary number of cells
static constexpr std::uint32_t nx = 50;
using PHARE_TYPES = PHARE::core::PHARE_Types<dimension, interp_order>;
using GridLayout_t = typename PHARE_TYPES::GridLayout_t;
using ParticleArray_t = typename PHARE_TYPES::ParticleArray_t;
using Electromag_t = typename PHARE_TYPES::Electromag_t;
using UsableVecFieldND = UsableVecField<dimension>;
Electromag_t em;
GridLayout_t layout{{0.1}, {nx}, {0.}};
ParticleArray_t particles;
InterpolatorT interp;
constexpr static auto safeLayer = static_cast<int>(1 + ghostWidthForParticles<interp_order>());
UsableVecFieldND B, E;
static constexpr double ex0 = 2.25;
static constexpr double ey0 = 2.50;
static constexpr double ez0 = 2.75;
static constexpr double bx0 = 2.25;
static constexpr double by0 = 2.50;
static constexpr double bz0 = 2.75;
A1DInterpolator()
: em{"EM"}
, particles{grow(layout.AMRBox(), safeLayer), 1}
, B{"EM_B", layout, HybridQuantity::Vector::B}
, E{"EM_E", layout, HybridQuantity::Vector::E}
{
for (auto ix = 0u; ix < nx; ++ix) // B & E are constant on their grid
{
B(Component::X)(ix) = bx0;
B(Component::Y)(ix) = by0;
B(Component::Z)(ix) = bz0;
E(Component::X)(ix) = ex0;
E(Component::Y)(ix) = ey0;
E(Component::Z)(ix) = ez0;
}
for (auto& part : particles)
{
part.iCell[0] = 5;
part.delta[0] = 0.32;
}
B.set_on(em.B);
E.set_on(em.E);
}
};
using Interpolators1D
= ::testing::Types<Interpolator<1, 1>, Interpolator<1, 2>, Interpolator<1, 3>>;
TYPED_TEST_SUITE(A1DInterpolator, Interpolators1D);
TYPED_TEST(A1DInterpolator, canComputeAllEMfieldsAtParticle)
{
for (auto const& part : this->particles)
{
auto const [E, B] = this->interp(part, this->em, this->layout);
auto const& [Ex, Ey, Ez] = E;
auto const& [Bx, By, Bz] = B;
EXPECT_NEAR(Ex, this->ex0, 1e-8);
EXPECT_NEAR(Ey, this->ey0, 1e-8);
EXPECT_NEAR(Ez, this->ez0, 1e-8);
EXPECT_NEAR(Bx, this->bx0, 1e-8);
EXPECT_NEAR(By, this->by0, 1e-8);
EXPECT_NEAR(Bz, this->bz0, 1e-8);
}
}
template<typename InterpolatorT>
class A2DInterpolator : public ::testing::Test
{
public:
static constexpr auto dimension = InterpolatorT::dimension;
static constexpr auto interp_order = InterpolatorT::interp_order;
// arbitrary number of cells
static constexpr std::uint32_t nx = 50;
static constexpr std::uint32_t ny = 50;
using PHARE_TYPES = PHARE::core::PHARE_Types<dimension, interp_order>;
using GridLayoutImpl = GridLayoutImplYee<dimension, interp_order>;
using ParticleArray_t = typename PHARE_TYPES::ParticleArray_t;
using Electromag_t = typename PHARE_TYPES::Electromag_t;
using UsableVecFieldND = UsableVecField<dimension>;
Electromag_t em;
GridLayout<GridLayoutImpl> layout{{0.1, 0.1}, {nx, ny}, {0., 0.}};
ParticleArray_t particles;
InterpolatorT interp;
constexpr static auto safeLayer = static_cast<int>(1 + ghostWidthForParticles<interp_order>());
UsableVecFieldND B, E;
static constexpr double ex0 = 2.25;
static constexpr double ey0 = 2.50;
static constexpr double ez0 = 2.75;
static constexpr double bx0 = 2.25;
static constexpr double by0 = 2.50;
static constexpr double bz0 = 2.75;
A2DInterpolator()
: em{"EM"}
, particles{grow(layout.AMRBox(), safeLayer), 1}
, B{"EM_B", layout, HybridQuantity::Vector::B}
, E{"EM_E", layout, HybridQuantity::Vector::E}
{
for (auto ix = 0u; ix < nx; ++ix)
{
for (auto iy = 0u; iy < ny; ++iy)
{
B(Component::X)(ix, iy) = bx0;
B(Component::Y)(ix, iy) = by0;
B(Component::Z)(ix, iy) = bz0;
E(Component::X)(ix, iy) = ex0;
E(Component::Y)(ix, iy) = ey0;
E(Component::Z)(ix, iy) = ez0;
}
}
for (auto& part : particles)
{
part.iCell[0] = 5;
part.delta[0] = 0.32;
}
B.set_on(em.B);
E.set_on(em.E);
}
};
using Interpolators2D
= ::testing::Types<Interpolator<2, 1>, Interpolator<2, 2>, Interpolator<2, 3>>;
TYPED_TEST_SUITE(A2DInterpolator, Interpolators2D);
TYPED_TEST(A2DInterpolator, canComputeAllEMfieldsAtParticle)
{
for (auto const& part : this->particles)
{
auto const [E, B] = this->interp(part, this->em, this->layout);
auto const& [Ex, Ey, Ez] = E;
auto const& [Bx, By, Bz] = B;
EXPECT_NEAR(Ex, this->ex0, 1e-8);
EXPECT_NEAR(Ey, this->ey0, 1e-8);
EXPECT_NEAR(Ez, this->ez0, 1e-8);
EXPECT_NEAR(Bx, this->bx0, 1e-8);
EXPECT_NEAR(By, this->by0, 1e-8);
EXPECT_NEAR(Bz, this->bz0, 1e-8);
}
}
template<typename InterpolatorT>
class A3DInterpolator : public ::testing::Test
{
public:
static constexpr auto dimension = InterpolatorT::dimension;
static constexpr auto interp_order = InterpolatorT::interp_order;
// arbitrary number of cells
static constexpr std::uint32_t nx = 50;
static constexpr std::uint32_t ny = 50;
static constexpr std::uint32_t nz = 50;
using PHARE_TYPES = PHARE::core::PHARE_Types<dimension, interp_order>;
using GridLayout_t = typename PHARE_TYPES::GridLayout_t;
using ParticleArray_t = typename PHARE_TYPES::ParticleArray_t;
using Electromag_t = typename PHARE_TYPES::Electromag_t;
using UsableVecFieldND = UsableVecField<dimension>;
Electromag_t em;
GridLayout_t layout{{0.1, 0.1, 0.1}, {nx, ny, nz}, {0., 0., 0.}};
ParticleArray_t particles;
InterpolatorT interp;
constexpr static auto safeLayer = static_cast<int>(1 + ghostWidthForParticles<interp_order>());
UsableVecFieldND B, E;
static constexpr double ex0 = 2.25;
static constexpr double ey0 = 2.50;
static constexpr double ez0 = 2.75;
static constexpr double bx0 = 2.25;
static constexpr double by0 = 2.50;
static constexpr double bz0 = 2.75;
A3DInterpolator()
: em{"EM"}
, particles{grow(layout.AMRBox(), safeLayer), 1}
, B{"EM_B", layout, HybridQuantity::Vector::B}
, E{"EM_E", layout, HybridQuantity::Vector::E}
{
for (auto ix = 0u; ix < nx; ++ix)
{
for (auto iy = 0u; iy < ny; ++iy)
{
for (auto iz = 0u; iz < nz; ++iz)
{
B(Component::X)(ix, iy, iz) = bx0;
B(Component::Y)(ix, iy, iz) = by0;
B(Component::Z)(ix, iy, iz) = bz0;
E(Component::X)(ix, iy, iz) = ex0;
E(Component::Y)(ix, iy, iz) = ey0;
E(Component::Z)(ix, iy, iz) = ez0;
}
}
}
for (auto& part : particles)
{
part.iCell[0] = 5;
part.delta[0] = 0.32;
}
B.set_on(em.B);
E.set_on(em.E);
}
};
using Interpolators3D
= ::testing::Types<Interpolator<3, 1>, Interpolator<3, 2>, Interpolator<3, 3>>;
TYPED_TEST_SUITE(A3DInterpolator, Interpolators3D);
TYPED_TEST(A3DInterpolator, canComputeAllEMfieldsAtParticle)
{
for (auto const& part : this->particles)
{
auto const [E, B] = this->interp(part, this->em, this->layout);
auto const& [Ex, Ey, Ez] = E;
auto const& [Bx, By, Bz] = B;
EXPECT_NEAR(Ex, this->ex0, 1e-8);
EXPECT_NEAR(Ey, this->ey0, 1e-8);
EXPECT_NEAR(Ez, this->ez0, 1e-8);
EXPECT_NEAR(Bx, this->bx0, 1e-8);
EXPECT_NEAR(By, this->by0, 1e-8);
EXPECT_NEAR(Bz, this->bz0, 1e-8);
}
}
// set a collection of particle (the number depending on interpOrder) so that
// their cumulative density equals 1 at index 20. idem for velocity components...
template<typename Interpolator>
class ACollectionOfParticles_1d : public ::testing::Test
{
static constexpr auto dimension = Interpolator::dimension;
static constexpr auto interp_order = Interpolator::interp_order;
using PHARE_TYPES = PHARE::core::PHARE_Types<dimension, interp_order>;
using ParticleArray_t = typename PHARE_TYPES::ParticleArray_t;
using GridLayout_t = typename PHARE_TYPES::GridLayout_t;
using Grid_t = typename PHARE_TYPES::Grid_t;
using Particle_t = typename ParticleArray_t::Particle_t;
using UsableVecFieldND = UsableVecField<dimension>;
public:
static constexpr std::uint32_t nx = 30;
static constexpr std::uint32_t nbrPoints = nbrPointsSupport(Interpolator::interp_order);
static constexpr std::uint32_t numOfPart = Interpolator::interp_order + 2;
GridLayout_t layout{{0.1}, {nx}, {0.}};
constexpr static auto safeLayer = static_cast<int>(1 + ghostWidthForParticles<interp_order>());
Particle_t part;
ParticleArray_t particles;
Grid_t rho;
Grid_t rho_c;
UsableVecFieldND v;
std::array<double, nbrPointsSupport(Interpolator::interp_order)> weights;
ACollectionOfParticles_1d()
: part{}
, particles{grow(layout.AMRBox(), safeLayer)}
, rho{"field", HybridQuantity::Scalar::rho, nx}
, rho_c{"field", HybridQuantity::Scalar::rho, nx}
, v{"v", layout, HybridQuantity::Vector::V}
{
if constexpr (Interpolator::interp_order == 1)
{
part.iCell[0] = 19; // AMR index
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.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.5;
part.weight = 0.6;
part.v[0] = +2.;
part.v[1] = -1.;
part.v[2] = +1.;
particles.push_back(part);
}
if constexpr (Interpolator::interp_order == 2)
{
part.iCell[0] = 19; // AMR index
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.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.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.0;
part.weight = 1.0;
part.v[0] = +2.;
part.v[1] = -1.;
part.v[2] = +1.;
particles.push_back(part);
}
if constexpr (Interpolator::interp_order == 3)
{
part.iCell[0] = 18; // AMR index
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.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.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.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.5;
part.weight = 0.9;
part.v[0] = +2.;
part.v[1] = -1.;
part.v[2] = +1.;
particles.push_back(part);
}
interpolator(makeIndexRange(particles), rho, rho_c, v, layout);
}
protected:
Interpolator interpolator;
};
TYPED_TEST_SUITE_P(ACollectionOfParticles_1d);
TYPED_TEST_P(ACollectionOfParticles_1d, DepositCorrectlyTheirWeight_1d)
{
constexpr auto interp = TypeParam::interp_order;
auto idx = 20 + this->layout.nbrGhosts(QtyCentering::dual);
auto const& [vx, vy, vz] = this->v();
EXPECT_DOUBLE_EQ(this->rho(idx), 1.0);
EXPECT_DOUBLE_EQ(vx(idx), 2.0);
EXPECT_DOUBLE_EQ(vy(idx), -1.0);
EXPECT_DOUBLE_EQ(vz(idx), 1.0);
}
REGISTER_TYPED_TEST_SUITE_P(ACollectionOfParticles_1d, DepositCorrectlyTheirWeight_1d);
using MyTypes = ::testing::Types<Interpolator<1, 1>, Interpolator<1, 2>, Interpolator<1, 3>>;
INSTANTIATE_TYPED_TEST_SUITE_P(testInterpolator, ACollectionOfParticles_1d, MyTypes);
template<typename Interpolator>
struct ACollectionOfParticles_2d : public ::testing::Test
{
static constexpr auto interp_order = Interpolator::interp_order;
static constexpr std::size_t dim = 2;
static constexpr std::uint32_t nx = 15, ny = 15;
static constexpr int start = 0, end = 5;
static constexpr auto safeLayer = static_cast<int>(1 + ghostWidthForParticles<interp_order>());
using PHARE_TYPES = PHARE::core::PHARE_Types<dim, interp_order>;
using ParticleArray_t = typename PHARE_TYPES::ParticleArray_t;
using GridLayout_t = typename PHARE_TYPES::GridLayout_t;
using Grid_t = typename PHARE_TYPES::Grid_t;
using UsableVecFieldND = UsableVecField<dim>;
GridLayout_t layout{ConstArray<double, dim>(.1), {nx, ny}, ConstArray<double, dim>(0)};
ParticleArray_t particles;
Grid_t rho;
Grid_t rho_c;
UsableVecFieldND v;
Interpolator interpolator;
ACollectionOfParticles_2d()
: particles{grow(layout.AMRBox(), safeLayer)}
, rho{"field", HybridQuantity::Scalar::rho, nx, ny}
, rho_c{"field", HybridQuantity::Scalar::rho, nx, ny}
, v{"v", layout, HybridQuantity::Vector::V}
{
for (int i = start; i < end; i++)
for (int j = start; j < end; j++)
{
auto& part = particles.emplace_back();
part.iCell = {i, j};
part.delta = ConstArray<double, dim>(.5);
part.weight = 1.;
part.v[0] = +2.;
part.v[1] = -1.;
part.v[2] = +1.;
}
interpolator(makeIndexRange(particles), rho, rho_c, v, layout);
}
};
TYPED_TEST_SUITE_P(ACollectionOfParticles_2d);
TYPED_TEST_P(ACollectionOfParticles_2d, DepositCorrectlyTheirWeight_2d)
{
constexpr auto interp = TypeParam::interp_order;
auto idx = 2 + this->layout.nbrGhosts(QtyCentering::dual);
auto const& [vx, vy, vz] = this->v();
EXPECT_DOUBLE_EQ(this->rho(idx, idx), 1.0);
EXPECT_DOUBLE_EQ(vx(idx, idx), 2.0);
EXPECT_DOUBLE_EQ(vy(idx, idx), -1.0);
EXPECT_DOUBLE_EQ(vz(idx, idx), 1.0);
}
REGISTER_TYPED_TEST_SUITE_P(ACollectionOfParticles_2d, DepositCorrectlyTheirWeight_2d);
using My2dTypes = ::testing::Types<Interpolator<2, 1>, Interpolator<2, 2>, Interpolator<2, 3>>;
INSTANTIATE_TYPED_TEST_SUITE_P(testInterpolator, ACollectionOfParticles_2d, My2dTypes);
int main(int argc, char** argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}