IPPL API Reference
Independent Parallel Particle Layer C++ API
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"
22#include "FieldLayout/FieldLayout.h"
23
24namespace ippl {
25 class Index;
26
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 host_mirror_type = 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
67 BareField();
68
69 BareField(const BareField&) = default;
70
75 BareField(Layout_t& l, int nghost = 1);
76
81 BareField deepCopy() const;
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();
128 void accumulateHalo();
129 void accumulateHalo_noghost(int nghost = 1);
130
131 auto& getCommunicator() const { return getLayout().comm; }
132
133 // Access to the layout.
134 Layout_t& getLayout() const {
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.
145 BareField& operator=(T x);
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 host_mirror_type getHostMirror() const { return Kokkos::create_mirror(dview_m); }
174
182 template <class... PolicyArgs>
183 policy_type<execution_space, PolicyArgs...> getFieldRangePolicy(
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
206 void write_as_list(std::ostream& out = std::cout) const;
207
212 void write_as_list(Inform& inf) const;
213
217 friend std::ostream& operator<<(std::ostream& out,
218 const BareField<T, Dim, ViewArgs...>& field) {
219 field.write_as_list(out);
220 return out;
221 }
222
223 T sum(int nghost = 0) const;
224 T max(int nghost = 0) const;
225 T min(int nghost = 0) const;
226 T prod(int nghost = 0) const;
227
228 private:
230 int nghost_m;
231
233 view_type dview_m;
234
236 Domain_t owned_m;
237
238 halo_type halo_m;
239
243 void setup();
244
246 Layout_t* layout_m = nullptr;
247 };
248
249} // namespace ippl
250
251#include "Field/BareField.hpp"
252#include "Field/BareFieldOperations.hpp"
253
254#endif
Definition Inform.h:40
Definition BareField.h:42
friend std::ostream & operator<<(std::ostream &out, const BareField< T, Dim, ViewArgs... > &field)
Definition BareField.h:217
const Domain_t getAllocated() const
Definition BareField.h:123
typename detail::ViewType< T, Dim, ViewArgs... >::view_type view_type
View type storing the data.
Definition BareField.h:50
policy_type< execution_space, PolicyArgs... > getFieldRangePolicy(const int nghost=0) const
Definition BareField.h:183
void initialize(Layout_t &l, int nghost=1)
Definition BareField.hpp:113
BareField & operator=(const detail::Expression< E, N > &expr)
void write(std::ostream &out=std::cout) const
Definition BareField.hpp:197
BareField deepCopy() const
Definition BareField.hpp:98
BareField()
Definition BareField.hpp:93
detail::size_type size(unsigned d) const
Definition BareField.h:111
KOKKOS_INLINE_FUNCTION T operator()(Args... args) const
Definition BareField.h:165
void resize(Args... args)
Definition BareField.hpp:142
const Domain_t & getOwned() const
Definition BareField.h:117
void write_as_list(std::ostream &out=std::cout) const
Definition BareField.hpp:208
NDIndex< Dim > Domain_t
Domain type specifying the index region.
Definition BareField.h:47
Definition FieldLayout.h:166
Definition NDIndex.h:21
KOKKOS_INLINE_FUNCTION NDIndex< Dim > grow(int ncells) const
Definition NDIndex.hpp:68
Definition Archive.h:20
RangePolicy< View::rank, typenameView::execution_space, PolicyArgs... >::policy_type getRangePolicy(const View &view, int shift=0)
Definition ParallelDispatch.h:56
Definition ParallelDispatch.h:24
Definition IpplExpressions.h:26
Definition ViewTypes.h:44