Skip to content

Commit

Permalink
Merge pull request #5917 from gassmoeller/cleanup_get_particle_world
Browse files Browse the repository at this point in the history
Code cleanup
  • Loading branch information
MFraters authored Jun 16, 2024
2 parents cfd52ff + d1741e7 commit 9f93afa
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 55 deletions.
6 changes: 6 additions & 0 deletions include/aspect/simulator_access.h
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,12 @@ namespace aspect
const Postprocess::Manager<dim> &
get_postprocess_manager () const;

/**
* Returns whether there is at least one particle world.
*/
unsigned int
n_particle_worlds() const;

/**
* Returns a const reference to the particle world, in case anyone
* wants to query something about particles.
Expand Down
6 changes: 2 additions & 4 deletions source/material_model/rheology/strain_dependent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -410,11 +410,9 @@ namespace aspect
AssertThrow(false, ExcMessage("Not a valid Strain healing mechanism!"));

// Currently this functionality only works in field composition
if (healing_mechanism != no_healing && this->get_postprocess_manager().template has_matching_postprocessor<Postprocess::Particles<dim>>())
if (healing_mechanism != no_healing && this->n_particle_worlds() > 0)
{
const Postprocess::Particles<dim> &particle_postprocessor = this->get_postprocess_manager().template get_matching_postprocessor<Postprocess::Particles<dim>>();
const Particle::Property::Manager<dim> &particle_property_manager = particle_postprocessor.get_particle_world().get_property_manager();

const Particle::Property::Manager<dim> &particle_property_manager = this->get_particle_world().get_property_manager();
AssertThrow(particle_property_manager.plugin_name_exists("viscoplastic strain invariants") == false, ExcMessage("This healing mechanism currently does not work if the strain is tracked on particles."));
}

Expand Down
10 changes: 3 additions & 7 deletions source/mesh_refinement/particle_density.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@

#include <aspect/mesh_refinement/particle_density.h>

#include <aspect/postprocess/particles.h>
#include <aspect/simulator.h>
#include <aspect/particle/world.h>

namespace aspect
{
Expand All @@ -32,15 +31,12 @@ namespace aspect
void
ParticleDensity<dim>::execute(Vector<float> &indicators) const
{
AssertThrow(this->get_postprocess_manager().template has_matching_postprocessor<Postprocess::Particles<dim>>(),
AssertThrow(this->n_particle_worlds() > 0,
ExcMessage("The mesh refinement plugin `particle density' requires the "
"postprocessor plugin `particles' to be selected. Please activate the "
"particles or deactivate this mesh refinement plugin."));

const Postprocess::Particles<dim> &particle_postprocessor =
this->get_postprocess_manager().template get_matching_postprocessor<Postprocess::Particles<dim>>();

const Particle::ParticleHandler<dim> &particle_handler = particle_postprocessor.get_particle_world().get_particle_handler();
const Particle::ParticleHandler<dim> &particle_handler = this->get_particle_world().get_particle_handler();

for (const auto &cell : this->get_dof_handler().active_cell_iterators())
if (cell->is_locally_owned())
Expand Down
5 changes: 1 addition & 4 deletions source/particle/interpolator/bilinear_least_squares.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/

#include <aspect/particle/interpolator/bilinear_least_squares.h>
#include <aspect/postprocess/particles.h>
#include <aspect/particle/world.h>
#include <aspect/utilities.h>

Expand Down Expand Up @@ -282,9 +281,7 @@ namespace aspect
{
prm.enter_subsection("Bilinear least squares");
{
const Postprocess::Particles<dim> &particle_postprocessor =
this->get_postprocess_manager().template get_matching_postprocessor<const Postprocess::Particles<dim>>();
const auto &particle_property_information = particle_postprocessor.get_particle_world().get_property_manager().get_data_info();
const auto &particle_property_information = this->get_particle_world().get_property_manager().get_data_info();
const unsigned int n_property_components = particle_property_information.n_components();
const unsigned int n_internal_components = particle_property_information.get_components_by_field_name("internal: integrator properties");

Expand Down
5 changes: 1 addition & 4 deletions source/particle/interpolator/quadratic_least_squares.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/

#include <aspect/particle/interpolator/quadratic_least_squares.h>
#include <aspect/postprocess/particles.h>
#include <aspect/particle/world.h>
#include <aspect/utilities.h>

Expand Down Expand Up @@ -559,9 +558,7 @@ namespace aspect
{
prm.enter_subsection("Quadratic least squares");
{
const Postprocess::Particles<dim> &particle_postprocessor =
this->get_postprocess_manager().template get_matching_postprocessor<const Postprocess::Particles<dim>>();
const auto &particle_property_information = particle_postprocessor.get_particle_world().get_property_manager().get_data_info();
const auto &particle_property_information = this->get_particle_world().get_property_manager().get_data_info();
const unsigned int n_property_components = particle_property_information.n_components();
const unsigned int n_internal_components = particle_property_information.get_components_by_field_name("internal: integrator properties");

Expand Down
9 changes: 2 additions & 7 deletions source/postprocess/load_balance_statistics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@

#include <aspect/postprocess/load_balance_statistics.h>

#include <aspect/postprocess/particles.h>
#include <aspect/particle/world.h>
#include <aspect/simulator.h>

namespace aspect
{
Expand All @@ -45,12 +43,9 @@ namespace aspect
statistics.add_value ("Average cells per process",
cell_distribution.avg);

if (this->get_postprocess_manager().template
has_matching_postprocessor<const Postprocess::Particles<dim>>())
if (this->n_particle_worlds() > 0)
{
const auto &particle_postprocessor = this->get_postprocess_manager().template
get_matching_postprocessor<const Postprocess::Particles<dim>>();
const unsigned int locally_owned_particles = particle_postprocessor.get_particle_world().
const unsigned int locally_owned_particles = this->get_particle_world().
get_particle_handler().n_locally_owned_particles();
const dealii::Utilities::MPI::MinMaxAvg particles_per_process =
dealii::Utilities::MPI::min_max_avg(locally_owned_particles,this->get_mpi_communicator());
Expand Down
13 changes: 3 additions & 10 deletions source/postprocess/particle_count_statistics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,11 @@


#include <aspect/postprocess/particle_count_statistics.h>
#include <aspect/particle/world.h>

#include <deal.II/base/quadrature_lib.h>
#include <deal.II/fe/fe_values.h>

#include <aspect/postprocess/particles.h>
#include <aspect/particle/world.h>
#include <aspect/simulator.h>



namespace aspect
{
Expand All @@ -38,15 +34,12 @@ namespace aspect
std::pair<std::string,std::string>
ParticleCountStatistics<dim>::execute (TableHandler &statistics)
{
const Postprocess::Particles<dim> &particle_postprocessor =
this->get_postprocess_manager().template get_matching_postprocessor<Postprocess::Particles<dim>>();

const Particle::ParticleHandler<dim> &particle_handler =
particle_postprocessor.get_particle_world().get_particle_handler();
this->get_particle_world().get_particle_handler();

unsigned int local_min_particles = std::numeric_limits<unsigned int>::max();
unsigned int local_max_particles = 0;
const Particle::types::particle_index global_particles = particle_postprocessor.get_particle_world().n_global_particles();
const Particle::types::particle_index global_particles = this->get_particle_world().n_global_particles();

// compute local min/max
for (const auto &cell : this->get_dof_handler().active_cell_iterators())
Expand Down
8 changes: 1 addition & 7 deletions source/postprocess/visualization/particle_count.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@


#include <aspect/postprocess/visualization/particle_count.h>

#include <aspect/postprocess/particles.h>
#include <aspect/particle/world.h>
#include <aspect/simulator.h>


namespace aspect
Expand All @@ -45,11 +42,8 @@ namespace aspect
std::pair<std::string, std::unique_ptr<Vector<float>>>
ParticleCount<dim>::execute() const
{
const Postprocess::Particles<dim> &particle_postprocessor =
this->get_postprocess_manager().template get_matching_postprocessor<Postprocess::Particles<dim>>();

const Particle::ParticleHandler<dim> &particle_handler =
particle_postprocessor.get_particle_world().get_particle_handler();
this->get_particle_world().get_particle_handler();

std::pair<std::string, std::unique_ptr<Vector<float>>>
return_value ("particles_per_cell",
Expand Down
21 changes: 9 additions & 12 deletions source/simulator/initial_conditions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -284,22 +284,19 @@ namespace aspect
// need to write into it and we can not
// write into vectors with ghost elements

const Postprocess::Particles<dim> &particle_postprocessor =
postprocess_manager.template get_matching_postprocessor<Postprocess::Particles<dim>>();

const Particle::Interpolator::Interface<dim> *particle_interpolator = &particle_postprocessor.get_particle_world().get_interpolator();
const Particle::Property::Manager<dim> *particle_property_manager = &particle_postprocessor.get_particle_world().get_property_manager();
const Particle::Interpolator::Interface<dim> &particle_interpolator = particle_world->get_interpolator();
const Particle::Property::Manager<dim> &particle_property_manager = particle_world->get_property_manager();

std::vector<unsigned int> particle_property_indices;
ComponentMask property_mask (particle_property_manager->get_data_info().n_components(),false);
ComponentMask property_mask (particle_property_manager.get_data_info().n_components(),false);

for (const auto &advection_field: advection_fields)
{
if (parameters.mapped_particle_properties.size() != 0)
{
const std::pair<std::string,unsigned int> particle_property_and_component = parameters.mapped_particle_properties.find(advection_field.compositional_variable)->second;

const unsigned int particle_property_index = particle_property_manager->get_data_info().get_position_by_field_name(particle_property_and_component.first)
const unsigned int particle_property_index = particle_property_manager.get_data_info().get_position_by_field_name(particle_property_and_component.first)
+ particle_property_and_component.second;

particle_property_indices.push_back(particle_property_index);
Expand All @@ -311,7 +308,7 @@ namespace aspect
const unsigned int particle_property_index = std::count(introspection.compositional_field_methods.begin(),
introspection.compositional_field_methods.begin() + advection_field.compositional_variable,
Parameters<dim>::AdvectionFieldMethod::particles);
AssertThrow(particle_property_index <= particle_property_manager->get_data_info().n_components(),
AssertThrow(particle_property_index <= particle_property_manager.get_data_info().n_components(),
ExcMessage("Can not automatically match particle properties to fields, because there are"
"more fields that are marked as particle advected than particle properties"));

Expand Down Expand Up @@ -359,10 +356,10 @@ namespace aspect
try
{
particle_properties =
particle_interpolator->properties_at_points(particle_postprocessor.get_particle_world().get_particle_handler(),
quadrature_points,
property_mask,
cell);
particle_interpolator.properties_at_points(particle_world->get_particle_handler(),
quadrature_points,
property_mask,
cell);
}
// interpolators that throw exceptions usually do not result in
// anything good, because they result in an unwinding of the stack
Expand Down
13 changes: 13 additions & 0 deletions source/simulator/simulator_access.cc
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,17 @@ namespace aspect
}



template <int dim>
unsigned int
SimulatorAccess<dim>::n_particle_worlds() const
{
// operator () returns whether an object is managed by a unique ptr
return (simulator->particle_world ? 1 : 0);
}



template <int dim>
const Particle::World<dim> &
SimulatorAccess<dim>::get_particle_world() const
Expand All @@ -825,6 +836,8 @@ namespace aspect
return *simulator->particle_world.get();
}



template <int dim>
Particle::World<dim> &
SimulatorAccess<dim>::get_particle_world()
Expand Down

0 comments on commit 9f93afa

Please sign in to comment.