Skip to content

Commit e3a72c8

Browse files
committed
Refactor Decomposition
Simplify it a lot by making the actual domain decomposition outside of class constructor. Implement make_decomposition taking id and number of processes and perform domain decomposition based on that. Do not save any additional information to Decompositoin what we don't use at the moment, we will extend this later on.
1 parent a71cf60 commit e3a72c8

36 files changed

+254
-167
lines changed

apps/aluminumNew/Aluminum.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ class Aluminum : public Model {
171171
auto Lz = size[2];
172172

173173
const Decomposition &decomp = get_decomposition();
174-
std::array<int, 3> low = decomp.outbox.low;
175-
std::array<int, 3> high = decomp.outbox.high;
174+
std::array<int, 3> low = decomp.get_outbox().low;
175+
std::array<int, 3> high = decomp.get_outbox().high;
176176

177177
int idx = 0;
178178
const double pi = std::atan(1.0) * 4.0;
@@ -240,8 +240,8 @@ class Aluminum : public Model {
240240
double x0 = w.origin()[0];
241241
int Lx = w.size()[0];
242242
const Decomposition &decomp = get_decomposition();
243-
std::array<int, 3> low = decomp.inbox.low;
244-
std::array<int, 3> high = decomp.inbox.high;
243+
std::array<int, 3> low = decomp.get_inbox().low;
244+
std::array<int, 3> high = decomp.get_inbox().high;
245245

246246
// Calculate mean-field density n_mf
247247
fft.forward(psi, psi_F);

apps/aluminumNew/SeedGridFCC.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ class SeedGridFCC : public FieldModifier {
6161
const World &w = m.get_world();
6262
const Decomposition &decomp = m.get_decomposition();
6363
Field &field = m.get_real_field("psi");
64-
Vec3<int> low = decomp.inbox.low;
65-
Vec3<int> high = decomp.inbox.high;
64+
Vec3<int> low = decomp.get_inbox().low;
65+
Vec3<int> high = decomp.get_inbox().high;
6666

6767
// Use the new World API to get size, spacing, and origin
6868
auto size = w.size();

apps/aluminumNew/SlabFCC.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ class SlabFCC : public FieldModifier {
6767
const World &w = m.get_world();
6868
const Decomposition &decomp = m.get_decomposition();
6969
Field &field = m.get_real_field("psi");
70-
Vec3<int> low = decomp.inbox.low;
71-
Vec3<int> high = decomp.inbox.high;
70+
Vec3<int> low = decomp.get_inbox().low;
71+
Vec3<int> high = decomp.get_inbox().high;
7272

7373
// auto Lx = w.Lx;
7474
auto Ly = w.get_size()[1];

apps/tungsten.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ class Tungsten : public Model {
113113
auto Lz = size[2];
114114

115115
const Decomposition &decomp = get_decomposition();
116-
std::array<int, 3> low = decomp.outbox.low;
117-
std::array<int, 3> high = decomp.outbox.high;
116+
std::array<int, 3> low = decomp.get_outbox().low;
117+
std::array<int, 3> high = decomp.get_outbox().high;
118118

119119
int idx = 0;
120120
const double pi = std::atan(1.0) * 4.0;

examples/02_domain_decomposition.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ int main(int argc, char *argv[]) {
3232
// size of the calculation domain, id number and total number of subdomains:
3333
int comm_rank = 0, comm_size = 2;
3434
World world1({32, 4, 4});
35-
Decomposition decomp1(world1, comm_rank, comm_size);
35+
Decomposition decomp1 = make_decomposition(world1, comm_rank, comm_size);
3636
cout << decomp1 << endl;
3737

38-
// In practive, we let MPI communicator to decide the number of subdomains.
38+
// In practice, we let MPI communicator to decide the number of subdomains.
3939
MPI_Init(&argc, &argv);
4040
MPI_Comm comm = MPI_COMM_WORLD;
4141
MPI_Comm_rank(comm, &comm_rank);

examples/04_diffusion_model.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ class Diffusion : public Model {
110110
Upper and lower limits for this particular MPI rank, in both inbox and
111111
outbox, are given by domain decomposition object
112112
*/
113-
Vec3<int> i_low = decomp.inbox.low;
114-
Vec3<int> i_high = decomp.inbox.high;
115-
Vec3<int> o_low = decomp.outbox.low;
116-
Vec3<int> o_high = decomp.outbox.high;
113+
Vec3<int> i_low = decomp.get_inbox().low;
114+
Vec3<int> i_high = decomp.get_inbox().high;
115+
Vec3<int> o_low = decomp.get_outbox().low;
116+
Vec3<int> o_high = decomp.get_outbox().high;
117117

118118
/*
119119
Typically initial conditions are constructed elsewhere. However, to keep

examples/05_simulator.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ class GaussianIC : public FieldModifier {
5252
const World &w = m.get_world();
5353
const Decomposition &decomp = m.get_decomposition();
5454
std::vector<double> &field = m.get_real_field("psi");
55-
std::array<int, 3> low = decomp.inbox.low;
56-
std::array<int, 3> high = decomp.inbox.high;
55+
std::array<int, 3> low = decomp.get_inbox().low;
56+
std::array<int, 3> high = decomp.get_inbox().high;
5757

5858
if (m.is_rank0()) std::cout << "Create initial condition" << std::endl;
5959
size_t idx = 0;
@@ -100,8 +100,8 @@ class Diffusion : public Model {
100100
void prepare_operators(double dt) {
101101
const World &w = get_world();
102102
const Decomposition &decomp = get_decomposition();
103-
std::array<int, 3> low = decomp.outbox.low;
104-
std::array<int, 3> high = decomp.outbox.high;
103+
std::array<int, 3> low = decomp.get_outbox().low;
104+
std::array<int, 3> high = decomp.get_outbox().high;
105105

106106
if (is_rank0()) std::cout << "Prepare operators" << std::endl;
107107
size_t idx = 0;

examples/08_discrete_fields.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <openpfc/core/decomposition.hpp>
66
#include <openpfc/core/world.hpp>
77
#include <openpfc/discrete_field.hpp>
8+
#include <openpfc/factory/decomposition_factory.hpp>
89
#include <openpfc/utils.hpp>
910

1011
using namespace pfc;
@@ -43,10 +44,11 @@ class Modifier {
4344
int main() {
4445
World world({16, 8, 1});
4546
std::cout << world << std::endl;
46-
Decomposition decomp1(world, 0, 4);
47-
Decomposition decomp2(world, 1, 4);
48-
Decomposition decomp3(world, 2, 4);
49-
Decomposition decomp4(world, 3, 4);
47+
Decomposition decomp1 = make_decomposition(world, 0, 4);
48+
Decomposition decomp2 = make_decomposition(world, 1, 4);
49+
Decomposition decomp3 = make_decomposition(world, 2, 4);
50+
Decomposition decomp4 = make_decomposition(world, 3, 4);
51+
5052
std::cout << decomp1 << std::endl;
5153
const std::array<int, 3> &inbox_size1 = decomp1.get_inbox_size();
5254
const std::array<int, 3> &inbox_offset1 = decomp1.get_inbox_offset();

examples/12_cahn_hilliard.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ class CahnHilliard : public Model {
4242

4343
// prepare operators
4444
World w = get_world();
45-
std::array<int, 3> o_low = decomp.outbox.low;
46-
std::array<int, 3> o_high = decomp.outbox.high;
45+
std::array<int, 3> o_low = decomp.get_outbox().low;
46+
std::array<int, 3> o_high = decomp.get_outbox().high;
4747
size_t idx = 0;
4848
double pi = std::atan(1.0) * 4.0;
4949
auto spacing = w.spacing();

examples/diffusion_model.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ class Diffusion : public Model {
2828
psi_F.resize(fft.size_outbox());
2929
opL.resize(fft.size_outbox());
3030

31-
Vec3<int> i_low = decomp.inbox.low;
32-
Vec3<int> i_high = decomp.inbox.high;
33-
Vec3<int> o_low = decomp.outbox.low;
34-
Vec3<int> o_high = decomp.outbox.high;
31+
Vec3<int> i_low = decomp.get_inbox().low;
32+
Vec3<int> i_high = decomp.get_inbox().high;
33+
Vec3<int> o_low = decomp.get_outbox().low;
34+
Vec3<int> o_high = decomp.get_outbox().high;
3535

3636
auto origin = w.origin();
3737
auto spacing = w.spacing();

0 commit comments

Comments
 (0)