Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing multiple traction models for a boundary #5220

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/modules/changes/20230713_chameerasilva
@@ -0,0 +1,4 @@
Changed: Boundary traction models are now allowed to combine
and used for single boundary.
<br>
(Chameera Silva, Rene Gassmoeller, 2023/07/13)
185 changes: 161 additions & 24 deletions include/aspect/boundary_traction/interface.h
Expand Up @@ -126,31 +126,168 @@ namespace aspect
const GeometryModel::Interface<dim> *geometry_model;
};

template <int dim>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add one empty line before the class. Our usual convention is to have one empty line between functions/classes in the header file and three empty lines between functions in the source .cc file.

class Manager : public ::aspect::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.
*/
Tensor<1,dim>
boundary_traction (const types::boundary_id boundary_indicator,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you will have to change something compared to the velocity manager. Take a look at line 100 of this file, the boundary_traction function has a slightly different interface. In particular it takes a third argument that indicates the normal direction on the current boundary. You will have to add this here as an additional argument as well, otherwise the manager cannot call the respective function of the individual plugins.

const Point<dim> &position,
const Tensor<1,dim> &normal_vector) const;

/**
* Register a traction boundary conditions model so that it can be
* selected from the parameter file.
*
* @param name A string that identifies the traction boundary conditions
* model
* @param description A text description of what this model does and that
* will be listed in the documentation of the parameter file.
* @param declare_parameters_function A pointer to a function that can be
* used to declare the parameters that this traction boundary conditions
* model wants to read from input files.
* @param factory_function A pointer to a function that can create an
* object of this traction boundary conditions model.
*
* @ingroup BoundaryTractions
*/
template <int dim>
void
register_boundary_traction (const std::string &name,
const std::string &description,
void (*declare_parameters_function) (ParameterHandler &),
std::unique_ptr<Interface<dim>> (*factory_function) ());
/**
* Return the names of all prescribed boundary traction models currently
* used in the computation as specified in the input file. The function
* returns a map between a boundary identifier and a pair. The
* first part of the pair is a string that represents the prescribed
* traction components on this boundary (e.g. y, xz, or xyz) and the
* second part is a vector of strings that represent the names of
* boundary traction plugins for this boundary.
* If there are no prescribed boundary traction plugins
* for a particular boundary, this boundary identifier will not appear
* in the map.
*/
const std::map<types::boundary_id, std::pair<std::string,std::vector<std::string>>> &
get_active_boundary_traction_names () const;

/**
* Return pointers to all boundary traction models
* currently used in the computation, as specified in the input file.
* The function returns a map between a boundary identifier and a vector
* of unique pointers that represent the names of prescribed traction
* 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.
*/
const std::map<types::boundary_id,std::vector<std::unique_ptr<BoundaryTraction::Interface<dim>>>> &
get_active_boundary_traction_conditions () const;

/**
* Declare the parameters of all known boundary traction plugins, as
* well as the ones this class has itself.
*/
static
void
declare_parameters (ParameterHandler &prm);

/**
* Read the parameters this class declares from the parameter file.
* This determines which boundary traction objects will be created;
* then let these objects read their parameters as well.
*/
void
parse_parameters (ParameterHandler &prm);

/**
* Go through the list of all boundary traction models that have been selected
* in the input file (and are consequently currently active) and return
* true if one of them has the desired type specified by the template
* argument.
*/
template <typename BoundaryTractionType>
bool
has_matching_boundary_traction_model () const;

/**
* Go through the list of all boundary traction models that have been selected
* in the input file (and are consequently currently active) and see
* if one of them has the type specified by the template
* argument or can be casted to that type. If so, return a reference
* to it. If no boundary traction model is active that matches the given type,
* throw an exception.
*/
template <typename BoundaryTractionType>
const BoundaryTractionType &
get_matching_boundary_traction_model () const;

/**
* For the current plugin subsystem, write a connection graph of all of the
* plugins we know about, in the format that the
* programs dot and neato understand. This allows for a visualization of
* how all of the plugins that ASPECT knows about are interconnected, and
* connect to other parts of the ASPECT code.
*
* @param output_stream The stream to write the output to.
*/
static
void
write_plugin_graph (std::ostream &output_stream);


/**
* Exception.
*/
DeclException1 (ExcBoundaryTractionNameNotFound,
std::string,
<< "Could not find entry <"
<< arg1
<< "> among the names of registered boundary traction objects.");

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an empty line here:

Suggested change
/**
/**

* Register a traction boundary conditions model so that it can be
* selected from the parameter file.
*
* @param name A string that identifies the traction boundary conditions
* model
* @param description A text description of what this model does and that
* will be listed in the documentation of the parameter file.
* @param declare_parameters_function A pointer to a function that can be
* used to declare the parameters that this traction boundary conditions
* model wants to read from input files.
* @param factory_function A pointer to a function that can create an
* object of this traction boundary conditions model.
*
* @ingroup BoundaryTractions
*/
static
void
register_boundary_traction (const std::string &name,
const std::string &description,
void (*declare_parameters_function) (ParameterHandler &),
std::unique_ptr<Interface<dim>> (*factory_function) ());

private:
/**
* A list of boundary traction objects that have been requested in the
* parameter file.
*/
std::map<types::boundary_id,std::vector<std::unique_ptr<BoundaryTraction::Interface<dim>>>> boundary_traction_objects;

/**
* Map from boundary id to a pair
* ("components", list of "traction boundary type"),
* where components is of the format "[x][y][z]" and the traction type is
* 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.
*/
std::map<types::boundary_id, std::pair<std::string,std::vector<std::string>>> boundary_traction_indicators;

};

/**
* A function that given the name of a model returns a pointer to an
Expand Down Expand Up @@ -214,10 +351,10 @@ namespace aspect
namespace ASPECT_REGISTER_BOUNDARY_TRACTION_MODEL_ ## classname \
{ \
aspect::internal::Plugins::RegisterHelper<aspect::BoundaryTraction::Interface<2>,classname<2>> \
dummy_ ## classname ## _2d (&aspect::BoundaryTraction::register_boundary_traction<2>, \
dummy_ ## classname ## _2d (&aspect::BoundaryTraction::Manager<2>::register_boundary_traction, \
name, description); \
aspect::internal::Plugins::RegisterHelper<aspect::BoundaryTraction::Interface<3>,classname<3>> \
dummy_ ## classname ## _3d (&aspect::BoundaryTraction::register_boundary_traction<3>, \
dummy_ ## classname ## _3d (&aspect::BoundaryTraction::Manager<3>::register_boundary_traction, \
name, description); \
}
}
Expand Down
2 changes: 1 addition & 1 deletion include/aspect/simulator.h
Expand Up @@ -1931,7 +1931,7 @@ namespace aspect
std::shared_ptr<WorldBuilder::World> world_builder;
#endif
BoundaryVelocity::Manager<dim> boundary_velocity_manager;
std::map<types::boundary_id,std::unique_ptr<BoundaryTraction::Interface<dim>>> boundary_traction;
BoundaryTraction::Manager<dim> boundary_traction_manager;
const std::unique_ptr<BoundaryHeatFlux::Interface<dim>> boundary_heat_flux;

/**
Expand Down
13 changes: 8 additions & 5 deletions include/aspect/simulator_access.h
Expand Up @@ -90,6 +90,7 @@ namespace aspect

namespace BoundaryTraction
{
template <int dim> class Manager;
template <int dim> class Interface;
}

Expand Down Expand Up @@ -596,11 +597,13 @@ namespace aspect
get_boundary_composition_manager () const;

/**
* Return a reference to the object that describes traction
* boundary conditions.
*/
const std::map<types::boundary_id,std::unique_ptr<BoundaryTraction::Interface<dim>>> &
get_boundary_traction () const;
* Return an reference to the manager of the boundary traction models.
* This can then, for example, be used to get the names of the boundary traction
* models used in a computation, or to compute the boundary traction
* for a given position.
*/
const BoundaryTraction::Manager<dim> &
get_boundary_traction_manager () const;

/**
* Return a reference to the manager of the initial temperature models.
Expand Down
10 changes: 6 additions & 4 deletions source/boundary_traction/ascii_data.cc
Expand Up @@ -35,10 +35,12 @@ namespace aspect
void
AsciiData<dim>::initialize ()
{
for (const auto &bv : this->get_boundary_traction())
if (bv.second.get() == this)
boundary_ids.insert(bv.first);

for (const auto &bv : this->get_boundary_traction_manager().get_active_boundary_traction_conditions())
{
for (const auto &plugin : bv.second)
if (plugin.get() == this)
boundary_ids.insert(bv.first);
}
AssertThrow(*(boundary_ids.begin()) != numbers::invalid_boundary_id,
ExcMessage("Did not find the boundary indicator for the traction ascii data plugin."));

Expand Down
7 changes: 4 additions & 3 deletions source/boundary_traction/initial_lithostatic_pressure.cc
Expand Up @@ -47,10 +47,11 @@ 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())
for (const auto &p : this->get_boundary_traction_manager().get_active_boundary_traction_conditions())
{
if (p.second.get() == this)
traction_bi.insert(p.first);
for (const auto &plugin : p.second)
if (plugin.get() == this)
traction_bi.insert(p.first);
}
AssertThrow(*(traction_bi.begin()) != numbers::invalid_boundary_id,
ExcMessage("Did not find any boundary indicators for the initial lithostatic pressure plugin."));
Expand Down