From d1741e77c4001a8302b00a0d14bea7dee77b1161 Mon Sep 17 00:00:00 2001 From: Rene Gassmoeller Date: Sat, 15 Jun 2024 20:45:58 -0400 Subject: [PATCH] Code cleanup --- include/aspect/simulator_access.h | 6 ++++++ .../rheology/strain_dependent.cc | 6 ++---- source/mesh_refinement/particle_density.cc | 10 +++------ .../interpolator/bilinear_least_squares.cc | 5 +---- .../interpolator/quadratic_least_squares.cc | 5 +---- source/postprocess/load_balance_statistics.cc | 9 ++------ .../postprocess/particle_count_statistics.cc | 13 +++--------- .../visualization/particle_count.cc | 8 +------ source/simulator/initial_conditions.cc | 21 ++++++++----------- source/simulator/simulator_access.cc | 13 ++++++++++++ 10 files changed, 41 insertions(+), 55 deletions(-) diff --git a/include/aspect/simulator_access.h b/include/aspect/simulator_access.h index 550eac428f2..af167715830 100644 --- a/include/aspect/simulator_access.h +++ b/include/aspect/simulator_access.h @@ -930,6 +930,12 @@ namespace aspect const Postprocess::Manager & 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. diff --git a/source/material_model/rheology/strain_dependent.cc b/source/material_model/rheology/strain_dependent.cc index 8c37ab85b02..70eae8ceb39 100644 --- a/source/material_model/rheology/strain_dependent.cc +++ b/source/material_model/rheology/strain_dependent.cc @@ -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>()) + if (healing_mechanism != no_healing && this->n_particle_worlds() > 0) { - const Postprocess::Particles &particle_postprocessor = this->get_postprocess_manager().template get_matching_postprocessor>(); - const Particle::Property::Manager &particle_property_manager = particle_postprocessor.get_particle_world().get_property_manager(); - + const Particle::Property::Manager &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.")); } diff --git a/source/mesh_refinement/particle_density.cc b/source/mesh_refinement/particle_density.cc index bf17b4bc6f6..ddb125d1f80 100644 --- a/source/mesh_refinement/particle_density.cc +++ b/source/mesh_refinement/particle_density.cc @@ -21,8 +21,7 @@ #include -#include -#include +#include namespace aspect { @@ -32,15 +31,12 @@ namespace aspect void ParticleDensity::execute(Vector &indicators) const { - AssertThrow(this->get_postprocess_manager().template has_matching_postprocessor>(), + 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 &particle_postprocessor = - this->get_postprocess_manager().template get_matching_postprocessor>(); - - const Particle::ParticleHandler &particle_handler = particle_postprocessor.get_particle_world().get_particle_handler(); + const Particle::ParticleHandler &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()) diff --git a/source/particle/interpolator/bilinear_least_squares.cc b/source/particle/interpolator/bilinear_least_squares.cc index 9ad85cb0301..2b1ccf75e0c 100644 --- a/source/particle/interpolator/bilinear_least_squares.cc +++ b/source/particle/interpolator/bilinear_least_squares.cc @@ -19,7 +19,6 @@ */ #include -#include #include #include @@ -282,9 +281,7 @@ namespace aspect { prm.enter_subsection("Bilinear least squares"); { - const Postprocess::Particles &particle_postprocessor = - this->get_postprocess_manager().template get_matching_postprocessor>(); - 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"); diff --git a/source/particle/interpolator/quadratic_least_squares.cc b/source/particle/interpolator/quadratic_least_squares.cc index d1e009e3ed2..80a14824ec9 100644 --- a/source/particle/interpolator/quadratic_least_squares.cc +++ b/source/particle/interpolator/quadratic_least_squares.cc @@ -19,7 +19,6 @@ */ #include -#include #include #include @@ -559,9 +558,7 @@ namespace aspect { prm.enter_subsection("Quadratic least squares"); { - const Postprocess::Particles &particle_postprocessor = - this->get_postprocess_manager().template get_matching_postprocessor>(); - 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"); diff --git a/source/postprocess/load_balance_statistics.cc b/source/postprocess/load_balance_statistics.cc index 18df7aa107c..adecef1cc8b 100644 --- a/source/postprocess/load_balance_statistics.cc +++ b/source/postprocess/load_balance_statistics.cc @@ -21,9 +21,7 @@ #include -#include #include -#include namespace aspect { @@ -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>()) + if (this->n_particle_worlds() > 0) { - const auto &particle_postprocessor = this->get_postprocess_manager().template - get_matching_postprocessor>(); - 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()); diff --git a/source/postprocess/particle_count_statistics.cc b/source/postprocess/particle_count_statistics.cc index 5f005dadc23..3004f37ce9b 100644 --- a/source/postprocess/particle_count_statistics.cc +++ b/source/postprocess/particle_count_statistics.cc @@ -20,15 +20,11 @@ #include +#include #include #include -#include -#include -#include - - namespace aspect { @@ -38,15 +34,12 @@ namespace aspect std::pair ParticleCountStatistics::execute (TableHandler &statistics) { - const Postprocess::Particles &particle_postprocessor = - this->get_postprocess_manager().template get_matching_postprocessor>(); - const Particle::ParticleHandler &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::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()) diff --git a/source/postprocess/visualization/particle_count.cc b/source/postprocess/visualization/particle_count.cc index fcbf637335e..715a44f72c0 100644 --- a/source/postprocess/visualization/particle_count.cc +++ b/source/postprocess/visualization/particle_count.cc @@ -20,10 +20,7 @@ #include - -#include #include -#include namespace aspect @@ -45,11 +42,8 @@ namespace aspect std::pair>> ParticleCount::execute() const { - const Postprocess::Particles &particle_postprocessor = - this->get_postprocess_manager().template get_matching_postprocessor>(); - const Particle::ParticleHandler &particle_handler = - particle_postprocessor.get_particle_world().get_particle_handler(); + this->get_particle_world().get_particle_handler(); std::pair>> return_value ("particles_per_cell", diff --git a/source/simulator/initial_conditions.cc b/source/simulator/initial_conditions.cc index e1733dc2192..6f21ded96ab 100644 --- a/source/simulator/initial_conditions.cc +++ b/source/simulator/initial_conditions.cc @@ -284,14 +284,11 @@ namespace aspect // need to write into it and we can not // write into vectors with ghost elements - const Postprocess::Particles &particle_postprocessor = - postprocess_manager.template get_matching_postprocessor>(); - - const Particle::Interpolator::Interface *particle_interpolator = &particle_postprocessor.get_particle_world().get_interpolator(); - const Particle::Property::Manager *particle_property_manager = &particle_postprocessor.get_particle_world().get_property_manager(); + const Particle::Interpolator::Interface &particle_interpolator = particle_world->get_interpolator(); + const Particle::Property::Manager &particle_property_manager = particle_world->get_property_manager(); std::vector 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) { @@ -299,7 +296,7 @@ namespace aspect { const std::pair 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); @@ -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::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")); @@ -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 diff --git a/source/simulator/simulator_access.cc b/source/simulator/simulator_access.cc index 373c680db72..e538cc06cc2 100644 --- a/source/simulator/simulator_access.cc +++ b/source/simulator/simulator_access.cc @@ -816,6 +816,17 @@ namespace aspect } + + template + unsigned int + SimulatorAccess::n_particle_worlds() const + { + // operator () returns whether an object is managed by a unique ptr + return (simulator->particle_world ? 1 : 0); + } + + + template const Particle::World & SimulatorAccess::get_particle_world() const @@ -825,6 +836,8 @@ namespace aspect return *simulator->particle_world.get(); } + + template Particle::World & SimulatorAccess::get_particle_world()