aboutsummaryrefslogtreecommitdiff
path: root/Source/Particles/ParticleBoundaryBuffer.H
blob: 7099ef4d6912d84f1b32979f39e3439f99f0e4ef (plain) (blame)
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
/* Copyright 2021 Andrew Myers
 *
 * This file is part of WarpX.
 *
 * License: BSD-3-Clause-LBNL
 */
#ifndef PARTICLEBOUNDARYBUFFER_H_
#define PARTICLEBOUNDARYBUFFER_H_

#include "Particles/MultiParticleContainer_fwd.H"
#include "Particles/WarpXParticleContainer.H"
#include "Particles/PinnedMemoryParticleContainer.H"
#include "Utils/export.H"

#include <vector>


/**
 *  This stores particles that have left / been absorbed by domain and embedded boundaries.
 */
class WARPX_EXPORT ParticleBoundaryBuffer
{
public:
    ParticleBoundaryBuffer ();

    ~ParticleBoundaryBuffer() {}

    /** Copy constructor for ParticleBoundaryBuffer */
    ParticleBoundaryBuffer ( const ParticleBoundaryBuffer &) = delete;
    /** Copy operator for ParticleBoundaryBuffer */
    ParticleBoundaryBuffer& operator= ( const ParticleBoundaryBuffer & ) = delete;

    /** Move constructor for NamedComponentParticleContainer */
    ParticleBoundaryBuffer ( ParticleBoundaryBuffer && ) = default;
    /** Move operator for NamedComponentParticleContainer */
    ParticleBoundaryBuffer& operator= ( ParticleBoundaryBuffer && ) = default;

    int numSpecies() const { return getSpeciesNames().size(); }

    const std::vector<std::string>& getSpeciesNames() const;

    void gatherParticles (MultiParticleContainer& mypc,
                          const amrex::Vector<const amrex::MultiFab*>& distance_to_eb);

    void redistribute ();
    void clearParticles ();
    void clearParticles (int i);

    void printNumParticles () const;

    int getNumParticlesInContainer(std::string species_name, int boundary, bool local);

    PinnedMemoryParticleContainer& getParticleBuffer(std::string species_name, int boundary);

    PinnedMemoryParticleContainer* getParticleBufferPointer(std::string species_name, int boundary);

    static constexpr int numBoundaries () {
        return AMREX_SPACEDIM*2
#ifdef AMREX_USE_EB
            + 1
#endif
            ;
    }

    bool isDefinedForAnySpecies (int const ibuffer) {return (m_do_any_boundary[ibuffer] != 0);}

    std::string boundaryName (int const ibuffer) {return m_boundary_names[ibuffer];}

private:
    // over boundary, then number of species
    std::vector<std::vector<PinnedMemoryParticleContainer> > m_particle_containers;

    // over boundary, then number of species
    std::vector<std::vector<int> > m_do_boundary_buffer;

    // over boundary
    std::vector<int> m_do_any_boundary;
    std::vector<std::string> m_boundary_names;

    mutable std::vector<std::string> m_species_names;
};

#endif /*PARTICLEBOUNDARYBUFFER_H_*/