Skip to content

Commit

Permalink
MueLu: get dual/primal node mapping from user data
Browse files Browse the repository at this point in the history
For InterfaceAggregationFactory, the dual-to-primal node mapping needs
to be provided by the user on the "user data" sublist. Then, it is
treated as non-serializable data and added to the hierarchy during
CreateXpetraPreconditioner().

Adapted the test.

Part of trilinos#7164.
  • Loading branch information
mayrmt committed Apr 17, 2020
1 parent a767968 commit 6af3e1a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 33 deletions.
30 changes: 12 additions & 18 deletions packages/muelu/src/Misc/MueLu_InterfaceAggregationFactory_def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,6 @@ RCP<const ParameterList> InterfaceAggregationFactory<Scalar, LocalOrdinal, Globa

validParamList->set<LocalOrdinal>("number of DOFs per dual node", Teuchos::ScalarTraits<LocalOrdinal>::one(), "Number of DOFs per dual node");

/*
DualNodeID2PrimalNodeID represents the mapping between the Dual Node IDs to the Primal Node IDs.
This map makes one assumption: the number of dofs per dual node is a constant and has to be set in
the parameter list as "number of DOFs per dual node".
Layout of the std::map<key, value>:
- key: local ID of dual node
- value: local ID of primal node
*/
validParamList->set<RCP<std::map<LocalOrdinal, LocalOrdinal>>>("DualNodeID2PrimalNodeID - level 0", null, "");
return validParamList;
}

Expand All @@ -86,7 +76,17 @@ void InterfaceAggregationFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Dec
Input(currentLevel, "A");
Input(currentLevel, "Aggregates");

if (currentLevel.GetLevelID() != 0)
if (currentLevel.GetLevelID() == 0)
{
if(currentLevel.IsAvailable("DualNodeID2PrimalNodeID", NoFactory::get())) {
currentLevel.DeclareInput("DualNodeID2PrimalNodeID", NoFactory::get(), this);
} else {
TEUCHOS_TEST_FOR_EXCEPTION(currentLevel.IsAvailable("DualNodeID2PrimalNodeID", NoFactory::get()),
Exceptions::RuntimeError,
"DualNodeID2PrimalNodeID was not provided by the user on level 0!");
}
}
else
{
Input(currentLevel, "DualNodeID2PrimalNodeID");
}
Expand Down Expand Up @@ -114,15 +114,9 @@ void InterfaceAggregationFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Bui
RCP<Dual2Primal_type> lagr2dof;

if (currentLevel.GetLevelID() == 0)
{
lagr2dof = pL.get<RCP<Dual2Primal_type>>("DualNodeID2PrimalNodeID - level 0");

TEUCHOS_TEST_FOR_EXCEPTION(lagr2dof.is_null(), std::runtime_error, prefix << " MueLu requires a provided DualNodeID2PrimalNodeID map on the finest level.");
}
lagr2dof = currentLevel.Get<RCP<Dual2Primal_type>>("DualNodeID2PrimalNodeID", NoFactory::get());
else
{
lagr2dof = Get<RCP<Dual2Primal_type>>(currentLevel, "DualNodeID2PrimalNodeID");
}

const LocalOrdinal nDOFPerDualNode = pL.get<LocalOrdinal>("number of DOFs per dual node");

Expand Down
15 changes: 12 additions & 3 deletions packages/muelu/src/MueCentral/MueLu_HierarchyUtils_def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ namespace MueLu {
const std::string& name = it2->first;
TEUCHOS_TEST_FOR_EXCEPTION(name != "A" && name != "P" && name != "R" && name != "K" && name != "M" && name != "Mdiag" &&
name != "Nullspace" && name != "Coordinates" && name != "pcoarsen: element to node map" &&
name != "Node Comm" &&
name != "Node Comm" && name != "DualNodeID2PrimalNodeID" &&
!IsParamMuemexVariable(name), Exceptions::InvalidArgument,
std::string("MueLu::Utils::AddNonSerializableDataToHierarchy: parameter list contains unknown data type(") + name + ")");

Expand Down Expand Up @@ -131,7 +131,11 @@ namespace MueLu {
level->AddKeepFlag(name,NoFactory::get(),MueLu::UserData);
level->Set(name, Teuchos::getValue<RCP<const Teuchos::Comm<int> > >(it2->second), NoFactory::get());
}

else if(name == "DualNodeID2PrimalNodeID")
{
level->AddKeepFlag(name,NoFactory::get(),MueLu::UserData);
level->Set(name, Teuchos::getValue<RCP<std::map<LO, LO>>>(it2->second), NoFactory::get());
}
#ifdef HAVE_MUELU_INTREPID2
else if (name == "pcoarsen: element to node map")
{
Expand Down Expand Up @@ -187,7 +191,7 @@ namespace MueLu {
const std::string& name = it2->first;
TEUCHOS_TEST_FOR_EXCEPTION(name != "P" && name != "R" && name != "K" && name != "M" && name != "Mdiag" &&
name != "Nullspace" && name != "Coordinates" && name != "pcoarsen: element to node map" &&
name != "Node Comm" &&
name != "Node Comm" && name != "DualNodeID2PrimalNodeID" &&
!IsParamValidVariable(name), Exceptions::InvalidArgument,
std::string("MueLu::Utils::AddNonSerializableDataToHierarchy: user data parameter list contains unknown data type (") + name + ")");
if( name == "P" || name == "R" || name == "K" || name == "M") {
Expand All @@ -210,6 +214,11 @@ namespace MueLu {
level->AddKeepFlag(name,NoFactory::get(),MueLu::UserData);
level->Set(name, Teuchos::getValue<RCP<const Teuchos::Comm<int> > >(it2->second), NoFactory::get());
}
else if(name == "DualNodeID2PrimalNodeID")
{
level->AddKeepFlag(name,NoFactory::get(),MueLu::UserData);
level->Set(name, Teuchos::getValue<RCP<std::map<LO, LO>>>(it2->second), NoFactory::get());
}
#ifdef HAVE_MUELU_INTREPID2
else if (name == "pcoarsen: element to node map")
{
Expand Down
2 changes: 1 addition & 1 deletion packages/muelu/src/Utils/MueLu_Utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ namespace MueLu {
for (ParameterList::ConstIterator it2 = levelList.begin(); it2 != levelList.end(); it2++) {
const std::string& name = it2->first;
if (name == "A" || name == "P" || name == "R" || name== "M" || name == "Mdiag" || name == "K" || name == "Nullspace" || name == "Coordinates"
|| name == "Node Comm"
|| name == "Node Comm" || name == "DualNodeID2PrimalNodeID"
#ifdef HAVE_MUELU_INTREPID2 // For the IntrepidPCoarsenFactory
|| name == "pcoarsen: element to node map"
#endif
Expand Down
15 changes: 5 additions & 10 deletions packages/muelu/test/meshtying/MeshTyingBlocked_SimpleSmoother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
// @HEADER

// MueLu
#include <MueLu_CreateXpetraPreconditioner.hpp>
#include <MueLu_ConfigDefs.hpp>
#include <MueLu_ParameterListInterpreter.hpp>

Expand Down Expand Up @@ -209,17 +210,11 @@ int main(int argc, char *argv[])
std::string xmlFile = "myXML.xml";

RCP<ParameterList> params = Teuchos::getParametersFromXmlFile(xmlFile);
RCP<ParameterList> paramsF, paramsI;
paramsF = sublist(params, "Factories");
paramsI = sublist(paramsF, "myInterfaceAggs2");
paramsI->set<RCP<std::map<LO, LO>>>("DualNodeID2PrimalNodeID - level 0", rcpFromRef(myLagr2Dof));

ParameterListInterpreter mueLuFactory(*params, comm);
RCP<Hierarchy> H = mueLuFactory.CreateHierarchy();
H->GetLevel(0)->Set("A", rcp_dynamic_cast<xpetra_matrix_type>(blockedMatrix));
ParameterList& userDataParams = params->sublist("user data");
userDataParams.set<RCP<std::map<LO, LO>>>("DualNodeID2PrimalNodeID", rcpFromRef(myLagr2Dof));

RCP<Hierarchy> H = MueLu::CreateXpetraPreconditioner(Teuchos::rcp_dynamic_cast<Matrix>(blockedMatrix, true), *params);
H->IsPreconditioner(true);
H->SetDefaultVerbLevel(MueLu::Extreme);
mueLuFactory.SetupHierarchy(*H);

// Create the preconditioned GMRES solver
typedef xpetra_mvector_type MV;
Expand Down
2 changes: 1 addition & 1 deletion packages/muelu/test/meshtying/myXML.xml
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@

<Parameter name="max levels" type="int" value="3"/>
<Parameter name="coarse: max size" type="int" value="25"/>
<Parameter name="verbosity" type="string" value="High"/>
<Parameter name="verbosity" type="string" value="Extreme"/>
<Parameter name="use kokkos refactor" type="bool" value="false"/>

<ParameterList name="AllLevel">
Expand Down

0 comments on commit 6af3e1a

Please sign in to comment.