Skip to content

Commit

Permalink
Derive TractionManager from ManagerBase
Browse files Browse the repository at this point in the history
  • Loading branch information
gassmoeller committed Oct 22, 2024
1 parent 4101744 commit 2f4273f
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 83 deletions.
81 changes: 58 additions & 23 deletions include/aspect/boundary_traction/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,32 +71,13 @@ namespace aspect
};

template <int dim>
class Manager : public SimulatorAccess<dim>
class Manager : public Plugins::ManagerBase<Interface<dim>>, public SimulatorAccess<dim>
{
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,
Expand All @@ -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<types::boundary_id, std::pair<std::string,std::vector<std::string>>> &
get_active_boundary_traction_names () const;

Expand All @@ -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<types::boundary_id,std::vector<std::unique_ptr<BoundaryTraction::Interface<dim>>>> &
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<types::boundary_id> &
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<ComponentMask> &
get_active_plugin_component_masks() const;

/**
* Declare the parameters of all known boundary traction plugins, as
* well as the ones this class has itself.
Expand All @@ -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
Expand Down Expand Up @@ -193,9 +200,32 @@ namespace aspect
std::unique_ptr<Interface<dim>> (*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<types::boundary_id> 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<ComponentMask> 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<types::boundary_id,std::vector<std::unique_ptr<BoundaryTraction::Interface<dim>>>> boundary_traction_objects;

Expand All @@ -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<types::boundary_id, std::pair<std::string,std::vector<std::string>>> boundary_traction_indicators;

Expand Down
3 changes: 2 additions & 1 deletion include/aspect/plugins.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@

#include <deal.II/base/utilities.h>
#include <deal.II/base/parameter_handler.h>
#include <tuple>
#include <deal.II/base/exceptions.h>
#include <deal.II/fe/component_mask.h>

#include <boost/core/demangle.hpp>

#include <tuple>
#include <string>
#include <list>
#include <set>
Expand Down
13 changes: 8 additions & 5 deletions source/boundary_traction/ascii_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@ namespace aspect
void
AsciiData<dim>::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<dim>::initialize(boundary_ids,
Expand Down
12 changes: 7 additions & 5 deletions source/boundary_traction/initial_lithostatic_pressure.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<types::boundary_id> 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
Expand Down
104 changes: 66 additions & 38 deletions source/boundary_traction/interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,6 @@ namespace aspect
{
namespace BoundaryTraction
{
template <int dim>
Manager<dim>::~Manager()
= default;



template <int dim>
void
Manager<dim>::update ()
{
for (const auto &boundary : boundary_traction_objects)
for (const auto &p : boundary.second)
p->update();
}



namespace
{
std::tuple
Expand Down Expand Up @@ -78,20 +61,32 @@ namespace aspect
const Point<dim> &position,
const Tensor<1,dim> &normal_vector) const
{
typename std::map<types::boundary_id,std::vector<std::unique_ptr<BoundaryTraction::Interface<dim>>>>::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<dim; ++d)
if (component_masks[i][d] == true)
traction[d] += plugin_traction[d];
}

Assert(boundary_plugins != boundary_traction_objects.end(),
++i;
}

(void) found_plugin;
Assert(found_plugin == true,
ExcMessage("The boundary traction manager class was asked for the "
"boundary traction at a boundary that contains no active "
"boundary traction plugin."));

Tensor<1,dim> traction = Tensor<1,dim>();

for (const auto &plugin : boundary_plugins->second)
traction += plugin->boundary_traction(boundary_indicator,
position,normal_vector);

return traction;
}

Expand All @@ -110,11 +105,32 @@ namespace aspect
const std::map<types::boundary_id,std::vector<std::unique_ptr<BoundaryTraction::Interface<dim>>>> &
Manager<dim>::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 <int dim>
const std::vector<types::boundary_id> &
Manager<dim>::get_active_plugin_boundary_indicators() const
{
return boundary_indicators;
}



template <int dim>
const std::vector<ComponentMask> &
Manager<dim>::get_active_plugin_component_masks() const
{
return component_masks;
}



template <int dim>
void
Manager<dim>::declare_parameters (ParameterHandler &prm)
Expand Down Expand Up @@ -254,27 +270,39 @@ namespace aspect
{
boundary_traction_indicators[boundary_id] = std::make_pair(comp,std::vector<std::string>(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<Interface<dim>> (std::get<dim>(registered_plugins)
.create_plugin (name,
"Boundary traction::Model names")));
// create boundary traction objects
this->plugin_objects.push_back(std::get<dim>(registered_plugins)
.create_plugin (plugin_name,
"Boundary traction::Model names"));

if (SimulatorAccess<dim> *sim = dynamic_cast<SimulatorAccess<dim>*>(boundary_traction_objects[boundary_id.first].back().get()))
sim->initialize_simulator (this->get_simulator());
if (SimulatorAccess<dim> *sim = dynamic_cast<SimulatorAccess<dim>*>(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 ();
}
}

Expand Down
7 changes: 4 additions & 3 deletions source/simulator/assemblers/stokes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -939,9 +939,10 @@ namespace aspect

const typename DoFHandler<dim>::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; q<scratch.face_finite_element_values.n_quadrature_points; ++q)
{
Expand Down
4 changes: 2 additions & 2 deletions source/simulator/assembly.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ namespace aspect
" defined that handles this formulation."));

// add the terms for traction boundary conditions
if (!boundary_traction_manager.get_active_boundary_traction_names().empty())
if (!boundary_traction_manager.get_active_plugins().empty())
{
assemblers->stokes_system_on_boundary_face.push_back(
std::make_unique<aspect::Assemblers::StokesBoundaryTraction<dim>>());
Expand Down Expand Up @@ -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 |
Expand Down
9 changes: 4 additions & 5 deletions source/simulator/melt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1034,11 +1034,10 @@ namespace aspect
Assert(face_no != numbers::invalid_unsigned_int,ExcInternalError());

const typename DoFHandler<dim>::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);

Expand Down Expand Up @@ -1690,7 +1689,7 @@ namespace aspect
std::make_unique<aspect::Assemblers::MeltStokesSystemBoundary<dim>>());

// 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<Assemblers::MeltBoundaryTraction<dim>> ());
Expand Down
Loading

0 comments on commit 2f4273f

Please sign in to comment.