Line data Source code
1 : //
2 : // Class ParticleLayout
3 : // Base class for all particle layout classes.
4 : //
5 : // This class is used as the generic base class for all classes
6 : // which maintain the information on where all the particles are located
7 : // on a parallel machine. It is responsible for performing particle
8 : // load balancing.
9 : //
10 : // If more general layout information is needed, such as the global -> local
11 : // mapping for each particle, then derived classes must provide this info.
12 : //
13 : // When particles are created or destroyed, this class is also responsible
14 : // for determining where particles are to be created, gathering this
15 : // information, and recalculating the global indices of all the particles.
16 : // For consistency, creation and destruction requests are cached, and then
17 : // performed all in one step when the update routine is called.
18 : //
19 : // Derived classes must provide the following:
20 : // 1) Specific version of update and loadBalance. These are not virtual,
21 : // as this class is used as a template parameter (instead of being
22 : // assigned to a base class pointer).
23 : // 2) Internal storage to maintain their specific layout mechanism
24 : // 3) the definition of a class pair_iterator, and a function
25 : // void getPairlist(int, pair_iterator&, pair_iterator&) to get a
26 : // begin/end iterator pair to access the local neighbor of the Nth
27 : // local atom. This is not a virtual function, it is a requirement of
28 : // the templated class for use in other parts of the code.
29 : //
30 :
31 : namespace ippl {
32 : namespace detail {
33 : template <typename T, unsigned Dim, typename... Properties>
34 360 : void ParticleLayout<T, Dim, Properties...>::applyBC(const particle_position_type& R,
35 : const NDRegion<T, Dim>& nr) {
36 : /* loop over all faces
37 : * 0: lower x-face
38 : * 1: upper x-face
39 : * 2: lower y-face
40 : * 3: upper y-face
41 : * etc...
42 : */
43 360 : Kokkos::RangePolicy<typename particle_position_type::execution_space> policy{
44 360 : 0, (unsigned)R.getParticleCount()};
45 2880 : for (unsigned face = 0; face < 2 * Dim; ++face) {
46 : // unsigned face = i % Dim;
47 2520 : unsigned d = face / 2;
48 2520 : bool isUpper = face & 1;
49 2520 : switch (bcs_m[face]) {
50 504 : case BC::PERIODIC:
51 : // Periodic faces come in pairs and the application of
52 : // BCs checks both sides, so there is no reason to
53 : // apply periodic conditions twice
54 504 : if (isUpper) {
55 252 : break;
56 : }
57 :
58 252 : Kokkos::parallel_for("Periodic BC", policy,
59 504 : PeriodicBC(R.getView(), nr, d, isUpper));
60 252 : break;
61 336 : case BC::REFLECTIVE:
62 336 : Kokkos::parallel_for("Reflective BC", policy,
63 672 : ReflectiveBC(R.getView(), nr, d, isUpper));
64 336 : break;
65 336 : case BC::SINK:
66 336 : Kokkos::parallel_for("Sink BC", policy,
67 672 : SinkBC(R.getView(), nr, d, isUpper));
68 336 : break;
69 1344 : case BC::NO:
70 : default:
71 1344 : break;
72 : }
73 : }
74 360 : }
75 : } // namespace detail
76 : } // namespace ippl
|