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>
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>
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;
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_ */
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)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Timer to be used in factories. Similar to Monitor but with additional timers.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
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.