46 #ifndef MUELU_USERPFACTORY_DEF_HPP 47 #define MUELU_USERPFACTORY_DEF_HPP 49 #include <Xpetra_MultiVectorFactory.hpp> 50 #include <Xpetra_Matrix.hpp> 53 #include "MueLu_PerfUtils.hpp" 54 #include "MueLu_UserPFactory.hpp" 55 #include "MueLu_Utilities.hpp" 59 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
61 RCP<ParameterList> validParamList = rcp(
new ParameterList());
63 validParamList->set< RCP<const FactoryBase> >(
"A", Teuchos::null,
"Generating factory of the matrix A");
64 validParamList->set< RCP<const FactoryBase> >(
"Nullspace", Teuchos::null,
"Generating factory of the nullspace");
65 validParamList->set< std::string > (
"matrixFileName",
"",
"File with matrix data");
66 validParamList->set< std::string > (
"mapFileName",
"",
"File with coarse map data");
68 return validParamList;
71 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
73 Input(fineLevel,
"A");
74 Input(fineLevel,
"Nullspace");
77 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
79 return BuildP(fineLevel, coarseLevel);
82 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
86 RCP<Matrix> A = Get< RCP<Matrix> > (fineLevel,
"A");
87 RCP<MultiVector> fineNullspace = Get< RCP<MultiVector> > (fineLevel,
"Nullspace");
89 TEUCHOS_TEST_FOR_EXCEPTION(A->GetFixedBlockSize() != 1,
Exceptions::RuntimeError,
"Block size > 1 has not been implemented");
91 const Teuchos::ParameterList& pL = GetParameterList();
93 std::string mapFile = pL.get<std::string>(
"mapFileName");
94 RCP<const Map> rowMap = A->getRowMap();
95 RCP<const Map> coarseMap =
Utils2::ReadMap(mapFile, rowMap->lib(), rowMap->getComm());
96 Set(coarseLevel,
"CoarseMap", coarseMap);
98 std::string matrixFile = pL.get<std::string>(
"matrixFileName");
99 RCP<Matrix> P =
Utils::Read(matrixFile, rowMap, coarseMap, coarseMap, rowMap);
101 Set(coarseLevel,
"P", P);
104 RCP<Matrix> P1 = Utils::Multiply(*A,
false, *P,
false);
105 P =
Utils::Read(matrixFile, rowMap, P1->getColMap(), coarseMap, rowMap);
106 Set(coarseLevel,
"P", P);
109 RCP<MultiVector> coarseNullspace = MultiVectorFactory::Build(coarseMap, fineNullspace->getNumVectors());
110 P->apply(*fineNullspace, *coarseNullspace, Teuchos::TRANS, Teuchos::ScalarTraits<SC>::one(), Teuchos::ScalarTraits<SC>::zero());
111 Set(coarseLevel,
"Nullspace", coarseNullspace);
114 size_t n = Teuchos::as<size_t>(sqrt(coarseMap->getGlobalNumElements()));
115 TEUCHOS_TEST_FOR_EXCEPTION(n*n != coarseMap->getGlobalNumElements(),
Exceptions::RuntimeError,
"Unfortunately, this is not the case, don't know what to do");
117 RCP<MultiVector> coarseCoords = MultiVectorFactory::Build(coarseMap, 2);
118 ArrayRCP<Scalar> x = coarseCoords->getDataNonConst(0), y = coarseCoords->getDataNonConst(1);
119 for (
size_t LID = 0; LID < coarseMap->getNodeNumElements(); ++LID) {
120 GlobalOrdinal GID = coarseMap->getGlobalElement(LID) - coarseMap->getIndexBase();
121 GlobalOrdinal i = GID % n, j = GID/n;
125 Set(coarseLevel,
"Coordinates", coarseCoords);
128 RCP<ParameterList> params = rcp(
new ParameterList());
129 params->set(
"printLoadBalancingInfo",
true);
137 #define MUELU_USERPFACTORY_SHORT 138 #endif // MUELU_USERPFACTORY_DEF_HPP void Build(Level &fineLevel, Level &coarseLevel) const
Build an object with this factory.
Timer to be used in factories. Similar to Monitor but with additional timers.
void BuildP(Level &fineLevel, Level &coarseLevel) const
Abstract Build method.
Namespace for MueLu classes and methods.
static Teuchos::RCP< Matrix > Read(const std::string &fileName, Xpetra::UnderlyingLib lib, const RCP< const Teuchos::Comm< int > > &comm, bool binary=false)
Read matrix from file in Matrix Market or binary format.
void DeclareInput(Level &fineLevel, Level &coarseLevel) const
Input.
Class that holds all level-specific information.
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
static std::string PrintMatrixInfo(const Matrix &A, const std::string &msgTag, RCP< const Teuchos::ParameterList > params=Teuchos::null)
static RCP< const Map > ReadMap(const std::string &fileName, Xpetra::UnderlyingLib lib, const RCP< const Teuchos::Comm< int > > &comm)
Exception throws to report errors in the internal logical of the program.