| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// MueLu: A package for multigrid based preconditioning |
| 4 |
// |
| 5 |
// Copyright 2012 NTESS and the MueLu contributors. |
| 6 |
// SPDX-License-Identifier: BSD-3-Clause |
| 7 |
// ***************************************************************************** |
| 8 |
// @HEADER |
| 9 |
|
| 10 |
// Test |
| 11 |
#include "contact_Helpers.hpp" |
| 12 |
|
| 13 |
// MueLu |
| 14 |
#include "MueLu_AmalgamationFactory.hpp" |
| 15 |
#include "MueLu_CoalesceDropFactory.hpp" |
| 16 |
#include "MueLu_FactoryManager.hpp" |
| 17 |
#include "MueLu_GenericRFactory.hpp" |
| 18 |
#include "MueLu_MapTransferFactory.hpp" |
| 19 |
#include "MueLu_NullspaceFactory.hpp" |
| 20 |
#include "MueLu_ParameterListInterpreter.hpp" |
| 21 |
#include "MueLu_RAPFactory.hpp" |
| 22 |
#include "MueLu_SegregatedAFactory.hpp" |
| 23 |
#include "MueLu_TentativePFactory.hpp" |
| 24 |
#include "MueLu_TestHelpers.hpp" |
| 25 |
#include "MueLu_TransPFactory.hpp" |
| 26 |
#include "MueLu_UncoupledAggregationFactory.hpp" |
| 27 |
|
| 28 |
// Teuchos |
| 29 |
#include <Teuchos_XMLParameterListHelpers.hpp> |
| 30 |
|
| 31 |
// Xpetra |
| 32 |
#include <Xpetra_MatrixUtils.hpp> |
| 33 |
#include <Xpetra_MapFactory.hpp> |
| 34 |
#include <Xpetra_StridedMapFactory.hpp> |
| 35 |
|
| 36 |
template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node> |
| 37 |
int main_(Teuchos::CommandLineProcessor &clp, Xpetra::UnderlyingLib &lib, int argc, char *argv[]) { |
| 38 |
#include "MueLu_UseShortNames.hpp" |
| 39 |
|
| 40 |
// The SegregatedAFactory tests only work with real Scalar types, |
| 41 |
if (Teuchos::ScalarTraits<Scalar>::isComplex) return EXIT_SUCCESS; |
| 42 |
|
| 43 |
using GST = Teuchos::ScalarTraits<GO>; |
| 44 |
|
| 45 |
using Teuchos::RCP; |
| 46 |
using Teuchos::rcp; |
| 47 |
|
| 48 |
RCP<const Teuchos::Comm<int>> comm = Teuchos::DefaultComm<int>::getComm(); |
| 49 |
|
| 50 |
std::string probName = ""; |
| 51 |
clp.setOption("probName", &probName, "Short name of the problem. Used to read-in the problem from files."); |
| 52 |
GO numTotalDofs = -GST::one(); |
| 53 |
clp.setOption("nDof", &numTotalDofs, "Total number of DOFs"); |
| 54 |
int nDofPerNode = -1; |
| 55 |
clp.setOption("nDofPerNode", &nDofPerNode, "Number of DOFS per Node"); |
| 56 |
|
| 57 |
clp.recogniseAllOptions(true); |
| 58 |
switch (clp.parse(argc, argv)) { |
| 59 |
case Teuchos::CommandLineProcessor::PARSE_HELP_PRINTED: |
| 60 |
return EXIT_SUCCESS; |
| 61 |
case Teuchos::CommandLineProcessor::PARSE_ERROR: |
| 62 |
case Teuchos::CommandLineProcessor::PARSE_UNRECOGNIZED_OPTION: |
| 63 |
return EXIT_FAILURE; |
| 64 |
case Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL: |
| 65 |
break; |
| 66 |
} |
| 67 |
|
| 68 |
TEUCHOS_TEST_FOR_EXCEPTION(probName == "", MueLu::Exceptions::InvalidArgument, "Please specify the problem name on the command line."); |
| 69 |
TEUCHOS_TEST_FOR_EXCEPTION(numTotalDofs == -GST::one(), MueLu::Exceptions::InvalidArgument, "Please specify the global number of DOF on the command line."); |
| 70 |
TEUCHOS_TEST_FOR_EXCEPTION(nDofPerNode == -1, MueLu::Exceptions::InvalidArgument, "Please specify the number of DOF per mesh node on the command line."); |
| 71 |
|
| 72 |
const std::string matrixFileName = probName + "_matrix.mm"; |
| 73 |
const std::string nullspaceFileName = probName + "_nullspace.mm"; |
| 74 |
const std::string dropMap1Name = "dropMap1"; |
| 75 |
const std::string dropMap2Name = "dropMap2"; |
| 76 |
const std::string droppingScheme = "map-pair"; |
| 77 |
|
| 78 |
std::vector<size_t> stridingInfo; |
| 79 |
stridingInfo.push_back(nDofPerNode); |
| 80 |
TEUCHOS_ASSERT(!matrixFileName.empty()); |
| 81 |
RCP<Matrix> mat = Xpetra::IO<SC, LO, GO, NO>::Read(matrixFileName, lib, comm); |
| 82 |
Xpetra::MatrixUtils<SC, LO, GO, NO>::convertMatrixToStridedMaps(mat, stridingInfo, stridingInfo); |
| 83 |
RCP<const Map> rowmap = mat->getRowMap(); |
| 84 |
TEUCHOS_ASSERT(!nullspaceFileName.empty()); |
| 85 |
RCP<MultiVector> nullspace = Xpetra::IO<SC, LO, GO, NO>::ReadMultiVector(nullspaceFileName, rowmap); |
| 86 |
|
| 87 |
// Create the interface dof row maps |
| 88 |
std::vector<GO> integration_side_map_Entries{42, 43, 44, 45, 52, 53}; |
| 89 |
RCP<const Map> dropMap1 = Xpetra::MapFactory<LO, GO, NO>::Build(lib, integration_side_map_Entries.size(), integration_side_map_Entries, 0, |
| 90 |
comm); |
| 91 |
std::vector<GO> projection_side_map_Entries{0, 1, 6, 7, 22, 23}; |
| 92 |
RCP<const Map> dropMap2 = Xpetra::MapFactory<LO, GO, NO>::Build(lib, projection_side_map_Entries.size(), projection_side_map_Entries, 0, |
| 93 |
comm); |
| 94 |
///////////// Factories Definitions ///////////// |
| 95 |
//// Factories: level 0 |
| 96 |
// define segregatedAFactory that provides Matrix A to CoalesceDropFactory |
| 97 |
RCP<SegregatedAFactory> segregatedAFactLevelZero = RCP(new SegregatedAFactory()); |
| 98 |
segregatedAFactLevelZero->SetFactory("A", MueLu::NoFactory::getRCP()); |
| 99 |
segregatedAFactLevelZero->SetParameter("droppingScheme", Teuchos::ParameterEntry(droppingScheme)); |
| 100 |
segregatedAFactLevelZero->SetFactory(dropMap1Name, MueLu::NoFactory::getRCP()); |
| 101 |
segregatedAFactLevelZero->SetFactory(dropMap2Name, MueLu::NoFactory::getRCP()); |
| 102 |
|
| 103 |
// define amalgamation factory |
| 104 |
RCP<AmalgamationFactory> amalgFactLevelZero = RCP(new AmalgamationFactory()); |
| 105 |
|
| 106 |
// define CoalesceDropFactory that provides Graph |
| 107 |
RCP<CoalesceDropFactory> dropFactLevelZero = RCP(new CoalesceDropFactory()); |
| 108 |
dropFactLevelZero->SetFactory("UnAmalgamationInfo", amalgFactLevelZero); |
| 109 |
dropFactLevelZero->SetFactory("A", segregatedAFactLevelZero); |
| 110 |
|
| 111 |
// Setup aggregation factory |
| 112 |
RCP<UncoupledAggregationFactory> uncoupledAggFactLevelZero = rcp(new UncoupledAggregationFactory()); |
| 113 |
uncoupledAggFactLevelZero->SetFactory("Graph", dropFactLevelZero); |
| 114 |
uncoupledAggFactLevelZero->SetFactory("DofsPerNode", dropFactLevelZero); |
| 115 |
uncoupledAggFactLevelZero->SetOrdering("graph"); |
| 116 |
uncoupledAggFactLevelZero->SetParameter("aggregation: min agg size", Teuchos::ParameterEntry(2)); |
| 117 |
uncoupledAggFactLevelZero->SetParameter("aggregation: max agg size", Teuchos::ParameterEntry(3)); |
| 118 |
|
| 119 |
// Setup TentativePFactory |
| 120 |
RCP<TentativePFactory> tentativePFactLevelZero = rcp(new TentativePFactory()); |
| 121 |
tentativePFactLevelZero->SetFactory("A", segregatedAFactLevelZero); |
| 122 |
tentativePFactLevelZero->SetFactory("Aggregates", uncoupledAggFactLevelZero); |
| 123 |
|
| 124 |
// Setup transPFact for generating R |
| 125 |
RCP<TransPFactory> transPFactLevelZero = rcp(new TransPFactory()); |
| 126 |
transPFactLevelZero->SetFactory("P", tentativePFactLevelZero); |
| 127 |
|
| 128 |
// Setup nullspace Factory |
| 129 |
RCP<NullspaceFactory> nullspaceFactLevelZero = rcp(new NullspaceFactory()); |
| 130 |
nullspaceFactLevelZero->SetParameter("Fine level nullspace", Teuchos::ParameterEntry(std::string("Nullspace"))); |
| 131 |
nullspaceFactLevelZero->SetFactory("Nullspace", tentativePFactLevelZero); |
| 132 |
|
| 133 |
// Setup RAP Factory |
| 134 |
RCP<RAPFactory> rapFactLevelZero = rcp(new RAPFactory()); |
| 135 |
rapFactLevelZero->SetFactory("A", MueLu::NoFactory::getRCP()); |
| 136 |
rapFactLevelZero->SetFactory("P", tentativePFactLevelZero); |
| 137 |
rapFactLevelZero->SetFactory("R", transPFactLevelZero); |
| 138 |
|
| 139 |
// Main Factory manager |
| 140 |
RCP<FactoryManager> M0 = rcp(new FactoryManager()); |
| 141 |
M0->SetFactory("A", MueLu::NoFactory::getRCP()); |
| 142 |
M0->SetFactory("Graph", dropFactLevelZero); |
| 143 |
M0->SetFactory("UnAmalgamationInfo", amalgFactLevelZero); |
| 144 |
M0->SetFactory("Nullspace", nullspaceFactLevelZero); |
| 145 |
M0->SetFactory("P", tentativePFactLevelZero); |
| 146 |
M0->SetFactory("R", transPFactLevelZero); |
| 147 |
M0->SetFactory("Aggregates", uncoupledAggFactLevelZero); |
| 148 |
M0->SetFactory(dropMap1Name, MueLu::NoFactory::getRCP()); |
| 149 |
M0->SetFactory(dropMap2Name, MueLu::NoFactory::getRCP()); |
| 150 |
|
| 151 |
///////////// Level Definition ///////////// |
| 152 |
RCP<Level> levelZero = rcp(new Level()); |
| 153 |
RCP<Level> levelOne = rcp(new Level()); |
| 154 |
|
| 155 |
levelZero->SetLevelID(0); |
| 156 |
levelOne->SetLevelID(1); |
| 157 |
|
| 158 |
levelOne->SetPreviousLevel(levelZero); |
| 159 |
|
| 160 |
TEUCHOS_ASSERT_EQUALITY(levelZero->GetLevelID(), 0); |
| 161 |
TEUCHOS_ASSERT_EQUALITY(levelOne->GetLevelID(), 1); |
| 162 |
|
| 163 |
levelZero->Set("A", mat); |
| 164 |
levelZero->Set("Nullspace", nullspace); |
| 165 |
levelZero->Set(dropMap1Name, dropMap1); |
| 166 |
levelZero->Set(dropMap2Name, dropMap2); |
| 167 |
|
| 168 |
TEUCHOS_ASSERT(levelZero->IsAvailable("A", MueLu::NoFactory::get())); |
| 169 |
TEUCHOS_ASSERT(levelZero->IsAvailable("Nullspace", MueLu::NoFactory::get())); |
| 170 |
TEUCHOS_ASSERT(levelZero->IsAvailable(dropMap1Name, MueLu::NoFactory::get())); |
| 171 |
TEUCHOS_ASSERT(levelZero->IsAvailable(dropMap2Name, MueLu::NoFactory::get())); |
| 172 |
|
| 173 |
levelZero->SetFactoryManager(M0); |
| 174 |
|
| 175 |
///////////// Request and build level info ///////////// |
| 176 |
levelZero->Request("Aggregates", uncoupledAggFactLevelZero.get()); |
| 177 |
levelZero->Request(*uncoupledAggFactLevelZero); |
| 178 |
levelOne->Request("A", rapFactLevelZero.get()); |
| 179 |
|
| 180 |
TEUCHOS_ASSERT(levelZero->IsRequested("Aggregates", uncoupledAggFactLevelZero.get())); |
| 181 |
TEUCHOS_ASSERT(levelOne->IsRequested("A", rapFactLevelZero.get())); |
| 182 |
|
| 183 |
rapFactLevelZero->Build(*levelZero, *levelOne); |
| 184 |
|
| 185 |
TEUCHOS_ASSERT(levelZero->IsAvailable("Aggregates", uncoupledAggFactLevelZero.get())); |
| 186 |
|
| 187 |
RCP<Aggregates> aggsLevelZero = levelZero->Get<RCP<Aggregates>>("Aggregates", uncoupledAggFactLevelZero.get()); |
| 188 |
MueLuTests::checkAggregatesMapPair<SC, LO, GO, NO>(aggsLevelZero, stridingInfo, |
| 189 |
levelZero->Get<RCP<const Map>>(dropMap1Name, MueLu::NoFactory::get()), |
| 190 |
levelZero->Get<RCP<const Map>>(dropMap2Name, MueLu::NoFactory::get())); |
| 191 |
|
| 192 |
return EXIT_SUCCESS; |
| 193 |
} |
| 194 |
|
| 195 |
//----------------------------------------------------------- |
| 196 |
#define MUELU_AUTOMATIC_TEST_ETI_NAME main_ |
| 197 |
#include "MueLu_Test_ETI.hpp" |
| 198 |
|
| 199 |
int main(int argc, char *argv[]) { |
| 200 |
return Automatic_Test_ETI(argc, argv); |
| 201 |
} |