Skip to content

Commit

Permalink
Convert a few places to use operator| to filter iterators.
Browse files Browse the repository at this point in the history
  • Loading branch information
bangerth committed Nov 17, 2021
1 parent 8a08c48 commit ee7cd83
Showing 1 changed file with 50 additions and 58 deletions.
108 changes: 50 additions & 58 deletions source/particles/generators.cc
Original file line number Diff line number Diff line change
Expand Up @@ -205,23 +205,19 @@ namespace Particles
particle_handler.reserve(particle_handler.n_locally_owned_particles() +
n_particles_to_generate);

for (const auto &cell : triangulation.active_cell_iterators())
for (const auto &cell : triangulation.active_cell_iterators() |
IteratorFilters::LocallyOwnedCell())
{
if (cell->is_locally_owned())
for (const auto &reference_location : particle_reference_locations)
{
for (const auto &reference_location :
particle_reference_locations)
{
const Point<spacedim> position_real =
mapping.transform_unit_to_real_cell(cell,
reference_location);

particle_handler.insert_particle(position_real,
reference_location,
particle_index,
cell);
++particle_index;
}
const Point<spacedim> position_real =
mapping.transform_unit_to_real_cell(cell, reference_location);

particle_handler.insert_particle(position_real,
reference_location,
particle_index,
cell);
++particle_index;
}
}

Expand Down Expand Up @@ -398,23 +394,23 @@ namespace Particles
// between their weight and the local weight integral
types::particle_index particles_created = 0;

for (const auto &cell : triangulation.active_cell_iterators())
if (cell->is_locally_owned())
{
const types::particle_index cumulative_particles_to_create =
std::llround(
static_cast<double>(n_local_particles) *
cumulative_cell_weights[cell->active_cell_index()] /
local_weight_integral);

// Compute particles for this cell as difference between
// number of particles that should be created including this
// cell minus the number of particles already created.
particles_per_cell[cell->active_cell_index()] =
cumulative_particles_to_create - particles_created;
particles_created +=
particles_per_cell[cell->active_cell_index()];
}
for (const auto &cell : triangulation.active_cell_iterators() |
IteratorFilters::LocallyOwnedCell())
{
const types::particle_index cumulative_particles_to_create =
std::llround(
static_cast<double>(n_local_particles) *
cumulative_cell_weights[cell->active_cell_index()] /
local_weight_integral);

// Compute particles for this cell as difference between
// number of particles that should be created including this
// cell minus the number of particles already created.
particles_per_cell[cell->active_cell_index()] =
cumulative_particles_to_create - particles_created;
particles_created +=
particles_per_cell[cell->active_cell_index()];
}
}
}

Expand All @@ -424,22 +420,22 @@ namespace Particles
n_local_particles);
unsigned int current_particle_index = start_particle_id;

for (const auto &cell : triangulation.active_cell_iterators())
if (cell->is_locally_owned())
{
for (unsigned int i = 0;
i < particles_per_cell[cell->active_cell_index()];
++i)
{
random_particle_in_cell_insert(cell,
current_particle_index,
random_number_generator,
particle_handler,
mapping);

++current_particle_index;
}
}
for (const auto &cell : triangulation.active_cell_iterators() |
IteratorFilters::LocallyOwnedCell())
{
for (unsigned int i = 0;
i < particles_per_cell[cell->active_cell_index()];
++i)
{
random_particle_in_cell_insert(cell,
current_particle_index,
random_number_generator,
particle_handler,
mapping);

++current_particle_index;
}
}

particle_handler.update_cached_numbers();
}
Expand Down Expand Up @@ -503,18 +499,14 @@ namespace Particles
triangulation.n_active_cells());

// Loop through cells and gather gauss points
for (const auto &cell : triangulation.active_cell_iterators())
for (const auto &cell : triangulation.active_cell_iterators() |
IteratorFilters::LocallyOwnedCell())
{
if (cell->is_locally_owned())
for (const auto &reference_location : particle_reference_locations)
{
for (const auto &reference_location :
particle_reference_locations)
{
const Point<spacedim> position_real =
mapping.transform_unit_to_real_cell(cell,
reference_location);
points_to_generate.push_back(position_real);
}
const Point<spacedim> position_real =
mapping.transform_unit_to_real_cell(cell, reference_location);
points_to_generate.push_back(position_real);
}
}
particle_handler.insert_global_particles(points_to_generate,
Expand Down

0 comments on commit ee7cd83

Please sign in to comment.