10 #ifndef MUELU_USERAGGREGATIONFACTORY_DEF_HPP_
11 #define MUELU_USERAGGREGATIONFACTORY_DEF_HPP_
13 #include <Xpetra_Map.hpp>
15 #include <Xpetra_MultiVectorFactory.hpp>
17 #include <Xpetra_MapFactory.hpp>
22 #include "MueLu_Aggregates.hpp"
27 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
32 validParamList->
set<std::string>(
"filePrefix",
"",
"The data is read from files of this name: <filePrefix><level>_<PID>.<fileExt>");
33 validParamList->
set<std::string>(
"fileExt",
"",
"The data is read from files of this name: <filePrefix><level>_<PID>.<fileExt>");
35 return validParamList;
38 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
47 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
54 const int myRank = comm->getRank();
56 std::string fileName = pL.
get<std::string>(
"filePrefix") +
toString(currentLevel.
GetLevelID()) +
"_" +
toString(myRank) +
"." + pL.
get<std::string>(
"fileExt");
57 std::ifstream ifs(fileName.c_str());
60 LO numVertices, numAggregates;
65 TEUCHOS_TEST_FOR_EXCEPTION(numAggregates <= 0, Exceptions::InvalidArgument, "Number of aggregates must be > 0
");
67 Xpetra::UnderlyingLib lib = currentLevel.lib();
68 const int indexBase = 0;
69 RCP<Map> map = MapFactory::Build(lib, numVertices, indexBase, comm);
71 RCP<Aggregates> aggregates = rcp(new Aggregates(map));
72 aggregates->setObjectLabel("User
");
74 aggregates->SetNumAggregates(numAggregates);
76 Teuchos::ArrayRCP<LO> vertex2AggId = aggregates->GetVertex2AggId()->getDataNonConst(0);
77 Teuchos::ArrayRCP<LO> procWinner = aggregates->GetProcWinner()->getDataNonConst(0);
79 for (LO i = 0; i < numAggregates; i++) {
83 std::vector<LO> list(aggSize);
84 for (int k = 0; k < aggSize; k++) {
85 // FIXME: File contains GIDs, we need LIDs
86 // for now, works on a single processor
90 // Mark first node as root node for the aggregate
91 aggregates->SetIsRoot(list[0]);
93 // Fill vertex2AggId and procWinner structure with information
94 for (int k = 0; k < aggSize; k++) {
95 vertex2AggId[list[k]] = i;
96 procWinner[list[k]] = myRank;
100 // FIXME: do the proper check whether aggregates cross interprocessor boundary
101 aggregates->AggregatesCrossProcessors(false);
105 GetOStream(Statistics0) << aggregates->description() << std::endl;
110 #endif /* MUELU_USERAGGREGATIONFACTORY_DEF_HPP_ */
std::string toString(const T &what)
Little helper function to convert non-string types to strings.
Container class for aggregation information.
void DeclareInput(Level ¤tLevel) const
Input.
T & get(const std::string &name, T def_value)
Timer to be used in factories. Similar to Monitor but with additional timers.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
static Teuchos::RCP< const Comm< OrdinalType > > getComm()
void Build(Level ¤tLevel) const
Build aggregates.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
Class that holds all level-specific information.
int GetLevelID() const
Return level number.
Exception throws to report errors in the internal logical of the program.