Skip to content

Commit fba6c9f

Browse files
committed
Refactor World, part 1/x
- Create create_world and delete multiple constructor. - Try "free function" api style.
1 parent 22668eb commit fba6c9f

35 files changed

+340
-374
lines changed

.clang-format

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
# SPDX-FileCopyrightText: 2025 VTT Technical Research Centre of Finland Ltd
22
# SPDX-License-Identifier: AGPL-3.0-or-later
33

4-
AllowShortIfStatementsOnASingleLine: WithoutElse
5-
AllowShortLoopsOnASingleLine: true
6-
# AllowShortFunctionsOnASingleLine: InlineOnly
4+
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
5+
6+
# Basic settings
7+
78
IndentWidth: 2
89
TabWidth: 2
910
UseTab: Never
10-
ColumnLimit: 120
11-
BreakConstructorInitializers: BeforeColon # ensures that : is placed on a new line
12-
ConstructorInitializerAllOnOneLineOrOnePerLine: true # puts each initializer on its own line
13-
AllowAllConstructorInitializersOnNextLine: false # disables grouping on the next line
14-
BinPackParameters: false # prevents squeezing multiple parameters into one line
15-
AlignAfterOpenBracket: Align # keeps nice vertical alignment
16-
# ColumnLimit: 120
11+
ColumnLimit: 100
12+
13+
# Allow things on a single line
14+
15+
AllowShortIfStatementsOnASingleLine: true
16+
AllowShortLoopsOnASingleLine: true
1717
AllowShortFunctionsOnASingleLine: All
1818
AllowShortLambdasOnASingleLine: true
1919
AllowShortCaseLabelsOnASingleLine: true
20-
# AllowShortFunctionsOnASingleLine: Inline
20+
21+
# Constructor formatting
22+
23+
# ensures that : is placed on a new line
24+
BreakConstructorInitializers: BeforeColon
25+
ConstructorInitializerAllOnOneLineOrOnePerLine: false # puts each initializer on its own line
26+
AllowAllConstructorInitializersOnNextLine: false # disables grouping on the next line
27+
BinPackParameters: false # prevents squeezing multiple parameters into one line
28+
AlignAfterOpenBracket: Align # keeps nice vertical alignment

apps/aluminumNew/Aluminum.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ class Aluminum : public Model {
161161

162162
void prepare_operators(double dt) {
163163
World w = get_world();
164-
auto spacing = w.spacing();
165-
auto size = w.size();
164+
auto spacing = get_spacing(w);
165+
auto size = get_size(w);
166166
auto dx = spacing[0];
167167
auto dy = spacing[1];
168168
auto dz = spacing[2];
@@ -236,9 +236,9 @@ class Aluminum : public Model {
236236

237237
FFT &fft = get_fft();
238238
World w = get_world();
239-
double dx = w.spacing()[0];
240-
double x0 = w.origin()[0];
241-
int Lx = w.size()[0];
239+
double dx = get_spacing(w, 0);
240+
double x0 = get_origin(w, 0);
241+
int Lx = get_size(w, 0);
242242
const Decomposition &decomp = get_decomposition();
243243
std::array<int, 3> low = decomp.get_inbox().low;
244244
std::array<int, 3> high = decomp.get_inbox().high;

apps/aluminumNew/SeedGridFCC.hpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,14 @@ class SeedGridFCC : public FieldModifier {
3030
SeedGridFCC() = default;
3131

3232
SeedGridFCC(int Ny, int Nz, double X0, double radius, double amplitude, double rho, double rseed)
33-
: m_Nx(1), m_Ny(Ny), m_Nz(Nz), m_X0(X0), m_radius(radius), m_amplitude(amplitude), m_rho(rho), m_rseed(rseed) {}
33+
: m_Nx(1),
34+
m_Ny(Ny),
35+
m_Nz(Nz),
36+
m_X0(X0),
37+
m_radius(radius),
38+
m_amplitude(amplitude),
39+
m_rho(rho),
40+
m_rseed(rseed) {}
3441

3542
// getters
3643
int get_Nx() const { return m_Nx; }
@@ -65,9 +72,9 @@ class SeedGridFCC : public FieldModifier {
6572
Vec3<int> high = decomp.get_inbox().high;
6673

6774
// Use the new World API to get size, spacing, and origin
68-
auto size = w.size();
69-
auto spacing = w.spacing();
70-
auto origin = w.origin();
75+
auto size = get_size(w);
76+
auto spacing = get_spacing(w);
77+
auto origin = get_origin(w);
7178
auto Ly = size[1];
7279
auto Lz = size[2];
7380
auto dx = spacing[0];

apps/aluminumNew/aluminumTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ using namespace Catch::Matchers;
4444
TEST_CASE("Aluminum functionality", "[Aluminum]") {
4545
SECTION("Step model and calculate norm of the result") {
4646
MPI_Worker worker(0, nullptr);
47-
World world({32, 32, 32});
47+
World world = create_world({32, 32, 32});
4848
Decomposition decomp = make_decomposition(world);
4949
auto plan_options = heffte::default_options<heffte::backend::fftw>();
5050
FFT fft(decomp, MPI_COMM_WORLD, plan_options, world);

apps/tungsten.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ class Tungsten : public Model {
103103

104104
void prepare_operators(double dt) {
105105
World w = get_world();
106-
auto spacing = w.spacing();
107-
auto size = w.size();
106+
auto spacing = get_spacing(w);
107+
auto size = get_size(w);
108108
auto dx = spacing[0];
109109
auto dy = spacing[1];
110110
auto dz = spacing[2];

examples/01_hello_world.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,23 @@ int main() {
3535
std::array<int, 3> dimensions = {10, 20, 30};
3636
std::array<double, 3> origin = {0.0, 0.0, 0.0};
3737
std::array<double, 3> discretization = {0.1, 0.1, 0.1};
38-
World world(dimensions, origin, discretization);
38+
World world = create_world(dimensions, origin, discretization);
3939

4040
// Retrieve world properties
4141
cout << "World properties:" << endl;
42-
auto size = world.size();
42+
auto size = get_size(world);
4343
cout << "Dimensions: " << size[0] << " x " << size[1] << " x " << size[2] << endl;
44-
auto world_origin = world.origin();
44+
auto world_origin = get_origin(world);
4545
cout << "Origin: (" << world_origin[0] << ", " << world_origin[1] << ", " << world_origin[2] << ")" << endl;
46-
auto spacing = world.spacing();
46+
auto spacing = get_spacing(world);
4747
cout << "Spacing: dx = " << spacing[0] << ", dy = " << spacing[1] << ", dz = " << spacing[2] << endl;
4848

4949
// Simpler way:
5050
cout << world << endl;
5151

5252
// If just the size of the doman is defined, it is assumed that x0 = y0 = z0 =
5353
// 0 and dx = dy = dz = 1
54-
World world2({64, 64, 64});
54+
World world2 = create_world({64, 64, 64});
5555
cout << world2 << endl;
5656

5757
return 0;

examples/02_domain_decomposition.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ int main(int argc, char *argv[]) {
3131
// Domain decomposition can be done in a manual manner, just by giving the
3232
// size of the calculation domain, id number and total number of subdomains:
3333
int comm_rank = 0, comm_size = 2;
34-
World world1({32, 4, 4});
34+
World world1 = create_world({32, 4, 4});
3535
Decomposition decomp1 = make_decomposition(world1, comm_rank, comm_size);
3636
cout << decomp1 << endl;
3737

3838
// 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);
42-
World world2({32, 4, 4});
42+
World world2 = create_world({32, 4, 4});
4343
Decomposition decomp2 = make_decomposition(world2, comm);
4444
if (comm_rank == 0) cout << decomp2 << endl;
4545

examples/03_parallel_fft.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ int main(int argc, char *argv[]) {
112112
MPI_Comm_size(comm, &num_procs);
113113

114114
// Construct world, decomposition and fft
115-
World world({8, 1, 1});
115+
World world = create_world({8, 1, 1});
116116
Decomposition decomposition = make_decomposition(world, comm);
117117
auto plan_options = heffte::default_options<heffte::backend::fftw>();
118118
FFT fft(decomposition, comm, plan_options, world);

examples/04_diffusion_model.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ class Diffusion : public Model {
126126
for (int k = i_low[2]; k <= i_high[2]; k++) {
127127
for (int j = i_low[1]; j <= i_high[1]; j++) {
128128
for (int i = i_low[0]; i <= i_high[0]; i++) {
129-
auto origin = w.origin();
130-
auto spacing = w.spacing();
129+
auto origin = get_origin(w);
130+
auto spacing = get_spacing(w);
131131
double x = origin[0] + i * spacing[0];
132132
double y = origin[1] + j * spacing[1];
133133
double z = origin[2] + k * spacing[2];
@@ -144,8 +144,8 @@ class Diffusion : public Model {
144144
if (rank0) cout << "Prepare operators" << endl;
145145
idx = 0;
146146
double pi = std::atan(1.0) * 4.0;
147-
auto spacing = w.spacing();
148-
auto size = w.size();
147+
auto spacing = get_spacing(w);
148+
auto size = get_size(w);
149149
double fx = 2.0 * pi / (spacing[0] * size[0]);
150150
double fy = 2.0 * pi / (spacing[1] * size[1]);
151151
double fz = 2.0 * pi / (spacing[2] * size[2]);
@@ -229,7 +229,7 @@ void run() {
229229
double z0 = -0.5 * Lz * dz;
230230

231231
// Construct world, decomposition, fft and model
232-
World world({Lx, Ly, Lz}, {x0, y0, z0}, {dx, dy, dz});
232+
World world = create_world({Lx, Ly, Lz}, {x0, y0, z0}, {dx, dy, dz});
233233
Decomposition decomp = make_decomposition(world);
234234
auto plan_options = heffte::default_options<heffte::backend::fftw>();
235235
FFT fft(decomp, MPI_COMM_WORLD, plan_options, world);

examples/05_simulator.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ class GaussianIC : public FieldModifier {
6060
for (int k = low[2]; k <= high[2]; k++) {
6161
for (int j = low[1]; j <= high[1]; j++) {
6262
for (int i = low[0]; i <= high[0]; i++) {
63-
auto origin = w.origin();
64-
auto spacing = w.spacing();
63+
auto origin = get_origin(w);
64+
auto spacing = get_spacing(w);
6565
double x = origin[0] + i * spacing[0];
6666
double y = origin[1] + j * spacing[1];
6767
double z = origin[2] + k * spacing[2];
@@ -105,8 +105,8 @@ class Diffusion : public Model {
105105

106106
if (is_rank0()) std::cout << "Prepare operators" << std::endl;
107107
size_t idx = 0;
108-
auto spacing = w.spacing();
109-
auto size = w.size();
108+
auto spacing = get_spacing(w);
109+
auto size = get_size(w);
110110
double fx = 2.0 * PI / (spacing[0] * size[0]);
111111
double fy = 2.0 * PI / (spacing[1] * size[1]);
112112
double fz = 2.0 * PI / (spacing[2] * size[2]);
@@ -181,7 +181,7 @@ void run() {
181181
std::array<int, 3> dimensions = {L, L, L};
182182
std::array<double, 3> discretization = {h, h, h};
183183
std::array<double, 3> origin = {o, o, o};
184-
World world(dimensions, origin, discretization);
184+
World world = create_world(dimensions, origin, discretization);
185185

186186
Decomposition decomp = make_decomposition(world);
187187
auto plan_options = heffte::default_options<heffte::backend::fftw>();

0 commit comments

Comments
 (0)