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 16, 2021
1 parent d17f9b1 commit 6c6733e
Showing 1 changed file with 52 additions and 60 deletions.
112 changes: 52 additions & 60 deletions source/particles/generators.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,23 +139,19 @@ namespace Particles
}
#endif

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);

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

const Particle<dim, spacedim> particle(position_real,
reference_location,
particle_index);
particle_handler.insert_particle(particle, cell);
++particle_index;
}
}

Expand Down Expand Up @@ -355,23 +351,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 @@ -384,24 +380,24 @@ namespace Particles
Particle<dim, spacedim>>
particles;

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)
{
Particle<dim, spacedim> particle =
random_particle_in_cell(cell,
current_particle_index,
random_number_generator,
mapping);
particles.emplace_hint(particles.end(),
cell,
std::move(particle));
++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)
{
Particle<dim, spacedim> particle =
random_particle_in_cell(cell,
current_particle_index,
random_number_generator,
mapping);
particles.emplace_hint(particles.end(),
cell,
std::move(particle));
++current_particle_index;
}
}

particle_handler.insert_particles(particles);
}
Expand Down Expand Up @@ -463,18 +459,14 @@ namespace Particles
std::vector<Point<spacedim>> points_to_generate;

// 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 6c6733e

Please sign in to comment.