// @HEADER // ***************************************************************************** // MueLu: A package for multigrid based preconditioning // // Copyright 2012 NTESS and the MueLu contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER #ifndef MUELU_NULLSPACEPRESMOOTHFACTORY_DEF_HPP #define MUELU_NULLSPACEPRESMOOTHFACTORY_DEF_HPP #include #include #include #include "MueLu_NullspacePresmoothFactory_decl.hpp" #include "MueLu_Utilities.hpp" #include "MueLu_Monitor.hpp" namespace MueLu { template RCP NullspacePresmoothFactory::GetValidParameterList() const { RCP validParamList = rcp(new ParameterList()); validParamList->set >("A", Teuchos::null, "Generating factory for A"); validParamList->set >("Nullspace", Teuchos::null, "Generating factory for the nonsmoothed nullspace"); return validParamList; } template void NullspacePresmoothFactory::DeclareInput(Level ¤tLevel) const { Input(currentLevel, "Nullspace"); if (currentLevel.GetLevelID() == 0) Input(currentLevel, "A"); } template void NullspacePresmoothFactory::Build(Level ¤tLevel) const { FactoryMonitor m(*this, "Nullspace presmooth factory", currentLevel); RCP newB; if (currentLevel.GetLevelID() == 0) { RCP A = Get >(currentLevel, "A"); RCP B = Get >(currentLevel, "Nullspace"); newB = MultiVectorFactory::Build(B->getMap(), B->getNumVectors()); Teuchos::ArrayRCP D = Utilities::GetMatrixDiagonal_arcp(*A); SC damping = 4. / 3; damping /= Utilities::PowerMethod(*A, true, (LO)10, 1e-4); A->apply(*B, *newB, Teuchos::NO_TRANS); size_t numVec = newB->getNumVectors(); LO numElements = newB->getLocalLength(); for (size_t j = 0; j < numVec; j++) { Teuchos::ArrayRCP Bj = B->getData(j); Teuchos::ArrayRCP newBj = newB->getDataNonConst(j); for (LO i = 0; i < numElements; i++) newBj[i] = Bj[i] - damping * newBj[i] / D[i]; } } else { newB = Get >(currentLevel, "Nullspace"); } // provide "Nullspace" variable on current level Set(currentLevel, "Nullspace", newB); } // Build } // namespace MueLu #endif // MUELU_NULLSPACEPRESMOOTHFACTORY_DEF_HPP