IPPL (Independent Parallel Particle Layer)
IPPL
Loading...
Searching...
No Matches
ParticleAttrib.h
Go to the documentation of this file.
1//
2// Class ParticleAttrib
3// Templated class for all particle attribute classes.
4//
5// This templated class is used to represent a single particle attribute.
6// An attribute is one data element within a particle object, and is
7// stored as a Kokkos::View. This class stores the type information for the
8// attribute, and provides methods to create and destroy new items, and
9// to perform operations involving this attribute with others.
10//
11// ParticleAttrib is the primary element involved in expressions for
12// particles (just as LField is the primary element there). This file
13// defines the necessary templated classes and functions to make
14// ParticleAttrib a capable expression-template participant.
15//
16#ifndef IPPL_PARTICLE_ATTRIB_H
17#define IPPL_PARTICLE_ATTRIB_H
18
20
21#include "Interpolation/CIC.h"
23
24namespace ippl {
25
26 // ParticleAttrib class definition
27 template <typename T, class... Properties>
28 class ParticleAttrib : public detail::ParticleAttribBase<>::with_properties<Properties...>,
29 public detail::Expression<
30 ParticleAttrib<T, Properties...>,
31 sizeof(typename detail::ViewType<T, 1, Properties...>::view_type)> {
32 public:
33 typedef T value_type;
34 constexpr static unsigned dim = 1;
35
36 using Base = typename detail::ParticleAttribBase<>::with_properties<Properties...>;
37
38 using hash_type = typename Base::hash_type;
39
40 using view_type = typename detail::ViewType<T, 1, Properties...>::view_type;
41
42 using HostMirror = typename view_type::host_mirror_type;
43
44 using memory_space = typename view_type::memory_space;
45 using execution_space = typename view_type::execution_space;
46
48
49 // Create storage for M particle attributes. The storage is uninitialized.
50 // New items are appended to the end of the array.
51 void create(size_type) override;
52
60 void destroy(const hash_type& deleteIndex, const hash_type& keepIndex,
61 size_type invalidCount) override;
62
63 void pack(const hash_type&) override;
64
65 void unpack(size_type) override;
66
68 ar.serialize(buf_m, nsends);
69 }
70
72 ar.deserialize(buf_m, nrecvs);
73 }
74
75 virtual ~ParticleAttrib() = default;
76
77 size_type size() const override { return dview_m.extent(0); }
78
79 size_type packedSize(const size_type count) const override {
80 return count * sizeof(value_type);
81 }
82
83 void resize(size_type n) { Kokkos::resize(dview_m, n); }
84
85 void realloc(size_type n) { Kokkos::realloc(dview_m, n); }
86
87 void print() {
88 HostMirror hview = Kokkos::create_mirror_view(dview_m);
89 Kokkos::deep_copy(hview, dview_m);
90 for (size_type i = 0; i < *(this->localNum_mp); ++i) {
91 std::cout << hview(i) << std::endl;
92 }
93 }
94
95 KOKKOS_INLINE_FUNCTION T& operator()(const size_t i) const { return dview_m(i); }
96
97 view_type& getView() { return dview_m; }
98
99 const view_type& getView() const { return dview_m; }
100
101 HostMirror getHostMirror() const { return Kokkos::create_mirror(dview_m); }
102
103 void set_name(const std::string & name_) override { this->name_m = name_; }
104
105 std::string get_name() const override { return this->name_m; }
106
110 // KOKKOS_INLINE_FUNCTION
111 ParticleAttrib<T, Properties...>& operator=(T x);
112
120 template <typename E, size_t N>
121 // KOKKOS_INLINE_FUNCTION
122 ParticleAttrib<T, Properties...>& operator=(detail::Expression<E, N> const& expr);
123
151 template <typename Field, typename P2, typename policy_type>
152 void scatter(Field& f, const ParticleAttrib<Vector<P2, Field::dim>, Properties...>& pp,
153 policy_type iteration_policy, hash_type hash_array = {}) const;
154
173 template <typename Field, typename P2>
174 void gather(Field& f, const ParticleAttrib<Vector<P2, Field::dim>, Properties...>& pp,
175 const bool addToAttribute = false);
176
181
192 void applyPermutation(const hash_type& permutation) override;
193
202 void internalCopy(const hash_type& indices) override;
203
204 private:
207 };
208} // namespace ippl
209
211
212#endif
Definition Archive.h:20
std::size_t size_type
Definition IpplTypes.h:13
void serialize(const Kokkos::View< T *, ViewArgs... > &view, size_type nsends)
Definition Archive.hpp:20
void deserialize(Kokkos::View< T *, ViewArgs... > &view, size_type nrecvs)
Definition Archive.hpp:63
void destroy(const hash_type &deleteIndex, const hash_type &keepIndex, size_type invalidCount) override
HostMirror getHostMirror() const
typename view_type::memory_space memory_space
void create(size_type) override
void set_name(const std::string &name_) override
static constexpr unsigned dim
void unpack(size_type) override
void internalCopy(const hash_type &indices) override
Copy and create values of given indices.
virtual ~ParticleAttrib()=default
detail::size_type size_type
void scatter(Field &f, const ParticleAttrib< Vector< P2, Field::dim >, Properties... > &pp, policy_type iteration_policy, hash_type hash_array={}) const
Scatter particle attribute data onto a field.
size_type packedSize(const size_type count) const override
typename detail::ViewType< T, 1, Properties... >::view_type view_type
void gather(Field &f, const ParticleAttrib< Vector< P2, Field::dim >, Properties... > &pp, const bool addToAttribute=false)
Gather field data into the particle attribute.
const view_type & getView() const
void serialize(detail::Archive< memory_space > &ar, size_type nsends) override
typename view_type::execution_space execution_space
void deserialize(detail::Archive< memory_space > &ar, size_type nrecvs) override
view_type & getView()
KOKKOS_INLINE_FUNCTION T & operator()(const size_t i) const
typename Base::hash_type hash_type
void realloc(size_type n)
void pack(const hash_type &) override
std::string get_name() const override
typename view_type::host_mirror_type HostMirror
void applyPermutation(const hash_type &permutation) override
Sort the attribute according to a permutation.
typename detail::ParticleAttribBase<>::with_properties< Properties... > Base
ParticleAttrib< T, Properties... > & operator=(T x)
void resize(size_type n)
ParticleAttrib< T, Properties... > & operator=(detail::Expression< E, N > const &expr)
size_type size() const override
typename WithMemSpace< Properties... >::type with_properties