IPPL API Reference
Independent Parallel Particle Layer C++ API
Loading...
Searching...
No Matches
ParticleAttribBase.h
1//
2// Class ParticleAttribBase
3// Base class for all particle attribute classes.
4//
5// This class is used as the generic base class for all (templated) classes
6// which represent a single attribute of a Particle. An attribute class
7// contains a Kokkos::View of data for N particles, and methods to operate with
8// this data.
9//
10// This base class provides virtual methods used to create and destroy
11// elements of the attribute array.
12//
13
14#ifndef IPPL_PARTICLE_ATTRIB_BASE_H
15#define IPPL_PARTICLE_ATTRIB_BASE_H
16
17#include <cstring>
18
19#include "Types/IpplTypes.h"
20#include "Types/ViewTypes.h"
21
22#include "Communicate/Archive.h"
23
24namespace ippl {
25 namespace detail {
26 // Maximum length for attribute names (including null terminator)
27 constexpr size_t ATTRIB_NAME_MAX_LEN = 64;
28
29 template <typename MemorySpace = Kokkos::DefaultExecutionSpace::memory_space>
31 template <class... Properties>
32 struct WithMemSpace {
33 using memory_space = typename Kokkos::View<char*, Properties...>::memory_space;
35 };
36
37 public:
38 using hash_type = ippl::detail::hash_type<MemorySpace>;
39 using memory_space = MemorySpace;
40 using execution_space = typename memory_space::execution_space;
41
42 template <typename... Properties>
43 using with_properties = typename WithMemSpace<Properties...>::type;
44
45 KOKKOS_FUNCTION
47 const char* default_name = "UNNAMED_attribute";
48 for (size_t i = 0; i < ATTRIB_NAME_MAX_LEN && default_name[i] != '\0'; ++i) {
49 name_m[i] = default_name[i];
50 if (i + 1 < ATTRIB_NAME_MAX_LEN) {
51 name_m[i + 1] = '\0';
52 }
53 }
54 }
55
56 virtual void set_name(const std::string& name_) = 0;
57
58 virtual std::string get_name() const = 0;
59
60 // Allocate internal capacity for N particles. Does NOT touch the logical
61 // particle count (localNum_m on ParticleBase). Existing data is not preserved.
62 virtual void alloc(size_type) = 0;
63
64 // non_destructive=false (default) keeps the historical destructive-on-grow
65 // behavior (Kokkos::realloc). non_destructive=true uses Kokkos::resize so
66 // prior entries survive a capacity grow.
67 virtual void create(size_type, bool non_destructive = false) = 0;
68
69 virtual void destroy(const hash_type&, const hash_type&, size_type) = 0;
70 virtual size_type packedSize(const size_type) const = 0;
71
72 virtual void pack(const hash_type&) = 0;
73
74 virtual void unpack(size_type) = 0;
75
76 virtual void serialize(Archive<memory_space>& ar, size_type nsends) = 0;
77
78 virtual void deserialize(Archive<memory_space>& ar, size_type nrecvs) = 0;
79
80 virtual size_type size() const = 0;
81
82 virtual ~ParticleAttribBase() = default;
83
84 void setParticleCount(size_type& num) { localNum_mp = &num; }
85 size_type getParticleCount() const { return *localNum_mp; }
86
87 virtual void applyPermutation(const hash_type&) = 0;
88 virtual void internalCopy(const hash_type&) = 0;
89
90 protected:
91 const size_type* localNum_mp;
92 char name_m[ATTRIB_NAME_MAX_LEN];
93 };
94 } // namespace detail
95} // namespace ippl
96
97#endif
Definition Archive.h:29
Definition ParticleAttribBase.h:30
Definition Archive.h:20