From 4a991b22d2e6fe9305df08e561b16cc1a413d0b0 Mon Sep 17 00:00:00 2001 From: Menno Fraters Date: Sun, 16 Jun 2024 15:56:31 -0400 Subject: [PATCH 1/2] Add ParticleInterfaceBase to set the particle world index for the particle plugins. --- include/aspect/particle/generator/interface.h | 4 +- .../aspect/particle/integrator/interface.h | 4 +- include/aspect/particle/interface.h | 64 +++++++++++++++++++ .../aspect/particle/interpolator/interface.h | 4 +- include/aspect/particle/property/interface.h | 10 ++- source/particle/interface.cc | 41 ++++++++++++ source/particle/property/interface.cc | 12 ++++ source/particle/world.cc | 4 ++ 8 files changed, 135 insertions(+), 8 deletions(-) create mode 100644 include/aspect/particle/interface.h create mode 100644 source/particle/interface.cc diff --git a/include/aspect/particle/generator/interface.h b/include/aspect/particle/generator/interface.h index 713869d96b0..13508fa1c41 100644 --- a/include/aspect/particle/generator/interface.h +++ b/include/aspect/particle/generator/interface.h @@ -21,7 +21,7 @@ #ifndef _aspect_particle_generator_interface_h #define _aspect_particle_generator_interface_h -#include +#include #include #include @@ -65,7 +65,7 @@ namespace aspect * @ingroup ParticleGenerators */ template - class Interface : public SimulatorAccess, public Plugins::InterfaceBase + class Interface : public SimulatorAccess, public ParticleInterfaceBase { public: virtual diff --git a/include/aspect/particle/integrator/interface.h b/include/aspect/particle/integrator/interface.h index 84e1ba196b5..dab8f945625 100644 --- a/include/aspect/particle/integrator/interface.h +++ b/include/aspect/particle/integrator/interface.h @@ -21,7 +21,7 @@ #ifndef _aspect_particle_integrator_interface_h #define _aspect_particle_integrator_interface_h -#include +#include #include #include @@ -44,7 +44,7 @@ namespace aspect * @ingroup ParticleIntegrators */ template - class Interface : public Plugins::InterfaceBase + class Interface : public ParticleInterfaceBase { public: /** diff --git a/include/aspect/particle/interface.h b/include/aspect/particle/interface.h new file mode 100644 index 00000000000..89d6ebebf59 --- /dev/null +++ b/include/aspect/particle/interface.h @@ -0,0 +1,64 @@ +/* + Copyright (C) 2015 - 2022 by the authors of the ASPECT code. + + This file is part of ASPECT. + + ASPECT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + ASPECT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with ASPECT; see the file LICENSE. If not see + . + */ + +#ifndef _aspect_particle_interface_h +#define _aspect_particle_interface_h + +#include "aspect/plugins.h" + +namespace aspect +{ + namespace Particle + { + /** + * An abstract base class defining methods and member variables + * shared along all the particle plugins. This includes the generator, + * integrator, interpolator and the property classes. + * + * @ingroup Particle + */ + class ParticleInterfaceBase : public Plugins::InterfaceBase + { + public: + /** + * @brief Set which particle world the plugin belong to. + * + * @param particle_world_index The index of the particle world this plugin belongs to. + */ + void set_particle_world_index(unsigned int particle_world_index); + + /** + * @brief Gets which particle world the plugin belong to. + */ + unsigned int get_particle_world_index() const; + + private: + /** + * Stores the index to the particle world in the + * particle worlds vector, to which the plugin belongs. + */ + unsigned int particle_world_index; + }; + + } +} + + +#endif diff --git a/include/aspect/particle/interpolator/interface.h b/include/aspect/particle/interpolator/interface.h index 127b133353c..6d52b743356 100644 --- a/include/aspect/particle/interpolator/interface.h +++ b/include/aspect/particle/interpolator/interface.h @@ -21,7 +21,7 @@ #ifndef _aspect_particle_interpolator_interface_h #define _aspect_particle_interpolator_interface_h -#include +#include #include #include @@ -47,7 +47,7 @@ namespace aspect * @ingroup ParticleInterpolators */ template - class Interface : public Plugins::InterfaceBase + class Interface : public ParticleInterfaceBase { public: /** diff --git a/include/aspect/particle/property/interface.h b/include/aspect/particle/property/interface.h index 188e928590b..a41ab6c270c 100644 --- a/include/aspect/particle/property/interface.h +++ b/include/aspect/particle/property/interface.h @@ -21,8 +21,8 @@ #ifndef _aspect_particle_property_interface_h #define _aspect_particle_property_interface_h +#include #include -#include #include #include @@ -305,7 +305,7 @@ namespace aspect * @ingroup ParticleProperties */ template - class Interface : public Plugins::InterfaceBase + class Interface : public ParticleInterfaceBase { public: /** @@ -733,6 +733,12 @@ namespace aspect void parse_parameters (ParameterHandler &prm); + /** + * @brief Set the particle world for all particle properties + * + * @param particle_world_index The index of the particle world. + */ + void set_particle_world_index(unsigned int particle_world_index); /** * For the current plugin subsystem, write a connection graph of all of the diff --git a/source/particle/interface.cc b/source/particle/interface.cc new file mode 100644 index 00000000000..a51897aeb4f --- /dev/null +++ b/source/particle/interface.cc @@ -0,0 +1,41 @@ +/* + Copyright (C) 2015 - 2022 by the authors of the ASPECT code. + + This file is part of ASPECT. + + ASPECT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + ASPECT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with ASPECT; see the file LICENSE. If not see + . + */ + +#include + + +namespace aspect +{ + namespace Particle + { + void + ParticleInterfaceBase::set_particle_world_index(const unsigned int particle_world_index) + { + this->particle_world_index = particle_world_index; + } + + unsigned int + ParticleInterfaceBase::get_particle_world_index() const + { + return this->particle_world_index; + } + + } +} diff --git a/source/particle/property/interface.cc b/source/particle/property/interface.cc index 8935dfdb8e8..add91d4a325 100644 --- a/source/particle/property/interface.cc +++ b/source/particle/property/interface.cc @@ -748,6 +748,18 @@ namespace aspect + template + void + Manager::set_particle_world_index(unsigned int particle_world_index) + { + for (auto &property : property_list) + { + property->set_particle_world_index(particle_world_index); + } + } + + + template void Manager:: diff --git a/source/particle/world.cc b/source/particle/world.cc index 965901f3df5..1ea4a77e352 100644 --- a/source/particle/world.cc +++ b/source/particle/world.cc @@ -1333,6 +1333,7 @@ namespace aspect sim->initialize_simulator (this->get_simulator()); generator->parse_parameters(prm); generator->initialize(); + generator->set_particle_world_index(world_index); // Create a property_manager object and initialize its properties property_manager = std::make_unique> (); @@ -1340,6 +1341,7 @@ namespace aspect sim->initialize_simulator (this->get_simulator()); property_manager->parse_parameters(prm); property_manager->initialize(); + property_manager->set_particle_world_index(world_index); // Create an integrator object depending on the specified parameter integrator = Integrator::create_particle_integrator (prm); @@ -1347,6 +1349,7 @@ namespace aspect sim->initialize_simulator (this->get_simulator()); integrator->parse_parameters(prm); integrator->initialize(); + integrator->set_particle_world_index(world_index); // Create an interpolator object depending on the specified parameter interpolator = Interpolator::create_particle_interpolator (prm); @@ -1354,6 +1357,7 @@ namespace aspect sim->initialize_simulator (this->get_simulator()); interpolator->parse_parameters(prm); interpolator->initialize(); + interpolator->set_particle_world_index(world_index); } prm.leave_subsection (); From 861cd508cc504449d494287eeba16258754210c1 Mon Sep 17 00:00:00 2001 From: Menno Fraters Date: Thu, 20 Jun 2024 13:36:13 +0000 Subject: [PATCH 2/2] Adress comments from code review Rene Co-authored-by: Rene Gassmoeller --- include/aspect/particle/interface.h | 9 ++++----- include/aspect/particle/property/interface.h | 2 +- source/particle/interface.cc | 7 ++++--- source/particle/world.cc | 8 ++++---- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/include/aspect/particle/interface.h b/include/aspect/particle/interface.h index 89d6ebebf59..04ab2a319ba 100644 --- a/include/aspect/particle/interface.h +++ b/include/aspect/particle/interface.h @@ -21,14 +21,14 @@ #ifndef _aspect_particle_interface_h #define _aspect_particle_interface_h -#include "aspect/plugins.h" +#include namespace aspect { namespace Particle { /** - * An abstract base class defining methods and member variables + * A base class defining methods and member variables * shared along all the particle plugins. This includes the generator, * integrator, interpolator and the property classes. * @@ -38,7 +38,7 @@ namespace aspect { public: /** - * @brief Set which particle world the plugin belong to. + * @brief Set which particle world the plugin belongs to. * * @param particle_world_index The index of the particle world this plugin belongs to. */ @@ -51,8 +51,7 @@ namespace aspect private: /** - * Stores the index to the particle world in the - * particle worlds vector, to which the plugin belongs. + * Stores the index to the particle world, to which the plugin belongs. */ unsigned int particle_world_index; }; diff --git a/include/aspect/particle/property/interface.h b/include/aspect/particle/property/interface.h index a41ab6c270c..c38cec81970 100644 --- a/include/aspect/particle/property/interface.h +++ b/include/aspect/particle/property/interface.h @@ -734,7 +734,7 @@ namespace aspect parse_parameters (ParameterHandler &prm); /** - * @brief Set the particle world for all particle properties + * @brief Set the particle world index for all particle properties * * @param particle_world_index The index of the particle world. */ diff --git a/source/particle/interface.cc b/source/particle/interface.cc index a51897aeb4f..659e348739c 100644 --- a/source/particle/interface.cc +++ b/source/particle/interface.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2015 - 2022 by the authors of the ASPECT code. + Copyright (C) 2024 by the authors of the ASPECT code. This file is part of ASPECT. @@ -31,11 +31,12 @@ namespace aspect this->particle_world_index = particle_world_index; } + + unsigned int ParticleInterfaceBase::get_particle_world_index() const { - return this->particle_world_index; + return particle_world_index; } - } } diff --git a/source/particle/world.cc b/source/particle/world.cc index 1ea4a77e352..a5ae5958669 100644 --- a/source/particle/world.cc +++ b/source/particle/world.cc @@ -1331,33 +1331,33 @@ namespace aspect generator = Generator::create_particle_generator (prm); if (SimulatorAccess *sim = dynamic_cast*>(generator.get())) sim->initialize_simulator (this->get_simulator()); + generator->set_particle_world_index(world_index); generator->parse_parameters(prm); generator->initialize(); - generator->set_particle_world_index(world_index); // Create a property_manager object and initialize its properties property_manager = std::make_unique> (); SimulatorAccess *sim = dynamic_cast*>(property_manager.get()); sim->initialize_simulator (this->get_simulator()); + property_manager->set_particle_world_index(world_index); property_manager->parse_parameters(prm); property_manager->initialize(); - property_manager->set_particle_world_index(world_index); // Create an integrator object depending on the specified parameter integrator = Integrator::create_particle_integrator (prm); if (SimulatorAccess *sim = dynamic_cast*>(integrator.get())) sim->initialize_simulator (this->get_simulator()); + integrator->set_particle_world_index(world_index); integrator->parse_parameters(prm); integrator->initialize(); - integrator->set_particle_world_index(world_index); // Create an interpolator object depending on the specified parameter interpolator = Interpolator::create_particle_interpolator (prm); if (SimulatorAccess *sim = dynamic_cast*>(interpolator.get())) sim->initialize_simulator (this->get_simulator()); + interpolator->set_particle_world_index(world_index); interpolator->parse_parameters(prm); interpolator->initialize(); - interpolator->set_particle_world_index(world_index); } prm.leave_subsection ();