IPPL (Independent Parallel Particle Layer)
IPPL
Loading...
Searching...
No Matches
BareField.h
Go to the documentation of this file.
1//
2// Class BareField
3// A BareField represents a field.
4//
5#ifndef IPPL_BARE_FIELD_H
6#define IPPL_BARE_FIELD_H
7
8#include <Kokkos_Core.hpp>
9
10#include <cstdlib>
11#include <iostream>
12
13#include "Types/IpplTypes.h"
14
15#include "Utility/IpplInfo.h"
16#include "Utility/PAssert.h"
17#include "Utility/ViewUtils.h"
18
20
21#include "Field/HaloCells.h"
23
24namespace ippl {
25 class Index;
26
31
39 template <typename T, unsigned Dim, class... ViewArgs>
41 BareField<T, Dim, ViewArgs...>,
42 sizeof(typename detail::ViewType<T, Dim, ViewArgs...>::view_type)> {
43 public:
45
48
50 using view_type = typename detail::ViewType<T, Dim, ViewArgs...>::view_type;
51 typedef typename view_type::memory_space memory_space;
52 typedef typename view_type::execution_space execution_space;
53 using HostMirror = typename view_type::host_mirror_type;
54 template <class... PolicyArgs>
55 using policy_type = typename RangePolicy<Dim, PolicyArgs...>::policy_type;
56
57 using halo_type = detail::HaloCells<T, Dim, ViewArgs...>;
58
59 using value_type = T;
60 constexpr static unsigned dim = Dim;
61
68
69 BareField(const BareField&) = default;
70
75 BareField(Layout_t& l, int nghost = 1);
76
82
83 // Destroy the BareField.
84 ~BareField() = default;
85
91 template <typename... Args>
92 void resize(Args... args);
93
101 void initialize(Layout_t& l, int nghost = 1);
102
103 // ML
104 void updateLayout(Layout_t&, int nghost = 1);
105
111 detail::size_type size(unsigned d) const { return owned_m[d].length(); }
112
117 const Domain_t& getOwned() const { return owned_m; }
118
123 const Domain_t getAllocated() const { return owned_m.grow(nghost_m); }
124
125 int getNghost() const { return nghost_m; }
126
127 void fillHalo();
129 void accumulateHalo_noghost(int nghost = 1);
130
131 auto& getCommunicator() const { return getLayout().comm; }
132
133 // Access to the layout.
135 PAssert(layout_m != 0);
136 return *layout_m;
137 }
138
139 const Index& getIndex(unsigned d) const { return getLayout().getDomain()[d]; }
140 const NDIndex<Dim>& getDomain() const { return getLayout().getDomain(); }
141
142 halo_type& getHalo() { return halo_m; }
143
144 // Assignment from a constant.
146
154 template <typename E, size_t N>
156
164 template <typename... Args>
165 KOKKOS_INLINE_FUNCTION T operator()(Args... args) const {
166 return dview_m(args...);
167 }
168
169 view_type& getView() { return dview_m; }
170
171 const view_type& getView() const { return dview_m; }
172
173 HostMirror getHostMirror() const { return Kokkos::create_mirror(dview_m); }
174
182 template <class... PolicyArgs>
184 const int nghost = 0) const {
185 PAssert_LE(nghost, nghost_m);
186 const size_t shift = nghost_m - nghost;
187 return getRangePolicy(dview_m, shift);
188 }
189
194 void write(std::ostream& out = std::cout) const;
195
200 void write(Inform& inf) const;
201
202 T sum(int nghost = 0) const;
203 T max(int nghost = 0) const;
204 T min(int nghost = 0) const;
205 T prod(int nghost = 0) const;
206
207 private:
210
213
216
218
222 void setup();
223
225 Layout_t* layout_m = nullptr;
226 };
227
228} // namespace ippl
229
230#include "Field/BareField.hpp"
232
233#endif
constexpr unsigned Dim
#define PAssert_LE(a, b)
Definition PAssert.h:126
#define PAssert(c)
Definition PAssert.h:116
Definition Archive.h:20
RangePolicy< View::rank, typenameView::execution_space, PolicyArgs... >::policy_type getRangePolicy(const View &view, int shift=0)
std::size_t size_type
Definition IpplTypes.h:13
Layout_t & getLayout() const
Definition BareField.h:134
T sum(int nghost=0) const
static constexpr unsigned dim
Definition BareField.h:60
BareField & operator=(T x)
view_type::memory_space memory_space
Definition BareField.h:51
const Domain_t getAllocated() const
Definition BareField.h:123
void write(Inform &inf) const
typename detail::ViewType< T, Dim, ViewArgs... >::view_type view_type
View type storing the data.
Definition BareField.h:50
void accumulateHalo()
HostMirror getHostMirror() const
Definition BareField.h:173
T prod(int nghost=0) const
typename RangePolicy< Dim, PolicyArgs... >::policy_type policy_type
Definition BareField.h:55
int getNghost() const
Definition BareField.h:125
FieldLayout< Dim > Layout_t
Definition BareField.h:44
view_type & getView()
Definition BareField.h:169
halo_type & getHalo()
Definition BareField.h:142
auto & getCommunicator() const
Definition BareField.h:131
policy_type< execution_space, PolicyArgs... > getFieldRangePolicy(const int nghost=0) const
Definition BareField.h:183
void initialize(Layout_t &l, int nghost=1)
BareField & operator=(const detail::Expression< E, N > &expr)
const NDIndex< Dim > & getDomain() const
Definition BareField.h:140
void write(std::ostream &out=std::cout) const
BareField deepCopy() const
Definition BareField.hpp:94
T max(int nghost=0) const
T min(int nghost=0) const
const Index & getIndex(unsigned d) const
Definition BareField.h:139
BareField(const BareField &)=default
BareField(Layout_t &l, int nghost=1)
void updateLayout(Layout_t &, int nghost=1)
typename view_type::host_mirror_type HostMirror
Definition BareField.h:53
detail::size_type size(unsigned d) const
Definition BareField.h:111
view_type dview_m
Actual field data.
Definition BareField.h:212
void accumulateHalo_noghost(int nghost=1)
detail::HaloCells< T, Dim, ViewArgs... > halo_type
Definition BareField.h:57
const view_type & getView() const
Definition BareField.h:171
~BareField()=default
KOKKOS_INLINE_FUNCTION T operator()(Args... args) const
Definition BareField.h:165
void resize(Args... args)
view_type::execution_space execution_space
Definition BareField.h:52
const Domain_t & getOwned() const
Definition BareField.h:117
NDIndex< Dim > Domain_t
Domain type specifying the index region.
Definition BareField.h:47
const NDIndex< Dim > & getDomain() const
mpi::Communicator comm