MueLu
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
MueLu_UserAggregationFactory_def.hpp
Go to the documentation of this file.
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
#ifndef MUELU_USERAGGREGATIONFACTORY_DEF_HPP_
11
#define MUELU_USERAGGREGATIONFACTORY_DEF_HPP_
12
13
#include <Xpetra_Map.hpp>
14
#include <Xpetra_Vector.hpp>
15
#include <Xpetra_MultiVectorFactory.hpp>
16
#include <Xpetra_VectorFactory.hpp>
17
#include <Xpetra_MapFactory.hpp>
18
19
#include "
MueLu_UserAggregationFactory_decl.hpp
"
20
21
#include "
MueLu_Level.hpp
"
22
#include "MueLu_Aggregates.hpp"
23
#include "
MueLu_Monitor.hpp
"
24
25
namespace
MueLu
{
26
27
template
<
class
LocalOrdinal,
class
GlobalOrdinal,
class
Node>
28
RCP<const ParameterList>
UserAggregationFactory<LocalOrdinal, GlobalOrdinal, Node>::GetValidParameterList
()
const
{
29
RCP<ParameterList> validParamList = rcp(
new
ParameterList());
30
31
// input parameters
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>"
);
34
35
return
validParamList;
36
}
37
38
template
<
class
LocalOrdinal,
class
GlobalOrdinal,
class
Node>
39
void
UserAggregationFactory<LocalOrdinal, GlobalOrdinal, Node>::DeclareInput
(
Level
&
/* currentLevel */
)
const
{}
40
47
template
<
class
LocalOrdinal,
class
GlobalOrdinal,
class
Node>
48
void
UserAggregationFactory<LocalOrdinal, GlobalOrdinal, Node>::Build
(
Level
& currentLevel)
const
{
49
FactoryMonitor
m(*
this
,
"Build"
, currentLevel);
50
51
const
ParameterList& pL =
GetParameterList
();
52
53
RCP<const Teuchos::Comm<int> > comm = Teuchos::DefaultComm<int>::getComm();
54
const
int
myRank = comm->getRank();
55
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());
58
TEUCHOS_TEST_FOR_EXCEPTION(!ifs.good(),
Exceptions::RuntimeError
,
"Cannot read data from \""
<< fileName <<
"\""
);
59
60
LO numVertices, numAggregates;
61
ifs >> numVertices;
62
TEUCHOS_TEST_FOR_EXCEPTION(!ifs.good(),
Exceptions::RuntimeError
,
"Cannot read data from \""
<< fileName <<
"\""
);
63
ifs >> numAggregates;
64
TEUCHOS_TEST_FOR_EXCEPTION(numVertices <= 0, Exceptions::InvalidArgument, "Number of vertices must be > 0
");
65
TEUCHOS_TEST_FOR_EXCEPTION(numAggregates <= 0, Exceptions::InvalidArgument, "
Number of aggregates must be > 0
");
66
67
Xpetra::UnderlyingLib lib = currentLevel.lib();
68
const int indexBase = 0;
69
RCP<Map> map = MapFactory::Build(lib, numVertices, indexBase, comm);
70
71
RCP<Aggregates> aggregates = rcp(new Aggregates(map));
72
aggregates->setObjectLabel("
User
");
73
74
aggregates->SetNumAggregates(numAggregates);
75
76
Teuchos::ArrayRCP<LO> vertex2AggId = aggregates->GetVertex2AggId()->getDataNonConst(0);
77
Teuchos::ArrayRCP<LO> procWinner = aggregates->GetProcWinner()->getDataNonConst(0);
78
79
for (LO i = 0; i < numAggregates; i++) {
80
int aggSize = 0;
81
ifs >> aggSize;
82
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
87
ifs >> list[k];
88
}
89
90
// Mark first node as root node for the aggregate
91
aggregates->SetIsRoot(list[0]);
92
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;
97
}
98
}
99
100
// FIXME: do the proper check whether aggregates cross interprocessor boundary
101
aggregates->AggregatesCrossProcessors(false);
102
103
Set(currentLevel, "
Aggregates
", aggregates);
104
105
GetOStream(Statistics0) << aggregates->description() << std::endl;
106
}
107
108
} // namespace MueLu
109
110
#endif /* MUELU_USERAGGREGATIONFACTORY_DEF_HPP_ */
MueLu_Level.hpp
MueLu_Monitor.hpp
MueLu_UserAggregationFactory_decl.hpp
MueLu::Aggregates
Container class for aggregation information.
Definition
MueLu_Aggregates_decl.hpp:67
MueLu::Exceptions::RuntimeError
Exception throws to report errors in the internal logical of the program.
Definition
MueLu_Exceptions.hpp:36
MueLu::FactoryMonitor
Timer to be used in factories. Similar to Monitor but with additional timers.
Definition
MueLu_Monitor.hpp:165
MueLu::Level
Class that holds all level-specific information.
Definition
MueLu_Level.hpp:63
MueLu::Level::GetLevelID
int GetLevelID() const
Return level number.
Definition
MueLu_Level.cpp:51
MueLu::ParameterListAcceptorImpl::GetParameterList
virtual const Teuchos::ParameterList & GetParameterList() const
Definition
MueLu_ParameterListAcceptor.cpp:50
MueLu::UserAggregationFactory::DeclareInput
void DeclareInput(Level ¤tLevel) const
Input.
Definition
MueLu_UserAggregationFactory_def.hpp:39
MueLu::UserAggregationFactory::Build
void Build(Level ¤tLevel) const
Build aggregates.
Definition
MueLu_UserAggregationFactory_def.hpp:48
MueLu::UserAggregationFactory::GetValidParameterList
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
Definition
MueLu_UserAggregationFactory_def.hpp:28
MueLu
Namespace for MueLu classes and methods.
Definition
MueLu_BrickAggregationFactory_decl.hpp:42
MueLu::toString
std::string toString(const T &what)
Little helper function to convert non-string types to strings.
Definition
MueLu_Utilities_decl.hpp:242
src
Graph
UserAggregation
MueLu_UserAggregationFactory_def.hpp
Generated by
1.17.0