Debian Codegraph @

packages/muelu/test/contact/SegregatedAggFromFile.cpp

raw
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_Aggregates.hpp"
15 #include "MueLu_AmalgamationFactory.hpp"
16 #include "MueLu_CoalesceDropFactory.hpp"
17 #include "MueLu_CreateXpetraPreconditioner.hpp"
18 #include "MueLu_Hierarchy.hpp"
19 #include "MueLu_ParameterListInterpreter.hpp"
20 #include "MueLu_TestHelpers.hpp"
21 #include "MueLu_UncoupledAggregationFactory.hpp"
22
23 // Teuchos
24 #include <Teuchos_XMLParameterListHelpers.hpp>
25
26 // Xpetra
27 #include <Xpetra_IO.hpp>
28 #include <Xpetra_MatrixUtils.hpp>
29
30 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
31 int main_(Teuchos::CommandLineProcessor &clp, Xpetra::UnderlyingLib &lib, int argc, char *argv[]) {
32 #include "MueLu_UseShortNames.hpp"
33
34 // The SegregatedAFactory tests only work with real Scalar types,
35 if (Teuchos::ScalarTraits<Scalar>::isComplex) return EXIT_SUCCESS;
36
37 using GST = Teuchos::ScalarTraits<GO>;
38
39 using Teuchos::RCP;
40 using Teuchos::rcp;
41
42 RCP<const Teuchos::Comm<int>> comm = Teuchos::DefaultComm<int>::getComm();
43
44 std::string probName = "";
45 clp.setOption("probName", &probName, "Short name of the problem. Used to read-in the problem from files.");
46 GO numTotalDofs = -GST::one();
47 clp.setOption("nDof", &numTotalDofs, "Total number of DOFs");
48 int nDofPerNode = -1;
49 clp.setOption("nDofPerNode", &nDofPerNode, "Number of DOFS per Node");
50
51 switch (clp.parse(argc, argv)) {
52 case Teuchos::CommandLineProcessor::PARSE_HELP_PRINTED: return EXIT_SUCCESS;
53 case Teuchos::CommandLineProcessor::PARSE_ERROR:
54 case Teuchos::CommandLineProcessor::PARSE_UNRECOGNIZED_OPTION: return EXIT_FAILURE;
55 case Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL: break;
56 }
57
58 TEUCHOS_TEST_FOR_EXCEPTION(probName == "", MueLu::Exceptions::InvalidArgument, "Please specify a valid problem name.");
59 TEUCHOS_TEST_FOR_EXCEPTION(numTotalDofs == -GST::one(), MueLu::Exceptions::InvalidArgument,
60 "Please specify the global number of DOFs on the command line.");
61
62 std::vector<size_t> stridingInfo;
63 stridingInfo.push_back(nDofPerNode);
64
65 // Create the solid block dof row map
66 std::string map1Name = "blockmap";
67 std::vector<GO> blockmapEntries{30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53};
68 RCP<const Map> blockmap = Xpetra::MapFactory<LO, GO, NO>::Build(lib, blockmapEntries.size(), blockmapEntries, 30, comm);
69
70 // Create the interface dof row maps
71 std::vector<GO> integration_side_map_entries{42, 43, 44, 45, 52, 53};
72 RCP<const Map> integration_side_map = Xpetra::MapFactory<LO, GO, NO>::Build(lib, integration_side_map_entries.size(), integration_side_map_entries, 0,
73 comm);
74 std::vector<GO> projection_side_map_entries{0, 1, 6, 7, 22, 23};
75 RCP<const Map> projection_side_map = Xpetra::MapFactory<LO, GO, NO>::Build(lib, projection_side_map_entries.size(), projection_side_map_entries, 0,
76 comm);
77
78 // Read the matrix from file
79 const std::string matrixFileName = probName + "_matrix.mm";
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
84 // define amalgamation factory
85 RCP<AmalgamationFactory> amalgFact = RCP(new AmalgamationFactory());
86
87 // define CoalesceDropFactory that provides Graph
88 RCP<CoalesceDropFactory> dropFact = RCP(new CoalesceDropFactory());
89 dropFact->SetFactory("UnAmalgamationInfo", amalgFact);
90
91 // Setup aggregation factory
92 RCP<UncoupledAggregationFactory> uncoupledAggFact = rcp(new UncoupledAggregationFactory());
93 uncoupledAggFact->SetFactory("Graph", dropFact);
94 uncoupledAggFact->SetOrdering("graph");
95
96 RCP<FactoryManager> M = rcp(new FactoryManager());
97 RCP<MueLu::Level> level = rcp(new MueLu::Level());
98 level->SetLevelID(0);
99 TEUCHOS_ASSERT_EQUALITY(level->GetLevelID(), 0);
100 level->Set("A", mat);
101 TEUCHOS_ASSERT(level->IsAvailable("A", MueLu::NoFactory::get()));
102 level->SetFactoryManager(M);
103
104 level->Request("Aggregates", uncoupledAggFact.get());
105 level->Request(*uncoupledAggFact);
106 uncoupledAggFact->Build(*level);
107 RCP<Aggregates> aggregates = level->Get<RCP<Aggregates>>("Aggregates", uncoupledAggFact.get());
108
109 typename Aggregates::LO_view aggPtr;
110 typename Aggregates::LO_view aggNodes;
111 typename Aggregates::LO_view unaggregated;
112
113 aggregates->ComputeNodesInAggregate(aggPtr, aggNodes, unaggregated);
114
115 MueLuTests::checkAggregatesBlockmap<SC, LO, GO, NO>(aggregates, stridingInfo, blockmap);
116 MueLuTests::checkAggregatesMapPair<SC, LO, GO, NO>(aggregates, stridingInfo, integration_side_map, projection_side_map);
117 return EXIT_SUCCESS;
118 }
119
120 //-----------------------------------------------------------
121 #define MUELU_AUTOMATIC_TEST_ETI_NAME main_
122 #include "MueLu_Test_ETI.hpp"
123
124 int main(int argc, char *argv[]) {
125 return Automatic_Test_ETI(argc, argv);
126 }