Skip to content

Commit dc561ba

Browse files
authored
Merge pull request #6068 from gassmoeller/test_load_balancing
Add test for load balancing and fix postprocessors
2 parents 69b3924 + 05a7d84 commit dc561ba

12 files changed

+1217
-11
lines changed

source/postprocess/load_balance_statistics.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ namespace aspect
4545

4646
if (this->n_particle_worlds() > 0)
4747
{
48-
const unsigned int locally_owned_particles = this->get_particle_world(0).
49-
get_particle_handler().n_locally_owned_particles();
48+
unsigned int locally_owned_particles = 0;
49+
for (unsigned int particle_handler_index = 0; particle_handler_index < this->n_particle_worlds(); ++particle_handler_index)
50+
locally_owned_particles += this->get_particle_world(particle_handler_index).
51+
get_particle_handler().n_locally_owned_particles();
52+
5053
const dealii::Utilities::MPI::MinMaxAvg particles_per_process =
5154
dealii::Utilities::MPI::min_max_avg(locally_owned_particles,this->get_mpi_communicator());
5255

source/postprocess/particle_count_statistics.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,21 @@ namespace aspect
3434
std::pair<std::string,std::string>
3535
ParticleCountStatistics<dim>::execute (TableHandler &statistics)
3636
{
37-
const Particle::ParticleHandler<dim> &particle_handler =
38-
this->get_particle_world(0).get_particle_handler();
39-
4037
unsigned int local_min_particles = std::numeric_limits<unsigned int>::max();
4138
unsigned int local_max_particles = 0;
42-
const Particle::types::particle_index global_particles = this->get_particle_world(0).n_global_particles();
39+
40+
Particle::types::particle_index global_particles = 0;
41+
for (unsigned int particle_handler_index = 0; particle_handler_index < this->n_particle_worlds(); ++particle_handler_index)
42+
global_particles += this->get_particle_world(particle_handler_index).n_global_particles();
4343

4444
// compute local min/max
4545
for (const auto &cell : this->get_dof_handler().active_cell_iterators())
4646
if (cell->is_locally_owned())
4747
{
48-
const unsigned int particles_in_cell = particle_handler.n_particles_in_cell(cell);
48+
unsigned int particles_in_cell = 0;
49+
for (unsigned int particle_handler_index = 0; particle_handler_index < this->n_particle_worlds(); ++particle_handler_index)
50+
particles_in_cell += this->get_particle_world(particle_handler_index).get_particle_handler().n_particles_in_cell(cell);
51+
4952
local_min_particles = std::min(local_min_particles,particles_in_cell);
5053
local_max_particles = std::max(local_max_particles,particles_in_cell);
5154
}

source/postprocess/visualization/particle_count.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ namespace aspect
4242
std::pair<std::string, std::unique_ptr<Vector<float>>>
4343
ParticleCount<dim>::execute() const
4444
{
45-
const Particle::ParticleHandler<dim> &particle_handler =
46-
this->get_particle_world(0).get_particle_handler();
47-
4845
std::pair<std::string, std::unique_ptr<Vector<float>>>
4946
return_value ("particles_per_cell",
5047
std::make_unique<Vector<float>>(this->get_triangulation().n_active_cells()));
@@ -53,7 +50,13 @@ namespace aspect
5350
for (const auto &cell : this->get_dof_handler().active_cell_iterators())
5451
if (cell->is_locally_owned())
5552
{
56-
(*return_value.second)(cell->active_cell_index()) = static_cast<float> (particle_handler.n_particles_in_cell(cell));
53+
unsigned int n_particles_in_cell = 0;
54+
for (unsigned int particle_handler_index = 0;
55+
particle_handler_index < this->n_particle_worlds();
56+
++particle_handler_index)
57+
n_particles_in_cell += this->get_particle_world(particle_handler_index).get_particle_handler().n_particles_in_cell(cell);
58+
59+
(*return_value.second)(cell->active_cell_index()) = static_cast<float>(n_particles_in_cell);
5760
}
5861

5962
return return_value;
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# A test for the particle load balancing strategy 'repartition'
2+
# when multiple particle worlds are active.
3+
# The test is balanced to show that the cell weight used for
4+
# the repartition algorithm is exactly 1000 and only added once
5+
# from the first particle world. The test domain is split into
6+
# two particle worlds, one containing particles in the upper
7+
# right quarter of the domain, the other covering the rest of
8+
# the domain. The particle weights are chosen so that
9+
# for a cell weight of 1000 the integrated weight from the
10+
# upper right quarter of the domain equals the integrated
11+
# weight from the other three quarters, which leads to a
12+
# cell distribution between the two processes of 16:48,
13+
# which can be seen in the output.
14+
15+
# MPI: 2
16+
17+
set Dimension = 2
18+
set End time = 0
19+
set Use years in output instead of seconds = false
20+
set Number of particle worlds = 2
21+
22+
subsection Geometry model
23+
set Model name = box
24+
25+
subsection Box
26+
set X extent = 1.0000
27+
set Y extent = 1.0000
28+
end
29+
end
30+
31+
subsection Boundary velocity model
32+
set Tangential velocity boundary indicators = left, right
33+
set Zero velocity boundary indicators = bottom, top
34+
end
35+
36+
subsection Material model
37+
set Model name = simple
38+
39+
subsection Simple model
40+
set Reference density = 1010
41+
set Viscosity = 1e2
42+
set Thermal expansion coefficient = 0
43+
set Density differential for compositional field 1 = -10
44+
end
45+
end
46+
47+
subsection Gravity model
48+
set Model name = vertical
49+
50+
subsection Vertical
51+
set Magnitude = 10
52+
end
53+
end
54+
55+
############### Parameters describing the temperature field
56+
# Note: The temperature plays no role in this model
57+
58+
59+
subsection Initial temperature model
60+
set Model name = function
61+
62+
subsection Function
63+
set Function expression = 0
64+
end
65+
end
66+
67+
############### Parameters describing the compositional field
68+
# Note: The compositional field is what drives the flow
69+
# in this example
70+
71+
subsection Compositional fields
72+
set Number of fields = 1
73+
end
74+
75+
subsection Initial composition model
76+
set Model name = function
77+
78+
subsection Function
79+
set Variable names = x,z
80+
set Function constants = pi=3.1415926
81+
set Function expression = 0.5*(1+tanh((0.2+0.02*cos(pi*x/0.9142)-z)/0.02))
82+
end
83+
end
84+
85+
############### Parameters describing the discretization
86+
87+
subsection Mesh refinement
88+
set Initial adaptive refinement = 1
89+
set Strategy = maximum refinement function, minimum refinement function
90+
set Initial global refinement = 2
91+
set Time steps between mesh refinement = 1
92+
set Coarsening fraction = 0.05
93+
set Refinement fraction = 0.3
94+
subsection Maximum refinement function
95+
set Function expression = 3
96+
end
97+
subsection Minimum refinement function
98+
set Function expression = 3
99+
end
100+
end
101+
102+
############### Parameters describing what to do with the solution
103+
104+
subsection Postprocess
105+
set List of postprocessors = particles, particle count statistics, load balance statistics, visualization
106+
107+
subsection Visualization
108+
set Time between graphical output = 0
109+
set Output format = gnuplot
110+
set List of output variables = partition, particle count
111+
end
112+
113+
subsection Particles
114+
set Time between data output = 100
115+
set Data output format = gnuplot
116+
end
117+
end
118+
119+
subsection Particles
120+
set Load balancing strategy = repartition
121+
set Integration scheme = euler
122+
set Particle weight = 5000
123+
set Particle generator name = probability density function
124+
125+
subsection Generator
126+
subsection Probability density function
127+
set Number of particles = 16
128+
set Function expression = x > 0.5 ? (y > 0.5 ? 1.0 : 1e-3) : 1e-3
129+
set Random cell selection = false
130+
end
131+
end
132+
end
133+
134+
subsection Particles 2
135+
set Load balancing strategy = repartition
136+
set Integration scheme = euler
137+
set Particle weight = 1000
138+
set Particle generator name = probability density function
139+
140+
subsection Generator
141+
subsection Probability density function
142+
set Number of particles = 48
143+
set Function expression = x > 0.5 ? (y > 0.5 ? 1e-3 : 1.0) : 1.0
144+
set Random cell selection = false
145+
end
146+
end
147+
end

tests/particle_load_balancing_repartition_multiple_worlds/particles-2/particles-2-00000.0000.gnuplot

Lines changed: 103 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/particle_load_balancing_repartition_multiple_worlds/particles-2/particles-2-00000.0001.gnuplot

Whitespace-only changes.

tests/particle_load_balancing_repartition_multiple_worlds/particles/particles-00000.0000.gnuplot

Whitespace-only changes.

tests/particle_load_balancing_repartition_multiple_worlds/particles/particles-00000.0001.gnuplot

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
Number of active cells: 16 (on 3 levels)
3+
Number of degrees of freedom: 349 (162+25+81+81)
4+
5+
*** Timestep 0: t=0 seconds, dt=0 seconds
6+
Skipping temperature solve because RHS is zero.
7+
Solving C_1 system ... 0 iterations.
8+
Solving Stokes system (GMG)... 11+0 iterations.
9+
10+
Number of active cells: 64 (on 4 levels)
11+
Number of degrees of freedom: 1,237 (578+81+289+289)
12+
13+
*** Timestep 0: t=0 seconds, dt=0 seconds
14+
Skipping temperature solve because RHS is zero.
15+
Advecting particles... done.
16+
Advecting particles... done.
17+
Solving C_1 system ... 0 iterations.
18+
Solving Stokes system (GMG)... 12+0 iterations.
19+
20+
Postprocessing:
21+
Writing particle output: output-particle_load_balancing_repartition_multiple_worlds/particles/particles-00000
22+
Particle count per cell min/avg/max: 0, 1, 3
23+
Cells per process min/max/avg: 16/48/32
24+
Writing graphical output: output-particle_load_balancing_repartition_multiple_worlds/solution/solution-00000
25+
26+
Number of active cells: 64 (on 4 levels)
27+
Number of degrees of freedom: 1,237 (578+81+289+289)
28+
29+
Termination requested by criterion: end time
30+
31+
32+

0 commit comments

Comments
 (0)