From 2f4273f81aaa816a011fd49eafbe89e118a90700 Mon Sep 17 00:00:00 2001 From: Rene Gassmoeller Date: Mon, 21 Oct 2024 15:55:08 +0200 Subject: [PATCH] Derive TractionManager from ManagerBase --- include/aspect/boundary_traction/interface.h | 81 ++++++++++---- include/aspect/plugins.h | 3 +- source/boundary_traction/ascii_data.cc | 13 ++- .../initial_lithostatic_pressure.cc | 12 +- source/boundary_traction/interface.cc | 104 +++++++++++------- source/simulator/assemblers/stokes.cc | 7 +- source/simulator/assembly.cc | 4 +- source/simulator/melt.cc | 9 +- source/simulator/newton.cc | 2 +- 9 files changed, 152 insertions(+), 83 deletions(-) diff --git a/include/aspect/boundary_traction/interface.h b/include/aspect/boundary_traction/interface.h index 68bff12a0be..85a8cdd13d6 100644 --- a/include/aspect/boundary_traction/interface.h +++ b/include/aspect/boundary_traction/interface.h @@ -71,32 +71,13 @@ namespace aspect }; template - class Manager : public SimulatorAccess + class Manager : public Plugins::ManagerBase>, public SimulatorAccess { public: - /** - * Destructor. Made virtual since this class has virtual member - * functions. - */ - ~Manager () override; - - /** - * A function that is called at the beginning of each time step and - * calls the corresponding functions of all created plugins. - * - * The point of this function is to allow complex boundary traction - * models to do an initialization step once at the beginning of each - * time step. An example would be a model that needs to call an - * external program to compute the traction change at a boundary. - */ - virtual - void - update (); - /** * A function that calls the boundary_traction functions of all the - * individual boundary traction objects and uses the stored operators - * to combine them. + * individual boundary traction objects that are active for boundary id + * @p boundary_indicator and uses the stored operators to combine them. */ Tensor<1,dim> boundary_traction (const types::boundary_id boundary_indicator, @@ -114,7 +95,11 @@ namespace aspect * If there are no prescribed boundary traction plugins * for a particular boundary, this boundary identifier will not appear * in the map. + * + * @deprecated: This function will be removed. Use the function + * get_active_plugin_names() of the base class ManagerBase instead. */ + DEAL_II_DEPRECATED const std::map>> & get_active_boundary_traction_names () const; @@ -126,10 +111,32 @@ namespace aspect * boundary models for this boundary. If there are no prescribed * boundary traction plugins for a particular boundary this boundary * identifier will not appear in the map. + * + * @deprecated: This function has been removed. Use the function + * get_active_plugins() of the base class ManagerBase instead. */ + DEAL_II_DEPRECATED const std::map>>> & get_active_boundary_traction_conditions () const; + /** + * Return a list of boundary indicators that indicate for + * each active plugin which boundary id + * it is responsible for. The list of active plugins can be + * requested by calling get_active_plugins(). + */ + const std::vector & + get_active_plugin_boundary_indicators() const; + + /** + * Return a list of component masks that indicate for + * each active plugin which components it is responsible for. + * The list of plugin objects can be + * requested by calling get_active_plugins(). + */ + const std::vector & + get_active_plugin_component_masks() const; + /** * Declare the parameters of all known boundary traction plugins, as * well as the ones this class has itself. @@ -144,7 +151,7 @@ namespace aspect * then let these objects read their parameters as well. */ void - parse_parameters (ParameterHandler &prm); + parse_parameters (ParameterHandler &prm) override; /** * For the current plugin subsystem, write a connection graph of all of the @@ -193,9 +200,32 @@ namespace aspect std::unique_ptr> (*factory_function) ()); private: + /** + * A list of boundary indicators that indicate for + * each plugin in the list of plugin_objects which boundary id + * it is responsible for. By default each plugin + * is active for all boundaries, but this list + * can be modified by derived classes to limit the application + * of plugins to specific boundaries. + */ + std::vector boundary_indicators; + + /** + * A list of boundary indicators that indicate for + * each plugin in the list of plugin_objects which components + * it is responsible for. By default each plugin + * is active for all components, but this list + * can be modified by derived classes to limit the application + * of plugins to specific boundaries. + */ + std::vector component_masks; + /** * A list of boundary traction objects that have been requested in the * parameter file. + * + * @deprecated: This variable is no longer used, but needed to issue a proper + * error message in the function get_active_boundary_traction_conditions(). */ std::map>>> boundary_traction_objects; @@ -206,6 +236,11 @@ namespace aspect * mapped to one of the plugins of traction boundary conditions (e.g. * "function"). If the components string is empty, it is assumed the * plugins are used for all components. + * + * @deprecated: Remove this variable when the deprecated functions + * get_active_boundary_traction_names and + * get_active_boundary_traction_conditions are removed. Use the base class + * variable plugin_names instead. */ std::map>> boundary_traction_indicators; diff --git a/include/aspect/plugins.h b/include/aspect/plugins.h index ec0e7fec888..da4d97125f4 100644 --- a/include/aspect/plugins.h +++ b/include/aspect/plugins.h @@ -26,11 +26,12 @@ #include #include -#include #include +#include #include +#include #include #include #include diff --git a/source/boundary_traction/ascii_data.cc b/source/boundary_traction/ascii_data.cc index 6d84b16ec7b..1cea4822749 100644 --- a/source/boundary_traction/ascii_data.cc +++ b/source/boundary_traction/ascii_data.cc @@ -35,13 +35,16 @@ namespace aspect void AsciiData::initialize () { - for (const auto &bv : this->get_boundary_traction_manager().get_active_boundary_traction_conditions()) + unsigned int i=0; + for (const auto &plugin : this->get_boundary_traction_manager().get_active_plugins()) { - for (const auto &plugin : bv.second) - if (plugin.get() == this) - boundary_ids.insert(bv.first); + if (plugin.get() == this) + boundary_ids.insert(this->get_boundary_traction_manager().get_active_plugin_boundary_indicators()[i]); + + ++i; } - AssertThrow(*(boundary_ids.begin()) != numbers::invalid_boundary_id, + + AssertThrow(boundary_ids.empty() == false, ExcMessage("Did not find the boundary indicator for the traction ascii data plugin.")); Utilities::AsciiDataBoundary::initialize(boundary_ids, diff --git a/source/boundary_traction/initial_lithostatic_pressure.cc b/source/boundary_traction/initial_lithostatic_pressure.cc index c03db50a8ac..5b5fc1c774b 100644 --- a/source/boundary_traction/initial_lithostatic_pressure.cc +++ b/source/boundary_traction/initial_lithostatic_pressure.cc @@ -49,13 +49,15 @@ namespace aspect // Ensure the initial lithostatic pressure traction boundary conditions are used, // and register for which boundary indicators these conditions are set. std::set traction_bi; - for (const auto &p : this->get_boundary_traction_manager().get_active_boundary_traction_conditions()) + unsigned int i=0; + for (const auto &plugin : this->get_boundary_traction_manager().get_active_plugins()) { - for (const auto &plugin : p.second) - if (plugin.get() == this) - traction_bi.insert(p.first); + if (plugin.get() == this) + traction_bi.insert(this->get_boundary_traction_manager().get_active_plugin_boundary_indicators()[i]); + + ++i; } - AssertThrow(*(traction_bi.begin()) != numbers::invalid_boundary_id, + AssertThrow(traction_bi.empty() == false, ExcMessage("Did not find any boundary indicators for the initial lithostatic pressure plugin.")); // Determine whether traction boundary conditions are only set on the bottom diff --git a/source/boundary_traction/interface.cc b/source/boundary_traction/interface.cc index 2e02b8da1e5..1917009295d 100644 --- a/source/boundary_traction/interface.cc +++ b/source/boundary_traction/interface.cc @@ -33,23 +33,6 @@ namespace aspect { namespace BoundaryTraction { - template - Manager::~Manager() - = default; - - - - template - void - Manager::update () - { - for (const auto &boundary : boundary_traction_objects) - for (const auto &p : boundary.second) - p->update(); - } - - - namespace { std::tuple @@ -78,20 +61,32 @@ namespace aspect const Point &position, const Tensor<1,dim> &normal_vector) const { - typename std::map>>>::const_iterator boundary_plugins = - boundary_traction_objects.find(boundary_indicator); + Tensor<1,dim> traction; + + bool found_plugin = false; + unsigned int i=0; + for (const auto &plugin: this->plugin_objects) + { + if (boundary_indicators[i] == boundary_indicator) + { + found_plugin = true; + const Tensor<1,dim> plugin_traction = plugin->boundary_traction(boundary_indicator, + position, + normal_vector); + for (unsigned int d=0; d traction = Tensor<1,dim>(); - - for (const auto &plugin : boundary_plugins->second) - traction += plugin->boundary_traction(boundary_indicator, - position,normal_vector); - return traction; } @@ -110,11 +105,32 @@ namespace aspect const std::map>>> & Manager::get_active_boundary_traction_conditions () const { + AssertThrow(false, ExcMessage("This function has been removed. Use the function " + "get_active_plugins() of the base class ManagerBase " + "instead.")); return boundary_traction_objects; } + template + const std::vector & + Manager::get_active_plugin_boundary_indicators() const + { + return boundary_indicators; + } + + + + template + const std::vector & + Manager::get_active_plugin_component_masks() const + { + return component_masks; + } + + + template void Manager::declare_parameters (ParameterHandler &prm) @@ -254,27 +270,39 @@ namespace aspect { boundary_traction_indicators[boundary_id] = std::make_pair(comp,std::vector(1,value)); } + + this->plugin_names.push_back(value); + boundary_indicators.push_back(boundary_id); + + const bool default_component_mask = comp.empty(); + ComponentMask component_mask(dim, default_component_mask); + + if (comp.find('x') != std::string::npos) + component_mask.set(0,true); + if (comp.find('y') != std::string::npos) + component_mask.set(1,true); + if (dim == 3 && comp.find('z') != std::string::npos) + component_mask.set(2,true); + + component_masks.push_back(component_mask); } } prm.leave_subsection(); // go through the list, create objects and let them parse // their own parameters - for (const auto &boundary_id : boundary_traction_indicators) + for (const auto &plugin_name: this->plugin_names) { - for (const auto &name : boundary_id.second.second) - { - boundary_traction_objects[boundary_id.first].push_back( - std::unique_ptr> (std::get(registered_plugins) - .create_plugin (name, - "Boundary traction::Model names"))); + // create boundary traction objects + this->plugin_objects.push_back(std::get(registered_plugins) + .create_plugin (plugin_name, + "Boundary traction::Model names")); - if (SimulatorAccess *sim = dynamic_cast*>(boundary_traction_objects[boundary_id.first].back().get())) - sim->initialize_simulator (this->get_simulator()); + if (SimulatorAccess *sim = dynamic_cast*>(this->plugin_objects.back().get())) + sim->initialize_simulator (this->get_simulator()); - boundary_traction_objects[boundary_id.first].back()->parse_parameters (prm); - boundary_traction_objects[boundary_id.first].back()->initialize (); - } + this->plugin_objects.back()->parse_parameters (prm); + this->plugin_objects.back()->initialize (); } } diff --git a/source/simulator/assemblers/stokes.cc b/source/simulator/assemblers/stokes.cc index 83f5661a68a..eb949ac4612 100644 --- a/source/simulator/assemblers/stokes.cc +++ b/source/simulator/assemblers/stokes.cc @@ -939,9 +939,10 @@ namespace aspect const typename DoFHandler::face_iterator face = scratch.cell->face(scratch.face_number); - if (this->get_boundary_traction_manager().get_active_boundary_traction_names().find (face->boundary_id()) - != - this->get_boundary_traction_manager().get_active_boundary_traction_names().end()) + const auto &traction_bis = this->get_boundary_traction_manager().get_active_plugin_boundary_indicators(); + + if (std::find(traction_bis.begin(), traction_bis.end(), face->boundary_id()) + != traction_bis.end()) { for (unsigned int q=0; qstokes_system_on_boundary_face.push_back( std::make_unique>()); @@ -767,7 +767,7 @@ namespace aspect = ( // see if we need to assemble traction boundary conditions. // only if so do we actually need to have an FEFaceValues object - boundary_traction_manager.get_active_boundary_traction_names ().size() > 0 + !boundary_traction_manager.get_active_plugins().empty() ? update_values | update_quadrature_points | diff --git a/source/simulator/melt.cc b/source/simulator/melt.cc index c5110d07924..e478f3d7a5c 100644 --- a/source/simulator/melt.cc +++ b/source/simulator/melt.cc @@ -1034,11 +1034,10 @@ namespace aspect Assert(face_no != numbers::invalid_unsigned_int,ExcInternalError()); const typename DoFHandler::face_iterator face = cell->face(face_no); + const auto &traction_bis = this->get_boundary_traction_manager().get_active_plugin_boundary_indicators(); - if (this->get_boundary_traction_manager().get_active_boundary_traction_names() - .find (face->boundary_id()) - != - this->get_boundary_traction_manager().get_active_boundary_traction_names().end()) + if (std::find(traction_bis.begin(), traction_bis.end(), face->boundary_id()) + != traction_bis.end()) { scratch.face_finite_element_values.reinit (cell, face_no); @@ -1690,7 +1689,7 @@ namespace aspect std::make_unique>()); // add the terms for traction boundary conditions - if (!this->get_boundary_traction_manager().get_active_boundary_traction_names().empty()) + if (!this->get_boundary_traction_manager().get_active_plugins().empty()) { assemblers.stokes_system_on_boundary_face.push_back( std::make_unique> ()); diff --git a/source/simulator/newton.cc b/source/simulator/newton.cc index dbe07857332..e22adb8d381 100644 --- a/source/simulator/newton.cc +++ b/source/simulator/newton.cc @@ -97,7 +97,7 @@ namespace aspect " defined that handles this formulation.")); // add the terms for traction boundary conditions - if (!this->get_boundary_traction_manager().get_active_boundary_traction_names().empty()) + if (!this->get_boundary_traction_manager().get_active_plugins().empty()) { assemblers.stokes_system_on_boundary_face.push_back( std::make_unique>());