// @HEADER // ***************************************************************************** // MueLu: A package for multigrid based preconditioning // // Copyright 2012 NTESS and the MueLu contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER /* * MueLu_CoarseMapFactory_def.hpp * * Created on: Oct 12, 2012 * Author: wiesner */ #ifndef MUELU_COARSEMAPFACTORY_DEF_HPP_ #define MUELU_COARSEMAPFACTORY_DEF_HPP_ #include #include #include #include "MueLu_CoarseMapFactory_decl.hpp" #include "MueLu_Level.hpp" #include "MueLu_Aggregates.hpp" #include "MueLu_Monitor.hpp" namespace MueLu { template CoarseMapFactory::CoarseMapFactory() = default; template CoarseMapFactory::~CoarseMapFactory() = default; template RCP CoarseMapFactory::GetValidParameterList() const { RCP validParamList = rcp(new ParameterList()); validParamList->set >("Aggregates", Teuchos::null, "Generating factory for aggregates."); validParamList->set >("Nullspace", Teuchos::null, "Generating factory for null space."); validParamList->set("Striding info", "{}", "Striding information"); validParamList->set("Strided block id", -1, "Strided block id"); // Domain GID offsets: list of offset values for domain gids (coarse gids) of tentative prolongator (default = 0). // For each multigrid level we can define a different offset value, ie for the prolongator between // level 0 and level 1 we use the offset entry domainGidOffsets_[0], for the prolongator between // level 1 and level 2 we use domainGidOffsets_[1]... // If the vector domainGidOffsets_ is too short and does not contain a sufficient number of gid offset // values for all levels, a gid offset of 0 is used for all the remaining levels! // The GIDs for the domain dofs of Ptent start with domainGidOffset, are contiguous and distributed // equally over the procs (unless some reordering is done). validParamList->set("Domain GID offsets", "{0}", "vector with offsets for GIDs for each level. If no offset GID value is given for the level we use 0 as default."); return validParamList; } template void CoarseMapFactory::DeclareInput(Level& currentLevel) const { Input(currentLevel, "Aggregates"); Input(currentLevel, "Nullspace"); } template void CoarseMapFactory::setStridingData(std::vector stridingInfo) { // store striding map in internal variable stridingInfo_ = stridingInfo; // try to remove string "Striding info" from parameter list to make sure, // that stridingInfo_ is not replaced in the Build call. std::string strStridingInfo; strStridingInfo.clear(); SetParameter("Striding info", ParameterEntry(strStridingInfo)); } template void CoarseMapFactory::Build(Level& currentLevel) const { FactoryMonitor m(*this, "Build", currentLevel); GlobalOrdinal domainGIDOffset = GetDomainGIDOffset(currentLevel); BuildCoarseMap(currentLevel, domainGIDOffset); } template void CoarseMapFactory::BuildCoarseMap( Level& currentLevel, const GlobalOrdinal domainGIDOffset) const { RCP aggregates = Get >(currentLevel, "Aggregates"); GlobalOrdinal numAggs = aggregates->GetNumAggregates(); RCP aggMap = aggregates->GetMap(); RCP nullspace = Get >(currentLevel, "Nullspace"); const size_t NSDim = nullspace->getNumVectors(); RCP > comm = aggMap->getComm(); const ParameterList& pL = GetParameterList(); LocalOrdinal stridedBlockId = pL.get("Strided block id"); // read in stridingInfo from parameter list and fill the internal member variable // read the data only if the parameter "Striding info" exists and is non-empty if (pL.isParameter("Striding info")) { std::string strStridingInfo = pL.get("Striding info"); if (strStridingInfo.empty() == false) { Teuchos::Array arrayVal = Teuchos::fromStringToArray(strStridingInfo); stridingInfo_ = Teuchos::createVector(arrayVal); } } CheckForConsistentStridingInformation(stridedBlockId, NSDim); GetOStream(Statistics2) << "domainGIDOffset: " << domainGIDOffset << " block size: " << getFixedBlockSize() << " stridedBlockId: " << stridedBlockId << std::endl; // number of coarse level dofs (fixed by number of aggregates and blocksize data) GlobalOrdinal nCoarseDofs = numAggs * getFixedBlockSize(); GlobalOrdinal indexBase = aggMap->getIndexBase(); RCP coarseMap = StridedMapFactory::Build(aggMap->lib(), Teuchos::OrdinalTraits::invalid(), nCoarseDofs, indexBase, stridingInfo_, comm, stridedBlockId, domainGIDOffset); Set(currentLevel, "CoarseMap", coarseMap); } template GlobalOrdinal CoarseMapFactory::GetDomainGIDOffset( Level& currentLevel) const { GlobalOrdinal domainGidOffset = Teuchos::ScalarTraits::zero(); std::vector domainGidOffsets; domainGidOffsets.clear(); const ParameterList& pL = GetParameterList(); if (pL.isParameter("Domain GID offsets")) { std::string strDomainGIDs = pL.get("Domain GID offsets"); if (strDomainGIDs.empty() == false) { Teuchos::Array arrayVal = Teuchos::fromStringToArray(strDomainGIDs); domainGidOffsets = Teuchos::createVector(arrayVal); if (currentLevel.GetLevelID() < Teuchos::as(domainGidOffsets.size())) { domainGidOffset = domainGidOffsets[currentLevel.GetLevelID()]; } } } return domainGidOffset; } template void CoarseMapFactory::CheckForConsistentStridingInformation( const LocalOrdinal stridedBlockId, const size_t nullspaceDimension) const { // check for consistency of striding information with NSDim and nCoarseDofs if (stridedBlockId == -1) { // this means we have no real strided map but only a block map with constant blockSize "nullspaceDimension" TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo_.size() > 1, Exceptions::RuntimeError, "MueLu::CoarseMapFactory::Build(): stridingInfo_.size() but must be one"); stridingInfo_.clear(); stridingInfo_.push_back(nullspaceDimension); TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo_.size() != 1, Exceptions::RuntimeError, "MueLu::CoarseMapFactory::Build(): stridingInfo_.size() but must be one"); } else { // stridedBlockId > -1, set by user TEUCHOS_TEST_FOR_EXCEPTION(stridedBlockId > Teuchos::as(stridingInfo_.size() - 1), Exceptions::RuntimeError, "MueLu::CoarseMapFactory::Build(): it is stridingInfo_.size() <= stridedBlockId_. error."); size_t stridedBlockSize = stridingInfo_[stridedBlockId]; TEUCHOS_TEST_FOR_EXCEPTION(stridedBlockSize != nullspaceDimension, Exceptions::RuntimeError, "MueLu::CoarseMapFactory::Build(): dimension of strided block != nullspaceDimension. error."); } } } // namespace MueLu #endif /* MUELU_COARSEMAPFACTORY_DEF_HPP_ */