IPPL (Independent Parallel Particle Layer)
IPPL
Loading...
Searching...
No Matches
SubFieldLayout.h
Go to the documentation of this file.
1//
2// Class SubFieldLayout
3// SubFieldLayout provides a layout for a sub-region of a larger field.
4// It ensures that the sub-region is partitioned in the same way as the original FieldLayout,
5// maintaining consistent parallel decomposition and neighbor relationships within the sub-region.
6//
7#ifndef IPPL_SUB_FIELD_LAYOUT_H
8#define IPPL_SUB_FIELD_LAYOUT_H
9
10#include <array>
11#include <iostream>
12#include <map>
13#include <vector>
14
15#include "Types/ViewTypes.h"
16
19
20namespace ippl {
21
38 template <unsigned Dim>
39 class SubFieldLayout : public FieldLayout<Dim> {
40 public:
43 using host_mirror_type = typename view_type::host_mirror_type;
44
51 SubFieldLayout(const mpi::Communicator& = MPI_COMM_WORLD);
52
62 SubFieldLayout(mpi::Communicator, const NDIndex<Dim>& domain, const NDIndex<Dim>& subDomain, std::array<bool, Dim> decomp,
63 bool isAllPeriodic = false);
64
73 SubFieldLayout(mpi::Communicator, const NDIndex<Dim>& domain, std::array<bool, Dim> decomp,
74 bool isAllPeriodic = false);
75
79 virtual ~SubFieldLayout() = default;
80
90 void initialize(const NDIndex<Dim>& domain, const NDIndex<Dim>& subDomain, std::array<bool, Dim> decomp,
91 bool isAllPeriodic = false);
92
100 void initialize(const NDIndex<Dim>& domain, std::array<bool, Dim> decomp,
101 bool isAllPeriodic = false);
102
108 const NDIndex<Dim>& getOriginDomain() const { return originDomain_m; }
109
117 template <unsigned Dim2>
118 bool operator==(const SubFieldLayout<Dim2>& x) const {
119 // Ensure the dimensions match
120 if (Dim2 != Dim) {
121 return false;
122 }
123
124 // Check if the original and global domains match
125 if (originDomain_m != x.getOriginDomain() || this->gDomain_m != x.getDomain()) {
126 return false;
127 }
128
129 // Ensure the local domains match
130 for (unsigned int rank = 0; rank < this->comm.size(); ++rank) {
131 if (this->hLocalDomains_m(rank) != x.getLocalNDIndex(rank)) {
132 return false;
133 }
134 }
135
136 // If all checks passed, the SubFieldLayouts matche
137 return true;
138 }
139
147 template <unsigned Dim2>
148 bool operator==(const FieldLayout<Dim2>& x) const {
149 // Ensure the dimensions match
150 if (Dim2 != Dim) {
151 return false;
152 }
153
154 // Check if the global domain matches the original domain and the FieldLayout's domain
155 if (this->gDomain_m != originDomain_m || this->gDomain_m != x.getDomain()) {
156 return false;
157 }
158
159 // Ensure the local domains match
160 for (unsigned int rank = 0; rank < this->comm.size(); ++rank) {
161 if (this->hLocalDomains_m(rank) != x.getLocalNDIndex(rank)) {
162 return false;
163 }
164 }
165
166 // If all checks passed, the SubFieldLayout matches the FieldLayout
167 return true;
168 }
169
170 private:
178 };
179} // namespace ippl
180
182
183#endif
constexpr unsigned Dim
Definition Archive.h:20
const NDIndex< Dim > & getDomain() const
const NDIndex_t & getLocalNDIndex() const
mpi::Communicator comm
FieldLayout(const mpi::Communicator &=MPI_COMM_WORLD)
host_mirror_type hLocalDomains_m
Local domains (host mirror view).
NDIndex_t gDomain_m
Global domain.
bool operator==(const FieldLayout< Dim2 > &x) const
Compare SubFieldLayout to a FieldLayout to see if they represent the same domain.
const NDIndex< Dim > & getOriginDomain() const
Return the original domain before sub-region extraction.
typename view_type::host_mirror_type host_mirror_type
NDIndex< Dim > NDIndex_t
bool operator==(const SubFieldLayout< Dim2 > &x) const
Compare SubFieldLayouts to see if they represent the same domain.
typename detail::ViewType< NDIndex_t, 1 >::view_type view_type
SubFieldLayout(const mpi::Communicator &=MPI_COMM_WORLD)
Default constructor, which should only be used if you are going to call 'initialize' soon after (befo...
virtual ~SubFieldLayout()=default
Destructor: Everything deletes itself automatically.
NDIndex_t originDomain_m
Original global domain in which the sub-field is defined.
void initialize(const NDIndex< Dim > &domain, const NDIndex< Dim > &subDomain, std::array< bool, Dim > decomp, bool isAllPeriodic=false)
Initializes a SubFieldLayout with the sub-domain partitioned in the same way as the original FieldLay...
Kokkos::View< typename NPtr< T, Dim >::type, Properties... > view_type
Definition ViewTypes.h:45