Skip to content

Commit

Permalink
Make addRelationshipManagers more general
Browse files Browse the repository at this point in the history
Arbitrary actions should be able to add relationship managers. Prior
to this we could only really add relationship managers from traditional
MooseObjectActions. This enables actions from rattlesnake for example to
add relationship managers from arbitrary objects
  • Loading branch information
lindsayad committed Apr 9, 2019
1 parent 917cb2d commit 97c0cb3
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 83 deletions.
18 changes: 16 additions & 2 deletions framework/include/actions/Action.h
Expand Up @@ -45,6 +45,21 @@ class Action : public ConsoleStreamInterface, public PerfGraphInterface
*/
void timedAct();

protected:
/**
* Method to add a relationship manager for the objects being added to the system. Relationship
* managers have to be added relatively early. In many cases before the Action::act() method
* is called.
* @param when_type The parameter indicating the normal time for adding either Geometric or
* Algebraic RelationshipManagers. It may not always be possible to add your
* RelationshipManager as early as you'd like. In these cases, your DistributedMesh may
* consume more memory during the problem setup.
* @param moose_object_pars The MooseObject to inspect for RelationshipManagers to add
*/
void addRelationshipManagers(Moose::RelationshipManagerType when_type,
const InputParameters & moose_object_pars);

public:
/**
* Method to add a relationship manager for the objects being added to the system. Relationship
* managers have to be added relatively early. In many cases before the Action::act() method
Expand Down Expand Up @@ -109,8 +124,7 @@ class Action : public ConsoleStreamInterface, public PerfGraphInterface
* back to the normal behavior of mooseError - only printing a message using the given args.
*/
template <typename... Args>
[[noreturn]] void paramError(const std::string & param, Args... args)
{
[[noreturn]] void paramError(const std::string & param, Args... args) {
auto prefix = param + ": ";
if (!_pars.inputLocation(param).empty())
prefix = _pars.inputLocation(param) + ": (" + _pars.paramFullpath(param) + "):\n";
Expand Down
1 change: 1 addition & 0 deletions framework/include/actions/MooseObjectAction.h
Expand Up @@ -24,6 +24,7 @@ class MooseObjectAction : public Action
public:
MooseObjectAction(InputParameters params);

using Action::addRelationshipManagers;
virtual void addRelationshipManagers(Moose::RelationshipManagerType when_type) override;

/**
Expand Down
85 changes: 85 additions & 0 deletions framework/src/actions/Action.C
Expand Up @@ -13,6 +13,9 @@
#include "MooseTypes.h"
#include "MooseUtils.h" // remove when getBaseName is removed
#include "MooseMesh.h"
#include "FEProblemBase.h"
#include "DisplacedProblem.h"
#include "RelationshipManager.h"

template <>
InputParameters
Expand Down Expand Up @@ -88,6 +91,88 @@ Action::timedAct()

void Action::addRelationshipManagers(Moose::RelationshipManagerType) {}

void
Action::addRelationshipManagers(Moose::RelationshipManagerType input_rm_type,
const InputParameters & moose_object_pars)
{
const auto & buildable_types = moose_object_pars.getBuildableRelationshipManagerTypes();

// These need unique names
static unsigned int unique_object_id = 0;

for (const auto & buildable_type : buildable_types)
{
unique_object_id++;

auto & rm_name = std::get<0>(buildable_type);
auto & rm_type = std::get<1>(buildable_type);
auto rm_input_parameter_func = std::get<2>(buildable_type);

auto new_name = moose_object_pars.get<std::string>("_moose_base") + '_' + name() + '_' +
rm_name + "_" + Moose::stringify(rm_type) + " " +
std::to_string(unique_object_id);

auto rm_params = _factory.getValidParams(rm_name);
rm_params.set<Moose::RelationshipManagerType>("rm_type") = rm_type;
rm_params.set<std::string>("for_whom") = name();

// Figure out if we shouldn't be adding this one yet
if (((rm_type & input_rm_type) != input_rm_type) // Does this RM not have the type passed in?

|| // Or are we adding Geometric but this one needs to be delayed

(((input_rm_type & Moose::RelationshipManagerType::GEOMETRIC) ==
Moose::RelationshipManagerType::GEOMETRIC) &&
((rm_type & Moose::RelationshipManagerType::GEOMETRIC) ==
Moose::RelationshipManagerType::GEOMETRIC) &&
!rm_params.template get<bool>("attach_geometric_early"))

|| // Or is this an Algebraic and Geometric one that we already added earlier?

(((input_rm_type & Moose::RelationshipManagerType::ALGEBRAIC) ==
Moose::RelationshipManagerType::ALGEBRAIC) &&
(rm_type == (Moose::RelationshipManagerType::GEOMETRIC |
Moose::RelationshipManagerType::ALGEBRAIC)) &&
rm_params.template get<bool>("attach_geometric_early")))
continue;

// If there is a callback for setting the RM parameters let's use it
if (rm_input_parameter_func)
rm_input_parameter_func(moose_object_pars, rm_params);

// If we're doing geometric but we can't build it early - then let's not build it yet
// (It will get built when we do algebraic)
if ((input_rm_type & Moose::RelationshipManagerType::GEOMETRIC) ==
Moose::RelationshipManagerType::GEOMETRIC &&
!rm_params.get<bool>("attach_geometric_early"))
{
// We also need to tell the mesh not to delete remote elements yet
// Note this will get reset in AddRelationshipManager::act() when attaching Algebraic
_mesh->getMesh().allow_remote_element_removal(false);

if (_problem->getDisplacedProblem())
_problem->getDisplacedProblem()->mesh().getMesh().allow_remote_element_removal(false);

// Keep looking for more RMs
continue;
}

rm_params.set<MooseMesh *>("mesh") = _mesh.get();

if (rm_params.areAllRequiredParamsValid())
{
auto rm_obj = _factory.create<RelationshipManager>(rm_name, new_name, rm_params);

// Delete the resources created on behalf of the RM if it ends up not being added to the App.
if (!_app.addRelationshipManager(rm_obj))
_factory.releaseSharedObjects(*rm_obj);
}
else
mooseError("Missing required parameters for RelationshipManager " + rm_name + " for object " +
name());
}
}

/// DEPRECATED METHODS
std::string
Action::getShortName() const
Expand Down
80 changes: 1 addition & 79 deletions framework/src/actions/MooseObjectAction.C
Expand Up @@ -11,12 +11,9 @@
#include "MooseObjectAction.h"
#include "MooseUtils.h"
#include "Factory.h"
#include "RelationshipManager.h"
#include "Conversion.h"
#include "MooseMesh.h"
#include "MooseApp.h"
#include "FEProblemBase.h"
#include "DisplacedProblem.h"

template <>
InputParameters
Expand Down Expand Up @@ -50,80 +47,5 @@ MooseObjectAction::MooseObjectAction(InputParameters params)
void
MooseObjectAction::addRelationshipManagers(Moose::RelationshipManagerType input_rm_type)
{
const auto & buildable_types = _moose_object_pars.getBuildableRelationshipManagerTypes();

// These need unique names
static unsigned int unique_object_id = 0;

for (const auto & buildable_type : buildable_types)
{
unique_object_id++;

auto & rm_name = std::get<0>(buildable_type);
auto & rm_type = std::get<1>(buildable_type);
auto rm_input_parameter_func = std::get<2>(buildable_type);

auto new_name = _moose_object_pars.get<std::string>("_moose_base") + '_' + name() + '_' +
rm_name + "_" + Moose::stringify(rm_type) + " " +
std::to_string(unique_object_id);

auto rm_params = _factory.getValidParams(rm_name);
rm_params.set<Moose::RelationshipManagerType>("rm_type") = rm_type;
rm_params.set<std::string>("for_whom") = name();

// Figure out if we shouldn't be adding this one yet
if (((rm_type & input_rm_type) != input_rm_type) // Does this RM not have the type passed in?

|| // Or are we adding Geometric but this one needs to be delayed

(((input_rm_type & Moose::RelationshipManagerType::GEOMETRIC) ==
Moose::RelationshipManagerType::GEOMETRIC) &&
((rm_type & Moose::RelationshipManagerType::GEOMETRIC) ==
Moose::RelationshipManagerType::GEOMETRIC) &&
!rm_params.template get<bool>("attach_geometric_early"))

|| // Or is this an Algebraic and Geometric one that we already added earlier?

(((input_rm_type & Moose::RelationshipManagerType::ALGEBRAIC) ==
Moose::RelationshipManagerType::ALGEBRAIC) &&
(rm_type == (Moose::RelationshipManagerType::GEOMETRIC |
Moose::RelationshipManagerType::ALGEBRAIC)) &&
rm_params.template get<bool>("attach_geometric_early")))
continue;

// If there is a callback for setting the RM parameters let's use it
if (rm_input_parameter_func)
rm_input_parameter_func(_moose_object_pars, rm_params);

// If we're doing geometric but we can't build it early - then let's not build it yet
// (It will get built when we do algebraic)
if ((input_rm_type & Moose::RelationshipManagerType::GEOMETRIC) ==
Moose::RelationshipManagerType::GEOMETRIC &&
!rm_params.get<bool>("attach_geometric_early"))
{
// We also need to tell the mesh not to delete remote elements yet
// Note this will get reset in AddRelationshipManager::act() when attaching Algebraic
_mesh->getMesh().allow_remote_element_removal(false);

if (_problem->getDisplacedProblem())
_problem->getDisplacedProblem()->mesh().getMesh().allow_remote_element_removal(false);

// Keep looking for more RMs
continue;
}

rm_params.set<MooseMesh *>("mesh") = _mesh.get();

if (rm_params.areAllRequiredParamsValid())
{
auto rm_obj = _factory.create<RelationshipManager>(rm_name, new_name, rm_params);

// Delete the resources created on behalf of the RM if it ends up not being added to the App.
if (!_app.addRelationshipManager(rm_obj))
_factory.releaseSharedObjects(*rm_obj);
}
else
mooseError("Missing required parameters for RelationshipManager " + rm_name + " for object " +
name());
}
addRelationshipManagers(input_rm_type, _moose_object_pars);
}
2 changes: 1 addition & 1 deletion framework/src/dgkernels/ADDGKernel.C
Expand Up @@ -17,7 +17,7 @@
// libmesh includes
#include "libmesh/threads.h"

defineADBaseValidParams(ADDGKernel, DGKernelBase, params.registerBase("DGKernel"););
defineADBaseValidParams(ADDGKernel, DGKernelBase, );

template <ComputeStage compute_stage>
ADDGKernel<compute_stage>::ADDGKernel(const InputParameters & parameters)
Expand Down
1 change: 0 additions & 1 deletion framework/src/dgkernels/DGKernel.C
Expand Up @@ -28,7 +28,6 @@ InputParameters
validParams<DGKernel>()
{
InputParameters params = validParams<DGKernelBase>();
params.registerBase("DGKernel");
return params;
}

Expand Down
1 change: 1 addition & 0 deletions framework/src/dgkernels/DGKernelBase.C
Expand Up @@ -61,6 +61,7 @@ validParams<DGKernelBase>()
params.addRelationshipManager("ElementSideNeighborLayers",
Moose::RelationshipManagerType::GEOMETRIC |
Moose::RelationshipManagerType::ALGEBRAIC);
params.registerBase("DGKernel");

return params;
}
Expand Down

0 comments on commit 97c0cb3

Please sign in to comment.