Skip to content

Commit 42fab4c

Browse files
committed
Refactor Decomposition: use free functions
1 parent 86ab010 commit 42fab4c

27 files changed

+138
-247
lines changed

apps/aluminumNew/Aluminum.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ class Aluminum : public Model {
162162
}
163163

164164
void prepare_operators(double dt) {
165-
World w = get_world();
165+
const Decomposition &decomp = get_decomposition();
166+
World w = decomposition::get_world(decomp);
166167
auto spacing = get_spacing(w);
167168
auto size = get_size(w);
168169
auto dx = spacing[0];
@@ -172,9 +173,8 @@ class Aluminum : public Model {
172173
auto Ly = size[1];
173174
auto Lz = size[2];
174175

175-
const Decomposition &decomp = get_decomposition();
176-
std::array<int, 3> low = decomp.get_outbox().low;
177-
std::array<int, 3> high = decomp.get_outbox().high;
176+
std::array<int, 3> low = get_outbox(decomp).low;
177+
std::array<int, 3> high = get_outbox(decomp).high;
178178

179179
int idx = 0;
180180
const double pi = std::atan(1.0) * 4.0;
@@ -243,8 +243,8 @@ class Aluminum : public Model {
243243
double x0 = get_origin(w, 0);
244244
int Lx = get_size(w, 0);
245245
const Decomposition &decomp = get_decomposition();
246-
std::array<int, 3> low = decomp.get_inbox().low;
247-
std::array<int, 3> high = decomp.get_inbox().high;
246+
Int3 low = get_inbox(decomp).low;
247+
Int3 high = get_inbox(decomp).high;
248248

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

apps/aluminumNew/SeedGridFCC.hpp

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

7070
// Use the new World API to get size, spacing, and origin
7171
auto size = get_size(w);

apps/aluminumNew/SlabFCC.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ class SlabFCC : public FieldModifier {
7474
const World &w = m.get_world();
7575
const Decomposition &decomp = m.get_decomposition();
7676
Field &field = m.get_real_field("psi");
77-
Vec3<int> low = decomp.get_inbox().low;
78-
Vec3<int> high = decomp.get_inbox().high;
77+
Int3 low = get_inbox(decomp).low;
78+
Int3 high = get_inbox(decomp).high;
7979

8080
// auto Lx = w.Lx;
8181
auto Ly = get_size(w, 1);

apps/tungsten.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ class Tungsten : public Model {
102102
}
103103

104104
void prepare_operators(double dt) {
105-
World w = get_world();
105+
const Decomposition &decomp = get_decomposition();
106+
World w = decomposition::get_world(decomp);
106107
auto spacing = get_spacing(w);
107108
auto size = get_size(w);
108109
auto dx = spacing[0];
@@ -112,9 +113,8 @@ class Tungsten : public Model {
112113
auto Ly = size[1];
113114
auto Lz = size[2];
114115

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

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

examples/04_diffusion_model.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ class Diffusion : public Model {
8383
if (rank0) cout << "Allocate space" << endl;
8484

8585
// Get references to world, fft and domain decomposition
86-
const World &w = get_world();
87-
FFT &fft = get_fft();
8886
const Decomposition &decomp = get_decomposition();
87+
const World &w = decomposition::get_world(decomp);
88+
FFT &fft = get_fft();
8989

9090
// Allocate space for the main variable and it's fourier transform
9191
psi.resize(fft.size_inbox());
@@ -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.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;
113+
Int3 i_low = get_inbox(decomp).low;
114+
Int3 i_high = get_inbox(decomp).high;
115+
Int3 o_low = get_outbox(decomp).low;
116+
Int3 o_high = get_outbox(decomp).high;
117117

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

examples/05_simulator.cpp

Lines changed: 5 additions & 5 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.get_inbox().low;
56-
std::array<int, 3> high = decomp.get_inbox().high;
55+
Int3 low = get_inbox(decomp).low;
56+
Int3 high = get_inbox(decomp).high;
5757

5858
if (m.is_rank0()) std::cout << "Create initial condition" << std::endl;
5959
size_t idx = 0;
@@ -98,10 +98,10 @@ class Diffusion : public Model {
9898
}
9999

100100
void prepare_operators(double dt) {
101-
const World &w = get_world();
102101
const Decomposition &decomp = get_decomposition();
103-
std::array<int, 3> low = decomp.get_outbox().low;
104-
std::array<int, 3> high = decomp.get_outbox().high;
102+
const World &w = decomposition::get_world(decomp);
103+
std::array<int, 3> low = get_outbox(decomp).low;
104+
std::array<int, 3> high = get_outbox(decomp).high;
105105

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

examples/08_discrete_fields.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,23 @@ int main() {
5252
Decomposition decomp4 = make_decomposition(world, 3, 4);
5353

5454
std::cout << decomp1 << std::endl;
55-
const std::array<int, 3> &inbox_size1 = decomp1.get_inbox_size();
56-
const std::array<int, 3> &inbox_offset1 = decomp1.get_inbox_offset();
55+
const std::array<int, 3> &inbox_size1 = get_inbox_size(decomp1);
56+
const std::array<int, 3> &inbox_offset1 = get_inbox_offset(decomp1);
5757
DiscreteField<double, 3> field1(inbox_size1, inbox_offset1, get_origin(world),
5858
get_spacing(world));
5959

60-
const std::array<int, 3> &inbox_size2 = decomp2.get_inbox_size();
61-
const std::array<int, 3> &inbox_offset2 = decomp2.get_inbox_offset();
60+
const std::array<int, 3> &inbox_size2 = get_inbox_size(decomp2);
61+
const std::array<int, 3> &inbox_offset2 = get_inbox_offset(decomp2);
6262
DiscreteField<double, 3> field2(inbox_size2, inbox_offset2, get_origin(world),
6363
get_spacing(world));
6464

65-
const std::array<int, 3> &inbox_size3 = decomp3.get_inbox_size();
66-
const std::array<int, 3> &inbox_offset3 = decomp3.get_inbox_offset();
65+
const std::array<int, 3> &inbox_size3 = get_inbox_size(decomp3);
66+
const std::array<int, 3> &inbox_offset3 = get_inbox_offset(decomp3);
6767
DiscreteField<double, 3> field3(inbox_size3, inbox_offset3, get_origin(world),
6868
get_spacing(world));
6969

70-
const std::array<int, 3> &inbox_size4 = decomp4.get_inbox_size();
71-
const std::array<int, 3> &inbox_offset4 = decomp4.get_inbox_offset();
70+
const std::array<int, 3> &inbox_size4 = get_inbox_size(decomp4);
71+
const std::array<int, 3> &inbox_offset4 = get_inbox_offset(decomp4);
7272
DiscreteField<double, 3> field4(inbox_size4, inbox_offset4, get_origin(world),
7373
get_spacing(world));
7474
std::cout << field1 << std::endl;

examples/09_parallel_fft_high_level.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ int main(int argc, char *argv[]) {
1717
// Create input field
1818
// DiscreteField<double, 3> input(decomp);
1919

20-
auto dimensions = decomp.get_inbox_size();
21-
auto offsets = decomp.get_inbox_offset();
20+
auto dimensions = get_inbox_size(decomp);
21+
auto offsets = get_inbox_offset(decomp);
2222
auto origin = get_origin(world);
2323
auto discretization = get_spacing(world);
2424
DiscreteField<double, 3> input(dimensions, offsets, origin, discretization);

examples/11_write_results.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ int main(int argc, char **argv) {
1616
World world = world::create({4, 3, 2});
1717
Decomposition decomp = make_decomposition(world);
1818
// DiscreteField<double, 3> field(decomp);
19-
auto dimensions = decomp.get_inbox_size();
20-
auto offsets = decomp.get_inbox_offset();
19+
auto dimensions = get_inbox_size(decomp);
20+
auto offsets = get_inbox_offset(decomp);
2121
auto origin = get_origin(world);
2222
auto discretization = get_spacing(world);
2323
DiscreteField<double, 3> field(dimensions, offsets, origin, discretization);

examples/12_cahn_hilliard.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ class CahnHilliard : public Model {
4343

4444
// prepare operators
4545
World w = get_world();
46-
std::array<int, 3> o_low = decomp.get_outbox().low;
47-
std::array<int, 3> o_high = decomp.get_outbox().high;
46+
std::array<int, 3> o_low = get_outbox(decomp).low;
47+
std::array<int, 3> o_high = get_outbox(decomp).high;
4848
size_t idx = 0;
4949
double pi = std::atan(1.0) * 4.0;
5050
auto spacing = get_spacing(w);
@@ -143,8 +143,8 @@ int main(int argc, char **argv) {
143143
// file_count
144144
writer.set_uri(sprintf("cahn_hilliard_%04i.vti", file_count));
145145
writer.set_field_name("concentration");
146-
writer.set_domain(get_size(world), decomp.get_inbox_size(),
147-
decomp.get_inbox_offset());
146+
writer.set_domain(get_size(world), get_inbox_size(decomp),
147+
get_inbox_offset(decomp));
148148
writer.set_origin(get_origin(world));
149149
writer.set_spacing(get_spacing(world));
150150
writer.initialize();

0 commit comments

Comments
 (0)