// @HEADER // ***************************************************************************** // MueLu: A package for multigrid based preconditioning // // Copyright 2012 NTESS and the MueLu contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER #ifndef MUELU_USERPFACTORY_DEF_HPP #define MUELU_USERPFACTORY_DEF_HPP #include #include #include #include "MueLu_Monitor.hpp" #include "MueLu_PerfUtils.hpp" #include "MueLu_UserPFactory_decl.hpp" namespace MueLu { template RCP UserPFactory::GetValidParameterList() const { RCP validParamList = rcp(new ParameterList()); validParamList->set >("A", Teuchos::null, "Generating factory of the matrix A"); validParamList->set >("Nullspace", Teuchos::null, "Generating factory of the nullspace"); validParamList->set("matrixFileName", "", "File with matrix data"); validParamList->set("mapFileName", "", "File with coarse map data"); return validParamList; } template void UserPFactory::DeclareInput(Level& fineLevel, Level& /* coarseLevel */) const { Input(fineLevel, "A"); Input(fineLevel, "Nullspace"); } template void UserPFactory::Build(Level& fineLevel, Level& coarseLevel) const { return BuildP(fineLevel, coarseLevel); } template void UserPFactory::BuildP(Level& fineLevel, Level& coarseLevel) const { FactoryMonitor m(*this, "Build", coarseLevel); RCP A = Get >(fineLevel, "A"); RCP fineNullspace = Get >(fineLevel, "Nullspace"); TEUCHOS_TEST_FOR_EXCEPTION(A->GetFixedBlockSize() != 1, Exceptions::RuntimeError, "Block size > 1 has not been implemented"); const Teuchos::ParameterList& pL = GetParameterList(); std::string mapFile = pL.get("mapFileName"); RCP rowMap = A->getRowMap(); RCP coarseMap = Xpetra::IO::ReadMap(mapFile, rowMap->lib(), rowMap->getComm()); Set(coarseLevel, "CoarseMap", coarseMap); std::string matrixFile = pL.get("matrixFileName"); RCP P = Xpetra::IO::Read(matrixFile, rowMap, coarseMap, coarseMap, rowMap); #if 1 Set(coarseLevel, "P", P); #else // Expand column map by 1 RCP P1 = Xpetra::MatrixMatrix::Multiply(*A, false, *P, false); P = Xpetra::IO::Read(matrixFile, rowMap, P1->getColMap(), coarseMap, rowMap); Set(coarseLevel, "P", P); #endif RCP coarseNullspace = MultiVectorFactory::Build(coarseMap, fineNullspace->getNumVectors()); P->apply(*fineNullspace, *coarseNullspace, Teuchos::TRANS, Teuchos::ScalarTraits::one(), Teuchos::ScalarTraits::zero()); Set(coarseLevel, "Nullspace", coarseNullspace); // Coordinates transfer size_t n = Teuchos::as(sqrt(coarseMap->getGlobalNumElements())); TEUCHOS_TEST_FOR_EXCEPTION(n * n != coarseMap->getGlobalNumElements(), Exceptions::RuntimeError, "Unfortunately, this is not the case, don't know what to do"); RCP coarseCoords = MultiVectorFactory::Build(coarseMap, 2); ArrayRCP x = coarseCoords->getDataNonConst(0), y = coarseCoords->getDataNonConst(1); for (size_t LID = 0; LID < coarseMap->getLocalNumElements(); ++LID) { GlobalOrdinal GID = coarseMap->getGlobalElement(LID) - coarseMap->getIndexBase(); GlobalOrdinal i = GID % n, j = GID / n; x[LID] = i; y[LID] = j; } Set(coarseLevel, "Coordinates", coarseCoords); if (IsPrint(Statistics1)) { RCP params = rcp(new ParameterList()); params->set("printLoadBalancingInfo", true); GetOStream(Statistics1) << PerfUtils::PrintMatrixInfo(*P, "P", params); } } } // namespace MueLu #define MUELU_USERPFACTORY_SHORT #endif // MUELU_USERPFACTORY_DEF_HPP