46#ifndef MUELU_USERAGGREGATIONFACTORY_DEF_HPP_
47#define MUELU_USERAGGREGATIONFACTORY_DEF_HPP_
49#include <Xpetra_Map.hpp>
50#include <Xpetra_Vector.hpp>
51#include <Xpetra_MultiVectorFactory.hpp>
52#include <Xpetra_VectorFactory.hpp>
53#include <Xpetra_MapFactory.hpp>
59#include "MueLu_Aggregates.hpp"
61#include "MueLu_Utilities.hpp"
65 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
67 RCP<ParameterList> validParamList = rcp(
new ParameterList());
70 validParamList->set<std::string>(
"filePrefix",
"",
"The data is read from files of this name: <filePrefix><level>_<PID>.<fileExt>");
71 validParamList->set<std::string>(
"fileExt",
"",
"The data is read from files of this name: <filePrefix><level>_<PID>.<fileExt>");
73 return validParamList;
76 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
85 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
89 const ParameterList& pL = GetParameterList();
91 RCP< const Teuchos::Comm<int> > comm = Teuchos::DefaultComm<int>::getComm();
92 const int myRank = comm->getRank();
94 std::string fileName = pL.get<std::string>(
"filePrefix") +
toString(currentLevel.
GetLevelID()) +
"_" +
toString(myRank) +
"." + pL.get<std::string>(
"fileExt");
95 std::ifstream ifs(fileName.c_str());
98 LO numVertices, numAggregates;
101 ifs >> numAggregates;
102 TEUCHOS_TEST_FOR_EXCEPTION(numVertices <= 0, Exceptions::InvalidArgument, "Number of vertices must be > 0
");
103 TEUCHOS_TEST_FOR_EXCEPTION(numAggregates <= 0, Exceptions::InvalidArgument, "Number of aggregates must be > 0
");
105 Xpetra::UnderlyingLib lib = currentLevel.lib();
106 const int indexBase = 0;
107 RCP<Map> map = MapFactory::Build(lib, numVertices, indexBase, comm);
109 RCP<Aggregates> aggregates = rcp(new Aggregates(map));
110 aggregates->setObjectLabel("User
");
112 aggregates->SetNumAggregates(numAggregates);
114 Teuchos::ArrayRCP<LO> vertex2AggId = aggregates->GetVertex2AggId()->getDataNonConst(0);
115 Teuchos::ArrayRCP<LO> procWinner = aggregates->GetProcWinner() ->getDataNonConst(0);
117 for (LO i = 0; i < numAggregates; i++) {
121 std::vector<LO> list(aggSize);
122 for (int k = 0; k < aggSize; k++) {
123 // FIXME: File contains GIDs, we need LIDs
124 // for now, works on a single processor
128 // Mark first node as root node for the aggregate
129 aggregates->SetIsRoot(list[0]);
131 // Fill vertex2AggId and procWinner structure with information
132 for (int k = 0; k < aggSize; k++) {
133 vertex2AggId[list[k]] = i;
134 procWinner [list[k]] = myRank;
138 // FIXME: do the proper check whether aggregates cross interprocessor boundary
139 aggregates->AggregatesCrossProcessors(false);
143 GetOStream(Statistics0) << aggregates->description() << std::endl;
148#endif /* MUELU_USERAGGREGATIONFACTORY_DEF_HPP_ */
Container class for aggregation information.
Exception throws to report errors in the internal logical of the program.
Timer to be used in factories. Similar to Monitor but with additional timers.
Class that holds all level-specific information.
int GetLevelID() const
Return level number.
void DeclareInput(Level ¤tLevel) const
Input.
void Build(Level ¤tLevel) const
Build aggregates.
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
Namespace for MueLu classes and methods.
std::string toString(const T &what)
Little helper function to convert non-string types to strings.